Esempio n. 1
0
        public void AddNewAttribute(string attributeName, string newSimpleDataType, uint?lower, UnlimitedNatural?upper, string @default)
        {
            MacroCommand <ModelController> command = MacroCommandFactory <ModelController> .Factory().Create(DiagramController.ModelController);

            AddSimpleTypeCommand     simpleTypeCommand = (AddSimpleTypeCommand)AddSimpleTypeCommandFactory.Factory().Create(DiagramController.ModelController);
            ElementHolder <DataType> type = new ElementHolder <DataType>();

            simpleTypeCommand.CreatedSimpleType = type;
            command.Commands.Add(simpleTypeCommand);
            NewAttributeCommand attributeCommand = (NewAttributeCommand)NewAttributeCommandFactory.Factory().Create(DiagramController.ModelController);

            if (!String.IsNullOrEmpty(attributeName))
            {
                attributeCommand.Name = attributeName;
            }
            else
            {
                attributeCommand.Name = NameSuggestor <Property> .SuggestUniqueName(Class.Attributes, "Attribute", property => property.Name);
            }
            attributeCommand.Type    = type;
            attributeCommand.Lower   = lower;
            attributeCommand.Upper   = upper;
            attributeCommand.Default = @default;
            attributeCommand.Owner   = Class;
            command.Commands.Add(attributeCommand);
            command.Execute();
        }
        public void Set(PSMAttribute attribute)
        {
            //Only PIMLess attributes
            if (attribute.RepresentedAttribute != null)
            {
                return;
            }

            ElementHolder <Property> AttributeHolder = new ElementHolder <Property>();
            NewAttributeCommand      c1 = NewAttributeCommandFactory.Factory().Create(Controller) as NewAttributeCommand;

            c1.createdAttributeHolder = AttributeHolder;
            c1.Owner   = attribute.Class.RepresentedClass;
            c1.Lower   = attribute.Lower;
            c1.Upper   = attribute.Upper;
            c1.Default = attribute.Default;
            c1.Name    = NameSuggestor <Property> .SuggestUniqueName(attribute.Class.RepresentedClass.Attributes, attribute.Name ?? attribute.Alias, property => property.Name);

            c1.Type = new ElementHolder <DataType>(attribute.Type);
            Commands.Add(c1);

            RenameElementCommand <Property> c2 = RenameElementCommandFactory <Property> .Factory().Create(Controller) as RenameElementCommand <Property>;

            c2.ContainingCollection = attribute.Class.Attributes;
            c2.RenamedElement       = attribute;
            c2.NewName = c1.Name;
            Commands.Add(c2);

            PropagatePIMLessCommand c3 = PropagatePIMLessCommandFactory.Factory().Create(Controller) as PropagatePIMLessCommand;

            c3.Set(new ElementHolder <PSMAttribute>(attribute), AttributeHolder);
            Commands.Add(c3);
        }
Esempio n. 3
0
 internal override void CommandOperation()
 {
     if (Diagram == null)
     {
         Diagram = new PIMDiagram(NameSuggestor <PIMDiagram> .SuggestUniqueName(Project.PIMDiagrams, "PIM Diagram", diagram => diagram.Caption));
     }
     Project.AddDiagram(Diagram);
 }
Esempio n. 4
0
        protected override DragButtonData PrepareButtonData()
        {
            className = NameSuggestor <PIMClass> .SuggestUniqueName(ActiveDiagramView.Controller.ModelController.Model.Classes, "Class", modelClass => modelClass.Name);

            return(new DragButtonData(NewModelClassToDiagramCommandFactory.Factory(), new PIM_Class(ActiveDiagramView)
            {
                ElementName = className
            }));
        }
Esempio n. 5
0
        public string GetName(Classifier varType)
        {
            string nameBase = varType.Name.ToLower()[0].ToString();

            string result = NameSuggestor <string> .SuggestUniqueName(UsedNames, nameBase, item => item, true, false);

            UsedNames.Add(result);
            return(result);
        }
Esempio n. 6
0
        protected override DragButtonData PrepareButtonData()
        {
            text = NameSuggestor <Comment> .SuggestUniqueName(ActiveDiagramView.Controller.ModelController.Model.Comments,
                                                              "Comment", comment => comment.Body);

            return(new DragButtonData(NewModelCommentaryToDiagramCommandFactory.Factory(),
                                      new XCaseComment(ActiveDiagramView)
            {
                CommentText = text
            }));
        }
