Exemplo n.º 1
0
        /// <summary>
        /// DeleteRule: typeof(ORMSolutions.ORMArchitect.Core.ObjectModel.ExclusiveOrConstraintCoupler), FireTime=TopLevelCommit, Priority=DiagramFixupConstants.AddShapeRulePriority;
        /// Split a single shape into two shapes when a exclusion constraint
        /// is decoupled from a mandatory constraint
        /// </summary>
        private static void ExclusiveOrCouplerDeletedRule(ElementDeletedEventArgs e)
        {
            ExclusiveOrConstraintCoupler link      = e.ModelElement as ExclusiveOrConstraintCoupler;
            MandatoryConstraint          mandatory = link.MandatoryConstraint;
            ExclusionConstraint          exclusion = link.ExclusionConstraint;

            if (!mandatory.IsDeleted && !exclusion.IsDeleted)
            {
                LinkedElementCollection <PresentationElement> pels = PresentationViewsSubject.GetPresentation(mandatory);
                int pelCount = pels.Count;
                for (int i = 0; i < pelCount; ++i)
                {
                    ExternalConstraintShape shape = pels[i] as ExternalConstraintShape;
                    if (shape != null)
                    {
                        ORMDiagram diagram = (ORMDiagram)shape.Diagram;
                        RectangleD bounds  = shape.AbsoluteBounds;
                        double     width   = bounds.Width;
                        bounds.Offset(-width / 2, 0);
                        bounds = diagram.BoundsRules.GetCompliantBounds(shape, bounds);
                        shape.AbsoluteBounds = bounds;
                        bounds.Offset(width, 0);
                        diagram.PlaceORMElementOnDiagram(null, exclusion, bounds.Location, ORMPlacementOption.None, null, null);
                    }
                }
            }
        }
Exemplo n.º 2
0
            /// <summary>
            /// Create a connection between an ExternalConstraintShape and a FactType. Roles
            /// used in the connection are stored with the currently active connect action.
            /// </summary>
            /// <param name="sourceShapeElement">The source of the requested connection</param>
            /// <param name="targetShapeElement">The target of the requested connection</param>
            /// <param name="paintFeedbackArgs">PaintFeedbackArgs</param>
            public override void CreateConnection(ShapeElement sourceShapeElement, ShapeElement targetShapeElement, PaintFeedbackArgs paintFeedbackArgs)
            {
                ORMDiagram        diagram = (ORMDiagram)sourceShapeElement.Diagram;
                RoleConnectAction action  = diagram.RoleConnectAction;
                ObjectType        objectType;
                RoleBase          sourceRole = action.mySourceRole;
                RoleBase          roleBase;
                RoleBase          targetRole;
                FactTypeShape     factTypeShape;

                if (sourceRole != null &&
                    sourceShapeElement == targetShapeElement &&
                    null != (targetRole = action.myLastMouseMoveRole) &&
                    targetRole != sourceRole &&
                    null != (factTypeShape = sourceShapeElement as FactTypeShape))
                {
                    LinkedElementCollection <RoleBase> displayedRoles = factTypeShape.GetEditableDisplayRoleOrder();
                    displayedRoles.Move(displayedRoles.IndexOf(sourceRole), displayedRoles.IndexOf(targetRole));
                }
                else if ((null != (roleBase = sourceRole) && null != (objectType = ObjectTypeFromShape(targetShapeElement))) ||
                         (null != (objectType = action.mySourceObjectType) && null != (roleBase = action.myLastMouseMoveRole)))
                {
                    // Don't trigger a change if none is indicated. Turn this into a noop
                    Role role = roleBase.Role;
                    if (role.RolePlayer != objectType)
                    {
                        role.RolePlayer = objectType;
                    }
                }
                else if (targetShapeElement == diagram &&
                         action.mySourceRoleMissingConnector)
                {
                    diagram.PlaceORMElementOnDiagram(null, roleBase.Role.RolePlayer, paintFeedbackArgs.TargetFeedbackBounds.Location, ORMPlacementOption.AllowMultipleShapes, null, null);
                }
            }
