コード例 #1
0
            public void DeleteShapesForElement(DomainModelLink element)
            {
                if (element == null)
                {
                    return;
                }

                DomainModelLink            link = element;
                DiagramDomainDataDirectory data = link.Store.DomainDataAdvDirectory.ResolveExtensionDirectory <DiagramDomainDataDirectory>();

                DomainModelElement m      = DomainRoleInfo.GetSourceRolePlayer(link) as DomainModelElement;
                List <Guid>        shapes = data.GetShapeTypesForElement(m.GetDomainClassId());

                if (shapes == null)
                {
                    return;
                }
                foreach (Guid g in shapes)
                {
                    if (data.MappingRelationshipShapeInfos.ContainsKey(g))
                    {
                        this.DeleteShapesForElement(m.Store, m.Id, g);
                        return;
                    }
                }
            }
コード例 #2
0
            public virtual void AddRSShapesForElement(DomainModelLink modelElement)
            {
                if (modelElement == null)
                {
                    return;
                }

                DiagramDomainDataDirectory data = modelElement.Store.DomainDataAdvDirectory.ResolveExtensionDirectory <DiagramDomainDataDirectory>();

                if (data == null)
                {
                    throw new ArgumentNullException("DiagramDomainDataDirectory");
                }

                List <Guid> shapes = data.GetShapeTypesForElement(modelElement.GetDomainClassId());

                if (shapes != null)
                {
                    if (shapes.Count > 0)
                    {
                        DomainModelElement source = DomainRoleInfo.GetSourceRolePlayer(modelElement) as DomainModelElement;
                        DomainModelElement target = DomainRoleInfo.GetTargetRolePlayer(modelElement) as DomainModelElement;
                        foreach (Guid shape in shapes)
                        {
                            AddRSShapesForElement(source, target, modelElement, shape);
                        }
                    }
                }
            }
            public void DeleteShapesForElement(DomainModelElement element)
            {
                if (element == null)
                    return;

                DeleteShapesForElement(element.Store, element.Id);
            }
            public virtual void AddMappingRSShapesForElement(DomainModelElement modelElement)
            {
                if (modelElement == null)
                    return;

                DiagramDomainDataDirectory data = modelElement.Store.DomainDataAdvDirectory.ResolveExtensionDirectory<DiagramDomainDataDirectory>();
                if (data == null)
                    throw new ArgumentNullException("DiagramDomainDataDirectory");


                List<Guid> shapes = data.GetShapeTypesForElement(modelElement.GetDomainClassId());
                if (shapes == null)
                    return;
                foreach (Guid g in shapes)
                    if (data.MappingRelationshipShapeInfos.ContainsKey(g))
                    {
                        MappingRelationshipShapeInfo info = data.MappingRelationshipShapeInfos[g];

                        // see if the required relationships exist
                        ReadOnlyCollection<ElementLink> colSource = DomainRoleInfo.GetElementLinks<ElementLink>(modelElement, info.SourceDomainRole);
                        if (colSource.Count != 1)
                            return;

                        ReadOnlyCollection<ElementLink> colTarget = DomainRoleInfo.GetElementLinks<ElementLink>(modelElement, info.TargetDomainRole);
                        if (colTarget.Count != 1)
                            return;

                        DomainModelElement source = DomainRoleInfo.GetTargetRolePlayer(colSource[0]) as DomainModelElement;
                        DomainModelElement target = DomainRoleInfo.GetTargetRolePlayer(colTarget[0]) as DomainModelElement;


                        AddRSShapesForElement(source, target, modelElement, g);
                    }
            }
コード例 #5
0
            public virtual void AddShapesForElement(DomainModelElement modelElement)
            {
                DomainModelElement parent = modelElement.GetDomainModelServices().ElementParentProvider.GetEmbeddingParent(modelElement) as DomainModelElement;
                DomainModelElement child  = modelElement;

                AddShapesForElement(parent, child);
            }