Esempio n. 7
0
        public void AddNewAttribute()
        {
            NewAttributeCommand c = NewAttributeCommandFactory.Factory().Create(DiagramController.ModelController) as NewAttributeCommand;

            c.Owner = AttributeHolder as IHasAttributes;
            c.Name  = NameSuggestor <Property> .SuggestUniqueName(((IHasAttributes)AttributeHolder).Attributes, "Attribute", property => property.Name);

            if (c.CanExecute())
            {
                c.Execute();
            }
        }
Esempio n. 8
0
        private void OnAddAttributeClick(object sender, RoutedEventArgs e)
        {
            MenuItem m = sender as MenuItem;

            if (m.DataContext is Class)
            {
                NewAttributeCommand newAttributeCommand = (NewAttributeCommand)NewAttributeCommandFactory.Factory().Create(project.GetModelController());
                newAttributeCommand.Owner = m.DataContext as Class;
                newAttributeCommand.Name  = NameSuggestor <Property> .SuggestUniqueName((newAttributeCommand.Owner as IHasAttributes).Attributes, "Attribute", property => property.Name);

                newAttributeCommand.Execute();
            }
        }
Esempio n. 9
0
        /// <summary>
        /// Gets a unique name for global element. Adds record to <see cref="usedRootLabels"/>.
        /// The name is based upon <paramref name="psmClass"/>' <see cref="PSMClass.ElementName"/>.
        /// </summary>
        /// <param name="psmClass">The class for which the name is returned.</param>
        /// <returns>unique global element name</returns>
        public string GetNameForGlobalElement(PSMClass psmClass)
        {
            string normalized  = NormalizeTypeName(psmClass, r => r.ElementName);
            string elementName =
                NameSuggestor <string> .SuggestUniqueName(usedRootLabels, normalized, item => item, true, false);

            if (elementName != normalized)
            {
                Log.AddWarning(string.Format(LogMessages.XS_DUPLICATE_ROOT_ELEMENTS, psmClass.ElementName, elementName));
            }
            usedRootLabels.Add(elementName);
            return(elementName);
        }
Esempio n. 10
0
        internal override void CommandOperation()
        {
            if (CreatedComment == null)
            {
                CreatedComment = new ElementHolder <Comment>();
            }
            CreatedComment.Element = AnnotatedElement.AddComment(NameSuggestor <Comment> .SuggestUniqueName(AnnotatedElement.Comments, "Comment", comment => comment.Body));;

            CreatedComment.Element.Body = Text;

            Debug.Assert(CreatedComment.HasValue);
            AssociatedElements.Add(CreatedComment.Element);
        }
Esempio n. 11
0
        public void AddNewAttribute(string attributeName)
        {
            NewAttributeCommand c = (NewAttributeCommand)NewAttributeCommandFactory.Factory().Create(DiagramController.ModelController);

            if (!String.IsNullOrEmpty(attributeName))
            {
                c.Name = attributeName;
            }
            else
            {
                c.Name = NameSuggestor <Property> .SuggestUniqueName(Class.Attributes, "Attribute", property => property.Name);
            }
            c.Owner = Class;
            c.Execute();
        }
Esempio n. 12
0
        protected string GetTemplateName(string name)
        {
            string returns;

            if (NameSuggestor <string> .IsNameUnique(templateNames, name, S => S))
            {
                returns = name;
            }
            else
            {
                returns = NameSuggestor <string> .SuggestUniqueName(templateNames, name, S => S);
            }
            templateNames.Add(returns);
            return(returns);
        }
Esempio n. 13
0
        private void TranslateScript(XElement schSchema, OCLScript oclScript, TranslationSettings translationSettings,
                                     ref Dictionary <PSMClass, List <PatternInfo> > patterns)
        {
            OclCompilerResult compilerResult = oclScript.CompileToAst();

            compilerResult.CompileExpressionsInMessages();
            if (!compilerResult.Errors.HasError)
            {
                XComment comment = new XComment(string.Format("Below follow constraints from OCL script '{0}'. ", oclScript.Name));
                schSchema.Add(comment);

                foreach (ClassifierConstraintBlock classifierConstraintBlock in compilerResult.Constraints.ClassifierConstraintBlocks)
                {
                    PSMClass contextClass = (PSMClass)classifierConstraintBlock.Context.Tag;
                    patterns.CreateSubCollectionIfNeeded(contextClass);
                    string patternName = NameSuggestor <PatternInfo> .SuggestUniqueName(patterns[contextClass], contextClass.Name, p => p.PatternName, true, false);

                    PatternInfo patternInfo = new PatternInfo {
                        PatternName = patternName
                    };
                    XElement patternElement = schSchema.SchematronPattern(patternInfo.PatternName);
                    patterns[contextClass].Add(patternInfo);

                    bool abstractPattern = !contextClass.GeneralizationsAsGeneral.IsEmpty();

                    if (abstractPattern)
                    {
                        patternElement.AddAttributeWithValue("abstract", "true");
                    }

                    string context = !abstractPattern?contextClass.GetXPathFull(true).ToString() : "$" + classifierConstraintBlock.Self.Name;

                    XElement ruleElement = patternElement.SchematronRule(context);
                    patternInfo.ContextVariableName = classifierConstraintBlock.Self.Name;
                    if (!abstractPattern)
                    {
                        ruleElement.SchematronLet(patternInfo.ContextVariableName, @".");
                    }

                    TranslateInvariantsToXPath(classifierConstraintBlock, ruleElement, (PSMBridge)compilerResult.Bridge, translationSettings);
                }
            }
            else
            {
                XComment comment = new XComment(string.Format("OCL script '{0}' contains errors and thus can not be translated. ", oclScript.Name));
                schSchema.Add(comment);
            }
        }
Esempio n. 14
0
        public void AddNewOperation(string operationName)
        {
            NewOperationCommand c = (NewOperationCommand)NewOperationCommandFactory.Factory().Create(DiagramController.ModelController);

            if (!String.IsNullOrEmpty(operationName))
            {
                c.Name = operationName;
            }
            else
            {
                c.Name = NameSuggestor <Operation> .SuggestUniqueName(Class.Operations, "Operation", operation => operation.Name);
            }

            c.Owner = Class;
            c.Execute();
        }
Esempio n. 15
0
        protected string GetTemplateName(string prefix)
        {
            string     returns;
            XNamespace ns = GetNamespace(prefix);
            string     id = CutID(prefix);

            if (NameSuggestor <string> .IsNameUnique(templateNames, Namespaces[ns] + ":" + id, S => S))
            {
                returns = Namespaces[ns] + ":" + id;
            }
            else
            {
                returns = NameSuggestor <string> .SuggestUniqueName(templateNames, Namespaces[ns] + ":" + id, S => S);
            }
            templateNames.Add(returns);
            return(returns);
        }
Esempio n. 16
0
        internal override void CommandOperation()
        {
            PSMAttribute psmAttribute;

            if (RepresentedAttribute != null)
            {
                psmAttribute       = PSMClass.AddAttribute(RepresentedAttribute);
                psmAttribute.Lower = RepresentedAttribute.Lower;
                psmAttribute.Upper = RepresentedAttribute.Upper;
            }
            else
            {
                psmAttribute = PSMClass.AddAttribute((Property)null);
                if (!String.IsNullOrEmpty(Name))
                {
                    psmAttribute.Name = Name;
                }
                else if (!String.IsNullOrEmpty(Alias))
                {
                    psmAttribute.Name = Alias;
                }
                else
                {
                    psmAttribute.Name = NameSuggestor <PSMAttribute> .SuggestUniqueName(PSMClass.PSMAttributes, "Attribute", a => a.AliasOrName);
                }

                psmAttribute.Type = Type;
            }

            psmAttribute.Alias = Alias;

            if (customMultiplicity)
            {
                psmAttribute.Lower = Lower;
                psmAttribute.Upper = Upper;
            }

            psmAttribute.Default = Default;

            AssociatedElements.Add(PSMClass);
            CreatedAttribute = psmAttribute;
        }
