Beispiel #1
0
        // pin & unpin handling -- begin
        // ### make sure no side effect for EVAACodeSnippetShape (reference mode)
        public bool SelectUnpinedParentShape(DiagramItem item, DiagramClientView view)
        {
            if (item == null || view == null)
            {
                return(false);
            }

            // find top-most unpined predecessor
            VDWidgetShape shape     = this;
            bool          bReSelect = false;

            while ((shape.isPinned || shape is VDHoriContainerShape || shape is VDVertContainerShape) && /* avoid selecting container */
                   shape.ParentShape != null && shape.ParentShape is VDWidgetShape)
            {
                shape     = shape.ParentShape as VDWidgetShape;
                bReSelect = true;
            }

            if (shape != null && bReSelect)// && !object.ReferenceEquals(shape, this))
            {
                item.SetItem(shape);
                view.Selection.Clear();
                view.Selection.Add(item);
                view.Selection.PrimaryItem = item;
                view.Selection.FocusedItem = item;
                return(true);
            }

            return(false);
        }
            public override RectangleD GetCompliantBounds(ShapeElement shape, RectangleD proposedBounds)
            {
                // base rule
                proposedBounds = VDDefaultBoundsRules.Instance.GetCompliantBounds(shape, proposedBounds);

                VDWidgetShape    parentShape = shape.ParentShape as VDWidgetShape;
                VDContainer      thisMEL     = shape.ModelElement as VDContainer;
                VDContainerShape thisPEL     = shape as VDContainerShape;

                //
                if (parentShape != null && thisMEL != null && thisPEL != null)
                {
                    if (parentShape is VDHoriContainerShape)
                    {
                        // setup left anchor
                        setAnchor(parentShape, thisMEL, thisPEL, thisMEL.HasLeftAnchor && !thisPEL.Anchoring.HasLeftAnchor,
                                  thisMEL.LeftSibling, AnchoringBehavior.Edge.Left);
                        // setup right anchor
                        setAnchor(parentShape, thisMEL, thisPEL, thisMEL.HasRightAnchor && !thisPEL.Anchoring.HasRightAnchor,
                                  thisMEL.RightSibling, AnchoringBehavior.Edge.Right);
                    }
                    else if (parentShape is VDVertContainerShape)
                    {
                        // setup top anchor
                        setAnchor(parentShape, thisMEL, thisPEL, thisMEL.HasTopAnchor && !thisPEL.Anchoring.HasTopAnchor,
                                  thisMEL.TopSibling, AnchoringBehavior.Edge.Top);
                        // setup bottom anchor
                        setAnchor(parentShape, thisMEL, thisPEL, thisMEL.HasBottomAnchor && !thisPEL.Anchoring.HasBottomAnchor,
                                  thisMEL.BottomSibling, AnchoringBehavior.Edge.Bottom);
                    }
                    else if (!(parentShape is VDFullFilledContainerShape))
                    {
                        // setup left anchor
                        setAnchor(parentShape, thisMEL, thisPEL, thisMEL.HasLeftAnchor && !thisPEL.Anchoring.HasLeftAnchor,
                                  thisMEL.LeftSibling, AnchoringBehavior.Edge.Left);
                        // setup right anchor
                        setAnchor(parentShape, thisMEL, thisPEL, thisMEL.HasRightAnchor && !thisPEL.Anchoring.HasRightAnchor,
                                  thisMEL.RightSibling, AnchoringBehavior.Edge.Right);
                        // setup top anchor
                        setAnchor(parentShape, thisMEL, thisPEL, thisMEL.HasTopAnchor && !thisPEL.Anchoring.HasTopAnchor,
                                  thisMEL.TopSibling, AnchoringBehavior.Edge.Top);
                        // setup bottom anchor
                        setAnchor(parentShape, thisMEL, thisPEL, thisMEL.HasBottomAnchor && !thisPEL.Anchoring.HasBottomAnchor,
                                  thisMEL.BottomSibling, AnchoringBehavior.Edge.Bottom);
                    }

                    if (thisMEL is VDHoriContainer && ((VDHoriContainer)thisMEL).FixedHeight > VDConstants.DOUBLE_DIFF)
                    {
                        proposedBounds = new RectangleD(proposedBounds.Location,
                                                        new SizeD(proposedBounds.Width, ((VDHoriContainer)thisMEL).FixedHeight));
                    }
                    else if (thisMEL is VDVertContainer && ((VDVertContainer)thisMEL).FixedWidth > VDConstants.DOUBLE_DIFF)
                    {
                        proposedBounds = new RectangleD(proposedBounds.Location,
                                                        new SizeD(((VDVertContainer)thisMEL).FixedWidth, proposedBounds.Height));
                    }
                }

                return(proposedBounds);
            }
            private static void setAnchor(VDWidgetShape parentShape, VDContainer thisMEL, VDContainerShape thisPEL,
                                          bool setAnchor, VDWidget sibling, AnchoringBehavior.Edge edge)
            {
                if (!setAnchor)
                {
                    return;
                }

                if (sibling != null) // anchor to sibling
                {
                    VDWidgetShape siblingShape = parentShape.GetChildShape <VDWidgetShape>(sibling);
                    if (siblingShape != null)
                    {
                        switch (edge)
                        {
                        case AnchoringBehavior.Edge.Bottom:
                            thisPEL.Anchoring.SetBottomAnchor(siblingShape, AnchoringBehavior.Edge.Top, thisMEL.BottomMargin);
                            break;

                        case AnchoringBehavior.Edge.Left:
                            thisPEL.Anchoring.SetLeftAnchor(siblingShape, AnchoringBehavior.Edge.Right, thisMEL.LeftMargin);
                            break;

                        case AnchoringBehavior.Edge.Right:
                            thisPEL.Anchoring.SetRightAnchor(siblingShape, AnchoringBehavior.Edge.Left, thisMEL.RightMargin);
                            break;

                        case AnchoringBehavior.Edge.Top:
                            thisPEL.Anchoring.SetTopAnchor(siblingShape, AnchoringBehavior.Edge.Bottom, thisMEL.TopMargin);
                            break;
                        }
                    }
                }
                else // anchor to parent
                {
                    switch (edge)
                    {
                    case AnchoringBehavior.Edge.Bottom:
                        thisPEL.Anchoring.SetBottomAnchor(edge, thisMEL.BottomMargin);
                        break;

                    case AnchoringBehavior.Edge.Left:
                        thisPEL.Anchoring.SetLeftAnchor(edge, thisMEL.LeftMargin);
                        break;

                    case AnchoringBehavior.Edge.Right:
                        thisPEL.Anchoring.SetRightAnchor(edge, thisMEL.RightMargin);
                        break;

                    case AnchoringBehavior.Edge.Top:
                        thisPEL.Anchoring.SetTopAnchor(edge, thisMEL.TopMargin);
                        break;
                    }
                }
            }
 public override void OnRelayoutChildShapes()
 {
     foreach (var childShape in NestedChildShapes)
     {
         VDWidgetShape ws = childShape as VDWidgetShape;
         if (ws != null)
         {
             ws.OnBoundsFixup(BoundsFixupState.ViewFixup, 1, false);
         }
     }
 }
 public override void OnClick(DiagramPointEventArgs e)
 {
     if (e != null && e.HitDiagramItem != null && e.HitDiagramItem.Field != null &&
         e.HitDiagramItem.Field is VDTitleImageField)
     {
         VDTitleImageField field       = e.HitDiagramItem.Field as VDTitleImageField;
         VDWidgetShape     parentShape = this.ParentShape as VDWidgetShape;
         if (parentShape != null)
         {
             parentShape.OnClickAdditionalTitleIcon(field.Index);
         }
     }
     base.OnClick(e);
 }