コード例 #6
0
        /// <summary>
        /// Called whenever a model element is deleted from the store.
        /// </summary>
        /// <param name="sender">ViewModelStore</param>
        /// <param name="args">Event Arguments for notification of the removal of an ModelElement.</param>
        private void OnElementDeleted(object sender, ElementDeletedEventArgs args)
        {
            if (args.ModelElement is DomainModelElement)
            {
                DomainModelElement modelElement = args.ModelElement as DomainModelElement;

                List <Guid> shapes = GraphicalDependencyShapeStore.GetFromStore(modelElement.Id);
                if (shapes != null)
                {
                    if (shapes.Count > 0)
                    {
                        modelElement.Store.UndoManager.UndoState = UndoState.DisabledNoFlush;
                        using (Transaction t = modelElement.Store.TransactionManager.BeginTransaction("", true))
                        {
                            for (int i = shapes.Count - 1; i >= 0; i--)
                            {
                                ShapeElement shape = modelElement.Store.ElementDirectory.FindElement(shapes[i]) as ShapeElement;
                                if (shape != null)
                                {
                                    shape.Delete();
                                }
                            }
                            t.Commit();
                        }
                        modelElement.Store.UndoManager.UndoState = UndoState.Enabled;
                        GraphicalDependencyShapeStore.RemoveFromStore(modelElement.Id);
                    }
                }
            }
        }
コード例 #7
0
            public virtual void AddRootShapesForElement(DomainModelElement modelElement)//, bool bIgnoreVisualizationBehavior)
            {
                DiagramDomainDataDirectory data    = modelElement.Store.DomainDataAdvDirectory.ResolveExtensionDirectory <DiagramDomainDataDirectory>();
                IDomainModelServices       topMost = modelElement.GetDomainModelServices().TopMostService;

                List <Guid> shapeIds = data.GetRootShapeTypesForElement(modelElement.GetDomainClassId());

                if (shapeIds != null)
                {
                    foreach (Guid shapeId in shapeIds)
                    {
                        ShapeClassInfo shapeInfo = data.ShapeClassInfos[shapeId];
                        ReadOnlyCollection <ModelElement> diagrams = modelElement.Store.ElementDirectory.FindElements(shapeInfo.DiagramClassType);
                        if (diagrams.Count == 0)
                        {
                            continue;
                        }
                        foreach (Diagram d in diagrams)
                        {
                            if (d.IsVisible && d.CanHostShape(shapeId))
                            {
                                if (!DiagramHelper.IsElementDisplayedOn(d, shapeId, modelElement.Id))
                                {
                                    NodeShape shape = topMost.ShapeProvider.CreateShapeForElement(shapeId, modelElement) as NodeShape;
                                    d.Children.Add(shape);
                                    DiagramsShapeStore.AddToStore(shape.Element.Id, shape.Id);
                                    shape.FixUpMissingLinkShapes();
                                }
                            }
                        }
                    }
                }
            }
コード例 #8
0
 public virtual void AddShapesForElement(DomainModelElement modelElement)
 {
     DomainModelElement parent = modelElement.GetDomainModelServices().ElementParentProvider.GetEmbeddingParent(modelElement) as DomainModelElement;
     DomainModelElement child = modelElement;
     
     AddShapesForElement(parent, child);
 }
コード例 #9
0
        /// <summary>
        /// Called whenever a model element is beeing deleted.
        /// </summary>
        /// <param name="e"></param>
        public override void ElementDeleting(ElementDeletingEventArgs e)
        {
            base.ElementDeleting(e);

            DomainModelElement modelElement = e.ModelElement as DomainModelElement;

            if (modelElement == null)
            {
                return;
            }


            List <Guid> shapes = GraphicalDependencyShapeStore.GetFromStore(modelElement.Id);

            if (shapes != null)
            {
                modelElement.Store.UndoManager.UndoState = UndoState.DisabledNoFlush;
                using (Transaction t = modelElement.Store.TransactionManager.BeginTransaction("", true))
                {
                    for (int i = shapes.Count - 1; i >= 0; i--)
                    {
                        ShapeElement shape = modelElement.Store.ElementDirectory.FindElement(shapes[i]) as ShapeElement;
                        if (shape != null)
                        {
                            shape.Delete();
                        }
                    }
                    t.Commit();
                }
                modelElement.Store.UndoManager.UndoState = UndoState.Enabled;
            }
        }
コード例 #10
0
            public virtual void AddRootShapesForElement(DomainModelElement modelElement)//, bool bIgnoreVisualizationBehavior)
            {
                DiagramDomainDataDirectory data = modelElement.Store.DomainDataAdvDirectory.ResolveExtensionDirectory<DiagramDomainDataDirectory>();
                IDomainModelServices topMost = modelElement.GetDomainModelServices().TopMostService;

                List<Guid> shapeIds = data.GetRootShapeTypesForElement(modelElement.GetDomainClassId());
                if (shapeIds != null)
                    foreach (Guid shapeId in shapeIds)
                    {
                        ShapeClassInfo shapeInfo = data.ShapeClassInfos[shapeId];
                        ReadOnlyCollection<ModelElement> diagrams = modelElement.Store.ElementDirectory.FindElements(shapeInfo.DiagramClassType);
                        if (diagrams.Count == 0)
                            continue;
                        foreach (Diagram d in diagrams)
                        {
                            if (d.IsVisible && d.CanHostShape(shapeId))
                            {
                                if (!DiagramHelper.IsElementDisplayedOn(d, shapeId, modelElement.Id))
                                {
                                    NodeShape shape = topMost.ShapeProvider.CreateShapeForElement(shapeId, modelElement) as NodeShape;
                                    d.Children.Add(shape);
                                    DiagramsShapeStore.AddToStore(shape.Element.Id, shape.Id);
                                    shape.FixUpMissingLinkShapes();
                                }
                            }
                        }
                    }
            }
