예제 #1
0
        /// <summary>
        /// Sets the given pen with the new given color.
        /// </summary>
        internal static void SetShapePenColor(this ShapeElement shape, StyleSetResourceId resourceId, Color color)
        {
            PenSettings penSettings = shape.StyleSet.GetOverriddenPenSettings(resourceId);

            if (penSettings == null)
            {
                penSettings = new PenSettings();
            }

            penSettings.Color = color;
            shape.StyleSet.OverridePen(resourceId, penSettings);
            shape.Invalidate();
        }
예제 #2
0
        /// <summary>
        /// Sets the given brush with the new given color.
        /// </summary>
        internal static void SetShapeBrushColor(this ShapeElement shape, StyleSetResourceId resourceId, Color color)
        {
            BrushSettings brushSettings = shape.StyleSet.GetOverriddenBrushSettings(resourceId);

            if (brushSettings == null)
            {
                brushSettings = new BrushSettings();
            }

            brushSettings.Color = color;
            shape.StyleSet.OverrideBrush(resourceId, brushSettings);
            shape.Invalidate();
        }
예제 #3
0
        /// <summary>
        /// Force a redraw of the associated presentation elements on a given diagram.
        /// This is used when a transaction is not active to update for a temporary
        /// display change.
        /// </summary>
        private static void RedrawPelsOnDiagram(ModelElement element, Diagram diagram)
        {
            LinkedElementCollection <PresentationElement> pels = PresentationViewsSubject.GetPresentation(element);
            int pelsCount = pels.Count;

            for (int i = 0; i < pelsCount; ++i)
            {
                ShapeElement shape = pels[i] as ShapeElement;
                if (shape != null && shape.Diagram == diagram)
                {
                    shape.Invalidate(true);
                }
            }
        }
예제 #4
0
        public static bool SelectModelElement(this DiagramView diagramView, ModelElement modelElement, bool ensureVisible)
        {
            // Get the shape element that corresponds to the model element

            ShapeElement shapeElement = PresentationViewsSubject.GetPresentation(modelElement)
                                        .OfType <ShapeElement>()
                                        .FirstOrDefault(s => s.Diagram == diagramView.Diagram);

            if (shapeElement != null)
            {
                // Make sure the shape element is visible (because connectors can be hidden)
                if (!shapeElement.IsVisible)
                {
                    shapeElement.Show();
                }

                // Create a diagram item for this shape element and select it
                diagramView.Selection.Set(new DiagramItem(shapeElement));

                if (ensureVisible)
                {
                    diagramView.Selection.EnsureVisible(DiagramClientView.EnsureVisiblePreferences.ScrollIntoViewCenter);
                    diagramView.ZoomAtViewCenter(1);
                }

                shapeElement.Invalidate();
                return(true);
            }

            // If the model element does not have a shape, try to cast it IModelElementCompartment

            if (modelElement is IModelElementInCompartment compartmentedModelElement)
            {
                // Get the parent
                IModelElementWithCompartments parentModelElement = compartmentedModelElement.ParentModelElement;

                if (parentModelElement != null)
                {
                    // Get the compartment that stores the model element
                    CompartmentShape parentShapeElement = PresentationViewsSubject.GetPresentation((ModelElement)parentModelElement)
                                                          .OfType <CompartmentShape>()
                                                          .FirstOrDefault(s => s.Diagram == diagramView.Diagram);

                    ElementListCompartment compartment = parentShapeElement?.GetCompartment(compartmentedModelElement.CompartmentName);

                    if (compartment != null)
                    {
                        if (!compartment.IsExpanded)
                        {
                            using (Transaction trans = modelElement.Store.TransactionManager.BeginTransaction("IsExpanded"))
                            {
                                compartment.IsExpanded = true;
                                trans.Commit();
                            }
                        }

                        // Find the model element in the compartment

                        int index = compartment.Items.IndexOf(modelElement);

                        if (index >= 0)
                        {
                            // Create a diagram item and select it
                            diagramView.Selection.Set(new DiagramItem(compartment, compartment.ListField, new ListItemSubField(index)));

                            if (ensureVisible)
                            {
                                diagramView.Selection.EnsureVisible(DiagramClientView.EnsureVisiblePreferences.ScrollIntoViewCenter);
                                diagramView.ZoomAtViewCenter(1);
                            }

                            compartment.Invalidate();
                            return(true);
                        }
                    }
                }
            }

            return(false);
        }