Class BlockRef
- Namespace
- CADability.GeoObject
- Assembly
- CADability.dll
A reference to a Block that is placed in the model with a modification (Insertion), comparable to a block insert in DXF. The referenced block is shared and not owned by the reference, so several references may show the same block at different positions. For display, hit testing, extent and Decompose() the reference lazily creates a flattened copy of the block transformed by the insertion, which is discarded whenever the block or the insertion changes.
public class BlockRef : IGeoObjectImpl, IGeoObject, ILayer, IStyle, IOctTreeInsertable, IComparable, ISerializable, IFeedBack, ICloneable, IColorDef, IGeoObjectOwner
- Inheritance
-
BlockRef
- Implements
- Inherited Members
Constructors
BlockRef(Block)
Creates a reference to the given block with the identity as insertion. Protected so that references are created via Construct(Block); derived classes call it from their own constructors.
protected BlockRef(Block referredBlock)
Parameters
referredBlockBlockThe block to refer to
BlockRef(SerializationInfo, StreamingContext)
Constructor required by deserialization
protected BlockRef(SerializationInfo info, StreamingContext context)
Parameters
infoSerializationInfoSerializationInfo
contextStreamingContextStreamingContext
Fields
Constructor
Optional factory for block references: when set, Construct(Block) calls this delegate instead of creating a plain BlockRef, so that every reference CADability creates is an instance of your derived class. Null by default.
public static BlockRef.ConstructionDelegate Constructor
Field Value
OnPaintTo3D
Hook to replace the painting of block references: when set, PaintTo3D(IPaintTo3D) calls this delegate first and does nothing more if it returns true. Applies to all block references. Null by default.
public static BlockRef.PaintTo3DDelegate OnPaintTo3D
Field Value
Properties
ColorDef
The color of the reference. It is given to those objects of the displayed block that have no color of their own or whose color is "from parent" (see Flattened); objects with a color of their own keep it. May be null. Setting it raises the change events and is undoable.
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
Flattened
Returns a new Block with the Insertion applied and also the ByBlock colors and layers applied Usually the result is only used temporarily.
public Block Flattened { get; }
Property Value
Insertion
The modification (translation, rotation, scaling ...) that places the referenced block in the model: the reference displays the block as it is defined, transformed by this operation. It is the identity after Construct(Block), and Modify(ModOp) prepends its operation. Setting it discards the cached flattened block, raises the change events and is undoable.
public ModOp Insertion { get; set; }
Property Value
RefPoint
The position of the reference point of the referenced block (RefPoint) in the model, i.e. that point transformed by Insertion. Setting it translates the reference so that the reference point comes to lie at the given point; this changes Insertion, raises the change events and is undoable.
public GeoPoint RefPoint { get; set; }
Property Value
ReferencedBlock
The block definition this reference displays. The block is shared with other references and is not owned by the reference, so modifying it changes all references. Setting it subscribes the reference to the change events of the new block (changes of the block discard the cached flattened copy), raises the change events and is undoable.
public Block ReferencedBlock { get; set; }
Property Value
Methods
Add(IGeoObject)
Implements Add(IGeoObject). Only sets the Owner of the given object to this reference, the object is not added to the referenced block. This is how the flattened copy of the block (see Flattened) is owned.
public void Add(IGeoObject toAdd)
Parameters
toAddIGeoObjectThe object to be owned by this reference
AttributeChanged(INamedAttribute)
Overrides AttributeChanged(INamedAttribute). Checks all CADability attributes. Checking your own attributes is left to your code.
public override bool AttributeChanged(INamedAttribute attribute)
Parameters
attributeINamedAttribute
Returns
Clone()
Clones this GeoObject.
public override IGeoObject Clone()
Returns
- IGeoObject
the cloned GeoObject
Construct(Block)
Creates a reference to the given block with the identity as Insertion, i.e. the block appears where it is defined; move it with Modify(ModOp), Insertion or RefPoint. This is the only public way to create a block reference. If a Constructor is registered, the reference is created by that delegate.
public static BlockRef Construct(Block referredBlock)
Parameters
referredBlockBlockThe block to refer to; it is shared with other references, not copied
Returns
- BlockRef
The new block reference
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
toCopyFromIGeoObject
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
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(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
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
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
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
paintTo3DIPaintTo3Dthe 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
precisiondoubleRequired precision
Remove(IGeoObject)
Implements Remove(IGeoObject). The reference owns only the temporary flattened copy of its block (see Flattened), so this merely clears the Owner of the given object. The referenced block is not changed.
public void Remove(IGeoObject toRemove)
Parameters
toRemoveIGeoObjectThe object that is no longer owned by this reference