Entity
Namespace: Digi21.DigiNG.Entities
Assembly: Digi21.DigiNG
Abstract base class of all entities. Defines codes, colors, attributes, the drawing file to which each entity belongs, and minimum and maximum coordinates.
public abstract class Entity : IWindow3D, ICloneable
Implements: IWindow3D, ICloneable. The installed assembly also implements IDisposable; the reference package does not declare it.
Derived types: ReadOnlyLine, ReadOnlyPoint, ReadOnlyText, ReadOnlyPolygon and ReadOnlyComplex.
The class has no public constructors. Entities are created using the constructors of Line, Point, Text, Polygon and Complex, or read from a drawing file.
Read-only entities
An entity is read-only (ReadOnly is true) when it belongs to a drawing file: entities returned by the file during iteration and those added using Add. In a read-only entity, the set accessors of Color, Weight and FillColor, methods modifying Codes, and modifying members of derived classes throw InvalidOperationException. Hidden, Attributes and UserData can also be assigned on a read-only entity.
To modify a file's entity, modify the copy returned by Clone and add it to the file.
Minimum and maximum coordinates
The IWindow3D properties describe the box containing the entity's coordinates. A newly created entity has no box: Valid is false until the entity has coordinates. The Points collections of Line and Polygon update the box on each change. Assigning Coordinate in a Point or Text does not update the box.
While Valid is false:
Xminisnull, andYmin,Zmin,Xmax,YmaxandZmaxreturn empty-box values (double.MaxValuefor minima and-double.MaxValuefor maxima);Width,Height,Depth,Center,NW,N,NE,E,SE,S,SWandWthrowInvalidOperationException;- the
getaccessors ofColor,WeightandFillColorthrowInvalidOperationException.
Properties
| Property | Description |
|---|---|
IDictionary<string, object> Attributes { get; set; } |
Entity attributes: name and value. |
IList<Code> Codes { get; } |
Entity codes. |
int? Color { get; set; } |
Entity's own color, or null to use the code table's color. |
DateTime CreationTime { get; } |
Entity creation date and time. |
bool Deleted { get; } |
true if the entity is marked as deleted. |
string FilePointer { get; } |
Entity identifier in its drawing file. |
int? FillColor { get; set; } |
Own fill color, or null to use the code table's fill color. |
bool Hidden { get; set; } |
true to hide the entity. |
IDrawingFile Owner { get; } |
Drawing file to which the entity belongs, or null. |
bool ReadOnly { get; } |
true if Owner is not null. |
object UserData { get; set; } |
Programmer's object associated with the entity. |
bool Visible { get; } |
true if the entity is displayed in the drawing window. |
int? Weight { get; set; } |
Own line weight, or null to use the code table's line weight. |
double? Xmin { get; } |
Minimum X coordinate, or null if Valid is false. |
double Ymin { get; }, Zmin, Xmax, Ymax, Zmax |
Remaining minimum and maximum coordinates. The installed assembly also declares a set accessor on all six properties (including Xmin), which throws InvalidOperationException. |
bool Valid { get; } |
true if the box is valid: each minimum is less than or equal to its maximum. |
double Width { get; }, Height, Depth |
Xmax - Xmin, Ymax - Ymin and Zmax - Zmin. |
Point3D Center { get; } |
Box center. Not necessarily a point on the entity; to obtain a point inside an enclosed area, use ICloseable.InteriorPoint. |
Point3D NW, N, NE, E, SE, S, SW, W |
Corners and side midpoints of the box in the X, Y plane. All eight points have Z equal to Zmin. |
Methods
| Method | Description |
|---|---|
Entity Clone() |
Returns a copy of the entity. The copy does not belong to any drawing file. |
string ToString() |
Localized text with the entity type, minimum and maximum coordinates, codes and type-specific data (vertices, coordinate, text). |
void Dispose() |
Releases the native entity. Dispose is available only in the installed assembly: the reference package does not declare IDisposable, so code compiled with the package cannot call Dispose or use using with an entity. For entities forming part of another (polygon holes, complex entities), this method does not release the native entity. After calling Dispose, you cannot use the entity. |
Example
This program assigns colors to a line, checks that the line becomes read-only when added to a .bind file, and adds an offset copy:
using Digi21.DigiNG.Entities;
using Digi21.DigiNG.IO.BinDouble;
using Digi21.Math;
if (args.Length != 1)
{
Console.WriteLine("Uso: PropiedadesEntidad <salida.bind>");
return 1;
}
var línea = new Line(new Code("050100"));
línea.Points.Add(new Point3D(0, 0, 0));
línea.Points.Add(new Point3D(10, 5, 2));
// Read Color, Weight and FillColor once the entity has coordinates (Valid is true).
línea.Color = 3;
línea.Weight = 2;
Console.WriteLine($"{línea.Color} {línea.Weight} {línea.FillColor?.ToString() ?? "null"}"); // 3 2 null
Console.WriteLine($"{línea.Width} {línea.Height} {línea.Depth}"); // 10 5 2
Console.WriteLine(línea.ReadOnly); // False
using var archivo = new BinDouble(args[0]);
archivo.Add(línea);
// The entity now belongs to the file and is read-only.
Console.WriteLine(línea.ReadOnly); // True
Console.WriteLine(ReferenceEquals(línea.Owner, archivo)); // True
try
{
línea.Color = 5;
}
catch (InvalidOperationException e)
{
Console.WriteLine(e.Message);
}
// Clone returns a copy that does not belong to any file.
var copia = línea.Clone();
copia.Color = 5;
copia.Offset(0, 10);
archivo.Add(copia);
return 0;