diff options
Diffstat (limited to 'Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.ui')
3 files changed, 131 insertions, 1 deletions
diff --git a/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.ui/bin/.gitignore b/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.ui/bin/.gitignore deleted file mode 100644 index 1c0a02cd..00000000 --- a/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.ui/bin/.gitignore +++ /dev/null | |||
@@ -1 +0,0 @@ | |||
1 | /hu/ | ||
diff --git a/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.ui/bin/hu/bme/mit/inf/dslreasoner/faulttree/ui/handler/.gitignore b/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.ui/bin/hu/bme/mit/inf/dslreasoner/faulttree/ui/handler/.gitignore new file mode 100644 index 00000000..b271af76 --- /dev/null +++ b/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.ui/bin/hu/bme/mit/inf/dslreasoner/faulttree/ui/handler/.gitignore | |||
@@ -0,0 +1,3 @@ | |||
1 | /.ReliabilityAnalysisHandler.java._trace | ||
2 | /.ReliabilityAnalysisHandler.xtendbin | ||
3 | /ReliabilityAnalysisHandler.java | ||
diff --git a/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.ui/bin/hu/bme/mit/inf/dslreasoner/faulttree/ui/handler/ReliabilityAnalysisHandler.xtend b/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.ui/bin/hu/bme/mit/inf/dslreasoner/faulttree/ui/handler/ReliabilityAnalysisHandler.xtend new file mode 100644 index 00000000..5fa89148 --- /dev/null +++ b/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.ui/bin/hu/bme/mit/inf/dslreasoner/faulttree/ui/handler/ReliabilityAnalysisHandler.xtend | |||
@@ -0,0 +1,128 @@ | |||
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 | } | ||