コード例 #11
0
        /*
         * /// <summary>
         * /// Tries to find a free position on parent and update the location of the shape to that location.
         * /// </summary>
         * /// <returns>
         * /// Coordinates of a free position.
         * /// </returns>
         * /// <remarks>
         * /// Needs to be called within a modeling transaction.
         * /// </remarks>
         * public virtual void SetAtFreePositionOnParent()
         * {
         *  IList<NodeShape> shapes;
         *  if (this.Parent == null)
         *  {
         *      // free position on diagram
         *      Diagram diagram = this.Diagram;
         *      shapes = diagram.Children;
         *  }
         *  else
         *  {
         *      if (this.IsRelativeChildShape)
         *      {
         *          float width = (float)this.Bounds.Width;
         *          float height = (float)this.Bounds.Height;
         *
         *          float parentWidth = (float)this.Parent.Bounds.Width;
         *          float parentHeight = (float)this.Parent.Bounds.Height;
         *
         *          Dictionary<PortPlacement, int> dict = new Dictionary<PortPlacement, int>();
         *          dict.Add(PortPlacement.Left, 0);
         *          dict.Add(PortPlacement.Top, 0);
         *          dict.Add(PortPlacement.Bottom, 0);
         *          dict.Add(PortPlacement.Right, 0);
         *          for (int i = 0; i < this.Parent.RelativeChildren.Count; i++)
         *          {
         *              if (this.Parent.RelativeChildren[i] == this)
         *                  continue;
         *
         *              dict[this.Parent.RelativeChildren[i].PlacementSide]++;
         *          }
         *          List<KeyValuePair<PortPlacement, int>> myList = new List<KeyValuePair<PortPlacement, int>>(dict);
         *          myList.Sort((firstPair, nextPair) =>
         *          {
         *              return firstPair.Value.CompareTo(nextPair.Value);
         *          });
         *
         *          foreach (KeyValuePair<PortPlacement, int> p in myList)
         *          {
         *              RectangleF rectH;
         *              switch (p.Key)
         *              {
         *                  case PortPlacement.Left:
         *                      rectH = new RectangleF(-width / 2, 0, width, parentHeight);
         *                      break;
         *
         *                  case PortPlacement.Top:
         *                      rectH = new RectangleF(0, -height / 2, parentWidth, height);
         *                      break;
         *
         *                  case PortPlacement.Right:
         *                      rectH = new RectangleF(parentWidth - width / 2, 0, width, parentHeight);
         *                      break;
         *
         *                  case PortPlacement.Bottom:
         *                      rectH = new RectangleF(0, parentHeight - height / 2, parentWidth, height);
         *                      break;
         *
         *                  default:
         *                      throw new NotSupportedException();
         *              }
         *
         *              if (SetPortAtFreePositionOnParent(p.Key, rectH))
         *              {
         *                  return;
         *              }
         *          }
         *
         *          this.SetLocation(NodeShape.CorrectPortLocation(this.Parent, this, new PointD(0, 0)));
         *          return;
         *      }
         *
         *      // free position on parent shape
         *      shapes = this.Parent.NestedChildren;
         *  }
         *
         *  // trivial algo.. TODO: find something good
         *  RectangleF rect = new RectangleF(0, 0, (float)this.Size.Width, (float)this.Size.Height);
         *
         *  // find area that is already filled
         *  RectangleF completeBounds = new RectangleF(0, 0, 0, 0);
         *  for (int i = 0; i < shapes.Count; i++)
         *  {
         *      if (shapes[i] == this)
         *          continue;
         *
         *      if (i == 0)
         *          completeBounds = shapes[i].Bounds.ToRectangleF();
         *      else
         *      {
         *          RectangleF f = shapes[i].Bounds.ToRectangleF();
         *          if (completeBounds.X > f.X)
         *              completeBounds.X = f.X;
         *          if (completeBounds.Y > f.Y)
         *              completeBounds.Y = f.Y;
         *
         *          if (completeBounds.Right < f.Right)
         *              completeBounds.Width = f.Right - completeBounds.X;
         *
         *          if (completeBounds.Bottom < f.Bottom)
         *              completeBounds.Height = f.Bottom - completeBounds.Y;
         *      }
         *  }
         *
         *  /*
         *  // see if we can insert shape somewhere in that area
         *  // if not, add shape right at the edge of that area
         *  for (int i = 0; i < shapes.Count; i++)
         *  {
         *      if (shapes[i] == this)
         *          continue;
         *
         *      // TODO ... (not necessaraly required)
         *  }
         *
         *  // could not add shape in the completeBounds are, so add it outside of it
         */
        /*
         *  if( completeBounds.Width < completeBounds.Height )
         *      this.SetLocation(new PointD(completeBounds.Right + 5, 5));
         *  else
         *      this.SetLocation(new PointD(5, completeBounds.Bottom + 5));
         *  this.UpdateAbsoluteLocation();
         * }
         *
         * private bool SetPortAtFreePositionOnParent(PortPlacement side, RectangleF freeRectangle)
         * {
         *  List<RectangleF> freeRectangles = new List<RectangleF>();
         *  freeRectangles.Add(freeRectangle);
         *
         *  for (int i = 0; i < this.Parent.RelativeChildren.Count; i++)
         *  {
         *      if (this.Parent.RelativeChildren[i] == this)
         *          continue;
         *
         *      if (this.Parent.RelativeChildren[i].PlacementSide != side)
         *          continue;
         *
         *      RectangleF s = this.Parent.RelativeChildren[i].Bounds.ToRectangleF();
         *      for (int y = freeRectangles.Count - 1; y >= 0; y--)
         *      {
         *          RectangleF r = freeRectangles[y];
         *          RectangleF t = r;
         *          r.Intersect(s);
         *
         *          if (!r.IsEmpty)
         *          {
         *              // remove r from freeRectangley[y] --> yields <=2 rects
         *              // add 2 rects to freeRectangles
         *              freeRectangles.RemoveAt(y);
         *
         *              switch (side)
         *              {
         *                  case PortPlacement.Left:
         *                  case PortPlacement.Right:
         *                      if (t.Y < r.Y)
         *                      {
         *                          // first r
         *                          RectangleF r1 = new RectangleF(t.X, t.Y, t.Width, r.Y - t.Y);
         *                          freeRectangles.Add(r1);
         *                      }
         *
         *                      if (r.Bottom < t.Bottom)
         *                      {
         *                          // second r
         *                          RectangleF r2 = new RectangleF(t.X, r.Bottom, t.Width, t.Bottom - r.Bottom);
         *                          freeRectangles.Add(r2);
         *                      }
         *                      break;
         *
         *                  case PortPlacement.Top:
         *                  case PortPlacement.Bottom:
         *                      if (t.X < r.X)
         *                      {
         *                          // first r
         *                          RectangleF r1 = new RectangleF(t.X, t.Y, r.X-t.X, t.Height);
         *                          freeRectangles.Add(r1);
         *                      }
         *
         *                      if (r.Right < t.Right)
         *                      {
         *                          // second r
         *                          RectangleF r2 = new RectangleF(r.Right, t.Y, t.Right-r.Right, t.Height);
         *                          freeRectangles.Add(r2);
         *                      }
         *                      break;
         *              }
         *
         *          }
         *      }
         *  }
         *
         *  // try to place at a fitting free rectangle
         *  foreach (RectangleF r in freeRectangles)
         *  {
         *      if (r.Width >= this.Bounds.Width && r.Height >= this.Bounds.Height)
         *      {
         *          this.Location = new PointD(r.X, r.Y);
         *          this.PlacementSide = side;
         *          this.UpdateAbsoluteLocation();
         *          return true;
         *      }
         *  }
         *
         *  return false;
         * }
         */

        /// <summary>
        /// Create missing shapes.
        /// </summary>
        public virtual void FixUpMissingShapes()
        {
            if (this.Element == null)
            {
                return;
            }

            DomainModelElement e = this.Element as DomainModelElement;

            IDomainModelServices       topMost = e.GetDomainModelServices().TopMostService;
            DiagramDomainDataDirectory data    = this.Store.DomainDataAdvDirectory.ResolveExtensionDirectory <DiagramDomainDataDirectory>();

            List <EmbeddingRelationshipAdvancedInfo> infos = this.Store.DomainDataAdvDirectory.FindDomainClassSourceEmbeddings(e.GetDomainClassId());

            if (infos != null)
            {
                foreach (EmbeddingRelationshipAdvancedInfo info in infos)
                {
                    List <Guid> shapes = data.GetShapeTypesForElement(info.TargetElementDomainClassId);
                    if (shapes == null)
                    {
                        continue;
                    }
                    if (shapes.Count == 0)
                    {
                        continue;
                    }

                    ReadOnlyCollection <ElementLink> instances = DomainRoleInfo.GetElementLinks <ElementLink>(this.Element, info.SourceRoleId);
                    foreach (ElementLink link in instances)
                    {
                        DomainModelElement child = DomainRoleInfo.GetTargetRolePlayer(link) as DomainModelElement;
                        if (child == null)
                        {
                            continue;
                        }

                        // see if we need to add shape
                        foreach (Guid elementShapeId in data.GetShapeTypesForElement(child.GetDomainClassId(), this.GetDomainClassId()))
                        {
                            if (!DiagramHelper.IsElementDisplayedOn(this, elementShapeId, child.Id))
                            {
                                NodeShape shape = topMost.ShapeProvider.CreateShapeForElement(elementShapeId, child) as NodeShape;
                                if (shape.IsRelativeChildShape)
                                {
                                    this.AddRelativeChild(shape);
                                }
                                else
                                {
                                    this.AddNestedChild(shape);
                                }

                                shape.FixUpMissingShapes();
                            }
                        }
                    }
                }
            }
        }
