internal override void CommandOperation()
 {
     CreatedNestingJoin = Association.Element.AddNestingJoin((Association.Element.Child as PSMClass).RepresentedClass);
     for (int i = 0; i < ParentPath.Count; i++)
     {
         CreatedNestingJoin.Parent.AddStep(ParentPath[i].End, ParentPath[i].Start, ParentPath[i].Association);
     }
     AssociatedElements.Add(Association.Element);
 }
Exemple #2
0
        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;
            }
        }