Table of Contents

Class Dimension

Namespace
CADability.GeoObject
Assembly
CADability.dll

The dimension object represents a dimensioning in a model and is a IGeoObject. To use a dimension object you must at least set the properties DimensionStyle, DimLineRef, DimLineDirection, and add two points with the AddPoint(GeoPoint) method. Example:

// assuming "project" is a reference to a Project
Dimension d = Dimension.Construct();
d.DimensionStyle = project.DimensionStyleList.Current;
d.DimLineRef = new GeoPoint(200, 200, 0);
d.DimLineDirection = GeoVector.XAxis;
d.AddPoint(new GeoPoint(100, 100, 0));
d.AddPoint(new GeoPoint(200, 100, 0));
d.AddPoint(new GeoPoint(300, 100, 0));
project.GetActiveModel().Add(d);
public class Dimension : IGeoObjectImpl, IGeoObject, ILayer, IStyle, IOctTreeInsertable, IComparable, IFeedBack, ICloneable, ISerializable, IDimensionStyle, IGeoObjectOwner
Inheritance
Dimension
Implements
Inherited Members

Constructors

Dimension()

Creates an empty dimension of type DimPoints in the xy plane (Normal is the z axis). Protected so that dimensions are created via Construct(); derived classes call it from their own constructors.

protected Dimension()

Dimension(SerializationInfo, StreamingContext)

Constructor required by deserialization

protected Dimension(SerializationInfo info, StreamingContext context)

Parameters

info SerializationInfo

SerializationInfo

context StreamingContext

StreamingContext

Fields

Constructor

Optional factory for dimensions: when set, Construct() calls this delegate instead of creating a plain Dimension, so that every dimension CADability creates (by a construction action, when importing a file etc.) is an instance of your derived class. Null by default.

public static Dimension.ConstructionDelegate Constructor

Field Value

Dimension.ConstructionDelegate

OnPaintTo3D

Hook to replace the painting of dimensions: when set, PaintTo3D(IPaintTo3D) calls this delegate first and does nothing more if it returns true. Applies to all dimensions. Null by default.

public static Dimension.PaintTo3DDelegate OnPaintTo3D

Field Value

Dimension.PaintTo3DDelegate

Properties

DimLineDirection

The direction of the dimension line for DimPoints and DimCoord dimensions; together with DimLineRef and Normal it defines the Plane of the dimension. For the radius, diameter and location types it is derived from DimLineRef and the first point whenever the dimension is computed. The change raises the change events and is undoable.

public GeoVector DimLineDirection { get; set; }

Property Value

GeoVector

DimLineRef

The reference point of the dimension line in world coordinates. For DimPoints and DimCoord the dimension line passes through this point, the measured points are projected onto it. For DimAngle its distance from the center is the radius of the dimension arc. For DimRadius and DimDiameter it determines the direction of the dimension line from the center and, when it lies outside the circle, the bend point of the leader. For DimLocation it is the bend point of the leader. The change raises the change events and is undoable.

public GeoPoint DimLineRef { get; set; }

Property Value

GeoPoint

DimType

The kind of dimensioning (distance between points, coordinate, angle, radius, diameter or location label), which decides how the points and the other properties are interpreted. DimPoints after Construct(). Set it before adding points, because AddPoint(GeoPoint) organises the texts differently for the point based types. The change raises the change events and is undoable.

public Dimension.EDimType DimType { get; set; }

Property Value

Dimension.EDimType

DimensionStyle

The DimensionStyle that defines the appearance of the dimension: font and size of the texts, symbols, tolerances, prefix and postfix, number format, placement of the texts and so on. The dimension is not displayed as long as no style is set; usually a style of the DimensionStyleList is used. Setting it raises the change events and is undoable. When the style itself has been modified, call Recalc() to update the dimension.

public DimensionStyle DimensionStyle { get; set; }

Property Value

DimensionStyle

DistToEnd

