From ba0d89ab9214bdb3d24967e2eea27e83045a5b3a Mon Sep 17 00:00:00 2001 From: lempinen Date: Wed, 16 May 2012 12:40:22 +0000 Subject: [PATCH] Editor name fixed to show "module name : module type name" instead of "module name : module name". Took enumeration replacements into account in chart properties. (refs #3414) git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@24990 ac1ea38d-2e2b-0410-8846-a27921b304fc --- .../OpenDiagramFromConfigurationAdapter.java | 1 - .../sysdyn/ui/editor/SysdynEditorInput.java | 2 - .../ui/editor/SysdynEditorNamingService.java | 61 +++++++++++-------- .../chart/properties/RangeComposite.java | 33 +++++++++- .../sysdyn/ui/utils/ExpressionUtils.java | 4 +- .../sysdyn/manager/SysdynGameExperiment.java | 26 -------- 6 files changed, 69 insertions(+), 58 deletions(-) diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/OpenDiagramFromConfigurationAdapter.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/OpenDiagramFromConfigurationAdapter.java index 433a3b36..d5a155cf 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/OpenDiagramFromConfigurationAdapter.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/OpenDiagramFromConfigurationAdapter.java @@ -18,7 +18,6 @@ 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.layer0.Layer0; import org.simantics.modeling.ComponentUtils; import org.simantics.modeling.ModelingResources; import org.simantics.modeling.ui.Activator; diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/SysdynEditorInput.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/SysdynEditorInput.java index 67b642d2..ee100d49 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/SysdynEditorInput.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/SysdynEditorInput.java @@ -17,7 +17,6 @@ import org.simantics.db.layer0.variable.Variable; import org.simantics.db.layer0.variable.Variables; import org.simantics.db.service.LifecycleSupport; import org.simantics.db.service.SerialisationSupport; -import org.simantics.layer0.Layer0; import org.simantics.operation.Layer0X; import org.simantics.ui.SimanticsUI; import org.simantics.ui.icons.ImageDescriptorProvider; @@ -379,7 +378,6 @@ public class SysdynEditorInput extends ResourceEditorInput2 { if (!exists) throw new Nonexistant(); - Layer0 L0 = Layer0.getInstance(g); // 2. Validate modelURI if (getModelURI() != null) { Layer0X L0X = Layer0X.getInstance(g); diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/SysdynEditorNamingService.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/SysdynEditorNamingService.java index abb9f0b8..f47c890c 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/SysdynEditorNamingService.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/SysdynEditorNamingService.java @@ -18,6 +18,8 @@ import org.simantics.db.common.utils.NameUtils; import org.simantics.db.exception.DatabaseException; import org.simantics.db.layer0.variable.Variable; import org.simantics.db.layer0.variable.Variables; +import org.simantics.layer0.Layer0; +import org.simantics.modeling.ModelingResources; import org.simantics.modeling.ui.features.EditorNamingService2; import org.simantics.simulation.ontology.SimulationResource; import org.simantics.ui.workbench.IResourceEditorInput2; @@ -31,32 +33,39 @@ import org.simantics.ui.workbench.IResourceEditorInput2; * */ public class SysdynEditorNamingService extends EditorNamingService2 { - - @Override - public String getName(ReadGraph g, String editorId, IEditorInput in) throws DatabaseException { - if(in instanceof IResourceEditorInput2) { - IResourceEditorInput2 input = (IResourceEditorInput2) in; - - if(!input.getRVI().isEmpty()) { - Resource model = g.getPossibleResource(input.getModelURI()); - if(model != null) { - Resource configuration = g.getPossibleObject(model, SimulationResource.getInstance(g).HasConfiguration); - String configurationName = NameUtils.getSafeName(g, configuration); - String uri = input.getModelURI() + "/" + configurationName + input.getRVI(); - Variable v = Variables.getPossibleVariable(g, uri); - if(v != null) { - String name = input.getRVI(); - if(name.contains("/")) - name = name.substring(name.lastIndexOf("/") + 1); - - String instanceOf = super.getName(g, editorId, in); - return name + " : " + instanceOf; - } - } - } - } - return super.getName(g, editorId, in); - } + @Override + public String getName(ReadGraph g, String editorId, IEditorInput in) throws DatabaseException { + if(in instanceof IResourceEditorInput2) { + IResourceEditorInput2 input = (IResourceEditorInput2) in; + + if(!input.getRVI().isEmpty()) { + Resource model = g.getPossibleResource(input.getModelURI()); + if(model != null) { + Resource configuration = g.getPossibleObject(model, SimulationResource.getInstance(g).HasConfiguration); + String configurationName = NameUtils.getSafeName(g, configuration); + String uri = input.getModelURI() + "/" + configurationName + input.getRVI(); + Variable v = Variables.getPossibleVariable(g, uri); + if(v != null) { + String name = input.getRVI(); + if(name.contains("/")) + name = name.substring(name.lastIndexOf("/") + 1); + + Resource instanceOf = g.getPossibleObject(v.getRepresents(g), Layer0.getInstance(g).InstanceOf); + return name + " : " + NameUtils.getSafeName(g, instanceOf); + } + } + } else { + ModelingResources mr = ModelingResources.getInstance(g); + Resource conf = g.getPossibleObject(input.getResource(), mr.DiagramToComposite); + if(conf != null) { + Resource module = g.getPossibleObject(conf, Layer0.getInstance(g).PartOf); + if(module != null) + return NameUtils.getSafeName(g, module); + } + } + } + return super.getName(g, editorId, in); + } } diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/RangeComposite.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/RangeComposite.java index e7284fc1..7ccce029 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/RangeComposite.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/RangeComposite.java @@ -11,6 +11,7 @@ *******************************************************************************/ package org.simantics.sysdyn.ui.trend.chart.properties; +import java.util.HashMap; import java.util.Iterator; import java.util.LinkedHashMap; import java.util.List; @@ -43,6 +44,7 @@ import org.simantics.db.layer0.variable.Variables; import org.simantics.db.management.ISessionContext; import org.simantics.db.procedure.Listener; import org.simantics.db.request.Read; +import org.simantics.layer0.Layer0; import org.simantics.sysdyn.JFreeChartResource; import org.simantics.sysdyn.SysdynResource; import org.simantics.sysdyn.ui.trend.chart.ChartUtils; @@ -97,6 +99,27 @@ public class RangeComposite extends Composite implements Widget { Variable v = Variables.getVariable(graph, realizationURI + rvi.trim()); if(v == null) return null; + + // Find all enumeration replacements in the variable's path + HashMap redeclarations = new HashMap(); + Variable parent = v; + while((parent = parent.getParent(graph)) != null) { + Resource represents = parent.getRepresents(graph); + Resource type = graph.getSingleObject(represents, Layer0.getInstance(graph).InstanceOf); + if(!graph.isInheritedFrom(type, sr.Module)) + break; + + for(Resource redeclaration : graph.getObjects(represents, sr.Module_redeclaration)) { + redeclarations.put( + graph.getPossibleObject(redeclaration, sr.Redeclaration_replacedEnumeration), + graph.getPossibleObject(redeclaration, sr.Redeclaration_replacingEnumeration) + ); + } + } + + + + Resource variable = v.getRepresents(graph); // Return the enumerations assigned to that variable @@ -104,8 +127,14 @@ public class RangeComposite extends Composite implements Widget { if(arrayIndexes != null) { LinkedHashMap result = new LinkedHashMap(); for(Resource enumeration : OrderedSetUtils.toList(graph, arrayIndexes)) { - String enumerationName = NameUtils.getSafeName(graph, enumeration); - result.put(enumerationName, enumeration); + + // Find possible redeclarations for enumeration + Resource redeclaration = enumeration; + while(redeclarations.get(redeclaration) != null) + redeclaration = redeclarations.get(redeclaration); + + String enumerationName = NameUtils.getSafeName(graph, redeclaration); + result.put(enumerationName, redeclaration); } return result; } diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/utils/ExpressionUtils.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/utils/ExpressionUtils.java index d0acb085..6773376d 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/utils/ExpressionUtils.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/utils/ExpressionUtils.java @@ -83,7 +83,9 @@ public class ExpressionUtils { * @param configuration configuration where the variable is located */ static public void validateExpressionFields(final Resource variable, IExpression expression, Table variableTable) { - + if(variable == null || expression == null || variableTable == null) + return; + Resource configuration = null; try { configuration = SimanticsUI.getSession().syncRequest(new Read() { diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynGameExperiment.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynGameExperiment.java index f9c9da33..be625aa3 100644 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynGameExperiment.java +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynGameExperiment.java @@ -209,9 +209,6 @@ public class SysdynGameExperiment extends SysdynExperiment { try { - long t = System.currentTimeMillis(); - long oldT; - control.setStepLength(stepLength); // Set step length each time in case there has been changes double time = control.getTime(); @@ -220,41 +217,18 @@ public class SysdynGameExperiment extends SysdynExperiment { while(control.getTime() < (eTime - 1e-9)) { // Substract a very small number, because OpenModelica is not very precise with its Real numbers - oldT = t; - t = System.currentTimeMillis(); - System.out.println("step start ----------------------------------------- "); - control.simulateStep(); - System.out.println("simulate step \t\t " + (System.currentTimeMillis() - oldT)); - - results = control.getSubscribedResults(results); - System.out.println("results\t\t\t " + (System.currentTimeMillis() - oldT)); - for(int k = 0; k < subscription.length; k++) { this.results.get(subscription[k]).add(results[k]); } - - oldT = t; - t = System.currentTimeMillis(); - System.out.println("step complete\t " + (t - oldT)); } - oldT = t; - t = System.currentTimeMillis(); - System.out.println("results ready ------------------------------- "); - - sysdynModel.getSysdynResult().setResult(new GameResult(this.results, this.subscription)); sysdynModel.resultChanged(); - oldT = t; - t = System.currentTimeMillis(); - System.out.println("results changed\t " + (t - oldT)); - - } catch (FMUJNIException e) { System.err.println("SysdynGameExperiment simulateDuration failed: \n\t" + e.getMessage()); } -- 2.47.1