Class Line
- Namespace
- CADability.GeoObject
- Assembly
- CADability.dll
The line is a IGeoObject. It is actually a line segment not an infinite line.
public class Line : IGeoObjectImpl, IFeedBack, ICloneable, IColorDef, ILineWidth, ILinePattern, ISerializable, ICurve, IGeoObject, ILayer, IStyle, IOctTreeInsertable, IComparable, IExtentedableCurve, IExplicitPCurve3D, IJsonSerialize, IExportStep
- Inheritance
-
Line
- Implements
- Derived
- Inherited Members
Constructors
Line()
Empty protected constructor.
protected Line()
Line(SerializationInfo, StreamingContext)
Constructor required by deserialization
protected Line(SerializationInfo info, StreamingContext context)
Parameters
infoSerializationInfoSerializationInfo
contextStreamingContextStreamingContext
Fields
Constructor
Provide a delegate here if you want you Line derived class to be created each time CADability creates a line.
public static Line.ConstructionDelegate Constructor
Field Value
OnPaintTo3D
Hook to replace the painting of lines: when set, PaintTo3D(IPaintTo3D) calls it first and does nothing more when it returns true. The hook is static, so it applies to every line of the process.
public static Line.PaintTo3DDelegate OnPaintTo3D
Field Value
Properties
ColorDef
The color of the line, see ColorDef. Setting it raises the change events as a change of an attribute and is undoable. A color with fromParent is replaced by the corresponding color of the Block the line belongs to.
public ColorDef ColorDef { get; set; }
Property Value
Description
Returns a textual description of the GeoObject. Mainly used for debugging purposes
public override string Description { get; }
Property Value
EndDirection
The direction from the start point to the end point, the same as StartDirection.
public GeoVector EndDirection { get; }
Property Value
EndPoint
Sets or gets the endpoint of the line. Setting the endpoint causes the line to fire the WillChangeEvent and the DidChangeEvent.
public virtual GeoPoint EndPoint { get; set; }
Property Value
IsClosed
Always false: a line is never closed.
public bool IsClosed { get; }
Property Value
IsSingular
True if start point and end point coincide within Precision, i.e. the line has no length and no direction. Such a line is not valid, see HasValidData().
public bool IsSingular { get; }
Property Value
Length
Gets or sets the length of the line. Setting the length modifies the endpoint and keeps the startpoint and causes the line to fire the WillChangeEvent and the DidChangeEvent.
public double Length { get; set; }
Property Value
LengthFixPoint
do not use, used only internaly.
public GeoPoint LengthFixPoint { get; }
Property Value
LinePattern
The line pattern attribute of the line, see LinePattern; null means a solid line. Setting it raises the change events as a change of an attribute and is undoable.
public LinePattern LinePattern { get; set; }
Property Value
LineWidth
The line width attribute of the line, see LineWidth; null means the default width. Setting it raises the change events as a change of an attribute and is undoable.
public LineWidth LineWidth { get; set; }
Property Value
PreferredStyle
Returns the preferred style for this objects, see Style.EDefaultFor.
public override Style.EDefaultFor PreferredStyle { get; }
Property Value
StartDirection
The direction from the start point to the end point. Its length is the length of the line, and it is the same for every point of the line.
public GeoVector StartDirection { get; }
Property Value
StartPoint
Sets or gets the startpoint of the line. Setting the startpoint causes the line to fire the WillChangeEvent and the DidChangeEvent.
public virtual GeoPoint StartPoint { get; set; }
Property Value
Methods
Clone()
public override IGeoObject Clone()
Returns
- IGeoObject
the clone
Construct()
The only way to create a line. There are no public constructors for the line to assure that this is the only way to construct a line.
public static Line Construct()
Returns
CopyGeometry(IGeoObject)
Overrides CopyGeometry(IGeoObject) and implements CopyGeometry(IGeoObject). Copies the start and endpoint of the given line. This method causes the line to fire the WillChangeEvent and the DidChangeEvent.
public override void CopyGeometry(IGeoObject ToCopyFrom)
Parameters
ToCopyFromIGeoObjectmust be a line, to copy data from
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
PositiondoublePosition 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
spfSnapPointFinderdefinition and collection of the snap points
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
projectionProjectionthe projection
extentPrecisionExtentPrecisionExact 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
precisiondoublePrecision 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
dataIJsonWriteDatareceives 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
infoSerializationInforeceives the data
contextStreamingContextthe 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
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
pPlaneThe 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
projectionProjectionthe projection
extentPrecisionExtentPrecisionprecision of the extent, see GetExtent(Projection, ExtentPrecision)
Returns
- IQuadTreeInsertableZ
the item for the quad tree
GetShowProperties(IFrame)
Returns the property entry (a ShowPropertyLine) that shows and edits this line, i.e. its start and end point, length and direction and its attributes, in the property grid.
public override IPropertyEntry GetShowProperties(IFrame Frame)
Parameters
FrameIFrame
Returns
HasValidData()
Default implementation of IGeoObject.HasValidData. Returns true. Override if the derived object can decide itself.
public override bool HasValidData()
Returns
- bool
true
HitTest(ref BoundingCube, double)
Tests whether an object is touched by the provided cube
public override bool HitTest(ref BoundingCube cube, double precision)
Parameters
cubeBoundingCubeTo test with
precisiondoubleRequired 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
projectionProjectionThe projection for the test
rectBoundingRectThe rectangle to test the position
onlyInsidebooltrue: 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
areaProjection.PickAreaThe area to check for
onlyInsidebooltrue: 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
IsInPlane(Plane)
Determines whether the curve resides in the given plane.
public bool IsInPlane(Plane p)
Parameters
pPlaneThe plane for the test
Returns
- bool
true, when the curve resides in the plane
MakeLine(GeoPoint, GeoPoint)
Creates a line from p1 to p2. Identical to TwoPoints(GeoPoint, GeoPoint).
public static Line MakeLine(GeoPoint p1, GeoPoint p2)
Parameters
Returns
- Line
the new line
Modify(ModOp)
Overrides Modify(ModOp) and implements Modify(ModOp).
public override void Modify(ModOp m)
Parameters
mModOpthe operator for the modification
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
paintTo3DIPaintTo3Dwhere to paint
PointAndDerivativesAt(double, int)
Implements PointAndDerivativesAt(double, int): all derivatives beyond the first one vanish.
public IReadOnlyList<GeoVector> PointAndDerivativesAt(double position, int grad)
Parameters
Returns
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
PositiondoublePosition on the curve
Returns
- GeoPoint
The requested point
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
fromHereGeoPointStartpoint of the line
directionGeoVectorDirection of the line
precisiondoublePrecision for the test
Returns
- double
Position on the line
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
pGeoPointPoint, 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
pGeoPointPoint, whos position is requested
plPlanePlane 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
pGeoPointPoint, for which the position is requested
preferdoublepreferable 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
precisiondoubleRequired precision
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
dataIJsonReadDataprovides the data
SetTwoPoints(GeoPoint, GeoPoint)
Sets the start and endpoint of the line. This method causes the line to fire the WillChangeEvent and the DidChangeEvent.
public void SetTwoPoints(GeoPoint startPoint, GeoPoint endPoint)
Parameters
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
PositiondoubleWhere 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
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
TwoPoints(GeoPoint, GeoPoint)
Creates a line from sp to ep. The line is created with Construct(),
so a registered Constructor is honored. Same as MakeLine(GeoPoint, GeoPoint).
public static Line TwoPoints(GeoPoint sp, GeoPoint ep)
Parameters
Returns
- Line
the new line
Events
Constructed
Raised from the constructor whenever a line is created, be it by Construct(), by cloning or by deserialization, before its geometry is set. An application can use it to attach data of its own to every line.
public static event Line.ConstructedDelegate Constructed