Counterpart of DistToStart for the end of an angle dimension. The value is kept and saved with the dimension but is currently not used when the dimension is computed. It is stored as a double, the property converts it to an Angle. The change raises the change events and is undoable.

public Angle DistToEnd { get; set; }

Property Value

Angle

DistToStart

Distance value of an angle dimension, taken over from an older file format. The value is kept and saved with the dimension but is currently not used when the dimension is computed. The change raises the change events and is undoable.

public double DistToStart { get; set; }

Property Value

double

EndAngle

End angle of an angle dimension, taken over from an older file format. The value is kept and saved with the dimension but is currently not used when the dimension is computed: the angle is taken from the points (see AddPoint(GeoPoint)). The change raises the change events and is undoable.

public Angle EndAngle { get; set; }

Property Value

Angle

ExtLineAngle

The angle of the extension lines relative to the dimension line, usually a right angle. The value is kept and saved with the dimension but is currently not used when the dimension is computed: the extension lines are always perpendicular to the dimension line. The change raises the change events and is undoable.

public Angle ExtLineAngle { get; set; }

Property Value

Angle

Normal

The normal of the plane in which the dimension lies, the z axis after Construct(); the construction actions set it to the normal of the drawing plane. Together with DimLineRef and DimLineDirection (or the center for radius and diameter dimensions) it defines the Plane of the dimension; for angle dimensions, whose plane is given by the three points, it only selects the side from which the dimension is seen. Setting it raises no change events and is not undoable, so set it before the dimension is added to a model.

public GeoVector Normal { get; set; }

Property Value

GeoVector

Plane

The plane in which the dimension is drawn. For the point based types its origin is DimLineRef and its x axis the dimension line, for angle, radius and diameter dimensions its origin is the center. It is derived from the points and the properties of the dimension whenever the dimension is computed (Recalc(Projection, GeoObjectList)), so it is only up to date after the dimension has been displayed or measured; the xy plane after Construct(). Read only.

public Plane Plane { get; }

Property Value

Plane

PointCount

The number of points of the dimension, see AddPoint(GeoPoint) for their meaning.

public int PointCount { get; }

Property Value

int

PreferredStyle

Returns the preferred style for this objects, see Style.EDefaultFor.

public override Style.EDefaultFor PreferredStyle { get; }

Property Value

Style.EDefaultFor

Radius

The radius of the circle or arc for DimRadius and DimDiameter dimensions, measured from the first point (the center). It determines where the dimension line touches the circle and the displayed value: the radius or twice the radius, multiplied by the Scale of the style. Not used by the other types. The change raises the change events and is undoable.

public double Radius { get; set; }

Property Value

double

StartAngle

Start angle of an angle dimension, taken over from an older file format. The value is kept and saved with the dimension but is currently not used when the dimension is computed: the angle is taken from the points (see AddPoint(GeoPoint)). The change raises the change events and is undoable.

public Angle StartAngle { get; set; }

Property Value

Angle

Methods

Add(IGeoObject)

Implements Add(IGeoObject). The dimension keeps no child objects (its representation is computed on demand), so this merely sets the Owner of the given object to this dimension, e.g. for a temporary object that belongs to the dimension while it is edited.

public void Add(IGeoObject toAdd)

Parameters

toAdd IGeoObject

The object to be owned by this dimension

AddPoint(GeoPoint)

Appends a point to the points of the dimension. What the points mean depends on DimType: for DimPoints and DimCoord they are the measured points (any number, at least two, for DimCoord the first point is the origin), for DimAngle the center followed by a point on each leg, for DimRadius and DimDiameter the center of the circle, for DimLocation the labelled points. For DimPoints and DimCoord the texts of the segments (GetDimText(int), GetTextPos(int) ...) get an additional empty entry; call SortPoints() afterwards to keep the points ordered along the dimension line. For the other types the text entries are created with the first point. The change raises the change events and is undoable.

public void AddPoint(GeoPoint p)

Parameters

p GeoPoint

The point to add in world coordinates

Clone()

Clones this GeoObject.

public override IGeoObject Clone()

Returns

IGeoObject

the cloned GeoObject

Construct()

Creates a new dimension of type DimPoints without points, style and dimension line. This is the only public way to create a dimension, the constructor is protected. If a Constructor is registered, the dimension is created by that delegate. See the class description for what must be set before the dimension can be displayed.

public static Dimension Construct()

Returns

Dimension

The new dimension

CopyGeometry(IGeoObject)

Copies the geometrical aspects of the given GeoObject to this GeoObject. Both objects must be of the same type. The attributes are not copied.

public override void CopyGeometry(IGeoObject ToCopyFrom)

Parameters

ToCopyFrom IGeoObject

GeoObject to copy from

Decompose()

Decomposes the object into simpler objects, see Decompose(). The default implementation returns null: the object cannot be decomposed.

public override GeoObjectList Decompose()

Returns

GeoObjectList

the parts, or null

GetAttributeProperties(IFrame)

Implements GetAttributeProperties(IFrame). The default implementation returns ShowProperties for all CADability attributes.

public override IPropertyEntry[] GetAttributeProperties(IFrame Frame)

Parameters

Frame IFrame

the frame of the view

Returns

IPropertyEntry[]

list of IPropertyEntry

GetBoundingCube()

Returns a bounding cube of the object. The object must fir into this cube. There may be a smaller cube that contains the object if it is to expensive to calculate the exact cube.

public override BoundingCube GetBoundingCube()

Returns

BoundingCube

the bounding cube

GetDimText(int)

Returns the main text of a segment: the text set with SetDimText(int, string) if there is one, otherwise the measured value formatted according to the DimensionStyle (the distance along the dimension line, the distance from the origin, the angle, the radius or the diameter, or the coordinates of the first point for a location dimension). Prefix, postfix and tolerances are not included.

public string GetDimText(int index)

Parameters

index int

Index of the segment, see GetTextPos(int)

Returns

string

The text as it is displayed

GetExtent(Projection, ExtentPrecision)

Returns the 2d extent of the object as it appears in the given projection, in the coordinates of the projection's plane (not in pixels).

public override BoundingRect GetExtent(Projection projection, ExtentPrecision extentPrecision)

Parameters

projection Projection

the projection

extentPrecision ExtentPrecision

Exact for the exact extent, Raw for a quick estimate that may be larger

Returns

BoundingRect

the extent in the projection's 2d coordinates

GetExtent(double)

Gets the 3-dimensional extent of an object

public override BoundingCube GetExtent(double precision)

Parameters

precision double

Precision of the test

Returns

BoundingCube

The minmax cube

GetHitPosition(Projection, GeoPoint2D, out int)

Determines which parts of the dimension (dimension line, texts) are hit by a point and in which segment. Intended for the interactive editing of dimensions, where a click on a text selects the corresponding property and a point dropped on the dimension line of a point dimension extends that dimension. The implementation is currently disabled: it always returns 0 (nothing hit) and sets Index to -1.

public Dimension.HitPosition GetHitPosition(Projection p, GeoPoint2D projectedPoint, out int Index)

Parameters

p Projection

The projection of the view in which the point was picked

projectedPoint GeoPoint2D

The point in the 2d coordinates of that projection

Index int

Receives the index of the hit segment (see GetTextPos(int)), -1 when nothing was hit

Returns

Dimension.HitPosition

The hit parts as a combination of Dimension.HitPosition flags, 0 when nothing was hit

GetObjectData(SerializationInfo, StreamingContext)

Writes the data of this object for the legacy binary serialization (ISerializable). Files are written in the JSON format (IJsonSerialize) now; the binary format is still read.

public void GetObjectData(SerializationInfo info, StreamingContext context)

Parameters