コード例 #12
0
        /// <summary>
        /// Called whenever a model element is beeing deleted.
        /// </summary>
        /// <param name="e"></param>
        public override void ElementDeleting(ElementDeletingEventArgs e)
        {
            base.ElementDeleting(e);

            DomainModelElement modelElement = e.ModelElement as DomainModelElement;

            deletionHelper.DeleteShapesForElement(modelElement);
        }
コード例 #13
0
            public void DeleteShapesForElement(DomainModelElement element)
            {
                if (element == null)
                {
                    return;
                }

                DeleteShapesForElement(element.Store, element.Id);
            }
コード例 #14
0
            public virtual void AddRSShapesForElement(DomainModelLink modelElement)
            {
                if (modelElement == null)
                {
                    return;
                }

                DomainModelElement m = DomainRoleInfo.GetSourceRolePlayer(modelElement) as DomainModelElement;

                AddMappingRSShapesForElement(m);
            }
コード例 #15
0
        /// <summary>
        /// Constuctor.
        /// </summary>
        /// <param name="viewModelStore">The store this view model belongs to.</param>
        /// <param name="element">Element.</param>
        protected ModalDesignerSurfaceViewModel(ViewModelStore viewModelStore, DomainModelElement element)
            : base(viewModelStore, null, viewModelStore.ModelData.CurrentModelContext.Name, false)
        {
            this.modelElement  = element;
            this.nameExtension = Guid.NewGuid();

            this.PreInitialize();
            this.Initialize();

            // if the hosted element is deleted, we have to close this
            this.EventManager.GetEvent <ModelElementDeletedEvent>().Subscribe(this.modelElement.Id, OnModelElementDeleted);
        }
