public static void CheckPsmParentsAndRoots(PSMDiagram diagram) { foreach (Element element in diagram.DiagramElements.Keys) { PSMSubordinateComponent subordinateComponent = (element as PSMSubordinateComponent); if (subordinateComponent != null) { if (subordinateComponent.Parent == null && !diagram.Roots.Contains((PSMClass)subordinateComponent)) { throw new ModelConsistencyException(string.Format("Bad subordinate component {0}", subordinateComponent)); } if (subordinateComponent.Parent != null) { if (!subordinateComponent.Parent.Components.Contains(subordinateComponent)) { throw new ModelConsistencyException(string.Format("Bad subordinate component {0}", subordinateComponent)); } } } PSMSuperordinateComponent superordinateComponent = element as PSMSuperordinateComponent; if (superordinateComponent != null) { foreach (PSMSubordinateComponent component in superordinateComponent.Components) { if (component.Parent != superordinateComponent) { throw new ModelConsistencyException(string.Format("Bad superordinateComponent component {0}", superordinateComponent)); } } } } }
private static void CheckPsmClassParent(PSMDiagram diagram) { foreach (PSMClass psmClass in diagram.DiagramElements.Keys.OfType <PSMClass>()) { if (psmClass.ParentAssociation != null) { if (psmClass.ParentAssociation.Child != psmClass) { throw new ModelConsistencyException(string.Format("Bad class parent association component {0}", psmClass)); } if (psmClass.ParentUnion != null) { throw new ModelConsistencyException(string.Format("Bad class parent association component {0}", psmClass)); } } else if (psmClass.ParentUnion != null) { if (!psmClass.ParentUnion.Components.Contains(psmClass)) { throw new ModelConsistencyException(string.Format("Bad class parent union component {0}", psmClass)); } if (psmClass.ParentAssociation != null) { throw new ModelConsistencyException(string.Format("Bad class parent association component {0}", psmClass)); } } else { if (!diagram.Roots.Contains(psmClass) && psmClass.Generalizations.Count == 0) { throw new ModelConsistencyException(string.Format("Bad class {0}", psmClass)); } } } }
public static IList <EvolutionChange> Detect(Version v1, Version v2, PSMDiagram diagram) { List <EvolutionChange> result = new List <EvolutionChange>(); PSMDiagram diagramOldVersion = (PSMDiagram)diagram.GetInVersion(v1); foreach (PSMSuperordinateComponent root in diagram.Roots) { PSMSuperordinateComponent rootOldVersion = (PSMSuperordinateComponent)root.GetInVersion(v1); IList <PSMSuperordinateComponent> oldRoots = diagramOldVersion.Roots.ToList(); if (rootOldVersion != null && oldRoots.Contains(rootOldVersion) && oldRoots.IndexOf(rootOldVersion) != diagram.Roots.ToList().IndexOf(root) ) { result.Add(new DiagramRootIndexChange(root) { OldVersion = v1, NewVersion = v2 }); } } return(result); }
private void SelectNotRequiredSubtrees() { PSMDiagram psmDiagram = ((PSMDiagram)Diagram); List <PSMClass> startClasses = SelectedItems.OfType <IModelElementRepresentant>().Select( r => ElementRepresentations.GetElementRepresentedBy(r)).OfType <PSMClass>().Where( r => psmDiagram.Roots.Contains(r)).ToList(); List <PSMClass> visitedClasses = new List <PSMClass>(startClasses); Queue <Element> queue = new Queue <Element>(startClasses); while (!queue.IsEmpty()) { Element element = queue.Dequeue(); PSMClass psmClass = element as PSMClass; if (psmClass != null) { visitedClasses.Add(psmClass); // new subtree added when structural representative found. if (psmClass.IsStructuralRepresentative && !psmClass.IsStructuralRepresentativeExternal) { queue.Enqueue(psmClass.RepresentedPSMClass); } } foreach (Element child in PSMTree.GetChildrenOfElement(element)) { queue.Enqueue(child); } } IEnumerable <IModelElementRepresentant> representants = psmDiagram.Roots.Where(r => !visitedClasses.Contains(r)).Select(element => ElementRepresentations[element]); SelectedItems.SetSelection(representants); }
public EvolutionChangeSet(PSMDiagram diagram, IEnumerable <EvolutionChange> changes, Version oldVersion, Version newVersion) { Diagram = diagram; this.AddRange(changes); OldVersion = oldVersion; NewVersion = newVersion; }
public List <EvolutionChange> Translate(PSMDiagram diagramOldVersion, PSMDiagram diagramNewVersion) { ChangesDetectorContext context = new ChangesDetectorContext { NewVersion = diagramNewVersion.Version, OldVersion = diagramOldVersion.Version, Diagram = diagramNewVersion }; Diagram = diagramNewVersion; context.ScopeStack.Push(EChangeScope.Diagram); ChangesLookupManager.DetectLocalChanges(context); foreach (PSMClass rootClass in diagramNewVersion.Roots) { TranslateClass(rootClass, context); } EChangeScope pop = context.ScopeStack.Pop(); Debug.Assert(pop == EChangeScope.Diagram); EvolutionChangeSet set = new EvolutionChangeSet(context.Diagram, context.DetectedChanges, diagramOldVersion.Version, diagramNewVersion.Version); set.Verify(); return(context.DetectedChanges); }
public override void Execute(object parameter) { if (CanExecute(parameter)) { ChangesDetector detector = new ChangesDetector(); PSMDiagram diagramNewVersion = (PSMDiagram)ActiveDiagramView.Diagram; PSMDiagram diagramOldVersion = null; if (previousVersions.Count == 1) { diagramOldVersion = (PSMDiagram)diagramNewVersion.GetInVersion(previousVersions.First()); } else { SelectItemsDialog d = new SelectItemsDialog(); d.ShortMessage = "Select previous version of the diagram. "; d.Title = "Select version"; d.UseRadioButtons = true; d.SetItems(previousVersions); d.SelectItem(previousVersions.FirstOrDefault(v => v.Number == previousVersions.Max(vm => vm.Number))); if (d.ShowDialog() == true && d.selectedObjects.Count == 1) { diagramOldVersion = (PSMDiagram)d.selectedObjects[0]; } } if (diagramOldVersion != null) { List <EvolutionChange> evolutionChanges = detector.Translate(diagramOldVersion, diagramNewVersion); EvolutionChangesWindow.Show(evolutionChanges, MainWindow, diagramOldVersion, diagramNewVersion); } } }
public override bool CanExecute(object parameter) { if (ActiveDiagramView != null && ActiveDiagramView.Diagram != null && ActiveDiagramView.Diagram is PSMDiagram) { PSMDiagram psmDiagram = (PSMDiagram)ActiveDiagramView.Diagram; if (psmDiagram.VersionManager != null && psmDiagram.VersionManager.Versions.Count > 0) { Version newVersion = psmDiagram.Version; previousVersions = new List <Version>(); foreach (Version version in psmDiagram.VersionManager.Versions) { if (/*version.Number < newVersion.Number && */ psmDiagram.GetInVersion(version) != null && version != psmDiagram.Version) { previousVersions.Add(version); } } if (previousVersions.Count > 0) { return(true); } } } return(false); }
//public static void Show(string documentText, PSMDiagram diagram) public static void Show(DockingManager manager, string documentText, PSMDiagram diagram, TranslationLog log) { documentText = documentText.Replace("utf-16", "utf-8"); SampleDocumentWindow w = new SampleDocumentWindow(); w.Diagram = diagram; w.documentText = documentText; w.tbDocument.Text = documentText; w.LogMessages = log; w.MainWindow = (MainWindow)manager.ParentWindow; w.foldingManager = FoldingManager.Install(w.tbDocument.TextArea); w.foldingStrategy = new XmlFoldingStrategy(); if (!String.IsNullOrEmpty(documentText)) { w.UpdateFolding(); } w.IsFloatingAllowed = true; w.IsCloseable = true; w.Title = string.Format("{0}.xml", diagram.Caption); DocumentFloatingWindow fw = new DocumentFloatingWindow(manager, w, manager.MainDocumentPane) { Topmost = true }; w.MainWindow.DiagramTabManager.CreatedFloatingWindows.Add(fw); w.DocumentFloatingWindow = fw; fw.Show(); }
private void BindProjectVersion(ProjectVersion projectVersion) { if (projectVersion.PIMDiagrams.Count == 0) { PIMDiagram pimDiagram = new PIMDiagram(projectVersion.Project); projectVersion.PIMDiagrams.Add(pimDiagram); pimDiagram.LoadSchemaToDiagram(projectVersion.PIMSchema); } if (projectVersion.PSMDiagrams.Count == 0) { foreach (PSMSchema psmSchema in projectVersion.PSMSchemas) { PSMDiagram psmDiagram = new PSMDiagram(projectVersion.Project); projectVersion.PSMDiagrams.Add(psmDiagram); psmDiagram.LoadSchemaToDiagram(psmSchema); } } DiagramTabManager.BindToProjectVersion(projectVersion); if (DiagramTabManager.ActiveDiagram == null) { DiagramTabManager.OpenTabsForProjectVersion(Current.Project.LatestVersion); } //navigatorTab.PIMModelTreeView.BindToProjectVersion(projectVersion); RefreshMenu(); }
public void ChangeReferencedDiagram(PSMDiagram referencedDiagram) { PSMDiagramReferenceChangeReferencedDiagramCommand command = (PSMDiagramReferenceChangeReferencedDiagramCommand)PSMDiagramReferenceChangeReferencedDiagramCommandFactory.Factory().Create(DiagramController); command.ReferencedDiagram = referencedDiagram; command.DiagramReference = this.DiagramReference; command.Execute(); }
public void DerivePSMClassToDiagram(PSMDiagram d) { DerivePSMClassToDiagramCommand c = (DerivePSMClassToDiagramCommand)DerivePSMClassToDiagramCommandFactory.Factory().Create(DiagramController.ModelController); c.Set(Class, d); c.Execute(); }
internal override void CommandOperation() { if (Diagram == null) { Diagram = new PSMDiagram(NameSuggestor <PSMDiagram> .SuggestUniqueName(Project.PSMDiagrams, "PSM Diagram", diagram => diagram.Caption)); } Project.AddDiagram(Diagram); }
internal override void CommandOperation() { PSMDiagram psmDiagram = Project.TranslateComponent <PSMDiagram>(DiagramGuid); psmDiagram.ProjectVersion.PSMDiagrams.RemoveChecked(psmDiagram); Project.mappingDictionary.Remove(DiagramGuid); Report = new CommandReport(CommandReports.PSM_diagram_removed, psmDiagram); }
internal override CommandBase.OperationResult UndoOperation() { PSMSchema s = Project.TranslateComponent <PSMSchema>(SchemaGuid); PSMDiagram psmDiagram = Project.TranslateComponent <PSMDiagram>(diagramGuid); s.ProjectVersion.PSMDiagrams.Remove(psmDiagram); Project.mappingDictionary.Remove(psmDiagram); return(OperationResult.OK); }
internal override CommandBase.OperationResult UndoOperation() { PSMSchema psmSchema = Project.TranslateComponent <PSMSchema>(SchemaGuid); PSMDiagram psmDiagram = new PSMDiagram(Project, DiagramGuid); psmDiagram.Schema = psmSchema; psmDiagram.LoadSchemaToDiagram(psmSchema); psmSchema.ProjectVersion.PSMDiagrams.Add(psmDiagram); return(OperationResult.OK); }
public static bool?ShowDialog(List <EvolutionChange> changes, PSMDiagram activeDiagramOldVersion, PSMDiagram activeDiagramNewVersion) { XsltTestWindow xsltTestWindow = new XsltTestWindow(changes); xsltTestWindow.DiagramOldVersion = activeDiagramOldVersion; xsltTestWindow.DiagramNewVersion = activeDiagramNewVersion; //return xsltTestWindow.ShowDialog(); xsltTestWindow.Show(); return(true); }
/// <summary> /// Returns true of <paramref name="psmClass"/> is a specialization /// of some of the root classes in <paramref name="diagram"/>. /// </summary> /// <param name="psmClass">psm class</param> /// <param name="diagram">PSM diagram</param> /// <param name="abstractRootsOnly">if set to true, only roots with <see cref="Class.IsAbstract"/> flag are considered</param> /// <param name="root">root that is specialized by <paramref name="psmClass"/> (if any)</param> /// <returns></returns> public static bool IsClassSpecializedRoot(this PSMClass psmClass, PSMDiagram diagram, bool abstractRootsOnly, out PSMClass root) { PSMClass r = psmClass; while (r.Generalizations.Count() != 0) { r = (PSMClass)r.Generalizations.First().General; } root = r; return((r.IsAbstract || !abstractRootsOnly) && diagram.Roots.Contains(r)); }
internal override CommandBase.OperationResult UndoOperation() { PSMSchema s = Project.TranslateComponent <PSMSchema>(SchemaGuid); s.Caption = oldName; PSMDiagram psmDiagram = s.PSMDiagram; if (psmDiagram != null && psmDiagram.Caption == NewName) { psmDiagram.Caption = oldName; } return(OperationResult.OK); }
public override string Translate(PSMDiagram diagram) { Diagram = diagram; //TODO: This is only fixed, it needs to take into account the Content Containers! IEnumerable <PSMClass> rootCandidates = diagram.Roots.Where(c => c is PSMClass && (c as PSMClass).HasElementLabel).Cast <PSMClass>(); if (rootCandidates.Count() == 0) { Log.AddError("No possible root element. Consider assigning an element label to one of the root classes."); return(String.Empty); } try { PSMClass root = rootCandidates.ChooseOneRandomly(); DataGeneratorContext context = new DataGeneratorContext(); TranslateComments(null, context); TranslateClass(root, context); AddSchemaArguments((XmlElement)context.ClassNodes[root], context); // write with indentation StringBuilder sb = new StringBuilder(); XmlWriterSettings settings = new XmlWriterSettings(); settings.Indent = true; settings.IndentChars = " "; settings.NewLineChars = "\r\n"; settings.NewLineHandling = NewLineHandling.Replace; XmlWriter writer = XmlWriter.Create(sb, settings); // ReSharper disable AssignNullToNotNullAttribute context.Document.Save(writer); // ReSharper restore AssignNullToNotNullAttribute // ReSharper disable PossibleNullReferenceException writer.Close(); // ReSharper restore PossibleNullReferenceException return(sb.ToString()); } catch (XmlSchemaException e) { if (e.Message.Contains("is recursive and causes infinite nesting")) { return(null); } else { throw; } } }
public static void CheckPsmElementsDiagram(PSMDiagram diagram) { foreach (Element element in diagram.DiagramElements.Keys) { PSMElement psmElement = element as PSMElement; if (psmElement != null) { if (psmElement.Diagram != diagram) { throw new ModelConsistencyException(string.Format("Element {0} has wrong diagram.", psmElement)); } } } }
internal override void CommandOperation() { PSMSchema s = Project.TranslateComponent <PSMSchema>(SchemaGuid); oldName = s.Caption; s.Caption = NewName; PSMDiagram psmDiagram = s.PSMDiagram; if (psmDiagram != null && psmDiagram.Caption == oldName) { psmDiagram.Caption = NewName; } Report = new CommandReport(CommandReports.SCHEMA_RENAMED, oldName, NewName); }
internal override void CommandOperation() { if (DiagramGuid == Guid.Empty) { DiagramGuid = Guid.NewGuid(); } PSMSchema psmSchema = Project.TranslateComponent <PSMSchema>(schemaGuid); PSMDiagram diagram = new PSMDiagram(Project, DiagramGuid); diagram.LoadSchemaToDiagram(psmSchema); psmSchema.ProjectVersion.PSMDiagrams.Add(diagram); Report = new CommandReport(CommandReports.PSM_diagram_added, psmSchema); }
internal static Element GetComponentAndCollection(ISelectable selectedItem, PSMDiagram diagram, out IList <PSMSuperordinateComponent> rootsCollection, out IList <PSMAssociationChild> associationChildCollection, out IList <PSMSubordinateComponent> subordinateComponentCollection) { rootsCollection = null; associationChildCollection = null; subordinateComponentCollection = null; if (selectedItem is IPSMSubordinateComponentRepresentant) { PSMSubordinateComponent subordinateComponent = ((IPSMSubordinateComponentRepresentant)selectedItem).ModelSubordinateComponent; if (subordinateComponent.Parent != null) { subordinateComponentCollection = subordinateComponent.Parent.Components; return(subordinateComponent); } } PSMAssociationChild associationChild = null; if (selectedItem is PSM_Class) { associationChild = ((PSM_Class)selectedItem).PSMClass; PSMClass psmClass = (PSMClass)associationChild; if (diagram.Roots.Contains(psmClass)) { rootsCollection = diagram.Roots; return(psmClass); } } if (selectedItem is PSM_ClassUnion) { associationChild = ((PSM_ClassUnion)selectedItem).ClassUnion; } if (associationChild != null) { if (associationChild.ParentAssociation != null && associationChild.ParentAssociation.Parent != null) { subordinateComponentCollection = associationChild.ParentAssociation.Parent.Components; return(associationChild.ParentAssociation); } else if (associationChild.ParentUnion != null) { associationChildCollection = associationChild.ParentUnion.Components; return(associationChild); } } return(null); }
public override void Execute(object parameter) { // todo: uncomment the next statement to run a test //Test(); return; PSMDiagram diagram = (PSMDiagram)ActiveDiagramView.Diagram; if (diagram.Roots.Count < 1) { MessageBox.Show("PSM diagram is empty. Nothing to translate.", "XCase Warning"); return; } // show dialog starting translation StartTranslation st = new StartTranslation(); DialogResult dr = st.ShowDialog(); if (dr != DialogResult.OK) { return; } Configuration config = new Configuration(); if (!st.isDefConfigChecked()) { config.Load(st.getConfigFileName()); } if (config == null) { return; } // get short name of current project string projectName = getProjectName(); // call XML Schema translation XmlSchemaTranslator translator = new XmlSchemaTranslator(config, projectName); string resultMessage = translator.Translate(diagram); if (resultMessage.Equals("ok")) { // get results and display them in nice window Dictionary <string, string> schemas = translator.getResults(); XMLSchemaWindow.Show(MainWindow.dockManager, (PSMDiagram)ActiveDiagramView.Diagram, schemas, translator.Log); } }
private void ConvertPSMSchema(PSMDiagram xcasePSMDiagram) { this.xcasePSMDiagram = xcasePSMDiagram; Type[] psmTypes = new[] { typeof(PSMClass), typeof(PSMContentContainer), typeof(PSMClassUnion), typeof(PSMAttributeContainer), typeof(PSMContentChoice), typeof(Association), typeof(Generalization), typeof(Comment) }; foreach (KeyValuePair <Element, ViewHelper> diagramElement in xcasePSMDiagram.DiagramElements.OrderBy( e => Array.IndexOf(psmTypes, e.GetType()))) { ConvertPSMElement((PSMElement)diagramElement.Key, diagramElement.Value); } SetStructuralRepresentatives(); CreateComponentAssociations(); ReorderAssociations(); }
internal override void CommandOperation() { if (CreatedContainer == null) { CreatedContainer = new Helpers.ElementHolder <PSMContentContainer>(); } PSMSubordinateComponent first = Parent.Components.FirstOrDefault(component => containedComponents.Contains(component)); PSMContentContainer psmContainer; if (Parent != null) { if (first == null) { psmContainer = (PSMContentContainer)Parent.AddComponent(PSMContentContainerFactory.Instance); } else { psmContainer = (PSMContentContainer)Parent.AddComponent( PSMContentContainerFactory.Instance, Parent.Components.IndexOf(first)); } } else //add as root { PSMDiagram diagram = (PSMDiagram)Diagram; PSMContentContainer contentContainer = (PSMContentContainer)PSMContentContainerFactory.Instance.Create(null, diagram.Project.Schema); contentContainer.Diagram = diagram; psmContainer = contentContainer; diagram.Roots.Add(psmContainer); } psmContainer.Name = Name; CreatedContainer.Element = psmContainer; AssociatedElements.Add(psmContainer); foreach (PSMSubordinateComponent containedComponent in containedComponents) { oldIndexes[containedComponent] = containedComponent.ComponentIndex(); Parent.Components.Remove(containedComponent); psmContainer.Components.Add(containedComponent); } Debug.Assert(CreatedContainer.HasValue); Diagram.AddModelElement(psmContainer, ViewHelper = new PSMElementViewHelper(Diagram)); }
public void Set(Project project, PSMDiagram removedDiagram, DiagramController DiagramController) { DeleteFromPSMDiagramConsideringRepresentativesMacroCommand delete = (DeleteFromPSMDiagramConsideringRepresentativesMacroCommand)DeleteFromPSMDiagramConsideringRepresentativesMacroCommandFactory.Factory().Create(DiagramController); delete.ForceDelete = true; if (!delete.InitializeCommand(null, removedDiagram.Roots.Cast <Element>().ToArray())) { Commands.Clear(); return; } Commands.Add(delete); RemoveDiagramCommand c = (RemoveDiagramCommand)RemoveDiagramCommandFactory.Factory().Create(Controller); c.Set(project, removedDiagram); Commands.Add(c); }
public static void Show(DockingManager manager, PSMDiagram diagram, string schema, TranslationLog log) { XMLSchemaWindow w = new XMLSchemaWindow(); w.Diagram = diagram; w.XMLSchemaText = schema; w.LogMessages = log; w.MainWindow = manager.GetMainWindow(); w.IsFloatingAllowed = true; w.IsCloseable = true; w.Title = string.Format("{0}.xsd", diagram.Caption); w.Show(manager, true); //DocumentFloatingWindow fw = new DocumentFloatingWindow(manager, w, manager.MainDocumentPane) { Topmost = true }; //w.MainWindow.DiagramTabManager.CreatedFloatingWindows.Add(fw); //w.DocumentFloatingWindow = fw; //fw.Show(); }
public static IList <EvolutionChange> Detect(Version v1, Version v2, PSMDiagram diagram) { List <EvolutionChange> result = new List <EvolutionChange>(); PSMDiagram diagramOldVersion = (PSMDiagram)diagram.GetInVersion(v1); foreach (PSMSuperordinateComponent root in diagramOldVersion.Roots) { if (root.GetInVersion(v2) == null) { result.Add(new DiagramRootRemovedChange(root) { OldVersion = v1, NewVersion = v2 }); } } return(result); }