Skip to content
Snippets Groups Projects
Commit 7f52072b authored by Alberto Debiasi's avatar Alberto Debiasi
Browse files

- added smvExport Plugin

Change-Id: Iabf4f632af6cb46eba4824ccb280c0f2183eda95
parent 8120c2c2
No related branches found
No related tags found
No related merge requests found
Showing
with 566 additions and 0 deletions
<?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>
/bin/
<?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>
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
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.polarsys.chess.diagram.ui,
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
source.. = src/
output.. = bin/
bin.includes = META-INF/,\
.,\
plugin.xml
<?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>
/*******************************************************************************
* 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 java.util.Collection;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.uml2.uml.StateMachine;
import org.polarsys.chess.diagram.ui.utils.ExportDialogUtils;
import org.polarsys.chess.smvExport.services.SmvExportService;
import eu.fbk.eclipse.standardtools.commands.AbstractJobCommand;
public class ExportNominalSMsToSmvFilesCommand extends AbstractJobCommand {
//private SelectionUtil selectionUtil = SelectionUtil.getInstance();
private ExportDialogUtils exportDialogUtils = ExportDialogUtils.getInstance();
//private DirectoryUtil directoryUtils = DirectoryUtil.getInstance();
private SmvExportService smvExportService = SmvExportService.getInstance();
public ExportNominalSMsToSmvFilesCommand() {
super("Export Nominal State Machines To .smv Files");
}
//private Class umlSelectedComponent;
private String outputDirectoryName;
private boolean showPopups;
//private String currentProjectName;
private Collection<StateMachine> stateMachines;
@Override
public void execGUIOperations(ExecutionEvent event, IProgressMonitor monitor) throws Exception {
//umlSelectedComponent = selectionUtil.getUmlComponentFromSelectedObject(event);
outputDirectoryName = exportDialogUtils.getDirectoryNameFromDialog();
//currentProjectName = directoryUtils.getCurrentProjectName();
showPopups = true;
stateMachines = smvExportService.getNominalStateMachines();
}
@Override
public void execJobCommand(ExecutionEvent event, IProgressMonitor monitor) throws Exception {
smvExportService.exportNominalStateMachines(stateMachines,outputDirectoryName,showPopups,monitor);
}
}
/*******************************************************************************
* 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 java.util.Collection;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.uml2.uml.StateMachine;
import org.polarsys.chess.diagram.ui.utils.ExportDialogUtils;
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 ExportDialogUtils exportDialogUtils = ExportDialogUtils.getInstance();
//private DirectoryUtil directoryUtils = DirectoryUtil.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;
//private String currentProjectName;
private Collection<StateMachine> stateMachines;
@Override
public void execGUIOperations(ExecutionEvent event, IProgressMonitor monitor) throws Exception {
umlSelectedComponent = selectionUtil.getUmlComponentFromSelectedObject(event);
outputDirectoryName = exportDialogUtils.getDirectoryNameFromDialog();
//currentProjectName = directoryUtils.getCurrentProjectName();
showPopups = true;
stateMachines = smvExportService.getNominalStateMachines(umlSelectedComponent);
}
@Override
public void execJobCommand(ExecutionEvent event, IProgressMonitor monitor) throws Exception {
smvExportService.exportNominalStateMachines(stateMachines,outputDirectoryName,showPopups,monitor);
}
}
/*******************************************************************************
* 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 org.eclipse.emf.common.util.BasicEList;
import org.eclipse.emf.common.util.EList;
import org.eclipse.papyrus.sysml.portandflows.FlowDirection;
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));
/*StateMachine sm = ((StateMachine) stateMachine);
Region region = sm.getRegions().get(0);
EList<Vertex> statesList = region.getSubvertices();
EList<String> stateNames = new BasicEList<String>();
for(Vertex state : statesList){
stateNames.add(state.getName());
}
return stateNames;*/
}
@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 getAssignedVariableText(Object variable, Object transition) throws Exception {
String assignedVariables = getTransitionEffectText((Transition)transition);
String variableName = getVariableName(variable);
return getAssignedVariableText(variableName,assignedVariables);
}*/
/*@Override
public boolean isVariableAssigned(Object variable, Object transition) throws Exception {
String assignedVariables = abstractStateMachineModel.getTransitionEffectText((Transition)transition);
String variableName = abstractStateMachineModel.getVariableName(variable);
return isVariableAssigned(variableName,assignedVariables);
}*/
@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);
}
}
/*******************************************************************************
* 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.Collection;
import java.util.Set;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.papyrus.uml.tools.model.UmlModel;
import org.eclipse.papyrus.uml.tools.model.UmlUtils;
import org.eclipse.uml2.uml.Class;
import org.eclipse.uml2.uml.StateMachine;
import org.polarsys.chess.contracts.profile.chesscontract.util.EntityUtil;
import org.polarsys.chess.smvExport.model.UMLStateMachineModel;
import eu.fbk.eclipse.standardtools.StateMachineTranslatorToSmv.services.SMVTranslatorService;
import eu.fbk.eclipse.standardtools.exceptions.NoComponentException;
import eu.fbk.eclipse.standardtools.utils.DialogUtil;
public class SmvExportService {
private static SmvExportService instance;
//private final Logger logger = Logger.getLogger(SmvExportService.class);
private EntityUtil entityUtil = EntityUtil.getInstance();
//private StateMachineModelToSmvModelTranslator smTranslator = StateMachineModelToSmvModelTranslator.getInstance(UMLStateMachineModel.getInstance());
private SMVTranslatorService smvTranslatorService = SMVTranslatorService.getInstance(UMLStateMachineModel.getInstance());
private DialogUtil dialogUtil = DialogUtil.getInstance();
public static SmvExportService getInstance(){
if(instance==null){
instance = new SmvExportService();
}
return instance;
}
public void exportNominalStateMachines(Collection<StateMachine> stateMachines, String selectedDirectory,boolean showPopups, IProgressMonitor monitor) throws Exception {
for(StateMachine stateMachine : stateMachines){
smvTranslatorService.exportStateMachineToSmvFile(stateMachine, selectedDirectory,null, monitor);
}
if(showPopups){
dialogUtil.showMessage_ExportNominalStateMachinesDone(selectedDirectory);
}
}
public File exportSmv(Class umlSelectedComponent,boolean showPopups, String selectedDirectory, IProgressMonitor monitor)
throws Exception {
if (umlSelectedComponent == null) {
throw new NoComponentException();
}
File smvFile = null;
StateMachine stateMachine = getNominalStateMachine(umlSelectedComponent);
if(stateMachine!=null){
smvFile = smvTranslatorService.exportStateMachineToSmvFile(stateMachine, selectedDirectory,getSmvFileName(umlSelectedComponent), monitor);
if(showPopups){
dialogUtil.showMessage_ExportBehaviourDone(smvFile.getAbsolutePath());
}
}else{
dialogUtil.showMessage_NoStateMachine();
}
return smvFile;
}
private StateMachine getNominalStateMachine(Class umlSelectedComponent) {
Set<StateMachine> stateMachines = entityUtil.getNominalStateMachines(umlSelectedComponent);
if((stateMachines!=null)&&(stateMachines.size()>0)){
return stateMachines.iterator().next();
}else return null;
}
private String getSmvFileName(Class umlSelectedComponent) {
// String systemQN = umlSelectedComponent.getQualifiedName();
// String systemName = systemQN.substring(systemQN.lastIndexOf("::") + 2);
// return umlSelectedComponent.getModel().getName() + "_" + systemName + ".smv";
return umlSelectedComponent.getName();
}
public Collection<StateMachine> getNominalStateMachines(Class umlSelectedComponent) {
Set<StateMachine> stateMachines = entityUtil.getNominalStateMachines(umlSelectedComponent);
System.out.println("stateMachines");
for (StateMachine sm : stateMachines) {
System.out.println(sm);
}
return stateMachines;
}
public Collection<StateMachine> getNominalStateMachines() {
UmlModel umlModel = UmlUtils.getUmlModel();
Set<StateMachine> stateMachines = entityUtil.getNominalStateMachines(umlModel);
System.out.println("stateMachines");
for (StateMachine sm : stateMachines) {
System.out.println(sm);
}
return stateMachines;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment