示例#1
0
        private static void ApplyShapesLayout(GleeGraph g, Dictionary <string, NodeShape> shapesMap, double graphLeft, double graphTop)
        {
            // apply layout information to child shapes
            foreach (string key in shapesMap.Keys)
            {
                NodeShape nodeShape = shapesMap[key];
                Node      node      = g.NodeMap[key];

                // appy layout information for shape
                double shapeTop = (graphTop - node.BBox.Top) + HostMargin;
                double shapeLeft;
                if (graphLeft <= 0)
                {
                    shapeLeft = Math.Abs(graphLeft) + node.BBox.Left + HostMargin;
                }
                else
                {
                    shapeLeft = node.BBox.Left - graphLeft + HostMargin;
                }

                if (nodeShape.MovementBehaviour == ShapeMovementBehaviour.PositionOnEdgeOfParent)
                {
                    if (nodeShape.Parent != null)
                    {
                        nodeShape.SetLocation(NodeShape.CorrectPortLocation(nodeShape.Parent, nodeShape, new PointD(shapeLeft, shapeTop)));
                    }
                }
                else
                {
                    nodeShape.SetLocation(new PointD(shapeLeft, shapeTop));
                }
            }
        }
示例#2
0
 /// <summary>
 /// Called when [drag over package].
 /// </summary>
 /// <param name="shape">The shape.</param>
 /// <param name="e">The <see cref="Microsoft.VisualStudio.Modeling.Diagrams.DiagramDragEventArgs"/> instance containing the event data.</param>
 /// <returns></returns>
 internal static bool OnDragOverPackage(NodeShape shape, DiagramDragEventArgs e)
 {
     if (e.Data.GetDataPresent(DataFormats.Text) && (shape.ModelElement is Package))
     {
         string txt = (string)e.Data.GetData(DataFormats.Text);
         if (File.Exists(txt))
         {
             // Il faut que ce soit une interface
             FileCodeModel fcm = ServiceLocator.Instance.ShellHelper.GetFileCodeModel(txt);
             if (fcm != null)
             {
                 foreach (CodeElement cn in fcm.CodeElements)
                 {
                     if (cn is CodeNamespace)
                     {
                         foreach (CodeElement ci in ((CodeNamespace)cn).Members)
                         {
                             if (ci is CodeClass && shape.ModelElement is Package)
                             {
                                 e.Effect = DragDropEffects.Link;
                                 return(true);
                             }
                         }
                     }
                 }
             }
         }
     }
     return(false);
 }
示例#3
0
        /// <summary>
        /// TIPS Affectation d'un parent graphique diffèrent que le parent du modèle à un enfant
        /// </summary>
        /// <param name="childShape">The child shape.</param>
        /// <returns>The parent shape for the child shape.</returns>
        public override ShapeElement ChooseParentShape(ShapeElement childShape)
        {
            // Les layers apparaissent graphiquement dans un PackageLayer mais leur père reste
            // le composant
            if (childShape.ModelElement is Layer)
            {
                // Recherche du shape du layerPackage
                LayerPackage package = ((Layer)childShape.ModelElement).LayerPackage;
                if (package != null)
                {
                    IList <PresentationElement> shapes = PresentationViewsSubject.GetPresentation(package);
                    if (shapes.Count > 0)
                    {
                        NodeShape parentShape = (NodeShape)shapes[0];
                        return(parentShape);
                    }
                }
            }

            if (childShape.ModelElement is DataLayer)
            {
                CandleModel model = ((DataLayer)childShape.ModelElement).Component.Model;
                if (model != null)
                {
                    IList <PresentationElement> shapes = PresentationViewsSubject.GetPresentation(model);
                    if (shapes.Count > 0)
                    {
                        NodeShape parentShape = (NodeShape)shapes[0];
                        return(parentShape);
                    }
                }
            }

            return(base.ChooseParentShape(childShape));
        }
示例#4
0
        private static void LayoutShape(NodeShape parentShape)
        {
            Guard.NotNull(() => parentShape, parentShape);

            LastShapeBottom = parentShape.AbsoluteBounds.Bottom;

            // Get (linked) children shapes by y-pos
            var childrenShapes = GetChildrenShapes(parentShape);

            foreach (var childShape in childrenShapes)
            {
                if (childShape.CanMove)
                {
                    childShape.MoveTo(parentShape.AbsoluteBounds.Right + ShapeMarginX, LastShapeBottom + ShapeMarginY);

                    // Ensure connector points
                    var connector = GetConnectorToParent(childShape);
                    if (connector != null &&
                        connector.CanMoveAnchorPoints)
                    {
                        connector.FromEndPoint = new PointD(parentShape.AbsoluteBounds.Center.X, parentShape.AbsoluteBounds.Bottom);
                        connector.FixedFrom    = VGFixedCode.Caller;
                        connector.ToEndPoint   = new PointD(childShape.AbsoluteBounds.Left, childShape.AbsoluteBounds.Center.Y);
                        connector.FixedTo      = VGFixedCode.Caller;
                    }
                }

                LayoutShape(childShape);
            }
        }
示例#5
0
 public void Initialize(NodeShape dest, RectTransform listParent, UnityAction onButtonClick)
 {
     id             = dest.id;
     dNameText.text = dest.name;
     gameObject.transform.SetParent(listParent);
     dButton.onClick.AddListener(onButtonClick);
 }
示例#6
0
        /// <summary>
        /// Resizes to content.
        /// </summary>
        /// <param name="shape">The shape.</param>
        internal static void ResizeToContent(NodeShape shape)
        {
            double num1 = 0.27;

            foreach (Decorator decorator in shape.Decorators)
            {
                if (decorator.Field != null)
                {
                    if (decorator.Field is TextField)
                    {
                        SizeD sz = MeasureTextFieldSize(shape, (TextField)decorator.Field);
                        num1 += Math.Max(0.7, sz.Width);
                    }
                    else //if( decorator1 is ExpandCollapseDecorator  )
                    {
                        RectangleD rec = decorator.Field.GetBounds(shape);
                        num1 += (0.05 + rec.Width) + 0.08;
                    }
                }
            }
            using (Transaction transaction = shape.Store.TransactionManager.BeginTransaction("Resize contents"))
            {
                shape.Size = new SizeD(num1, shape.Size.Height);
                transaction.Commit();
            }
        }
        // traverse according to layout positions
        public IEnumerator <VDWidget> GetEnumerator()
        {
            List <NodeShape> childShapeList = new List <NodeShape>();
            var shapes = PresentationViewsSubject.GetPresentation(m_rootWidget);

            if (shapes != null && shapes.Count > 0)
            {
                NodeShape parentShape = shapes[0] as NodeShape;
                if (parentShape != null)
                {
                    foreach (var shape in parentShape.NestedChildShapes)
                    {
                        NodeShape childShape = shape as NodeShape;
                        if (childShape != null)
                        {
                            childShapeList.Add(childShape);
                        }
                    }
                }
            }

            // traverse according to position, row first
            childShapeList.Sort((a, b) =>
            {
                if (a.Location.Y - b.Location.Y > Utility.NumberHelper.DOUBLE_DIFFERENCE)
                {
                    return(1);
                }
                else if (b.Location.Y - a.Location.Y > Utility.NumberHelper.DOUBLE_DIFFERENCE)
                {
                    return(-1);
                }
                else if (a.Location.X - b.Location.X > Utility.NumberHelper.DOUBLE_DIFFERENCE)
                {
                    return(1);
                }
                else if (b.Location.X - a.Location.X > Utility.NumberHelper.DOUBLE_DIFFERENCE)
                {
                    return(-1);
                }
                else
                {
                    return(0);
                }
            });

            //
            List <VDWidget> childWidgets = new List <VDWidget>();

            foreach (NodeShape shape in childShapeList)
            {
                VDWidget widget = shape.ModelElement as VDWidget;
                if (widget != null)
                {
                    childWidgets.Add(widget);
                }
            }

            return(childWidgets.GetEnumerator());
        }
