Table of Contents

Class Path

Namespace
CADability.GeoObject
Assembly
CADability.dll

A geoobject, that derives from Block and represents a ordered collection of geoobjects which all support the ICurve intrface. The contained curves are connected, i.e. Child(i).EndPoint is equal or close to Child(i+1).StartPoint. The Path is not necessary planar, closed and may be self intersecting.

public class Path : IGeoObjectImpl, IFeedBack, ICloneable, IColorDef, ILinePattern, ILineWidth, ICurve, IGeoObject, ILayer, IStyle, IOctTreeInsertable, IComparable, IGeoObjectOwner, ISerializable, IDeserializationCallback, IExtentedableCurve, IJsonSerialize, IJsonSerializeDone
Inheritance
Path
Implements
Inherited Members

Constructors

Path()

Needed for JsonSerialize

protected Path()

Path(SerializationInfo, StreamingContext)

Constructor required by deserialization

protected Path(SerializationInfo info, StreamingContext context)

Parameters

info SerializationInfo

SerializationInfo

context StreamingContext

StreamingContext

Fields

Constructor

Optional hook for polymorphic construction. When set, Construct() calls this delegate instead of creating a plain Path, so that an application can have its own derived class instantiated wherever CADability creates a path.

public static Path.ConstructionDelegate Constructor

Field Value

Path.ConstructionDelegate

OnPaintTo3D

Static hook called at the beginning of PaintTo3D(IPaintTo3D) for every path. Set it to replace or extend the way paths are displayed; when the handler returns true, the default painting is skipped.

public static Path.PaintTo3DDelegate OnPaintTo3D

Field Value

Path.PaintTo3DDelegate

Properties

ColorDef

The color of this path. Setting it also sets the color of all contained curves. It is an undoable attribute change that raises the change events; a "color from parent" value is resolved against the Block that owns this object.

public ColorDef ColorDef { get; set; }

Property Value

ColorDef

Count

The number of sub curves (segments) of this path, 0 if the path is empty. Same as CurveCount.

public int Count { get; }

Property Value

int

Gets the number of subcurves in this path.

CurveCount

Returns the number of curves in the Path

public int CurveCount { get; }

Property Value

int

Curves

Returns a cloned array of the curves of this path. Do not modify the curves or the path will be in an invalid state.

public ICurve[] Curves { get; }

Property Value

ICurve[]

Description

Returns a textual description of the GeoObject. Mainly used for debugging purposes

public override string Description { get; }

Property Value

string

EndDirection

The end direction of the last curve (see EndDirection).

public GeoVector EndDirection { get; }

Property Value

GeoVector

Exceptions

PathException

with PathIsEmtpy when the path contains no curves

EndPoint

The end point of the last curve. Setting it sets the end point of the last curve, which adapts itself as its EndPoint setter does; the change is undoable and raises the change events.

public GeoPoint EndPoint { get; set; }

Property Value

GeoPoint

Exceptions

PathException

with PathIsEmtpy when the path contains no curves

IsClosed

true when the end point of the last curve coincides with the start point of the first curve (within eps).

public bool IsClosed { get; }

Property Value

bool

Exceptions

PathException

with PathIsEmtpy when the path contains no curves

IsSingular

true when every curve of the path is singular, i.e. degenerates to a point; also true for an empty path.

public bool IsSingular { get; }

Property Value

bool

Layer

Fully implements Layer. Stores the layer in a private member. Setting raises the WillChangeEvent and DidChangeEvent.

public override Layer Layer { get; set; }

Property Value

Layer

Length

The sum of the lengths of all curves, 0 for an empty path.

public double Length { get; }

Property Value

double

LinePattern

The line pattern (dashes) used to display this path, null for a solid line. Setting it also sets the pattern of all contained curves; it is an undoable attribute change that raises the change events.

public LinePattern LinePattern { get; set; }

Property Value

LinePattern

LineWidth

The line width used to display this path, null for the default. Setting it also sets the line width of all contained curves; it is an undoable attribute change that raises the change events.

public LineWidth LineWidth { get; set; }

Property Value

LineWidth

PreferredStyle

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

