C# Class Dynamo.Graph.Workspaces.WorkspaceModel

Represents base class for all kind of workspaces which contains general data such as Name, collections of nodes, notes, annotations, etc.
Inheritance: Dynamo.Core.NotificationObject, ILocatable, IUndoRedoRecorderClient, ILogSource, IDisposable, IWorkspaceModel
显示文件 Open project: DynamoDS/Dynamo Class Usage Examples

Public Properties

Property Type Description
NodeFactory NodeFactory

Protected Properties

Property Type Description
guid Guid

Private Properties

Property Type Description
AddAndRegisterNode void
AddAnnotation AnnotationModel
AddAnnotation void
AddNewAnnotation void
AddNode void
AddNote NoteModel
AddNote void
AddNote void
AddPreset PresetModel
AddPresetCore PresetModel
ApplyPreset void
AvoidSubgraphOverlap void
CheckIfModelExistsInSameGroup bool
ClearAnnotations void
ClearNodes void
ClearNotes void
ClearUndoRecorder void
ComputeUpstreamCacheForEntireGraph void
ConvertNodesToCodeInternal void
DoGraphAutoLayout void
GenerateCombinedGraph void
GenerateSeparateSubgraphs void
GetHangingNodes IEnumerable
GetModelsInternal IEnumerable
GetSourceNodes IEnumerable
GetStringRepOfWorkspace string
IncrementPasteOffset void
IsInternalNodeToCodeConnection bool
OnCurrentOffsetChanged void
OnRequestNodeCentered void
OnSyncWithDefinitionEnd void
OnSyncWithDefinitionStart void
OnZoomChanged void
ReConnectInputConnections List
ReConnectOutputConnections List
RecordAndDeleteModels void
RecordCreatedModel void
RecordCreatedModels void
RecordGroupModelBeforeUngroup void
RecordModelForModification void
RecordModelsForModification void
RecordModelsForUndo void
RecordUndoGraphLayout void
Redo void
RegisterConnector void
RemoveAndDisposeNode void
RemoveAnnotation void
RemoveNote void
ResetWorkspace void
RunLayoutSubgraph void
SaveInternal bool
SaveLayoutGraph void
SendModelEvent void
SerializeElementResolver void
SetModelEventOnAnnotation void
ShouldProceedWithRecording bool
ShouldProceedWithRecording bool
Undo void
UpdateModelValue void
annotationModel_GetModelBase ModelBase
computeUpstreamNodesWhenWorkspaceAdded void

Public Methods

Method Description
Clear ( ) : void

Clears this workspace of nodes, notes, and connectors.

CreateModel ( XmlElement modelData ) : void

Creates ModelBase object by given xml data and adds it to corresponding collection of the workspace.

DeleteModel ( XmlElement modelData ) : void

Deletes ModelBase object given by XmlElement from a corresponding collection of the workspace.

Dispose ( ) : void

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

GetModelForElement ( XmlElement modelData ) : Dynamo.Models.ModelBase

Gets model by GUID which is contained in given Xml data.

GetModelInternal ( System.Guid modelGuid ) : Dynamo.Models.ModelBase

Returns model by GUID

GetSharedName ( ) : string

Returns appropriate name of workspace for sharing.

ImportPresets ( IEnumerable presetCollection ) : void

Adds a specified collection PresetModel objects to the preset collection of the workspace.

RecordModelsForModification ( IEnumerable models ) : void

Implement recording node modification for undo/redo.

ReloadModel ( XmlElement modelData ) : void

Updates ModelBase object with given xml data

RemoveGroup ( Dynamo.Models.ModelBase model ) : void

Deletes AnnotationModel object from annotation collection of the workspace.

RemovePreset ( PresetModel state ) : void

Removes a specified PresetModel object from the preset collection of the workspace.

ReportPosition ( ) : void

Called when workspace position is changed. This method notifyies all the listeners when a workspace is changed.

Save ( ProtoCore runtimeCore ) : bool

Save assuming that the Filepath attribute is set.

