diff options
author | Falk Wurst | 2018-10-30 12:37:39 +0000 |
---|---|---|
committer | Falk Wurst | 2018-10-30 12:37:39 +0000 |
commit | abffedfdc2cf53cb251db8c5463533439a9af7b2 (patch) | |
tree | a5682f4bb67dc15fa250be573ace5f4f9e4cec6c | |
parent | 6e1e4f4c6ab872a0e3bb0705ee3b06e520e6474e (diff) | |
download | org.eclipse.app4mc-abffedfdc2cf53cb251db8c5463533439a9af7b2.tar.gz org.eclipse.app4mc-abffedfdc2cf53cb251db8c5463533439a9af7b2.tar.xz org.eclipse.app4mc-abffedfdc2cf53cb251db8c5463533439a9af7b2.zip |
Updated HwVisualization plugin: Converts special charackters, overworked error reporting
Signed-off-by: Falk Wurst <falk.wurst@de.bosch.com>
4 files changed, 134 insertions, 41 deletions
diff --git a/plugins/org.eclipse.app4mc.amalthea.visualization.hw/src/org/eclipse/app4mc/amalthea/visualization/hw/ModelToTextResult.java b/plugins/org.eclipse.app4mc.amalthea.visualization.hw/src/org/eclipse/app4mc/amalthea/visualization/hw/ModelToTextResult.java new file mode 100644 index 000000000..9f77de1d7 --- /dev/null +++ b/plugins/org.eclipse.app4mc.amalthea.visualization.hw/src/org/eclipse/app4mc/amalthea/visualization/hw/ModelToTextResult.java @@ -0,0 +1,30 @@ +/** + ******************************************************************************** + * Copyright (c) 2018 Robert Bosch GmbH. + * + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + *******************************************************************************/ + +package org.eclipse.app4mc.amalthea.visualization.hw; + +public class ModelToTextResult { + + ModelToTextResult(){ + errorFlag = false; + } + + private Boolean errorFlag; + + public Boolean getErrorFlag() { + return errorFlag; + } + + public void setErrorFlag(Boolean errorFlag) { + this.errorFlag = errorFlag; + } + +} diff --git a/plugins/org.eclipse.app4mc.amalthea.visualization.hw/src/org/eclipse/app4mc/amalthea/visualization/hw/VisualizationHandler.java b/plugins/org.eclipse.app4mc.amalthea.visualization.hw/src/org/eclipse/app4mc/amalthea/visualization/hw/VisualizationHandler.java index 2aa208359..d974f73e0 100644 --- a/plugins/org.eclipse.app4mc.amalthea.visualization.hw/src/org/eclipse/app4mc/amalthea/visualization/hw/VisualizationHandler.java +++ b/plugins/org.eclipse.app4mc.amalthea.visualization.hw/src/org/eclipse/app4mc/amalthea/visualization/hw/VisualizationHandler.java @@ -91,34 +91,46 @@ public class VisualizationHandler extends AbstractHandler { String absPath = ResourcesPlugin.getWorkspace().getRoot().getLocation().toString() + folder.getFullPath().toString(); - - CharSequence umlOutput = umlDiagramCreator.generatePlantUmlContent(hwModel); - - createDiagramFile.createfile(umlOutput, absPath, plantumlFileName); - - System.out.println("diagram.plantuml created"); - System.out.println(umlOutput); - - try { - OutputStream diagramFile = new FileOutputStream(absPath + "/" + diagramFileName); - SourceStringReader reader = new SourceStringReader(umlOutput.toString()); - reader.generateImage(diagramFile, new FileFormatOption(FileFormat.SVG)); - diagramFile.close(); - - folder.refreshLocal(1, new NullProgressMonitor()); - - MessageDialog.openInformation(Display.getDefault().getActiveShell(), - "AMALTHEA HW Visualization", - "Successfully generated HW Visualization for amalthea model file"); - - } catch (Exception e) { + + final ModelToTextResult errorCheck = new ModelToTextResult(); + + CharSequence umlOutput = umlDiagramCreator.generatePlantUmlContent(hwModel, errorCheck); + + if(errorCheck.getErrorFlag() == false) + { + + createDiagramFile.createfile(umlOutput, absPath, plantumlFileName); + + System.out.println("diagram.plantuml created"); + System.out.println(umlOutput); + + try { + OutputStream diagramFile = new FileOutputStream(absPath + "/" + diagramFileName); + SourceStringReader reader = new SourceStringReader(umlOutput.toString()); + reader.generateImage(diagramFile, new FileFormatOption(FileFormat.SVG)); + diagramFile.close(); + + folder.refreshLocal(1, new NullProgressMonitor()); + + MessageDialog.openInformation(Display.getDefault().getActiveShell(), + "AMALTHEA HW Visualization", + "Successfully generated HW Visualization for amalthea model file"); + + } catch (Exception e) { + MessageDialog.openError(Display.getDefault().getActiveShell(), + "AMALTHEA HW Visualization", + "Unable to generate HW Visualization for selected AMALTHEA model file"); + e.printStackTrace(); + } + + } + else { MessageDialog.openError(Display.getDefault().getActiveShell(), "AMALTHEA HW Visualization", - "Unable to generate HW Visualization for selected AMALTHEA model file"); - e.printStackTrace(); + "Due to errors unable to generate HW Visualization for selected AMALTHEA model file"); } - } + } catch (Exception e) { e.printStackTrace(); } diff --git a/plugins/org.eclipse.app4mc.amalthea.visualization.hw/src/org/eclipse/app4mc/amalthea/visualization/hw/templates/HWBlockDiagramCreator.xtend b/plugins/org.eclipse.app4mc.amalthea.visualization.hw/src/org/eclipse/app4mc/amalthea/visualization/hw/templates/HWBlockDiagramCreator.xtend index 3c85c6949..162e1784a 100644 --- a/plugins/org.eclipse.app4mc.amalthea.visualization.hw/src/org/eclipse/app4mc/amalthea/visualization/hw/templates/HWBlockDiagramCreator.xtend +++ b/plugins/org.eclipse.app4mc.amalthea.visualization.hw/src/org/eclipse/app4mc/amalthea/visualization/hw/templates/HWBlockDiagramCreator.xtend @@ -23,10 +23,11 @@ import org.eclipse.app4mc.amalthea.model.ProcessingUnit import org.eclipse.app4mc.amalthea.model.ReferableBaseObject import org.eclipse.jface.dialogs.MessageDialog import org.eclipse.swt.widgets.Display +import org.eclipse.app4mc.amalthea.visualization.hw.ModelToTextResult class HWBlockDiagramCreator { - def CharSequence generateLevel(HWModel model, HwStructure s) ''' + def CharSequence generateLevel(HWModel model, HwStructure s, ModelToTextResult errorCheck) ''' «IF !(s.name.nullOrEmpty)» frame "«s.name»" as «convertFluxString(s.name)» { «IF !s.modules.empty» @@ -43,14 +44,16 @@ class HWBlockDiagramCreator { «ENDIF» «ELSE» «MessageDialog.openError(Display.getDefault().getActiveShell(), "AMALTHEA HW Visualization", "Missing HW Module name: " + m.toString)» + «errorCheck.errorFlag = true» «ENDIF» «ENDFOR» «ENDIF» «FOR su : s.structures» - «generateLevel(model, su)» + «generateLevel(model, su, errorCheck)» «ENDFOR» «ELSE» «MessageDialog.openError(Display.getDefault().getActiveShell(), "AMALTHEA HW Visualization", "Name of HwStructure is missing " + s.toString)» + «errorCheck.errorFlag = true» «ENDIF» } @@ -69,7 +72,7 @@ class HWBlockDiagramCreator { ''' - def CharSequence generateLogicalRoutes(HWModel model, HwStructure s) ''' + def CharSequence generateLogicalRoutes(HWModel model, HwStructure s, ModelToTextResult errorCheck) ''' «IF !s.modules.empty» «FOR m: s.modules» «IF m instanceof ProcessingUnit» @@ -80,12 +83,14 @@ class HWBlockDiagramCreator { «convertFluxString(pUnit.name)» ..>«convertFluxString(ae.destination.name)» : «ae.name» «ELSE» «MessageDialog.openError(Display.getDefault().getActiveShell(), "AMALTHEA HW Visualization", "Missing Destination of AccessElement:" + ae.name)» + «errorCheck.errorFlag = true» «ENDIF» «ELSE» «IF ae.destination !== null» «convertFluxString(pUnit.name)» ..>«convertFluxString(ae.destination.name)» : «ae.toString» «ELSE» «MessageDialog.openError(Display.getDefault().getActiveShell(), "AMALTHEA HW Visualization", "Missing Destination of AccessElement:" + ae.toString)» + «errorCheck.errorFlag = true» «ENDIF» «ENDIF» «ENDFOR» @@ -93,20 +98,21 @@ class HWBlockDiagramCreator { «ENDFOR» «ENDIF» «FOR su : s.structures» - «generateLogicalRoutes(model, su)» + «generateLogicalRoutes(model, su, errorCheck)» «ENDFOR» ''' - def generatePlantUmlContent(HWModel model) ''' + def generatePlantUmlContent(HWModel model, ModelToTextResult errorCheck) ''' @startuml «IF !model.structures.empty» «FOR s : model.structures» - «generateLevel(model, s)» + «generateLevel(model, s, errorCheck)» ' add logical connections: - «generateLogicalRoutes(model, s)» + «generateLogicalRoutes(model, s, errorCheck)» «ENDFOR» «ELSE» «MessageDialog.openError(Display.getDefault().getActiveShell(), "AMALTHEA HW Visualization", "No Structure in the model")» + «errorCheck.errorFlag = true» «ENDIF» skinparam component { @@ -170,8 +176,27 @@ class HWBlockDiagramCreator { val String Regex11 = '\\.'; val tmpstr11 = tmpstr10.replaceAll(Regex11, replacestring); - - return tmpstr11; + + val String Regex12 = '#'; + val tmpstr12 = tmpstr11.replaceAll(Regex12, replacestring); + + val String Regex13 = '"'; + val tmpstr13 = tmpstr12.replaceAll(Regex13, replacestring); + + val String Regex14 = '$'; + val tmpstr14 = tmpstr13.replaceAll(Regex14, replacestring); + + val String Regex15 = '~'; + val tmpstr15 = tmpstr14.replaceAll(Regex15, replacestring); + + val String Regex16 = '%'; + val tmpstr16 = tmpstr15.replaceAll(Regex16, replacestring); + + val String Regex17 = '&'; + val tmpstr17 = tmpstr16.replaceAll(Regex17, replacestring); + + return tmpstr17; + } }
\ No newline at end of file diff --git a/plugins/org.eclipse.app4mc.amalthea.visualization.hw/xtend-gen/org/eclipse/app4mc/amalthea/visualization/hw/templates/HWBlockDiagramCreator.java b/plugins/org.eclipse.app4mc.amalthea.visualization.hw/xtend-gen/org/eclipse/app4mc/amalthea/visualization/hw/templates/HWBlockDiagramCreator.java index 6110a0813..db0e6eb6e 100644 --- a/plugins/org.eclipse.app4mc.amalthea.visualization.hw/xtend-gen/org/eclipse/app4mc/amalthea/visualization/hw/templates/HWBlockDiagramCreator.java +++ b/plugins/org.eclipse.app4mc.amalthea.visualization.hw/xtend-gen/org/eclipse/app4mc/amalthea/visualization/hw/templates/HWBlockDiagramCreator.java @@ -22,6 +22,7 @@ import org.eclipse.app4mc.amalthea.model.HwStructure; import org.eclipse.app4mc.amalthea.model.Memory; import org.eclipse.app4mc.amalthea.model.ProcessingUnit; import org.eclipse.app4mc.amalthea.model.ReferableBaseObject; +import org.eclipse.app4mc.amalthea.visualization.hw.ModelToTextResult; import org.eclipse.emf.common.util.EList; import org.eclipse.emf.ecore.EObject; import org.eclipse.jface.dialogs.MessageDialog; @@ -32,7 +33,7 @@ import org.eclipse.xtext.xbase.lib.StringExtensions; @SuppressWarnings("all") public class HWBlockDiagramCreator { - public CharSequence generateLevel(final HWModel model, final HwStructure s) { + public CharSequence generateLevel(final HWModel model, final HwStructure s, final ModelToTextResult errorCheck) { StringConcatenation _builder = new StringConcatenation(); { boolean _isNullOrEmpty = StringExtensions.isNullOrEmpty(s.getName()); @@ -117,6 +118,10 @@ public class HWBlockDiagramCreator { String _plus = ("Missing HW Module name: " + _string); MessageDialog.openError(_activeShell, "AMALTHEA HW Visualization", _plus); _builder.newLineIfNotEmpty(); + _builder.append("\t"); + _builder.append("\t"); + errorCheck.setErrorFlag(Boolean.valueOf(true)); + _builder.newLineIfNotEmpty(); } } } @@ -128,7 +133,7 @@ public class HWBlockDiagramCreator { for(final HwStructure su : _structures) { _builder.append("\t"); _builder.append("\t"); - CharSequence _generateLevel = this.generateLevel(model, su); + CharSequence _generateLevel = this.generateLevel(model, su, errorCheck); _builder.append(_generateLevel, "\t\t"); _builder.newLineIfNotEmpty(); } @@ -140,6 +145,9 @@ public class HWBlockDiagramCreator { String _plus_1 = ("Name of HwStructure is missing " + _string_1); MessageDialog.openError(_activeShell_1, "AMALTHEA HW Visualization", _plus_1); _builder.newLineIfNotEmpty(); + _builder.append("\t"); + errorCheck.setErrorFlag(Boolean.valueOf(true)); + _builder.newLineIfNotEmpty(); } } _builder.append("\t"); @@ -216,7 +224,7 @@ public class HWBlockDiagramCreator { return _builder; } - public CharSequence generateLogicalRoutes(final HWModel model, final HwStructure s) { + public CharSequence generateLogicalRoutes(final HWModel model, final HwStructure s, final ModelToTextResult errorCheck) { StringConcatenation _builder = new StringConcatenation(); { boolean _isEmpty = s.getModules().isEmpty(); @@ -255,6 +263,8 @@ public class HWBlockDiagramCreator { String _plus = ("Missing Destination of AccessElement:" + _name_1); MessageDialog.openError(_activeShell, "AMALTHEA HW Visualization", _plus); _builder.newLineIfNotEmpty(); + errorCheck.setErrorFlag(Boolean.valueOf(true)); + _builder.newLineIfNotEmpty(); } } } else { @@ -277,6 +287,8 @@ public class HWBlockDiagramCreator { String _plus_1 = ("Missing Destination of AccessElement:" + _string_1); MessageDialog.openError(_activeShell_1, "AMALTHEA HW Visualization", _plus_1); _builder.newLineIfNotEmpty(); + errorCheck.setErrorFlag(Boolean.valueOf(true)); + _builder.newLineIfNotEmpty(); } } } @@ -292,7 +304,7 @@ public class HWBlockDiagramCreator { { EList<HwStructure> _structures = s.getStructures(); for(final HwStructure su : _structures) { - CharSequence _generateLogicalRoutes = this.generateLogicalRoutes(model, su); + CharSequence _generateLogicalRoutes = this.generateLogicalRoutes(model, su, errorCheck); _builder.append(_generateLogicalRoutes); _builder.newLineIfNotEmpty(); } @@ -300,7 +312,7 @@ public class HWBlockDiagramCreator { return _builder; } - public CharSequence generatePlantUmlContent(final HWModel model) { + public CharSequence generatePlantUmlContent(final HWModel model, final ModelToTextResult errorCheck) { StringConcatenation _builder = new StringConcatenation(); _builder.append("@startuml"); _builder.newLine(); @@ -311,12 +323,12 @@ public class HWBlockDiagramCreator { { EList<HwStructure> _structures = model.getStructures(); for(final HwStructure s : _structures) { - CharSequence _generateLevel = this.generateLevel(model, s); + CharSequence _generateLevel = this.generateLevel(model, s, errorCheck); _builder.append(_generateLevel); _builder.newLineIfNotEmpty(); _builder.append("\' add logical connections:"); _builder.newLine(); - CharSequence _generateLogicalRoutes = this.generateLogicalRoutes(model, s); + CharSequence _generateLogicalRoutes = this.generateLogicalRoutes(model, s, errorCheck); _builder.append(_generateLogicalRoutes); _builder.newLineIfNotEmpty(); } @@ -324,6 +336,8 @@ public class HWBlockDiagramCreator { } else { MessageDialog.openError(Display.getDefault().getActiveShell(), "AMALTHEA HW Visualization", "No Structure in the model"); _builder.newLineIfNotEmpty(); + errorCheck.setErrorFlag(Boolean.valueOf(true)); + _builder.newLineIfNotEmpty(); } } _builder.newLine(); @@ -395,6 +409,18 @@ public class HWBlockDiagramCreator { final String tmpstr10 = tmpstr9.replaceAll(Regex10, replacestring); final String Regex11 = "\\."; final String tmpstr11 = tmpstr10.replaceAll(Regex11, replacestring); - return tmpstr11; + final String Regex12 = "#"; + final String tmpstr12 = tmpstr11.replaceAll(Regex12, replacestring); + final String Regex13 = "\""; + final String tmpstr13 = tmpstr12.replaceAll(Regex13, replacestring); + final String Regex14 = "$"; + final String tmpstr14 = tmpstr13.replaceAll(Regex14, replacestring); + final String Regex15 = "~"; + final String tmpstr15 = tmpstr14.replaceAll(Regex15, replacestring); + final String Regex16 = "%"; + final String tmpstr16 = tmpstr15.replaceAll(Regex16, replacestring); + final String Regex17 = "&"; + final String tmpstr17 = tmpstr16.replaceAll(Regex17, replacestring); + return tmpstr17; } } |