コード例 #16
0
        /// <summary>
        /// Callback from SelectionChangedEvent.
        /// </summary>
        /// <param name="eventArgs">SelectionChangedEventArgs.</param>
        private void ReactOnViewSelection(SelectionChangedEventArgs eventArgs)
        {
            this.selectedModelElement = null;

            if (eventArgs.SelectedItems != null)
            {
                if (eventArgs.SelectedItems.Count == 1)
                {
                    this.selectedModelElement = eventArgs.SelectedItems[0] as DomainModelElement;
                }
            }
        }
コード例 #17
0
            /// <summary>
            /// Adds shapes for a given element.
            /// </summary>
            /// <param name="con"></param>
            internal void AddShapesForElement(DomainModelLink con)
            {
                if (con == null)
                {
                    return;
                }

                DomainModelElement parent = DomainRoleInfo.GetSourceRolePlayer(con) as DomainModelElement;
                DomainModelElement child  = DomainRoleInfo.GetTargetRolePlayer(con) as DomainModelElement;

                AddShapesForElement(parent, child);
            }
コード例 #18
0
        /// <summary>
        /// Constuctor.
        /// </summary>
        /// <param name="viewModelStore">The store this view model belongs to.</param>
        /// <param name="element">Element.</param>
        protected ModalDesignerSurfaceViewModel(ViewModelStore viewModelStore, DomainModelElement element)
            : base(viewModelStore, null, viewModelStore.ModelData.CurrentModelContext.Name, false)
        {
            this.modelElement = element;
            this.nameExtension = Guid.NewGuid();

            this.PreInitialize();
            this.Initialize();

            // if the hosted element is deleted, we have to close this
            this.EventManager.GetEvent<ModelElementDeletedEvent>().Subscribe(this.modelElement.Id, OnModelElementDeleted);
        }
 public void DeleteShapesForElement(DomainModelElement modelElement)
 {
     if (modelElement != null)
     {
         List<Guid> shapes = DiagramsShapeStore.GetFromStore(modelElement.Id);
         if (shapes != null)
             for (int i = shapes.Count - 1; i >= 0; i--)
             {
                 NodeShape shape = modelElement.Store.ElementDirectory.FindElement(shapes[i]) as NodeShape;
                 if (shape != null)
                     shape.Delete();
             }
     }
 }