Beispiel #6
0
            public override RectangleD GetCompliantBounds(ShapeElement shape, RectangleD proposedBounds)
            {
                proposedBounds = DefaultBoundsRules.Instance.GetCompliantBounds(shape, proposedBounds);

                VDWidgetShape parent = shape.ParentShape as VDWidgetShape;

                if (parent != null)
                {
                    if (parent is VDHoriContainerShape)
                    {
                        if (proposedBounds.Location.Y != 0 || proposedBounds.Size.Height != parent.Bounds.Height)
                        {
                            proposedBounds = new RectangleD(new PointD(proposedBounds.Location.X, 0),
                                                            new SizeD(proposedBounds.Size.Width, parent.Bounds.Height));
                        }
                    }
                    else if (parent is VDVertContainerShape)
                    {
                        if (proposedBounds.Location.X != 0 || proposedBounds.Size.Width != parent.Bounds.Width)
                        {
                            proposedBounds = new RectangleD(new PointD(0, proposedBounds.Location.Y),
                                                            new SizeD(parent.Bounds.Width, proposedBounds.Size.Height));
                        }
                    }
                    else if (parent is VDFullFilledContainerShape)
                    {
                        proposedBounds = new RectangleD(PointD.Empty, parent.Bounds.Size);
                    }
                }

                VDWidgetShape thisShape = shape as VDWidgetShape;

                if (thisShape != null && !thisShape.AllowToResizeUnResizableSides &&
                    thisShape.ModelElement != null && !(thisShape.ModelElement is VDInternalUtility))
                {
                    if (thisShape.ResizableSides == NodeSides.Horizontal)
                    {
                        proposedBounds.Height = thisShape.DefaultSize.Height;
                    }
                    else if (thisShape.ResizableSides == NodeSides.Vertical)
                    {
                        proposedBounds.Width = thisShape.DefaultSize.Width;
                    }
                    else if (thisShape.ResizableSides == NodeSides.None)
                    {
                        proposedBounds.Size = thisShape.DefaultSize;
                    }
                }
                return(proposedBounds);
            }
            public override RectangleD GetCompliantBounds(ShapeElement portShape, RectangleD proposedBounds)
            {
                if (portShape == null)
                {
                    throw new ArgumentNullException("portShape");
                }

                VDWidgetShape parentShape = portShape.ParentShape as VDWidgetShape;

                if (parentShape == null || portShape.Store.InUndoRedoOrRollback)
                {
                    return(proposedBounds);
                }

                PointD location = new PointD(0, -portShape.DefaultSize.Height - portShape.OutlinePenWidth * 2);
                SizeD  size     = portShape.DefaultSize;

                TextField titleTextField = portShape.FindShapeField("WidgetTitleText") as TextField;

                if (titleTextField != null)
                {
                    size.Width  = titleTextField.GetMinimumSize(portShape).Width;
                    size.Width += size.Height + 0.03;
                }
                if (parentShape.HasWidgetTitleIcon)
                {
                    size.Width += size.Height + 0.02; // add more space for icon
                }

                for (int i = 0; i < ADDITIONAL_TITLE_ICON_COUNT; i++)
                {
                    // add more space for additional title icon
                    if (parentShape.HasAdditionalWidgetTitleIcon(i))
                    {
                        size.Width += size.Height + 0.02;
                    }
                }

                // should be smaller than parent shape
                if (size.Width > parentShape.Size.Width)
                {
                    size.Width = parentShape.Size.Width;
                }

                return(new RectangleD(location, size));
            }
        void OnToggleButtonStateChanging(object sender, ToggleButtonEventArgs e)
        {
            VDWidgetTitlePort title = e.ParentShape as VDWidgetTitlePort;

            if (title != null && title.ParentShape != null && title.ParentShape is VDWidgetShape)
            {
                VDWidgetShape widget = title.ParentShape as VDWidgetShape;
                using (Transaction transaction = title.Store.TransactionManager.BeginTransaction("Pin/Unpin"))
                {
                    widget.isPinned = !widget.isPinned;
                    transaction.Commit();
                }

                //
                DiagramClientView clientView = title.Diagram.ActiveDiagramView.DiagramClientView;
                widget.SelectUnpinedParentShape(new DiagramItem(), clientView);
            }
        }
