Class Picture
- Namespace
- CADability.GeoObject
- Assembly
- CADability.dll
A bitmap as a rectangular or rhombiod face in 3D space. This object is mainly used for illustration or as a background in a model. It is a GeoObject and may be part of a model. It is defined by the image and the location in space. The image is kept as the bytes of a PNG, JPEG, GIF or BMP file (ImageData), which is also what project files contain; the kernel does not decode it (issue #412).
public class Picture : IGeoObjectImpl, IGeoObject, ILayer, IStyle, IOctTreeInsertable, IComparable, IFeedBack, ICloneable, ISerializable
- Inheritance
-
Picture
- Implements
- Inherited Members
Constructors
Picture()
Protected constructor: raises Constructed. Use Construct() to create a picture and Set(byte[], GeoPoint, GeoVector, GeoVector) to define it.
protected Picture()
Picture(SerializationInfo, StreamingContext)
Constructor required by deserialization
protected Picture(SerializationInfo info, StreamingContext context)
Parameters
infoSerializationInfoSerializationInfo
contextStreamingContextStreamingContext
Fields
Constructor
Provide a delegate here if you want you Picture derived class to be created each time CADability creates a Picture.
public static Picture.ConstructionDelegate Constructor
Field Value
Properties
Bitmap
The bitmap, the contents of the Picture, decoded from ImageData with GDI+. Setting it encodes the bitmap into ImageData. Needs GDI+, i.e. Windows.
[Obsolete("Use ImageData, the bytes of the image file. A GDI+ Bitmap only works on Windows (issue #412).")]
public Bitmap Bitmap { get; set; }
Property Value
DirectionHeight
The location of the left side of the bitmap
public GeoVector DirectionHeight { get; set; }
Property Value
DirectionWidth
The location of the lower baseline of the bitmap
public GeoVector DirectionWidth { get; set; }
Property Value
ImageData
The image of the picture as the bytes of a PNG, JPEG, GIF or BMP file, null if the picture has no image. This is what project files contain. The array must not be changed; set a new array instead. Setting it raises the change events and is undoable.
public byte[] ImageData { get; set; }
Property Value
- byte[]
Exceptions
- ArgumentException
The data is not a PNG, JPEG, GIF or BMP file
Location
Position of the lower left point of the bitmap
public GeoPoint Location { get; set; }
Property Value
Path
The path where the image file is located. This value is not used by the Picture object and may have any content. Usually it is the path and filename, especially when the object is being generated interactively by CADability's user interface. Setting the value does NOT load the specified image. This must be done separately by setting the ImageData property. When an old project file has a picture whose image cannot be read, the picture is loaded from this path, if the file exists.
public string Path { 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
PreferredStyle
Returns the preferred style for this objects, see Style.EDefaultFor.
public override Style.EDefaultFor PreferredStyle { get; }
Property Value
Methods
Clip(Plane, CompoundShape)
Clips the bitmap according to the provided shape and plane. The BitmapBits are replaced by transparent pixels, the original bits are lost. Setting another clip area doesn't restore already clipped pixels. (Of course undo restores the original bitmap bits)
public void Clip(Plane plane, CompoundShape shape)
Parameters
planePlaneThe plane as a reference system for the shape
shapeCompoundShapeThe shape for the clip operation
Remarks
Needs GDI+, i.e. Windows. The clipped image is stored as PNG.
Clone()
Clones this GeoObject.
public override IGeoObject Clone()
Returns
- IGeoObject
the cloned GeoObject
Construct()
The only way to create a Picture. There are no public constructors for the Picture to assure that this is the only way to construct a Picture.
public static Picture 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
toCopyFromIGeoObject
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. The base implementation saves UserData, Layer and Style; a derived class saves its own data and calls the base implementation.
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
Set(byte[], GeoPoint, GeoVector, GeoVector)
Sets the image and the position of the picture.
public void Set(byte[] imageData, GeoPoint location, GeoVector directionWidth, GeoVector directionHeight)
Parameters
imageDatabyte[]The bytes of a PNG, JPEG, GIF or BMP file, e.g. from ReadAllBytes(string); null for no image. The array is kept, so it must not be changed afterwards.
locationGeoPointPosition where the lower left point of the image will be displayed
directionWidthGeoVectorVector specifying the baseline of the image
directionHeightGeoVectorVector specifying the left side of the image
Exceptions
- ArgumentException
The data is not a PNG, JPEG, GIF or BMP file
Set(Bitmap, GeoPoint, GeoVector, GeoVector)
Sets the Data of the Bitmap. 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, GeoVector, GeoVector) with the bytes of the image file. A GDI+ Bitmap only works on Windows (issue #412).")]
public void Set(Bitmap bitmap, GeoPoint location, GeoVector directionWidth, GeoVector directionHeight)
Parameters
bitmapBitmapThe bitmap to be displayed
locationGeoPointPosition where the lower left point of the bitmap will be displayed
directionWidthGeoVectorVector specifying the baseline of the bitmap
directionHeightGeoVectorVector specifying the left side of the bitmap
SetBitmapNoUndo(Bitmap)
Replaces the bitmap without raising the change events and without an undo step, in contrast to setting Bitmap. For callers that record the undo themselves. Not used within CADability.
[Obsolete("Use SetImageDataNoUndo with the bytes of the image file. A GDI+ Bitmap only works on Windows (issue #412).")]
public void SetBitmapNoUndo(Bitmap bmp)
Parameters
bmpBitmapthe new bitmap
SetHeight(double, bool)
Sets the height of the picture, i.e. the length of DirectionHeight, to l (in
world units), keeping its direction. With keepAspectRatio the width is adjusted as well, so
that the picture keeps the aspect ratio of the bitmap's pixels. A value of 0 is ignored. Raises the change events
and is undoable.
public void SetHeight(double l, bool keepAspectRatio)
Parameters
ldoublethe new height
keepAspectRatiobooltrue to also set the width according to the aspect ratio of the bitmap
SetImageDataNoUndo(byte[])
Replaces the image without raising the change events and without an undo step, in contrast to setting ImageData. For callers that record the undo themselves.
public void SetImageDataNoUndo(byte[] imageData)
Parameters
imageDatabyte[]the bytes of a PNG, JPEG, GIF or BMP file, or null
Exceptions
- ArgumentException
The data is not a PNG, JPEG, GIF or BMP file
SetWidth(double, bool)
Sets the width of the picture, i.e. the length of DirectionWidth, to l (in
world units), keeping its direction. With keepAspectRatio the height is adjusted as well, so
that the picture keeps the aspect ratio of the bitmap's pixels. A value of 0 is ignored. Raises the change events
and is undoable.
public void SetWidth(double l, bool keepAspectRatio)
Parameters
ldoublethe new width
keepAspectRatiobooltrue to also set the height according to the aspect ratio of the bitmap
Events
Constructed
Event being raised when a Picture object has been created.
public static event Picture.ConstructedDelegate Constructed