SaveAs ( string newPath, ProtoCore runtimeCore, bool isBackup = false ) : bool

Save to a specific file path, if the path is null or empty, does nothing. If successful, the CurrentWorkspace.FilePath field is updated as a side effect

Protected Methods

Method Description
DisposeNode ( Dynamo.Models.NodeModel node ) : void
Log ( ILogMessage obj ) : void
Log ( string msg ) : void
Log ( string msg, WarningLevel severity ) : void
NodeModified ( Dynamo.Models.NodeModel node ) : void

Indicates that the AST for a node in this workspace requires recompilation

OnAnnotationAdded ( AnnotationModel annotation ) : void
OnAnnotationRemoved ( AnnotationModel annotation ) : void
OnAnnotationsCleared ( ) : void
OnConnectorAdded ( ConnectorModel obj ) : void
OnConnectorDeleted ( ConnectorModel obj ) : void
OnNodeAdded ( Dynamo.Models.NodeModel node ) : void
OnNodeRemoved ( Dynamo.Models.NodeModel node ) : void
OnNodesCleared ( ) : void
OnNoteAdded ( NoteModel note ) : void
OnNoteRemoved ( NoteModel note ) : void
OnNotesCleared ( ) : void
OnSaving ( XmlDocument obj ) : void
OnToggleNodeFreeze ( Dynamo.Models.NodeModel obj ) : void
OnWorkspaceSaved ( ) : void
PopulateXmlDocument ( XmlDocument xmlDoc ) : bool
RegisterNode ( Dynamo.Models.NodeModel node ) : void
RequestRun ( ) : void
ResetWorkspaceCore ( ) : void

Derived workspace classes can choose to override this method to perform clean-up specific to them.

SerializeSessionData ( XmlDocument document, ProtoCore runtimeCore ) : void
WorkspaceModel ( IEnumerable nodes, IEnumerable notes, IEnumerable annotations, WorkspaceInfo info, NodeFactory factory, IEnumerable presets, ElementResolver resolver ) : Dynamo.Core

Private Methods

Method Description
AddAndRegisterNode ( Dynamo.Models.NodeModel node, bool centered = false ) : void

Adds a node to this workspace.

AddAnnotation ( string text, System.Guid id ) : AnnotationModel
AddAnnotation ( AnnotationModel annotationModel ) : void
AddNewAnnotation ( AnnotationModel annotation ) : void
AddNode ( Dynamo.Models.NodeModel node ) : void
AddNote ( bool centerNote, double xPos, double yPos, string text, System.Guid id ) : NoteModel
AddNote ( NoteModel note ) : void
AddNote ( NoteModel note, bool centered ) : void
AddPreset ( string name, string description, IEnumerable IDSToSave ) : PresetModel
AddPresetCore ( string name, string description, IEnumerable currentSelection ) : PresetModel

this method creates a new preset state from a set of NodeModels and adds this new state to this presets collection

ApplyPreset ( PresetModel state ) : void
AvoidSubgraphOverlap ( ) : void

This method repeatedly shifts subgraphs away vertically from each other when there are any two nodes from different subgraphs overlapping.

CheckIfModelExistsInSameGroup ( IEnumerable selectNodes, IEnumerable selectNotes ) : bool

Checks if model exists in same group.

ClearAnnotations ( ) : void
ClearNodes ( ) : void
ClearNotes ( ) : void
ClearUndoRecorder ( ) : void
ComputeUpstreamCacheForEntireGraph ( ) : void

This method ensures that all upstream node caches are correct by calling ComputeUpstreamOnDownstream on all source nodes in the graph, this is done in such a way that each node is only computed once.

ConvertNodesToCodeInternal ( Dynamo.Engine.EngineController engineController, INamingProvider namingProvider ) : void
DoGraphAutoLayout ( ) : void

This function wraps a few methods on the workspace model layer to set up and run the graph layout algorithm.

GenerateCombinedGraph ( bool isGroupLayout ) : void