public override Style.EDefaultFor PreferredStyle { get; }

Property Value

Style.EDefaultFor

StartDirection

The start direction of the first curve (see StartDirection).

public GeoVector StartDirection { get; }

Property Value

GeoVector

Exceptions

PathException

with PathIsEmtpy when the path contains no curves

StartPoint

The start point of the first curve. Setting it sets the start point of the first curve, which adapts itself as its StartPoint setter does; the change is undoable and raises the change events.

public GeoPoint StartPoint { get; set; }

Property Value

GeoPoint

Exceptions

PathException

with PathIsEmtpy when the path contains no curves

Vertices

The points where the curves are connected: the start points of all curves and, for an open path, the end point of the last curve. For a closed path the end point coincides with the first vertex and is not repeated.

public GeoPoint[] Vertices { get; }

Property Value

GeoPoint[]

Methods

Add(ICurve)

Adds a curve to this path. It is checked whether the curve to add can be connected to the start or endpoint of this path. If necessary the curve will be reversed. If it cannot be connected false will be returned.

public bool Add(ICurve ToAdd)

Parameters

ToAdd ICurve

curve to add

Returns

bool

true on success, false on failure

BestCyclicalPosition(Path)

Assumes both this and toThis are closed Paths with the same number of segments. Changes this Path to start with the segment where the distance of corresponding vertices is minimal. The geometry of this curve will not be changed

public bool BestCyclicalPosition(Path toThis)

Parameters

toThis Path

adapt to this path

Returns

bool

true, if condition is satisfied

ChangeCyclicalStart(int)

Rotates the order of the curves so that the curve with the given index becomes the first one. Meant for a closed path, where this only moves the start point (and thus the parameter range) without changing the geometry. The change is undoable and raises the change events.

public void ChangeCyclicalStart(int newStartCurve)

Parameters

newStartCurve int

Index of the curve that becomes the first curve, 0 to CurveCount-1

Clear()

Removes all subcurves, the Path will be empty. Use this before modifying contained objects of this path because it is not allowed to mdify an object in a path in a way that would compromise the consitence of the path

public void Clear()

Clone()

Clones this GeoObject.

public override IGeoObject Clone()

Returns

IGeoObject

the cloned GeoObject

Construct()

Creates a new path. This is the only way to create one, the constructor is protected. The returned path contains no curves; fill it with Set(ICurve[]) or Set(GeoObjectList, bool, double), or use FromSegments(IEnumerable<ICurve>, bool).

public static Path Construct()

Returns

Path

A new Path, or an object of the derived class provided by Constructor

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

CreateFromModel(ICurve, Model, Projection, bool)

Returns a Path containing the curve BeginWith and other curves from the projectedModel. The curve BeginWith is checked at both ends to find connected objects. The search is stopped if there are nore more connected objects. The curves are clones and are tagged with UserData objects with the name key "CADability.Path.Original" and the original object as the value. If flatten is true, UserData will be lost.

public static Path CreateFromModel(ICurve BeginWith, Model model, Projection projection, bool flatten)

Parameters

BeginWith ICurve

Curve to begin with

model Model

Model to search for connected curves

projection Projection

Projection, in which the end points of the curves are projected to find connected objects in the model

flatten bool

true: flatten the result, false: result not flattened

Returns

Path

The path or null if no cennecting objects found

CreateFromModel(ICurve, Model, bool)

Returns a Path containing the curve BeginWith and other curves from the Model. The curve BeginWith is checked at both ends to find connected objects. The search is stopped when there are nore more connected objects. The curves are clones and are tagged with UserData objects with the name key "CADability.Path.Original" and the original object as the value. If flatten is true, UserData will be lost.

public static Path CreateFromModel(ICurve BeginWith, Model model, bool flatten)

Parameters

BeginWith ICurve

Curve to begin with

model Model

the model to search for connecting curves

flatten bool

true: flatten the result, false: result not flattened

Returns

Path

The path or null if no cennecting objects found

Curve(int)

Returns the i-th curve of the path. Do not modify this curve or the path will be in an invalid state. For the number of curves see CurveCount.

public ICurve Curve(int Index)

Parameters

Index int

Index of the desired curve

