Table of Contents

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

info SerializationInfo

SerializationInfo

context StreamingContext

StreamingContext

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

Picture.ConstructionDelegate

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

Bitmap

DirectionHeight

The location of the left side of the bitmap

public GeoVector DirectionHeight { get; set; }

Property Value

GeoVector

DirectionWidth

The location of the lower baseline of the bitmap

public GeoVector DirectionWidth { get; set; }

Property Value

GeoVector

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

GeoPoint

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

string

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

PreferredStyle

Returns the preferred style for this objects, see Style.EDefaultFor.

public override Style.EDefaultFor PreferredStyle { get; }

Property Value

Style.EDefaultFor

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

plane Plane

The plane as a reference system for the shape

shape CompoundShape

The 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

Picture

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

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(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

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

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, GeoVector, GeoVector)

Sets the image and the position of the picture.

public void Set(byte[] imageData, GeoPoint location, GeoVector directionWidth, GeoVector directionHeight)

Parameters

imageData byte[]

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.

location GeoPoint

Position where the lower left point of the image will be displayed

directionWidth GeoVector

Vector specifying the baseline of the image

directionHeight GeoVector

Vector 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

bitmap Bitmap

The bitmap to be displayed

location GeoPoint

Position where the lower left point of the bitmap will be displayed

directionWidth GeoVector

Vector specifying the baseline of the bitmap

directionHeight GeoVector

Vector 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

bmp Bitmap

the 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

l double

the new height

keepAspectRatio bool

true 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

imageData byte[]

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

l double

the new width

keepAspectRatio bool

true 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

Event Type

Picture.ConstructedDelegate