Beispiel #9
0
        public override void ElementPropertyChanged(ElementPropertyChangedEventArgs e)
        {
            base.ElementPropertyChanged(e);

            if (e.ModelElement == null || e.DomainProperty == null)
            {
                return;
            }

            VDWidgetShape shape = e.ModelElement as VDWidgetShape;

            //
            if ((e.DomainProperty.Id == VDWidgetShape.relayoutChildrenDomainPropertyId) && ((bool)e.NewValue))
            {
                shape.relayoutChildren = false;
                shape.OnRelayoutChildShapes();
            }
        }
        private static ICollection <PresentationElement> domainToRelativePresentation(ModelElement modelElement)
        {
            // modelElement is VDWidgetShape
            VDWidgetShape widgetShape = modelElement as VDWidgetShape;

            if (widgetShape != null)
            {
                var port = widgetShape.RelativeChildShapes.Find(x => x is VDWidgetTitlePort);
                if (port != null)
                {
                    return new List <PresentationElement>()
                           {
                               port
                           }
                }
                ;
            }
            return(null);
        }
        public override void OnClick(DiagramPointEventArgs e)
        {
            base.OnClick(e);

            foreach (var shape in this.Diagram.NestedChildShapes)
            {
                if (shape is VDWidgetShape)
                {
                    VDWidgetShape ws = shape as VDWidgetShape;
                    if (ws.DoHitTest(e.MousePosition, e.DiagramHitTestInfo))
                    {
                        ws.ZOrder += this.ZOrder;
                        ws.Invalidate(true);
                        //this.Diagram.Invalidate(true);
                        break;
                    }
                }
            }
        }
