internal override void CommandOperation() { PSMSuperordinateComponent p = AttributeContainerLeftOut.Parent; while (!(p is PSMClass) && p is PSMSubordinateComponent) { p = ((PSMSubordinateComponent)p).Parent; } parentClass = p as PSMClass; if (parentClass != null) { returnedAttributes = new List <PSMAttribute>(); foreach (PSMAttribute attribute in AttributeContainerLeftOut.PSMAttributes) { if (parentClass.PSMAttributes.Any(a => a.RepresentedAttribute == attribute.RepresentedAttribute)) { continue; } PSMAttribute createdAttribute = parentClass.AddAttribute(attribute.RepresentedAttribute); returnedAttributes.Add(createdAttribute); if (!String.IsNullOrEmpty(attribute.Alias)) { createdAttribute.Alias = attribute.Alias; } } AttributeContainerLeftOut.RemoveMeFromModel(); viewHelper = Diagram.DiagramElements[AttributeContainerLeftOut]; Diagram.RemoveModelElement(AttributeContainerLeftOut); } }
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; }
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); } } }