Table of Contents

Class Icon

Namespace
CADability.GeoObject
Assembly
CADability.dll

A GeoObject that displays an icon at a given position. The icon will always face the viewer and will not be scaled. The icon appears with a small offset in direction to the viewer, so it will not be covered by a face with which it coincides. The image is kept as the bytes of a PNG, JPEG, GIF or BMP file (ImageData), which is also what project files contain (issue #412).

public class Icon : IGeoObjectImpl, IGeoObject, ILayer, IStyle, IOctTreeInsertable, IComparable, IFeedBack, ICloneable, ISerializable
Inheritance
Icon
Implements
Inherited Members

Constructors

Icon()

Protected constructor: raises Constructed. Use Construct() to create an icon and Set(byte[], GeoPoint, int, int) to define it.

protected Icon()

Icon(SerializationInfo, StreamingContext)

Constructor required by deserialization

protected Icon(SerializationInfo info, StreamingContext context)

Parameters

info SerializationInfo

SerializationInfo

context StreamingContext

StreamingContext

Fields

Constructor

Provide a delegate here if you want your Icon derived class to be created each time CADability creates an Icon.

public static Icon.ConstructionDelegate Constructor

Field Value

Icon.ConstructionDelegate

Properties

ImageData

The image of the icon as the bytes of a PNG, JPEG, GIF or BMP file, null if the icon has no image. The array must not be changed; use Set(byte[], GeoPoint, int, int) to replace it.

public byte[] ImageData { get; }

Property Value

byte[]

Location

The point in world coordinates at which the icon is displayed: the pixel of the bitmap given by the offsets in Set(byte[], GeoPoint, int, int) is placed at this point. Setting it raises the change events and is undoable.

public GeoPoint Location { get; set; }

Property Value

GeoPoint

PixelHeight

The height of the image in pixels, read from the header of ImageData; 0 without an image.

public int PixelHeight { get; }

Property Value

int

PixelWidth

The width of the image in pixels, read from the header of ImageData; 0 without an image.

public int PixelWidth { get; }

Property Value

int

Methods

Clone()

Clones this GeoObject.

public override IGeoObject Clone()

Returns

IGeoObject

the cloned GeoObject

Construct()

The only way to create an Icon. There are no public constructors for the Icon to assure that this is the only way to construct an Icon.

public static Icon Construct()

Returns

Icon

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

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

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

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

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

Set(byte[], GeoPoint, int, int)

Sets the image and the position of the icon.

public void Set(byte[] imageData, GeoPoint location, int offsetx, int offsety)

Parameters

imageData byte[]

The bytes of a PNG, JPEG, GIF or BMP file; null for no image. The array is kept, so it must not be changed afterwards.

location GeoPoint

Position where the icon will be displayed

offsetx int

X-Position in the icon where location is applied

offsety int

Y-Position in the icon where location is applied. (0,0) is lower left of the icon

Exceptions

ArgumentException

The data is not a PNG, JPEG, GIF or BMP file

Set(Bitmap, GeoPoint, int, int)

Sets the Data of the UnscaledIcon. The bitmap is encoded into ImageData: PNG, JPEG, GIF and BMP images keep their format, any other image becomes PNG. Needs GDI+, i.e. Windows.

[Obsolete("Use Set(byte[], GeoPoint, int, int) with the bytes of the image file. A GDI+ Bitmap only works on Windows (issue #412).")]
public void Set(Bitmap bitmap, GeoPoint location, int offsetx, int offsety)

Parameters

bitmap Bitmap

The icon to be displayed

location GeoPoint

Position where the icon will be displayed

offsetx int

X-Position in the icon where location is applied

offsety int

Y-Position in the icon where location is applied. (0,0) is lower left of the icon

Events

Constructed

Event being raised when an Icon object has been created.

public static event Icon.ConstructedDelegate Constructed

Event Type

Icon.ConstructedDelegate