Exemplo n.º 3
0
        /// <summary>
        /// Implements <see cref="IModelingEventSubscriber.ManageModelingEventHandlers"/>.
        /// </summary>
        protected void ManageModelingEventHandlers(ModelingEventManager eventManager, EventSubscriberReasons reasons, EventHandlerAction action)
        {
            // UNDONE: If we delay attach user interface events (possible in the future for
            // external model scenarios), then we need to check ModelStateEvents here and
            // be more precise in which events are attached that affect model state such as
            // calculated shape size. Currently, this is only called without 'UserInterfaceEvents'
            // for unit-testing.
            if ((EventSubscriberReasons.DocumentLoaded | EventSubscriberReasons.UserInterfaceEvents) == (reasons & (EventSubscriberReasons.DocumentLoaded | EventSubscriberReasons.UserInterfaceEvents)))
            {
                Store store = Store;
                ORMDiagram.ManageEventHandlers(store, eventManager, action);
                ORMBaseShape.ManageEventHandlers(store, eventManager, action);
                ReadingShape.ManageEventHandlers(store, eventManager, action);
                ExternalConstraintShape.ManageEventHandlers(store, eventManager, action);
                RolePlayerLink.ManageEventHandlers(store, eventManager, action);
                ObjectTypeShape.ManageEventHandlers(store, eventManager, action);
                ORMBaseBinaryLinkShape.ManageEventHandlers(store, eventManager, action);
                FactTypeShape.ManageEventHandlers(store, eventManager, action);
                SubtypeLink.ManageEventHandlers(store, eventManager, action);
            }

            if (0 != (reasons & EventSubscriberReasons.DocumentLoaded))
            {
                IORMToolServices             services;
                IORMExtendableElementService extendableElementService;
                if (null != (services = Store as IORMToolServices) &&
                    null != (extendableElementService = services.ExtendableElementService))
                {
                    extendableElementService.RegisterExtensionRoles(new Guid[] { ORMDiagramHasExtensionElement.ExtensionDomainRoleId, ORMBaseShapeHasExtensionElement.ExtensionDomainRoleId });
                }
            }
        }
 /// <summary>
 /// An IMS event to track the shape element added to the associated
 /// diagram during this connect action.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void InternalConstraintAddedEvent(object sender, ElementAddedEventArgs e)
 {
     if (myAddedConstraint == null)
     {
         UniquenessConstraint candidate = e.ModelElement as UniquenessConstraint;
         if (candidate != null && candidate.IsInternal)
         {
             ORMDiagram d = Diagram as ORMDiagram;
             if (d != null)
             {
                 // Find the shape associated with the fact type we added to
                 LinkedElementCollection <FactType> candidateFacts = candidate.FactTypeCollection;
                 if (candidateFacts.Count != 0)
                 {
                     FactTypeShape shape = d.FindShapeForElement(candidateFacts[0]) as FactTypeShape;
                     if (shape != null)
                     {
                         myDropTargetShape = shape;
                         myAddedConstraint = candidate;
                     }
                 }
             }
         }
     }
 }
