Example #1
0
        void PPSMtoPSM(P_PSMDiagram D)
        {
            NewModelClassCommand addPIMClass = NewModelClassCommandFactory.Factory().Create(DiagramController.ModelController) as NewModelClassCommand;

            addPIMClass.Package = DiagramController.Project.Schema.Model;
            addPIMClass.Execute();
            tempPIMClass = addPIMClass.CreatedClass.Element;

            X.p.Maximum    = X.ClassesCount;
            X.p.Value      = 0;
            X.p.Visibility = Visibility.Visible;
            X.l.Visibility = Visibility.Visible;
            if (!Layout)
            {
                TreeLayout.SwitchOff();
            }
            Stopwatch S = new Stopwatch();

            S.Start();
            if (UseCommands)
            {
                GeneratePSM(D);
            }
            else
            {
                DiagramController.getUndoStack().Invalidate();
                DiagramController.getRedoStack().Invalidate();
                GeneratePSM2(D);
            }
            S.Stop();
            X.t.Text += "Generated PSM in " + S.ElapsedMilliseconds.ToString() + "ms" + Environment.NewLine;

            S = new Stopwatch();
            S.Start();
            if (UseCommands)
            {
                LinkSRs(D);
            }
            else
            {
                LinkSRs2(D);
            }
            S.Stop();
            X.t.Text += "Linked SRs in " + S.ElapsedMilliseconds.ToString() + "ms" + Environment.NewLine;
            if (!Layout)
            {
                TreeLayout.SwitchOn();
            }

            //Only to refresh GUI, which normally happens after each command
            ActivateDiagramCommand A = ActivateDiagramCommandFactory.Factory().Create(DiagramController.ModelController) as ActivateDiagramCommand;

            A.Set(DiagramController.Diagram);
            A.Execute();
        }
Example #2
0
        public void BindToDiagram(Diagram diagram, ModelController modelController)
        {
            PropertyPath propertyPath = new PropertyPath("Caption");
            Binding      titleBinding = new Binding {
                Source = diagram, Path = propertyPath
            };

            SetBinding(TitleProperty, titleBinding);

            // bound view to controller and controller to model
            DiagramController = new DiagramController(diagram, modelController);
            ModelController   = modelController;

            xCaseDrawComponent.Canvas.Controller = DiagramController;
            try
            {
                Mouse.SetCursor(Cursors.Wait);

                #region load items on the diagram

                List <Element>  alreadyProcessed = new List <Element>();
                RegistrationSet registrationSet;
                if (diagram is PIMDiagram)
                {
                    registrationSet = MainWindow.PIMRepresentantsSet;
                    /* Elements in PIM diagram are loaded in the order of their LoadPriority in registration set */
                    foreach (RepresentantRegistration registration in registrationSet.OrderBy(reg => reg.LoadPriority))
                    {
                        foreach (KeyValuePair <Element, ViewHelper> pair in diagram.DiagramElements)
                        {
                            if (!alreadyProcessed.Contains(pair.Key) &&
                                registration.ModelElementType.IsInstanceOfType(pair.Key))
                            {
                                diagram.NotifyElementAdded(this, pair.Key, pair.Value);
                                alreadyProcessed.Add(pair.Key);
                            }
                        }
                    }
                }
                else
                {
                    /* order of the elements in PSM diagram is more complex, an ordering function
                     * is called to order the elements (basically BFS)
                     */
                    TreeLayout.SwitchOff();
                    IList <Element> ordered;
                    if (PSMTree.ReturnElementsInPSMOrder(((PSMDiagram)diagram).Roots, out ordered, true))
                    {
                        foreach (Element element in ordered)
                        {
                            diagram.NotifyElementAdded(this, element, diagram.DiagramElements[element]);
                        }
                        foreach (Comment comment in diagram.DiagramElements.Keys.OfType <Comment>())
                        {
                            diagram.NotifyElementAdded(this, comment, diagram.DiagramElements[comment]);
                        }
                        foreach (PSMDiagramReference psmDiagramReference in diagram.DiagramElements.Keys.OfType <PSMDiagramReference>())
                        {
                            diagram.NotifyElementAdded(this, psmDiagramReference, diagram.DiagramElements[psmDiagramReference]);
                        }
                    }
                    xCaseDrawComponent.Canvas.Loaded += Canvas_Loaded;
                }

                #endregion
            }
            finally
            {
                Mouse.SetCursor(Cursors.Arrow);
            }
        }