This method extracts all models from the workspace and puts them into the combined graph object, LayoutSubgraphs.First() True if all the selected models are groups.

GenerateSeparateSubgraphs ( HashSet nodes ) : void

This method repeatedly takes a selected node in the combined graph and uses breadth-first search to find all other nodes in the same subgraph until all selected nodes have been processed.

GetHangingNodes ( ) : IEnumerable
GetModelsInternal ( IEnumerable modelGuids ) : IEnumerable

Gets model list by their GUIDs

GetSourceNodes ( ) : IEnumerable

Returns the nodes in the graph that have no inputs or have none of their inputs filled

GetStringRepOfWorkspace ( ) : string
IncrementPasteOffset ( ) : void

Increment the current paste offset to prevent overlapping pasted elements

IsInternalNodeToCodeConnection ( IEnumerable nodes, ConnectorModel connector ) : bool

Checks whether the given connection is inside the node to code set or outside it. This determines if it should be redrawn(if it is external) or if it should be deleted (if it is internal)

OnCurrentOffsetChanged ( object sender, Dynamo.Models.PointEventArgs e ) : void

Used during open and workspace changes to set the location of the workspace

OnRequestNodeCentered ( object sender, Dynamo.Models.ModelEventArgs e ) : void

Requests that a Node or Note model should be centered.

OnSyncWithDefinitionEnd ( Dynamo.Models.NodeModel nodeModel ) : void
OnSyncWithDefinitionStart ( Dynamo.Models.NodeModel nodeModel ) : void
OnZoomChanged ( object sender, Dynamo.Models.ZoomEventArgs e ) : void

Used during open and workspace changes to set the zoom of the workspace

ReConnectInputConnections ( string>.Dictionary externalInputConnections, CodeBlockNodeModel cbn ) : List

Forms new connections from the external nodes to the Node To Code Node, based on the connectors passed as inputs.

ReConnectOutputConnections ( string>.Dictionary externalOutputConnections, CodeBlockNodeModel cbn ) : List

Forms new connections from the external nodes to the Node To Code Node, based on the connectors passed as inputs.

RecordAndDeleteModels ( List models ) : void
RecordCreatedModel ( Dynamo.Models.ModelBase model ) : void
RecordCreatedModels ( List models ) : void
RecordGroupModelBeforeUngroup ( AnnotationModel annotation ) : void
RecordModelForModification ( Dynamo.Models.ModelBase model, Dynamo.Core.UndoRedoRecorder recorder ) : void
RecordModelsForModification ( List models, Dynamo.Core.UndoRedoRecorder recorder ) : void

TODO(Ben): This method is exposed this way for external codes (e.g. the DragCanvas) to record models before they are modified. This is by no means ideal. The ideal case of course is for ALL codes that end up modifying models to be folded back into WorkspaceViewModel in the form of commands. These commands then internally record those affected models before updating them. We need this method to be gone sooner than later.

RecordModelsForUndo ( UndoRedoRecorder.UserAction>.Dictionary models, Dynamo.Core.UndoRedoRecorder recorder ) : void
RecordUndoGraphLayout ( bool isGroupLayout ) : void

This method adds relevant models to the undo recorder.

Redo ( ) : void
RegisterConnector ( ConnectorModel connector ) : void
RemoveAndDisposeNode ( Dynamo.Models.NodeModel model, bool dispose = true ) : void

Removes a node from this workspace. This method does not raise a NodesModified event. (LC notes this is clearly not true)

RemoveAnnotation ( AnnotationModel annotation ) : void
RemoveNote ( NoteModel note ) : void
ResetWorkspace ( ) : void
RunLayoutSubgraph ( GraphLayout graph, bool isGroupLayout ) : void

This function calls the graph layout algorithm methods.

SaveInternal ( string targetFilePath, ProtoCore runtimeCore ) : bool
SaveLayoutGraph ( ) : void

This method pushes changes from the GraphLayout.Graph objects back to the workspace models.

