diff options
Diffstat (limited to 'Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.ui/src')
2 files changed, 0 insertions, 172 deletions
diff --git a/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.ui/src/hu/bme/mit/inf/dslreasoner/faulttree/ui/Activator.java b/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.ui/src/hu/bme/mit/inf/dslreasoner/faulttree/ui/Activator.java deleted file mode 100644 index 4363fc63..00000000 --- a/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.ui/src/hu/bme/mit/inf/dslreasoner/faulttree/ui/Activator.java +++ /dev/null | |||
@@ -1,44 +0,0 @@ | |||
1 | package hu.bme.mit.inf.dslreasoner.faulttree.ui; | ||
2 | |||
3 | import org.eclipse.ui.plugin.AbstractUIPlugin; | ||
4 | import org.osgi.framework.BundleContext; | ||
5 | |||
6 | /** | ||
7 | * The activator class controls the plug-in life cycle | ||
8 | */ | ||
9 | public class Activator extends AbstractUIPlugin { | ||
10 | |||
11 | // The plug-in ID | ||
12 | public static final String PLUGIN_ID = "hu.bme.mit.inf.dslreasoner.faulttree.ui"; //$NON-NLS-1$ | ||
13 | |||
14 | // The shared instance | ||
15 | private static Activator plugin; | ||
16 | |||
17 | /** | ||
18 | * The constructor | ||
19 | */ | ||
20 | public Activator() { | ||
21 | } | ||
22 | |||
23 | @Override | ||
24 | public void start(BundleContext context) throws Exception { | ||
25 | super.start(context); | ||
26 | plugin = this; | ||
27 | } | ||
28 | |||
29 | @Override | ||
30 | public void stop(BundleContext context) throws Exception { | ||
31 | plugin = null; | ||
32 | super.stop(context); | ||
33 | } | ||
34 | |||
35 | /** | ||
36 | * Returns the shared instance | ||
37 | * | ||
38 | * @return the shared instance | ||
39 | */ | ||
40 | public static Activator getDefault() { | ||
41 | return plugin; | ||
42 | } | ||
43 | |||
44 | } | ||
diff --git a/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.ui/src/hu/bme/mit/inf/dslreasoner/faulttree/ui/handler/ReliabilityAnalysisHandler.xtend b/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.ui/src/hu/bme/mit/inf/dslreasoner/faulttree/ui/handler/ReliabilityAnalysisHandler.xtend deleted file mode 100644 index 5fa89148..00000000 --- a/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.ui/src/hu/bme/mit/inf/dslreasoner/faulttree/ui/handler/ReliabilityAnalysisHandler.xtend +++ /dev/null | |||
@@ -1,128 +0,0 @@ | |||
1 | package hu.bme.mit.inf.dslreasoner.faulttree.ui.handler | ||
2 | |||
3 | import hu.bme.mit.inf.dslreasoner.application.execution.EclipseBasedProgressMonitor | ||
4 | import hu.bme.mit.inf.dslreasoner.faulttree.components.cftLanguage.CftModel | ||
5 | import hu.bme.mit.inf.dslreasoner.faulttree.components.cftLanguage.TransformationDefinition | ||
6 | import hu.bme.mit.inf.dslreasoner.faulttree.transformation.cft2ft.Cft2FtTransformation | ||
7 | import hu.bme.mit.inf.dslreasoner.faulttree.transformation.ecore2cft.Ecore2CftTransformation | ||
8 | import hu.bme.mit.inf.dslreasoner.faulttree.transformation.solver.FtAnalysisObjective | ||
9 | import hu.bme.mit.inf.dslreasoner.faulttree.transformation.solver.ReliabilityResult | ||
10 | import hu.bme.mit.inf.dslreasoner.faulttree.transformation.solver.StormDftConfiguration | ||
11 | import hu.bme.mit.inf.dslreasoner.faulttree.transformation.solver.StormDftSolver | ||
12 | import hu.bme.mit.inf.dslreasoner.logic.model.builder.DocumentationLevel | ||
13 | import hu.bme.mit.inf.dslreasoner.workspace.ProjectWorkspace | ||
14 | import org.eclipse.core.commands.AbstractHandler | ||
15 | import org.eclipse.core.commands.ExecutionEvent | ||
16 | import org.eclipse.core.commands.ExecutionException | ||
17 | import org.eclipse.core.resources.IFile | ||
18 | import org.eclipse.core.resources.IProject | ||
19 | import org.eclipse.core.resources.IResource | ||
20 | import org.eclipse.core.runtime.IProgressMonitor | ||
21 | import org.eclipse.core.runtime.NullProgressMonitor | ||
22 | import org.eclipse.emf.common.util.URI | ||
23 | import org.eclipse.emf.ecore.resource.Resource | ||
24 | import org.eclipse.emf.ecore.resource.ResourceSet | ||
25 | import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl | ||
26 | import org.eclipse.swt.widgets.MessageBox | ||
27 | import org.eclipse.ui.PlatformUI | ||
28 | import org.eclipse.ui.handlers.HandlerUtil | ||
29 | import org.eclipse.viatra.query.runtime.api.AdvancedViatraQueryEngine | ||
30 | import org.eclipse.viatra.query.runtime.emf.EMFScope | ||
31 | |||
32 | class ReliabilityAnalysisHandler extends AbstractHandler { | ||
33 | |||
34 | override execute(ExecutionEvent event) throws ExecutionException { | ||
35 | val selection = HandlerUtil.getCurrentStructuredSelection(event) | ||
36 | val resourceSet = new ResourceSetImpl | ||
37 | val iterator = selection.iterator | ||
38 | var IProject targetProject = null | ||
39 | var Resource targetResource = null | ||
40 | var TransformationDefinition transformationDefinition = null | ||
41 | while (iterator.hasNext) { | ||
42 | val selectedElement = iterator.next | ||
43 | if (selectedElement instanceof IFile) { | ||
44 | val resource = tryLoadResource(resourceSet, selectedElement) | ||
45 | if (resource !== null && !resource.contents.empty) { | ||
46 | val rootElement = resource.contents.head | ||
47 | if (rootElement instanceof CftModel) { | ||
48 | if (rootElement.transformationDefinitions.empty) { | ||
49 | throw new IllegalArgumentException("Selected cft file is not a transformation definition.") | ||
50 | } | ||
51 | if (transformationDefinition !== null) { | ||
52 | throw new IllegalArgumentException( | ||
53 | "Only a single transformation definition may be selected.") | ||
54 | } | ||
55 | transformationDefinition = rootElement.transformationDefinitions.head | ||
56 | } else { | ||
57 | if (targetResource !== null) { | ||
58 | throw new IllegalArgumentException("Only a single architecture model may be selected.") | ||
59 | } | ||
60 | targetResource = resource | ||
61 | targetProject = selectedElement.project | ||
62 | } | ||
63 | } | ||
64 | } | ||
65 | } | ||
66 | if (targetResource === null || targetResource === null) { | ||
67 | throw new IllegalArgumentException( | ||
68 | "A transformation definition and an architecture model must be selected.") | ||
69 | } | ||
70 | runAnalysis(transformationDefinition, targetResource, targetProject, new NullProgressMonitor) | ||
71 | null | ||
72 | } | ||
73 | |||
74 | private static def tryLoadResource(ResourceSet resourceSet, IFile file) { | ||
75 | val fullPath = file.fullPath.toString | ||
76 | val uri = URI.createPlatformResourceURI(fullPath, true) | ||
77 | try { | ||
78 | resourceSet.getResource(uri, true) | ||
79 | } catch (RuntimeException e) { | ||
80 | null | ||
81 | } | ||
82 | } | ||
83 | |||
84 | private def runAnalysis(TransformationDefinition transformationDefinition, Resource resource, IProject project, | ||
85 | IProgressMonitor monitor) { | ||
86 | val workspace = createWorkspace(project, monitor) | ||
87 | val cft = createComponentFaultTree(transformationDefinition, resource) | ||
88 | workspace.writeModel(cft, "cft.xmi") | ||
89 | val cft2ft = new Cft2FtTransformation | ||
90 | val ft = cft2ft.createFaultTree(cft) | ||
91 | workspace.writeModel(ft, "ft.xmi") | ||
92 | val solver = new StormDftSolver | ||
93 | val config = new StormDftConfiguration | ||
94 | config.progressMonitor = new EclipseBasedProgressMonitor(monitor) | ||
95 | config.documentationLevel = DocumentationLevel.NORMAL | ||
96 | config.objective = FtAnalysisObjective.MTTF | ||
97 | val result = solver.solve(ft, config, workspace) | ||
98 | displayResult(result) | ||
99 | } | ||
100 | |||
101 | private def createWorkspace(IProject project, IProgressMonitor monitor) { | ||
102 | val folder = project.getFolder("debug") | ||
103 | if (!folder.exists) { | ||
104 | folder.create(IResource.NONE, true, monitor) | ||
105 | } | ||
106 | val path = folder.fullPath.toString | ||
107 | val uri = URI.createPlatformResourceURI(path, true) | ||
108 | val workspace = new ProjectWorkspace(uri.toString, "") | ||
109 | workspace.initAndClear | ||
110 | workspace | ||
111 | } | ||
112 | |||
113 | private def createComponentFaultTree(TransformationDefinition transformationDefinition, Resource resource) { | ||
114 | val queryEngine = AdvancedViatraQueryEngine.createUnmanagedEngine(new EMFScope(resource)) | ||
115 | try { | ||
116 | val ecore2cft = new Ecore2CftTransformation(transformationDefinition, queryEngine) | ||
117 | ecore2cft.createComponentFaultTree | ||
118 | } finally { | ||
119 | queryEngine.dispose | ||
120 | } | ||
121 | } | ||
122 | |||
123 | private def displayResult(ReliabilityResult result) { | ||
124 | val messageBox = new MessageBox(PlatformUI.workbench.activeWorkbenchWindow.shell) | ||
125 | messageBox.message = result.toString | ||
126 | messageBox.open | ||
127 | } | ||
128 | } | ||