示例#8
0
 internal void ChangeNodeShape(NodeShape nodeShape)
 {
     foreach (ResizeNode node in Manager.ResizeNodes)
     {
         node.Shape = nodeShape;
     }
 }
 /// <summary>
 /// Move the name label above the parent shape
 /// </summary>
 public override void PlaceAsChildOf(NodeShape parent, bool createdDuringViewFixup)
 {
     AutoResize();
     if (createdDuringViewFixup)
     {
         SizeD      size         = Size;
         RectangleD parentBounds = ParentShape.AbsoluteBoundingBox;
         // Place slightly to the right and aligned with the top
         // of the shape. This will place the cardinality shape
         // below any value ranges.
         // For a fact type shape with a role cardinality, we want
         // to align with the top of the current roles shape field,
         // not the top of the shape itself.
         double        top = 0d;
         FactTypeShape factTypeShape;
         ShapeField    rolesField;
         if (ModelElement is UnaryRoleCardinalityConstraint &&
             null != (factTypeShape = parent as FactTypeShape) &&
             null != (rolesField = FactTypeShape.RolesField))
         {
             top = rolesField.GetBounds(factTypeShape).Top;
         }
         Location = new PointD(parentBounds.Width + .06, top);
     }
 }
示例#10
0
        private void OnMenuShowShape(object sender, EventArgs e)
        {
            NodeShape firstShape = CurrentSelection.OfType <NodeShape>().FirstOrDefault();

            if (firstShape != null)
            {
                using (Transaction tx = firstShape.Store.TransactionManager.BeginTransaction("HideShapes"))
                {
                    LinkedElementCollection <ShapeElement> childShapes = CurrentDocView.CurrentDiagram.NavigationRoot.NestedChildShapes;

                    foreach (ClassShape shape in childShapes.OfType <ClassShape>().Where(s => !s.IsVisible))
                    {
                        shape.Visible = true;
                    }

                    foreach (EnumShape shape in childShapes.OfType <EnumShape>().Where(s => !s.IsVisible))
                    {
                        shape.Visible = true;
                    }

                    foreach (ShapeElement shape in childShapes.Where(s => !s.IsVisible))
                    {
                        shape.Show();
                    }

                    tx.Commit();
                }
            }
        }
示例#11
0
        /// <summary>
        /// Adjust element location for existing shapes and set the Location properties
        /// </summary>
        /// <param name="ignoreExistingShapes">Set if no attempt should be made to flow around existing shapes</param>
        private void Reflow(bool ignoreExistingShapes)
        {
            // Respect the diagram margin
            Diagram diagram         = myDiagram;
            double  deltaX          = 0;
            double  deltaY          = 0;
            bool    movedFirstShape = ignoreExistingShapes;

            foreach (LayoutShape shape in myLayoutShapes)
            {
                if (!shape.Pinned)
                {
                    NodeShape ns = shape.Shape;
                    PointD    currentLocation = shape.TargetLocation;
                    if (!movedFirstShape)
                    {
                        // The shape location has not been set until immediately after this branch
                        // so finding the free area will not force a shape to move because it
                        // is on itself. Also, the available free area is always down and right.
                        RectangleD currentShapeBounds = ns.AbsoluteBounds;
                        RectangleD currentRectangle   = new RectangleD(currentLocation, currentShapeBounds.Size);
                        movedFirstShape = true;
                        PointD currentCenter = currentRectangle.Center;
                        if (currentShapeBounds.Location.IsEmpty || !currentShapeBounds.Contains(currentCenter))
                        {
                            RectangleD diagramBounds    = diagram.AbsoluteBounds;
                            PointD     adjustedLocation = diagram.FindFreeArea(currentCenter.X, currentCenter.Y, currentCenter.X, currentCenter.Y, currentRectangle.Width * 1.3, currentRectangle.Height * 1.3, currentRectangle.Width, currentRectangle.Height, currentRectangle.Left, currentRectangle.Top, double.MaxValue, double.MaxValue);
                            deltaX += adjustedLocation.X - currentCenter.X;
                            deltaY += adjustedLocation.Y - currentCenter.Y;
                        }
                    }
                    ns.Location = new PointD(currentLocation.X + deltaX, currentLocation.Y + deltaY);
                }
            }
        }
示例#12
0
        protected void OnArrangeShapes(object sender, EventArgs e)
        {
            NodeShape            shape   = SingleSelection as NodeShape;
            ArrangeShapesCommand command = new ArrangeShapesCommand(shape);

            command.Exec();
        }
示例#13
0
        /// <summary>
        /// Import d'un service
        /// </summary>
        /// <param name="shape">The shape.</param>
        /// <param name="e">The <see cref="Microsoft.VisualStudio.Modeling.Diagrams.DiagramDragEventArgs"/> instance containing the event data.</param>
        /// <returns></returns>
        internal static bool OnDragDropOnPackage(NodeShape shape, DiagramDragEventArgs e)
        {
            if (e.Data.GetDataPresent(DataFormats.Text))
            {
                string txt = (string)e.Data.GetData(DataFormats.Text);
                using (
                    Transaction transaction =
                        shape.ModelElement.Store.TransactionManager.BeginTransaction("Import entity"))
                {
                    // On ne veut pas que les assistants soient appelés
                    shape.ModelElement.Store.TransactionManager.CurrentTransaction.TopLevelTransaction.Context.
                    ContextInfo[StrategyManager.IgnoreStrategyWizards] = true;

                    IImportEntityHelper importer = ServiceLocator.Instance.GetService <IImportEntityHelper>();
                    if (importer == null)
                    {
                        return(false);
                    }
                    if (importer.ImportProperties(shape.ModelElement as Package, null, txt))
                    {
                        shape.RebuildShape();
                        transaction.Commit();
                    }
                }

                return(true);
            }
            return(false);
        }
示例#14
0
        /// <summary>
        /// Import d'un service
        /// </summary>
        /// <param name="shape">The shape.</param>
        /// <param name="e">The <see cref="Microsoft.VisualStudio.Modeling.Diagrams.DiagramDragEventArgs"/> instance containing the event data.</param>
        internal static void OnDragDropOnLayer(NodeShape shape, DiagramDragEventArgs e)
        {
            if (e.Data.GetDataPresent(DataFormats.Text))
            {
                string txt = (string)e.Data.GetData(DataFormats.Text);
                using (
                    Transaction transaction =
                        shape.ModelElement.Store.TransactionManager.BeginTransaction("Import interface"))
                {
                    // On ne veut pas que les assistants soient appelés
                    shape.ModelElement.Store.TransactionManager.CurrentTransaction.TopLevelTransaction.Context.
                    ContextInfo[StrategyManager.IgnoreStrategyWizards] = true;

                    IImportInterfaceHelper importer = ServiceLocator.Instance.GetService <IImportInterfaceHelper>();
                    if (importer == null)
                    {
                        return;
                    }
                    if (importer.ImportOperations(shape.ModelElement as SoftwareLayer, null, txt))
                    {
                        shape.RebuildShape();
                        transaction.Commit();
                    }
                }

                using (
                    Transaction transaction =
                        shape.ModelElement.Store.TransactionManager.BeginTransaction("Arrange ports"))
                {
                    LayerHelper.ArrangePorts(shape, typeof(ServiceContractShape));
                    transaction.Commit();
                }
            }
        }
示例#15
0
        /// <summary>
        /// Arranges the ports.
        /// </summary>
        /// <param name="parentShape">The parent shape.</param>
        /// <param name="portType">Type of the port.</param>
        internal static void ArrangePorts(NodeShape parentShape, Type portType)
        {
            List <NodeShape> portShapes = new List <NodeShape>();

            foreach (NodeShape childShape in parentShape.RelativeChildShapes)
            {
                if (childShape.GetType() == portType)
                {
                    portShapes.Add(childShape);
                }
            }

            if (portShapes.Count == 0)
            {
                return;
            }

            // Tri dans l'ordre d'affichage
            portShapes.Sort(new PortComparer());

            NodeShape portShape = portShapes[0];

            double gap = Math.Max(
                0,
                (parentShape.Bounds.Width - (2 * 0.15) - (portShapes.Count * portShape.Bounds.Width)) / (portShapes.Count + 1)
                );

            RectangleD pos = new RectangleD(gap, portShape.Bounds.Top, portShape.Bounds.Width, portShape.Bounds.Height);

            foreach (NodeShape shape in portShapes)
            {
                shape.Bounds = pos;
                pos.X       += shape.Bounds.Width + gap;
            }
        }
