/// <summary> /// Read shape data from XML stream and return it. /// </summary> /// <param name="reader"></param> /// <param name="parent"></param> /// <param name="umlType"></param> /// <returns></returns> public static UmlNodeShapeViewModel ReadDocument(XmlReader reader, IShapeParent parent, UmlTypes umlType) { UmlNodeShapeViewModel ret = UmlElementDataDef.CreateShape(umlType, new System.Windows.Point(UmlTypeToStringConverter.DefaultX, UmlTypeToStringConverter.DefaultY), parent) as UmlNodeShapeViewModel; reader.ReadToNextSibling(ret.UmlDataTypeString); while (reader.MoveToNextAttribute()) { if (ret.ReadAttributes(reader.Name, reader.Value) == false) { if (reader.Name.Trim().Length > 0 && reader.Name != UmlShapeBaseViewModel.XmlComment) { throw new ArgumentException("XML node:'" + reader.Name + "' as child of '" + ret.XElementName + "' is not supported."); } } } // Read common model information (eg. comments) UmlShapeBaseViewModel.ReadDocument(reader, ret); return(ret); }
/// <summary> /// Standard contructor hidding XElement constructor /// </summary> public UmlNoteShapeViewModel(IShapeParent parent, UmlTypes umlType) : base(parent, ShapeViewModelKey.NoteShape, ShapeViewModelSubKeys.None, umlType) { }
/// <summary> /// Roll forward to the next state. /// /// Page definition properties are not in scope of undo/redo /// </summary> /// <param name="parentOfShapes">Is necessary to create shapes with references to their parent.</param> public void Redo(IShapeParent parentOfShapes) { VerifyAccess(); VerifyState(ModelState.Ready, ModelState.Invalid); if (HasRedoData) { UndoState undoState = _RedoList.First.Value; string fragment = string.Empty; if (_DocRoot.Count > 0) { fragment = this.GetShapesAsXmlString(_DocRoot); } _UndoList.AddFirst(new UndoState(fragment, _HasUnsavedData)); _RedoList.RemoveFirst(); // Reload shape collection from this Xml formated (persistence) undo state RecreateShapeCollectionFromXml(parentOfShapes, undoState.DocRoot); _HasUnsavedData = undoState.HasUnsavedData; State = ModelState.Ready; NotifyPropertyChanged(() => HasUndoData); NotifyPropertyChanged(() => HasRedoData); NotifyPropertyChanged(() => HasUnsavedData); } }
/// <summary> /// Method is required by <seealso cref="IDragableCommandModel"/>. It is executed /// when the drag & drop operation on the canvas is infished with its last step /// (the creation of the viewmodel for the new item). /// </summary> /// <param name="dropPoint"></param> public void OnDragDropExecute(Point dropPoint) { IShapeParent parent = this.mViewModel.mWindowViewModel.vm_DocumentViewModel.vm_CanvasViewModel; this.AddShape(this.mViewModel.mWindowViewModel.vm_DocumentViewModel.vm_CanvasViewModel, UmlElementDataDef.CreateShape(this.mUmlType, dropPoint, parent)); }
/// <summary> /// Create a shape viewwmodel that represents a canvas element. /// </summary> /// <param name="dropPoint"></param> /// <returns></returns> private static ShapeViewModelBase CreateAssocationShapeViewModel(Point dropPoint, IShapeParent parent, DataDef item, UmlTypes umlType) { var element = new UmlUseCaseShapeViewModel(parent, umlType); switch (umlType) { case UmlTypes.ConnectorAggregation: return(new UmlAssociationShapeViewModel(parent, ConnectorKeys.WhiteDiamond, ConnectorKeys.None, UmlTypes.ConnectorAggregation)); case UmlTypes.ConnectorAssociation: return(new UmlAssociationShapeViewModel(parent, ConnectorKeys.None, ConnectorKeys.None, UmlTypes.ConnectorAssociation)); case UmlTypes.ConnectorComposition: return(new UmlAssociationShapeViewModel(parent, ConnectorKeys.BlackDiamond, ConnectorKeys.None, UmlTypes.ConnectorComposition)); case UmlTypes.ConnectorInheritance: return(new UmlAssociationShapeViewModel(parent, ConnectorKeys.None, ConnectorKeys.Triangle, UmlTypes.ConnectorInheritance)); default: throw new System.NotImplementedException(umlType.ToString()); } }
public override PageViewModelBase LoadDocument(string fileName, IShapeParent docDataModel, out List <ShapeViewModelBase> docRoot) { docRoot = new List <ShapeViewModelBase>(); PageViewModel root = null; try { root = new PageViewModel(); try { using (XmlReader reader = XmlReader.Create(fileName)) { return(this.ReadXML(reader, docDataModel, root, out docRoot)); } } catch (Exception) { throw; } } catch (Exception) { throw; } }
/// <summary> /// Roll forward to the next state. /// /// Page definition properties are not in scope of undo/redo /// </summary> /// <param name="parentOfShapes">Is necessary to create shapes with references to their parent.</param> public void Redo(IShapeParent parentOfShapes) { this.VerifyAccess(); this.VerifyState(ModelState.Ready, ModelState.Invalid); if (this.HasRedoData) { UndoState undoState = this.mRedoList.First.Value; string fragment = string.Empty; if (this.mDocRoot.Count > 0) { fragment = this.GetShapesAsXmlString(this.mDocRoot); } this.mUndoList.AddFirst(new UndoState(fragment, this.mHasUnsavedData)); this.mRedoList.RemoveFirst(); // Reload shape collection from this Xml formated (persistence) undo state this.RecreateShapeCollectionFromXml(parentOfShapes, undoState.DocRoot); this.mHasUnsavedData = undoState.HasUnsavedData; this.State = ModelState.Ready; this.SendPropertyChanged("HasUndoData", "HasRedoData", "HasUnsavedData"); } }
/// <summary> /// Recreate document collection from Xml persistence in a string. /// </summary> /// <param name="parentOfShapes"></param> /// <param name="xmlText"></param> private void RecreateShapeCollectionFromXml(IShapeParent parentOfShapes, string xmlText) { // Look-up plugin model string plugin = this.PluginModelName; PluginModelBase m = PluginManager.GetPluginModel(plugin); // Look-up shape converter UmlTypeToStringConverterBase conv = null; conv = m.ShapeConverter; // Convert Xml document into a list of shapes and page definition List <ShapeViewModelBase> coll; PageViewModelBase page = conv.ReadDocument(xmlText, parentOfShapes, out coll); if (coll == null) { return; } if (coll.Count == 0) { return; } // Page definition properties are not in scope of undo/redo this.ResetDocRoot(coll); }
/// <summary> /// Standard contructor hidding XElement constructor /// </summary> public UmlCanvasShapeViewModel(IShapeParent parent, ShapeViewModelSubKeys canvasShape, UmlTypes umlType) : base(parent, ShapeViewModelKey.CanvasShape, canvasShape, umlType) { this.mCanvasShape = canvasShape; }
/// <summary> /// Standard contructor hidding XElement constructor /// </summary> public UmlUseCaseShapeViewModel(IShapeParent parent, UmlTypes umlType) : base(parent, ShapeViewModelKey.UseCaseShape, ShapeViewModelSubKeys.None, umlType) { this.MinHeight = 50; this.MinWidth = 50; }
private PageViewModel ReadXML(XmlReader reader, IShapeParent docDataModel, PageViewModel root, out List <ShapeViewModelBase> docRoot) { docRoot = new List <ShapeViewModelBase>(); reader.ReadToNextSibling(PageViewModel.XmlElementName); while (reader.MoveToNextAttribute()) { if (root.ReadAttribute(reader.Name, reader.Value) == false) { return(root); } } // Read child elements of this XML node while (reader.Read()) { if (reader.NodeType == XmlNodeType.Element) { string nodeName = reader.Name; object o = this.ConvertBack(nodeName, nodeName.GetType(), null, CultureInfo.InvariantCulture); if ((o is UmlTypes) == false) { throw new ArgumentException("Node name: '" + nodeName + "' is not supported."); } UmlTypes umlType = (UmlTypes)o; if (umlType == UmlTypes.Undefined) { throw new ArgumentException("Undefined node name: '" + nodeName + "' in conversion is not supported."); } ShapeViewModelBase s = null; try { s = UmlElementDataDef.ReadShape(reader, umlType, docDataModel); if (s != null) { docRoot.Add(s); } } catch (Exception) { throw; } } } return(root); }
/// <summary> /// Standard contructor hidding XElement constructor /// </summary> public UmlAssociationShapeViewModel(IShapeParent parent, ConnectorKeys fromConnectorKey, ConnectorKeys toConnectorKey, UmlTypes umlType) : base(parent) { this.mUmlType = umlType; this.mFromConnectorKey = fromConnectorKey; this.mToConnectorKey = toConnectorKey; this.mElementName = UmlTypeToStringConverter.Instance.Convert(umlType, umlType.GetType(), null, System.Globalization.CultureInfo.InvariantCulture) as string; }
/// <summary> /// Method is required by <seealso cref="IDragableCommandModel"/>. It is executed /// when the drag & drop operation on the canvas is infished with its last step /// (the creation of the viewmodel for the new item). /// </summary> /// <param name="dropPoint"></param> public void OnDragDropExecute(Point dropPoint) { var model = this.mViewModel.mWindowViewModel.vm_DocumentViewModel; model.v_CanvasView.ForceCursor = true; model.v_CanvasView.Cursor = Cursors.Pen; IShapeParent parent = model.vm_CanvasViewModel; // Tell the canvas view model that we are about to change the mode of 'object selection' // to one which allows us to connect things on the canvas. model.vm_CanvasViewModel.BeginCanvasViewMouseHandler( new CreateAssociationMouseHandler(model, UmlElementDataDef.CreateShape(this.mUmlType, dropPoint, parent) as UmlAssociationShapeViewModel)); }
/// <summary> /// Create a shape viewwmodel that represents a canvas element. /// </summary> /// <param name="dropPoint"></param> /// <returns></returns> private static ShapeViewModelBase CreateCanvasShapeViewModel(Point dropPoint, IShapeParent parent, DataDef item, UmlTypes umlType) { var element = new UmlCanvasShapeViewModel(parent, item.ShapeViewModelSubKey, umlType); element.Name = item.ShapeName; element.Top = dropPoint.Y; element.Left = dropPoint.X; element.Width = item.DefaultWidth; element.Height = item.DefaultHeight; return(element); }
/// <summary> /// Create a shape viewwmodel that represents a canvas element. /// </summary> /// <param name="dropPoint"></param> /// <returns></returns> private static ShapeViewModelBase CreateNoteShapeViewModel(Point dropPoint, IShapeParent parent, DataDef item, UmlTypes umlType) { var element = new UmlNoteShapeViewModel(parent, umlType); element.Text = item.ToolboxName; element.Top = dropPoint.Y; element.Left = dropPoint.X; element.Width = item.DefaultWidth; element.Height = item.DefaultHeight; return(element); }
/// <summary> /// Standard constructor /// </summary> /// <param name="parent"></param> /// <param name="ElementName"></param> /// <param name="shapeKey"></param> /// <param name="shapeViewModelSubKeys"></param> public UmlShapeBaseViewModel(IShapeParent parent, ShapeViewModelKey shapeKey, ShapeViewModelSubKeys shapeViewModelSubKeys, UmlTypes umlType) : base(parent) { this.mShapeKey = shapeKey; this.mShapeViewModelSubKeys = shapeViewModelSubKeys; this.mUmlType = umlType; this.mComments = new ObservableCollection <CommentViewModel>(); this.mElementName = UmlTypeToStringConverter.Instance.Convert(umlType, umlType.GetType(), null, CultureInfo.InvariantCulture) as string; }
public static UmlAssociationShapeViewModel ReadDocument(XmlReader reader, IShapeParent parent, UmlTypes umlType) { UmlAssociationShapeViewModel ret = UmlElementDataDef.CreateShape(umlType, new System.Windows.Point(UmlTypeToStringConverter.DefaultX, UmlTypeToStringConverter.DefaultY), parent) as UmlAssociationShapeViewModel; reader.ReadToNextSibling(ret.UmlDataTypeString); while (reader.MoveToNextAttribute()) { if (ret.ReadAttributes(reader.Name, reader.Value) == false) { if (reader.Name.Trim().Length > 0 && reader.Name != XmlComment) { throw new ArgumentException("XML node:'" + reader.Name + "' as child of '" + ret.UmlDataTypeString + "' is not supported."); } } } // Read child elements of this XML node while (reader.Read()) { if (reader.NodeType == XmlNodeType.Element) { switch (reader.Name) { case "Anchor": AnchorViewModel p = new AnchorViewModel(parent) { Left = 0, Top = 0 }; AnchorViewModel.ReadDocument(reader.ReadSubtree(), parent, p); ret.Add(p); break; default: throw new NotImplementedException(string.Format("'{0}' is not a valid sub-node of {1}", reader.Name, ret.XElementName)); } } } return(ret); }
/// <summary> /// Create a shape viewwmodel that represents a canvas element. /// </summary> /// <param name="dropPoint"></param> /// <returns></returns> private static ShapeViewModelBase CreateUseCaseShapeViewModel(Point dropPoint, IShapeParent parent, DataDef item, UmlTypes umlType) { var element = new UmlUseCaseShapeViewModel(parent, umlType); element.Name = item.ShapeName; element.Top = dropPoint.Y; element.Left = dropPoint.X; element.Width = item.DefaultWidth; element.Height = item.DefaultHeight; element.StrokeDashArray = (item.StrokeDashArray == null ? string.Empty : item.StrokeDashArray); return(element); }
internal static AnchorViewModel ReadDocument(XmlReader reader, IShapeParent parent, AnchorViewModel anchor) { reader.ReadToNextSibling(anchor.XElementName); while (reader.MoveToNextAttribute()) { if (anchor.ReadAttributes(reader.Name, reader.Value) == false) { throw new NotImplementedException(string.Format("The attribute '{0}' is not supported in '{1}'.", reader.Name, anchor.XElementName)); } } return(anchor); }
/// <summary> /// Create a shape viewwmodel that represents a canvas element. /// </summary> /// <param name="dropPoint"></param> /// <returns></returns> private static ShapeViewModelBase CreateNodeShapeViewModel(Point dropPoint, IShapeParent parent, DataDef item, UmlTypes umlType) { var element = new UmlNodeShapeViewModel(parent, umlType); element.Stereotype = item.ShapeStereotype == null ? string.Empty : item.ShapeStereotype; element.Name = item.ShapeName; element.ShapeImageUrl = item.ShapeImageUrl == null ? string.Empty : item.ShapeImageUrl; element.Top = dropPoint.Y; element.Left = dropPoint.X; element.Width = item.DefaultWidth; element.Height = item.DefaultHeight; return(element); }
/// <summary> /// Create a shape viewwmodel that represents a canvas element. /// </summary> /// <param name="dropPoint"></param> /// <returns></returns> private static ShapeViewModelBase CreateDecisionShapeViewModel(Point dropPoint, IShapeParent parent, DataDef item, UmlTypes umlType) { var element = new UmlDecisionShapeViewModel(parent, umlType); element.Name = item.ShapeName; if (dropPoint == null) { dropPoint = new Point(100, 100); } element.Top = dropPoint.Y; element.Left = dropPoint.X; element.Width = item.DefaultWidth; element.Height = item.DefaultHeight; return(element); }
/// <summary> /// Read shape from XML stream and return it. /// </summary> /// <param name="reader"></param> /// <param name="parent"></param> /// <param name="umlType"></param> /// <returns></returns> public static UmlNoteShapeViewModel ReadDocument(XmlReader reader, IShapeParent parent, UmlTypes umlType) { UmlNoteShapeViewModel ret = UmlElementDataDef.CreateShape(umlType, new System.Windows.Point(UmlTypeToStringConverter.DefaultX, UmlTypeToStringConverter.DefaultY), parent) as UmlNoteShapeViewModel; reader.ReadToNextSibling(ret.UmlDataTypeString); while (reader.MoveToNextAttribute()) { if (ret.ReadAttributes(reader.Name, reader.Value) == false) { if (reader.Name.Trim().Length > 0 && reader.Name != UmlShapeBaseViewModel.XmlComment) { throw new ArgumentException("XML node:'" + reader.Name + "' as child of '" + ret.XElementName + "' is not supported."); } } } // Read child elements of this XML node while (reader.Read()) { if (reader.NodeType == XmlNodeType.Element) { string nodeName = reader.Name; string error; if ((error = ret.ReadXMLNode(nodeName, reader)) != string.Empty) { throw new NotImplementedException(error); } } } return(ret); }
/// <summary> /// Read a shapes configiration information from persistence and return the new shape view model. /// </summary> /// <param name="reader"></param> /// <param name="umlType"></param> /// <param name="parent"></param> /// <returns></returns> public static ShapeViewModelBase ReadShape(XmlReader reader, UmlTypes umlType, IShapeParent parent) { switch (umlType) { case UmlTypes.Primitive: case UmlTypes.DataType: case UmlTypes.Signal: case UmlTypes.Class: case UmlTypes.Interface: case UmlTypes.Table: case UmlTypes.Enumeration: case UmlTypes.Component: return(UmlSquareShapeViewModel.ReadDocument(reader.ReadSubtree(), parent, umlType)); case UmlTypes.Decision: return(UmlDecisionShapeViewModel.ReadDocument(reader.ReadSubtree(), parent, umlType)); case UmlTypes.Package: return(UmlPackageShapeViewModel.ReadDocument(reader.ReadSubtree(), parent, umlType)); case UmlTypes.Boundary: return(UmlBoundaryShapeViewModel.ReadDocument(reader.ReadSubtree(), parent, umlType)); case UmlTypes.Note: return(UmlNoteShapeViewModel.ReadDocument(reader.ReadSubtree(), parent, umlType)); case UmlTypes.Node: case UmlTypes.Device: case UmlTypes.DeploymentSpec: return(UmlNodeShapeViewModel.ReadDocument(reader.ReadSubtree(), parent, umlType)); case UmlTypes.Collaboration: case UmlTypes.UseCase: return(UmlUseCaseShapeViewModel.ReadDocument(reader.ReadSubtree(), parent, umlType)); case UmlTypes.CanvasShape: case UmlTypes.Actor: case UmlTypes.Actor1: case UmlTypes.ActivityInitial: case UmlTypes.ActivityFinal: case UmlTypes.ActivityFlowFinal: case UmlTypes.ActivitySync: case UmlTypes.Event1: case UmlTypes.Event2: case UmlTypes.Action1: case UmlTypes.Action2: case UmlTypes.ExecutionEnvironment: return(UmlCanvasShapeViewModel.ReadDocument(reader.ReadSubtree(), parent, umlType)); case UmlTypes.ConnectorAggregation: case UmlTypes.ConnectorAssociation: case UmlTypes.ConnectorComposition: case UmlTypes.ConnectorInheritance: return(UmlAssociationShapeViewModel.ReadDocument(reader.ReadSubtree(), parent, umlType)); case UmlTypes.Undefined: default: throw new NotImplementedException(string.Format("System error: '{0}' not supported in ReadShape.", umlType)); } throw new NotImplementedException(umlType.ToString()); }
/// <summary> /// Create a shape viewmodel and return it. /// </summary> /// <param name="umlType"></param> /// <param name="dropPoint"></param> /// <param name="parent"></param> /// <returns></returns> public static ShapeViewModelBase CreateShape(UmlTypes umlType, Point dropPoint, IShapeParent parent) { DataDef item; if (UmlElementDataDef.mUmlElements.TryGetValue(umlType, out item) == true) { switch (item.ImplementingViewModel) { case ShapeViewModelKey.SquareShape: return(CreateSquareShapeViewModel(dropPoint, parent, item, umlType)); case ShapeViewModelKey.DecisionShape: return(CreateDecisionShapeViewModel(dropPoint, parent, item, umlType)); case ShapeViewModelKey.PackageShape: return(CreatePackageShapeViewModel(dropPoint, parent, item, umlType)); case ShapeViewModelKey.BoundaryShape: return(CreateBoundaryShapeViewModel(dropPoint, parent, item, umlType)); case ShapeViewModelKey.NoteShape: return(CreateNoteShapeViewModel(dropPoint, parent, item, umlType)); case ShapeViewModelKey.NodeShape: return(CreateNodeShapeViewModel(dropPoint, parent, item, umlType)); case ShapeViewModelKey.UseCaseShape: return(CreateUseCaseShapeViewModel(dropPoint, parent, item, umlType)); case ShapeViewModelKey.CanvasShape: return(CreateCanvasShapeViewModel(dropPoint, parent, item, umlType)); case ShapeViewModelKey.AssocationShape: return(CreateAssocationShapeViewModel(dropPoint, parent, item, umlType)); case ShapeViewModelKey.Undefined: default: throw new NotImplementedException(string.Format("System error: '{0}' not supported in CreateShape.", umlType)); } } throw new NotImplementedException(umlType.ToString()); }
/// <summary> /// Standard contructor /// </summary> public ShapeSizeViewModelBase(IShapeParent parent) : base(parent) { }
/// <summary> /// Standard contructor /// </summary> public ShapeViewModelBase(IShapeParent parent) { this._Parent = parent; }
/// <summary> /// Standard contructor hidding XElement constructor /// </summary> /// <param name="parent"></param> public AnchorBaseViewModel(IShapeParent parent) : base(parent) { }
/// <summary> /// Load a document from file persistence. /// </summary> /// <param name="filename"></param> /// <param name="docDataModel"></param> /// <param name="docRoot"></param> /// <returns></returns> public abstract PageViewModelBase LoadDocument(string filename, IShapeParent docDataModel, out List <ShapeViewModelBase> docRoot);
/// <summary> /// Load a document from string persistence. /// </summary> /// <param name="xml"></param> /// <param name="docDataModel"></param> /// <param name="docRoot"></param> /// <returns></returns> public abstract PageViewModelBase ReadDocument(string xml, IShapeParent docDataModel, out List <ShapeViewModelBase> docRoot);