internal override PropagationMacroCommand PrePropagation() { PIMAttribute pimAttribute = Project.TranslateComponent <PIMAttribute>(attributeGuid); PIMClass specialPIMClass = Project.TranslateComponent <PIMClass>(specialClassGuid); PIMClass generalPIMClass = pimAttribute.PIMClass; List <PSMAttribute> psmAttributes = pimAttribute.GetInterpretedComponents().Cast <PSMAttribute>().ToList(); PropagationMacroCommand command = new PropagationMacroCommand(Controller) { CheckFirstOnlyInCanExecute = true }; command.Report = new CommandReport("Pre-propagation (specialize PIM attribute)"); foreach (PSMAttribute a in psmAttributes) { if (a.PSMClass.Interpretation == null) { //class without interpretation, maybe including impl.inheritance command.Commands.Add(new cmdMovePSMAttribute(Controller) { AttributeGuid = a, ClassGuid = a.PSMClass.NearestInterpretedClass() }); } IEnumerable <Tuple <PSMClass, IEnumerable <PSMClass> > > paths = a.PSMClass.GetSpecialClassesWithPaths(); if (paths.Any(p => p.Item1.Interpretation == specialPIMClass)) //1) there is special PIMClass counterpart -> move there { IEnumerable <PSMClass> path = paths.First(p => p.Item1.Interpretation == specialPIMClass).Item2; foreach (PSMClass c in path) { command.Commands.Add(new acmdSpecializePSMAttribute(Controller, a, c)); } } else //2) There is none... create. TODO: FIX: multiple attributes in one class => multiple classes { Guid newClassGuid = Guid.NewGuid(); command.Commands.Add(new acmdNewPSMClass(Controller, a.PSMSchema) { ClassGuid = newClassGuid }); command.Commands.Add(new acmdRenameComponent(Controller, newClassGuid, specialPIMClass.Name)); command.Commands.Add(new acmdSetPSMClassInterpretation(Controller, newClassGuid, specialPIMClass)); command.Commands.Add(new acmdNewPSMGeneralization(Controller, a.PSMClass.NearestInterpretedClass(), newClassGuid, a.PSMSchema)); command.Commands.Add(new acmdSpecializePSMAttribute(Controller, a, newClassGuid)); } } return(command); }
internal override PropagationMacroCommand PrePropagation() { PIMAttribute pimAttribute = Project.TranslateComponent <PIMAttribute>(attributeGuid); PIMClass oldPIMClass = pimAttribute.PIMClass; PIMClass newPIMClass = oldPIMClass.GeneralizationAsSpecific.General; List <PSMAttribute> psmAttributes = pimAttribute.GetInterpretedComponents().Cast <PSMAttribute>().ToList(); PropagationMacroCommand command = new PropagationMacroCommand(Controller) { CheckFirstOnlyInCanExecute = true }; command.Report = new CommandReport("Pre-propagation (generalize PIM attribute)"); foreach (PSMAttribute a in psmAttributes) { IEnumerable <PSMClass> generals = a.PSMClass.NearestInterpretedClass().GetGeneralClasses(); if (generals.Any(c => c.Interpretation == newPIMClass)) { if (a.PSMClass.Interpretation == null) { //class without interpretation, maybe including impl.inheritance command.Commands.Add(new cmdMovePSMAttribute(Controller) { AttributeGuid = a, ClassGuid = a.PSMClass.NearestInterpretedClass() }); } //whether the class uses implicit inheritance or not (a.PSMClass.Interpretation == oldPIMClass) we move it to the PSMClass, whose interpretation is newPIMClass command.Commands.Add(new cmdGeneralizePSMAttribute(Controller) { AttributeGuid = a, PSMClassGuid = generals.First(c => c.Interpretation == newPIMClass) }); } } return(command); }
internal override PropagationMacroCommand PrePropagation() { PropagationMacroCommand command = new PropagationMacroCommand(Controller); command.Report = new CommandReport("Pre-propagation (move PIM attribute)"); PIMAttribute attribute = Project.TranslateComponent <PIMAttribute>(attributeGuid); PIMClass targetClass = Project.TranslateComponent <PIMClass>(newClassGuid); PIMClass sourceClass = attribute.PIMClass; IEnumerable <PIMAssociation> pimAssociations = targetClass.GetAssociationsWith(sourceClass); IEnumerable <PSMAttribute> interpretedAttributes = attribute.GetInterpretedComponents().Cast <PSMAttribute>().Where(a => a.ID != PropagateSource); foreach (PSMAttribute psmAttribute in interpretedAttributes) { PSMClass intclass = psmAttribute.PSMClass.NearestInterpretedClass(); Debug.Assert(intclass.Interpretation == sourceClass, "Intclass != sourceclass"); bool found = false; PSMAssociation parentAssociation = intclass.ParentAssociation; foreach (PIMAssociation association in pimAssociations) { if (parentAssociation != null && parentAssociation.Interpretation == association) { //moving the attribute up in PSM found = true; cmdCreateNewPSMAttribute c2 = new cmdCreateNewPSMAttribute(Controller); Guid attrGuid2 = Guid.NewGuid(); c2.AttributeGuid = attrGuid2; c2.Set(intclass, psmAttribute.AttributeType, psmAttribute.Name, psmAttribute.Lower, psmAttribute.Upper, psmAttribute.Element); command.Commands.Add(c2); if (psmAttribute.PSMClass != intclass) { command.Commands.Add(new cmdMovePSMAttribute(Controller) { AttributeGuid = psmAttribute, ClassGuid = intclass, Propagate = false }); } acmdSynchroPSMAttributes s2 = new acmdSynchroPSMAttributes(Controller) { Propagate = false }; s2.X1.Add(psmAttribute); s2.X2.Add(attrGuid2); command.Commands.Add(s2); if (psmAttribute.PSMClass != intclass) { command.Commands.Add(new cmdMovePSMAttribute(Controller) { AttributeGuid = psmAttribute, ClassGuid = psmAttribute.PSMClass, Propagate = false }); } acmdSetInterpretation i2 = new acmdSetPSMAttributeInterpretation(Controller, attrGuid2, attribute); command.Commands.Add(i2); cmdMovePSMAttribute m2 = new cmdMovePSMAttribute(Controller) { Propagate = false }; m2.Set(attrGuid2, intclass.NearestInterpretedParentClass()); command.Commands.Add(m2); } //select nearest interpreted child PSM classes, whose parent association's interpretation is the PIM association through which we are moving the attribute IEnumerable <PSMClass> children = intclass.InterpretedSubClasses().Where <PSMClass>(pc => pc.Interpretation == targetClass && pc.ParentAssociation.Interpretation == association); foreach (PSMClass child in children) { found = true; cmdCreateNewPSMAttribute c = new cmdCreateNewPSMAttribute(Controller); Guid attrGuid = Guid.NewGuid(); c.AttributeGuid = attrGuid; c.Set(intclass, psmAttribute.AttributeType, psmAttribute.Name, psmAttribute.Lower, psmAttribute.Upper, psmAttribute.Element); command.Commands.Add(c); if (psmAttribute.PSMClass != intclass) { command.Commands.Add(new cmdMovePSMAttribute(Controller) { AttributeGuid = psmAttribute, ClassGuid = intclass, Propagate = false }); } acmdSynchroPSMAttributes s2 = new acmdSynchroPSMAttributes(Controller) { Propagate = false }; s2.X1.Add(psmAttribute); s2.X2.Add(attrGuid); command.Commands.Add(s2); if (psmAttribute.PSMClass != intclass) { command.Commands.Add(new cmdMovePSMAttribute(Controller) { AttributeGuid = psmAttribute, ClassGuid = psmAttribute.PSMClass, Propagate = false }); } acmdSetInterpretation i = new acmdSetPSMAttributeInterpretation(Controller, attrGuid, attribute); command.Commands.Add(i); cmdMovePSMAttribute m = new cmdMovePSMAttribute(Controller) { Propagate = false }; m.Set(attrGuid, child); command.Commands.Add(m); } if (!found) { cmdCreateNewPSMAttribute c = new cmdCreateNewPSMAttribute(Controller); Guid attrGuid = Guid.NewGuid(); c.AttributeGuid = attrGuid; c.Set(/*intclass*/ psmAttribute.PSMClass, psmAttribute.AttributeType, psmAttribute.Name, psmAttribute.Lower, psmAttribute.Upper, psmAttribute.Element); command.Commands.Add(c); /*if (psmAttribute.PSMClass != intclass) * { * cmdMovePSMAttribute m1 = new cmdMovePSMAttribute(Controller) { Propagate = false }; * m1.Set(psmAttribute, intclass); * command.Commands.Add(m1); * }*/ acmdSynchroPSMAttributes s = new acmdSynchroPSMAttributes(Controller) { Propagate = false }; s.X1.Add(psmAttribute); s.X2.Add(attrGuid); command.Commands.Add(s); /*if (psmAttribute.PSMClass != intclass) * { * cmdMovePSMAttribute m2 = new cmdMovePSMAttribute(Controller) { Propagate = false }; * m2.Set(psmAttribute, psmAttribute.PSMClass); * command.Commands.Add(m2); * }*/ acmdSetInterpretation i = new acmdSetPSMAttributeInterpretation(Controller, attrGuid, attribute); command.Commands.Add(i); //create psmassoc, class Guid ncGuid = Guid.NewGuid(); acmdNewPSMClass nc = new acmdNewPSMClass(Controller, psmAttribute.PSMSchema) { ClassGuid = ncGuid }; command.Commands.Add(nc); acmdRenameComponent rc = new acmdRenameComponent(Controller, ncGuid, targetClass.Name); command.Commands.Add(rc); acmdSetInterpretation ic = new acmdSetPSMClassInterpretation(Controller, ncGuid, targetClass); command.Commands.Add(ic); Guid naGuid = Guid.NewGuid(); acmdNewPSMAssociation na = new acmdNewPSMAssociation(Controller, /*intclass*/ psmAttribute.PSMClass, ncGuid, psmAttribute.PSMSchema) { AssociationGuid = naGuid }; command.Commands.Add(na); acmdRenameComponent ra = new acmdRenameComponent(Controller, naGuid, association.Name); command.Commands.Add(ra); PIMAssociationEnd e = targetClass.PIMAssociationEnds.Single <PIMAssociationEnd>(aend => aend.PIMAssociation == association); acmdUpdatePSMAssociationCardinality carda = new acmdUpdatePSMAssociationCardinality(Controller, naGuid, e.Lower, e.Upper) { Propagate = false }; command.Commands.Add(carda); acmdSetInterpretation ia = new acmdSetPSMAssociationInterpretation(Controller, naGuid, e, association); command.Commands.Add(ia); acmdMovePSMAttribute m = new acmdMovePSMAttribute(Controller, attrGuid, ncGuid) { Propagate = false }; command.Commands.Add(m); } } //delete attribute cmdDeletePSMAttribute d = new cmdDeletePSMAttribute(Controller) { Propagate = false }; d.Set(psmAttribute); command.Commands.Add(d); } command.CheckFirstOnlyInCanExecute = true; return(command); }