示例#16
0
        private static void AddNode(GleeGraph g, NodeShape n, Dictionary <string, NodeShape> shapesMap)
        {
            shapesMap.Add(n.Id.ToString(), n);

            Node node = new Node(n.Id.ToString(), CurveFactory.CreateBox(n.Bounds.Width, n.Bounds.Height, new Point(0.0, 0.0)));

            node.Padding = NodePadding;

            if (n.IsRelativeChildShape)
            {
                if (n.MovementBehaviour == ShapeMovementBehaviour.PositionOnEdgeOfParent)
                {
                    if (n.Parent != null)
                    {
                        if (g.NodeMap.ContainsKey(n.Parent.Id.ToString()))
                        {
                            //node.Padding = NodePaddingRelativeOnEdge;

                            // add edge so that this shape is kept close to its parent shape
                            //g.AddEdge(new Edge(g.NodeMap[n.Parent.Id.ToString()], node));
                        }
                    }
                }
            }


            g.AddNode(node);
        }
示例#17
0
 /// <summary>
 /// Drag d'élément d'un projet sur un layer
 /// </summary>
 /// <param name="shape">The shape.</param>
 /// <param name="e">The <see cref="Microsoft.VisualStudio.Modeling.Diagrams.DiagramDragEventArgs"/> instance containing the event data.</param>
 internal static void OnDragOverLayer(NodeShape shape, DiagramDragEventArgs e)
 {
     if (e.Data.GetDataPresent(DataFormats.Text) &&
         (shape.ModelElement is InterfaceLayer || shape.ModelElement is Layer))
     {
         string txt = (string)e.Data.GetData(DataFormats.Text);
         if (File.Exists(txt))
         {
             FileCodeModel fcm = ServiceLocator.Instance.ShellHelper.GetFileCodeModel(txt);
             if (fcm != null)
             {
                 foreach (CodeElement cn in fcm.CodeElements)
                 {
                     if (cn is CodeNamespace)
                     {
                         foreach (CodeElement ci in ((CodeNamespace)cn).Members)
                         {
                             if (ci is CodeInterface && shape.ModelElement is InterfaceLayer ||
                                 // Une interface seulement sur la couche interface
                                 ci is CodeClass) // Une classe n'importe ou
                             {
                                 e.Effect = DragDropEffects.Link;
                                 return;
                             }
                         }
                     }
                 }
             }
         }
     }
 }
        public NodeGraphics()
        {
            double num3 = X = (Y = 0.0);

            num3  = (Width = (Height = 10.0));
            Shape = NodeShape.Rectangle;
        }
示例#19
0
        /// <summary>
        /// Returns a collection of standard values for the data type this type converter is designed for when provided with a format context.
        /// </summary>
        /// <param name="context">An <see cref="T:System.ComponentModel.ITypeDescriptorContext"></see> that provides a format context that can be used to extract additional information about the environment from which this converter is invoked. This parameter or properties of this parameter can be null.</param>
        /// <returns>
        /// A <see cref="T:System.ComponentModel.TypeConverter.StandardValuesCollection"></see> that holds a standard set of valid values, or null if the data type does not support a standard set of values.
        /// </returns>
        public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
        {
            NodeShape shape = context.Instance as NodeShape;

            if (shape != null)
            {
                ExternalComponent element = shape.ModelElement as ExternalComponent;
                if (element != null)
                {
                    List <ComponentModelMetadata> versions =
                        RepositoryManager.Instance.ModelsMetadata.Metadatas.GetAllVersions(element.ModelMoniker);
                    ArrayList items = new ArrayList();
                    if (versions.Count == 0)
                    {
                        object value = context.PropertyDescriptor.GetValue(element);
                        if (value != null)
                        {
                            items.Add(value.ToString());
                        }
                    }
                    else
                    {
                        foreach (ComponentModelMetadata item in versions)
                        {
                            items.Add(item.Version.ToString());
                        }
                    }

                    return(new StandardValuesCollection(items.ToArray()));
                }
            }
            return(base.GetStandardValues(context));
        }
示例#20
0
        private void OnMenuAddProperties(object sender, EventArgs e)
        {
            NodeShape shapeElement = CurrentSelection.OfType <ClassShape>().FirstOrDefault();

            if (shapeElement?.ModelElement is ModelClass element)
            {
                AddCodeForm codeForm = new AddCodeForm(element);
                if (codeForm.ShowDialog() == DialogResult.OK)
                {
                    using (Transaction tx = element.Store.TransactionManager.BeginTransaction("AddProperties"))
                    {
                        element.Attributes.Clear();
                        IEnumerable <ModelAttribute> modelAttributes =
                            codeForm.Lines
                            .Select(s => ModelAttribute.Parse(element.ModelRoot, s))
                            .Where(attr => attr != null)
                            .Select(parseResult => new ModelAttribute(element.Store,
                                                                      new PropertyAssignment(ModelAttribute.NameDomainPropertyId, parseResult.Name),
                                                                      new PropertyAssignment(ModelAttribute.TypeDomainPropertyId, parseResult.Type ?? "String"),
                                                                      new PropertyAssignment(ModelAttribute.RequiredDomainPropertyId, parseResult.Required ?? true),
                                                                      new PropertyAssignment(ModelAttribute.MaxLengthDomainPropertyId, parseResult.MaxLength ?? 0),
                                                                      new PropertyAssignment(ModelAttribute.InitialValueDomainPropertyId, parseResult.InitialValue),
                                                                      new PropertyAssignment(ModelAttribute.IsIdentityDomainPropertyId, parseResult.IsIdentity),
                                                                      new PropertyAssignment(ModelAttribute.SetterVisibilityDomainPropertyId, parseResult.SetterVisibility ?? SetterAccessModifier.Public)
                                                                      ));
                        element.Attributes.AddRange(modelAttributes);
                        tx.Commit();
                    }
                }
            }
        }
示例#21
0
        private static void PropertiesAsserts(NodeShape node)
        {
            var idProp = node.Properties.First(p => p.Path.EndsWith("#id"));

            Assert.IsInstanceOfType(idProp.Range, typeof(ScalarShape));
            Assert.IsTrue(idProp.Required);
            var id = (ScalarShape)idProp.Range;

            Assert.IsTrue(id.DataType.EndsWith("#integer"));
            Assert.AreEqual("id", id.Name);

            var nameProp = node.Properties.First(p => p.Path.EndsWith("#name"));

            Assert.IsTrue(nameProp.Required);
            var name = (ScalarShape)nameProp.Range;

            Assert.IsTrue(name.DataType.EndsWith("#string"));
            Assert.AreEqual(255, name.MaxLength);
            Assert.AreEqual("name", name.Name);

            var durationProp = node.Properties.First(p => p.Path.EndsWith("#duration"));

            Assert.IsFalse(durationProp.Required);
            var duration = (ScalarShape)durationProp.Range;

            Assert.IsTrue(duration.DataType.EndsWith("#number"));
            Assert.AreEqual("1", duration.Minimum);
            Assert.AreEqual("duration", duration.Name);

            var storylineProp = node.Properties.First(p => p.Path.EndsWith("#storyline"));

            Assert.IsFalse(storylineProp.Required);
            Assert.AreEqual("storyline?", storylineProp.Range.Name);
        }
