From: lempinen Date: Tue, 18 Oct 2011 06:26:29 +0000 (+0000) Subject: Issue decorations and better error handling X-Git-Tag: simantics-1.5~9 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=623c0311361706261d69de42330545eeb968a033;p=simantics%2Fsysdyn.git Issue decorations and better error handling git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@22796 ac1ea38d-2e2b-0410-8846-a27921b304fc --- diff --git a/org.simantics.sysdyn.ontology/graph.tg b/org.simantics.sysdyn.ontology/graph.tg index 14b2d4f3..8915d0ae 100644 Binary files a/org.simantics.sysdyn.ontology/graph.tg and b/org.simantics.sysdyn.ontology/graph.tg differ diff --git a/org.simantics.sysdyn.ontology/graph/Profiles.pgraph b/org.simantics.sysdyn.ontology/graph/Profiles.pgraph index 40a270f2..58ff98d7 100644 --- a/org.simantics.sysdyn.ontology/graph/Profiles.pgraph +++ b/org.simantics.sysdyn.ontology/graph/Profiles.pgraph @@ -13,14 +13,29 @@ groupStyleEntry : L0.Template DIA.ProfileEntry.HasStyle %style DIA.ProfileEntry.HasGroup %group + +// PROFILES SYSDYN.SimulationPlaybackProfile - none 0 fill 1 + none 0 fill 1 \ No newline at end of file diff --git a/org.simantics.sysdyn.ui/icons/error.svg b/org.simantics.sysdyn.ui/icons/error.svg new file mode 100644 index 00000000..e4eb0ab1 --- /dev/null +++ b/org.simantics.sysdyn.ui/icons/error.svg @@ -0,0 +1,151 @@ + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/org.simantics.sysdyn.ui/icons/fatal.svg b/org.simantics.sysdyn.ui/icons/fatal.svg new file mode 100644 index 00000000..5ee48164 --- /dev/null +++ b/org.simantics.sysdyn.ui/icons/fatal.svg @@ -0,0 +1,612 @@ + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/org.simantics.sysdyn.ui/icons/warning.svg b/org.simantics.sysdyn.ui/icons/warning.svg new file mode 100644 index 00000000..1dd13ec6 --- /dev/null +++ b/org.simantics.sysdyn.ui/icons/warning.svg @@ -0,0 +1,173 @@ + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/org.simantics.sysdyn.ui/plugin.xml b/org.simantics.sysdyn.ui/plugin.xml index a23cc2f2..a9237d57 100644 --- a/org.simantics.sysdyn.ui/plugin.xml +++ b/org.simantics.sysdyn.ui/plugin.xml @@ -173,6 +173,12 @@ relationship="stack" relative="org.simantics.browsing.ui.graph.propertyView"> + + diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/Activator.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/Activator.java index e531f9bb..cb2d6dd3 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/Activator.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/Activator.java @@ -23,7 +23,9 @@ import org.eclipse.jface.resource.LocalResourceManager; import org.eclipse.jface.resource.ResourceManager; import org.eclipse.swt.widgets.Display; import org.eclipse.ui.plugin.AbstractUIPlugin; +import org.osgi.framework.Bundle; import org.osgi.framework.BundleContext; +import org.simantics.utils.FileUtils; public class Activator extends AbstractUIPlugin { @@ -34,6 +36,10 @@ public class Activator extends AbstractUIPlugin { private static Activator plugin; private static LocalResourceManager resourceManager; + + public static String FATAL_SVG_TEXT; + public static String ERROR_SVG_TEXT; + public static String WARNING_SVG_TEXT; @Override public void start(BundleContext context) throws Exception { @@ -43,6 +49,13 @@ public class Activator extends AbstractUIPlugin { BasicConfigurator.configure(appender); Logger.getRootLogger().setLevel(Level.WARN); plugin = this; + + + Bundle bundle = context.getBundle(); + + FATAL_SVG_TEXT = FileUtils.getContents(bundle.getResource("icons/fatal.svg")); + ERROR_SVG_TEXT = FileUtils.getContents(bundle.getResource("icons/error.svg")); + WARNING_SVG_TEXT = FileUtils.getContents(bundle.getResource("icons/warning.svg")); } @Override diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/profiles/IssueDecorationStyle.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/profiles/IssueDecorationStyle.java new file mode 100644 index 00000000..1912264e --- /dev/null +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/profiles/IssueDecorationStyle.java @@ -0,0 +1,131 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 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.elements2.profiles; + +import java.awt.geom.AffineTransform; +import java.awt.geom.Rectangle2D; +import java.util.Collections; +import java.util.Set; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.common.request.PossibleTypedParent; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.variable.Variable; +import org.simantics.diagram.profile.StyleBase; +import org.simantics.diagram.synchronization.graph.DiagramGraphUtil; +import org.simantics.issues.Issue.Severity; +import org.simantics.issues.common.ErrorIssues; +import org.simantics.issues.common.FatalIssues; +import org.simantics.issues.common.IssueContexts; +import org.simantics.issues.common.WarningIssues; +import org.simantics.layer0.Layer0; +import org.simantics.modeling.ModelingResources; +import org.simantics.scenegraph.INode; +import org.simantics.scenegraph.g2d.nodes.SVGNode; +import org.simantics.scenegraph.profile.EvaluationContext; +import org.simantics.scenegraph.profile.common.ProfileVariables; +import org.simantics.scenegraph.utils.NodeUtil; +import org.simantics.simulation.ontology.SimulationResource; +import org.simantics.sysdyn.ui.Activator; +import org.simantics.utils.datastructures.map.Tuple; + +/** + * @author Tuukka Lehtonen + */ +public class IssueDecorationStyle extends StyleBase { + + private static final String DECORATION_NODE_NAME = "issueDecorations"; + + @Override + public IssueResult calculateStyle(ReadGraph graph, Resource runtimeDiagram, Resource entry, Resource module, Variable configuration) throws DatabaseException { + Layer0 L0 = Layer0.getInstance(graph); + ModelingResources MOD = ModelingResources.getInstance(graph); + Resource config = graph.getPossibleObject(module, MOD.ElementToComponent); + if (config == null) + return null; + + AffineTransform transform = DiagramGraphUtil.getAffineTransform(graph, module); + + Resource model = graph.syncRequest(new PossibleTypedParent(config, SimulationResource.getInstance(graph).Model)); + if (model == null) + return null; + + Resource project = graph.getPossibleObject(model, L0.PartOf); + if (project == null) + return null; + + Set fatals = graph.syncRequest(new FatalIssues(project, true)); + Set fatalContexts = graph.syncRequest(new IssueContexts(fatals)); + if (fatalContexts.contains(config)) + return new IssueResult(Severity.FATAL, transform); + + Set errors = graph.syncRequest(new ErrorIssues(project, true)); + Set errorContexts = graph.syncRequest(new IssueContexts(errors)); + if (errorContexts.contains(config)) + return new IssueResult(Severity.ERROR, transform); + + Set warnings = graph.syncRequest(new WarningIssues(project, true)); + Set warningContexts = graph.syncRequest(new IssueContexts(warnings)); + if (warningContexts.contains(config)) + return new IssueResult(Severity.WARNING, transform); + + return null; + } + + @Override + public void applyStyleForNode(EvaluationContext observer, INode node, IssueResult result) { + if (result == null) { + ProfileVariables.denyChild(node, "", DECORATION_NODE_NAME); + return; + } + + SVGNode svgNode = ProfileVariables.claimChild(node, "", DECORATION_NODE_NAME, SVGNode.class, observer); + + Rectangle2D bounds = NodeUtil.getLocalBounds(node, Collections.singleton(svgNode)); + + double tx = bounds.getMaxX(); + double ty = bounds.getY(); + + svgNode.setZIndex( Integer.MAX_VALUE ); + svgNode.setTransform( AffineTransform.getTranslateInstance(tx-1, ty-1)); + svgNode.getTransform().scale(0.5, 0.5); + + + Severity sev = result.getSeverity(); + if (Severity.FATAL.equals(sev)) + svgNode.setData(Activator.FATAL_SVG_TEXT); + else if (Severity.ERROR.equals(sev)) + svgNode.setData(Activator.ERROR_SVG_TEXT); + else if (Severity.WARNING.equals(sev)) + svgNode.setData(Activator.WARNING_SVG_TEXT); + } + + @Override + protected void cleanupStyleForNode(INode node) { + ProfileVariables.denyChild(node, "", DECORATION_NODE_NAME); + } + +} + +/** + * This is needed to keep the issue decoration up-to-date when its parent + * element moves. + */ +class IssueResult extends Tuple { + public IssueResult(Severity severity, AffineTransform transform) { + super(severity, transform); + } + public Severity getSeverity() { + return (Severity) getField(0); + } +} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/profiles/SimulationPlaybackStyle.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/profiles/SimulationPlaybackStyle.java index 0bdedd0d..1dd87165 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/profiles/SimulationPlaybackStyle.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/profiles/SimulationPlaybackStyle.java @@ -1,3 +1,14 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 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.elements2.profiles; import java.awt.Color; diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/NewModuleNodeHandler.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/NewModuleNodeHandler.java index e6ec15a6..4478bae7 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/NewModuleNodeHandler.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/NewModuleNodeHandler.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2010 Association for Decentralized Information Management in + * Copyright (c) 2010, 2011 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 @@ -67,6 +67,8 @@ public class NewModuleNodeHandler extends AbstractHandler { g.claim(moduleType, l0.Inherits, sr.Module); g.claim(moduleType, l0.PartOf, model); + + Resource configuration = GraphUtils.create2(g, sr.Configuration, l0.HasName, name + "Configuration", @@ -88,6 +90,19 @@ public class NewModuleNodeHandler extends AbstractHandler { g.deny(diagram, L0X.HasTrigger, trigger); } } + + GraphUtils.create2(g, + sr.Validations_Dependencies_DependencyConnectionsIssueSource, + L0X.IsActivatedBy, model, + l0.PartOf, moduleType + ); + + GraphUtils.create2(g, + sr.Validations_Expressions_ExpressionIssueSource, + L0X.IsActivatedBy, model, + l0.PartOf, moduleType + ); + Resource mapping = g.newResource(); g.claim(mapping, l0.InstanceOf, null, sr.DiagramToCompositeMapping); g.claim(diagram, L0X.HasTrigger, mapping); diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/utils/ProfileEntries.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/utils/ProfileEntries.java index 265aed91..f568a6ca 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/utils/ProfileEntries.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/utils/ProfileEntries.java @@ -1,3 +1,14 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 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.utils; import org.simantics.db.Resource; @@ -14,37 +25,37 @@ public class ProfileEntries { public static void createStandardProfiles(WriteGraph graph, final Resource model) throws DatabaseException { Layer0 L0 = Layer0.getInstance(graph); + SysdynResource sr = SysdynResource.getInstance(graph); + DiagramResource DIA = DiagramResource.getInstance(graph); - final Resource a = createSimulationPlaybackProfile(graph); + Resource simulationPlaybackProfile = createProfile(graph, "Simulation Playback", sr.SimulationPlaybackProfile ,sr.Profiles_SimulationPlaybackColours); - Resource plain = Profiles.createProfile(graph, "Plain"); + Resource defaultProfile = createProfile(graph, "Default", sr.DefaultProfile, sr.Profiles_IssueWarnings); - graph.claim(model, DIA.HasProfile, plain); - graph.claim(model, L0.ConsistsOf, a); - graph.claim(model, L0.ConsistsOf, plain); + graph.claim(model, DIA.HasProfile, defaultProfile); + graph.claim(model, L0.ConsistsOf, simulationPlaybackProfile); + graph.claim(model, L0.ConsistsOf, defaultProfile); // FIXME: add virtual graph write back once this is fixed: https://www.simulationsite.net/redmine/issues/3296 // graph.sync(new WriteRequest(graph.getService(VirtualGraphSupport.class).getWorkspacePersistent("profiles")) { // @Override // public void perform(WriteGraph graph) throws DatabaseException { // DiagramResource DIA = DiagramResource.getInstance(graph); - graph.claim(model, DIA.HasActiveProfile, plain); + graph.claim(model, DIA.HasActiveProfile, defaultProfile); // } // }); } - public static Resource createSimulationPlaybackProfile(WriteGraph graph) - throws DatabaseException { + public static Resource createProfile(WriteGraph graph, String name, Resource type, Resource... entries) throws DatabaseException { Layer0 L0 = Layer0.getInstance(graph); - SysdynResource sr = SysdynResource.getInstance(graph); - Resource profile = Profiles.createProfile(graph, "Simulation Playback", - sr.Profiles_SimulationPlaybackColours); + Resource profile = Profiles.createProfile(graph, name, + entries); graph.deny(profile, L0.InstanceOf); - graph.claim(profile, L0.InstanceOf, null, sr.SimulationPlaybackProfile); + graph.claim(profile, L0.InstanceOf, null, type); return profile; } diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/utils/SheetUtils.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/utils/SheetUtils.java index 5360fd83..c593f278 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/utils/SheetUtils.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/utils/SheetUtils.java @@ -1,3 +1,14 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 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.utils; import org.simantics.databoard.Bindings; diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/validation/DependencyFunction.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/validation/DependencyFunction.java index a6431ad4..ebd5f7ad 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/validation/DependencyFunction.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/validation/DependencyFunction.java @@ -1,3 +1,14 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 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.validation; import java.util.Collection; @@ -13,6 +24,7 @@ import org.simantics.issues.ontology.IssueResource; import org.simantics.layer0.Layer0; import org.simantics.scl.reflection.annotations.SCLValue; import org.simantics.simulation.ontology.SimulationResource; +import org.simantics.structural.stubs.StructuralResource2; import org.simantics.sysdyn.SysdynResource; public class DependencyFunction { @@ -47,36 +59,44 @@ public class DependencyFunction { Resource variable = (Resource)_resource; Collection existing = (Collection)_existing; - if(!graph.hasStatement(variable) || !graph.hasStatement(variable, Layer0.getInstance(graph).PartOf)) + IssueResource ISSUE = IssueResource.getInstance(graph); + SysdynResource sr = SysdynResource.getInstance(graph); + Layer0 l0 = Layer0.getInstance(graph); + + if(!graph.isInstanceOf(variable, sr.IndependentVariable)) + return Boolean.TRUE; + + if(!graph.hasStatement(variable) || !graph.hasStatement(variable, l0.PartOf)) return Boolean.FALSE; String name = graph.getRelatedValue(variable, Layer0.getInstance(graph).HasName, Bindings.STRING); - Set references; - Set dependencies; + Set dependencies = ValidationUtils.getDependencies(graph, variable); + + Set references = null; try { references = ValidationUtils.getReferences(graph, variable); - dependencies = ValidationUtils.getDependencies(graph, variable); - - + } catch (SyntaxErrorException e) { + } catch (UnsupportedCharactersException e) { + } catch (UndefinedExpressionException e) { + } + + if(references != null && dependencies != null) { for(String reference : references) { if(!dependencies.contains(reference) && match(graph, existing, variable, getMissingLinkLabel(name, reference)) == null) return Boolean.FALSE; } + } + if(dependencies != null) { for(String dependency : dependencies) { - if(!references.contains(dependency) && match(graph, existing, variable, getUnusedDependencyLabel(name, dependency)) == null) + if(references == null || + (!references.contains(dependency) && + match(graph, existing, variable, getUnusedDependencyLabel(name, dependency)) == null)) return Boolean.FALSE; } - } catch (SyntaxErrorException e) { - } catch (UnsupportedCharactersException e) { - } catch (UndefinedExpressionException e) { } - IssueResource ISSUE = IssueResource.getInstance(graph); - SysdynResource sr = SysdynResource.getInstance(graph); - Layer0 l0 = Layer0.getInstance(graph); - Resource context; for(Resource exist : existing) { context = graph.getSingleObject(exist, ISSUE.HasIssueContext); @@ -108,11 +128,16 @@ public class DependencyFunction { Set labels = new HashSet(); String label; - Set references; - Set dependencies; + Set dependencies = ValidationUtils.getDependencies(graph, variable); + Set references = null; try { references = ValidationUtils.getReferences(graph, variable); - dependencies = ValidationUtils.getDependencies(graph, variable); + } catch (SyntaxErrorException e) { + } catch (UnsupportedCharactersException e) { + } catch (UndefinedExpressionException e) { + } + + if(references != null && dependencies != null) { for(String reference : references) { if(!dependencies.contains(reference)) { if(ValidationUtils.isReachable(graph, variable, reference)) { @@ -130,19 +155,18 @@ public class DependencyFunction { } } } + } + if(dependencies != null) { for(String dependency : dependencies) { label = getUnusedDependencyLabel(name, dependency); - if(!references.contains(dependency)) { + if(references == null || !references.contains(dependency)) { labels.add(label); if(match(graph, existing, variable, label) == null) { ValidationUtils.createIssue(graph, model, source, variable, label, ISSUE.Severity_Warning, sr.DependencyIssue); } } } - } catch (SyntaxErrorException e) { - } catch (UnsupportedCharactersException e) { - } catch (UndefinedExpressionException e) { } Set toBeRemoved = new HashSet(); @@ -171,7 +195,12 @@ public class DependencyFunction { public static Object dependencyBaseRealizationFunction(Object _graph, Object _model) throws DatabaseException { ReadGraph graph = (ReadGraph)_graph; Resource model = (Resource)_model; - return graph.getSingleObject(model, SimulationResource.getInstance(graph).HasConfiguration); + SysdynResource sr = SysdynResource.getInstance(graph); + if(graph.isInstanceOf(model, sr.SysdynModel)) + return graph.getSingleObject(model, SimulationResource.getInstance(graph).HasConfiguration); + else if (graph.isInheritedFrom(model, sr.Module)) + return graph.getSingleObject(model, StructuralResource2.getInstance(graph).IsDefinedBy); + else return null; } diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/validation/ExpressionIssueFunction.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/validation/ExpressionIssueFunction.java index 344310fb..483f2d74 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/validation/ExpressionIssueFunction.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/validation/ExpressionIssueFunction.java @@ -1,3 +1,14 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 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.validation; import java.util.Collection; @@ -13,6 +24,7 @@ import org.simantics.issues.ontology.IssueResource; import org.simantics.layer0.Layer0; import org.simantics.scl.reflection.annotations.SCLValue; import org.simantics.simulation.ontology.SimulationResource; +import org.simantics.structural.stubs.StructuralResource2; import org.simantics.sysdyn.SysdynResource; /** @@ -41,8 +53,17 @@ public class ExpressionIssueFunction { ReadGraph graph = (ReadGraph)_graph; Resource variable = (Resource)_resource; Collection existing = (Collection)_existing; - String name = graph.getRelatedValue(variable, Layer0.getInstance(graph).HasName, Bindings.STRING); - + + SysdynResource sr = SysdynResource.getInstance(graph); + IssueResource ISSUE = IssueResource.getInstance(graph); + Layer0 l0 = Layer0.getInstance(graph); + + if(!graph.isInstanceOf(variable, sr.IndependentVariable)) { + return Boolean.TRUE; + } + + String name = graph.getRelatedValue(variable, l0.HasName, Bindings.STRING); +System.out.println(name); // Try if there are any errors while parsing the expressions try { ValidationUtils.getReferences(graph, variable); @@ -57,10 +78,6 @@ public class ExpressionIssueFunction { return Boolean.FALSE; } - SysdynResource sr = SysdynResource.getInstance(graph); - IssueResource ISSUE = IssueResource.getInstance(graph); - Layer0 l0 = Layer0.getInstance(graph); - Resource context; // There were no errors -> There should be no expression issues for this variable for(Resource exist : existing) { @@ -133,7 +150,12 @@ public class ExpressionIssueFunction { public static Object expressionBaseRealizationFunction(Object _graph, Object _model) throws DatabaseException { ReadGraph graph = (ReadGraph)_graph; Resource model = (Resource)_model; - return graph.getSingleObject(model, SimulationResource.getInstance(graph).HasConfiguration); + SysdynResource sr = SysdynResource.getInstance(graph); + if(graph.isInstanceOf(model, sr.SysdynModel)) + return graph.getSingleObject(model, SimulationResource.getInstance(graph).HasConfiguration); + else if (graph.isInheritedFrom(model, sr.Module)) { + return graph.getSingleObject(model, StructuralResource2.getInstance(graph).IsDefinedBy); + } else return null; } diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/validation/NoSuchVariableException.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/validation/NoSuchVariableException.java index 668ddee4..4ec11767 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/validation/NoSuchVariableException.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/validation/NoSuchVariableException.java @@ -1,3 +1,14 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 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.validation; public class NoSuchVariableException extends RuntimeException { diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/validation/SyntaxErrorException.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/validation/SyntaxErrorException.java index 8d577c98..0592a5d7 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/validation/SyntaxErrorException.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/validation/SyntaxErrorException.java @@ -1,3 +1,14 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 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.validation; public class SyntaxErrorException extends RuntimeException { diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/validation/UndefinedExpressionException.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/validation/UndefinedExpressionException.java index bffa074e..1c53cd87 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/validation/UndefinedExpressionException.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/validation/UndefinedExpressionException.java @@ -1,3 +1,14 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 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.validation; public class UndefinedExpressionException extends RuntimeException { diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/validation/UnsupportedCharactersException.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/validation/UnsupportedCharactersException.java index e96b6096..b2aa82f4 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/validation/UnsupportedCharactersException.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/validation/UnsupportedCharactersException.java @@ -1,3 +1,14 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 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.validation; public class UnsupportedCharactersException extends RuntimeException { diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/validation/ValidationUtils.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/validation/ValidationUtils.java index 349e0303..7659e3d5 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/validation/ValidationUtils.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/validation/ValidationUtils.java @@ -1,3 +1,14 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 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.validation; import java.io.StringReader; @@ -69,7 +80,11 @@ public class ValidationUtils { if(expressionList == null || expressionList.isEmpty()) throw new UndefinedExpressionException(); for(Resource expression : expressionList) { - for(Resource s : graph.syncRequest(new ObjectsWithType(expression, sr.HasEquation, l0.String))) { + Collection equations = graph.syncRequest(new ObjectsWithType(expression, sr.HasEquation, l0.String)); + if(equations.isEmpty()) + throw new UndefinedExpressionException(); + + for(Resource s : equations) { String value = graph.getValue(s, Bindings.STRING); if(value.length() == 0) throw new UndefinedExpressionException(); diff --git a/org.simantics.sysdyn/META-INF/MANIFEST.MF b/org.simantics.sysdyn/META-INF/MANIFEST.MF index 4b4c2998..c83f7bdb 100644 --- a/org.simantics.sysdyn/META-INF/MANIFEST.MF +++ b/org.simantics.sysdyn/META-INF/MANIFEST.MF @@ -23,7 +23,8 @@ Require-Bundle: org.simantics.objmap;bundle-version="0.1.0", org.simantics.scl.runtime;bundle-version="0.1.3", org.simantics.db.layer0;bundle-version="1.1.0", org.simantics.spreadsheet.common;bundle-version="1.1.0", - org.simantics.spreadsheet;bundle-version="1.1.0" + org.simantics.spreadsheet;bundle-version="1.1.0", + org.eclipse.jface.text;bundle-version="3.6.1" Export-Package: org.simantics.sysdyn, org.simantics.sysdyn.adapter, org.simantics.sysdyn.expressionParser, diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/adapter/SysdynVariableProperties.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/adapter/SysdynVariableProperties.java index 102348c9..c21b4a9c 100644 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/adapter/SysdynVariableProperties.java +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/adapter/SysdynVariableProperties.java @@ -1,3 +1,14 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 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.adapter; public class SysdynVariableProperties { diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/adapter/VariableValueSubscription.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/adapter/VariableValueSubscription.java index e04aed72..75a561c1 100644 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/adapter/VariableValueSubscription.java +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/adapter/VariableValueSubscription.java @@ -1,3 +1,14 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 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.adapter; import java.util.ArrayList; diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/FunctionUtils.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/FunctionUtils.java index ee40f1e8..725eed58 100644 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/FunctionUtils.java +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/FunctionUtils.java @@ -1,3 +1,14 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 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.manager; import java.io.File; diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynModel.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynModel.java index 56bd084a..0a857906 100644 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynModel.java +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynModel.java @@ -167,10 +167,23 @@ public class SysdynModel implements IMappingListener, IModel { public synchronized void simulate(final IModelicaMonitor monitor, final IProgressMonitor progressMonitor, final Experiment experiment) throws IOException { canceled = false; progressMonitor.subTask("Write modelica classes"); + + // Write Modelica files ModelicaWriter writer = new ModelicaWriter(); - for(Configuration c : modules) { - writer.write(c); + try { + for(Configuration c : modules) { + writer.write(c); + } + } catch (Exception e) { + setExperimentStopped(experiment); + + + monitor.showConsole(); + + monitor.message("Error when writing Modelica code."); + return; } + progressMonitor.worked(1); progressMonitor.subTask("Write initial files"); @@ -203,7 +216,7 @@ public class SysdynModel implements IMappingListener, IModel { final SimulationLocation simulationLocation = ModelicaManager.createInputFiles( getSimulationDir(), configuration.getName(), - writer.toString(), + modelText, inits, functionscript.toString()); @@ -350,10 +363,22 @@ public class SysdynModel implements IMappingListener, IModel { public synchronized boolean update(ReadGraph graph) throws DatabaseException { if(mapping.isDomainModified()) { mapping.updateRange(graph); - for(Resource config : readModules(graph, configurationResource)) { + Set configs = readModules(graph, configurationResource); + for(Resource config : configs) { if(!modules.contains(config)) modules.add((Configuration)mapping.map(graph, config)); } + + HashSet toBeRemoved = null; + for(Configuration module : modules) { + if(!configs.contains(mapping.inverseGet(module))) { + if(toBeRemoved == null) + toBeRemoved = new HashSet(); + toBeRemoved.add(module); + } + } + if(toBeRemoved != null) + modules.removeAll(toBeRemoved); return true; } else @@ -366,10 +391,22 @@ public class SysdynModel implements IMappingListener, IModel { @Override public void run(ReadGraph graph) throws DatabaseException { mapping.updateRange(graph); - for(Resource config : readModules(graph, configurationResource)) { - if(!modules.contains(config)) - modules.add((Configuration)mapping.map(graph, config)); - } + Set configs = readModules(graph, configurationResource); + for(Resource config : configs) { + if(!modules.contains(config)) + modules.add((Configuration)mapping.map(graph, config)); + } + + HashSet toBeRemoved = null; + for(Configuration module : modules) { + if(!configs.contains(mapping.inverseGet(module))) { + if(toBeRemoved == null) + toBeRemoved = new HashSet(); + toBeRemoved.add(module); + } + } + if(toBeRemoved != null) + modules.removeAll(toBeRemoved); } }); return true; diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/simulation/SimulationJob.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/simulation/SimulationJob.java index b2a729b6..3d51aa8f 100644 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/simulation/SimulationJob.java +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/simulation/SimulationJob.java @@ -18,12 +18,18 @@ import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; import org.eclipse.core.runtime.jobs.Job; -import org.eclipse.ui.console.IConsole; +import org.eclipse.jface.text.BadLocationException; +import org.eclipse.ui.PartInitException; +import org.eclipse.ui.PlatformUI; import org.eclipse.ui.console.ConsolePlugin; +import org.eclipse.ui.console.IConsole; import org.eclipse.ui.console.IConsoleManager; +import org.eclipse.ui.console.IHyperlink; +import org.eclipse.ui.console.IPatternMatchListener; import org.eclipse.ui.console.MessageConsole; import org.eclipse.ui.console.MessageConsoleStream; -import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.console.PatternMatchEvent; +import org.eclipse.ui.console.TextConsole; import org.simantics.modelica.IModelicaMonitor; import org.simantics.simulation.experiment.Experiment; import org.simantics.sysdyn.manager.SysdynModel; @@ -39,10 +45,10 @@ public class SimulationJob extends Job { this.model = model; this.experiment = experiment; if(PlatformUI.isWorkbenchRunning()) { - this.monitor = new ModelicaMonitor(); + this.monitor = new ModelicaMonitor(); } else { - // Fallback to headless - this.monitor = new HeadlessModelicaMonitor(); + // Fallback to headless + this.monitor = new HeadlessModelicaMonitor(); } } @@ -65,7 +71,7 @@ public class SimulationJob extends Job { monitor.done(); return Status.OK_STATUS; } - + @Override public boolean belongsTo(Object family) { return "SimulationJob".equals(family); @@ -77,9 +83,9 @@ public class SimulationJob extends Job { @Override public void message(String message) { - message(message, "hh:mm:ss"); + message(message, "hh:mm:ss"); } - + /** * Print message to a console with a specified time stamp format * @@ -90,22 +96,22 @@ public class SimulationJob extends Job { Calendar cal = Calendar.getInstance(); SimpleDateFormat sdf = new SimpleDateFormat(timeStampFormat); String time = sdf.format(cal.getTime()); - + System.out.println("[" + time +"] " + message); } public void clearConsole() { } - + public void showConsole() { } } - + //org.simantics.sysdyn.ui.modelicaEditor private class ModelicaMonitor implements IModelicaMonitor { MessageConsole console; - + public ModelicaMonitor() { ConsolePlugin plugin = ConsolePlugin.getDefault(); IConsoleManager conMan = plugin.getConsoleManager(); @@ -117,14 +123,103 @@ public class SimulationJob extends Job { MessageConsole myConsole = new MessageConsole("Simulation", null); conMan.addConsoles(new IConsole[]{myConsole}); console = myConsole; + console.addPatternMatchListener(new IPatternMatchListener() { + + @Override + public void matchFound(PatternMatchEvent event) { + try { + console.addHyperlink(new IssueLink(), event.getOffset(), event.getLength()); + } catch (BadLocationException e) { + e.printStackTrace(); + } + } + + @Override + public void disconnect() { + } + + @Override + public void connect(TextConsole console) { + } + + @Override + public String getPattern() { + + return "Issues view"; + } + + @Override + public String getLineQualifier() { + return null; + } + + @Override + public int getCompilerFlags() { + return 0; + } + }); + + /* Link to the modelica document: to be opened to a modelica code viewer. + console.addPatternMatchListener(new IPatternMatchListener() { + + @Override + public void matchFound(PatternMatchEvent event) { + try { + if(event.getSource() instanceof MessageConsole) { + MessageConsole console = (MessageConsole) event.getSource(); + IDocument document = console.getDocument(); + String s = document.get(event.getOffset(), event.getLength()); + s = s.substring(s.indexOf(":") + 1, s.lastIndexOf(":")); + String[] split = s.split(":|-"); + + //TODO: Find the modelica document and its locations + int startOffset = modelicaDocument.getLineOffset(Integer.parseInt(split[0])) + Integer.parseInt(split[1]); + int endOffset = modelicaDocument.getLineOffset(Integer.parseInt(split[2])) + Integer.parseInt(split[3]); + System.out.println("Open modelica editor for model at: " + startOffset + ", " + (endOffset - startOffset)); + + } + + console.addHyperlink(new ModelicaLink(), event.getOffset(), event.getLength()); + } catch (BadLocationException e) { + e.printStackTrace(); + } + } + + @Override + public void disconnect() { + } + + @Override + public void connect(TextConsole console) { + } + + @Override + public String getPattern() { + return "\\[[^\\[]*:[\\d]*:[\\d]*\\-[\\d]*:[\\d]*:writable\\]"; + + } + + @Override + public String getLineQualifier() { + return null; + } + + @Override + public int getCompilerFlags() { + return 0; + } + }); + */ + + } } @Override public void message(String message) { - message(message, "hh:mm:ss"); + message(message, "hh:mm:ss"); } - + /** * Print message to a console with a specified time stamp format * @@ -135,18 +230,23 @@ public class SimulationJob extends Job { Calendar cal = Calendar.getInstance(); SimpleDateFormat sdf = new SimpleDateFormat(timeStampFormat); String time = sdf.format(cal.getTime()); - + MessageConsoleStream out = this.console.newMessageStream(); if(message.length() > 1) - out.println("[" + time +"] " + message); - if(message.contains("Error")) - showConsole(); + out.println("[" + time +"] " + message); + + + + if(message.contains("Error")) { + showConsole(); + out.println("See Issues view"); + } } public void clearConsole() { this.console.clearConsole(); } - + public void showConsole() { ConsolePlugin plugin = ConsolePlugin.getDefault(); IConsoleManager conMan = plugin.getConsoleManager(); @@ -154,10 +254,48 @@ public class SimulationJob extends Job { } } - + @Override protected void canceling() { - model.cancelSimulation(); + + } + + + class IssueLink implements IHyperlink { + + @Override + public void linkEntered() { + } + + @Override + public void linkExited() { + } + + @Override + public void linkActivated() { + try { + PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().showView("org.simantics.issues.ui.issueview"); + } catch (PartInitException e) { + e.printStackTrace(); + } + } + } + + class ModelicaLink implements IHyperlink { + + @Override + public void linkEntered() { + } + + @Override + public void linkExited() { + } + + @Override + public void linkActivated() { + System.out.println("MODELICA LINK"); + } + } }