From: villberg Date: Fri, 9 Jul 2010 06:20:18 +0000 (+0000) Subject: Sysdyn dev X-Git-Tag: simantics-1.2.0~181 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=f60333ac12001065153adde471333cc3851de1d6;p=simantics%2Fsysdyn.git Sysdyn dev git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@16568 ac1ea38d-2e2b-0410-8846-a27921b304fc --- diff --git a/org.simantics.sysdyn.ui/plugin.xml b/org.simantics.sysdyn.ui/plugin.xml index e3c3fe68..5b5c4cfd 100644 --- a/org.simantics.sysdyn.ui/plugin.xml +++ b/org.simantics.sysdyn.ui/plugin.xml @@ -288,6 +288,25 @@ style="push"> + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/DiagramViewer.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/DiagramViewer.java index 4251e9bf..1b023211 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/DiagramViewer.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/DiagramViewer.java @@ -34,7 +34,11 @@ import org.simantics.sysdyn.ui.properties.SysdynPropertyPage; */ public class DiagramViewer extends org.simantics.modeling.ui.diagramEditor.DiagramViewer { - @Override + protected String getPopupId() { + return "#SysdynDiagramPopup"; + } + + @Override protected Set getPropertyPageContexts() { return Collections.singleton("http://www.simantics.org/Sysdyn-1.0/Browser"); } diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/ShowModuleHandler.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/ShowModuleHandler.java new file mode 100644 index 00000000..eff51ec0 --- /dev/null +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/ShowModuleHandler.java @@ -0,0 +1,119 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * 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: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.handlers; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.ui.PartInitException; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.handlers.HandlerUtil; +import org.simantics.databoard.binding.java.StringBindingDefault; +import org.simantics.db.Builtins; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.common.ResourceArray; +import org.simantics.db.common.request.ReadRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.variable.Variable; +import org.simantics.db.layer0.variable.Variables; +import org.simantics.diagram.stubs.DiagramResource; +import org.simantics.modeling.ComponentUtils; +import org.simantics.modeling.ModelingResources; +import org.simantics.structural.stubs.StructuralResource2; +import org.simantics.structural2.StructuralVariables; +import org.simantics.sysdyn.SysdynResource; +import org.simantics.sysdyn.ui.editor.DiagramViewer; +import org.simantics.ui.SimanticsUI; +import org.simantics.ui.utils.ResourceAdaptionUtils; +import org.simantics.ui.workbench.ResourceEditorInput2; +import org.simantics.utils.ui.workbench.WorkbenchUtils; + +/** + * Style Edit + * + * TODO : should we have extension point for expanding styles? + * TODO : default ColorChooser is not suitable for this task + * TODO : how to store MetricsFormat template list + * + * @author Marko Luukkainen + * + */ +public class ShowModuleHandler extends AbstractHandler { + + private static final String EDITOR_ID = "org.simantics.sysdyn.ui.diagramViewer"; + + @Override + public Object execute(ExecutionEvent event) throws ExecutionException { + + ISelection s = HandlerUtil.getCurrentSelectionChecked(event); + final Resource resources[] = ResourceAdaptionUtils.toResources(s); + final DiagramViewer viewer = (DiagramViewer)HandlerUtil.getActiveEditor(event); + + SimanticsUI.getSession().asyncRequest(new ReadRequest() { + + @Override + public void run(ReadGraph graph) throws DatabaseException { + + DiagramResource dr = DiagramResource.getInstance(graph); + Resource runtime = viewer.getRuntime(); + String uri = graph.getPossibleRelatedValue(runtime, dr.HasVariable, StringBindingDefault.INSTANCE); + String currentRVI = graph.getPossibleRelatedValue(runtime, dr.HasRVI, StringBindingDefault.INSTANCE); + Variable variable = Variables.getVariable(graph, uri); + Resource model = Variables.getModel(graph, variable); + final String modelURI = graph.getURI(model); + + for(Resource element : resources) { + + Builtins b = graph.getBuiltins(); + ModelingResources mr = ModelingResources.getInstance(graph); + SysdynResource sr = SysdynResource.getInstance(graph); + StructuralResource2 st = StructuralResource2.getInstance(graph); + + final Resource component = graph.getPossibleObject(element, mr.ElementToComponent); + final Resource componentType = graph.getPossibleType(component, sr.Module); + final Resource configuration = graph.getPossibleObject(componentType, st.IsDefinedBy); + final Resource diagram = ComponentUtils.getPossibleCompositeDiagram(graph, configuration); + + if(diagram == null) return; + + final String rvi = currentRVI + "/" + graph.getPossibleRelatedValue(component, b.HasName, StringBindingDefault.INSTANCE); + if(rvi == null) return; + + PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() { + + @Override + public void run() { + // for (Triple in : ins) { + try { + String editorId = EDITOR_ID; + System.out.println("Activating diagram: model=" + modelURI + " rvi='" + rvi + "'"); + WorkbenchUtils.openEditor(editorId, new ResourceEditorInput2(editorId, diagram, modelURI, rvi)); + } catch (PartInitException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + // } + } + }); + + } + + } + }); + + return null; + } + + +} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/StockExpression.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/StockExpression.java index 2f09a953..f9be1605 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/StockExpression.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/StockExpression.java @@ -181,10 +181,9 @@ public class StockExpression implements IExpression { Resource tail = graph.getPossibleObject(r, sr.HasTail); if(tail != null) { Object name = graph.getPossibleRelatedValue(tail, b.HasName); - if (name != null) { - System.out.println("STOCK += " + name); + if (name != null) builder.append(" + " + name); - } + } } } diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/TrendView.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/TrendView.java index f66c3087..707d83a8 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/TrendView.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/TrendView.java @@ -39,6 +39,8 @@ import org.simantics.db.Resource; import org.simantics.db.Session; import org.simantics.db.common.request.ReadRequest; import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.SelectionHints; +import org.simantics.diagram.stubs.DiagramResource; import org.simantics.modeling.ModelingResources; import org.simantics.sysdyn.SysdynResource; import org.simantics.sysdyn.manager.SysdynDataSet; @@ -137,6 +139,7 @@ public class TrendView extends ViewPart { return; if(selection instanceof IStructuredSelection) { Set ress = ISelectionUtils.filterSetSelection(selection, Resource.class); + Resource runtime = ISelectionUtils.getSinglePossibleKey(selection, SelectionHints.KEY_VARIABLE_RESOURCE, Resource.class); // Object[] els = ((IStructuredSelection) selection).toArray(); // Resource[] resources = new Resource[els.length]; // for(int i=0;i datasets = new ArrayList(); for(Resource resource : resources) { - Collection set = load(g, resource); + Collection set = load(g, resource, runtime); if(set == null) return; - datasets.addAll(load(g, resource)); + datasets.addAll(load(g, resource, runtime)); } SwingUtilities.invokeLater(new Runnable() { @@ -218,19 +224,25 @@ public class TrendView extends ViewPart { } } - protected Collection load(ReadGraph g, Resource resource) throws DatabaseException { + protected Collection load(ReadGraph g, Resource resource, Resource runtime) throws DatabaseException { Builtins b = g.getBuiltins(); SysdynResource sr = SysdynResource.getInstance(g); + DiagramResource dr = DiagramResource.getInstance(g); + +// String rvi = g.getPossibleRelatedValue(runtime, dr.HasRVI); +// System.out.println("load results rvi='" + rvi + "'"); + String prefix = ""; + ModelingResources mr = ModelingResources.getInstance(g); Resource map = g.getPossibleObject(resource, mr.ElementToComponent); if(map != null) resource = map; if(g.isInstanceOf(resource, sr.Variable)) { Resource module = g.getPossibleObject(resource, b.PartOf); - while(!g.isInstanceOf(module, sr.Configuration)) { - module = g.getPossibleObject(module, b.PartOf); - } +// while(!g.isInstanceOf(module, sr.Configuration)) { +// module = g.getPossibleObject(module, b.PartOf); +// } if(g.isInstanceOf(module, sr.Configuration)) { SysdynModel model = getModel(g, module); if(model == null) @@ -243,7 +255,7 @@ public class TrendView extends ViewPart { Collection activeResults = model.getActiveResults(g); ArrayList datasets = new ArrayList(); for(SysdynResult r : activeResults) { - SysdynDataSet sdds = r.getDataSet(var.getName()); + SysdynDataSet sdds = r.getDataSet(prefix + var.getName()); if(sdds != null) datasets.add(sdds); } return datasets; diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynResult.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynResult.java index 50014824..43056443 100644 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynResult.java +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynResult.java @@ -44,6 +44,7 @@ public class SysdynResult { } public SysdynResult(String result, String path) { + System.out.println("sysdynresult " + result + " " + path); this.resultName = result; File file = new File(path); try { diff --git a/sysdyn_ontologies/sysdyn.graph b/sysdyn_ontologies/sysdyn.graph index 20908392..c6e9f606 100644 --- a/sysdyn_ontologies/sysdyn.graph +++ b/sysdyn_ontologies/sysdyn.graph @@ -183,7 +183,7 @@ Module