示例#22
0
        /// <summary>
        /// Liste des shapes à positionner
        /// </summary>
        /// <param name="store">The store.</param>
        /// <returns></returns>
        public static List <NodeShape> GetUnplacedShapes(Store store)
        {
            object obj;

            store.TransactionManager.CurrentTransaction.TopLevelTransaction.Context.ContextInfo.TryGetValue(
                "{FED4CA6E-2FFC-4751-A799-9B3808C384EA}", out obj);
            if (obj == null)
            {
                return(null);
            }
            List <ModelElement> elements = obj as List <ModelElement>;
            List <NodeShape>    shapes   = new List <NodeShape>();

            foreach (ModelElement element in elements)
            {
                foreach (PresentationElement pel in PresentationViewsSubject.GetPresentation(element))
                {
                    if (pel is NodeShape)
                    {
                        NodeShape shape = pel as NodeShape;
                        shapes.Add(shape);
                    }
                }
            }
            return(shapes);
        }
示例#23
0
        /// <summary>
        /// Removes the host shape.
        /// </summary>
        /// <param name="shape">Host shape to remove.</param>
        protected virtual void RemoveHostShape(GraphicalDependencyShape shape)
        {
            shape.LinkShape.Delete();

            for (int y = shape.NestedChildren.Count - 1; y >= 0; y--)
            {
                NodeShape nodeShape = shape.NestedChildren[y];
                for (int i = this.childItemElements.Count - 1; i >= 0; i--)
                {
                    if (this.childItemElements[i].ShapeElement.Id == nodeShape.Id)
                    {
                        if (this.childItems.Contains(this.childItemElements[i]))
                        {
                            this.childItems.Remove(this.childItemElements[i]);
                        }

                        this.childItemElements[i].Dispose();
                        this.childItemElements.RemoveAt(i);
                    }
                }
            }

            // delete shape
            shape.Delete();
        }
示例#24
0
        /// <summary>
        /// Quand on commence à éditer une cellule, on supprime la sélection dans le diagramme pour être sur de capturer
        /// tous les événements
        /// (Pour corriger le BUG: Quand on appuie sur la touche DEL lors de l'édition d'une cellule, c'est le shape sélectionné qui disparait)
        /// </summary>
        /// <param name="e">A <see cref="T:System.Windows.Forms.DataGridViewCellCancelEventArgs"></see> that contains the event data.</param>
        /// <exception cref="T:System.ArgumentOutOfRangeException">The value of the <see cref="P:System.Windows.Forms.DataGridViewCellCancelEventArgs.ColumnIndex"></see> property of e is greater than the number of columns in the control minus one.-or-The value of the <see cref="P:System.Windows.Forms.DataGridViewCellCancelEventArgs.RowIndex"></see> property of e is greater than the number of rows in the control minus one.</exception>
        protected override void OnCellBeginEdit(DataGridViewCellCancelEventArgs e)
        {
            base.OnCellBeginEdit(e);

            ModelElement elem = _root as ModelElement;

            // On enlève la sélection sur le shape
            if (elem != null)
            {
                IList <PresentationElement> shapes = PresentationViewsSubject.GetPresentation(elem);
                if (shapes.Count > 0)
                {
                    NodeShape ns = shapes[0] as NodeShape;
                    if (ns != null && ns.Diagram != null && ns.Diagram.ClientViews.Count > 0)
                    {
                        DiagramClientView clientView = ns.Diagram.ClientViews[0] as DiagramClientView;
                        if (clientView != null)
                        {
                            clientView.Selection.Clear();
                        }
                    }
                }
            }

            // L'entete n'est pas éditable ou une catégorie
            VirtualTreeGridItem item = GetRowValue(e.RowIndex);

            if (item == null || item.Kind == ModelKind.Root || item.Kind == ModelKind.Category)
            {
                e.Cancel = true;
            }

            _inPlaceEditMode = true;
        }
示例#25
0
        protected void OnStatusArrangeShapes(object sender, EventArgs e)
        {
            NodeShape            shape   = SingleSelection as NodeShape;
            ArrangeShapesCommand command = new ArrangeShapesCommand(shape);
            MenuCommand          cmd     = sender as MenuCommand;

            cmd.Enabled = cmd.Visible = command.Visible();
        }
示例#26
0
 private static void UpdateNodePositions(GeometryGraph graph)
 {
     foreach (Node node in graph.Nodes)
     {
         NodeShape nodeShape = (NodeShape)node.UserData;
         nodeShape.Bounds = new RectangleD(node.BoundingBox.Left, node.BoundingBox.Top, node.BoundingBox.Width, node.BoundingBox.Height);
     }
 }
示例#27
0
            public TreeNode(NodeShape shape)
            {
                this.Children = new List <TreeNode>();
                this.Parents  = new List <TreeNode>();
                this.Sibling  = null;

                this.Shape = shape;
            }
示例#28
0
 /// <summary>
 /// Implements <see cref="IConfigureAsChildShape.ConfiguringAsChildOf"/>
 /// </summary>
 protected void ConfiguringAsChildOf(NodeShape parentShape, bool createdDuringViewFixup)
 {
     // ORM lines cross, they don't jump. However, the RouteJumpType cannot
     // be set before the diagram is in place, so this property cannot be set
     // from initialization code in the shape itself. This makes sure the jump
     // settings are corect.
     JumpFreeChanged();
 }
        /// <summary>
        /// This method ensures that the role in the related fact type is closest (spatially) to the related object shape.
        /// </summary>
        /// <param name="shape">The shape that was most recently placed on the diagram</param>
        protected override void PostShapePlacement(LayoutShape shape)
        {
            FactTypeShape factShape;
            LayoutShape   parentShape;

            if (shape.Pinned || null == (parentShape = shape.Parent) || null == (factShape = shape.Shape as FactTypeShape))
            {
                return;
            }

            NodeShape    objectShape   = parentShape.Shape;
            ModelElement objectElement = parentShape.Shape.ModelElement;
            FactType     factElement;

            if (null != (factElement = objectElement as FactType))
            {
                Objectification objectification = factElement.Objectification;
                if (objectification != null)
                {
                    objectElement = objectification.NestingType;
                }
            }
            factElement = factShape.ModelElement as FactType;
            LinkedElementCollection <RoleBase> roles = factShape.DisplayedRoleOrder;

            // set the index at which the role will be closest to otherLayoutShape
            int         targetIndex = 0;
            LayoutShape objectLayoutShape;
            PointD      objectShapeLocation = myLayoutShapes.TryGetValue(objectShape, out objectLayoutShape) ? objectLayoutShape.TargetLocation : objectShape.Location;
            SizeD       objectShapeSize     = objectShape.Size;

            objectShapeLocation.Offset(objectShapeSize.Width / 2, objectShapeSize.Height / 2);
            if (objectShapeLocation.X > shape.TargetLocation.X + (factShape.Size.Width / 2))
            {
                targetIndex = roles.Count - 1;
            }

            // find actual index
            bool haveEditableOrder = false;
            int  roleCount         = roles.Count;

            for (int i = 0; i < roleCount; ++i)
            {
                if (roles[i].Role.RolePlayer == objectElement)
                {
                    if (i == targetIndex)
                    {
                        if (!haveEditableOrder)
                        {
                            haveEditableOrder = true;
                            roles             = factShape.GetEditableDisplayRoleOrder();
                        }
                        roles.Move(i, targetIndex);
                        break;
                    }
                }
            }
        }
        public static void Node(Rect position, NodeShape shape, NodeColor color, bool selected)
        {
            if (e.type == EventType.Repaint)
            {
                var outerPosition = GetNodeEdgeToOuterPosition(position, shape);

                GetNodeStyle(shape, color).Draw(FixNodePosition(outerPosition, shape, color, selected), false, false, false, selected);
            }
        }