コード例 #20
0
            public virtual void AddMappingRSShapesForElement(DomainModelElement modelElement)
            {
                if (modelElement == null)
                {
                    return;
                }

                DiagramDomainDataDirectory data = modelElement.Store.DomainDataAdvDirectory.ResolveExtensionDirectory <DiagramDomainDataDirectory>();

                if (data == null)
                {
                    throw new ArgumentNullException("DiagramDomainDataDirectory");
                }


                List <Guid> shapes = data.GetShapeTypesForElement(modelElement.GetDomainClassId());

                if (shapes == null)
                {
                    return;
                }
                foreach (Guid g in shapes)
                {
                    if (data.MappingRelationshipShapeInfos.ContainsKey(g))
                    {
                        MappingRelationshipShapeInfo info = data.MappingRelationshipShapeInfos[g];

                        // see if the required relationships exist
                        ReadOnlyCollection <ElementLink> colSource = DomainRoleInfo.GetElementLinks <ElementLink>(modelElement, info.SourceDomainRole);
                        if (colSource.Count != 1)
                        {
                            return;
                        }

                        ReadOnlyCollection <ElementLink> colTarget = DomainRoleInfo.GetElementLinks <ElementLink>(modelElement, info.TargetDomainRole);
                        if (colTarget.Count != 1)
                        {
                            return;
                        }

                        DomainModelElement source = DomainRoleInfo.GetTargetRolePlayer(colSource[0]) as DomainModelElement;
                        DomainModelElement target = DomainRoleInfo.GetTargetRolePlayer(colTarget[0]) as DomainModelElement;


                        AddRSShapesForElement(source, target, modelElement, g);
                    }
                }
            }
コード例 #21
0
        /// <summary>
        /// Clean up.
        /// </summary>
        protected override void OnDispose()
        {
            if (this.modelElement != null)
            {
                this.EventManager.GetEvent <ModelElementDeletedEvent>().Unsubscribe(this.modelElement.Id, OnModelElementDeleted);

                BaseModelElementViewModel v = this.modelElementVM;
                this.modelElementVM = null;

                OnPropertyChanged("HostedElementVM");
                v.Dispose();

                this.modelElement = null;
            }

            base.OnDispose();
        }
コード例 #22
0
            /// <summary>
            /// Adds shapes for a given element.
            /// </summary>
            /// <param name="parent">Model element.</param>
            /// <param name="child"></param>
            internal void AddShapesForElement(DomainModelElement parent, DomainModelElement child)
            {
                if (parent == null || child == null)
                {
                    return;
                }

                DiagramDomainDataDirectory data    = child.Store.DomainDataAdvDirectory.ResolveExtensionDirectory <DiagramDomainDataDirectory>();
                IDomainModelServices       topMost = child.GetDomainModelServices().TopMostService;

                // find parent shapes
                List <Guid> shapeIds = DiagramsShapeStore.GetFromStore(parent.Id);

                if (shapeIds != null)
                {
                    foreach (Guid shapeId in shapeIds)
                    {
                        // see if each parent shape has a child shape already added to it
                        NodeShape parentShape = child.Store.ElementDirectory.FindElement(shapeId) as NodeShape;
                        if (parentShape == null)
                        {
                            continue;
                        }

                        foreach (Guid elementShapeId in data.GetShapeTypesForElement(child.GetDomainClassId(), parentShape.GetDomainClassId()))
                        {
                            if (!DiagramHelper.IsElementDisplayedOn(parentShape, elementShapeId, child.Id))
                            {
                                NodeShape shape = topMost.ShapeProvider.CreateShapeForElement(elementShapeId, child) as NodeShape;
                                if (shape.IsRelativeChildShape)
                                {
                                    parentShape.AddRelativeChild(shape);
                                }
                                else
                                {
                                    parentShape.AddNestedChild(shape);
                                }
                                shape.SetAtFreePositionOnParent();
                            }
                        }
                    }
                }

                //AddRootShapesForElement(child, false);
                AddRootShapesForElement(child);
            }
