From: lempinen Date: Thu, 27 Oct 2011 06:38:39 +0000 (+0000) Subject: Fixed mapping problems with diagramcontainer and added a default gradient to playback... X-Git-Tag: simantics-1.6~125 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=02e5d984badd0e76bb9b160b6163171fcf01a750;p=simantics%2Fsysdyn.git Fixed mapping problems with diagramcontainer and added a default gradient to playback experiment git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@23045 ac1ea38d-2e2b-0410-8846-a27921b304fc --- diff --git a/org.simantics.sysdyn.ontology/graph.tg b/org.simantics.sysdyn.ontology/graph.tg index 156c62e5..013b6508 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/Sysdyn.pgraph b/org.simantics.sysdyn.ontology/graph/Sysdyn.pgraph index 1e2942e3..c7ebe6d5 100644 --- a/org.simantics.sysdyn.ontology/graph/Sysdyn.pgraph +++ b/org.simantics.sysdyn.ontology/graph/Sysdyn.pgraph @@ -350,16 +350,7 @@ SYSDYN.GameExperiment { @Override public LabelDecorator getDecorator(ReadGraph graph, SimulationResultNode result) throws DatabaseException { - if (graph.hasStatement(result.data, SimulationResource.getInstance(graph).IsActive)) { + if (graph.hasStatement(result.data, SysdynResource.getInstance(graph).ShowResult)) { return new LabelDecorator.Stub() { @SuppressWarnings("unchecked") diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/SimulationResultImager.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/SimulationResultImager.java index f37b2b7f..70e418d8 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/SimulationResultImager.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/SimulationResultImager.java @@ -15,7 +15,7 @@ import org.eclipse.jface.resource.ImageDescriptor; import org.simantics.browsing.ui.swt.ImagerContributor; import org.simantics.db.ReadGraph; import org.simantics.db.exception.DatabaseException; -import org.simantics.simulation.ontology.SimulationResource; +import org.simantics.sysdyn.SysdynResource; import org.simantics.sysdyn.ui.Activator; import org.simantics.sysdyn.ui.browser.nodes.SimulationResultNode; @@ -23,7 +23,7 @@ public class SimulationResultImager extends ImagerContributor colorValues = new ArrayList(); for(Resource placement : graph.syncRequest(new ObjectsWithType(gradient, g2d.HasColorPlacement, g2d.ColorPlacement))) { Double position = graph.getPossibleRelatedValue(placement, g2d.HasGradientPosition, Bindings.DOUBLE); - float[] rgba = graph.getPossibleRelatedValue(placement, g2d.HasColor, Bindings.FLOAT_ARRAY); - colorValues.add(new ColorValue(new Color(new java.awt.Color(rgba[0], rgba[1], rgba[2])), position)); + Resource rColor = graph.getPossibleObject(placement, g2d.HasColor); + if (rColor != null) { + colorValues.add(new ColorValue(new Color((java.awt.Color) G2DUtils.getObject(graph, rColor)), position)); + } } cg = new ColorGradient(colorValues, ColorGradient.HSV); } else { diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/ImportModelHandler.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/ImportModelHandler.java index 6676e965..7d871b48 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/ImportModelHandler.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/ImportModelHandler.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 @@ -136,6 +136,10 @@ public class ImportModelHandler extends AbstractHandler { }); } else { + + Resource project = SimanticsUI.getProject().get(); + graph.claim(root, Layer0X.getInstance(graph).IsActivatedBy, project); + updateOldConfigurationToBaseRealization(graph, root); addDefaultOntologyLinks(graph, root); addURIsToDiagrams(graph, root); diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/NewExperimentNodeHandler.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/NewExperimentNodeHandler.java index 16bcd5ec..0d854f02 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/NewExperimentNodeHandler.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/NewExperimentNodeHandler.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 @@ -34,8 +34,6 @@ public class NewExperimentNodeHandler extends AbstractHandler { @Override public Object execute(ExecutionEvent event) throws ExecutionException { - System.out.println("New Experiment"); - ISelection sel = HandlerUtil.getCurrentSelection(event); ExperimentsFolder node = AdaptionUtils.adaptToSingle(sel, ExperimentsFolder.class); @@ -54,17 +52,25 @@ public class NewExperimentNodeHandler extends AbstractHandler { String name = NameUtils.findFreshName(g, getNameSuggestion(), model, l0.ConsistsOf, "%s%d"); - @SuppressWarnings("unused") Resource experiment = GraphUtils.create2(g, getExperimentType(g), l0.HasName, name, l0.HasLabel, name, DOC.HasReportFactory, report, l0.PartOf, model); + + configureExperiment(g, experiment); } }); return null; } + /** + * Override to do experiment-specific alterations + */ + protected void configureExperiment(WriteGraph graph, Resource experiment) throws DatabaseException { + + } + protected Resource getExperimentType(ReadGraph g) { return SysdynResource.getInstance(g).BasicExperiment; } diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/NewPlaybackExperimentNodeHandler.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/NewPlaybackExperimentNodeHandler.java index 417f3266..9eb53798 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/NewPlaybackExperimentNodeHandler.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/NewPlaybackExperimentNodeHandler.java @@ -1,16 +1,49 @@ +/******************************************************************************* + * 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.handlers; +import java.awt.Color; + import org.simantics.db.ReadGraph; import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.diagram.stubs.G2DResource; +import org.simantics.layer0.utils.direct.GraphUtils; import org.simantics.sysdyn.SysdynResource; public class NewPlaybackExperimentNodeHandler extends NewExperimentNodeHandler { - + + protected void configureExperiment(WriteGraph graph, Resource experiment) throws DatabaseException { + G2DResource g2d = G2DResource.getInstance(graph); + Resource defaultGradient = GraphUtils.create2(graph, g2d.ColorGradient); + graph.claim(experiment, g2d.HasColorGradient, defaultGradient); + + Resource placement = GraphUtils.create2(graph, g2d.ColorPlacement, + g2d.HasGradientPosition, 0.0); + graph.claimLiteral(placement, g2d.HasColor, g2d.Color, new Color(0, 62, 133).getColorComponents(new float[4])); + graph.claim(defaultGradient, g2d.HasColorPlacement, placement); + + placement = GraphUtils.create2(graph, g2d.ColorPlacement, + g2d.HasGradientPosition, 1.0); + graph.claimLiteral(placement, g2d.HasColor, g2d.Color, new Color(255, 230, 0).getColorComponents(new float[4])); + graph.claim(defaultGradient, g2d.HasColorPlacement, placement); + } + protected Resource getExperimentType(ReadGraph g) { return SysdynResource.getInstance(g).PlaybackExperiment; } - + protected String getNameSuggestion() { return "Playback Experiment"; } diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/ToggleResultActivation.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/ToggleResultActivation.java index 18616353..5eaa2d73 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/ToggleResultActivation.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/ToggleResultActivation.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 @@ -20,7 +20,6 @@ import org.simantics.db.Resource; import org.simantics.db.WriteGraph; import org.simantics.db.common.request.WriteRequest; import org.simantics.db.exception.DatabaseException; -import org.simantics.simulation.ontology.SimulationResource; import org.simantics.sysdyn.SysdynResource; import org.simantics.ui.SimanticsUI; import org.simantics.ui.utils.ResourceAdaptionUtils; @@ -46,13 +45,12 @@ public class ToggleResultActivation extends AbstractHandler { @Override public void perform(WriteGraph graph) throws DatabaseException { SysdynResource sr = SysdynResource.getInstance(graph); - SimulationResource SIMU = SimulationResource.getInstance(graph); for(Resource r : resources) { if(graph.isInstanceOf(r, sr.Result)) { - if (graph.hasStatement(r, SIMU.IsActive)) { - graph.denyStatement(r, SIMU.IsActive, r); + if (graph.hasStatement(r, sr.ShowResult)) { + graph.denyStatement(r, sr.ShowResult, r); } else { - graph.claim(r, SIMU.IsActive, r); + graph.claim(r, sr.ShowResult, r); } } } diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/PlaybackExperimentTab.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/PlaybackExperimentTab.java index f2eb35e1..4b7eb906 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/PlaybackExperimentTab.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/PlaybackExperimentTab.java @@ -12,6 +12,7 @@ package org.simantics.sysdyn.ui.properties; import java.util.ArrayList; +import java.util.Collection; import org.eclipse.jface.layout.GridDataFactory; import org.eclipse.jface.layout.GridLayoutFactory; @@ -141,7 +142,7 @@ public class PlaybackExperimentTab extends LabelPropertyTabContributor { for(ColorValue cv : colorValues) { Resource placement = GraphUtils.create2(graph, g2d.ColorPlacement, g2d.HasGradientPosition, cv.getValue()); - graph.claimLiteral(placement, g2d.HasColor, cv.getColor().getAWTColor().getColorComponents(new float[4]), Bindings.FLOAT_ARRAY); + graph.claimLiteral(placement, g2d.HasColor, g2d.Color, cv.getColor().getAWTColor().getColorComponents(new float[4])); graph.claim(gradient, g2d.HasColorPlacement, placement); } } @@ -169,8 +170,11 @@ public class PlaybackExperimentTab extends LabelPropertyTabContributor { if(gradient == null) { return Boolean.FALSE; } + Collection placements = graph.syncRequest(new ObjectsWithType(gradient, g2d.HasColorPlacement, g2d.ColorPlacement)); + if(placements.isEmpty()) + return Boolean.FALSE; - for(Resource placement : graph.syncRequest(new ObjectsWithType(gradient, g2d.HasColorPlacement, g2d.ColorPlacement))) { + for(Resource placement : placements) { Double position = graph.getPossibleRelatedValue(placement, g2d.HasGradientPosition); if(position == null) return Boolean.FALSE; diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/utils/VariableNameUtils.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/utils/VariableNameUtils.java index de423013..422f9e9a 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/utils/VariableNameUtils.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/utils/VariableNameUtils.java @@ -95,6 +95,8 @@ public class VariableNameUtils { if(model == null) return true; Configuration configuration = model.getConfiguration(); + if(configuration == null) + return true; IElement current = model.getElement(variable); for(IElement e : configuration.getElements()) { if(e instanceof Variable) { diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/DiagramContainerDummy.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/DiagramContainerDummy.java new file mode 100644 index 00000000..2e16d6ce --- /dev/null +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/DiagramContainerDummy.java @@ -0,0 +1,25 @@ +/******************************************************************************* + * 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.representation; + +import org.simantics.objmap.annotations.GraphType; +import org.simantics.sysdyn.representation.visitors.IElementVisitorVoid; + +@GraphType("http://www.simantics.org/Diagram-2.0/DiagramContainer") +public class DiagramContainerDummy implements IElement { + + @Override + public void accept(IElementVisitorVoid v) { + v.visit(this); + } + +} \ No newline at end of file diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/SysdynSchema.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/SysdynSchema.java index 5b95bc91..3c6a6eed 100644 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/SysdynSchema.java +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/SysdynSchema.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 @@ -53,6 +53,7 @@ public class SysdynSchema extends SimpleSchema { addLinkType(MappingSchemas.fromAnnotations(g, LibraryDummy.class)); addLinkType(MappingSchemas.fromAnnotations(g, Book.class)); addLinkType(MappingSchemas.fromAnnotations(g, Sheet.class)); + addLinkType(MappingSchemas.fromAnnotations(g, DiagramContainerDummy.class)); } catch (DatabaseException e) { e.printStackTrace(); } catch (InstantiationException e) { diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/visitors/ElementVisitorVoidAdapter.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/visitors/ElementVisitorVoidAdapter.java index 4ee889c1..64c7d287 100644 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/visitors/ElementVisitorVoidAdapter.java +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/visitors/ElementVisitorVoidAdapter.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 @@ -15,6 +15,7 @@ import org.simantics.sysdyn.representation.Auxiliary; import org.simantics.sysdyn.representation.Cloud; import org.simantics.sysdyn.representation.Configuration; import org.simantics.sysdyn.representation.Dependency; +import org.simantics.sysdyn.representation.DiagramContainerDummy; import org.simantics.sysdyn.representation.Enumeration; import org.simantics.sysdyn.representation.Flow; import org.simantics.sysdyn.representation.Input; @@ -73,4 +74,8 @@ public class ElementVisitorVoidAdapter implements IElementVisitorVoid { @Override public void visit(Book sheet) { } + + @Override + public void visit(DiagramContainerDummy container) { + } } diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/visitors/IElementVisitorVoid.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/visitors/IElementVisitorVoid.java index 89899f15..3c78343b 100644 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/visitors/IElementVisitorVoid.java +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/visitors/IElementVisitorVoid.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 @@ -15,6 +15,7 @@ import org.simantics.sysdyn.representation.Auxiliary; import org.simantics.sysdyn.representation.Cloud; import org.simantics.sysdyn.representation.Configuration; import org.simantics.sysdyn.representation.Dependency; +import org.simantics.sysdyn.representation.DiagramContainerDummy; import org.simantics.sysdyn.representation.Enumeration; import org.simantics.sysdyn.representation.Flow; import org.simantics.sysdyn.representation.Input; @@ -38,4 +39,5 @@ public interface IElementVisitorVoid { void visit(Enumeration enumeration); void visit(LibraryDummy libraryDummy); void visit(Book sheet); + void visit(DiagramContainerDummy container); }