示例#31
0
        /// <summary>
        /// Reroutes all compartment connection link shape connected to a given NodeShape.
        /// </summary>
        /// <remarks>
        /// The start and endpoints of the link will recalculated.
        /// </remarks>
        /// <param name="shape">The NodeShape</param>
        public static void RerouteCompartmentMappings(NodeShape shape)
        {
            // fill the cache
            FindAllCompartmentMappingRouter(shape.GetType().Assembly);

            using (Transaction t = shape.Store.TransactionManager.BeginTransaction("reroute all compartment links of a shape"))
            {
                foreach (LinkShape linkShape in shape.Link)
                    DoRerouteCompartmentMappings(linkShape as BinaryLinkShape);

                t.Commit();
            }
        }
        public static void SetAtFreePositionOnParent(NodeShape shape)
        {
            IList<NodeShape> shapes;
            if (shape.Parent == null)
            {
                // free position on diagram
                Diagram diagram = shape.Diagram;
                shapes = diagram.Children;
            }
            else
            {
                if (shape.IsRelativeChildShape)
                {
                    SetPortAtFreePositionOnParent(shape);
                    return;
                }

                // free position on parent shape
                shapes = shape.Parent.NestedChildren;
            }

            // simple algo - need better?
            RectangleF rectShape = new RectangleF(0, 0, (float)shape.Size.Width, (float)shape.Size.Height);
            RectangleF completeBounds = RectangleF.Empty;
            List<RectangleF> allShapes = new List<RectangleF>();
            for (int i = 0; i < shapes.Count; i++)
            {
                if (shapes[i] == shape)
                    continue;

                RectangleF r = new RectangleF((float)shapes[i].Location.X, (float)shapes[i].Location.Y, (float)shapes[i].Size.Width, (float)shapes[i].Size.Height);

                // add DistanceBetweenShapes
                if( r.X > DistanceBetweenShapes )
                    r.X -= DistanceBetweenShapes;
                if( r.Y > DistanceBetweenShapes )
                    r.Y -= DistanceBetweenShapes;
                if (r.X > DistanceBetweenShapes)
                    r.Width += DistanceBetweenShapes * 2;
                else
                    r.Width += DistanceBetweenShapes;

                if (r.Y > DistanceBetweenShapes)
                    r.Height += DistanceBetweenShapes * 2;
                else
                    r.Height += DistanceBetweenShapes;

                allShapes.Add(r);

                if (completeBounds == RectangleF.Empty)
                {
                    // set initial complete bounds
                    completeBounds = r;
                }
                else
                {
                    // extend complete bounds
                    if (completeBounds.X > r.X)
                    {
                        completeBounds.Width += r.X - completeBounds.X;
                        completeBounds.X = r.X;
                    }
                    if (completeBounds.Y > r.Y)
                    {
                        completeBounds.Height += r.Y - completeBounds.Y;
                        completeBounds.Y = r.Y;
                    }

                    if (completeBounds.Right < r.Right)
                        completeBounds.Width += r.Right - completeBounds.Right;

                    if (completeBounds.Bottom < r.Bottom)
                        completeBounds.Height += r.Bottom - completeBounds.Bottom;
                }
            }

            //float d = DistanceTopLeft;
            //if (shape.Parent != null)
            float d = DistanceBetweenShapes;
            
            if (completeBounds == RectangleF.Empty)
                completeBounds = new RectangleF(d, d, 0, 0);            

            // 1. see if we can fit a shape over completeBounds or to the left of it
            if (completeBounds.Top - rectShape.Height - d > d)
            {
                shape.SetLocation(new PointD(d, d));
                shape.UpdateAbsoluteLocation();
            }
            else if (completeBounds.Left - rectShape.Width - d > d)
            {
                shape.SetLocation(new PointD(d, d));
                shape.UpdateAbsoluteLocation();
            }
            else
            {
                // create region and exclude existing shapes
                Region region = new Region(new RectangleF(d, d, completeBounds.Width + completeBounds.X - d, completeBounds.Height + completeBounds.Y - d));
                foreach (RectangleF r in allShapes)
                    region.Exclude(r);

                double right = completeBounds.Width + completeBounds.X;
                double bottom = completeBounds.Height + completeBounds.Y;

                /*
                foreach (LinkShape linkShape in shape.Diagram.LinkShapes)
                {
                    List<PointF> points = new List<PointF>();
                    for (int i = 0; i < linkShape.EdgePoints.Count; i++)
                    {
                        PointF p = new PointF((float)linkShape.EdgePoints[i].X, (float)linkShape.EdgePoints[i].Y);
                        if (p.X <= right && p.Y <= bottom)
                            points.Add(p);
                    }

                    //new System.Drawing.Drawing2D.GraphicsPath(points.ToArray(), 
                    if (points.Count > 1)
                    {
                        System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath();
                        path.AddLines(points.ToArray());
                        region.Exclude(path);
                    }
                }*/
                

                // get free areas
                var rects = region.GetRegionScans(new System.Drawing.Drawing2D.Matrix());
                foreach(RectangleF r in rects )
                    if (r.Width >= rectShape.Width &&
                        r.Height >= rectShape.Height)
                    {
                        shape.SetLocation(new PointD(r.Left, r.Top));
                        shape.UpdateAbsoluteLocation();
                        
                        return;
                    }

                // 4. if no free are is found, we place the shape under compleBounds or to the right of it
                if (completeBounds.Width < completeBounds.Height)
                    shape.SetLocation(new PointD(completeBounds.Right, d));
                else
                    shape.SetLocation(new PointD(d, completeBounds.Bottom));
                shape.UpdateAbsoluteLocation();
            }
        }
示例#33
0
		void IConfigureAsChildShape.ConfiguringAsChildOf(NodeShape parentShape, bool createdDuringViewFixup)
		{
			ConfiguringAsChildOf(parentShape, createdDuringViewFixup);
		}
示例#34
0
 public NodeObject(float x = 0, float y = 0)
 {
     NodeSize = 13;
     Shape = NodeShape.Square;
     Position = new PointF(x, y);
 }
示例#35
0
		/// <summary>
		/// Place a newly added role name shape
		/// </summary>
		/// <param name="parent">Parent FactTypeShape</param>
		/// <param name="createdDuringViewFixup">Whether this shape was created as part of a view fixup</param>
		public override void PlaceAsChildOf(NodeShape parent, bool createdDuringViewFixup)
		{
			FactTypeShape factShape = (FactTypeShape)parent;
			double x = -0.2;
			double y = -0.2;
			FactType factType = factShape.AssociatedFactType;
			// Cascades RoleNameShapes for facts that contain more than one role
			LinkedElementCollection<RoleBase> roles = factShape.DisplayedRoleOrder;
			int roleIndex = roles.IndexOf((RoleBase)ModelElement);
			if (roleIndex != -1)
			{
				x += roleIndex * 0.15;
				y -= roleIndex * 0.15;
			}
			Location = new PointD(x, y);
		}
示例#36
0
		/// <summary>
		/// Implements <see cref="IConfigureAsChildShape.ConfiguringAsChildOf"/>
		/// </summary>
		protected new void ConfiguringAsChildOf(NodeShape parentShape, bool createdDuringViewFixup)
		{
			base.ConfiguringAsChildOf(parentShape, createdDuringViewFixup);
			// We have to make sure each shape is connected to its parent,
			// so we can't use the MultiShapeUtility.

			Diagram diagram = parentShape as Diagram;
			if (diagram == null)
			{
				return;
			}
			RoleHasValueConstraint modelLink = ModelElement as RoleHasValueConstraint;
			ModelElement factType = modelLink.Role.FactType;
			//connect the first unconnected constraint shape to its parent
			foreach (ValueConstraintShape shape in MultiShapeUtility.FindAllShapesForElement<ValueConstraintShape>(diagram, modelLink.ValueConstraint))
			{
				bool connected = false;
				foreach (ShapeElement link in shape.ToRoleLinkShapes)
				{
					//check if the shape is already connected
					ValueRangeLink valueRangeLink;
					if ((valueRangeLink = link as ValueRangeLink) != null &&
						valueRangeLink.FromShape.ModelElement == factType)
					{
						connected = true;
						break;
					}
				}
				FactTypeShape factTypeShape;
				if (connected ||
					null == (factTypeShape = shape.ParentShape as FactTypeShape) ||
					factTypeShape.DisplayAsObjectType)
				{
					continue;
				}


				Connect(factTypeShape, shape);
				return;
			}
			Delete();
		}