Returns

ICurve

The curve with the given index

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

DirectionAt(double)

Returns the direction of the curve at a specified point. The parameter position of the start-point is 0.0, the parameter position of the endpoint is 1.0. Directions of a position outside this interval may be undefined.

public GeoVector DirectionAt(double Position)

Parameters

Position double

Position on the curve

Returns

GeoVector

The requested direction

FindSnapPoint(SnapPointFinder)

Asks the object to add its snap points (end points, centres, intersections...) of the kinds that spf asks for. The default implementation adds none; objects with geometry override it.

public override void FindSnapPoint(SnapPointFinder spf)

Parameters

spf SnapPointFinder

definition and collection of the snap points

Flatten()

Flattens this path. All subcurves that are composed of simple curves are decomposed into simpler curves (e.g. a polyline is decomposed into lines)

public void Flatten()

FromSegments(IEnumerable<ICurve>, bool)

Creates a path from the given curves. When connectedAndOriented is true, the curves are taken in the given order and direction (see Set(ICurve[]); small gaps are closed by moving end points). Otherwise they are sorted and reversed as needed to form a connected chain (see Set(GeoObjectList, bool, double)), and curves that do not fit into the chain are left out. The curves become children of the path and are removed from their previous owner; pass clones if the originals must stay in their model.

public static Path FromSegments(IEnumerable<ICurve> curves, bool connectedAndOriented)

Parameters

curves IEnumerable<ICurve>

The curves that make up the path

connectedAndOriented bool

true if the curves are already in order and each one ends where the next one starts

Returns

Path

The new path, or null when connectedAndOriented is false and no connected chain of at least two curves could be built

FromSegments(List<ICurve>)

Groups the given curves into as many connected paths as possible: repeatedly builds a path of at least two curves from the remaining curves (see Set(GeoObjectList, bool, double)) until no more connected chain is found. Curves used in a path are removed from curves, so afterwards the list holds the curves that could not be connected to any other. The paths are flattened (see Flatten()).

public static List<Path> FromSegments(List<ICurve> curves)

Parameters

curves List<ICurve>

The curves to connect; curves used in a path are removed from this list

Returns

List<Path>

The paths found, an empty list when no two curves connect

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

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

GetObjectData(IJsonWriteData)

Writes the data of this base class (user data, layer, style, user attributes and actuator) for the JSON serialization (IJsonSerialize). Derived classes override it, call the base implementation and add their own properties.

public override void GetObjectData(IJsonWriteData data)

Parameters

data IJsonWriteData

receives the data

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 override void GetObjectData(SerializationInfo info, StreamingContext context)

Parameters

info SerializationInfo

receives the data

context StreamingContext

the destination of the serialization

GetPlanarState()

Determins the state of the curve in space. A curve may be either Planar (e.g. a cicle), NonPlanar (e.g. a polyline with vertices that dont shear a common plane) or UnderDetermined (e.g. a line defines a sheaf of planes (Ebenenbüschel))

public PlanarState GetPlanarState()

Returns

PlanarState

GetPlane()

Determins the plane in which the curve resides. Throws CurveException if the curve's PlanarState is NonPlanar or UnderDetermined.

public Plane GetPlane()

Returns

Plane

The plane

GetProjectedCurve(Plane)

Orthogonally projects this curve into the given plane. Returns the 2D curve in the coordinate system of the given plane.

public ICurve2D GetProjectedCurve(Plane p)

Parameters

p Plane

The plane this curve will be projected on

Returns

ICurve2D

The 2D curve in the given plane

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

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

IndexAtLength(double)

Returns the index of the subcurve at the given position. Position must be between 0.0 and this.Length

public int IndexAtLength(double position)

Parameters

position double

Position for the query

Returns

int

Index of the curve

InsertPoint(double)

Splits the curve of this path that contains the provided position. If position is exactely on the connection of two subcurves, the path remains unchanged. Otherwise the curve containing the position is split and both curves are added to the path

public void InsertPoint(double position)

Parameters

position double

Where to split, must be inbetween 0 and 1

IsInPlane(Plane)

Determines whether the curve resides in the given plane.