Exemplo n.º 5
0
        /// <summary>
        /// Set this mouse action as the active action on the
        /// diagram of the given shape, and activate its drag line
        /// centered on the shape.
        /// </summary>
        /// <param name="chainFromPoint">The point to begin the mouse action</param>
        /// <param name="clientView">The active DiagramClientView</param>
        /// <param name="emulateDrag">true if this should emulate a drag, meaning
        /// that the mouse up acts like a click.</param>
        public void ChainMouseAction(PointD chainFromPoint, DiagramClientView clientView, bool emulateDrag)
        {
            DiagramView activeView = Diagram.ActiveDiagramView;

            if (activeView != null)
            {
                // Move on to the selection action
                clientView.ActiveMouseAction = this;

                // Now emulate a mouse click in the middle of the added constraint. The click
                // actions provide a starting point for the connect action, so a mouse move
                // provides a drag line.
                Point emulateClickPoint = clientView.WorldToDevice(chainFromPoint);
                DiagramMouseEventArgs mouseEventArgs = new DiagramMouseEventArgs(new MouseEventArgs(MouseButtons.Left, 1, emulateClickPoint.X, emulateClickPoint.Y, 0), clientView);
                MouseDown(mouseEventArgs);
                Click(new DiagramPointEventArgs(emulateClickPoint.X, emulateClickPoint.Y, PointRelativeTo.Client, clientView));
                MouseUp(mouseEventArgs);

                // An extra move lets us chain when the mouse is not on the design surface,
                // such as when we are being activated via the task list.
                MouseMove(mouseEventArgs);

                myEmulateDrag = emulateDrag;
                ORMDiagram.SelectToolboxItem(activeView, ResourceStrings.ToolboxRoleConnectorItemId);
            }
        }
        /// <summary>
        /// Set this mouse action as the active action on the
        /// diagram of the given shape.
        /// </summary>
        /// <param name="attachToShape">The shape the constraint is being attached to.</param>
        /// <param name="constraint">The constraint being connected.</param>
        /// <param name="clientView">The active DiagramClientView</param>
        public void ChainMouseAction(FactTypeShape attachToShape, UniquenessConstraint constraint, DiagramClientView clientView)
        {
            DiagramView activeView = Diagram.ActiveDiagramView;

            if (activeView != null)
            {
                // Move on to the selection action
                clientView.ActiveMouseAction = this;

                // Now emulate a mouse click in the middle of the added constraint. The click
                // actions provide a starting point for the connect action, so a mouse move
                // provides a drag line.
                Point emulateClickPoint = clientView.WorldToDevice(attachToShape.GetAbsoluteConstraintAttachPoint(constraint, FactSetConstraint.GetLink(constraint, attachToShape.AssociatedFactType)));
                DiagramMouseEventArgs mouseEventArgs = new DiagramMouseEventArgs(new MouseEventArgs(MouseButtons.Left, 1, emulateClickPoint.X, emulateClickPoint.Y, 0), clientView);
                MouseDown(mouseEventArgs);
                Click(new DiagramPointEventArgs(emulateClickPoint.X, emulateClickPoint.Y, PointRelativeTo.Client, clientView));
                MouseUp(mouseEventArgs);
                attachToShape.Invalidate(true);

                // An extra move lets us chain when the mouse is not on the design surface,
                // such as when we are being activated via the task list.
                MouseMove(mouseEventArgs);

                ORMDiagram.SelectToolboxItem(activeView, ResourceStrings.ToolboxInternalUniquenessConstraintItemId);
                FactTypeShape.ActiveInternalUniquenessConstraintConnectAction = this;
            }
        }
Exemplo n.º 7
0
 /// <summary>
 /// Redirect all luminosity modification to the ORMDiagram.ModifyLuminosity
 /// algorithm
 /// </summary>
 /// <param name="currentLuminosity">The luminosity to modify</param>
 /// <param name="view">The view containing this item</param>
 /// <returns>Modified luminosity value</returns>
 protected override int ModifyLuminosity(int currentLuminosity, DiagramClientView view)
 {
     if (view.HighlightedShapes.Contains(new DiagramItem(this)))
     {
         return(ORMDiagram.ModifyLuminosity(currentLuminosity));
     }
     return(currentLuminosity);
 }
Exemplo n.º 8
0
        /// <summary>
        /// Creates the diagram.
        /// </summary>
        private void CreateDiagram(ModelElement model)
        {
            Store store = Utility.ValidateStore(model.Store);

            if (store == null)
            {
                return;
            }
            Partition  partition = Partition.FindByAlternateId(store, this);
            ORMDiagram diagram   = null;

            if (partition == null)
            {
                partition             = new Partition(store);
                partition.AlternateId = this;
                store.StoreDisposing += new EventHandler(Store_StoreDisposing);
            }
            else
            {
                ReadOnlyCollection <ORMDiagram> diagrams = partition.ElementDirectory.FindElements <ORMDiagram>();
                if (diagrams.Count != 0)
                {
                    diagram = diagrams[0];
                }
            }
            if (diagram == null && ((IORMToolServices)store).CanAddTransaction)
            {
                // We can get a partition with no diagram with an undo operation. The
                // diagram will be removed, but the partition will remain.
                using (Transaction t = store.TransactionManager.BeginTransaction("Create Context Diagram"))
                {
                    diagram = new ORMDiagram(partition);
                    diagram.ForeignPartitionTest = delegate(Partition elementPartition)
                    {
                        object testId = elementPartition.AlternateId;
                        return((testId == null) || (testId == this.mySelectedPartitionId));
                    };
                    diagram.Associate(myDiagramView);
                    myDiagramView.HasWatermark = false;
                    diagram.ModelElement       = model;
                    diagram.AutoPopulateShapes = false;
                    if (t.HasPendingChanges)
                    {
                        t.Commit();
                    }
                }
            }
            myDiagram = diagram;
            DiagramClientView clientView = myDiagramView.DiagramClientView;

            if (clientView.Diagram != diagram)
            {
                clientView.Diagram = diagram;
            }
        }