info SerializationInfo

receives the data

context StreamingContext

the destination of the serialization

GetPoint(int)

Returns the point with the given index, see AddPoint(GeoPoint) for the meaning of the points.

public GeoPoint GetPoint(int Index)

Parameters

Index int

Index of the point, 0 <= Index < PointCount

Returns

GeoPoint

The point in world coordinates

GetPostfix(int)

Returns the text displayed after the main text of a segment: the postfix set with SetPostfix(int, string) if there is one, otherwise the TextPostfix of the style.

public string GetPostfix(int index)

Parameters

index int

Index of the segment, see GetTextPos(int)

Returns

string

The postfix, may be null or empty

GetPostfixAlt(int)

Returns the postfix of the alternative text of a segment: the text set with SetPostfixAlt(int, string) if there is one, otherwise the TextPostfixAlt of the style. The alternative text (a second value in brackets) is currently not generated, so the value is kept and saved but not displayed.

public string GetPostfixAlt(int index)

Parameters

index int

Index of the segment, see GetTextPos(int)

Returns

string

The alternative postfix, may be null or empty

GetPrefix(int)

Returns the text displayed in front of the main text of a segment: the prefix set with SetPrefix(int, string) if there is one, otherwise the TextPrefix of the style.

public string GetPrefix(int index)

Parameters

index int

Index of the segment, see GetTextPos(int)

Returns

string

The prefix, may be null or empty

GetQuadTreeItem(Projection, ExtentPrecision)

Returns an item for a 2d quad tree of the projected objects, used for hit tests in a projection: it knows the 2d extent of the object, whether a 2d rectangle hits it, and the depth (z position) of the object at a 2d point. Composite objects (blocks, solids, paths) return a collection of the items of their parts.

public override IQuadTreeInsertableZ GetQuadTreeItem(Projection projection, ExtentPrecision extentPrecision)

Parameters

projection Projection

the projection

extentPrecision ExtentPrecision

precision of the extent, see GetExtent(Projection, ExtentPrecision)

Returns

IQuadTreeInsertableZ

the item for the quad tree

GetShowProperties(IFrame)

Should be overridden and return a IPropertyEntry derived object that handles the display and modification of the properties of the IGeoObject derived object. Default implementation return null.

public override IPropertyEntry GetShowProperties(IFrame Frame)

Parameters

Frame IFrame

Returns

IPropertyEntry

GetTextPos(int)

Returns the position of the text of a segment along its dimension line as a parameter: 0.0 at the start, 0.5 in the middle (the default), 1.0 at the end; values outside [0, 1] place the text beyond the ends. For angle dimensions the parameter runs along the dimension arc.

public double GetTextPos(int index)

Parameters

index int

Index of the segment: 0 for angle, radius, diameter and location dimensions, for DimPoints and DimCoord the index of the measured segment, 0 <= index < PointCount - 1

Returns

double

The position parameter of the text

GetTolMinusText(int)

Returns the lower tolerance text of a segment, which is displayed lowered after the main text: the text set with SetTolMinusText(int, string) if there is one, otherwise the MinusTolerance of the style formatted with a leading sign. The text is only displayed when the style shows tolerances or when the text was set explicitly.

public string GetTolMinusText(int index)

Parameters

index int

Index of the segment, see GetTextPos(int)

Returns

string

The tolerance text

GetTolPlusText(int)

Returns the upper tolerance text of a segment, which is displayed raised after the main text: the text set with SetTolPlusText(int, string) if there is one, otherwise the PlusTolerance of the style formatted with a leading sign. The text is only displayed when the style shows tolerances or when the text was set explicitly.

public string GetTolPlusText(int index)

Parameters

index int

Index of the segment, see GetTextPos(int)

Returns

string

The tolerance text

HitTest(ref BoundingCube, double)

Tests whether an object is touched by the provided cube

public override bool HitTest(ref BoundingCube cube, double precision)

