Commit a7421f59 authored by Eyrak Paen-Rochlitz's avatar Eyrak Paen-Rochlitz
Browse files

[ui, generator.doc] qualified diagram export paths by model namespace

Diagram export filepaths are now prefixed with the containing model
namespace to avoid name collisions.

Issue #50
parent 9c396c46
......@@ -19,6 +19,7 @@ import com.google.inject.Singleton
import java.util.List
import org.eclipse.emf.ecore.EObject
import org.eclipse.etrice.core.common.base.Documentation
import org.eclipse.etrice.core.fsm.fSM.ModelComponent
import org.eclipse.etrice.core.fsm.fSM.State
import org.eclipse.etrice.core.fsm.fSM.StateGraph
import org.eclipse.etrice.core.genmodel.etricegen.Root
......@@ -41,6 +42,9 @@ import org.eclipse.xtext.documentation.IEObjectDocumentationProvider
import static org.eclipse.etrice.core.common.documentation.DocumentationMarkup.*
import org.eclipse.etrice.generator.doc.Main
import org.eclipse.etrice.generator.base.AbstractGeneratorOptionsHelper
import org.eclipse.etrice.core.room.StructureClass
import static extension org.eclipse.xtext.EcoreUtil2.getContainerOfType
@Singleton
class AsciiDocGen {
......@@ -189,7 +193,7 @@ class AsciiDocGen {
system.docText
IF includeImages
includeImage(system.name + "_instanceTree.svg", true)
includeImage(system.instanceDiagramName + ".svg", true)
ENDIF
tagEnd(system)
......@@ -204,7 +208,7 @@ class AsciiDocGen {
ssc.docText
IF includeImages
includeImage(ssc.name + "_structure.jpg")
includeImage(ssc.diagramName + ".jpg")
ENDIF
tagEnd(ssc)
'''
......@@ -318,7 +322,7 @@ class AsciiDocGen {
==== Structure
IF includeImages
includeImage(ac.name + "_structure.jpg")
includeImage(ac.diagramName + ".jpg")
ENDIF
IF !ac.allPorts.empty
......@@ -355,10 +359,9 @@ class AsciiDocGen {
'''
def private CharSequence generateStateGraphDoc(ActorClass ac, StateGraph stateGraph, boolean includeImages, int depth) {
val statePath = if(stateGraph.eContainer instanceof State) "_" + (stateGraph.eContainer as State).genStatePathName else ""
'''
IF includeImages
includeImage(ac.name + statePath + "_behavior.jpg")
includeImage(stateGraph.diagramName + ".jpg")
ENDIF
FOR state: stateGraph.states
state.name::fill(':', depth)
......@@ -464,6 +467,23 @@ class AsciiDocGen {
if(index != -1) docText.subSequence(0, index) else docText
}
def private dispatch getDiagramName(StructureClass sc) {
val namespace = sc.getContainerOfType(RoomModel)?.name?.concat(".") ?: ""
namespace + sc.name + "_structure"
}
def private dispatch getDiagramName(StateGraph sg) {
val namespace = sg.getContainerOfType(RoomModel)?.name?.concat(".") ?: ""
val modelComponentName = sg.getContainerOfType(ModelComponent)?.componentName ?: ""
val subStatePath = if (sg.eContainer instanceof State) "." + (sg.eContainer as State)?.genStatePathName else ""
namespace + modelComponentName + subStatePath + "_behavior"
}
def private getInstanceDiagramName(LogicalSystem system) {
val namespace = system.getContainerOfType(RoomModel)?.name?.concat(".") ?: ""
namespace + system.name + "_instanceTree"
}
def private includeImage(String filename) {
includeImage(filename, false)
}
......
......@@ -26,6 +26,9 @@ import org.eclipse.etrice.generator.generic.RoomExtensions
import org.eclipse.etrice.core.etmap.util.ETMapUtil
import org.eclipse.etrice.generator.base.io.IGeneratorFileIO
import org.eclipse.etrice.core.room.RoomModel
import static extension org.eclipse.xtext.EcoreUtil2.getContainerOfType
@Singleton
class InstanceDiagramGen {
......@@ -35,7 +38,8 @@ class InstanceDiagramGen {
def doGenerate(Root root, IGeneratorFileIO fileIO) {
var path = "images/"
for (sys : root.systemInstances) {
var file = sys.name+"_instanceTree.dot"
val namespace = sys.logicalSystem.getContainerOfType(RoomModel)?.name?.concat(".") ?: ""
val file = namespace + sys.name + "_instanceTree.dot"
fileIO.generateFile("generating instance tree diagram", path + file, root.generate(sys))
}
}
......
......@@ -16,6 +16,7 @@ package org.eclipse.etrice.ui.behavior.fsm.editor;
import java.io.File;
import org.eclipse.emf.ecore.EAttribute;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.etrice.core.fsm.fSM.ModelComponent;
import org.eclipse.etrice.core.fsm.fSM.State;
......@@ -35,7 +36,7 @@ public class BehaviorExporter implements IBulkDiagramExporter {
public BehaviorExporter(DiagramAccessBase da) {
this.da = da;
}
public void export(EObject roomClass, String folder) {
boolean wasOpen = false;
......@@ -47,10 +48,11 @@ public class BehaviorExporter implements IBulkDiagramExporter {
ModelComponent mc = editor.getModelComponent();
if (editor!=null) {
String filename = folder+File.separatorChar+mc.getComponentName()+SUFFIX;
String basepath = folder+File.separatorChar+getQualifiedBaseName(mc);
String filename = basepath+SUFFIX;
DiagramExporter.export(editor, filename);
exportSubGraphsRecursively(mc.getStateMachine(), editor, folder+File.separatorChar+mc.getComponentName());
exportSubGraphsRecursively(mc.getStateMachine(), editor, basepath);
if (!wasOpen)
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().closeEditor(editor, false);
......@@ -64,7 +66,7 @@ public class BehaviorExporter implements IBulkDiagramExporter {
for (State state : sg.getStates()) {
if (FSMSupportUtil.getInstance().getFSMHelpers().hasDirectSubStructure(state)) {
if (editor.showStateGraph(state.getSubgraph())) {
String filename = basename+"_"+FSMSupportUtil.getInstance().getFSMNameProvider().getStatePathName(state)+SUFFIX;
String filename = basename+"."+FSMSupportUtil.getInstance().getFSMNameProvider().getStatePathName(state)+SUFFIX;
DiagramExporter.export(editor, filename);
}
......@@ -72,4 +74,29 @@ public class BehaviorExporter implements IBulkDiagramExporter {
}
}
}
private String inferNamespaceName(ModelComponent mc) {
EObject container = mc.eContainer();
if (container == null) {
return "";
}
EAttribute namespaceAttr = container.eClass().getEAllAttributes().stream()
.filter(attr -> attr.getName().equals("name"))
.findFirst()
.orElse(null);
if (namespaceAttr == null) {
return "";
}
String name = container.eGet(namespaceAttr).toString();
return name;
}
private String getQualifiedBaseName(ModelComponent mc) {
String namespaceName = inferNamespaceName(mc);
if (namespaceName != null && !namespaceName.isEmpty()) {
namespaceName += ".";
}
String qualifiedName = namespaceName + mc.getComponentName();
return qualifiedName;
}
}
......@@ -18,6 +18,7 @@ import java.io.File;
import org.eclipse.core.runtime.Assert;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.etrice.core.room.RoomModel;
import org.eclipse.etrice.core.room.StructureClass;
import org.eclipse.etrice.ui.common.base.export.DiagramExporter;
import org.eclipse.etrice.ui.common.base.export.IBulkDiagramExporter;
......@@ -31,8 +32,18 @@ public class StructureExporter implements IBulkDiagramExporter {
Assert.isLegal(roomClass instanceof StructureClass);
StructureClass sc = (StructureClass) roomClass;
File exportFile = new File(folder, getQualifiedBaseName(sc)+SUFFIX);
DiagramAccess da = new DiagramAccess();
DiagramExporter.export(sc, da, folder+File.separatorChar+sc.getName()+SUFFIX);
DiagramExporter.export(sc, da, exportFile.toString());
}
private String getQualifiedBaseName(StructureClass sc) {
String namespace = "";
if (sc.eContainer() instanceof RoomModel) {
namespace = ((RoomModel)sc.eContainer()).getName() + ".";
}
String filename = namespace + sc.getName();
return filename;
}
}
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (C) 2022, protos software gmbh (http://www.protos.de).
All rights reserved. This program and the accompanying materials
are made available under the terms of the Eclipse Public License 2.0
which accompanies this distribution, and is available at
https://www.eclipse.org/legal/epl-2.0/
SPDX-License-Identifier: EPL-2.0
-->
<project
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.eclipse.etrice</groupId>
<artifactId>org.eclipse.etrice.tests</artifactId>
<version>0.0.0-SNAPSHOT</version>
<relativePath>..</relativePath>
</parent>
<artifactId>org.eclipse.etrice.ui.behavior.tests</artifactId>
<packaging>eclipse-test-plugin</packaging>
<build>
<plugins>
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-surefire-plugin</artifactId>
<version>${tycho.version}</version>
<configuration>
<useUIHarness>true</useUIHarness>
</configuration>
</plugin>
</plugins>
</build>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (C) 2022, protos software gmbh (http://www.protos.de).
All rights reserved. This program and the accompanying materials
are made available under the terms of the Eclipse Public License 2.0
which accompanies this distribution, and is available at
https://www.eclipse.org/legal/epl-2.0/
SPDX-License-Identifier: EPL-2.0
-->
<project
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.eclipse.etrice</groupId>
<artifactId>org.eclipse.etrice.tests</artifactId>
<version>0.0.0-SNAPSHOT</version>
<relativePath>..</relativePath>
</parent>
<artifactId>org.eclipse.etrice.ui.structure.tests</artifactId>
<packaging>eclipse-test-plugin</packaging>
<build>
<plugins>
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-surefire-plugin</artifactId>
<version>${tycho.version}</version>
<configuration>
<useUIHarness>true</useUIHarness>
</configuration>
</plugin>
</plugins>
</build>
</project>
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment