Beispiel #1
0
        protected override void TranslateContentChoice(PSMContentChoice contentChoice, DataGeneratorContext context)
        {
            TranslateComments(contentChoice, context);
            PSMSubordinateComponent selectedPath = contentChoice.Components.ChooseOneRandomly();

            TranslateSubordinateComponent(selectedPath, context);
        }
        public void MoveToContentChoice(PSMContentChoice contentChoice)
        {
            MoveSubordinateToSuperordinateMacroCommand <PSMContentChoice> c = (MoveSubordinateToSuperordinateMacroCommand <PSMContentChoice>) MoveSubordinateToSuperordinateMacroCommandFactory <PSMContentChoice> .Factory().Create(DiagramController);

            c.InitializeCommand(new[] { PSMAssociation }, contentChoice);
            if (c.Commands.Count > 0)
            {
                c.Execute();
            }
        }
Beispiel #3
0
        protected override void TranslateContentChoice(PSMContentChoice contentChoice, ChangesDetectorContext context)
        {
            context.ScopeStack.Push(EChangeScope.ContentChoice);
            context.CurrentPSMElement = contentChoice;

            ChangesLookupManager.DetectLocalChanges(context);
            TranslateComponents(contentChoice, context);

            EChangeScope pop = context.ScopeStack.Pop();

            Debug.Assert(pop == EChangeScope.ContentChoice);
        }
Beispiel #4
0
        private void ConvertPSMContentChoice(PSMContentChoice psmContentChoice, PSMElementViewHelper psmElementViewHelper)
        {
            PSMContentModel contentModel;

            if (!TranslatedAlready(psmContentChoice, out contentModel))
            {
                contentModel = new PSMContentModel(evoxProject, psmSchema, false);
                translatedElements[psmContentChoice] = contentModel;
            }

            contentModel.Type = PSMContentModelType.Choice;
        }
Beispiel #5
0
        public override void FillCopy(Element copyElement, Model targetModel, ElementCopiesMap createdCopies)
        {
            base.FillCopy(copyElement, targetModel, createdCopies);
            PSMContentChoice copyPSMContentChoice = (PSMContentChoice)copyElement;

            if (Parent != null && createdCopies.ContainsKey(Parent))
            {
                PSMSuperordinateComponent copyParent = (PSMSuperordinateComponent)createdCopies[Parent];
                ((_ImplPSMSubordinateComponent)copyPSMContentChoice).Parent = (PSMSuperordinateComponent)createdCopies[Parent];
                copyParent.Components.Add(copyPSMContentChoice);
            }
        }
Beispiel #6
0
 public PSM_ContentChoiceController(PSMContentChoice contentChoice, DiagramController diagramController) :
     base(contentChoice, diagramController)
 {
 }
Beispiel #7
0
 /// <summary>
 /// Translates the content choice.
 /// </summary>
 /// <param name="contentChoice">The content choice.</param>
 /// <param name="context">The translation context.</param>
 protected virtual void TranslateContentChoice(PSMContentChoice contentChoice, Context context)
 {
 }
