コード例 #1
0
        /// <summary>
        /// Sets this command for use.
        /// </summary>
        /// <param name="parent">Reference to the PSM component that is the root of joined associations</param>
        /// <param name="joinedAssociations">List of associations to be joined to one class union</param>
        public void Set(PSMSuperordinateComponent parent, IEnumerable <PSMAssociation> joinedAssociations)
        {
            JoinedAssociations = new List <PSMAssociation>(joinedAssociations);

            PSMSubordinateComponent first = parent.Components.First(assoc => JoinedAssociations.Contains(assoc as PSMAssociation));
            int?index = parent.Components.IndexOf(first);


            if (ParentHolder == null)
            {
                ParentHolder = new Helpers.ElementHolder <PSMSuperordinateComponent>();
            }
            ParentHolder.Element = parent;

            if (CreatedUnion == null)
            {
                CreatedUnion = new Helpers.ElementHolder <PSMClassUnion>();
            }

            if (CreatedAssocChild == null)
            {
                CreatedAssocChild = new Helpers.ElementHolder <PSMAssociationChild>();
            }

            if (CreatedAssociationHolder == null)
            {
                CreatedAssociationHolder = new Helpers.ElementHolder <PSMAssociation>();
            }

            NewPSMClassUnionCommand c1 = NewPSMClassUnionCommandFactory.Factory().Create(Controller) as NewPSMClassUnionCommand;

            c1.CreatedUnion = CreatedUnion;
            c1.Parent       = parent;
            Commands.Add(c1);

            Helpers.HolderConvertorCommand <PSMClassUnion, PSMAssociationChild> cc =
                new Commands.Helpers.HolderConvertorCommand <PSMClassUnion, PSMAssociationChild>(CreatedUnion,
                                                                                                 CreatedAssocChild);
            Commands.Add(cc);

            NewPSMAssociationCommand newAssocCommand = NewPSMAssociationCommandFactory.Factory().Create(Controller.ModelController) as NewPSMAssociationCommand;

            newAssocCommand.Set(ParentHolder, CreatedAssocChild, CreatedAssociationHolder, index);
            Commands.Add(newAssocCommand);

            CopyNestingJoinsCommand copyNJcommand = CopyNestingJoinsCommandFactory.Factory().Create(Controller.ModelController) as CopyNestingJoinsCommand;

            copyNJcommand.Set(CreatedAssociationHolder, JoinedAssociations);
            Commands.Add(copyNJcommand);

            /*GetClassUnionContentCommand c4 = GetClassUnionContentCommandFactory.Factory().Create(Controller.ModelController) as GetClassUnionContentCommand;
             * c4.Set(joinedAssociations, CreatedUnion);
             * Commands.Add(c4);*/

            PutClassesToUnionCommand putCommand = PutClassesToUnionCommandFactory.Factory().Create(Controller.ModelController) as PutClassesToUnionCommand;

            putCommand.Set(joinedAssociations, CreatedUnion);
            Commands.Add(putCommand);

            DeleteFromPSMDiagramCommand delCommand = DeleteFromPSMDiagramCommandFactory.Factory().Create(Controller) as DeleteFromPSMDiagramCommand;

            delCommand.DeletedElements = new List <Element>(JoinedAssociations.Cast <Element>());
            delCommand.CheckOrdering   = false;
            Commands.Add(delCommand);

            foreach (PSMAssociation assoc in joinedAssociations)
            {
                PSMClassUnion union = assoc.Child as PSMClassUnion;
                if (union != null)
                {
                    MoveClassUnionContentCommand moveCommand = MoveClassUnionContentCommandFactory.Factory().Create(Controller) as MoveClassUnionContentCommand;
                    moveCommand.Set(union, CreatedUnion);
                    Commands.Add(moveCommand);
                    DeleteFromPSMDiagramCommand delUnion = DeleteFromPSMDiagramCommandFactory.Factory().Create(Controller) as DeleteFromPSMDiagramCommand;
                    delUnion.DeletedElements = new List <Element>();
                    delUnion.DeletedElements.Add(union);
                    Commands.Add(delUnion);
                }
            }

            ElementToDiagramCommand <PSMAssociation, PSMAssociationViewHelper> includeAssociation = (ElementToDiagramCommand <PSMAssociation, PSMAssociationViewHelper>) ElementToDiagramCommandFactory <PSMAssociation, PSMAssociationViewHelper> .Factory().Create(Controller);

            includeAssociation.IncludedElement = CreatedAssociationHolder;
            Commands.Add(includeAssociation);
        }
コード例 #2
0
ファイル: GroupByCommand.cs プロジェクト: mff-uk/xcase
        internal override void CommandOperation()
        {
            // The context of each new association includes the entire context of the previous
            // created association + Parent path of the nesting join of the previous association
            // Therefore we progressively cumulate it in this collection.
            List <PIMPath> context = new List <PIMPath>();

            for (int i = 0; i < Associations.Count; ++i)
            {
                // Get a reference to Ai and Ai+1 if defined.
                PSMAssociation association     = Associations[i];
                PSMAssociation nextAssociation = null;
                if (i < Associations.Count - 1)
                {
                    nextAssociation = Associations[i + 1];
                }

                // Remove Ai from the model
                DeleteFromPSMDiagramCommand cmdDel = DeleteFromPSMDiagramCommandFactory.Factory().Create(Controller) as DeleteFromPSMDiagramCommand;
                cmdDel.DeletedElements = new List <Element>();
                cmdDel.DeletedElements.Add(association);
                cmdDel.CommandOperation();
                deletedAssociations.Add(cmdDel);

                // Create a new PSM association A'i
                NewPSMAssociationCommand cmdNew = NewPSMAssociationCommandFactory.Factory().Create(
                    Controller.ModelController) as NewPSMAssociationCommand;
                PSMAssociationChild child = (nextAssociation == null ? GroupedClass : nextAssociation.Child);
                cmdNew.Set((PSMClass)association.Child, child, null, null);
                cmdNew.CommandOperation();
                PSMAssociation newAssociation = cmdNew.CreatedAssociation.Element;
                createdAssociations.Add(cmdNew);

                // Create a nesting join for the new association A'i, all the nesting joins
                // of the associations A1..n will have the GroupedClass as their CoreClass.
                NestingJoin nj = newAssociation.AddNestingJoin(GroupedClass.RepresentedClass);

                // Copy the parent path of the nesting join of Ai to the parent
                // path of A'i and reverse it.
                IEnumerable <PIMStep> revPath = association.NestingJoins[0].Parent.Steps.Reverse();
                foreach (PIMStep step in revPath)
                {
                    nj.Parent.AddStep(step.End, step.Start, step.Association);
                }


                // If Ai+1 is defined then copy its Parent path to the Child path of A'i
                // and reverse it. Set the A'i ending to the child of Ai+1.
                // Thus, the A'i association will look as follows
                //  - A'i: Ai.Child -> Ai+1.Child
                //  - Nesting join: GroupedClass[Ai.ParentPath(reversed) -> Ai+1.ParentPath(reversed)]
                //
                // If Ai+1 is not defined, A'i will end at the GroupedClass and will look as follows
                //  - A'i: Ai.Child -> GroupedClass
                //  - Nesting join: GroupedClass[Ai.ParentPath(reversed) -> .]
                if (nextAssociation != null)
                {
                    revPath = nextAssociation.NestingJoins[0].Parent.Steps.Reverse();
                    foreach (PIMStep step in revPath)
                    {
                        nj.Child.AddStep(step.End, step.Start, step.Association);
                    }
                }

                // Set the context of A'i as a collection of all the parent paths of A'1 .. A'i-1
                foreach (PIMPath path in context)
                {
                    PIMPath newPath = nj.AddContextPath();
                    foreach (PIMStep step in path.Steps)
                    {
                        newPath.AddStep(step.Start, step.End, step.Association);
                    }
                }

                // Add the parent path of A'i to the temporal collection to enable it for A'i+1
                context.Add(nj.Parent);

                // Put A'i on the diagram
                ElementToDiagramCommand <PSMAssociation, PSMAssociationViewHelper> cmdToDiag =
                    ElementToDiagramCommandFactory <PSMAssociation, PSMAssociationViewHelper> .Factory().Create(Controller)
                    as ElementToDiagramCommand <PSMAssociation, PSMAssociationViewHelper>;

                cmdToDiag.IncludedElement = new Helpers.ElementHolder <PSMAssociation>(newAssociation);
                cmdToDiag.CommandOperation();
                visualizedAssociations.Add(cmdToDiag);
            }

            // If the grouped class was previously a root of the PSM diagram
            // replace it with the topmost grouping class.
            rootIndex = GroupedClass.Diagram.Roots.IndexOf(GroupedClass);
            if (rootIndex != -1)
            {
                newRoot = Associations[0].Child as PSMClass;
                GroupedClass.Diagram.Roots[rootIndex] = newRoot;
            }
        }
