Skip to content

Commit

Permalink
Add Simulator perspective and add simulator to the build
Browse files Browse the repository at this point in the history
  • Loading branch information
mbats committed Jun 16, 2015
1 parent 6a5c619 commit bc86d79
Show file tree
Hide file tree
Showing 14 changed files with 412 additions and 15 deletions.
14 changes: 14 additions & 0 deletions packaging/fr.obeo.dsl.arduino.runtime.feature/feature.xml
Original file line number Diff line number Diff line change
Expand Up @@ -288,4 +288,18 @@ litigation.
version="0.0.0"
unpack="false"/>

<plugin
id="fr.obeo.dsl.arduino.simulator"
download-size="0"
install-size="0"
version="0.0.0"
unpack="false"/>

<plugin
id="fr.obeo.dsl.arduino.simulator.design"
download-size="0"
install-size="0"
version="0.0.0"
unpack="false"/>

</feature>
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public void preWindowOpen() {
configurer.setShowCoolBar(true);
configurer.setShowStatusLine(false);
configurer.setTitle("Arduino Designer"); //$NON-NLS-1$
configurer.setShowPerspectiveBar(true);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -305,9 +305,8 @@
</customization>
</defaultLayer>
</ownedRepresentations>

<ownedRepresentations xsi:type="description_1:DiagramDescription" name="Sketch" titleExpression="Sketch" initialisation="true" domainClass="arduino.Sketch" enablePopupBars="true">
<metamodel href="../../fr.obeo.dsl.arduino/model/arduino.ecore#/"/>
<metamodel href="viewpoint:/../fr.obeo.dsl.arduino/model/arduino.ecore#/"/>
<defaultLayer name="Default">
<nodeMappings name="SK_Loop" semanticCandidatesExpression="var:self" domainClass="arduino.Sketch">
<style xsi:type="style:WorkspaceImageDescription" labelFormat="italic" showIcon="false" labelExpression="Loop" hideLabelByDefault="true" workspacePath="/fr.obeo.dsl.arduino.design/images/loop.svg">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: fr.obeo.dsl.arduino.simulator.design
Bundle-SymbolicName: fr.obeo.dsl.arduino.simulator.design;singleton:=true
Bundle-Version: 1.0.0
Bundle-Version: 1.0.0.qualifier
Bundle-Activator: fr.obeo.dsl.arduino.simulator.design.Activator
Require-Bundle: org.eclipse.ui,
org.eclipse.core.runtime,
Expand All @@ -20,7 +20,8 @@ Require-Bundle: org.eclipse.ui,
org.eclipse.debug.ui;bundle-version="3.10.1",
fr.obeo.dsl.arduino;bundle-version="1.0.0",
fr.obeo.dsl.arduino.edit;bundle-version="1.0.0",
org.eclipse.emf.transaction
org.eclipse.emf.transaction,
org.eclipse.sirius.ui
Bundle-ActivationPolicy: lazy
Bundle-RequiredExecutionEnvironment: J2SE-1.5
Export-Package: fr.obeo.dsl.arduino.simulator.design,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<description:Group xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:description="http://www.eclipse.org/sirius/description/1.1.0" xmlns:description_1="http://www.eclipse.org/sirius/diagram/description/1.1.0" xmlns:tool="http://www.eclipse.org/sirius/description/tool/1.1.0" name="simulator" version="8.1.0">
<ownedViewpoints name="ArduinoSimulator" modelFileExtension="arduino">
<ownedRepresentationExtensions xsi:type="description_1:DiagramExtensionDescription" name="HardwareSimulator" viewpointURI="viewpoint:/fr.obeo.dsl.arduino.design/Arduino" representationName="Hardware">
<layers name="Simulator">
<layers name="Simulator" activeByDefault="true">
<toolSections name="Simulator">
<ownedTools xsi:type="tool:PopupMenu" name="Simulator">
<menuItemDescription xsi:type="tool:OperationAction" name="Debug">
Expand All @@ -23,7 +23,7 @@
</layers>
</ownedRepresentationExtensions>
<ownedRepresentationExtensions xsi:type="description_1:DiagramExtensionDescription" name="SketchSimulator" viewpointURI="viewpoint:/fr.obeo.dsl.arduino.design/Arduino" representationName="Sketch">
<layers name="Simulator">
<layers name="Simulator" activeByDefault="true">
<toolSections name="Simulator">
<ownedTools xsi:type="tool:PopupMenu" name="Simulator">
<menuItemDescription xsi:type="tool:OperationAction" name="Debug">
Expand Down Expand Up @@ -115,13 +115,13 @@
<customization>
<vsmElementCustomizations xsi:type="description:VSMElementCustomization" predicateExpression="service:self.isCurrentInstruction">
<featureCustomizations xsi:type="description:EReferenceCustomization" applyOnAll="true" referenceName="borderColor" value="//@userColorsPalettes[name='Arduino%20Palette']/@entries[name='current%20instruction']"/>
<featureCustomizations xsi:type="description:EAttributeCustomization" applyOnAll="true" attributeName="borderSizeComputationExpression" value="1"/>
<featureCustomizations xsi:type="description:EAttributeCustomization" applyOnAll="true" attributeName="borderSizeComputationExpression" value="2"/>
</vsmElementCustomizations>
</customization>
</layers>
</ownedRepresentationExtensions>
<ownedRepresentationExtensions xsi:type="description_1:DiagramExtensionDescription" name="FunctionSimulator" viewpointURI="viewpoint:/fr.obeo.dsl.arduino.design/Arduino" representationName="Function">
<layers name="Simulator">
<layers name="Simulator" activeByDefault="true">
<toolSections name="Simulator">
<ownedTools xsi:type="tool:PopupMenu" name="Simulator">
<menuItemDescription xsi:type="tool:OperationAction" name="Debug">
Expand Down Expand Up @@ -221,7 +221,7 @@
<ownedJavaExtensions qualifiedClassName="fr.obeo.dsl.arduino.simulator.design.services.SimulatorServices"/>
</ownedViewpoints>
<userColorsPalettes name="Arduino Palette">
<entries xsi:type="description:UserFixedColor" red="0" green="255" blue="64" name="current instruction"/>
<entries xsi:type="description:UserFixedColor" red="255" green="0" blue="0" name="current instruction"/>
<entries xsi:type="description:InterpolatedColor" name="level intencity" colorValueComputationExpression="[self.getLevel()/]">
<colorSteps associatedValue="0">
<associatedColor href="environment:/viewpoint#//@systemColors/@entries[name='black']"/>
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
45 changes: 44 additions & 1 deletion plugins/fr.obeo.dsl.arduino.simulator.design/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
type="fr.obeo.dsl.arduino.simulator.design.launchConfiguration">
<launchMode
mode="debug"
perspective="org.eclipse.debug.ui.DebugPerspective">
perspective="fr.obeo.dsl.arduino.debug.perspective">
</launchMode>
</launchConfigurationTabGroup>
</extension>
Expand Down Expand Up @@ -88,4 +88,47 @@
id="fr.obeo.dsl.arduino.simulator.design.action.ToggleBreakpointAction">
</javaActions>
</extension>
<extension
point="org.eclipse.ui.menus">
<menuContribution
allPopups="false"
locationURI="toolbar:org.eclipse.ui.main.toolbar?before=additions">
<toolbar
id="fr.obeo.dsl.arduino.debug.menus.toolbar">
<command
commandId="fr.obeo.dsl.arduino.simulator.design.debug"
helpContextId="Launch Debug"
icon="icons/simulator.png"
label="Debug"
style="push">
</command>
</toolbar>
</menuContribution>
</extension>
<extension
point="org.eclipse.ui.commands">
<command
id="fr.obeo.dsl.arduino.simulator.design.debug"
name="Debug">
</command>
</extension>
<extension
point="org.eclipse.ui.handlers">
<handler
class="fr.obeo.dsl.arduino.simulator.design.DebugHandler"
commandId="fr.obeo.dsl.arduino.simulator.design.debug">
<enabledWhen>
<with
variable="activeContexts">
<iterate
ifEmpty="true"
operator="and">
<test
property="fr.obeo.dsl.arduino.properties.validSketch">
</test>
</iterate>
</with>
</enabledWhen>
</handler>
</extension>
</plugin>
Original file line number Diff line number Diff line change
@@ -0,0 +1,236 @@
package fr.obeo.dsl.arduino.simulator.design;

import java.util.ArrayList;
import java.util.List;

import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Path;
import org.eclipse.debug.core.DebugPlugin;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.ILaunchConfigurationType;
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
import org.eclipse.debug.core.ILaunchManager;
import org.eclipse.debug.ui.DebugUITools;
import org.eclipse.debug.ui.ILaunchGroup;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.emf.transaction.RecordingCommand;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.sirius.business.api.componentization.ViewpointRegistry;
import org.eclipse.sirius.business.api.session.Session;
import org.eclipse.sirius.business.api.session.SessionManager;
import org.eclipse.sirius.ui.business.api.viewpoint.ViewpointSelectionCallback;
import org.eclipse.sirius.viewpoint.description.Viewpoint;
import org.eclipse.ui.PlatformUI;

import fr.obeo.dsl.arduino.Project;
import fr.obeo.dsl.arduino.design.ArduinoDesignerUtils;
import fr.obeo.dsl.arduino.simulator.design.launcher.LauncherDelegate;
import fr.obeo.dsl.debug.ide.Activator;
import fr.obeo.dsl.debug.ide.launch.AbstractDSLLaunchConfigurationDelegate;

public class DebugHandler extends AbstractHandler {

public Object execute(ExecutionEvent event) throws ExecutionException {
Project firstInstruction = ArduinoDesignerUtils.getOpenedProject();

// Activate Simulator viewpoint
enableSimulatorViewpoint(SessionManager.INSTANCE
.getSession(firstInstruction));
IFile file = getArduinoModel(firstInstruction);

if (file != null) {
// try to save dirty editors
PlatformUI.getWorkbench().getActiveWorkbenchWindow()
.getActivePage().saveAllEditors(true);

try {
ILaunchConfiguration[] configurations = getLaunchConfigurations(file);
String mode = "debug";
if (configurations.length == 0) {
// try to create a launch configuration
configurations = createLaunchConfiguration(file,
firstInstruction, mode);
}

// launch
if (configurations.length == 1) {
configurations[0].launch(mode, new NullProgressMonitor());
} else {
// more than one configuration applies
// open launch dialog for selection
final ILaunchGroup group = DebugUITools.getLaunchGroup(
configurations[0], mode);
DebugUITools.openLaunchConfigurationDialogOnGroup(
PlatformUI.getWorkbench()
.getActiveWorkbenchWindow().getShell(),
new StructuredSelection(configurations[0]),
group.getIdentifier(), null);
}

} catch (CoreException e) {
Activator.getDefault().error(e);
}
}

return null;
}

private static void enableSimulatorViewpoint(final Session session) {
if (session != null) {
session.getTransactionalEditingDomain()
.getCommandStack()
.execute(
new RecordingCommand(session
.getTransactionalEditingDomain()) {
@Override
protected void doExecute() {
ViewpointSelectionCallback callback = new ViewpointSelectionCallback();

for (Viewpoint vp : ViewpointRegistry
.getInstance().getViewpoints()) {
if ("ArduinoSimulator".equals(vp
.getName()))
callback.selectViewpoint(vp,
session,
new NullProgressMonitor());
}
}
});
}
}

private IFile getArduinoModel(Project firstInstruction) {
Resource resource = firstInstruction.eResource();
if (resource != null) {
URI uri = resource.getURI();
uri = resource.getResourceSet().getURIConverter().normalize(uri);
String scheme = uri.scheme();
if ("platform".equals(scheme) && uri.segmentCount() > 1
&& "resource".equals(uri.segment(0))) {
StringBuffer platformResourcePath = new StringBuffer();
for (int j = 1, size = uri.segmentCount(); j < size; ++j) {
platformResourcePath.append('/');
platformResourcePath.append(uri.segment(j));
}
return ResourcesPlugin.getWorkspace().getRoot()
.getFile(new Path(platformResourcePath.toString()));
}
}
return null;
}

/**
* Creates a {@link ILaunchConfiguration}. If the
* <code>firstInstruction</code> is <code>null</code> the launch
* configuration dialog is opened.
*
* @param file
* the selected model {@link IFile}
* @param firstInstruction
* the first {@link EObject instruction} or <code>null</code> for
* interactive selection
* @param mode
* the {@link ILaunchConfiguration#getModes() mode}
* @return an array of possible {@link ILaunchConfiguration}, can be empty
* but not <code>null</code>
* @throws CoreException
* if {@link ILaunchConfiguration} initialization fails of
* models can't be loaded
*/
protected ILaunchConfiguration[] createLaunchConfiguration(
final IResource file, EObject firstInstruction, final String mode)
throws CoreException {
final ILaunchConfiguration[] res;

ILaunchManager manager = DebugPlugin.getDefault().getLaunchManager();
ILaunchConfigurationType type = manager
.getLaunchConfigurationType(getLaunchConfigurationTypeID());

ILaunchConfigurationWorkingCopy configuration = type.newInstance(null,
file.getName());
configuration.setMappedResources(new IResource[] { file, });
configuration.setAttribute(
AbstractDSLLaunchConfigurationDelegate.RESOURCE_URI, file
.getFullPath().toString());
if (firstInstruction == null) {
// open configuration for further editing
final ILaunchGroup group = DebugUITools.getLaunchGroup(
configuration, mode);
if (group != null) {
configuration.doSave();
DebugUITools.openLaunchConfigurationDialog(PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getShell(),
configuration, group.getIdentifier(), null);
}
res = new ILaunchConfiguration[] {};
} else {
configuration
.setAttribute(
AbstractDSLLaunchConfigurationDelegate.FIRST_INSTRUCTION_URI,
EcoreUtil.getURI(firstInstruction).toString());
// save and return new configuration
configuration.doSave();
res = new ILaunchConfiguration[] { configuration, };
}
return res;
}

private String getLaunchConfigurationTypeID() {
return LauncherDelegate.TYPE_ID;
}

/**
* Get all {@link ILaunchConfiguration} that target the given
* {@link IResource}.
*
* @param resource
* root file to execute
* @return {@link ILaunchConfiguration}s using resource
*/
protected ILaunchConfiguration[] getLaunchConfigurations(IResource resource) {
final List<ILaunchConfiguration> configurations = new ArrayList<ILaunchConfiguration>();

final ILaunchManager manager = DebugPlugin.getDefault()
.getLaunchManager();
final ILaunchConfigurationType type = manager
.getLaunchConfigurationType(getLaunchConfigurationTypeID());

// try to find existing configurations using the same file
try {
for (ILaunchConfiguration configuration : manager
.getLaunchConfigurations(type)) {
if (configuration
.hasAttribute(AbstractDSLLaunchConfigurationDelegate.RESOURCE_URI)) {
final String pathString = configuration
.getAttribute(
AbstractDSLLaunchConfigurationDelegate.RESOURCE_URI,
"");
try {
IFile file = ResourcesPlugin.getWorkspace().getRoot()
.getFile(new Path(pathString));
if (resource != null && resource.equals(file)) {
configurations.add(configuration);
}
} catch (IllegalArgumentException e) {
}
}
}
} catch (CoreException e) {
// could not load configurations, ignore
e.toString();
}

return configurations.toArray(new ILaunchConfiguration[configurations
.size()]);
}
}
Loading

0 comments on commit bc86d79

Please sign in to comment.