Esempio n. 17
0
        private void OnAddPackageClick(object sender, RoutedEventArgs e)
        {
            MenuItem m = sender as MenuItem;

            if (m.DataContext == null || m.DataContext is Package)
            {
                NewModelPackageCommand newPackageCommand = (NewModelPackageCommand)NewModelPackageCommandFactory.Factory().Create(project.GetModelController());
                if (m.DataContext == null)
                {
                    newPackageCommand.Package = model;
                }
                else
                {
                    newPackageCommand.Package = m.DataContext as Package;
                }
                newPackageCommand.PackageName = NameSuggestor <Package> .SuggestUniqueName(newPackageCommand.Package.NestedPackages, "Package", package => package.Name);

                newPackageCommand.Execute();
                nestedPackages.DataContext = null;
            }
        }
Esempio n. 18
0
        public void AddNewAttribute(string attributeName, DataType type, uint?lower, UnlimitedNatural?upper, string @default)
        {
            NewAttributeCommand c = (NewAttributeCommand)NewAttributeCommandFactory.Factory().Create(DiagramController.ModelController);

            if (!String.IsNullOrEmpty(attributeName))
            {
                c.Name = attributeName;
            }
            else
            {
                c.Name = NameSuggestor <Property> .SuggestUniqueName(Class.Attributes, "Attribute", property => property.Name);
            }
            c.Type = new ElementHolder <DataType> {
                Element = type
            };
            c.Lower   = lower;
            c.Upper   = upper;
            c.Default = @default;
            c.Owner   = Class;
            c.Execute();
        }
Esempio n. 19
0
        public override void Execute(object parameter)
        {
            Element element;
            MacroCommand <DiagramController> command = MacroCommandFactory <DiagramController> .Factory().Create(ActiveDiagramView.Controller);

            command.Description = CommandDescription.ADD_OPERATION;
            foreach (ISelectable item in ActiveDiagramView.SelectedItems)
            {
                if (item is XCaseViewBase && (element = (item as XCaseViewBase).Controller.Element) is IHasOperations)
                {
                    NewOperationCommand c = NewOperationCommandFactory.Factory().Create(ActiveDiagramView.Controller.ModelController) as NewOperationCommand;
                    c.Owner = element as IHasOperations;
                    c.Name  = NameSuggestor <Operation> .SuggestUniqueName((element as IHasOperations).Operations, "Operation", property => property.Name);

                    command.Commands.Add(c);
                }
            }
            if (command.Commands.Count > 0)
            {
                command.Execute();
            }
        }
Esempio n. 20
0
        protected XNamespace GetNamespace(string s)
        {
            int i = s.IndexOf('#');

            if (i == -1)
            {
                if (!Namespaces.ContainsKey(XNamespace.None))
                {
                    Namespaces.Add(XNamespace.None, NameSuggestor <string> .SuggestUniqueName(Namespaces.Values, "ns", S => S));
                }
                return(XNamespace.None);
            }
            else
            {
                string sub = s.Substring(0, i);
                if (!Namespaces.ContainsKey(XNamespace.Get(sub)))
                {
                    Namespaces.Add(XNamespace.Get(sub), NameSuggestor <string> .SuggestUniqueName(Namespaces.Values, "ns", S => S));
                }
                return(XNamespace.Get(sub));
            }
        }
Esempio n. 21
0
        public override void Execute(object parameter)
        {
            Element element;
            MacroCommand <DiagramController> command = MacroCommandFactory <DiagramController> .Factory().Create(ActiveDiagramView.Controller);

            command.Description = CommandDescription.ADD_PSM_ATTRIBUTE;
            foreach (ISelectable item in ActiveDiagramView.SelectedItems)
            {
                if (item is PSM_Class && (element = (item as PSM_Class).Controller.Element) is PSMClass)
                {
                    AddPSMClassAttributeCommand c = AddPSMClassAttributeCommandFactory.Factory().Create(ActiveDiagramView.Controller) as AddPSMClassAttributeCommand;
                    c.PSMClass = (PSMClass)element;
                    c.Name     = NameSuggestor <PSMAttribute> .SuggestUniqueName(((PSMClass)element).PSMAttributes, "FreeAttribute", property => property.AliasOrName);

                    command.Commands.Add(c);
                }
            }
            if (command.Commands.Count > 0)
            {
                command.Execute();
            }
        }
Esempio n. 22
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);
                }
            }
        }