示例#37
0
		/// <summary>
		/// A utility function to attempt to perfom custom shape folding.
		/// Custom shape folding uses shape-specific information beyond that
		/// available to the ShapeGeometry to determine connection points.
		/// This function should be call after AdjustVectorEndPoint.
		/// </summary>
		/// <param name="geometryHost">The geometryHost value passed to DoFoldToShape</param>
		/// <param name="vectorEndPoint">The vectorEndPoint passed to DoFoldToShape and adjusted by <see cref="AdjustVectorEndPoint(IGeometryHost,PointD,out NodeShape)"/></param>
		/// <param name="oppositeShape">The opposite shape returned by <see cref="AdjustVectorEndPoint(IGeometryHost,PointD,out NodeShape)"/></param>
		/// <returns>Nullable&lt;PointD&gt; with a value on success, without a value if custom folding is not available</returns>
		public static PointD? DoCustomFoldShape(IGeometryHost geometryHost, PointD vectorEndPoint, NodeShape oppositeShape)
		{
			ICustomShapeFolding customFolding;
			IProxyConnectorShape proxyConnector;
			PointD customPoint;
			NodeShape realHost;
			if (oppositeShape != null &&
				null != (customFolding = geometryHost as ICustomShapeFolding) &&
				!(customPoint = customFolding.CalculateConnectionPoint(oppositeShape)).IsEmpty)
			{
				// Translate back to local coordinates
				PointD location = geometryHost.TranslateGeometryToAbsoluteBounds(geometryHost.GeometryBoundingBox).Location;
				customPoint.Offset(-location.X, -location.Y);
				return customPoint;
			}
			else if (null != (proxyConnector = geometryHost as IProxyConnectorShape) &&
				null != (realHost = proxyConnector.ProxyConnectorShapeFor as NodeShape))
			{
				SizeD size = realHost.Size;
				customPoint = realHost.ShapeGeometry.DoFoldToShape(new GeometryHostWrapper(realHost), new PointD(size.Width / 2, size.Height / 2), GeometryUtility.VectorEndPointForBase(realHost, vectorEndPoint));
				PointD location = geometryHost.TranslateGeometryToAbsoluteBounds(geometryHost.GeometryBoundingBox).Location;
				PointD realLocation = realHost.AbsoluteBounds.Location;
				customPoint.Offset(realLocation.X - location.X, realLocation.Y - location.Y);
				return customPoint;
			}
			return null;
		}
        private static bool SetPortAtFreePositionOnParent(NodeShape shape, PortPlacement side, RectangleF freeRectangle)
        {
            List<RectangleF> freeRectangles = new List<RectangleF>();
            freeRectangles.Add(freeRectangle);

            for (int i = 0; i < shape.Parent.RelativeChildren.Count; i++)
            {
                if (shape.Parent.RelativeChildren[i] == shape)
                    continue;

                if (shape.Parent.RelativeChildren[i].PlacementSide != side)
                    continue;

                RectangleF s = shape.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 >= shape.Bounds.Width && r.Height >= shape.Bounds.Height)
                {
                    shape.Location = new PointD(r.X, r.Y);
                    shape.PlacementSide = side;
                    shape.UpdateAbsoluteLocation();
                    return true;
                }
            }

            return false;
        }
        private static void AddNode(GleeGraph g, NodeShape n, Dictionary<string, NodeShape> shapesMap)
        {
            shapesMap.Add(n.Id.ToString(), n);

            Node node = new Node(n.Id.ToString(), CurveFactory.CreateBox(n.Bounds.Width, n.Bounds.Height, new Point(0.0, 0.0)));
            node.Padding = NodePadding;

            if (n.IsRelativeChildShape)
                if (n.MovementBehaviour == ShapeMovementBehaviour.PositionOnEdgeOfParent)
                {
                    if (n.Parent != null)
                        if (g.NodeMap.ContainsKey(n.Parent.Id.ToString()))
                        {
                            //node.Padding = NodePaddingRelativeOnEdge;

                            // add edge so that this shape is kept close to its parent shape
                            //g.AddEdge(new Edge(g.NodeMap[n.Parent.Id.ToString()], node));
                        }
                }


            g.AddNode(node);
        }
        private static void UpdateAbsoluteLocation(NodeShape shapeElement)
        {
            shapeElement.UpdateAbsoluteLocation();

            foreach (NodeShape shape in shapeElement.Children)
            {
                UpdateAbsoluteLocation(shape);
            }
        }
        /// <summary>
        /// Layout a subgraph defined by a given shape by using the GLEE layout library.
        /// </summary>
        /// <param name="shape">Main shape.</param>
        /// <remarks>
        /// This method needs to be called within a modeling transaction.
        /// </remarks>
        public static void Layout(NodeShape shape)
        {

            List<LinkShape> edges = new List<LinkShape>();
            List<LinkShape> dEdges = new List<LinkShape>();

            LayoutShape(shape, edges, dEdges);

            // update layout of link shapes
            foreach (LinkShape linkShape in edges)
            {
                linkShape.Layout(FixedGeometryPoints.None);

                linkShape.SourceAnchor.DiscardLocationChange = false;
                linkShape.TargetAnchor.DiscardLocationChange = false;
            }

            // update layout of discarded link shapes
            foreach (LinkShape linkShape in dEdges)
            {
                linkShape.Layout(FixedGeometryPoints.None);

                linkShape.SourceAnchor.DiscardLocationChange = false;
                linkShape.TargetAnchor.DiscardLocationChange = false;
            }

            // this is required because of size changes of the node shape:
            // 1. outgoing link shapes of the layed out node shape
            foreach(LinkShape linkShape in shape.OutgoingLinkShapes )
            {
                linkShape.Layout(FixedGeometryPoints.None);

                linkShape.SourceAnchor.DiscardLocationChange = false;
                linkShape.TargetAnchor.DiscardLocationChange = false;
            }

            // 2. incoming link shapes of the layed out node shape
            foreach (LinkShape linkShape in shape.IncomingLinkShapes)
            {
                linkShape.Layout(FixedGeometryPoints.None);

                linkShape.SourceAnchor.DiscardLocationChange = false;
                linkShape.TargetAnchor.DiscardLocationChange = false;
            }
        }
        /// <summary>
        /// Layout a subgraph defined by a given shape by using the GLEE layout library.
        /// </summary>
        /// <param name="shape">Main shape.</param>
        /// <remarks>
        /// This method needs to be called within a modeling transaction.
        /// </remarks>
        private static void LayoutShape(NodeShape shape, List<LinkShape> edges, List<LinkShape> dEdges)
        {
            Dictionary<string, NodeShape> shapesMap = new Dictionary<string, NodeShape>();

            // create glee graph
            GleeGraph g = new GleeGraph();
            g.Margins = GraphMargins;
            g.MinNodeHeight = MinNodeHeight;
            g.MinNodeWidth = GraphMargins;

            // transform the information in the diagram into the glee graph
            List<LinkShape> edgesLocal = new List<LinkShape>();
            foreach (NodeShape childShape in shape.Children)
            {
                // layout shape if it has children
                if (childShape.Children.Count > 0)
                    LayoutShape(childShape, edges, dEdges);

                // collect edges on the same level
                foreach (LinkShape linkShape in childShape.OutgoingLinkShapes)
                {
                    if (linkShape.ToShape.Parent == shape)
                        edgesLocal.Add(linkShape);
                    else
                        dEdges.Add(linkShape);
                }

                AddNode(g, childShape, shapesMap);
            }

            // 2. add edges
            foreach (LinkShape linkShape in edgesLocal)
            {
                g.AddEdge(new Edge(
                    g.NodeMap[linkShape.FromShape.Id.ToString()],
                    g.NodeMap[linkShape.ToShape.Id.ToString()]));
            }
            edges.AddRange(edgesLocal);

            // layout graph
            g.CalculateLayout();

            // apply layout information to diagram
            if (shape.Children.Count > 0)   // we have no way of knowning what min size a shape has for now..
            {
                if (shape.ResizingBehaviour == ShapeResizingBehaviour.Normal)
                    shape.SetSize(new SizeD(g.Width + HostMargin, g.Height + HostMargin));
                else if (shape.ResizingBehaviour == ShapeResizingBehaviour.FixedWidth)
                    shape.SetSize(new SizeD(shape.Size.Width, g.Height + HostMargin));
                else if (shape.ResizingBehaviour == ShapeResizingBehaviour.FixedHeight)
                    shape.SetSize(new SizeD(g.Width + HostMargin, shape.Size.Height));
            }

            ApplyShapesLayout(g, shapesMap, g.Left, g.Top);

            // update absolute location of shapes
            UpdateAbsoluteLocation(shape);
        }