Beispiel #8
0
        /// <summary>
        /// Adds attributes under a node into <param name="attributeList"/> (when called for a superordinate component, attributes
        /// from all subordinate PSM classes without element labels are included in the result too)
        /// </summary>
        /// <param name="node">node where to search for attributes</param>
        /// <param name="firstCall">false value indicates recursive call</param>
        /// <param name="attributeList">list in which attributes are added</param>
        private static void GetAttributesUnderNode(PSMElement node, bool firstCall, ref List <NodeAttributeWrapper> attributeList)
        {
            if (!firstCall && node is PSMClass &&
                !((PSMClass)node).HasElementLabel &&
                ((PSMClass)node).IsStructuralRepresentative)
            {
                PSMClass representedClass = ((PSMClass)node).RepresentedPSMClass;
                attributeList.Add(new StructuralRepresentativeAttributes((PSMClass)node, representedClass));
            }

            {
                PSMClass psmClass = node as PSMClass;
                if (psmClass != null)
                {
                    if (firstCall || (!psmClass.HasElementLabel))
                    {
                        foreach (PSMAttribute psmAttribute in psmClass.PSMAttributes)
                        {
                            attributeList.Add(new SimpleNodeAttribute(psmAttribute));
                        }
                    }
                    else
                    {
                        return;
                    }
                }
            }

            if (node is PSMClass || (node is PSMContentContainer && firstCall))
            {
                foreach (PSMSubordinateComponent component in ((PSMSuperordinateComponent)node).Components)
                {
                    GetAttributesUnderNode(component, false, ref attributeList);
                }
            }

            if (node is PSMClassUnion)
            {
                //throw new NotImplementedException("Can't handle unions yet");
            }

            if (node is PSMContentChoice)
            {
                PSMContentChoice             contentChoice = (PSMContentChoice)node;
                PSMTreeIterator              it            = new PSMTreeIterator(contentChoice);
                List <ChoiceAttributeOption> options       = new List <ChoiceAttributeOption>();
                foreach (PSMElement childNode in it.GetChildNodes())
                {
                    List <NodeAttributeWrapper> choices = new List <NodeAttributeWrapper>();
                    GetAttributesUnderNode(childNode, false, ref choices);
                    if (choices.Count > 0)
                    {
                        ChoiceAttributeOption option = new ChoiceAttributeOption();
                        option.Items = choices;
                        options.Add(option);
                    }
                }
                if (options.Count > 0)
                {
                    ChoiceAttributes choiceAttributes = new ChoiceAttributes(contentChoice, options);
                    attributeList.Add(choiceAttributes);
                }
            }

            else if (node is PSMClassUnion)
            {
                PSMClassUnion   classUnion           = (PSMClassUnion)node;
                PSMTreeIterator it                   = new PSMTreeIterator(classUnion);
                List <ChoiceAttributeOption> options = new List <ChoiceAttributeOption>();
                foreach (PSMElement childNode in it.GetChildNodes())
                {
                    List <NodeAttributeWrapper> choices = new List <NodeAttributeWrapper>();
                    GetAttributesUnderNode(childNode, false, ref choices);
                    if (choices.Count > 0)
                    {
                        ChoiceAttributeOption option = new ChoiceAttributeOption();
                        option.Items = choices;
                        options.Add(option);
                    }
                }
                if (options.Count > 0)
                {
                    UnionAttributes choiceAttributes = new UnionAttributes(classUnion, options);
                    attributeList.Add(choiceAttributes);
                }
            }

            if (node is PSMAssociation)
            {
                GetAttributesUnderNode(((PSMAssociation)node).Child, false, ref attributeList);
            }
            return;
        }
Beispiel #9
0
        public static List <NodeElementWrapper> FindElementChoices(this PSMContentChoice choice)
        {
            List <NodeElementWrapper> choices = choice.GetSubtreeElements();

            return(choices);
        }