SendModelEvent ( System.Guid modelGuid, string eventName, int value ) : void
SerializeElementResolver ( XmlDocument xmlDoc ) : void
SetModelEventOnAnnotation ( ) : void

this sets the event on Annotation. This event return the model from the workspace. When a model is ungrouped from a group, that model will be deleted from that group. So, when UNDO execution, cannot get that model from that group, it has to get from the workspace. The below method will set the event on every annotation model, that will return the specific model from workspace.

ShouldProceedWithRecording ( UndoRedoRecorder.UserAction>.Dictionary models ) : bool
ShouldProceedWithRecording ( List models ) : bool
Undo ( ) : void
UpdateModelValue ( IEnumerable modelGuids, string propertyName, string value ) : void
annotationModel_GetModelBase ( Guid modelGuid ) : ModelBase

Returns the model from Workspace

computeUpstreamNodesWhenWorkspaceAdded ( WorkspacesModificationEventArgs args ) : void

Computes the upstream nodes when workspace is added. when a workspace is added (assuming that all the nodes and its connectors were added successfully) compute the upstream cache for all the frozen nodes.

Method Details

Clear() public method

Clears this workspace of nodes, notes, and connectors.
public Clear ( ) : void
return void

CreateModel() public method

Creates ModelBase object by given xml data and adds it to corresponding collection of the workspace.
public CreateModel ( XmlElement modelData ) : void
modelData System.Xml.XmlElement Xml data to create model
return void

DeleteModel() public method

Deletes ModelBase object given by XmlElement from a corresponding collection of the workspace.
public DeleteModel ( XmlElement modelData ) : void
modelData System.Xml.XmlElement object given by
return void

Dispose() public method

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
public Dispose ( ) : void
return void

DisposeNode() protected method

protected DisposeNode ( Dynamo.Models.NodeModel node ) : void
node Dynamo.Models.NodeModel
return void

GetModelForElement() public method

Gets model by GUID which is contained in given Xml data.
public GetModelForElement ( XmlElement modelData ) : Dynamo.Models.ModelBase
modelData System.Xml.XmlElement Xml data to find model.
return Dynamo.Models.ModelBase

GetModelInternal() public method

Returns model by GUID
public GetModelInternal ( System.Guid modelGuid ) : Dynamo.Models.ModelBase
modelGuid System.Guid Identifier of the requested model.
return Dynamo.Models.ModelBase

GetSharedName() public method

Returns appropriate name of workspace for sharing.
public GetSharedName ( ) : string
return string

ImportPresets() public method

Adds a specified collection PresetModel objects to the preset collection of the workspace.
public ImportPresets ( IEnumerable presetCollection ) : void
presetCollection IEnumerable objects to add.
return void

Log() protected method

protected Log ( ILogMessage obj ) : void
obj ILogMessage
return void

Log() protected method

protected Log ( string msg ) : void
msg string
return void

Log() protected method

protected Log ( string msg, WarningLevel severity ) : void
msg string
severity WarningLevel
return void

NodeModified() protected method

Indicates that the AST for a node in this workspace requires recompilation
protected NodeModified ( Dynamo.Models.NodeModel node ) : void
node Dynamo.Models.NodeModel
return void

OnAnnotationAdded() protected method

protected OnAnnotationAdded ( AnnotationModel annotation ) : void
annotation AnnotationModel
return void

OnAnnotationRemoved() protected method

protected OnAnnotationRemoved ( AnnotationModel annotation ) : void
annotation AnnotationModel
return void

OnAnnotationsCleared() protected method

protected OnAnnotationsCleared ( ) : void
return void

OnConnectorAdded() protected method

protected OnConnectorAdded ( ConnectorModel obj ) : void
obj ConnectorModel
return void

OnConnectorDeleted() protected method

protected OnConnectorDeleted ( ConnectorModel obj ) : void
obj ConnectorModel
return void

OnNodeAdded() protected method

protected OnNodeAdded ( Dynamo.Models.NodeModel node ) : void
node Dynamo.Models.NodeModel
return void

OnNodeRemoved() protected method