Beispiel #12
0
            public override RectangleD GetCompliantBounds(ShapeElement shape, RectangleD proposedBounds)
            {
                VDHoriSeparatorShape separatorShape = shape as VDHoriSeparatorShape;

                if (separatorShape == null)
                {
                    throw new ArgumentNullException("horizontalSeparatorShape");
                }

                VDWidgetShape parentShape = separatorShape.ParentShape as VDWidgetShape;

                if (parentShape == null || separatorShape.Store.InUndoRedoOrRollback)
                {
                    return(proposedBounds);
                }

                VDHoriSeparator model = separatorShape.ModelElement as VDHoriSeparator;

                if (model == null)
                {
                    return(proposedBounds);
                }

                bool   bFlagBoundsSet = false;
                PointD location       = proposedBounds.Location;
                SizeD  size           = proposedBounds.Size;

                // anchor to parent widget
                if (!separatorShape.Anchoring.HasLeftAnchor)
                {
                    separatorShape.Anchoring.SetLeftAnchor(0);
                }
                if (!separatorShape.Anchoring.HasRightAnchor)
                {
                    separatorShape.Anchoring.SetRightAnchor(1);
                }

                // anchor to top widget
                if (model.TopWidget != null)
                {
                    NodeShape topWidgetShape = parentShape.NestedChildShapes.Find(c => c.ModelElement == model.TopWidget) as NodeShape;
                    if (topWidgetShape != null)
                    {
                        if (!topWidgetShape.Anchoring.HasBottomAnchor)
                        {
                            topWidgetShape.Anchoring.SetBottomAnchor(separatorShape, AnchoringBehavior.Edge.Top, model.TopMargin);
                        }
                        //if (!separatorShape.Anchoring.HasLeftAnchor)
                        //    separatorShape.Anchoring.SetLeftAnchor(topWidgetShape, AnchoringBehavior.Edge.Left, 0);
                        //if (!separatorShape.Anchoring.HasRightAnchor)
                        //    separatorShape.Anchoring.SetRightAnchor(topWidgetShape, AnchoringBehavior.Edge.Right, 0);

                        // set bounds of HorizonalSeparator according to top widget
                        //location.X = topWidgetShape.Bounds.Left;
                        if (location.Y < VDConstants.DOUBLE_DIFF || location.Y + size.Height + VDConstants.DOUBLE_DIFF > parentShape.Bounds.Height)
                        {
                            location.Y = topWidgetShape.Bounds.Bottom + model.TopMargin;
                        }
                        bFlagBoundsSet = true;
                    }
                }

                // anchor to bottom widget
                if (model.BottomWidget != null)
                {
                    NodeShape bottomWidgetShape = parentShape.NestedChildShapes.Find(c => c.ModelElement == model.BottomWidget) as NodeShape;
                    if (bottomWidgetShape != null)
                    {
                        if (!bottomWidgetShape.Anchoring.HasTopAnchor)
                        {
                            bottomWidgetShape.Anchoring.SetTopAnchor(separatorShape, AnchoringBehavior.Edge.Bottom, model.BottomMargin);
                        }
                        //if (!separatorShape.Anchoring.HasLeftAnchor)
                        //    separatorShape.Anchoring.SetLeftAnchor(bottomWidgetShape, AnchoringBehavior.Edge.Left, 0);
                        //if (!separatorShape.Anchoring.HasRightAnchor)
                        //    separatorShape.Anchoring.SetRightAnchor(bottomWidgetShape, AnchoringBehavior.Edge.Right, 0);

                        // set bounds of handle according to bottom widget
                        if (!bFlagBoundsSet)
                        {
                            //location.X = bottomWidgetShape.Bounds.Left;
                            if (location.Y < VDConstants.DOUBLE_DIFF || location.Y + size.Height + VDConstants.DOUBLE_DIFF > parentShape.Bounds.Height)
                            {
                                location.Y = bottomWidgetShape.Bounds.Top - size.Height - model.BottomMargin;
                            }
                        }
                    }
                }

                // set initial Y position
                if (model.DefaultY >= 0)
                {
                    location.Y     = model.DefaultY;
                    model.DefaultY = -1;
                }

                return(new RectangleD(location, size));
            }