Parameters

cube BoundingCube

To test with

precision double

Required precision

Returns

bool

true if the object strikes the cube

HitTest(Projection, BoundingRect, bool)

Tests whether an object is inside or touched by the rectangle when projected with the provided projection

public override bool HitTest(Projection projection, BoundingRect rect, bool onlyInside)

Parameters

projection Projection

The projection for the test

rect BoundingRect

The rectangle to test the position

onlyInside bool

true: the object must be totaly inside the rectangle, false: the object must be totaly or partially inside the rectangle

Returns

bool

true when the test succeedes, false otherwise

HitTest(PickArea, bool)

Tests whether an object is inside or touched by the provided area

public override bool HitTest(Projection.PickArea area, bool onlyInside)

Parameters

area Projection.PickArea

The area to check for

onlyInside bool

true: the object must be totaly inside the area, false: the object must be totaly or partially inside the area

Returns

bool

true when the test succeedes, false otherwise

IsAttributeUsed(object)

/// Overrides IsAttributeUsed(object). The default implementation recursively calls IsAttributeUsed for all children (if any) and then checks the usage for all attributes implemented by CADability. No checks are performed for non CADability attributes. So you can override this method to handle your own attributes and call the base implementation for CADability attributes.

public override bool IsAttributeUsed(object Attribute)

Parameters

Attribute object

Returns

bool

true if used by this GeoObject

Modify(ModOp)

Modifies this GeoObject with the given modification operation (includes moving, rotating, reflecting, scaling etc.).

public override void Modify(ModOp m)

Parameters

m ModOp

Operation to be applied

PaintTo3D(IPaintTo3D)

Paints the object with the methods of paintTo3D: lines, triangles, text... The views implement IPaintTo3D (with OpenGL or GDI) and collect what the object paints in a display list, so this is called rarely, after PrepareDisplayList(double) has done the expensive work (triangulation, approximation).

public override void PaintTo3D(IPaintTo3D paintTo3D)

Parameters

paintTo3D IPaintTo3D

where to paint

Position(GeoPoint, GeoVector, double)

Returns the smallest parameter value (l) where the provided line hits the object so that the point fromHere + l * direction is on or close to the object. The result may be negative. Return double.MaxValue if there is no such point.

public override double Position(GeoPoint fromHere, GeoVector direction, double precision)

Parameters

fromHere GeoPoint

Startpoint of the line

direction GeoVector

Direction of the line

precision double

Precision for the test

Returns

double

Position on the line

PrePaintTo3D(IPaintTo3D)

Called before PaintTo3D(IPaintTo3D), outside of the display list that collects what PaintTo3D paints. Override it for work that must not go into that list, e.g. painting that needs a display list of its own. The default implementation does nothing.

public override void PrePaintTo3D(IPaintTo3D paintTo3D)

Parameters

paintTo3D IPaintTo3D

the paint interface of the view

PrepareDisplayList(double)

Called before PaintTo3D(IPaintTo3D) is called, should implement the time consuming work for the display (like calculationg the triangulation of Faces or Polylines of Curves). Not normally used by user code.

public override void PrepareDisplayList(double precision)

Parameters

precision double

Required precision

Recalc()

Call this, if the DimensionStyle used by this Dimension was modified.

public void Recalc()

Recalc(Projection, GeoObjectList)

Computes the graphical representation of the dimension (dimension line, extension lines, symbols and texts as lines, polylines, hatches and texts) for the current DimType and appends it to the given list. Sizes the DimensionStyle specifies in paper units (text size, symbol size) are scaled by the LayoutFactor of the projection, and the horizontal direction of the projection decides how the texts are oriented. Nothing is added when the dimension is incomplete (no style, too few points, plane not determinable). The dimension keeps no child objects: painting, hit tests, extent and Decompose() all call this method. Plane is updated as a side effect.

public void Recalc(Projection p, GeoObjectList list)

Parameters

