Table of Contents

Class Block

Namespace
CADability.GeoObject
Assembly
CADability.dll

A block as a geometric object: a collection of several IGeoObjects which is handled as a single object. The block owns its children (it is their IGeoObjectOwner); cloning the block creates copies of the children. A block has a reference point (RefPoint), which serves as the base point when the block is placed or moved, and may carry a name. Modifying the block modifies all contained objects.

public class Block : IGeoObjectImpl, IGeoObject, ILayer, IStyle, IOctTreeInsertable, IComparable, IFeedBack, ICloneable, IColorDef, ISerializable, IGeoObjectOwner, IDeserializationCallback, IExportStep, IJsonSerialize, IJsonSerializeDone
Inheritance
Block
Implements
Derived
Inherited Members

Constructors

Block()

Creates an empty block. Protected so that blocks are created via Construct(); derived classes call it from their own constructors.

protected Block()

Block(SerializationInfo, StreamingContext)

Constructor required by deserialization

protected Block(SerializationInfo info, StreamingContext context)

Parameters

info SerializationInfo

SerializationInfo

context StreamingContext

StreamingContext

Fields

Constructor

Optional factory for blocks: when set, Construct() calls this delegate instead of creating a plain Block, so that every block CADability creates (when importing a file, grouping objects etc.) is an instance of your derived class. Null by default.

public static Block.ConstructionDelegate Constructor

Field Value

Block.ConstructionDelegate

OnPaintTo3D

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

public static Block.PaintTo3DDelegate OnPaintTo3D

Field Value

Block.PaintTo3DDelegate

containedObjects

The objects contained in this block, in drawing order. This is the internal state of the block: derived classes such as Hatch may read and modify it directly, everyone else uses Add(IGeoObject), Remove(int), Item(int) and Children, which keep the owner and the change events of the objects consistent.

protected GeoObjectList containedObjects

Field Value

GeoObjectList

Properties

Children

Yields a copy of the list of contained geoobjects. Removing objects from that list doesn't remove the objects from the Block.

public GeoObjectList Children { get; }

Property Value

GeoObjectList

ColorDef

The color of the block. Contained objects whose color is "from parent" (fromParent) are displayed in this color and follow it when it changes; objects with a color of their own are not affected. May be null, the objects "from parent" are then displayed in the default color. Setting it raises the change events and is undoable.

public virtual ColorDef ColorDef { get; set; }

Property Value

ColorDef

Count

Gets the number of GeoObjects in the Block

public int Count { get; }

Property Value

int

Description

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

public override string Description { get; }

Property Value

string

IsTmpContainer

Marks the block as a temporary container, e.g. the block in which a construction action collects the objects it is about to create in order to display them. In a temporary container the attributes of the block (Layer, ColorDef, Style) are copied to the contained objects whenever they are set, so that the objects carry these attributes when they are taken out of the block later. Setting it to true copies the attributes immediately. False by default; not saved with the block.

public bool IsTmpContainer { get; set; }

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

Name

The name of the block, e.g. the name of the product or assembly when the block stems from a STEP import, or the name of the block definition when it stems from a DXF file. It is written as the product name on STEP export. May be null. Setting it raises the change events and is undoable; it is an attribute change, the geometry is not affected.

public string Name { get; set; }

Property Value

string

NumChildren

Overrides NumChildren. The default implementation returns 0.

public override int NumChildren { get; }

Property Value

int

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

IGeoObject[]

Owner

Overrides Owner: when the block is added to or removed from a model, it and its nested blocks subscribe to or unsubscribe from the change event of their color, see CADability.GeoObject.Block.subscribedColorDef.

public override IGeoObjectOwner Owner { get; set; }

Property Value

IGeoObjectOwner

RefPoint

The reference point of the block in world coordinates: the base point that is used when the block is placed or inserted via a BlockRef. Modify(ModOp) transforms it together with the contained objects. Setting it only moves the reference point, not the contained objects; the change raises the change events and is undoable.

public GeoPoint RefPoint { get; set; }

Property Value

GeoPoint

Style

Fully implements Style. Stores the style in a private member. Setting raises the WillChangeEvent and DidChangeEvent.

public override Style Style { get; set; }

Property Value

Style

Methods

Add(GeoObjectList)

Appends all objects of the given list to the block as a single undoable change, otherwise like Add(IGeoObject) for each object. Unlike the single object overload this method does not remove the objects from a previous owner, so pass objects that have no owner yet.

public virtual void Add(GeoObjectList ToAdd)

Parameters

ToAdd GeoObjectList