Beispiel #10
0
        public static void CheckDiagram(PSMDiagram diagram, out List <string> errors, out List <string> warnings)
        {
            errors   = new List <string>();
            warnings = new List <string>();

            #region diagram has roots

            if (diagram.Roots.Count == 0)
            {
                errors.Add(string.Format("Diagram has no roots. "));
            }

            #endregion

            #region diagram has global element

            if (diagram.Roots.Where(r => (r is PSMClass) && ((PSMClass)r).HasElementLabel).Count() == 0)
            {
                bool found = false;
                foreach (PSMSuperordinateComponent superordinate in diagram.Roots)
                {
                    if (superordinate is PSMContentContainer)
                    {
                        found = true;
                        break;
                    }
                    else
                    {
                        PSMClass c = superordinate as PSMClass;
                        if (c != null)
                        {
                            if (GetSpecificiationsRecursive(c).Any(s => s.HasElementLabel))
                            {
                                found = true;
                            }
                        }
                    }
                }

                if (!found)
                {
                    warnings.Add(string.Format("Diagram has no root with an element label, no global element is declared. "));
                }
            }

            #endregion

            #region not zero or only one component in choice

            foreach (Element element in diagram.DiagramElements.Keys)
            {
                {
                    PSMContentChoice cc = element as PSMContentChoice;
                    if (cc != null && cc.Components.Count == 1)
                    {
                        warnings.Add(string.Format("Only one component in {0}. ", cc));
                    }
                    if (cc != null && cc.Components.Count == 0)
                    {
                        warnings.Add(string.Format("Zero components in {0}. ", cc));
                    }
                }

                {
                    PSMClassUnion cu = element as PSMClassUnion;
                    if (cu != null && cu.Components.Count == 1)
                    {
                        warnings.Add(string.Format("Only one component in {0}. ", cu));
                    }
                    if (cu != null && cu.Components.Count == 0)
                    {
                        warnings.Add(string.Format("Zero components in {0}. ", cu));
                    }
                }
            }

            #endregion
        }
