diff --git a/plugins/org.polarsys.chess.smvExport/.classpath b/plugins/org.polarsys.chess.smvExport/.classpath new file mode 100644 index 0000000000000000000000000000000000000000..b862a296d38fe04269faeee6c9d77d11ff77380d --- /dev/null +++ b/plugins/org.polarsys.chess.smvExport/.classpath @@ -0,0 +1,7 @@ +<?xml version="1.0" encoding="UTF-8"?> +<classpath> + <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/> + <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> + <classpathentry kind="src" path="src"/> + <classpathentry kind="output" path="bin"/> +</classpath> diff --git a/plugins/org.polarsys.chess.smvExport/.gitignore b/plugins/org.polarsys.chess.smvExport/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..ae3c1726048cd06b9a143e0376ed46dd9b9a8d53 --- /dev/null +++ b/plugins/org.polarsys.chess.smvExport/.gitignore @@ -0,0 +1 @@ +/bin/ diff --git a/plugins/org.polarsys.chess.smvExport/.project b/plugins/org.polarsys.chess.smvExport/.project new file mode 100644 index 0000000000000000000000000000000000000000..1a3d40d0dcaef1e846362c98f94f6113c0ba0ae1 --- /dev/null +++ b/plugins/org.polarsys.chess.smvExport/.project @@ -0,0 +1,28 @@ +<?xml version="1.0" encoding="UTF-8"?> +<projectDescription> + <name>org.polarsys.chess.smvExport</name> + <comment></comment> + <projects> + </projects> + <buildSpec> + <buildCommand> + <name>org.eclipse.jdt.core.javabuilder</name> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>org.eclipse.pde.ManifestBuilder</name> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>org.eclipse.pde.SchemaBuilder</name> + <arguments> + </arguments> + </buildCommand> + </buildSpec> + <natures> + <nature>org.eclipse.pde.PluginNature</nature> + <nature>org.eclipse.jdt.core.javanature</nature> + </natures> +</projectDescription> diff --git a/plugins/org.polarsys.chess.smvExport/.settings/org.eclipse.jdt.core.prefs b/plugins/org.polarsys.chess.smvExport/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000000000000000000000000000000000000..295926d964165896ea8aa7c1b1b3c9d3d3caa77e --- /dev/null +++ b/plugins/org.polarsys.chess.smvExport/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,7 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.compliance=1.8 +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/plugins/org.polarsys.chess.smvExport/META-INF/MANIFEST.MF b/plugins/org.polarsys.chess.smvExport/META-INF/MANIFEST.MF new file mode 100644 index 0000000000000000000000000000000000000000..cf4887323ca270211c7590125ce3055433cc8555 --- /dev/null +++ b/plugins/org.polarsys.chess.smvExport/META-INF/MANIFEST.MF @@ -0,0 +1,19 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: SmvExport +Bundle-SymbolicName: org.polarsys.chess.smvExport;singleton:=true +Bundle-Version: 1.0.0.qualifier +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Bundle-Vendor: Fondazione Bruno Kessler +Require-Bundle: org.eclipse.papyrus.infra.gmfdiag.common, + eu.fbk.eclipse.standardtools.utils, + org.polarsys.chess.service, + org.eclipse.uml2.uml, + org.polarsys.chess.contracts.profile;bundle-version="0.9.0", + eu.fbk.eclipse.standardtools.StateMachineTranslatorToSmv;bundle-version="1.0.0", + org.eclipse.papyrus.uml.tools, + org.eclipse.core.resources, + org.polarsys.chess.core, + org.eclipse.papyrus.cdo.core +Import-Package: org.apache.log4j +Export-Package: org.polarsys.chess.smvExport.services diff --git a/plugins/org.polarsys.chess.smvExport/build.properties b/plugins/org.polarsys.chess.smvExport/build.properties new file mode 100644 index 0000000000000000000000000000000000000000..6f20375d6c7d98fbc80bb5da99be9866b1fe2f73 --- /dev/null +++ b/plugins/org.polarsys.chess.smvExport/build.properties @@ -0,0 +1,5 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml diff --git a/plugins/org.polarsys.chess.smvExport/plugin.xml b/plugins/org.polarsys.chess.smvExport/plugin.xml new file mode 100644 index 0000000000000000000000000000000000000000..8891cbcf1d9f5f613c6a37e678332f60f5348c41 --- /dev/null +++ b/plugins/org.polarsys.chess.smvExport/plugin.xml @@ -0,0 +1,41 @@ +<?xml version="1.0" encoding="UTF-8"?> +<?eclipse version="3.4"?> +<plugin> + <extension + point="org.eclipse.ui.commands"> + <command + defaultHandler="org.polarsys.chess.smvExport.commands.ExportNominalSMsToSmvFilesCommand" + id="org.polarsys.chess.smvExport.commands.ExportNominalSMsToSmvFilesCommand" + name="Export state machines as .smv files"> + </command> + <command + defaultHandler="org.polarsys.chess.smvExport.commands.ExportSelectedNominalSMsToSmvFilesCommand" + id="org.polarsys.chess.smvExport.commands.ExportSelectedNominalSMsToSmvFilesCommand" + name="Export state machines of Selected Component as .smv files"> + </command> + </extension> + <extension + point="org.eclipse.ui.menus"> + <menuContribution + allPopups="false" + locationURI="menu:org.eclipse.ui.main.menu.CHESS.basicOperation"> + <command + commandId="org.polarsys.chess.smvExport.commands.ExportNominalSMsToSmvFilesCommand" + style="push"> + </command> + </menuContribution> + <menuContribution + allPopups="false" + locationURI="popup:org.polarsys.chess.modelexplorerpopupmenu.id"> + <menu + id="org.eclipse.ui.main.diagramEditorMenu.CHESS.basicOperations" + label="Basic Operations"> + <command + commandId="org.polarsys.chess.smvExport.commands.ExportSelectedNominalSMsToSmvFilesCommand" + style="push"> + </command> + </menu> + </menuContribution> + </extension> + +</plugin> diff --git a/plugins/org.polarsys.chess.smvExport/src/org/polarsys/chess/smvExport/commands/ExportNominalSMsToSmvFilesCommand.java b/plugins/org.polarsys.chess.smvExport/src/org/polarsys/chess/smvExport/commands/ExportNominalSMsToSmvFilesCommand.java new file mode 100644 index 0000000000000000000000000000000000000000..b1331f458fff98ee41e69f6897555bb05520606f --- /dev/null +++ b/plugins/org.polarsys.chess.smvExport/src/org/polarsys/chess/smvExport/commands/ExportNominalSMsToSmvFilesCommand.java @@ -0,0 +1,48 @@ +/******************************************************************************* + * Copyright (C) 2017 Fondazione Bruno Kessler. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alberto Debiasi - initial API and implementation + ******************************************************************************/ +package org.polarsys.chess.smvExport.commands; + +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.papyrus.uml.tools.model.UmlModel; +import org.eclipse.papyrus.uml.tools.model.UmlUtils; +import org.polarsys.chess.service.utils.DialogUtils; +import org.polarsys.chess.smvExport.services.SmvExportService; +import eu.fbk.eclipse.standardtools.commands.AbstractJobCommand; + +public class ExportNominalSMsToSmvFilesCommand extends AbstractJobCommand { + + private DialogUtils exportDialogUtils = DialogUtils.getInstance(); + private SmvExportService smvExportService = SmvExportService.getInstance(); + + public ExportNominalSMsToSmvFilesCommand() { + super("Export Nominal State Machines To .smv Files"); + } + + private String outputDirectoryName; + private boolean showPopups; + private UmlModel umlModel; + + @Override + public void execPreJobOperations(ExecutionEvent event, IProgressMonitor monitor) throws Exception { + + outputDirectoryName = exportDialogUtils.getDirectoryNameFromDialog(); + showPopups = true; + umlModel = UmlUtils.getUmlModel(); + } + + @Override + public void execJobCommand(ExecutionEvent event, IProgressMonitor monitor) throws Exception { + smvExportService.exportAllNominalStateMachinesOfTheModel(umlModel, outputDirectoryName, showPopups, monitor); + + } + +} diff --git a/plugins/org.polarsys.chess.smvExport/src/org/polarsys/chess/smvExport/commands/ExportSelectedNominalSMsToSmvFilesCommand.java b/plugins/org.polarsys.chess.smvExport/src/org/polarsys/chess/smvExport/commands/ExportSelectedNominalSMsToSmvFilesCommand.java new file mode 100644 index 0000000000000000000000000000000000000000..85697b492d8a0173963e8ae7d67ccfab5b267418 --- /dev/null +++ b/plugins/org.polarsys.chess.smvExport/src/org/polarsys/chess/smvExport/commands/ExportSelectedNominalSMsToSmvFilesCommand.java @@ -0,0 +1,49 @@ +/******************************************************************************* + * Copyright (C) 2017 Fondazione Bruno Kessler. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alberto Debiasi - initial API and implementation + ******************************************************************************/ +package org.polarsys.chess.smvExport.commands; + +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.runtime.IProgressMonitor; +import org.polarsys.chess.service.utils.DialogUtils; +import org.polarsys.chess.service.utils.SelectionUtil; +import org.polarsys.chess.smvExport.services.SmvExportService; +import eu.fbk.eclipse.standardtools.commands.AbstractJobCommand; +import org.eclipse.uml2.uml.Class; + +public class ExportSelectedNominalSMsToSmvFilesCommand extends AbstractJobCommand { + + private SelectionUtil selectionUtil = SelectionUtil.getInstance(); + private DialogUtils dialogUtils = DialogUtils.getInstance(); + private SmvExportService smvExportService = SmvExportService.getInstance(); + + public ExportSelectedNominalSMsToSmvFilesCommand() { + super("Export Nominal State Machines To .smv Files"); + } + + private Class umlSelectedComponent; + private String outputDirectoryName; + private boolean showPopups; + + @Override + public void execPreJobOperations(ExecutionEvent event, IProgressMonitor monitor) throws Exception { + + umlSelectedComponent = selectionUtil.getUmlComponentFromSelectedObject(event); + outputDirectoryName = dialogUtils.getDirectoryNameFromDialog(); + showPopups = true; + + } + + @Override + public void execJobCommand(ExecutionEvent event, IProgressMonitor monitor) throws Exception { + smvExportService.exportNominalStateMachines(umlSelectedComponent, outputDirectoryName, showPopups, monitor); + } + +} diff --git a/plugins/org.polarsys.chess.smvExport/src/org/polarsys/chess/smvExport/model/UMLStateMachineModel.java b/plugins/org.polarsys.chess.smvExport/src/org/polarsys/chess/smvExport/model/UMLStateMachineModel.java new file mode 100644 index 0000000000000000000000000000000000000000..15b9869e0a6d662f4bab6b0ba18ac0bfd4732806 --- /dev/null +++ b/plugins/org.polarsys.chess.smvExport/src/org/polarsys/chess/smvExport/model/UMLStateMachineModel.java @@ -0,0 +1,215 @@ +/******************************************************************************* + * Copyright (C) 2017 Fondazione Bruno Kessler. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alberto Debiasi - initial API and implementation + ******************************************************************************/ +package org.polarsys.chess.smvExport.model; + +import java.util.Set; + +import org.eclipse.emf.common.util.BasicEList; +import org.eclipse.emf.common.util.EList; +import org.eclipse.papyrus.sysml.portandflows.FlowDirection; +import org.eclipse.papyrus.uml.tools.model.UmlModel; +import org.eclipse.uml2.uml.Constraint; +import org.eclipse.uml2.uml.Element; +import org.eclipse.uml2.uml.Port; +import org.eclipse.uml2.uml.Property; +import org.eclipse.uml2.uml.StateMachine; +import org.eclipse.uml2.uml.Transition; +import org.eclipse.uml2.uml.Type; +import org.eclipse.uml2.uml.Vertex; +import org.polarsys.chess.contracts.profile.chesscontract.util.EntityUtil; + +import eu.fbk.eclipse.standardtools.StateMachineTranslatorToSmv.stateMachineModel.AbstractStateMachineModel; + +public class UMLStateMachineModel implements AbstractStateMachineModel { + + private static UMLStateMachineModel umlStateMachineModel; + private EntityUtil entityUtil = EntityUtil.getInstance(); + + public static UMLStateMachineModel getInstance() { + if (umlStateMachineModel == null) { + umlStateMachineModel = new UMLStateMachineModel(); + } + return umlStateMachineModel; + } + + @Override + public EList<Port> getOwnerInputPortsExceptEvents(Object stateMachine) { + Element owner = ((StateMachine) stateMachine).getOwner(); + return new BasicEList<Port>(entityUtil.getUmlPortsExceptEvents(owner, FlowDirection.IN_VALUE)); + } + + @Override + public EList<Port> getOwnerOutputPortsExceptEvents(Object stateMachine) { + Element owner = ((StateMachine) stateMachine).getOwner(); + return new BasicEList<Port>(entityUtil.getUmlPortsExceptEvents(owner, FlowDirection.OUT_VALUE)); + } + + @Override + public EList<Element> getOwnerAttributes(Object stateMachine) { + Element owner = ((StateMachine) stateMachine).getOwner(); + return new BasicEList<Element>(entityUtil.getAttributesExceptPorts(owner)); + } + + @Override + public EList<String> getTransitionsNameList(Object stateMachine) throws Exception { + return entityUtil.getTransitionNameList(entityUtil.getTranstitions((StateMachine) stateMachine)); + } + + @Override + public EList<String> getEventsNameList(Object stateMachine) { + EList<Port> events = entityUtil.getEventPorts(((StateMachine) stateMachine).getOwner()); + + return (entityUtil.getPortsName(events)); + } + + @Override + public String getStateMachineName(Object stateMachine) { + return (entityUtil.getStateMachineName((StateMachine) stateMachine)); + } + + @Override + public EList<Transition> getStartTransitions(Object stateMachine) throws Exception { + return entityUtil.getInitialTransitions((StateMachine) stateMachine); + } + + @Override + public EList<Transition> getNonStartTransitions(Object stateMachine) { + return entityUtil.getNonInitialTransitions((StateMachine) stateMachine); + } + + @Override + public EList<String> getIntermediateStatesNameList(Object stateMachine) { + EList<Vertex> states = entityUtil.getIntermediateStates((StateMachine) stateMachine); + return entityUtil.getStatesNameList(states); + } + + @Override + public String getTransitionName(Object transition) { + return entityUtil.getTransitionName((Transition) transition); + } + + @Override + public String getTransitionNextStateName(Object transition) { + Vertex nextState = entityUtil.getTransitionNextState((Transition) transition); + return entityUtil.getStateName(nextState); + } + + @Override + public String getTransitionStartStateName(Object transition) { + Vertex sourceState = entityUtil.getTransitionSourceState((Transition) transition); + return entityUtil.getStateName(sourceState); + } + + @Override + public EList<String> getTransitionEventsName(Object transition) { + EList<Port> events = entityUtil.getTransitionEvents((Transition) transition); + if (events != null) { + return entityUtil.getPortsName(events); + } + return null; + } + + @Override + public String getTransitionGuardCondition(Object transition) { + Constraint condition = entityUtil.getTransitionGuard((Transition) transition); + if (condition != null) { + return entityUtil.getConditionExpression(condition); + } + return null; + } + + @Override + public boolean isFinalTransition(Object transition) { + return entityUtil.isFinalTransition((Transition) transition); + + } + + @Override + public boolean isTransitionWithNoEvent(Object transition) { + return entityUtil.isTransitionWithNoEvent((Transition) transition); + } + + @Override + public String getVariableName(Object variable) { + return ((Property) variable).getName(); + } + + @Override + public Object getVariableType(Object variable) { + return entityUtil.getUmlType((Property) variable); + } + + @Override + public boolean isBooleanType(Object type) { + return entityUtil.isBooleanType((Type) type); + } + + @Override + public boolean isIntegerType(Object type) { + return entityUtil.isIntegerType((Type) type); + } + + @Override + public boolean isRealType(Object type) { + return entityUtil.isRealType((Type) type); + } + + @Override + public boolean isIntervalType(Object type) { + return entityUtil.isRangeType((Type) type); + } + + @Override + public String[] getLowHighIntervalType(Object type) { + return entityUtil.getLowerUpperBoundsForRangeType((Type) type); + } + + @Override + public EList<String> getEnumValues(Object type) { + return new BasicEList<String>(entityUtil.getListValuesForEnumeratorType((Type) type)); + } + + @Override + public boolean isEnumType(Object type) { + return entityUtil.isEnumerationType((Type) type); + } + + @Override + public String getStateMachineOwnerName(Object stateMachine) { + return ((org.eclipse.uml2.uml.Class) entityUtil.getOwner((StateMachine) stateMachine)).getName(); + } + + @Override + public String getTransitionEffectText(Object transition) { + return entityUtil.getTransitionEffectText((Transition) transition); + } + + @Override + public Set<StateMachine> getNominalStateMachinesIncludingFromSubComponents(Object umlSelectedComponent) { + return entityUtil.getNominalStateMachines((org.eclipse.uml2.uml.Class) umlSelectedComponent, true); + } + + @Override + public Set<StateMachine> getAllStateMachinesFromModel(Object model) { + return entityUtil.getNominalStateMachines((UmlModel) model); + } + + @Override + public Object getFirstNominalStateMachine(Object umlSelectedComponent) { + return entityUtil.getFirstNominalStateMachine((org.eclipse.uml2.uml.Class) umlSelectedComponent); + } + + @Override + public Object getStateMachineOwner(Object stateMachine) { + return entityUtil.getOwner((StateMachine) stateMachine); + + } +} diff --git a/plugins/org.polarsys.chess.smvExport/src/org/polarsys/chess/smvExport/services/SmvExportService.java b/plugins/org.polarsys.chess.smvExport/src/org/polarsys/chess/smvExport/services/SmvExportService.java new file mode 100644 index 0000000000000000000000000000000000000000..2af1d7690a79061a09eac33360b23308b83bffae --- /dev/null +++ b/plugins/org.polarsys.chess.smvExport/src/org/polarsys/chess/smvExport/services/SmvExportService.java @@ -0,0 +1,97 @@ +/******************************************************************************* + * Copyright (C) 2017 Fondazione Bruno Kessler. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alberto Debiasi - initial API and implementation + ******************************************************************************/ +package org.polarsys.chess.smvExport.services; + +import java.io.File; +import java.util.HashMap; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.emf.common.util.EList; +import org.eclipse.papyrus.uml.tools.model.UmlModel; +import org.eclipse.uml2.uml.Class; +import org.eclipse.uml2.uml.Property; +import org.polarsys.chess.service.internal.model.ChessSystemModel; +import org.polarsys.chess.smvExport.model.UMLStateMachineModel; +import eu.fbk.eclipse.standardtools.StateMachineTranslatorToSmv.services.SMVTranslatorService; +import eu.fbk.eclipse.standardtools.utils.DialogUtil; + +public class SmvExportService { + + private static SmvExportService instance; +private ChessSystemModel chessSystemModel = ChessSystemModel.getInstance(); + + private SMVTranslatorService smvTranslatorService = SMVTranslatorService.getInstance(chessSystemModel, + UMLStateMachineModel.getInstance()); + private DialogUtil dialogUtil = DialogUtil.getInstance(); + + public static SmvExportService getInstance() { + if (instance == null) { + instance = new SmvExportService(); + } + return instance; + } + + public void exportAllNominalStateMachinesOfTheModel(UmlModel umlModel, String selectedDirectory, boolean showPopups, + IProgressMonitor monitor) throws Exception { + + System.out.println("umlModel: " + umlModel); + smvTranslatorService.exportAllNominalStateMachinesOfTheModel(umlModel, selectedDirectory, null, monitor); + + if (showPopups) { + dialogUtil.showMessage_ExportNominalStateMachinesDone(selectedDirectory); + } + + } + + public void exportNominalStateMachines(Class umlSelectedComponent, String selectedDirectory, boolean showPopups, + IProgressMonitor monitor) throws Exception { + + smvTranslatorService.exportNominalStateMachines(umlSelectedComponent, selectedDirectory, null, monitor); + + if (showPopups) { + dialogUtil.showMessage_ExportNominalStateMachinesDone(selectedDirectory); + } + + } + + public String exportSingleSmv(Class umlSelectedComponent, boolean showPopups, String selectedDirectory, + IProgressMonitor monitor) throws Exception { + + File smvFile = smvTranslatorService.exportSingleSmv(umlSelectedComponent, showPopups, selectedDirectory, + monitor); + + if (showPopups) { + dialogUtil.showMessage_ExportBehaviourDone(smvFile.getAbsolutePath()); + } + + return smvFile.getPath(); + + } + + public HashMap<String, String> exportSmv(Class umlSelectedComponent, boolean showPopups, String selectedDirectory, + IProgressMonitor monitor) throws Exception { + + HashMap<String, String> mapSmvFile_ComponentName = smvTranslatorService.exportSmv(umlSelectedComponent, + selectedDirectory, monitor); + + if (showPopups) { + dialogUtil.showMessage_ExportBehaviourDone(selectedDirectory); + } + + return mapSmvFile_ComponentName; + + } + + public boolean isLeafComponent(Class umlSelectedComponent){ + EList<Property> subComponents = chessSystemModel.getSubComponentsInstances(umlSelectedComponent); + return ((subComponents==null)||(subComponents.size()==0)); + } + +}