示例#43
0
 public void ChangeShape(NodeShape shape)
 {
     _shape = shape;
 }
示例#44
0
        /// <summary>
        /// Creates a new view for a given node.
        /// </summary>
        /// <param name="parent">The parent of the new NodeViewData.</param>
        /// <param name="rootBehavior">The behaviour which is the root of the graph the given node is shown in.</param>
        /// <param name="node">The node the view is created for.</param>
        /// <param name="shape">The shape of the node when being rendered.</param>
        /// <param name="defaultStyle">The stle of the node when being neither hovered over nor selected.</param>
        /// <param name="currentStyle">The style of the node when the mouse is hovering over it.</param>
        /// <param name="selectedStyle">The style of the node when it is selected.</param>
        /// <param name="draggedStyle">The style of the node when it is attached to the mouse cursor when moving nodes in the graph.</param>
        /// <param name="label">The default label of the node.</param>
        /// <param name="font">The font used for the label.</param>
        /// <param name="minWidth">The minimum width of the node.</param>
        /// <param name="minHeight">The minimum height of the node.</param>
        /// <param name="description">The description of the node shown to the designer.</param>
        public NodeViewData(NodeViewData parent, BehaviorNode rootBehavior, Node node, NodeShape shape,
            Style defaultStyle, Style currentStyle, Style selectedStyle, Style draggedStyle, Style highlightedStyle, Style updatedStyle, Style prefabStyle,
            string label, Font font, Font profileFont, Font profileBoldFont, int minWidth, int minHeight, string description)
        {
            Debug.Check(rootBehavior != null);

            _rootBehavior = rootBehavior;
            _rootBehavior.WasModified += new WasModifiedEventDelegate(node_WasModified);

            _node = node;
            _node.SubItemAdded += new Node.SubItemAddedEventDelegate(node_SubItemAdded);

            _shape = shape;
            _font = font;
            _profileFont = profileFont;
            _profileBoldFont = profileBoldFont;
            _minWidth = minWidth;
            _minHeight = minHeight;

            if (defaultStyle == null)
            { throw new Exception(Resources.ExceptionDefaultStyleNull); }

            _defaultStyle = defaultStyle;
            _currentStyle = currentStyle;
            _selectedStyle = selectedStyle;
            _draggedStyle = draggedStyle;
            _highlightedStyle = highlightedStyle;
            _updatedStyle = updatedStyle;
            _prefabStyle = prefabStyle;

            setSubItems(node);

            GenerateNewLabel();
        }
示例#45
0
		/// <summary>
		/// Place the child shape the first time it is placed
		/// on the diagram
		/// </summary>
		/// <param name="parent">The parent shape</param>
		/// <param name="createdDuringViewFixup">Whether this shape was created as part of a view fixup</param>
		public virtual void PlaceAsChildOf(NodeShape parent, bool createdDuringViewFixup)
		{
		}
示例#46
0
		/// <summary>
		/// Creates a new node and attaches the default attributes DebugName and ExportType.
		/// </summary>
		/// <param name="shape">The shape of the node when being rendered.</param>
		/// <param name="defaultStyle">The stle of the node when being neither hovered over nor selected.</param>
		/// <param name="currentStyle">The style of the node when the mouse is hovering over it.</param>
		/// <param name="selectedStyle">The style of the node when it is selected.</param>
		/// <param name="draggedStyle">The style of the node when it is attached to the mouse cursor when moving nodes in the graph.</param>
		/// <param name="label">The default label of the node.</param>
		/// <param name="font">The font used for the label.</param>
		/// <param name="minWidth">The minimum width of the node.</param>
		/// <param name="minHeight">The minimum height of the node.</param>
		/// <param name="acceptsEvents">Defines if events may be attached to this node.</param>
		/// <param name="description">The description of the node shown to the designer.</param>
		public Node(NodeShape shape, Style defaultStyle, Style currentStyle, Style selectedStyle, Style draggedStyle, string label, Font font, int minWidth, int minHeight, bool acceptsEvents, string description)
		{
			_children= new ConnectedChildren(this);

			_label= label;
			_baselabel= label;
			_shape= shape;
			_font= font;
			_minWidth= minWidth;
			_minHeight= minHeight;

			_description= description;

			if(defaultStyle ==null)
				throw new Exception(Resources.ExceptionDefaultStyleNull);

			_defaultStyle= defaultStyle;
			_currentStyle= currentStyle;
			_selectedStyle= selectedStyle;
			_draggedStyle= draggedStyle;

			_acceptsEvents= acceptsEvents;
		}
示例#47
0
        private static void LayoutShape(NodeShape parentShape)
        {
            Guard.NotNull(() => parentShape, parentShape);

            LastShapeBottom = parentShape.AbsoluteBounds.Bottom;

            // Get (linked) children shapes by y-pos
            var childrenShapes = GetChildrenShapes(parentShape);
            foreach (var childShape in childrenShapes)
            {
                if (childShape.CanMove)
                {
                    childShape.MoveTo(parentShape.AbsoluteBounds.Right + ShapeMarginX, LastShapeBottom + ShapeMarginY);

                    // Ensure connector points
                    var connector = GetConnectorToParent(childShape);
                    if (connector != null &&
                        connector.CanMoveAnchorPoints)
                    {
                        connector.FromEndPoint = new PointD(parentShape.AbsoluteBounds.Center.X, parentShape.AbsoluteBounds.Bottom);
                        connector.FixedFrom = VGFixedCode.Caller;
                        connector.ToEndPoint = new PointD(childShape.AbsoluteBounds.Left, childShape.AbsoluteBounds.Center.Y);
                        connector.FixedTo = VGFixedCode.Caller;
                    }
                }

                LayoutShape(childShape);
            }
        }
        private static void SetPortAtFreePositionOnParent(NodeShape shape)
        {
            float width = (float)shape.Bounds.Width;
            float height = (float)shape.Bounds.Height;

            float parentWidth = (float)shape.Parent.Bounds.Width;
            float parentHeight = (float)shape.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 < shape.Parent.RelativeChildren.Count; i++)
            {
                if (shape.Parent.RelativeChildren[i] == shape)
                    continue;

                dict[shape.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(shape, p.Key, rectH))
                {
                    return;
                }
            }

            shape.SetLocation(NodeShape.CorrectPortLocation(shape.Parent, shape, new PointD(0, 0)));
        }
示例#49
0
 private static BinaryLinkShape GetConnectorToParent(NodeShape shape)
 {
     return shape.ToRoleLinkShapes.Cast<BinaryLinkShape>().FirstOrDefault();
 }