Exemplo n.º 9
0
        /// <summary>
        /// If we've reached the dragging state, then
        /// chaing to the toolbox action.
        /// </summary>
        /// <param name="e"></param>
        protected override void OnMouseMove(DiagramMouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left && CurrentMouseActionState == DraggingState)
            {
                DiagramClientView clientView = e.DiagramClientView;
                // Stop this mouse action
                Complete(clientView);

                // Chain to other action
                ORMDiagram diagram = (ORMDiagram)clientView.Diagram;
                diagram.RoleConnectAction.ChainMouseAction(this.MouseDownPoint, clientView, true);
            }
        }
Exemplo n.º 10
0
 /// <summary>
 /// If the role object is part of a sticky external constraint shape
 /// object then activate it on a double click. Equivalent to the
 /// 'ActiveRoleSequence' diagram command.
 /// </summary>
 protected override void OnDoubleClick(DiagramPointEventArgs e)
 {
     // Note this looks like a strange place to put this, but this
     // is the mouse action that is active when a role is clicked on.
     if (myAllowDoubleClick)
     {
         ORMDiagram              ormDiagram = Diagram as ORMDiagram;
         IStickyObject           sticky;
         ExternalConstraintShape constraintShape;
         if (null != (sticky = ormDiagram.StickyObject) &&
             null != (constraintShape = sticky as ExternalConstraintShape))
         {
             foreach (Role role in e.DiagramHitTestInfo.HitDiagramItem.RepresentedElements)
             {
                 if (sticky.StickySelectable(role))
                 {
                     IConstraint constraint     = constraintShape.AssociatedConstraint;
                     Role        constraintRole = role;
                     switch (constraint.ConstraintType)
                     {
                     case ConstraintType.ExternalUniqueness:
                     case ConstraintType.Frequency:
                         Role       oppositeRole;
                         ObjectType oppositeRolePlayer;
                         if (null != (oppositeRole = role.OppositeRole as Role) &&
                             null != (oppositeRolePlayer = oppositeRole.RolePlayer) &&
                             oppositeRolePlayer.IsImplicitBooleanValue)
                         {
                             constraintRole = oppositeRole;
                         }
                         break;
                     }
                     foreach (ConstraintRoleSequence sequence in constraintRole.ConstraintRoleSequenceCollection)
                     {
                         if (constraint == sequence.Constraint)
                         {
                             ExternalConstraintConnectAction connectAction = ormDiagram.ExternalConstraintConnectAction;
                             connectAction.ConstraintRoleSequenceToEdit = sequence;
                             connectAction.ChainMouseAction(constraintShape, e.DiagramClientView);
                             e.Handled = true;
                             return;
                         }
                     }
                 }
                 break;
             }
         }
     }
     base.OnDoubleClick(e);
 }