コード例 #3
0
        /// <summary>
        /// Processes one selected TreeView item. Generates commands for addition of PSMClasses, PSMStructuralRepresentatives and PSMAssociations
        /// </summary>
        /// <param name="T">The item to be processed</param>
        private void GenerateCommands(TreeClasses T)
        {
            #region Holders
            ElementHolder <PSMClass>            Child             = new ElementHolder <PSMClass>();
            ElementHolder <PSMAssociationChild> ChildAssociation  = new ElementHolder <PSMAssociationChild>();
            ElementHolder <PSMAssociation>      AssociationHolder = new ElementHolder <PSMAssociation>();
            #endregion

            #region Create new element

            if (T.RootClass == null)
            {
                NewPSMClassCommand c1 = NewPSMClassCommandFactory.Factory().Create(Controller.ModelController) as NewPSMClassCommand;
                c1.RepresentedClass = T.PIMClass;
                c1.CreatedClass     = Child;
                Commands.Add(c1);

                if (T.Represented != null) //Creating PSM Structural Representative
                {
                    SetRepresentedPSMClassCommand c1a = SetRepresentedPSMClassCommandFactory.Factory().Create(Controller) as SetRepresentedPSMClassCommand;
                    c1a.Set(T.Represented, Child);
                    Commands.Add(c1a);
                }

                //Put the newly created PSMClass to the diagram
                ElementToDiagramCommand <PSMClass, PSMElementViewHelper> c2 = ElementToDiagramCommandFactory <PSMClass, PSMElementViewHelper> .Factory().Create(Controller) as ElementToDiagramCommand <PSMClass, PSMElementViewHelper>;

                c2.IncludedElement = Child;
                Commands.Add(c2);
            }
            else //Connecting existing root
            {
                Child.Element = T.RootClass;
                RemovePSMClassFromRootsCommand c = RemovePSMClassFromRootsCommandFactory.Factory().Create(Controller) as RemovePSMClassFromRootsCommand;
                c.Set(Child);
                Commands.Add(c);
            }

            #endregion

            #region PSM Association

            #region Path generation
            //Prepare path for NestingJoin - Path from child to parent consisting of AssociationEnds (PIMSteps)
            List <NestingJoinStep> Path = new List <NestingJoinStep>();
            uint?Lower = 1;
            NUml.Uml2.UnlimitedNatural Upper = 1;
            TreeClasses t = T;
            while (t.ParentTC != null)
            {
                Path.Add(new NestingJoinStep()
                {
                    Association = t.Association, End = t.PIMClass, Start = t.ParentTC.PIMClass
                });
                Lower *= t.Lower;
                if (t.Upper.IsInfinity)
                {
                    Upper = NUml.Uml2.UnlimitedNatural.Infinity;
                }
                else if (!Upper.IsInfinity)
                {
                    Upper = Upper.Value * t.Upper.Value;
                }
                t = t.ParentTC;
            }

            #endregion

            //Add PSMAssociation connecting the parent to the PSMClass
            Commands.Add(new HolderConvertorCommand <PSMClass, PSMAssociationChild>(Child, ChildAssociation));
            NewPSMAssociationCommand c3 = NewPSMAssociationCommandFactory.Factory().Create(Controller.ModelController) as NewPSMAssociationCommand;
            c3.Set(new ElementHolder <PSMSuperordinateComponent>()
            {
                Element = SourcePSMClass
            }, ChildAssociation, AssociationHolder, null);

            //Set PSM association multiplicity
            c3.Upper = Upper;
            c3.Lower = Lower;
            c3.UsedGeneralizations = T.UsedGeneralizations;
            Commands.Add(c3);
            #endregion

            #region Nesting join
            //Set the nestingjoin
            AddSimpleNestingJoinCommand c4 = AddSimpleNestingJoinCommandFactory.Factory().Create(Controller.ModelController) as AddSimpleNestingJoinCommand;
            c4.Set(AssociationHolder, Path);
            Commands.Add(c4);
            #endregion

            #region Association to diagram
            //Add created PSMAssociations to the diagram
            ElementToDiagramCommand <PSMAssociation, PSMAssociationViewHelper> c5 = (ElementToDiagramCommand <PSMAssociation, PSMAssociationViewHelper>) ElementToDiagramCommandFactory <PSMAssociation, PSMAssociationViewHelper> .Factory().Create(Controller);

            c5.IncludedElement = AssociationHolder;
            Commands.Add(c5);
            #endregion
        }