p Projection

The projection the representation is computed for

list GeoObjectList

Receives the generated objects

Remove(IGeoObject)

Implements Remove(IGeoObject). The dimension keeps no child objects (its representation is computed on demand), so this merely clears the Owner of the given object.

public void Remove(IGeoObject toRemove)

Parameters

toRemove IGeoObject

The object that is no longer owned by this dimension

RemovePoint(int)

Removes the point with the given index. The texts of the segments are not adjusted, so for DimPoints and DimCoord dimensions the texts keep their old segment indices. The change raises the change events and is undoable.

public void RemovePoint(int Index)

Parameters

Index int

Index of the point, 0 <= Index < PointCount

SetDimText(int, string)

Replaces the measured value of a segment by a fixed text. Null or an empty string removes the replacement, so that the measured value is displayed again. Nothing happens when the text does not change; otherwise the change raises the change events.

public void SetDimText(int index, string text)

Parameters

index int

Index of the segment, see GetTextPos(int)

text string

The text to display instead of the measured value, or null

SetPoint(int, GeoPoint)

Replaces the point with the given index. For DimPoints and DimCoord call SortPoints() afterwards when the order of the points along the dimension line may have changed. The change raises the change events and is undoable.

public void SetPoint(int Index, GeoPoint p)

Parameters

Index int

Index of the point, 0 <= Index < PointCount

p GeoPoint

The new point in world coordinates

SetPostfix(int, string)

Replaces the postfix of a segment (see GetPostfix(int)) by a fixed text. Null or an empty string removes the replacement, so that the postfix of the style is used again. Nothing happens when the text does not change; otherwise the change raises the change events and is undoable.

public void SetPostfix(int index, string txt)

Parameters

index int

Index of the segment, see GetTextPos(int)

txt string

The text to display after the main text, or null

SetPostfixAlt(int, string)

Replaces the postfix of the alternative text of a segment (see GetPostfixAlt(int)) by a fixed text. Null or an empty string removes the replacement. Nothing happens when the text does not change; otherwise the change raises the change events and is undoable.

public void SetPostfixAlt(int index, string txt)

Parameters

index int

Index of the segment, see GetTextPos(int)

txt string

The alternative postfix, or null

SetPrefix(int, string)

Replaces the prefix of a segment (see GetPrefix(int)) by a fixed text. Null or an empty string removes the replacement, so that the prefix of the style is used again. Nothing happens when the text does not change; otherwise the change raises the change events and is undoable.

public void SetPrefix(int index, string txt)

Parameters

index int

Index of the segment, see GetTextPos(int)

txt string

The text to display in front of the main text, or null

SetTextPos(int, double)

Sets the position of the text of a segment along its dimension line, see GetTextPos(int). The change raises the change events and is undoable.

public void SetTextPos(int index, double val)

Parameters

index int

Index of the segment, see GetTextPos(int)

val double

The new position parameter, 0.0 at the start, 1.0 at the end of the dimension line

SetTolMinusText(int, string)

Replaces the lower tolerance text of a segment (see GetTolMinusText(int)) by a fixed text. Null or an empty string removes the replacement. Nothing happens when the text does not change; otherwise the change raises the change events and is undoable.

public void SetTolMinusText(int index, string txt)

Parameters

index int

Index of the segment, see GetTextPos(int)

txt string

The text to display, or null

SetTolPlusText(int, string)

Replaces the upper tolerance text of a segment (see GetTolPlusText(int)) by a fixed text. Null or an empty string removes the replacement. Nothing happens when the text does not change; otherwise the change raises the change events and is undoable.

public void SetTolPlusText(int index, string txt)

Parameters

index int

Index of the segment, see GetTextPos(int)

txt string

The text to display, or null

SortPoints()

Call this after a point to a dimension of type EDimType.DimCoord or EDimType.DimPoints has been added or changed, to rorder the list of points

public void SortPoints()