Beispiel #11
0
        void GeneratePSM2(I_PSMHasChildren current)
        {
            foreach (I_PSMHasParent child in current.Children)
            {
                if (child is P_PSMClass)
                {
                    //UPDATE GUI: This is wrong, but better than crash due to detected deadlock:
                    X.l.Content = (++currentClassCount).ToString() + "/" + X.ClassesCount.ToString() + " PSM Classes";
                    X.p.Value   = currentClassCount;
                    if (currentClassCount % (Math.Min(25, X.ClassesCount / 10) + 1) == 0)
                    {
                        Application.Current.Dispatcher.Invoke(DispatcherPriority.Background, new ThreadStart(delegate { }));
                    }

                    P_PSMClass C        = child as P_PSMClass;
                    PSMClass   psmClass = tempPIMClass.DerivePSMClass();
                    C.Super              = psmClass;
                    psmClass.Name        = C.Name.Name;
                    psmClass.ElementName = C.ElementLabel;

                    ViewHelper v = new PSMElementViewHelper(DiagramController.Diagram)
                    {
                        X = 0, Y = 0, Height = double.NaN, Width = double.NaN
                    };
                    DiagramController.Diagram.AddModelElement(psmClass, v);
                    psmClass.Diagram = DiagramController.Diagram as PSMDiagram;

                    //Attributes
                    foreach (P_PSMAttribute A in C.Attributes)
                    {
                        Property At = (C.Super as PSMClass).AddAttribute();
                        At.Name  = A.Alias;
                        At.Lower = A.Lower;

                        /*if (Type != null && Type.Element != null)
                         *  createdAttribute.Type = Type.Element;*/
                        At.Upper   = A.Upper;
                        At.Default = A.DefaultValue;
                        (At as PSMAttribute).Alias = A.Alias;
                    }

                    if (current is P_PSMDiagram)
                    {
                        (DiagramController.Diagram as PSMDiagram).Roots.Add(psmClass);
                    }
                    else
                    {
                        if (C.ExtensionOf != null)
                        {
                            Generalization generalization = DiagramController.ModelController.Model.Schema.SetGeneralization((current as P_PSMClass).Super as PSMClass, C.Super as PSMClass);

                            DiagramController.Diagram.AddModelElement(generalization, new GeneralizationViewHelper(DiagramController.Diagram));
                        }
                        else
                        {
                            PSMAssociation PSMAssoc = (PSMAssociation)(current as P_PSMBase).Super.AddComponent(PSMAssociationFactory.Instance);
                            PSMAssoc.Child = psmClass;
                            PSMAssoc.Upper = C.MaxOccurs;
                            PSMAssoc.Lower = C.MinOccurs;

                            DiagramController.Diagram.AddModelElement(PSMAssoc, new PSMAssociationViewHelper(DiagramController.Diagram));
                            PSMAssoc.Diagram = DiagramController.Diagram as PSMDiagram;
                        }
                    }
                    GeneratePSM2(C);
                }
                else if (!(current is P_PSMDiagram) && child is P_PSMContentChoice)
                {
                    PSMContentChoice psmChoice = (PSMContentChoice)(current as P_PSMBase).Super.AddComponent(PSMContentChoiceFactory.Instance);
                    DiagramController.Diagram.AddModelElement(psmChoice, new PSMElementViewHelper(DiagramController.Diagram));
                    (child as P_PSMContentChoice).Super = psmChoice;

                    GeneratePSM2(child as P_PSMContentChoice);
                }
                else if (!(current is P_PSMDiagram) && child is P_PSMAttributeContainer)
                {
                    PSMClass owner = null;
                    PSMSuperordinateComponent PSMSuper = null;
                    PSMAttributeContainer     psmAttributeContainer = null;
                    if (current is P_PSMClass)
                    {
                        owner = (current as P_PSMClass).Super as PSMClass;
                    }
                    else if (current is P_PSMContentChoice)
                    {
                        PSMSuper = (current as P_PSMContentChoice).Super as PSMSuperordinateComponent;
                        owner    = (current as P_PSMContentChoice).P_PSMClass.Super as PSMClass;
                    }
                    else if (current is P_PSMContentContainer)
                    {
                        PSMSuper = (current as P_PSMContentContainer).Super as PSMSuperordinateComponent;
                        owner    = (current as P_PSMContentContainer).P_PSMClass.Super as PSMClass;
                    }
                    List <PSMAttribute> PSMAttributes = new List <PSMAttribute>();
                    foreach (P_PSMAttribute A in (child as P_PSMAttributeContainer).Attributes)
                    {
                        Property At = owner.AddAttribute();
                        At.Name  = A.Alias;
                        At.Lower = A.Lower;

                        /*if (Type != null && Type.Element != null)
                         *  createdAttribute.Type = Type.Element;*/
                        At.Upper   = A.Upper;
                        At.Default = A.DefaultValue;
                        (At as PSMAttribute).Alias = A.Alias;
                        PSMAttributes.Add(At as PSMAttribute);
                        owner.PSMAttributes.Remove(At as PSMAttribute);
                    }

                    if (PSMSuper != null)
                    {
                        psmAttributeContainer = (PSMAttributeContainer)PSMSuper.AddComponent(PSMAttributeContainerFactory.Instance);
                    }
                    else
                    {
                        psmAttributeContainer = (PSMAttributeContainer)owner.AddComponent(PSMAttributeContainerFactory.Instance);
                    }
                    foreach (PSMAttribute attribute in PSMAttributes)
                    {
                        psmAttributeContainer.PSMAttributes.Add(attribute);
                    }
                    DiagramController.Diagram.AddModelElement(psmAttributeContainer, new PSMElementViewHelper(DiagramController.Diagram));
                }
                else if ((current is P_PSMClass) && child is P_PSMComment)
                {
                    Comment C = (current as P_PSMClass).Super.AddComment(NameSuggestor <Comment> .SuggestUniqueName((current as P_PSMClass).Super.Comments, "Comment", comment => comment.Body));
                    C.Body = (child as P_PSMComment).text;
                    DiagramController.Diagram.AddModelElement(C, new CommentViewHelper(DiagramController.Diagram));
                }
                else if (!(current is P_PSMDiagram) && child is P_PSMContentContainer)
                {
                    P_PSMContentContainer CC = child as P_PSMContentContainer;

                    PSMContentContainer psmContainer = (PSMContentContainer)(current as P_PSMBase).Super.AddComponent(PSMContentContainerFactory.Instance);
                    psmContainer.Name = CC.ElementLabel;
                    CC.Super          = psmContainer;
                    DiagramController.Diagram.AddModelElement(psmContainer, new PSMElementViewHelper(DiagramController.Diagram));

                    GeneratePSM2(CC);
                }
            }
        }