示例#50
0
		/// <summary>
		/// Locate the opposite shape based on the given points and
		/// adjust the opposite the endpoint accordingly. The endpoint
		/// is also modified to represent an absolute value. Use VectorEndPointForBase
		/// to restore the vector endpoint to its natural value.
		/// CenterToCenter routing is assumed.
		/// </summary>
		/// <param name="geometryHost">IGeometryHost (passed from DoFoldToShape)</param>
		/// <param name="vectorEndPoint">PointD (passed from DoFoldToShape)</param>
		/// <param name="oppositeShape">The located opposite shape at this location</param>
		/// <returns>Absolute location of end point</returns>
		public static PointD AdjustVectorEndPoint(IGeometryHost geometryHost, PointD vectorEndPoint, out NodeShape oppositeShape)
		{
			oppositeShape = null;
			// The vectorEndPoint value is coming in (negative, negative) for the lower
			// right quadrant instead of (positive, positive). All other values are
			// (positive, positive), so we switch the end point to make the rest of the work
			// easier. For CenterToCenter routing, subtracting the vectorEndPoint from the
			// lower right corner gives the correct value.
			RectangleD absoluteBoundingBox = geometryHost.TranslateGeometryToAbsoluteBounds(geometryHost.GeometryBoundingBox);
#if VISUALSTUDIO_10_0
			PointD absoluteCenter = absoluteBoundingBox.Center;
			vectorEndPoint = new PointD(absoluteCenter.X - vectorEndPoint.X, absoluteCenter.Y - vectorEndPoint.Y);
#else
			vectorEndPoint = new PointD(absoluteBoundingBox.Right - vectorEndPoint.X, absoluteBoundingBox.Bottom - vectorEndPoint.Y);
#endif

			NodeShape shape = geometryHost as NodeShape;
			if (shape != null)
			{
				ReadOnlyCollection<LinkConnectsToNode> links = DomainRoleInfo.GetElementLinks<LinkConnectsToNode>(shape, LinkConnectsToNode.NodesDomainRoleId);
				int linksCount = links.Count;
				for (int i = 0; i < linksCount; ++i)
				{
					LinkConnectsToNode link = links[i];
					BinaryLinkShape linkShape = link.Link as BinaryLinkShape;
					if (link != null)
					{
						// Get the opposite shape
						NodeShape testShape;
						if (linkShape.FromLinkConnectsToNode == link)
						{
							testShape = linkShape.ToShape;
						}
						else
						{
							testShape = linkShape.FromShape;
						}

						PointD shapeCenter = testShape.AbsoluteCenter;
						if (VGConstants.FuzzEqual(shapeCenter.X, vectorEndPoint.X, VGConstants.FuzzDistance) &&
							VGConstants.FuzzEqual(shapeCenter.Y, vectorEndPoint.Y, VGConstants.FuzzDistance))
						{
							oppositeShape = testShape;
							ICustomShapeFolding customFolding = testShape as ICustomShapeFolding;
							if (customFolding != null)
							{
								PointD customEndPoint = customFolding.CalculateConnectionPoint(shape);
								if (!customEndPoint.IsEmpty)
								{
									vectorEndPoint = customEndPoint;
								}
							}
							break;
						}
					}
				}
			}
			return vectorEndPoint;
		}
示例#51
0
		/// <summary>
		/// Organizes the shapes added with <see cref="AddShape(ShapeElement)"/> or similar methods.
		/// </summary>
		/// <param name="ignoreExistingShapes">Do not adjust for existing shapes</param>
		/// <param name="referenceShape">Layout shapes to the right of this shape.</param>
		/// <param name="layoutRightOfReferenceShape">Set to layout to the right of the <paramref name="referenceShape"/></param>
		/// <param name="layoutBelowReferenceShape">Set to layout below the <paramref name="referenceShape"/></param>
		public void Layout(bool ignoreExistingShapes, NodeShape referenceShape, bool layoutRightOfReferenceShape, bool layoutBelowReferenceShape)
		{
			LayoutShape backupRoot = null;
			LayoutShapeList allShapes = myLayoutShapes;
			switch (allShapes.Count)
			{
				case 0:
					return;
				default:
					backupRoot = allShapes[0];
					break;
			}
			myLayoutEngine.LateBind(myDiagram, allShapes);

			SizeD margin = myDiagram.NestedShapesMargin;
			if (referenceShape != null &&
				(layoutRightOfReferenceShape || layoutBelowReferenceShape))
			{
				RectangleD referenceBounds = referenceShape.AbsoluteBounds;
				if (layoutRightOfReferenceShape)
				{
					margin.Width = Math.Max(margin.Width, referenceBounds.Right);
				}
				if (layoutBelowReferenceShape)
				{
					margin.Height = Math.Max(margin.Height, referenceBounds.Bottom);
				}
			}
			PointD minimumPoint = new PointD(margin.Width, margin.Height);
			RectangleD layoutRectangle = new RectangleD(minimumPoint, SizeD.Empty);
			bool firstPass = true;
			for (; ; )
			{
				LayoutShape mostRelatives = myLayoutEngine.ResolveReferences(allShapes);
				LayoutShape root = null;
				// If the root shape was set by the user, AND the shape exists in our shape list
				if (myRootShape == null || !allShapes.TryGetValue(myRootShape, out root))
				{
					root = GetRoot(mostRelatives);
				}
				if (root == null)
				{
					if (backupRoot == null)
					{
						myLayoutEngine.PostLayout(minimumPoint);
						break;
					}
					root = backupRoot;
				}

				// run the layout of base shapes
				myLayoutEngine.PerformLayout(root, new PointD(margin.Width, layoutRectangle.Bottom + (firstPass ? 0 : root.Shape.Size.Height)), ref layoutRectangle);
				firstPass = false;
				backupRoot = null;
				myRootShape = null;
			}

			Reflow(ignoreExistingShapes);
		}
示例#52
0
		/// <summary>
		/// Implements <see cref="IConfigureAsChildShape.ConfiguringAsChildOf"/>
		/// </summary>
		protected void ConfiguringAsChildOf(NodeShape parentShape, bool createdDuringViewFixup)
		{
			// ORM lines cross, they don't jump. However, the RouteJumpType cannot
			// be set before the diagram is in place, so this property cannot be set
			// from initialization code in the shape itself.
			RouteJumpType = VGObjectLineJumpCode.VGObjectJumpCodeNever;
		}
示例#53
0
		/// <summary>
		/// Implements <see cref="IConfigureAsChildShape.ConfiguringAsChildOf"/>
		/// </summary>
		protected new void ConfiguringAsChildOf(NodeShape parentShape, bool createdDuringViewFixup)
		{
			base.ConfiguringAsChildOf(parentShape, createdDuringViewFixup);
			Reconfigure(null);
		}
示例#54
0
 public ResizeNode(int x = 0, int y = 0)
 {
     Size = 13;
     Shape = NodeShape.Square;
     Position = new Point(x, y);
 }
示例#55
0
 public NodeObject(int x = 0, int y = 0)
 {
     NodeSize = 13;
     Shape = NodeShape.Square;
     Position = new Point(x, y);
 }
示例#56
0
 private static IOrderedEnumerable<NodeShape> GetChildrenShapes(NodeShape shape)
 {
     var childrenElements = GetAllEmbeddedElements(shape.Subject);
     return childrenElements
         .Select(e => e.GetShape<NodeShape>())
         .Where(s => s != null)
         .OrderBy(s => s.AbsoluteBoundingBox.Top);
 }
示例#57
0
 public ShapeChange(MapNode node, NodeShape oldValue)
 {
     this.node = node;
     this.oldValue = oldValue;
 }
示例#58
0
		/// <summary>
		/// Determine if the opposite shape is a proxy connector shape
		/// and adjust the vectorEndPoint appropriately.
		/// </summary>
		/// <param name="vectorEndPoint">The vectorEndPoint passed to DoFoldToShape and adjusted by <see cref="AdjustVectorEndPoint(IGeometryHost,PointD,out NodeShape)"/></param>
		/// <param name="oppositeShape">The opposite shape returned by <see cref="AdjustVectorEndPoint(IGeometryHost,PointD,out NodeShape)"/></param>
		/// <returns>The original or adjusted points.</returns>
		public static PointD ResolveProxyConnectorVectorEndPoint(PointD vectorEndPoint, NodeShape oppositeShape)
		{
			IProxyConnectorShape proxyConnector = oppositeShape as IProxyConnectorShape;
			if (proxyConnector != null)
			{
				NodeShape proxyFor = proxyConnector.ProxyConnectorShapeFor as NodeShape;
				if (proxyFor != null)
				{
					return proxyFor.AbsoluteCenter;
				}
			}
			return vectorEndPoint;
		}
示例#59
0
		/// <summary>
		/// Sets the central shape from which all other shapes will extend.
		/// </summary>
		public void SetRootShape(NodeShape shape)
		{
			myRootShape = shape;
		}