Class Solid
- Namespace
- CADability.GeoObject
- Assembly
- CADability.dll
A Solid is a IGeoObject implementation that represents a solid body. Its main data is a collection of oriented faces. The normal vector on any point of the face points to the outside of the body. Solids have one set of faces that represent the outer hull and any number of cavities that reside totally inside the outer hull. All cavyties are disjoint.
public class Solid : IGeoObjectImpl, IGeoObject, ILayer, IStyle, IOctTreeInsertable, IComparable, IFeedBack, ICloneable, ISerializable, IColorDef, IGeoObjectOwner, IDeserializationCallback, IJsonSerialize, IJsonSerializeDone, IExportStep
- Inheritance
-
Solid
- Implements
- Inherited Members
Constructors
Solid()
Creates an empty solid without shells. Not for direct use: call Construct(), which honours Constructor, and set the shell afterwards.
protected Solid()
Solid(SerializationInfo, StreamingContext)
Constructor required by deserialization
protected Solid(SerializationInfo info, StreamingContext context)
Parameters
infoSerializationInfoSerializationInfo
contextStreamingContextStreamingContext
Fields
Constructed
When set, this delegate is called at the end of the Solid constructor for every new solid, e.g. to attach user data to it.
public static Solid.ConstructedDelegate Constructed
Field Value
Constructor
When set, Construct() calls this delegate instead of creating a Solid, so that an application can substitute a derived class for every solid CADability creates (also when reading files).
public static Solid.ConstructionDelegate Constructor
Field Value
OnPaintTo3D
Static hook called at the beginning of PaintTo3D(IPaintTo3D) for every solid. Set it to replace or extend the way solids are displayed; when the handler returns true, the default painting of the shells is skipped. Null by default.
public static Solid.PaintTo3DDelegate OnPaintTo3D
Field Value
Properties
ColorDef
The color of this solid. Setting it sets the same color on all shells of the solid (and hence on their faces); the change is undoable and raises the change events.
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
Edges
Returns all the edges of all shells of this solid. Each edge is unique in the array but may belong to two different faces.
public Edge[] Edges { get; }
Property Value
- Edge[]
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
Name
The name of the solid.
public string Name { get; set; }
Property Value
NameOrEmpty
The Name of the solid, or an empty string when it has none.
public string NameOrEmpty { get; }
Property Value
OwnedItems
Returns an array of objects owned by this object. E.g. a face is owned by a shell.
public override IGeoObject[] OwnedItems { get; }
Property Value
PreferredStyle
Returns the preferred style for this objects, see Style.EDefaultFor.
public override Style.EDefaultFor PreferredStyle { get; }
Property Value
Shell
The outer shell of the solid, i.e. Shells[0].
public Shell Shell { get; }
Property Value
Shells
Returns a list of all shells that bound this solid. In most cases there is only a single shell. If there is more than one shell the shell with index 0 is the outer hull and all subsequent shells describe cavyties that reside totally inside the outer hull.
public Shell[] Shells { get; }
Property Value
- Shell[]
Methods
Clone()
Clones this GeoObject.
public override IGeoObject Clone()
Returns
- IGeoObject
the cloned GeoObject
Construct()
Creates an empty solid, or an instance of the class Constructor provides. Set its shell with SetShell(Shell), or use MakeSolid(Shell), which does both.
public static Solid Construct()
Returns
- Solid
the new solid
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
ToCopyFromIGeoObjectGeoObject 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
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
FreeCachedMemory()
Forwards FreeCachedMemory() to all shells of this solid. Currently nothing is released.
public void FreeCachedMemory()
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
GetLineIntersection(GeoPoint, GeoVector)
Returns the points where the (infinite) line through location with the given direction crosses
the faces of this solid, in no particular order.
public GeoPoint[] GetLineIntersection(GeoPoint location, GeoVector direction)
Parameters
Returns
- GeoPoint[]
the intersection points, empty when the line misses the solid
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
GetPlaneIntersection(PlaneSurface)
Returns the curves that result from a planar intersection of this shell with the provided plane. The curves are properly clipped.
public ICurve[] GetPlaneIntersection(PlaneSurface pl)
Parameters
plPlaneSurfaceThe plane to intersect with
Returns
- ICurve[]
Array of intersection curves
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)
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
FrameIFrame
Returns
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
Intersect(Solid, Solid)
Returns the intersection of two solids, i.e. those parts that are common to both solids, as new solids; the operands are not modified. If the solids are disjunct or only touch, an empty array is returned. There may be more than one solid as a result. Only the outer shell of each solid takes part in the operation, cavities (further entries of Shells) are ignored. The result has no layer or colour, use SetDefaults(IGeoObject) or CopyAttributes(IGeoObject) to set them.
public static Solid[] Intersect(Solid solid1, Solid solid2)
Parameters
Returns
- Solid[]
array of common parts, empty when there are none
MakeSolid(Shell)
Creates a solid bound by the given closed shell (see SetShell(Shell)). The solid takes the colour of the shell. Shells come from the modelling methods in Make3D (e.g. SewFaces(Face[], bool)) or from the imports; check OpenEdges to make sure the shell is closed before making a solid of it.
public static Solid MakeSolid(Shell sh)
Parameters
shShellthe closed shell
Returns
- Solid
the solid
Modify(ModOp)
Modifies this GeoObject with the given modification operation (includes moving, rotating, reflecting, scaling etc.).
public override void Modify(ModOp m)
Parameters
mModOpOperation 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
paintTo3DIPaintTo3Dwhere to paint
PaintTo3DList(IPaintTo3D, ICategorizedDislayLists)
Adds this object as a whole to the display lists, in the category of its layer. Suitable for simple objects like curves and text; composite objects (solids, shells, blocks) override it and add their parts by category.
public override void PaintTo3DList(IPaintTo3D paintTo3D, ICategorizedDislayLists lists)
Parameters
paintTo3DIPaintTo3Dthe paint interface of the view
listsICategorizedDislayListsthe display lists to add to
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
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
RemoveShell(Shell)
Removes sh from this solid, if it is the outer shell (the first one): the solid is left without
shells and no longer listens to the change events of the shell. The change is undoable (it is the reverse of
SetShell(Shell)). Other shells are ignored.
protected void RemoveShell(Shell sh)
Parameters
shShellthe shell to remove
SameGeometry(Solid)
Returns true when the other solid has the same shells, faces and edges with the same geometry (within eps) as this solid. Attributes like layer and colour are not compared.
public bool SameGeometry(Solid other)
Parameters
otherSolidthe solid to compare with
Returns
- bool
true when the geometry is the same
SetFaces(Shell, Face[])
Replaces the faces of the shell sh, which must be one of the shells of this solid, so that the
change can be undone. Used by the modelling actions to apply the result of a boolean operation to the solid.
public void SetFaces(Shell sh, Face[] faces)
Parameters
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
SetShell(Shell)
Sets the (outer) shell of this solid, replacing all previous shells. The shell must be closed (no OpenEdges) and oriented outward to form a valid solid; this is not checked here. The solid becomes the owner of the shell.
public void SetShell(Shell sh)
Parameters
shShellthe shell that bounds the solid
SplitByPlane(Plane)
Splits the solid by a plane and returns the parts on both sides as new solids; this solid is not modified. A plane that does not cut the solid returns a single copy of it. Only the outer shell takes part, cavities are ignored.
public Solid[] SplitByPlane(Plane pln)
Parameters
plnPlanethe plane
Returns
- Solid[]
the parts of the solid
Subtract(Solid, Solid)
Returns the difference of two solids as new solids: the second solid is removed from the first solid; the operands are not modified. If the solids are disjunct, a copy of the first solid is returned. If the second solid lies inside the first one without touching it, the result is the first solid with the second one as a cavity (a second entry of Shells); if it touches the first one from inside, a copy of the first solid is returned, because a cavity must not touch the hull. If the second solid contains the first solid, an empty array is returned. Subtracting may split the first solid into several parts. Only the outer shell of each solid takes part in the operation, cavities (further entries of Shells) are ignored. The result has no layer or colour, use SetDefaults(IGeoObject) or CopyAttributes(IGeoObject) to set them.
public static Solid[] Subtract(Solid first, Solid second)
Parameters
Returns
- Solid[]
the difference, one or more solids, or an empty array
Unite(Solid, Solid)
Unites the two solids and returns the union as a new solid; the operands are not modified. If the solids are disjunct (they do not overlap, touch or intersect), null is returned. Only the outer shell of each solid takes part in the operation, cavities (further entries of Shells) are ignored. The result has no layer or colour, use SetDefaults(IGeoObject) or CopyAttributes(IGeoObject) to set them.
public static Solid Unite(Solid solid1, Solid solid2)
Parameters
Returns
- Solid
union or null
Volume(double)
Returns the volume of this solid. The calculation is based on a triangulation of the faces with the provided
precision (see GetTriangulation(double, out GeoPoint[], out GeoPoint2D[], out int[], out BoundingCube): the edges deviate by up to that value, the
triangles inside the faces by about five times that value). When a face cannot be triangulated that finely, a coarser
precision is used, see Volume(double).
public double Volume(double precision)
Parameters
precisiondoubleThe precision of the triangulation