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
infoSerializationInfoSerializationInfo
contextStreamingContextStreamingContext
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
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
PixelHeight
The height of the image in pixels, read from the header of ImageData; 0 without an image.
public int PixelHeight { get; }
Property Value
PixelWidth
The width of the image in pixels, read from the header of ImageData; 0 without an image.
public int PixelWidth { get; }
Property Value
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
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
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
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
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
imageDatabyte[]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.
locationGeoPointPosition where the icon will be displayed
offsetxintX-Position in the icon where location is applied
offsetyintY-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
bitmapBitmapThe icon to be displayed
locationGeoPointPosition where the icon will be displayed
offsetxintX-Position in the icon where location is applied
offsetyintY-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