The objects to add

Add(IGeoObject)

Appends an object to the block and makes the block its Owner. If the object currently belongs to another owner (a Model or another block) it is removed from there first. An object whose color is "from parent" is displayed in the color of this block from now on, and changes of the object are forwarded as changes of the block. The change raises the change events and is undoable.

public virtual void Add(IGeoObject ToAdd)

Parameters

ToAdd IGeoObject

The object to add

Child(int)

Overrides Child(int). The default implementation throws a GeoObjectException NoChildren.

public override IGeoObject Child(int Index)

Parameters

Index int

Returns

IGeoObject

Clear()

Removes all objects from that block and returns those objects in a new list. The returned objects have no Owner.

public GeoObjectList Clear()

Returns

GeoObjectList

a list with all the objects of this block

Clone()

Overrides Clone(). Returns a new Block, that contains clones of the children of this Block. An IGeoObject cannot be contained by two different block objects, because there may be only one owner (see also Owner).

public override IGeoObject Clone()

Returns

IGeoObject

Construct()

Creates a new, empty block. This is the only public way to create a block, the constructor is protected. If a Constructor is registered, the block is created by that delegate, otherwise a plain Block is returned. Fill it with Add(IGeoObject), Add(GeoObjectList) or Set(GeoObjectList).

public static Block Construct()

Returns

Block

The new block, which contains no objects yet

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

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

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)

Need to make it public in order to allow inheriting classes to acces this method via base.GetObjectData

public override void GetObjectData(IJsonWriteData data)

Parameters

data IJsonWriteData

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

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

HasChildren()

Overrides HasChildren(). The deafult implementation returns false.

public override bool HasChildren()

Returns

bool

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

Insert(int, IGeoObject)

Inserts an object at the given position in the drawing order of the block. Apart from the position this behaves like Add(IGeoObject): the object is removed from a previous owner and becomes owned by this block, the change raises the change events and is undoable.

public virtual void Insert(int index, IGeoObject ToAdd)

Parameters

index int

Position at which the object is inserted, 0 <= index <= Count

ToAdd IGeoObject

The object to insert

Item(int)

Returns the contained object at the given position in the drawing order.

public IGeoObject Item(int Index)

Parameters

Index int

Position of the object, 0 <= Index < Count

Returns

IGeoObject

The object itself (not a copy); it still belongs to the block

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

OnDeserialization(object)

Implements OnDeserialization(object) for the legacy binary format: after the whole object graph has been read, the block registers itself as owner of its contained objects, subscribes to their change events and reconnects the colors "from parent". Called by the deserialization, not meant to be called by user code.

public virtual void OnDeserialization(object sender)

Parameters

sender object

Not used

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

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

paintTo3D IPaintTo3D

the paint interface of the view

lists ICategorizedDislayLists

the 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

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

Remove(GeoObjectList)

Removes all objects of the given list from the block, see Remove(int). Objects that are not contained in this block are ignored. The change raises the change events and is undoable as a single step.

public virtual void Remove(GeoObjectList ToRemove)

Parameters

ToRemove GeoObjectList

The objects to remove

Remove(int)

Removes the object at the given position from the block. The object loses its owner and is no longer displayed with the block; an object whose color is "from parent" no longer follows the color of this block. The change raises the change events and is undoable.

public virtual void Remove(int Index)

Parameters

Index int

Position of the object to remove, 0 <= Index < Count

ReplaceContent(GeoObjectList)

Replace the list of child objects without fireing a chang event. This is used by derived classes (e.g. Hatch or Dimension or user derived classes to recalculate their contents. The derived classes already have fired the change event.

protected void ReplaceContent(GeoObjectList NewContent)

Parameters

NewContent GeoObjectList

List of child objects to replace the existing list

SerializationDone(JsonSerialize)

Implements SerializationDone(JsonSerialize). After reading from JSON the contained objects are completed first, then the block registers itself as their owner, subscribes to their change events and reconnects the colors "from parent". When writing there is nothing to do. Called by the serialization, not meant to be called by user code.

public virtual void SerializationDone(JsonSerialize jsonSerialize)

Parameters

jsonSerialize JsonSerialize

The serializer; IsWriting tells the direction

Set(GeoObjectList)

Replaces the contents of the block by the objects of the given list. The objects contained so far lose their owner, the new objects become owned by this block. The objects are not cloned, so pass copies if the originals are still in use elsewhere. The change raises the change events and is undoable.

public virtual void Set(GeoObjectList toSet)

Parameters

toSet GeoObjectList

The new contents of the block

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