Exemplo n.º 11
0
        /// <summary>
        /// Add error brushes to the styleSet
        /// </summary>
        protected override void InitializeResources(StyleSet classStyleSet)
        {
            base.InitializeResources(classStyleSet);

            IORMFontAndColorService colorService  = (Store as IORMToolServices).FontAndColorService;
            BrushSettings           brushSettings = new BrushSettings();

            //UNDONE: This color isn't permanent. probably want a better color for the errors.
            brushSettings.ForeColor = Color.LightPink;
            //brushSettings.ForeColor = colorService.GetForeColor(ORMDesignerColor.ConstraintError);
            brushSettings.HatchStyle = HatchStyle.LightDownwardDiagonal;
            brushSettings.BrushType  = typeof(HatchBrush);
            classStyleSet.AddBrush(ORMDiagram.ErrorBackgroundResource, DiagramBrushes.DiagramBackground, brushSettings);
            brushSettings.ForeColor = ORMDiagram.ModifyLuminosity(brushSettings.ForeColor);
            brushSettings.BackColor = ORMDiagram.ModifyLuminosity(((SolidBrush)classStyleSet.GetBrush(DiagramBrushes.DiagramBackground)).Color);
            classStyleSet.AddBrush(ORMDiagram.HighlightedErrorBackgroundResource, DiagramBrushes.DiagramBackground, brushSettings);

            BrushSettings transBrush = new BrushSettings();

            transBrush.ForeColor = Color.Transparent;
            classStyleSet.AddBrush(ORMDiagram.TransparentBrushResource, DiagramBrushes.DiagramBackground, transBrush);
        }
Exemplo n.º 12
0
            /// <summary>
            /// Called as the pointer is moved over potential targets after a source is selected
            /// So should be pretty quick
            /// </summary>
            /// <remarks>
            /// The cursor can change dependant on CanCreateConnection when this returns true
            /// </remarks>
            /// <param name="sourceShapeElement">ShapeElement</param>
            /// <param name="targetShapeElement">ShapeElement</param>
            /// <returns></returns>
            public override bool IsValidSourceAndTarget(ShapeElement sourceShapeElement, ShapeElement targetShapeElement)
            {
                ORMDiagram        diagram = (ORMDiagram)sourceShapeElement.Diagram;
                RoleConnectAction action  = diagram.RoleConnectAction;

                action.myRoleReorderConnector = false;
                ObjectType      objectType;
                RoleBase        sourceRole = action.mySourceRole;
                RoleBase        role;
                RoleBase        targetRole;
                Objectification objectification;

                // Reorder roles in the same shape
                if (sourceRole != null &&
                    sourceShapeElement == targetShapeElement &&
                    null != (targetRole = action.myLastMouseMoveRole) &&
                    targetRole != sourceRole)
                {
                    action.myRoleReorderConnector = true;
                    return(true);
                }
                else if ((null != (role = sourceRole) && null != (objectType = ObjectTypeFromShape(targetShapeElement)) &&
                          (null == (objectification = objectType.Objectification) || !objectification.IsImplied)) ||
                         (null != (objectType = action.mySourceObjectType) && null != (role = action.myLastMouseMoveRole)))
                {
                    return(role.Role.FactType != objectType.NestedFactType);
                }
                // Allow the user to drag out an existing role player from a
                // role on a shape that is not connected.
                else if (targetShapeElement == diagram &&
                         action.mySourceRoleMissingConnector)
                {
                    return(true);
                }
                return(false);
            }
Exemplo n.º 13
0
 public static DslModeling::LinkedElementCollection <global::Microsoft.VisualStudio.Modeling.ModelElement> GetExtensionCollection(ORMDiagram element)
 {
     return(new DslModeling::LinkedElementCollection <global::Microsoft.VisualStudio.Modeling.ModelElement>(element, ExtendedElementDomainRoleId));
 }
Exemplo n.º 14
0
 public static void SetExtendedElement(global::Microsoft.VisualStudio.Modeling.ModelElement element, ORMDiagram newExtendedElement)
 {
     DslModeling::DomainRoleInfo.SetLinkedElement(element, ExtensionDomainRoleId, newExtendedElement);
 }
Exemplo n.º 15
0
 /// <summary>
 /// Constructor
 /// Creates a ORMDiagramHasExtensionElement link in the same Partition as the given ORMDiagram
 /// </summary>
 /// <param name="source">ORMDiagram to use as the source of the relationship.</param>
 /// <param name="target">ModelElement to use as the target of the relationship.</param>
 public ORMDiagramHasExtensionElement(ORMDiagram source, global::Microsoft.VisualStudio.Modeling.ModelElement target)
     : base((source != null ? source.Partition : null), new DslModeling::RoleAssignment[] { new DslModeling::RoleAssignment(ORMDiagramHasExtensionElement.ExtendedElementDomainRoleId, source), new DslModeling::RoleAssignment(ORMDiagramHasExtensionElement.ExtensionDomainRoleId, target) }, null)
 {
 }
