Class Project
- Namespace
- CADability
- Assembly
- CADability.dll
A Project is the database CADability works on. A Project is serializable and contains one or more Models (which contain GeoObjects) lists of attributes, views and UserData. A Project is usually saved in a file.
[JsonVersion(1)]
public class Project : IShowPropertyImpl, IShowProperty, IPropertyEntry, ISerializable, IAttributeListContainer, ICommandHandler, IEnumerable, IDeserializationCallback, IJsonSerialize, IJsonSerializeDone
- Inheritance
-
Project
- Implements
- Inherited Members
Constructors
Project()
Creates an empty Project. The empty project contains clones of the globally defined attributes and attribute lists (like colors, layers etc.)
protected Project()
Project(SerializationInfo, StreamingContext)
Constructor required by deserialization
protected Project(SerializationInfo info, StreamingContext context)
Parameters
infoSerializationInfoSerializationInfo
contextStreamingContextStreamingContext
Fields
Constructor
Hook for the polymorphic construction of projects. When set, Construct() calls this delegate instead of creating a plain Project, so that an application can substitute its own class derived from Project wherever CADability creates a project by Construct() (e.g. CreateSimpleProject()). Null by default.
public static Project.ConstructionDelegate Constructor
Field Value
UserData
The UserData object can take any kind of data. If the data objects are serializable i.e. implement ISerializable they are serialized together with the project. If they implement the IPropertyEntry interface they are displayed and can be modified on the project tab page of the control center.
public UserData UserData
Field Value
Properties
AdditionalSymbols
The same list as SymbolList.
public GeoObjectList AdditionalSymbols { get; }
Property Value
AnimatedViews
The AnimatedViews defined in this project. The list is saved with the project. AddView(IView) and RemoveView(IView) add views to and remove them from this list and also register them with the frame; the list may be modified directly, but the frame does not notice that.
public List<AnimatedView> AnimatedViews { get; }
Property Value
ColorList
The colours (ColorList) of this project. The attribute lists of a project contain the attributes the objects of its models use; they are shown in the project tab of the control center, saved with the project and initialized from the global settings when the project is created. New objects get the current entry (see SetDefaults(IGeoObject)).
public ColorList ColorList { get; }
Property Value
DefaultPageSetup
The page settings of the project for printing, which are saved with the project. Null if none have been set: then the printer's defaults are used. On Windows they are also changed by the page setup and printer dialogs.
public PageSetup DefaultPageSetup { get; set; }
Property Value
DeferRefresh
While true, modifications of attributes do not raise the RefreshEvent; setting it back to false raises the event once. Use it to bracket a series of attribute changes so that the display is refreshed only once.
public bool DeferRefresh { get; set; }
Property Value
DimensionStyleList
The dimension styles (DimensionStyleList) of this project. The attribute lists of a project contain the attributes the objects of its models use; they are shown in the project tab of the control center, saved with the project and initialized from the global settings when the project is created. New objects get the current entry (see SetDefaults(IGeoObject)).
public DimensionStyleList DimensionStyleList { get; }
Property Value
EntryType
Overrides EntryType, returns GroupTitle.
public override ShowPropertyEntryType EntryType { get; }
Property Value
FileName
The name of the file in which this project ist stored. May be null.
public string FileName { get; set; }
Property Value
FilterList
The FilterList of this project: a list of filters that decide which objects may be selected or snapped to by the actions (see SelectObjectsAction). The actions pass it to GetObjectsFromRect(BoundingRect, Projection, HashSet<Layer>, PickMode, FilterList) and to the SnapPointFinder. It is shown in the control center and saved with the project.
public FilterList FilterList { get; }
Property Value
GdiViews
Gets a list of all defined GDI2DViews in this project.
public List<GDI2DView> GdiViews { get; }
Property Value
HatchStyleList
The hatch styles (HatchStyleList) of this project. The attribute lists of a project contain the attributes the objects of its models use; they are shown in the project tab of the control center, saved with the project and initialized from the global settings when the project is created. New objects get the current entry (see SetDefaults(IGeoObject)).
public HatchStyleList HatchStyleList { get; }
Property Value
IsModified
Gets or sets the modified flag
public bool IsModified { get; set; }
Property Value
LayerList
The layers (LayerList) of this project. The attribute lists of a project contain the attributes the objects of its models use; they are shown in the project tab of the control center, saved with the project and initialized from the global settings when the project is created. New objects get the current entry (see SetDefaults(IGeoObject)).
public LayerList LayerList { get; }
Property Value
LayoutCount
Gets the number of layouts in this project
public int LayoutCount { get; }
Property Value
LinePatternList
The line patterns (LinePatternList) of this project. The attribute lists of a project contain the attributes the objects of its models use; they are shown in the project tab of the control center, saved with the project and initialized from the global settings when the project is created. New objects get the current entry (see SetDefaults(IGeoObject)).
public LinePatternList LinePatternList { get; }
Property Value
LineWidthList
The line widths (LineWidthList) of this project. The attribute lists of a project contain the attributes the objects of its models use; they are shown in the project tab of the control center, saved with the project and initialized from the global settings when the project is created. New objects get the current entry (see SetDefaults(IGeoObject)).
public LineWidthList LineWidthList { get; }
Property Value
StyleList
The styles (named combinations of attributes) (StyleList) of this project. The attribute lists of a project contain the attributes the objects of its models use; they are shown in the project tab of the control center, saved with the project and initialized from the global settings when the project is created. New objects get the current entry (see SetDefaults(IGeoObject)).
public StyleList StyleList { get; }
Property Value
SubEntries
The sub entries shown below this entry when it is opened in the property page. The default implementation has none and returns an empty array.
public override IShowProperty[] SubEntries { get; }
Property Value
SubEntriesCount
The number of SubEntries, 0 for an entry that cannot be opened. The default implementation returns 0.
public override int SubEntriesCount { get; }
Property Value
SymbolList
A list of objects (symbols) that are saved with the project but do not belong to any model, e.g. templates for objects to insert. CADability itself only keeps and serializes the list; the application decides what to put into it.
public GeoObjectList SymbolList { get; }
Property Value
Undo
The UndoRedoSystem of this project, which records the undoable changes of the models and objects of the project; the models of the project share it (Undo). Use UndoFrame to combine several changes into one undo step.
public UndoRedoSystem Undo { get; }
Property Value
Methods
Add(object)
Not implemented, always throws a NotImplementedException. It exists only beside the IEnumerable implementation, which enumerates the models; add models with AddModel(Model).
public void Add(object toAdd)
Parameters
toAddobjectNot used
Exceptions
- NotImplementedException
always
AddLayout(Layout)
Adds the specified Layout to the project.
public int AddLayout(Layout l)
Parameters
lLayoutthe layout to add
Returns
- int
the index of the new layout
AddModel(Model)
Adds the given Model to the project. The attributes of the GeoObjects in this model are merged into the attribute lists of this project. Fires a ModelsChangedEvent.
public void AddModel(Model ToAdd)
Parameters
ToAddModelModel to add
AddProjectedModel(string, Model, Projection)
Adds a new ProjectedModel, the persistent part of a ModelView (the model, the projection and the visible layers), with the given name to the project. The name should be unique among the model views of the project, because the frame and the project refer to model views by name. No ModelView is created and no ViewChangedEvent is raised; AddView(IView) calls this when a ModelView is added to the frame.
public int AddProjectedModel(string name, Model model, Projection projection)
Parameters
namestringThe name of the model view
modelModelThe model that is shown
projectionProjectionThe projection; it is used as is, not cloned
Returns
- int
The index of the new entry in the list of projected models of the project
Construct()
Creates a new, empty project: by Constructor if that is set, otherwise a plain Project. Use it instead of the constructor when an application may have substituted a derived class. The project has no model yet; CreateSimpleProject() creates a project with a model and the standard views.
public static Project Construct()
Returns
- Project
The new project
CreateSimpleProject()
Creates a project with one empty Model and the standard views of it (from top, from right, from front and an isometric view). The model's extent is taken from the global setting "DefaultModelSize", or is 0 to 100 in each direction. The project has the default attribute lists (layers, colours, styles...), so objects can be given default attributes with SetDefaults(IGeoObject). This is the project to start with when CADability is used as a library without a user interface; GetActiveModel() returns the model to add objects to. The imports create their project this way.
public static Project CreateSimpleProject()
Returns
- Project
the new project
DeserializeObject(string)
Reads an object written by SerializeObject(ISerializable, string) from the file. Obsolete, see there.
public static object DeserializeObject(string fileName)
Parameters
fileNamestringThe name of the file
Returns
- object
The object read
Export(string, string)
Exports the project in one of the following formats: cdb (CADability's own JSON format, same as
WriteToFile(string)), dxf, dwg, step (or stp) and stl. The case of format does not
matter, the extension of the file name is not used. DXF and DWG write all models (see Export;
the DXF version is the setting "DxfDwg.Version", DWG is written as AutoCAD 2004 or later), STEP and STL write
the active model only. STEP writes solids, shells and faces as boundary representation and curves as curve
sets (see ExportStep), STL writes the triangulation of the faces with the precision of the setting
"Export.STL.Precision" (see ExportToSTL(string)).
public bool Export(string fileName, string format)
Parameters
fileNamestringPath and filename for the generated output file
formatstringFormat, one of the strings: cdb, dxf, dwg, step, stp, stl
Returns
- bool
true, if the file was written, false for a format that cannot be exported (e.g. dxb, iges, html)
ExportToSTL(string)
Writes the active model to a binary STL file: the triangulation of all faces, shells and solids, with the precision (maximal distance between the triangles and the surface) of the setting "Export.STL.Precision", 0.005 by default. Curves, text and other objects without faces are not written.
public void ExportToSTL(string fileName)
Parameters
fileNamestringPath and filename of the STL file
ExportToWebGl(string)
Writes the active model (GetActiveModel()) as a HTML file that displays it with WebGL, see ExportToWebGl. The HTML template "WebGLS.html" is expected in the directory of the CADability assembly. If there is an active view, its view direction is used as the initial view direction.
public void ExportToWebGl(string fileName)
Parameters
fileNamestringThe name of the HTML file to write
~Project()
Finalizer. It does nothing; a project holds no unmanaged resources.
protected ~Project()
FindModel(string)
Returns the Model with the given name, Returns null if there is no such model in the project.
public Model FindModel(string name)
Parameters
namestringname of the required model
Returns
- Model
the model found or null
GetActiveModel()
Returns the active Model of this project.
public Model GetActiveModel()
Returns
- Model
the active model
GetDefaultLayout()
Gets a default Layout for this project. If there is no layout in this project a standard Layout is created and adde to the project
public Layout GetDefaultLayout()
Returns
- Layout
a default layout
GetLayout(int)
Returns the Layout with the given index.
public Layout GetLayout(int index)
Parameters
indexintindex of required layout
Returns
- Layout
layout
GetModel(int)
Returns the Model with the given index.
public Model GetModel(int Index)
Parameters
IndexintIndex of the required model
Returns
- Model
the model
GetModelCount()
Returns the number of models in this project.
public int GetModelCount()
Returns
- int
the number of models
GetNamedValue(string)
Returns the named value with the given name. Named values are user defined doubles, GeoPoints and GeoVectors with a name each, which can be referred to by name in input fields and formulas. They are shown and edited in the "named values" group of the project in the control center and saved with the project.
public object GetNamedValue(string name)
Parameters
namestringThe name of the value
Returns
- object
The value, or null if there is no value with this name
GetObjectData(IJsonWriteData)
Implements GetObjectData(IJsonWriteData): writes the models, the active model, the attribute lists, the user data, the symbol list, the projected models, the named values, the filter list, the animated views and the name of the active view, and, unless the global setting "DontSave.System.Drawing" is set, the layouts, the GDI views and the page settings. This is the content of CADability's project files.
public void GetObjectData(IJsonWriteData data)
Parameters
dataIJsonWriteDataReceives the data
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.
public virtual void GetObjectData(SerializationInfo info, StreamingContext context)
Parameters
infoSerializationInforeceives the data
contextStreamingContextthe destination of the serialization
GetStandardModelView()
Creates a ModelView that shows the active model (GetActiveModel()) in the standard projection, i.e. the view from top with the x/y plane as drawing plane. Like GetStandardModelView(Model) it creates a new view on each call.
public ModelView GetStandardModelView()
Returns
- ModelView
The new model view
GetStandardModelView(Model)
Creates a ModelView that shows the given model in the standard projection, i.e. the view from top with the x/y plane as drawing plane. Note that a new view is created on each call; views already defined for the model are not looked up.
public ModelView GetStandardModelView(Model m)
Parameters
mModelThe model to show
Returns
- ModelView
The new model view
GetStandardModelView(Model, int)
Creates a ModelView that shows the given model in one of the standard projections: 0 the view from top with the x/y plane as drawing plane, 1 the view from the right with the y/z plane, 2 the view from the front with the x/z plane, 3 an isometric view in the direction (-1, -1, -1) with the drawing plane perpendicular to it. Any other index gives the view from top. A new view is created on each call.
public ModelView GetStandardModelView(Model m, int Index)
Parameters
Returns
- ModelView
The new model view
ReadFromFile(string)
Reads a project from a file in CADability's own format (cdb): the JSON format written by WriteToFile(string), or the binary format of older versions, which is converted when read. To read DXF, DWG, STEP or STL files use ReadFromFile(string, string).
public static Project ReadFromFile(string FileName)
Parameters
FileNamestringThe name of the file
Returns
- Project
The project read from the file, or null when
FileNameis null or the file does not contain a project
ReadFromFile(string, string)
Reads a file of the given format and returns it as a new project, see ReadFromFile(string, string, bool, bool).
public static Project ReadFromFile(string FileName, string Format)
Parameters
Returns
- Project
The new project, or null for an unknown or unsupported format
ReadFromFile(string, string, bool, bool)
Reads a file of the given format and returns it as a new project. Format is one of
"cdb" (CADability's own format, see ReadFromFile(string)), "dxf", "dwg", "step" or "stp" and "stl";
the case does not matter, the extension of the file name is not used. For the exchange formats the project is
created with CreateSimpleProject() and the imported objects are added to its model: DXF and DWG
bring their layers, blocks, colours, line styles and hatch styles along (see Import), STEP files
give solids, open shells and faces, named like their products and arranged in Blocks
according to the assembly structure when the setting "ImportStep.UseHierarchy" is true (see
ImportStep), and STL files give a solid for every closed set of triangles and a shell for every
open one. Objects without a colour or layer get the project's standard ones.
A DWG file that cannot be read throws an InvalidOperationException; a DXF or STEP file that cannot
be read throws an exception as well. A DXF or DWG file whose blocks expand to more objects than the setting
"DxfDwg.MaxImportObjects" allows throws a DxfImportLimitException, for both formats unwrapped.
public static Project ReadFromFile(string FileName, string Format, bool useProgress, bool makeCompounds = true)
Parameters
FileNamestringThe name of the file
FormatstringThe format: cdb, dxf, dwg, step, stp or stl
useProgressboolno longer used, the progress bar is shown by the frame when there is one
makeCompoundsboolno longer used
Returns
- Project
The new project, or null for an unknown or unsupported format (e.g. brep, sat, x_t) and for a STL file without shells
ReadFromJson(Stream)
Reads a Project from a JSON formatted stream.
public static Project ReadFromJson(Stream stream)
Parameters
streamStreamThe Stream containing JSON serialized project data
Returns
- Project
The deserialized Project or null if deserialization fails
ReadFromJson(Stream, IJsonProgress)
Reads a Project from a JSON formatted stream like ReadFromJson(Stream) and reports the progress of
reading to progress.
public static Project ReadFromJson(Stream stream, IJsonProgress progress)
Parameters
streamStreamThe Stream containing JSON serialized project data
progressIJsonProgressreceives the progress, may be null
Returns
- Project
The deserialized Project or null if deserialization fails
ReadFromStream(Stream)
Creates a new project reading the data from the given stream using binary deserialization. This method is obsolete but kept for backward compatibility to read legacy binary format files. Use ReadFromJson(Stream) for new code.
[Obsolete("Use ReadFromJson for new code. This method is kept only for reading legacy binary format files.")]
public static Project ReadFromStream(Stream stream)
Parameters
streamStreamStream to read from
Returns
- Project
The deserialized Project or null if deserialization fails
RemoveLayout(Layout)
Removes the given Layout from the project. There must always be at least one layout, so you cannot remove the last layout.
public bool RemoveLayout(Layout toRemove)
Parameters
toRemoveLayoutlayout to remove
Returns
- bool
success: true, failure: false
RemoveModel(Model)
Removes the given Model from the project. Fires a ModelsChangedEvent.
public void RemoveModel(Model ToRemove)
Parameters
ToRemoveModelmodel to remove
RemoveModel(int)
Removes the Model with the given index from the project. Fires a ModelsChangedEvent.
public void RemoveModel(int Index)
Parameters
IndexintIndex of the model to remove
RemoveModelView(ModelView)
Removes the given ModelView from the project. There must always be at least one modelview, so you cannot remove the last modelview.
public bool RemoveModelView(ModelView toRemove)
Parameters
toRemoveModelViewmodelview to remove
Returns
- bool
success: true, failure: false
RemoveModelView(int)
Removes the ProjectedModel with the given index from the list of model views of the project, without any checks: unlike RemoveModelView(ModelView) it also removes the last one and raises no ViewChangedEvent.
public void RemoveModelView(int index)
Parameters
indexintThe index of the projected model, as returned by AddProjectedModel(string, Model, Projection)
RenameLayout(Layout, string)
Renames the
public bool RenameLayout(Layout l, string newName)
Parameters
Returns
SaveModified()
Checks whether the project has been modified (IsModified) and, if so, asks the user whether to save it; on "yes" the project is written to its file. Without a user interface (setting "DontUse.WindowsForms") a modified project is saved without asking.
public virtual bool SaveModified()
Returns
- bool
false if the user pressed cancel, true otherwise (saved or discarded)
SerializeObject(ISerializable, string)
Writes the given object to a file with the BinaryFormatter, overwriting an existing file. Obsolete: the BinaryFormatter is deprecated and disabled on current .NET versions, and CADability writes its own files in JSON format (JsonSerialize). Not used by CADability itself.
public static void SerializeObject(ISerializable toSerialize, string fileName)
Parameters
toSerializeISerializableThe object to write
fileNamestringThe name of the file
SetActiveModel(int)
Makes the model with the given index (see GetModel(int)) the active model of the project, which GetActiveModel() returns: the model that new views show and that the imports and the methods working without a view (e.g. ExportToWebGl(string)) use.
public void SetActiveModel(int Index)
Parameters
IndexintThe index of the model
Exceptions
- ProjectException
if the index is out of range (InvalidModelIndex)
SetDefaults(IGeoObject)
Gives the object the default attributes of this project: the default Style for its kind of object (PreferredStyle), and the current layer, colour, dimension style, line width, line pattern and hatch style of the project's attribute lists for every attribute the object does not have yet. The construct actions and the methods of Make3D that take a project call this. Call it for objects you create yourself before adding them to a model, otherwise they have no layer and colour and are drawn in the default colour.
public void SetDefaults(IGeoObject go)
Parameters
goIGeoObjectthe object to set the attributes of
SetNamedValue(string, object)
Sets or adds the named value with the given name (see GetNamedValue(string)). With val
null the value is removed. With name null a unique name is generated from the type of the
value and, if the project is shown in the control center, the user is prompted to edit that name.
public void SetNamedValue(string name, object val)
Parameters
namestringThe name of the value, or null to generate one
valobjectThe value (a double, GeoPoint or GeoVector), or null to remove the entry
SetObjectData(IJsonReadData)
Implements SetObjectData(IJsonReadData): reads the data written by GetObjectData(IJsonWriteData). Properties missing in the file get their default values; the printer settings are skipped on platforms without System.Drawing printing. The object is completed (owner of the attribute lists, views, event subscriptions) in the callback SerializationDone(JsonSerialize).
public void SetObjectData(IJsonReadData data)
Parameters
dataIJsonReadDataThe data to read from
WriteToFile(string)
Saves the project in a file with the given FileName, in JSON format. If FileName is null, a SaveFileDialog is presented.
public virtual bool WriteToFile(string FileName)
Parameters
FileNamestringThe file name
Returns
- bool
true, if successful, false if the user pressed escape in the SaveFileDialog
WriteToFile(string, bool)
Saves the project in a file with the given FileName, in JSON format, like WriteToFile(string), and lets the caller decide whether a progress bar is shown while saving. If FileName is null, a SaveFileDialog is presented, which needs the UI thread.
public virtual bool WriteToFile(string FileName, bool useProgress)
Parameters
FileNamestringThe file name
useProgressbooltrue: show the progress bar while saving, false: save without any progress display, e.g. for a save in the background
Returns
- bool
true, if successful, false if the user pressed escape in the SaveFileDialog
WriteToFileWithoutUserData(string)
Saves a copy of the project in the given file (JSON format, like WriteToFile(string)) from which all UserData of the project, of its models and of all their objects (including child objects) has been removed. This project is not changed. Useful to pass a project on without application specific data.
public bool WriteToFileWithoutUserData(string fileName)
Parameters
fileNamestringThe name of the file to write
Returns
- bool
true on success, false if the copy could not be made or written
WriteToJson(Stream)
Writes the Project to a JSON formatted stream. Resets the IsModified flag.
public void WriteToJson(Stream stream)
Parameters
streamStreamThe Stream to write the JSON serialized project data to
WriteToStream(Stream)
Writes the project data to the given stream using binary serialization. Resets the IsModified flag. This method is obsolete. Use WriteToJson(Stream) instead for new code.
[Obsolete("Use WriteToJson instead. Binary serialization is deprecated in favor of JSON format.")]
public void WriteToStream(Stream stream)
Parameters
streamStreamStream where to write the data
Events
BindToTypeEvent
Event that gets called when a type cannot be resolved during the deserialization. Provide the Type of an constructable object as a result.
public static event Project.BindToTypeDelegate BindToTypeEvent
Event Type
ModelsChangedEvent
Raised after a model has been added to the project (AddModel(Model)), removed from it (RemoveModel(Model)) or renamed. The views listen to it to update their list of models.
public event Project.ModelsChangedDelegate ModelsChangedEvent
Event Type
ProjectModifiedEvent
Raised whenever IsModified is set to true, i.e. after a change that has to be saved. It is not raised when the flag is reset by saving.
public event Project.ProjectModifiedDelegate ProjectModifiedEvent
Event Type
RefreshEvent
Raised when the display of the project's objects must be refreshed because an attribute (a layer, colour, line pattern, hatch style...) of the attribute lists of the project has been modified, and when DeferRefresh is reset to false. The frame listens to it.
public event Project.RefreshDelegate RefreshEvent
Event Type
ViewChangedEvent
Raised when the list of views of the project has changed, i.e. a model view or a layout has been added or removed (e.g. by RemoveModelView(ModelView) or by the commands of the project in the control center). The frame listens to it to update its views.
public event Project.ViewChangedDelegate ViewChangedEvent