Beispiel #13
0
            public override RectangleD GetCompliantBounds(ShapeElement shape, RectangleD proposedBounds)
            {
                VDVertSeparatorShape separatorShape = shape as VDVertSeparatorShape;

                if (separatorShape == null)
                {
                    throw new ArgumentNullException("horizontalSeparatorShape");
                }

                VDWidgetShape parentShape = separatorShape.ParentShape as VDWidgetShape;

                if (parentShape == null || separatorShape.Store.InUndoRedoOrRollback)
                {
                    return(proposedBounds);
                }

                VDVertSeparator model = separatorShape.ModelElement as VDVertSeparator;

                if (model == null)
                {
                    return(proposedBounds);
                }

                bool   bFlagBoundsSet = false;
                PointD location       = proposedBounds.Location;
                SizeD  size           = proposedBounds.Size;

                // anchor to parent
                if (!separatorShape.Anchoring.HasTopAnchor)
                {
                    separatorShape.Anchoring.SetTopAnchor(0);
                }
                if (!separatorShape.Anchoring.HasBottomAnchor)
                {
                    separatorShape.Anchoring.SetBottomAnchor(1);
                }

                // anchor to left widget
                if (model.LeftWidget != null)
                {
                    NodeShape leftWidgetShape = parentShape.NestedChildShapes.Find(c => c.ModelElement == model.LeftWidget) as NodeShape;
                    if (leftWidgetShape != null)
                    {
                        if (!leftWidgetShape.Anchoring.HasRightAnchor)
                        {
                            leftWidgetShape.Anchoring.SetRightAnchor(separatorShape, AnchoringBehavior.Edge.Left, model.LeftMargin);
                        }
                        //if (!separatorShape.Anchoring.HasTopAnchor)
                        //    separatorShape.Anchoring.SetTopAnchor(leftWidgetShape, AnchoringBehavior.Edge.Top, 0);
                        //if (!separatorShape.Anchoring.HasBottomAnchor)
                        //    separatorShape.Anchoring.SetBottomAnchor(leftWidgetShape, AnchoringBehavior.Edge.Bottom, 0);

                        // set bounds of separator according to left widget
                        if (location.X < VDConstants.DOUBLE_DIFF || location.X + size.Width + VDConstants.DOUBLE_DIFF > parentShape.Bounds.Width)
                        {
                            location.X = leftWidgetShape.Bounds.Right + model.LeftMargin;
                        }
                        //location.Y = leftWidgetShape.Bounds.Top;
                        bFlagBoundsSet = true;
                    }
                }

                // anchor to right widget
                if (model.RightWidget != null)
                {
                    NodeShape rightWidgetShape = parentShape.NestedChildShapes.Find(c => c.ModelElement == model.RightWidget) as NodeShape;
                    if (rightWidgetShape != null)
                    {
                        if (!rightWidgetShape.Anchoring.HasLeftAnchor)
                        {
                            rightWidgetShape.Anchoring.SetLeftAnchor(separatorShape, AnchoringBehavior.Edge.Right, model.RightMargin);
                        }
                        //if (!separatorShape.Anchoring.HasTopAnchor)
                        //    separatorShape.Anchoring.SetTopAnchor(rightWidgetShape, AnchoringBehavior.Edge.Top, 0);
                        //if (!separatorShape.Anchoring.HasBottomAnchor)
                        //    separatorShape.Anchoring.SetBottomAnchor(rightWidgetShape, AnchoringBehavior.Edge.Bottom, 0);

                        // set bounds of handle according to bottom widget
                        if (!bFlagBoundsSet)
                        {
                            if (location.X < VDConstants.DOUBLE_DIFF || location.X + size.Width + VDConstants.DOUBLE_DIFF > parentShape.Bounds.Width)
                            {
                                location.X = rightWidgetShape.Bounds.Left - size.Width - model.RightMargin;
                            }
                            ;
                            //location.Y = rightWidgetShape.Bounds.Top;
                        }
                    }
                }

                // set initial Y position
                if (model.DefaultX >= 0)
                {
                    location.Y     = model.DefaultX;
                    model.DefaultX = -1;
                }

                return(new RectangleD(location, size));
            }