コード例 #23
0
 public void DeleteShapesForElement(DomainModelElement modelElement)
 {
     if (modelElement != null)
     {
         List <Guid> shapes = DiagramsShapeStore.GetFromStore(modelElement.Id);
         if (shapes != null)
         {
             for (int i = shapes.Count - 1; i >= 0; i--)
             {
                 NodeShape shape = modelElement.Store.ElementDirectory.FindElement(shapes[i]) as NodeShape;
                 if (shape != null)
                 {
                     shape.Delete();
                 }
             }
         }
     }
 }
コード例 #24
0
            public virtual void AddRSShapesForElement(DomainModelElement sourceElement, DomainModelElement targetElement, ModelElement con, Guid shapeType)
            {
                List <Guid> shapeIdsSource = DiagramsShapeStore.GetFromStore(sourceElement.Id);
                List <Guid> shapeIdsTarget = DiagramsShapeStore.GetFromStore(targetElement.Id);

                if (shapeIdsSource == null || shapeIdsTarget == null)
                {
                    return;
                }
                if (shapeIdsSource.Count == 0 || shapeIdsTarget.Count == 0)
                {
                    return;
                }

                IDomainModelServices topMost = sourceElement.GetDomainModelServices().TopMostService;

                foreach (Guid sourceShapeId in shapeIdsSource)
                {
                    NodeShape sourceShape = con.Store.ElementDirectory.FindElement(sourceShapeId) as NodeShape;
                    if (sourceShape == null)
                    {
                        continue;
                    }
                    foreach (Guid targetShapeId in shapeIdsTarget)
                    {
                        NodeShape targetShape = con.Store.ElementDirectory.FindElement(targetShapeId) as NodeShape;
                        if (targetShape != null)
                        {
                            if (sourceShape.Diagram == targetShape.Diagram)
                            {
                                if (!DiagramHelper.IsLinkDisplayedOn(sourceShape.Diagram, shapeType, con.Id, sourceShape.Id, targetShape.Id))
                                {
                                    LinkShape shape = topMost.ShapeProvider.CreateShapeForElementLink(shapeType, con, sourceShape, targetShape) as LinkShape;
                                    sourceShape.Diagram.LinkShapes.Add(shape);
                                    shape.Layout(FixedGeometryPoints.None);
                                }
                            }
                        }
                    }
                }
            }
コード例 #25
0
        /// <summary>
        /// Restore the VM based on stored information.
        /// </summary>
        /// <param name="element">Info.</param>
        /// <returns>
        /// True if the restore process was successful. False otherwise.
        /// </returns>
        public virtual bool Restore(XElement element)
        {
            try
            {
                string nameExtensionValue = element.Element("NameExtenstion").Value;
                string elementIdValue     = element.Element("HostedElementId").Value;

                this.nameExtension = new Guid(nameExtensionValue);
                Guid elementId = new Guid(elementIdValue);

                DomainModelElement e = this.Store.ElementDirectory.FindElement(elementId) as DomainModelElement;
                if (e != null)
                {
                    this.modelElement = e;
                    this.Initialize();

                    return(true);
                }
            }
            catch { }

            return(false);
        }
コード例 #26
0
        /// <summary>
        /// Clean up.
        /// </summary>
        protected override void OnDispose()
        {
            if (this.modelElement != null)
            {
                this.EventManager.GetEvent<ModelElementDeletedEvent>().Unsubscribe(this.modelElement.Id, OnModelElementDeleted);

                BaseModelElementViewModel v = this.modelElementVM;
                this.modelElementVM = null;
                
                OnPropertyChanged("HostedElementVM");
                v.Dispose();
              
                this.modelElement = null;
            }

            base.OnDispose();
        }