protected OnNodeRemoved ( Dynamo.Models.NodeModel node ) : void
node Dynamo.Models.NodeModel
return void

OnNodesCleared() protected method

protected OnNodesCleared ( ) : void
return void

OnNoteAdded() protected method

protected OnNoteAdded ( NoteModel note ) : void
note NoteModel
return void

OnNoteRemoved() protected method

protected OnNoteRemoved ( NoteModel note ) : void
note NoteModel
return void

OnNotesCleared() protected method

protected OnNotesCleared ( ) : void
return void

OnSaving() protected method

protected OnSaving ( XmlDocument obj ) : void
obj System.Xml.XmlDocument
return void

OnToggleNodeFreeze() protected method

protected OnToggleNodeFreeze ( Dynamo.Models.NodeModel obj ) : void
obj Dynamo.Models.NodeModel
return void

OnWorkspaceSaved() protected method

protected OnWorkspaceSaved ( ) : void
return void

PopulateXmlDocument() protected method

protected PopulateXmlDocument ( XmlDocument xmlDoc ) : bool
xmlDoc System.Xml.XmlDocument
return bool

RecordModelsForModification() public method

Implement recording node modification for undo/redo.
public RecordModelsForModification ( IEnumerable models ) : void
models IEnumerable Collection of objects to record.
return void

RegisterNode() protected method

protected RegisterNode ( Dynamo.Models.NodeModel node ) : void
node Dynamo.Models.NodeModel
return void

ReloadModel() public method

Updates ModelBase object with given xml data
public ReloadModel ( XmlElement modelData ) : void
modelData System.Xml.XmlElement Xml data to update model
return void

RemoveGroup() public method

Deletes AnnotationModel object from annotation collection of the workspace.
public RemoveGroup ( Dynamo.Models.ModelBase model ) : void
model Dynamo.Models.ModelBase object to remove.
return void

RemovePreset() public method

Removes a specified PresetModel object from the preset collection of the workspace.
public RemovePreset ( PresetModel state ) : void
state PresetModel object to remove.
return void

ReportPosition() public method

Called when workspace position is changed. This method notifyies all the listeners when a workspace is changed.
public ReportPosition ( ) : void
return void

RequestRun() protected method

protected RequestRun ( ) : void
return void

ResetWorkspaceCore() protected method

Derived workspace classes can choose to override this method to perform clean-up specific to them.
protected ResetWorkspaceCore ( ) : void
return void

Save() public method

Save assuming that the Filepath attribute is set.
public Save ( ProtoCore runtimeCore ) : bool
runtimeCore ProtoCore The object /// to obtain serialized trace data for node list to save.
return bool

SaveAs() public method

Save to a specific file path, if the path is null or empty, does nothing. If successful, the CurrentWorkspace.FilePath field is updated as a side effect
public SaveAs ( string newPath, ProtoCore runtimeCore, bool isBackup = false ) : bool
newPath string The path to save to
runtimeCore ProtoCore The object /// to obtain serialized trace data for node list to save.
isBackup bool Indicates whether saved workspace is backup or not. If it's not backup, /// we should add it to recent files. Otherwise leave it.
return bool

SerializeSessionData() protected method

protected SerializeSessionData ( XmlDocument document, ProtoCore runtimeCore ) : void
document System.Xml.XmlDocument
runtimeCore ProtoCore
return void

WorkspaceModel() protected method

protected WorkspaceModel ( IEnumerable nodes, IEnumerable notes, IEnumerable annotations, WorkspaceInfo info, NodeFactory factory, IEnumerable presets, ElementResolver resolver ) : Dynamo.Core
nodes IEnumerable
notes IEnumerable
annotations IEnumerable
info WorkspaceInfo
factory NodeFactory
presets IEnumerable
resolver ElementResolver
return Dynamo.Core

Property Details

NodeFactory public_oe property

A NodeFactory used by this workspace to create Nodes.
public NodeFactory NodeFactory
return NodeFactory

guid protected_oe property

protected Guid guid
return Guid