Exemplo n.º 16
0
		/// <summary>
		/// Default constructor.
		/// </summary>
		public LayoutManager(ORMDiagram diagram, LayoutEngine engine)
		{
			myDiagram = diagram;
			myLayoutEngine = engine;
		}
Exemplo n.º 17
0
 /// <summary>
 /// Removes the diagram.
 /// </summary>
 private void RemoveDiagram()
 {
     myDiagram = null;
     myDiagramView.Diagram = null;
 }
Exemplo n.º 18
0
 /// <summary>
 /// Default constructor.
 /// </summary>
 public LayoutManager(ORMDiagram diagram, LayoutEngine engine)
 {
     myDiagram      = diagram;
     myLayoutEngine = engine;
 }
Exemplo n.º 19
0
        /// <summary>
        /// Set shape visibility for the given fact type, fact type shape, and diagram
        /// </summary>
        private static void UpdateRoleNameDisplay(FactType factType, FactTypeShape factTypeShape, ORMDiagram diagram, bool immediateNotification)
        {
            DisplayRoleNames display       = factTypeShape.DisplayRoleNames;
            bool             asObjectType  = factTypeShape.DisplayAsObjectType;
            bool             shouldDisplay = !asObjectType && display == DisplayRoleNames.On || (display == DisplayRoleNames.UserDefault && OptionsPage.CurrentRoleNameDisplay == RoleNameDisplay.On);
            bool             shouldRemove  = asObjectType || display == DisplayRoleNames.Off;

            foreach (RoleBase roleBase in factType.RoleCollection)
            {
                Role role = roleBase as Role;
                if (role != null && !string.IsNullOrEmpty(role.Name))
                {
                    UpdateRoleNameDisplay(role, factType, factTypeShape, diagram, shouldDisplay, shouldRemove, immediateNotification);
                }
            }
        }
Exemplo n.º 20
0
        /// <summary>
        /// Set shape visibility for a role in the given fact type, fact type shape, and diagram
        /// </summary>
        private static void UpdateRoleNameDisplay(Role role, FactType factType, FactTypeShape factTypeShape, ORMDiagram diagram, bool shouldDisplay, bool shouldRemove, bool immediateNotification)
        {
            if (!shouldRemove && diagram != null)
            {
                diagram.FixUpLocalDiagram(factType, role);
            }
            LinkedElementCollection <ShapeElement> childShapes = factTypeShape.RelativeChildShapes;
            bool notifyUpdate = false;

            for (int i = childShapes.Count - 1; i >= 0; --i)
            {
                RoleNameShape roleNameShape;
                if (null != (roleNameShape = childShapes[i] as RoleNameShape))
                {
                    if (shouldRemove)
                    {
                        roleNameShape.Delete();
                    }
                    else
                    {
                        if (shouldDisplay)
                        {
                            if (!roleNameShape.IsVisible)
                            {
                                if (immediateNotification)
                                {
                                    roleNameShape.Show();
                                }
                                else
                                {
                                    notifyUpdate = true;
                                }
                            }
                        }
                        else if (roleNameShape.IsVisible)
                        {
                            if (immediateNotification)
                            {
                                roleNameShape.Hide();
                            }
                            else
                            {
                                notifyUpdate = true;
                            }
                            roleNameShape.Size = SizeD.Empty;
                        }
                    }
                }
            }
            if (notifyUpdate)
            {
                factTypeShape.OnRoleNameVisibilityChanged();
            }
        }
Exemplo n.º 21
0
		private void ContextMenuNewPageORMClick(object sender, EventArgs e)
		{
			Store store = base.DocData.Store;
			using (Transaction t = store.TransactionManager.BeginTransaction(ResourceStrings.DiagramCommandNewPage.Replace("&", "")))
			{
				ReadOnlyCollection<ORMModel> models = store.ElementDirectory.FindElements<ORMModel>();
				ORMDiagram diagram = new ORMDiagram(store);
				diagram.Associate(models.Count > 0 ? (ModelElement)models[0] : new ORMModel(store));
				t.Commit();
			}
		}