コード例 #27
0
            /// <summary>
            /// Adds shapes for a given element.
            /// </summary>
            /// <param name="parent">Model element.</param>
            /// <param name="child"></param>
            internal void AddShapesForElement(DomainModelElement parent, DomainModelElement child)
            {
                if (parent == null || child == null)
                    return;

                DiagramDomainDataDirectory data = child.Store.DomainDataAdvDirectory.ResolveExtensionDirectory<DiagramDomainDataDirectory>();
                IDomainModelServices topMost = child.GetDomainModelServices().TopMostService;

                // find parent shapes
                List<Guid> shapeIds = DiagramsShapeStore.GetFromStore(parent.Id);
                if (shapeIds != null)
                    foreach (Guid shapeId in shapeIds)
                    {
                        // see if each parent shape has a child shape already added to it
                        NodeShape parentShape = child.Store.ElementDirectory.FindElement(shapeId) as NodeShape;
                        if (parentShape == null)
                            continue;

                        foreach (Guid elementShapeId in data.GetShapeTypesForElement(child.GetDomainClassId(), parentShape.GetDomainClassId()))
                        {
                            if (!DiagramHelper.IsElementDisplayedOn(parentShape, elementShapeId, child.Id))
                            {
                                NodeShape shape = topMost.ShapeProvider.CreateShapeForElement(elementShapeId, child) as NodeShape;
                                if (shape.IsRelativeChildShape)
                                    parentShape.AddRelativeChild(shape);
                                else
                                    parentShape.AddNestedChild(shape);
                                shape.SetAtFreePositionOnParent();
                            }
                        }
                    }

                //AddRootShapesForElement(child, false);
                AddRootShapesForElement(child);
            }
コード例 #28
0
            public virtual void AddRSShapesForElement(DomainModelElement sourceElement, DomainModelElement targetElement, ModelElement con, Guid shapeType)
            {
                List<Guid> shapeIdsSource = DiagramsShapeStore.GetFromStore(sourceElement.Id);
                List<Guid> shapeIdsTarget = DiagramsShapeStore.GetFromStore(targetElement.Id);
                if (shapeIdsSource == null || shapeIdsTarget == null)
                    return;
                if (shapeIdsSource.Count == 0 || shapeIdsTarget.Count == 0)
                    return;

                IDomainModelServices topMost = sourceElement.GetDomainModelServices().TopMostService;
                foreach (Guid sourceShapeId in shapeIdsSource)
                {
                    NodeShape sourceShape = con.Store.ElementDirectory.FindElement(sourceShapeId) as NodeShape;
                    if (sourceShape == null)
                        continue;
                    foreach (Guid targetShapeId in shapeIdsTarget)
                    {
                        NodeShape targetShape = con.Store.ElementDirectory.FindElement(targetShapeId) as NodeShape;
                        if( targetShape != null )
                            if (sourceShape.Diagram == targetShape.Diagram)
                            {
                                if (!DiagramHelper.IsLinkDisplayedOn(sourceShape.Diagram, shapeType, con.Id, sourceShape.Id, targetShape.Id))
                                {
                                    LinkShape shape = topMost.ShapeProvider.CreateShapeForElementLink(shapeType, con, sourceShape, targetShape) as LinkShape;
                                    sourceShape.Diagram.LinkShapes.Add(shape);
                                    shape.Layout(FixedGeometryPoints.None);
                                }
                            }
                    }
                }
            }
コード例 #29
0
        /// <summary>
        /// Restore the VM based on stored information.
        /// </summary>
        /// <param name="element">Info.</param>
        /// <returns>
        /// True if the restore process was successful. False otherwise.
        /// </returns>
        public virtual bool Restore(XElement element)
        {
            try
            {
                string nameExtensionValue = element.Element("NameExtenstion").Value;
                string elementIdValue = element.Element("HostedElementId").Value;

                this.nameExtension = new Guid(nameExtensionValue);
                Guid elementId = new Guid(elementIdValue);

                DomainModelElement e = this.Store.ElementDirectory.FindElement(elementId) as DomainModelElement;
                if (e != null)
                {
                    this.modelElement = e;
                    this.Initialize();

                    return true;
                }
            }
            catch { }

            return false;
        }
コード例 #30
0
 /// <summary>
 /// Not required.
 /// </summary>
 /// <param name="element"></param>
 /// <returns></returns>
 public override bool IsInsertableRootItem(DomainModelElement element)
 {
     throw new NotImplementedException();
 }
コード例 #31
0
 /// <summary>
 /// Constructor. The view model constructed this way does not react on model changes, as such DoHookUpEvents is false.
 /// </summary>
 /// <param name="viewModelStore">The store this view model belongs to.</param>
 /// <param name="element">Element represented by this view model.</param>
 public ExampleElementViewModel(ViewModelStore viewModelStore, DomainModelElement element)
     : base(viewModelStore, element)
 {
     LocalChildrenCount = element.GetLocalChildren().Count.ToString();
     ChildrenCount      = element.GetChildren().Count.ToString();
 }