From 8c8a6f597d1c56ebe788a028d70c7851f58dae9f Mon Sep 17 00:00:00 2001 From: Reino Ruusu Date: Wed, 21 Aug 2019 15:27:11 +0300 Subject: [PATCH] Add "New Plant" as model browser action. Change-Id: I60d036fbc2cf726fbdf7e2961def4f34c8d45483 --- .../graph/plant3d_viewpoint.pgraph | 40 ++++--------------- .../simantics/plant3d/ontology/Plant3D.java | 33 +++++++-------- org.simantics.plant3d/adapters.xml | 5 +++ .../plant3d/handlers/NewPlantHandler.java | 29 +++++++++++++- 4 files changed, 54 insertions(+), 53 deletions(-) diff --git a/org.simantics.plant3d.ontology/graph/plant3d_viewpoint.pgraph b/org.simantics.plant3d.ontology/graph/plant3d_viewpoint.pgraph index 0c42f7ff..5be0264c 100644 --- a/org.simantics.plant3d.ontology/graph/plant3d_viewpoint.pgraph +++ b/org.simantics.plant3d.ontology/graph/plant3d_viewpoint.pgraph @@ -19,8 +19,8 @@ PBC = P3D.P3DBrowseContext : VP.BrowseContext @VP.constantImageRule P3D.Builtin.Straight IMAGES.Straight @VP.constantImageRule P3D.EndComponent IMAGES.Component @VP.constantImageRule P3D.PipeRun IMAGES.Straight - @VP.relationChildRule PROJ.Project L0.ConsistsOf P3D.Plant - @VP.relationChildRule PROJ.Project L0.ConsistsOf CSG.Model + @VP.relationChildRule L0.Library L0.ConsistsOf P3D.Plant + @VP.relationChildRule L0.Library L0.ConsistsOf CSG.Model @VP.relationChildRule P3D.Node P3D.children P3D.Node @VP.relationChildRule P3D.Node P3D.HasNozzle P3D.Node @@ -40,35 +40,9 @@ IMAGES.Tank : IMAGE.PngImage @L0.loadBytes "images/tank.png" MAC = P3D.P3DActionContext : VP.BrowseContext - VP.BrowseContext.IsIncludedIn PROJ.ProjectActionContext - - -MAC.newContribution : L0.Template - @template %actionContext %label %action %image - %actionContext - VP.BrowseContext.HasActionContribution _ : VP.ActionContribution - L0.HasLabel %label - VP.ActionContribution.HasImage %image - VP.ActionContribution.HasCategory VP.NewActionCategory - VP.ActionContribution.HasNodeType P3D.Plant - VP.ActionContribution.HasAction %action + VP.BrowseContext.IsIncludedIn PROJ.ProjectActionContext -MAC.newTypeContribution : L0.Template - @template %actionContext %label %action %type %image - %actionContext - VP.BrowseContext.HasActionContribution _ : VP.ActionContribution - L0.HasLabel %label - VP.ActionContribution.HasImage %image - VP.ActionContribution.HasCategory VP.NewActionCategory - VP.ActionContribution.HasNodeType %type - VP.ActionContribution.HasAction %action - -MAC.editTypeContribution : L0.Template - @template %actionContext %label %action %type %image - %actionContext - VP.BrowseContext.HasActionContribution _ : VP.ActionContribution - L0.HasLabel %label - VP.ActionContribution.HasImage %image - VP.ActionContribution.HasCategory VP.EditActionCategory - VP.ActionContribution.HasNodeType %type - VP.ActionContribution.HasAction %action \ No newline at end of file + @VP.actionContribution "Plant" L0.Library IMAGES.Factory VP.NewActionCategory P3D.Actions.NewPlant + +P3D.Actions : L0.Library +P3D.Actions.NewPlant : L0.Action diff --git a/org.simantics.plant3d.ontology/src/org/simantics/plant3d/ontology/Plant3D.java b/org.simantics.plant3d.ontology/src/org/simantics/plant3d/ontology/Plant3D.java index 817c9475..a9659d88 100644 --- a/org.simantics.plant3d.ontology/src/org/simantics/plant3d/ontology/Plant3D.java +++ b/org.simantics.plant3d.ontology/src/org/simantics/plant3d/ontology/Plant3D.java @@ -10,6 +10,8 @@ import org.simantics.db.service.QueryControl; public class Plant3D { + public final Resource Actions; + public final Resource Actions_NewPlant; public final Resource Builtin; public final Resource Builtin_BallValve; public final Resource Builtin_BallValveGeometryProvider; @@ -26,7 +28,6 @@ public class Plant3D { public final Resource Builtin_ElbowGeometryProvider; public final Resource Builtin_GateValve; public final Resource Builtin_GateValveGeometryProvider; - public final Resource Builtin_GeometryProvider; public final Resource Builtin_HorizontalTank; public final Resource Builtin_HorizontalTankGeometryProvider; public final Resource Builtin_Nozzle; @@ -45,6 +46,7 @@ public class Plant3D { public final Resource Equipment; public final Resource FixedAngleTurnComponent; public final Resource FixedLengthInlineComponent; + public final Resource GeometryProvider; public final Resource HasAlternativePipeRun; public final Resource HasBranch0; public final Resource HasBranch1; @@ -98,9 +100,6 @@ public class Plant3D { public final Resource NozzleOf; public final Resource OffsetComponent; public final Resource P3DActionContext; - public final Resource P3DActionContext_editTypeContribution; - public final Resource P3DActionContext_newContribution; - public final Resource P3DActionContext_newTypeContribution; public final Resource P3DBrowseContext; public final Resource Parameter; public final Resource PipeRun; @@ -115,13 +114,15 @@ public class Plant3D { public final Resource TurnComponent; public final Resource VariableAngleTurnComponent; public final Resource VariableLengthInlineComponent; - public final Resource childen; - public final Resource childen_Inverse; + public final Resource children; + public final Resource children_Inverse; public final Resource hasGeometry; public final Resource hasParameter; public final Resource hasParameterValue; public static class URIs { + public static final String Actions = "http://www.simantics.org/Plant3D-0.1/Actions"; + public static final String Actions_NewPlant = "http://www.simantics.org/Plant3D-0.1/Actions/NewPlant"; public static final String Builtin = "http://www.simantics.org/Plant3D-0.1/Builtin"; public static final String Builtin_BallValve = "http://www.simantics.org/Plant3D-0.1/Builtin/BallValve"; public static final String Builtin_BallValveGeometryProvider = "http://www.simantics.org/Plant3D-0.1/Builtin/BallValveGeometryProvider"; @@ -138,7 +139,6 @@ public class Plant3D { public static final String Builtin_ElbowGeometryProvider = "http://www.simantics.org/Plant3D-0.1/Builtin/ElbowGeometryProvider"; public static final String Builtin_GateValve = "http://www.simantics.org/Plant3D-0.1/Builtin/GateValve"; public static final String Builtin_GateValveGeometryProvider = "http://www.simantics.org/Plant3D-0.1/Builtin/GateValveGeometryProvider"; - public static final String Builtin_GeometryProvider = "http://www.simantics.org/Plant3D-0.1/Builtin/GeometryProvider"; public static final String Builtin_HorizontalTank = "http://www.simantics.org/Plant3D-0.1/Builtin/HorizontalTank"; public static final String Builtin_HorizontalTankGeometryProvider = "http://www.simantics.org/Plant3D-0.1/Builtin/HorizontalTankGeometryProvider"; public static final String Builtin_Nozzle = "http://www.simantics.org/Plant3D-0.1/Builtin/Nozzle"; @@ -157,6 +157,7 @@ public class Plant3D { public static final String Equipment = "http://www.simantics.org/Plant3D-0.1/Equipment"; public static final String FixedAngleTurnComponent = "http://www.simantics.org/Plant3D-0.1/FixedAngleTurnComponent"; public static final String FixedLengthInlineComponent = "http://www.simantics.org/Plant3D-0.1/FixedLengthInlineComponent"; + public static final String GeometryProvider = "http://www.simantics.org/Plant3D-0.1/GeometryProvider"; public static final String HasAlternativePipeRun = "http://www.simantics.org/Plant3D-0.1/HasAlternativePipeRun"; public static final String HasBranch0 = "http://www.simantics.org/Plant3D-0.1/HasBranch0"; public static final String HasBranch1 = "http://www.simantics.org/Plant3D-0.1/HasBranch1"; @@ -210,9 +211,6 @@ public class Plant3D { public static final String NozzleOf = "http://www.simantics.org/Plant3D-0.1/NozzleOf"; public static final String OffsetComponent = "http://www.simantics.org/Plant3D-0.1/OffsetComponent"; public static final String P3DActionContext = "http://www.simantics.org/Plant3D-0.1/P3DActionContext"; - public static final String P3DActionContext_editTypeContribution = "http://www.simantics.org/Plant3D-0.1/P3DActionContext/editTypeContribution"; - public static final String P3DActionContext_newContribution = "http://www.simantics.org/Plant3D-0.1/P3DActionContext/newContribution"; - public static final String P3DActionContext_newTypeContribution = "http://www.simantics.org/Plant3D-0.1/P3DActionContext/newTypeContribution"; public static final String P3DBrowseContext = "http://www.simantics.org/Plant3D-0.1/P3DBrowseContext"; public static final String Parameter = "http://www.simantics.org/Plant3D-0.1/Parameter"; public static final String PipeRun = "http://www.simantics.org/Plant3D-0.1/PipeRun"; @@ -227,8 +225,8 @@ public class Plant3D { public static final String TurnComponent = "http://www.simantics.org/Plant3D-0.1/TurnComponent"; public static final String VariableAngleTurnComponent = "http://www.simantics.org/Plant3D-0.1/VariableAngleTurnComponent"; public static final String VariableLengthInlineComponent = "http://www.simantics.org/Plant3D-0.1/VariableLengthInlineComponent"; - public static final String childen = "http://www.simantics.org/Plant3D-0.1/childen"; - public static final String childen_Inverse = "http://www.simantics.org/Plant3D-0.1/childen/Inverse"; + public static final String children = "http://www.simantics.org/Plant3D-0.1/children"; + public static final String children_Inverse = "http://www.simantics.org/Plant3D-0.1/children/Inverse"; public static final String hasGeometry = "http://www.simantics.org/Plant3D-0.1/hasGeometry"; public static final String hasParameter = "http://www.simantics.org/Plant3D-0.1/hasParameter"; public static final String hasParameterValue = "http://www.simantics.org/Plant3D-0.1/hasParameterValue"; @@ -244,6 +242,8 @@ public class Plant3D { } public Plant3D(ReadGraph graph) { + Actions = getResourceOrNull(graph, URIs.Actions); + Actions_NewPlant = getResourceOrNull(graph, URIs.Actions_NewPlant); Builtin = getResourceOrNull(graph, URIs.Builtin); Builtin_BallValve = getResourceOrNull(graph, URIs.Builtin_BallValve); Builtin_BallValveGeometryProvider = getResourceOrNull(graph, URIs.Builtin_BallValveGeometryProvider); @@ -260,7 +260,6 @@ public class Plant3D { Builtin_ElbowGeometryProvider = getResourceOrNull(graph, URIs.Builtin_ElbowGeometryProvider); Builtin_GateValve = getResourceOrNull(graph, URIs.Builtin_GateValve); Builtin_GateValveGeometryProvider = getResourceOrNull(graph, URIs.Builtin_GateValveGeometryProvider); - Builtin_GeometryProvider = getResourceOrNull(graph, URIs.Builtin_GeometryProvider); Builtin_HorizontalTank = getResourceOrNull(graph, URIs.Builtin_HorizontalTank); Builtin_HorizontalTankGeometryProvider = getResourceOrNull(graph, URIs.Builtin_HorizontalTankGeometryProvider); Builtin_Nozzle = getResourceOrNull(graph, URIs.Builtin_Nozzle); @@ -279,6 +278,7 @@ public class Plant3D { Equipment = getResourceOrNull(graph, URIs.Equipment); FixedAngleTurnComponent = getResourceOrNull(graph, URIs.FixedAngleTurnComponent); FixedLengthInlineComponent = getResourceOrNull(graph, URIs.FixedLengthInlineComponent); + GeometryProvider = getResourceOrNull(graph, URIs.GeometryProvider); HasAlternativePipeRun = getResourceOrNull(graph, URIs.HasAlternativePipeRun); HasBranch0 = getResourceOrNull(graph, URIs.HasBranch0); HasBranch1 = getResourceOrNull(graph, URIs.HasBranch1); @@ -332,9 +332,6 @@ public class Plant3D { NozzleOf = getResourceOrNull(graph, URIs.NozzleOf); OffsetComponent = getResourceOrNull(graph, URIs.OffsetComponent); P3DActionContext = getResourceOrNull(graph, URIs.P3DActionContext); - P3DActionContext_editTypeContribution = getResourceOrNull(graph, URIs.P3DActionContext_editTypeContribution); - P3DActionContext_newContribution = getResourceOrNull(graph, URIs.P3DActionContext_newContribution); - P3DActionContext_newTypeContribution = getResourceOrNull(graph, URIs.P3DActionContext_newTypeContribution); P3DBrowseContext = getResourceOrNull(graph, URIs.P3DBrowseContext); Parameter = getResourceOrNull(graph, URIs.Parameter); PipeRun = getResourceOrNull(graph, URIs.PipeRun); @@ -349,8 +346,8 @@ public class Plant3D { TurnComponent = getResourceOrNull(graph, URIs.TurnComponent); VariableAngleTurnComponent = getResourceOrNull(graph, URIs.VariableAngleTurnComponent); VariableLengthInlineComponent = getResourceOrNull(graph, URIs.VariableLengthInlineComponent); - childen = getResourceOrNull(graph, URIs.childen); - childen_Inverse = getResourceOrNull(graph, URIs.childen_Inverse); + children = getResourceOrNull(graph, URIs.children); + children_Inverse = getResourceOrNull(graph, URIs.children_Inverse); hasGeometry = getResourceOrNull(graph, URIs.hasGeometry); hasParameter = getResourceOrNull(graph, URIs.hasParameter); hasParameterValue = getResourceOrNull(graph, URIs.hasParameterValue); diff --git a/org.simantics.plant3d/adapters.xml b/org.simantics.plant3d/adapters.xml index a3f17be3..9efc3b18 100644 --- a/org.simantics.plant3d/adapters.xml +++ b/org.simantics.plant3d/adapters.xml @@ -46,4 +46,9 @@ + + + + \ No newline at end of file diff --git a/org.simantics.plant3d/src/org/simantics/plant3d/handlers/NewPlantHandler.java b/org.simantics.plant3d/src/org/simantics/plant3d/handlers/NewPlantHandler.java index 42e64cfe..7429e775 100644 --- a/org.simantics.plant3d/src/org/simantics/plant3d/handlers/NewPlantHandler.java +++ b/org.simantics.plant3d/src/org/simantics/plant3d/handlers/NewPlantHandler.java @@ -13,16 +13,42 @@ import org.simantics.db.WriteGraph; import org.simantics.db.common.request.WriteRequest; import org.simantics.db.common.utils.NameUtils; import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.adapter.ActionFactory; import org.simantics.layer0.Layer0; import org.simantics.plant3d.Activator; import org.simantics.plant3d.utils.P3DUtil; -public class NewPlantHandler extends AbstractHandler { +public class NewPlantHandler extends AbstractHandler implements ActionFactory { + // Action factory method + @Override + public Runnable create(final Object target) { + if (!(target instanceof Resource)) + return null; + + return new Runnable() { + @Override + public void run() { + createNewPlantJob((Resource) target); + } + }; + } + + // Handler method @Override public Object execute(ExecutionEvent event) throws ExecutionException { final Resource library = Simantics.getProject().get(); + createNewPlantJob(library); + return null; + } + + /** + * Create a new plant as a user-triggered job. + * + * @param library Parent resource for the new plant. + */ + public static void createNewPlantJob(final Resource library) { Job job = new Job("Create Plant ") { @Override protected IStatus run(IProgressMonitor monitor) { @@ -49,6 +75,5 @@ public class NewPlantHandler extends AbstractHandler { }; job.setUser(true); job.schedule(); - return null; } } -- 2.47.0