Eli

Eli

  • NA
  • 30
  • 0

Need help to finish this Class!

May 16 2007 12:19 PM
hi, i'm new to csharp and i'm working with it on a school project.
i'm building a class named inxblock. here is the summary: i'm trying through this class to modelize a block on an Adobe InDesign document. this block is caracterize by its anchor point(x,y) coordinate the width and height of the block. but the block can be in a parent block or have itself children.

using System;

using System.Collections.Generic;

using System.Collections.ObjectModel;

using System.ComponentModel;

using System.IO;

using System.Xml;

namespace Hot2Inx

{

class InxBlock

{

//the dimensions of the blocks: width, height and coordinates x,y of the anchor point.

private double _x;

private double _y;

private double _width;

private double _height;

//private string self;//the self attribute

//private string typeName; //the type of block

public Collection <InxBlock> Children = new Collection<InxBlock>();

private InxBlock _parent ;

//set the properties of the attributes

public double X

{

get { return _x; }

set { _x = value; }

}// end property X

public double Y

{

get { return _y; }

set { _y = value; }

}// end property Y

public double Height

{

get { return _height; }

set { _height = value; }

}// end property Height

public double Width

{

get { return _width; }

set { _width = value; }

}// end property Width

//public string Self

//{

// get { return self; }

// set { bSelf = value; }

//}// end property Self

//public string TypeName

//{

// get { return typeName; }

// set { typeName = value; }

//}// end property TypeName

public InxBlock Parent

{

get { return _parent; }

set

{

if (_parent != null)

{

_parent.Children.Remove(this);

}//end if

_parent.Children.Add(this);

}

}// end property Parent

public InxBlock(InxBlock inxParent)

{

if (inxParent != null)

{

this.Parent = inxParent;

}//end if

}// end InxBlock constructor

/// <summary>

///Lay out the block on the appropriate place of the ID doc

/// Determines the coordinates of the childs in the parent coordinate space

/// </summary>

public void LayoutBlock()

{

//the coordinates of parent block

double px = Parent._x;

double py = Parent._y;

double pw = Parent._width;

double ph = Parent._height;

//the child coordinates in the parent coordinate space

double cx = _x - (px + pw / 2);

double cy = _y - (py + ph / 2);

}//end LayoutBlock

 

public XmlNode CreateInxNode()

{

XmlNode inxnode = null;

string igeo = IGeometry.GetIGeometry(_x, _y, _width, _height);

addAttribute(inxnode, "IGeo", igeo);

return inxnode;

}//end CreateInxNode

/// <summary>

/// Add a new attribute to an XmlNode

/// </summary>

/// <param name="node"></param>

/// <param name="attributeName"></param>

/// <param name="value"></param>

private void addAttribute(XmlNode node, string attributeName, string value)

{

XmlNode newAttribute;

XmlNode cAttribute;

cAttribute = node.Attributes.GetNamedItem(attributeName);

if (cAttribute == null)

{

newAttribute = node.OwnerDocument.CreateAttribute(attributeName);

newAttribute.InnerText = value;

node.Attributes.SetNamedItem(newAttribute);

}

else

{

cAttribute.Value = value;

}

}//end addAttribute

 

}//end class InxBlock

}//end namespace Hot2Inx