public bool IsInPlane(Plane p)

Parameters

p Plane

The plane for the test

Returns

bool

true, when the curve resides in the plane

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

PointAndDerivativesAt(double, int)

Returns all derivatives up to grad. The first vector is actually the point at this position.

public IReadOnlyList<GeoVector> PointAndDerivativesAt(double position, int grad)

Parameters

position double

Where to calculate the derivatives

grad int

Number of derivatives. grad==2 returns the point, the first and the second derivative

Returns

IReadOnlyList<GeoVector>

Sequence of derivatives: element 0 = point-vector (P), 1 = first derivative (P'), 2 = second (P''), … . Length ≥ grad+1.

PointAt(double)

Returns the point of the given position. The parameter position of the start-point is 0.0, the parameter position of the endpoint is 1.0. Points of a position outside this interval may be undefined. The correlation between the parameter Position and the resulting point may be not linear.

public GeoPoint PointAt(double Position)

Parameters

Position double

Position on the curve

Returns

GeoPoint

The requested point

Position(GeoPoint, GeoVector, double)

Computes the parameter value along the given ray (fromHere + t * direction) where it intersects the path (if any). Returns double.MaxValue if no intersection is found or if the path is parallel to the ray direction.

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

Parameters

fromHere GeoPoint

Start point of the ray.

direction GeoVector

Direction of the ray.

precision double

Tolerance for intersection tests (used in sub-curves).

Returns

double

The parameter t where the intersection occurs, or double.MaxValue if no hit.

PositionOf(GeoPoint)

Returns the parametric position of the point on the curve. This function is inverse to DirectionAt(double). If the given point is not on the curve, the result is the position of a point on the curve, that is close to the given point, but not necessary of the closest point.

public double PositionOf(GeoPoint p)

Parameters

p GeoPoint

Point, for which the position is requested

Returns

double

the requested position

PositionOf(GeoPoint, Plane)

Similar to the PointAt(double) method. Returns the same result, if the point is on the curve. If the point is not on the curve the problem is looked at in the given plane. i.e. the closest point on the projected 2d curve from the projected 2d point is used.

public double PositionOf(GeoPoint p, Plane pl)

Parameters

p GeoPoint

Point, whos position is requested

pl Plane

Plane for the computation of the closest point

Returns

double

the requested position

PositionOf(GeoPoint, double)

Similar to PositionOf(GeoPoint). If the point is not on the curve and there are several solutions then the solution closest to the parameter prefer will be returned.

public double PositionOf(GeoPoint p, double prefer)

Parameters

p GeoPoint

Point, for which the position is requested

prefer double

preferable solution close to this value

Returns

double

the requested position

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

Remove(ICurve)

Removes a curve from this path and sets the remaining curves again with Set(ICurve[]). When a curve in the middle is removed, the resulting gap is closed by moving the end point of the previous curve to the start point of the next one (or the other way round if that fails). The change is undoable and raises the change events.

public bool Remove(ICurve toRemove)

Parameters

toRemove ICurve

The curve to remove, one of Curves

Returns

bool

true on success, false when the curve is not part of this path

RemoveShortSegments(double)

Removes all segments that are shorter than maxLengthToRemove. Connects the ramaining segments.

public void RemoveShortSegments(double maxLengthToRemove)

Parameters

maxLengthToRemove double

Max. length of subcurves to remove

SerializationDone(JsonSerialize)

Called by the JSON deserialization when all objects have been read: makes this path the owner of its curves and connects their change events, so that the path notices when a curve is modified.

public void SerializationDone(JsonSerialize jsonSerialize)

Parameters

jsonSerialize JsonSerialize

The serializer that read the objects

Set(GeoObjectList, bool, double)

Takes a list of unsorted and unoriented geoobjects and tries to put them together to a connected path. All previously contained segments are removed. All objects of the list, that are used in this path will be removed from their owner (see Owner). To avoid objects bee removed from their owner (e.g. Model or Block) use a list of cloned GeoObjects (CloneObjects()).

public bool Set(GeoObjectList l, bool moreThanOne, double maxgap)

Parameters

l GeoObjectList

List of unsorted GeoObjects

moreThanOne bool

if true, the path must consist of more than one curve

maxgap double

maximum distance between the end point of the path and the start or end point of the next curve for them to count as connected

Returns

bool

success

Set(ICurve[])

Makes this path represent the given list if all objects in that list are properly oriented and connected. If the objects do not connect, false will be returned and this path remains unchanged.

public bool Set(ICurve[] connectedCurves)

Parameters

connectedCurves ICurve[]

new contents of this path

Returns

bool

true on success, false on failure

SetObjectData(IJsonReadData)

Reads the data written by GetObjectData(IJsonWriteData) back from the JSON serialization. Derived classes override it, call the base implementation and read their own properties. Objects referenced by the data may still be incomplete at this time, see IJsonSerializeDone.

public override void SetObjectData(IJsonReadData data)

Parameters

data IJsonReadData

provides the data

SetPoint(int, GeoPoint, ModificationMode)

Moves a vertex of the path, i.e. the point where the curve index-1 ends and the curve index starts, and adapts both curves: each of them is transformed (moved, rotated and scaled) so that its other end stays fixed and the connection follows the new point; a circular arc becomes an elliptical arc this way. If that transformation cannot be computed, only the end point and the start point of the two curves are set. Index 0 of an open path moves the start point of the first curve only, index CurveCount or -1 the end point of the last curve only. If the path would become inconsistent (the curves no longer connect), the change is reverted. The change is undoable and raises the change events.

public void SetPoint(int index, GeoPoint newValue, Path.ModificationMode mode)

Parameters

index int

Index of the vertex, which is the index of the curve that starts there; -1 or CurveCount for the end point of the last curve

newValue GeoPoint

New position of the vertex

mode Path.ModificationMode

Intended to select how the curves are adapted; not evaluated by the current implementation

SetPoint(int, int, GeoPoint)

Sets the end point of the curve indexEndPoint and the start point of the curve indexStartPoint to the same point in one step, so that the path stays consistent. Normally indexStartPoint is indexEndPoint+1; pass -1 for one of them at the beginning or the end of an open path. Each curve adapts itself as its StartPoint or EndPoint setter does (a line is just shortened or lengthened, an arc changes its sweep). The change is undoable and raises the change events.

public void SetPoint(int indexEndPoint, int indexStartPoint, GeoPoint newValue)

Parameters

indexEndPoint int

Index of the curve whose end point is set, or -1 for none

indexStartPoint int

Index of the curve whose start point is set, or -1 for none

newValue GeoPoint

The new common point

Split(double)

Splits the curve at the given position. The position must be in the interval 0..1 and the curve must not be closed. For closed curves Split(double, double).

public ICurve[] Split(double Position)

Parameters

Position double

Where to split

Returns

ICurve[]

the splitted curve(s)

Split(double, double)

Splits the closed curve into two open curves at the given positions.

public ICurve[] Split(double Position1, double Position2)

Parameters

Position1 double

first Position

Position2 double

second Position

Returns

ICurve[]

the splitted curve(s)

Trim(double, double)

Modifies start and endpoint of this curve. StartPos must be less than EndPos. if StartPos is less than 0.0 or EndPos greater than 1.0 this only works for lines and (circular or elliptical) arcs.

public void Trim(double StartPos, double EndPos)

Parameters

StartPos double

New start position

EndPos double

New end position

TryPointDeriv2At(double, out GeoPoint, out GeoVector, out GeoVector)

Tries to get the point and the first and second derivative of the curve at the specified position. (0..1) Some curves do not implement the second derivative and hence will return false.

public virtual bool TryPointDeriv2At(double position, out GeoPoint point, out GeoVector deriv, out GeoVector deriv2)

Parameters

position double

Position where to calculate point and derivatives

point GeoPoint

The point at the required position

deriv GeoVector
deriv2 GeoVector

The second derivative at the provided parameter

Returns

bool

Events

Constructed

Raised whenever a new path is created, i.e. for every Construct() call, every clone and every path read from a file. The handler gets the new object; when it comes from Construct(), it contains no curves yet.

public static event Path.ConstructedDelegate Constructed

Event Type

Path.ConstructedDelegate