public dynWorkspaceViewModel(dynWorkspaceModel model, DynamoViewModel vm) { _model = model; var nodesColl = new CollectionContainer { Collection = Nodes }; WorkspaceElements.Add(nodesColl); var connColl = new CollectionContainer { Collection = Connectors }; WorkspaceElements.Add(connColl); var notesColl = new CollectionContainer { Collection = Notes }; WorkspaceElements.Add(notesColl); //respond to collection changes on the model by creating new view models //currently, view models are added for notes and nodes //connector view models are added during connection _model.Nodes.CollectionChanged += Nodes_CollectionChanged; _model.Notes.CollectionChanged += Notes_CollectionChanged; _model.Connectors.CollectionChanged += Connectors_CollectionChanged; _model.PropertyChanged += ModelPropertyChanged; HideCommand = new DelegateCommand <object>(Hide, CanHide); CrossSelectCommand = new DelegateCommand <object>(CrossingSelect, CanCrossSelect); ContainSelectCommand = new DelegateCommand <object>(ContainSelect, CanContainSelect); SetCurrentOffsetCommand = new DelegateCommand <object>(SetCurrentOffset, CanSetCurrentOffset); NodeFromSelectionCommand = new DelegateCommand(CreateNodeFromSelection, CanCreateNodeFromSelection); SetZoomCommand = new DelegateCommand <object>(SetZoom, CanSetZoom); FindByIdCommand = new DelegateCommand <object>(FindById, CanFindById); AlignSelectedCommand = new DelegateCommand <string>(AlignSelected, CanAlignSelected); SelectAllCommand = new DelegateCommand(SelectAll, CanSelectAll); FindNodesFromSelectionCommand = new DelegateCommand(FindNodesFromSelection, CanFindNodesFromSelection); DynamoSelection.Instance.Selection.CollectionChanged += NodeFromSelectionCanExecuteChanged; // sync collections Nodes_CollectionChanged(null, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, _model.Nodes)); Connectors_CollectionChanged(null, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, _model.Connectors)); Notes_CollectionChanged(null, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, _model.Notes)); }
/// <summary> /// Replace the home workspace with a new /// workspace. Only valid if the home workspace is already /// defined (usually by calling AddHomeWorkspace). /// </summary> public void NewHomeWorkspace() { if (this.Workspaces.Count > 0 && this.HomeSpace != null) { //var homeIndex = this._workSpaces.IndexOf(this.HomeSpace); //var newHomespace = new HomeWorkspace(); //this.Workspaces[0] = newHomespace; //this.HomeSpace = newHomespace; //this.CurrentSpace = newHomespace; this.AddHomeWorkspace(); _cspace = this.HomeSpace; this.CurrentSpace = this.HomeSpace; this.Workspaces.RemoveAt(1); } }
public dynWorkspaceViewModel(dynWorkspaceModel model, DynamoViewModel vm) { _model = model; this.CurrentOffset = new Point(10,10); var nodesColl = new CollectionContainer(); nodesColl.Collection = Nodes; WorkspaceElements.Add(nodesColl); var connColl = new CollectionContainer(); connColl.Collection = Connectors; WorkspaceElements.Add(connColl); var notesColl = new CollectionContainer(); notesColl.Collection = Notes; WorkspaceElements.Add(notesColl); //var watch3DColl = new CollectionContainer(); //watch3DColl.Collection = Watch3DViewModels; //WorkspaceElements.Add(watch3DColl); Watch3DViewModels.Add(new Watch3DFullscreenViewModel(this)); //respond to collection changes on the model by creating new view models //currently, view models are added for notes and nodes //connector view models are added during connection _model.Nodes.CollectionChanged += Nodes_CollectionChanged; _model.Notes.CollectionChanged += Notes_CollectionChanged; _model.Connectors.CollectionChanged += Connectors_CollectionChanged; _model.PropertyChanged += ModelPropertyChanged; HideCommand = new DelegateCommand<object>(Hide, CanHide); CrossSelectCommand = new DelegateCommand<object>(CrossingSelect, CanCrossSelect); ContainSelectCommand = new DelegateCommand<object>(ContainSelect, CanContainSelect); SetCurrentOffsetCommand = new DelegateCommand<object>(SetCurrentOffset, CanSetCurrentOffset); NodeFromSelectionCommand = new DelegateCommand(CreateNodeFromSelection, CanCreateNodeFromSelection); SetZoomCommand = new DelegateCommand<object>(SetZoom, CanSetZoom); DynamoSelection.Instance.Selection.CollectionChanged += NodeFromSelectionCanExecuteChanged; // sync collections Nodes_CollectionChanged(null, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, _model.Nodes)); Connectors_CollectionChanged(null, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, _model.Connectors)); Notes_CollectionChanged(null, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, _model.Notes)); }
/// <summary> /// Generate an xml doc and write the workspace to the given path /// </summary> /// <param name="xmlPath">The path to save to</param> /// <param name="workSpace">The workspace</param> /// <returns>Whether the operation was successful</returns> public static bool SaveWorkspace(string xmlPath, dynWorkspaceModel workSpace) { dynSettings.Controller.DynamoViewModel.Log("Saving " + xmlPath + "..."); try { var xmlDoc = GetXmlDocFromWorkspace(workSpace, workSpace is HomeWorkspace); xmlDoc.Save(xmlPath); workSpace.FilePath = xmlPath; workSpace.OnWorkspaceSaved(); } catch (Exception ex) { //Log(ex); DynamoLogger.Instance.Log(ex.Message); DynamoLogger.Instance.Log(ex.StackTrace); Debug.WriteLine(ex.Message + " : " + ex.StackTrace); return(false); } return(true); }
public dynWorkspaceViewModel(dynWorkspaceModel model, DynamoViewModel vm) { _model = model; var nodesColl = new CollectionContainer { Collection = Nodes }; WorkspaceElements.Add(nodesColl); var connColl = new CollectionContainer { Collection = Connectors }; WorkspaceElements.Add(connColl); var notesColl = new CollectionContainer { Collection = Notes }; WorkspaceElements.Add(notesColl); //respond to collection changes on the model by creating new view models //currently, view models are added for notes and nodes //connector view models are added during connection _model.Nodes.CollectionChanged += Nodes_CollectionChanged; _model.Notes.CollectionChanged += Notes_CollectionChanged; _model.Connectors.CollectionChanged += Connectors_CollectionChanged; _model.PropertyChanged += ModelPropertyChanged; HideCommand = new DelegateCommand<object>(Hide, CanHide); CrossSelectCommand = new DelegateCommand<object>(CrossingSelect, CanCrossSelect); ContainSelectCommand = new DelegateCommand<object>(ContainSelect, CanContainSelect); SetCurrentOffsetCommand = new DelegateCommand<object>(SetCurrentOffset, CanSetCurrentOffset); NodeFromSelectionCommand = new DelegateCommand(CreateNodeFromSelection, CanCreateNodeFromSelection); SetZoomCommand = new DelegateCommand<object>(SetZoom, CanSetZoom); FindByIdCommand = new DelegateCommand<object>(FindById, CanFindById); AlignSelectedCommand = new DelegateCommand<string>(AlignSelected, CanAlignSelected); SelectAllCommand = new DelegateCommand(SelectAll, CanSelectAll); FindNodesFromSelectionCommand = new DelegateCommand(FindNodesFromSelection, CanFindNodesFromSelection); DynamoSelection.Instance.Selection.CollectionChanged += NodeFromSelectionCanExecuteChanged; // sync collections Nodes_CollectionChanged(null, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, _model.Nodes)); Connectors_CollectionChanged(null, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, _model.Connectors)); Notes_CollectionChanged(null, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, _model.Notes)); }
/// <summary> /// Updates relevant parameters on save /// </summary> /// <param name="model">The workspace that was just saved</param> private static void OnWorkspaceSaved(dynWorkspaceModel model) { model.LastSaved = DateTime.Now; model.HasUnsavedChanges = false; }
/// <summary> /// Generate an xml doc and write the workspace to the given path /// </summary> /// <param name="xmlPath">The path to save to</param> /// <param name="workSpace">The workspace</param> /// <returns>Whether the operation was successful</returns> public static bool SaveWorkspace(string xmlPath, dynWorkspaceModel workSpace) { dynSettings.Controller.DynamoViewModel.Log("Saving " + xmlPath + "..."); try { var xmlDoc = GetXmlDocFromWorkspace(workSpace, workSpace is HomeWorkspace); xmlDoc.Save(xmlPath); workSpace.FilePath = xmlPath; workSpace.OnWorkspaceSaved(); } catch (Exception ex) { //Log(ex); DynamoLogger.Instance.Log(ex.Message); DynamoLogger.Instance.Log(ex.StackTrace); Debug.WriteLine(ex.Message + " : " + ex.StackTrace); return false; } return true; }
/// <summary> /// Generate the xml doc of the workspace from memory /// </summary> /// <param name="workSpace">The workspace</param> /// <param name="savingHomespace"></param> /// <returns>The generated xmldoc</returns> public static XmlDocument GetXmlDocFromWorkspace( dynWorkspaceModel workSpace, bool savingHomespace) { try { //create the xml document var xmlDoc = new XmlDocument(); xmlDoc.CreateXmlDeclaration("1.0", null, null); var root = xmlDoc.CreateElement("dynWorkspace"); //write the root element root.SetAttribute("X", workSpace.X.ToString(CultureInfo.InvariantCulture)); root.SetAttribute("Y", workSpace.Y.ToString(CultureInfo.InvariantCulture)); root.SetAttribute("zoom", workSpace.Zoom.ToString(CultureInfo.InvariantCulture)); if (!savingHomespace) //If we are not saving the home space { root.SetAttribute("Name", workSpace.Name); root.SetAttribute("Category", ((FuncWorkspace) workSpace).Category); var guid = dynSettings.Controller.CustomNodeLoader.GetGuidFromName(workSpace.Name); //friends don't let friends save an empty GUID if (guid == Guid.Empty) guid = Guid.NewGuid(); root.SetAttribute("ID", guid.ToString()); } xmlDoc.AppendChild(root); var elementList = xmlDoc.CreateElement("dynElements"); //write the root element root.AppendChild(elementList); foreach (var el in workSpace.Nodes) { var typeName = el.GetType().ToString(); var dynEl = xmlDoc.CreateElement(typeName); elementList.AppendChild(dynEl); //set the type attribute dynEl.SetAttribute("type", el.GetType().ToString()); dynEl.SetAttribute("guid", el.GUID.ToString()); dynEl.SetAttribute("nickname", el.NickName); dynEl.SetAttribute("x", el.X.ToString(CultureInfo.InvariantCulture)); dynEl.SetAttribute("y", el.Y.ToString(CultureInfo.InvariantCulture)); dynEl.SetAttribute("isVisible", el.IsVisible.ToString().ToLower()); dynEl.SetAttribute("isUpstreamVisible", el.IsUpstreamVisible.ToString().ToLower()); dynEl.SetAttribute("lacing", el.ArgumentLacing.ToString()); el.SaveNode(xmlDoc, dynEl, SaveContext.File); } //write only the output connectors var connectorList = xmlDoc.CreateElement("dynConnectors"); //write the root element root.AppendChild(connectorList); foreach (var el in workSpace.Nodes) { foreach (var port in el.OutPorts) { foreach ( var c in port.Connectors.Where(c => c.Start != null && c.End != null)) { var connector = xmlDoc.CreateElement(c.GetType().ToString()); connectorList.AppendChild(connector); connector.SetAttribute("start", c.Start.Owner.GUID.ToString()); connector.SetAttribute("start_index", c.Start.Index.ToString()); connector.SetAttribute("end", c.End.Owner.GUID.ToString()); connector.SetAttribute("end_index", c.End.Index.ToString()); if (c.End.PortType == PortType.INPUT) connector.SetAttribute("portType", "0"); } } } //save the notes var noteList = xmlDoc.CreateElement("dynNotes"); //write the root element root.AppendChild(noteList); foreach (var n in workSpace.Notes) { var note = xmlDoc.CreateElement(n.GetType().ToString()); noteList.AppendChild(note); note.SetAttribute("text", n.Text); note.SetAttribute("x", n.X.ToString(CultureInfo.InvariantCulture)); note.SetAttribute("y", n.Y.ToString(CultureInfo.InvariantCulture)); } return xmlDoc; } catch (Exception ex) { Debug.WriteLine(ex.Message + " : " + ex.StackTrace); return null; } }
public void HideWorkspace(dynWorkspaceModel workspace) { this.CurrentSpace = _workSpaces[0]; // typically the home workspace _workSpaces.Remove(workspace); _hiddenWorkspaces.Add(workspace); }
/// <summary> /// Remove a workspace from the dynamo model. /// </summary> /// <param name="workspace"></param> public void RemoveWorkspace(dynWorkspaceModel workspace) { _workSpaces.Remove(workspace); }
/// <summary> /// Generate the xml doc of the workspace from memory /// </summary> /// <param name="workSpace">The workspace</param> /// <param name="savingHomespace"></param> /// <returns>The generated xmldoc</returns> public static XmlDocument GetXmlDocFromWorkspace( dynWorkspaceModel workSpace, bool savingHomespace) { try { //create the xml document var xmlDoc = new XmlDocument(); xmlDoc.CreateXmlDeclaration("1.0", null, null); var root = xmlDoc.CreateElement("dynWorkspace"); //write the root element root.SetAttribute("X", workSpace.X.ToString(CultureInfo.InvariantCulture)); root.SetAttribute("Y", workSpace.Y.ToString(CultureInfo.InvariantCulture)); root.SetAttribute("zoom", workSpace.Zoom.ToString(CultureInfo.InvariantCulture)); root.SetAttribute("Description", workSpace.Description); root.SetAttribute("Category", workSpace.Category); root.SetAttribute("Name", workSpace.Name); if (!savingHomespace) //If we are not saving the home space { var guid = dynSettings.Controller.CustomNodeManager.GetGuidFromName(workSpace.Name); //friends don't let friends save an empty GUID if (guid == Guid.Empty) { guid = Guid.NewGuid(); } root.SetAttribute("ID", guid.ToString()); } xmlDoc.AppendChild(root); var elementList = xmlDoc.CreateElement("dynElements"); //write the root element root.AppendChild(elementList); foreach (var el in workSpace.Nodes) { var typeName = el.GetType().ToString(); var dynEl = xmlDoc.CreateElement(typeName); elementList.AppendChild(dynEl); //set the type attribute dynEl.SetAttribute("type", el.GetType().ToString()); dynEl.SetAttribute("guid", el.GUID.ToString()); dynEl.SetAttribute("nickname", el.NickName); dynEl.SetAttribute("x", el.X.ToString(CultureInfo.InvariantCulture)); dynEl.SetAttribute("y", el.Y.ToString(CultureInfo.InvariantCulture)); dynEl.SetAttribute("isVisible", el.IsVisible.ToString().ToLower()); dynEl.SetAttribute("isUpstreamVisible", el.IsUpstreamVisible.ToString().ToLower()); dynEl.SetAttribute("lacing", el.ArgumentLacing.ToString()); el.SaveNode(xmlDoc, dynEl, SaveContext.File); } //write only the output connectors var connectorList = xmlDoc.CreateElement("dynConnectors"); //write the root element root.AppendChild(connectorList); foreach (var el in workSpace.Nodes) { foreach (var port in el.OutPorts) { foreach ( var c in port.Connectors.Where(c => c.Start != null && c.End != null)) { var connector = xmlDoc.CreateElement(c.GetType().ToString()); connectorList.AppendChild(connector); connector.SetAttribute("start", c.Start.Owner.GUID.ToString()); connector.SetAttribute("start_index", c.Start.Index.ToString()); connector.SetAttribute("end", c.End.Owner.GUID.ToString()); connector.SetAttribute("end_index", c.End.Index.ToString()); if (c.End.PortType == PortType.INPUT) { connector.SetAttribute("portType", "0"); } } } } //save the notes var noteList = xmlDoc.CreateElement("dynNotes"); //write the root element root.AppendChild(noteList); foreach (var n in workSpace.Notes) { var note = xmlDoc.CreateElement(n.GetType().ToString()); noteList.AppendChild(note); note.SetAttribute("text", n.Text); note.SetAttribute("x", n.X.ToString(CultureInfo.InvariantCulture)); note.SetAttribute("y", n.Y.ToString(CultureInfo.InvariantCulture)); } return(xmlDoc); } catch (Exception ex) { Debug.WriteLine(ex.Message + " : " + ex.StackTrace); return(null); } }