]> gerrit.simantics Code Review - simantics/district.git/commitdiff
Enabling/Disabling map painting
authorjsimomaa <jani.simomaa@gmail.com>
Tue, 6 Nov 2018 08:03:04 +0000 (10:03 +0200)
committerTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Fri, 9 Nov 2018 07:18:28 +0000 (09:18 +0200)
gitlab #15

Change-Id: I034a334c4a47753342f9871ae68551ceda0b1d19

org.simantics.district.maps/src/org/simantics/maps/eclipse/MapPainter.java
org.simantics.district.network.ontology/graph/DistrictNetworkDiagramSettings.pgraph
org.simantics.district.network.ontology/src/org/simantics/district/network/ontology/DistrictNetworkResource.java
org.simantics.district.network.ui/fragment.e4xmi
org.simantics.district.network.ui/src/org/simantics/district/network/ui/DistrictDiagramViewer.java
org.simantics.district.network.ui/src/org/simantics/district/network/ui/contributions/DrawMapToggleHandler.java [new file with mode: 0644]
org.simantics.district.network/src/org/simantics/district/network/DistrictNetworkUtil.java
org.simantics.district.region.ui/src/org/simantics/district/region/ui/DiagramRegionsTableUI.java
org.simantics.district.region.ui/src/org/simantics/district/region/ui/DiagramRegionsTableView.java
org.simantics.district.region.ui/src/org/simantics/district/region/ui/handlers/ZoomToRegionHandler.java
org.simantics.district.region/src/org/simantics/district/region/DiagramRegions.java

index ee0c71a6cb54b8767a0aa7acba8ab26decd108c6..cdf0be15a5236d8a4826da71eb6b4b8f4e1f1cdd 100644 (file)
@@ -97,6 +97,11 @@ public class MapPainter extends AbstractCanvasParticipant {
             updateNode();
             setDirty();
             return true;
+        } else if (e.command.equals( Commands.ENABLE_PAINTING )) {
+            enablePainting();
+            updateNode();
+            setDirty();
+            return true;
         }
         return false;
     }
@@ -138,4 +143,7 @@ public class MapPainter extends AbstractCanvasParticipant {
         setHint(KEY_MAP_ENABLED, enabled);
     }
 
+    private void enablePainting() {
+        setHint(Hints.KEY_DISABLE_PAINTING, false);
+    }
 }
index 0ca711a12d282d61356a76bc0e9c7cbdf3c6d02e..eb2416e96f6589f08cd5c1077ca3b9e8de71c7cd 100644 (file)
@@ -78,6 +78,10 @@ DN.Diagram
         L0.HasLabel "Node Scale Bias"
     >-- DN.Diagram.nodeScaleProperty --> DN.Vertex.ScaleProperty <R L0.HasProperty : DN.VertexScalePropertyParameterType
         L0.HasLabel "Node Scale Property"
+    >-- DN.Diagram.backgroundColor ==> "String" <R L0.HasProperty : SEL.GenericParameterType
+        L0.HasLabel "Diagram Background Color"
+    >-- DN.Diagram.drawMapEnabled ==> "Boolean" <R L0.HasProperty : SEL.GenericParameterType
+        L0.HasLabel "Draw Map"
     @L0.assert DN.Diagram.elementColoringGradientHue
         0.0 : L0.Float
             L0.HasDataType $(Float(unit="deg",range=[0..360]))
@@ -91,6 +95,7 @@ DN.Diagram
     @L0.assert DN.Diagram.nodeScaleGain 1.0
     @L0.assert DN.Diagram.nodeScaleBias 0.0
     @L0.assert DN.Diagram.nodeScaleProperty DN.Vertex.ScaleProperty.NominalSupplyPressure
+    @L0.assert DN.Diagram.drawMapEnabled true
 
 // ----------------------------------------------------------------------------
 // Built-in enumerated ScaleProperty & ThicknessProperty instances
index f5f5ba0998728366af33420982f00e6083297818..6f9c6122d9f408d5c8f2b8b39abee7261e5477d7 100644 (file)
@@ -21,6 +21,10 @@ public class DistrictNetworkResource {
     public final Resource Diagram;
     public final Resource Diagram_MappedDiagram;
     public final Resource Diagram_MappedFromDiagram;
+    public final Resource Diagram_backgroundColor;
+    public final Resource Diagram_backgroundColor_Inverse;
+    public final Resource Diagram_drawMapEnabled;
+    public final Resource Diagram_drawMapEnabled_Inverse;
     public final Resource Diagram_edgeThicknessBias;
     public final Resource Diagram_edgeThicknessBias_Inverse;
     public final Resource Diagram_edgeThicknessGain;
@@ -278,6 +282,10 @@ public class DistrictNetworkResource {
         public static final String Diagram = "http://www.simantics.org/DistrictNetwork-1.0/Diagram";
         public static final String Diagram_MappedDiagram = "http://www.simantics.org/DistrictNetwork-1.0/Diagram/MappedDiagram";
         public static final String Diagram_MappedFromDiagram = "http://www.simantics.org/DistrictNetwork-1.0/Diagram/MappedFromDiagram";
+        public static final String Diagram_backgroundColor = "http://www.simantics.org/DistrictNetwork-1.0/Diagram/backgroundColor";
+        public static final String Diagram_backgroundColor_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/Diagram/backgroundColor/Inverse";
+        public static final String Diagram_drawMapEnabled = "http://www.simantics.org/DistrictNetwork-1.0/Diagram/drawMapEnabled";
+        public static final String Diagram_drawMapEnabled_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/Diagram/drawMapEnabled/Inverse";
         public static final String Diagram_edgeThicknessBias = "http://www.simantics.org/DistrictNetwork-1.0/Diagram/edgeThicknessBias";
         public static final String Diagram_edgeThicknessBias_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/Diagram/edgeThicknessBias/Inverse";
         public static final String Diagram_edgeThicknessGain = "http://www.simantics.org/DistrictNetwork-1.0/Diagram/edgeThicknessGain";
@@ -545,6 +553,10 @@ public class DistrictNetworkResource {
         Diagram = getResourceOrNull(graph, URIs.Diagram);
         Diagram_MappedDiagram = getResourceOrNull(graph, URIs.Diagram_MappedDiagram);
         Diagram_MappedFromDiagram = getResourceOrNull(graph, URIs.Diagram_MappedFromDiagram);
+        Diagram_backgroundColor = getResourceOrNull(graph, URIs.Diagram_backgroundColor);
+        Diagram_backgroundColor_Inverse = getResourceOrNull(graph, URIs.Diagram_backgroundColor_Inverse);
+        Diagram_drawMapEnabled = getResourceOrNull(graph, URIs.Diagram_drawMapEnabled);
+        Diagram_drawMapEnabled_Inverse = getResourceOrNull(graph, URIs.Diagram_drawMapEnabled_Inverse);
         Diagram_edgeThicknessBias = getResourceOrNull(graph, URIs.Diagram_edgeThicknessBias);
         Diagram_edgeThicknessBias_Inverse = getResourceOrNull(graph, URIs.Diagram_edgeThicknessBias_Inverse);
         Diagram_edgeThicknessGain = getResourceOrNull(graph, URIs.Diagram_edgeThicknessGain);
index 197f7f192727955f976e0954a7e3323b89d3a4d8..be0b7a40b5970567afbb3cc6853db14c36f37dc2 100644 (file)
@@ -5,18 +5,21 @@
     <elements xsi:type="commands:Command" xmi:id="_A1HBQOFYEeaJP6VyXP72Jw" elementId="org.simantics.district.network.ui.joinVertices" commandName="Join Vertices"/>
     <elements xsi:type="commands:Command" xmi:id="_QzdUQOIcEeaJP6VyXP72Jw" elementId="org.simantics.district.network.ui.setFocusable" commandName="Set Focusable"/>
     <elements xsi:type="commands:Command" xmi:id="_4wJtADWxEeeVXaXEq4_qpA" elementId="org.simantics.district.network.ui.command.changemapping" commandName="Change Mapping"/>
+    <elements xsi:type="commands:Command" xmi:id="_qillYOGQEeiIMuq1qhQJRQ" elementId="org.simantics.district.network.ui.command.toggledrawmap" commandName="Toggle Draw Map"/>
   </fragments>
   <fragments xsi:type="fragment:StringModelFragment" xmi:id="_Js7rUMMAEea1mdgpHNVHMA" featurename="menuContributions" parentElementId="xpath:/">
     <elements xsi:type="menu:MenuContribution" xmi:id="_T-jiEN8NEeaigNyzMJBOrg" elementId="org.simantics.district.network.ui.menucontribution.districtDiagramPopup" parentId="#DistrictDiagramPopup">
       <children xsi:type="menu:HandledMenuItem" xmi:id="_VCxYIN8NEeaigNyzMJBOrg" elementId="org.simantics.district.network.ui.handledmenuitem.importImage" label="Import PNG/SVG Image" iconURI="platform:/plugin/org.simantics.modeling.ui/icons/image_add.png" tooltip="Import PNG/SVG Image as a layout" command="_luNasN8NEeaigNyzMJBOrg"/>
       <children xsi:type="menu:HandledMenuItem" xmi:id="_O_UgUOIgEeaJP6VyXP72Jw" elementId="org.simantics.district.network.ui.handledmenuitem.joinvertices" label="Join Vertices" iconURI="platform:/plugin/org.simantics.ui/icons/etool16/arrow_join.png" tooltip="Join multiple vertices as one" command="_A1HBQOFYEeaJP6VyXP72Jw"/>
       <children xsi:type="menu:DynamicMenuContribution" xmi:id="_dieAsOIgEeaJP6VyXP72Jw" elementId="org.simantics.district.network.ui.dynamicmenucontribution.setFocusable" label="Set Focusable" contributionURI="bundleclass://org.simantics.district.network.ui/org.simantics.district.network.ui.contributions.SetFocusableDynamicMenuContribution"/>
-      <children xsi:type="menu:HandledMenuItem" xmi:id="_QbF4UDWyEeeVXaXEq4_qpA" elementId="org.simantics.district.network.ui.handledmenuitem.changemapping" label="Change Mapping" tooltip="Change mapping of multiple elements" command="_4wJtADWxEeeVXaXEq4_qpA"/>
+      <children xsi:type="menu:HandledMenuItem" xmi:id="_QbF4UDWyEeeVXaXEq4_qpA" elementId="org.simantics.district.network.ui.handledmenuitem.changemapping" label="Change Mapping" iconURI="platform:/plugin/com.famfamfam.silk/icons/arrow_switch.png" tooltip="Change mapping of multiple elements" command="_4wJtADWxEeeVXaXEq4_qpA"/>
+      <children xsi:type="menu:HandledMenuItem" xmi:id="_ZE-9sOGeEei2MexsDMErvQ" elementId="org.simantics.district.network.ui.handledmenuitem.toggledrawmap" label="Toggle Draw Map" iconURI="platform:/plugin/com.famfamfam.silk/icons/map_add.png" command="_qillYOGQEeiIMuq1qhQJRQ"/>
     </elements>
   </fragments>
   <fragments xsi:type="fragment:StringModelFragment" xmi:id="_dbiHcMMBEea1mdgpHNVHMA" featurename="handlers" parentElementId="xpath:/">
     <elements xsi:type="commands:Handler" xmi:id="_DPcVsOFYEeaJP6VyXP72Jw" elementId="org.simantics.district.network.ui.handler.joinVertices" contributionURI="bundleclass://org.simantics.district.network.ui/org.simantics.district.network.ui.contributions.JoinVerticesHandler" command="_A1HBQOFYEeaJP6VyXP72Jw"/>
     <elements xsi:type="commands:Handler" xmi:id="_VPgBwOIcEeaJP6VyXP72Jw" elementId="org.simantics.district.network.ui.handler.setFocusable" contributionURI="bundleclass://org.simantics.district.network.ui/org.simantics.district.network.ui.contributions.SetFocusableHandler" command="_QzdUQOIcEeaJP6VyXP72Jw"/>
     <elements xsi:type="commands:Handler" xmi:id="_LojWYDWyEeeVXaXEq4_qpA" elementId="org.simantics.district.network.ui.handler.0" contributionURI="bundleclass://org.simantics.district.network.ui/org.simantics.district.network.ui.contributions.ChangeMappingTypeHandler" command="_4wJtADWxEeeVXaXEq4_qpA"/>
+    <elements xsi:type="commands:Handler" xmi:id="_ubB2kOGQEeiIMuq1qhQJRQ" elementId="org.simantics.district.network.ui.handler.1" contributionURI="bundleclass://org.simantics.district.network.ui/org.simantics.district.network.ui.contributions.DrawMapToggleHandler" command="_qillYOGQEeiIMuq1qhQJRQ"/>
   </fragments>
 </fragment:ModelFragments>
index f3e556718202027ce966b2bab9c1f1e86414461e..c6c510e0a59d3546743ce68c0bd603003f599d91 100644 (file)
@@ -2,6 +2,11 @@ package org.simantics.district.network.ui;
 
 import java.util.concurrent.TimeUnit;
 
+import org.simantics.db.ReadGraph;
+import org.simantics.db.common.request.UniqueRead;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.procedure.Listener;
+import org.simantics.district.network.DistrictNetworkUtil;
 import org.simantics.district.network.ui.participants.DNPointerInteractor;
 import org.simantics.district.network.ui.participants.MapRulerPainter;
 import org.simantics.g2d.canvas.ICanvasContext;
@@ -19,10 +24,16 @@ import org.simantics.g2d.participant.ZoomToAreaHandler;
 import org.simantics.maps.MapScalingTransform;
 import org.simantics.maps.eclipse.MapPainter;
 import org.simantics.modeling.ui.diagramEditor.DiagramViewer;
+import org.simantics.scenegraph.g2d.events.command.CommandEvent;
+import org.simantics.scenegraph.g2d.events.command.Commands;
 import org.simantics.utils.datastructures.hints.IHintContext;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 public class DistrictDiagramViewer extends DiagramViewer {
 
+    private static final Logger LOGGER = LoggerFactory.getLogger(DistrictDiagramViewer.class);
+
     @Override
     protected void addDiagramParticipants(ICanvasContext ctx) {
         ctx.add(new ZOrderHandler());
@@ -68,4 +79,33 @@ public class DistrictDiagramViewer extends DiagramViewer {
         ctx.add(new ZoomToAreaHandler());
     }
 
+    @Override
+    protected void loadPageSettings(ICanvasContext ctx) {
+        super.loadPageSettings(ctx);
+        // this might be the wrong place to start such listening but at least
+        // super.loadPageSettings() does async-db-operations
+        sessionContext.getSession().asyncRequest(new UniqueRead<Boolean>() {
+
+            @Override
+            public Boolean perform(ReadGraph graph) throws DatabaseException {
+                return DistrictNetworkUtil.drawMapEnabled(graph, getInputResource());
+            }
+        }, new Listener<Boolean>() {
+
+            @Override
+            public void execute(Boolean result) {
+                canvasContext.getEventQueue().queueEvent(new CommandEvent(canvasContext, System.currentTimeMillis(), result ? Commands.MAP_ENABLE : Commands.MAP_DISABLE));
+            }
+
+            @Override
+            public void exception(Throwable t) {
+                LOGGER.error("Could not listen draw map for {}", getInputResource(), t);
+            }
+
+            @Override
+            public boolean isDisposed() {
+                return DistrictDiagramViewer.this.isDisposed();
+            }
+        });
+    }
 }
diff --git a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/contributions/DrawMapToggleHandler.java b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/contributions/DrawMapToggleHandler.java
new file mode 100644 (file)
index 0000000..ddec27b
--- /dev/null
@@ -0,0 +1,58 @@
+package org.simantics.district.network.ui.contributions;
+
+import java.util.List;
+
+import javax.inject.Named;
+
+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.e4.core.di.annotations.CanExecute;
+import org.eclipse.e4.core.di.annotations.Execute;
+import org.eclipse.e4.ui.services.IServiceConstants;
+import org.eclipse.jface.viewers.ISelection;
+import org.simantics.DatabaseJob;
+import org.simantics.Simantics;
+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.db.layer0.SelectionHints;
+import org.simantics.district.network.DistrictNetworkUtil;
+import org.simantics.district.network.ui.internal.Activator;
+import org.simantics.utils.ui.ISelectionUtils;
+
+public class DrawMapToggleHandler {
+
+    @CanExecute
+    public boolean canExecute(@Named(IServiceConstants.ACTIVE_SELECTION) ISelection selection) {
+        final List<Resource> diagrams = ISelectionUtils.getPossibleKeys(selection, SelectionHints.KEY_MAIN, Resource.class);
+        return diagrams.size() > 0;
+    }
+
+    @Execute
+    public void execute(@Named(IServiceConstants.ACTIVE_SELECTION) Object selection) {
+        final List<Resource> diagrams = ISelectionUtils.getPossibleKeys(selection, SelectionHints.KEY_MAIN, Resource.class);
+        Job job = new DatabaseJob("Toggle draw map") {
+
+            @Override
+            protected IStatus run(IProgressMonitor monitor) {
+                try {
+                    Simantics.getSession().syncRequest(new WriteRequest() {
+
+                        @Override
+                        public void perform(WriteGraph graph) throws DatabaseException {
+                            DistrictNetworkUtil.toggleDrawMap(graph, diagrams.get(0));
+                        }
+                    });
+                } catch (DatabaseException e) {
+                    return new Status(IStatus.ERROR, Activator.PLUGIN_ID, getName() + " failed.", e);
+                }
+                return Status.OK_STATUS;
+            }
+        };
+        job.setUser(true);
+        job.schedule();
+    }
+}
index 64aab473a8a726ba6f4244ea1ce91c3367af9168..821085175a91886b25807fde8d30133b805b3ca3 100644 (file)
@@ -8,7 +8,10 @@ import org.simantics.db.ReadGraph;
 import org.simantics.db.Resource;
 import org.simantics.db.WriteGraph;
 import org.simantics.db.common.utils.OrderedSetUtils;
+import org.simantics.db.exception.BindingException;
 import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.exception.ManyObjectsForFunctionalRelationException;
+import org.simantics.db.exception.ServiceException;
 import org.simantics.db.layer0.request.PossibleVariable;
 import org.simantics.db.layer0.variable.Variable;
 import org.simantics.diagram.stubs.DiagramResource;
@@ -204,4 +207,17 @@ public class DistrictNetworkUtil {
         return null;
     }
 
+    public static void toggleDrawMap(WriteGraph graph, Resource diagram) throws ManyObjectsForFunctionalRelationException, BindingException, ServiceException {
+        DistrictNetworkResource DN = DistrictNetworkResource.getInstance(graph);
+        Boolean current = graph.getPossibleRelatedValue(diagram, DN.Diagram_drawMapEnabled, Bindings.BOOLEAN);
+        if (current == null)
+            current = true;
+        graph.claimLiteral(diagram, DN.Diagram_drawMapEnabled, !current, Bindings.BOOLEAN);
+    }
+
+    public static Boolean drawMapEnabled(ReadGraph graph, Resource diagram) throws ManyObjectsForFunctionalRelationException, BindingException, ServiceException {
+        DistrictNetworkResource DN = DistrictNetworkResource.getInstance(graph);
+        Boolean current = graph.getPossibleRelatedValue(diagram, DN.Diagram_drawMapEnabled, Bindings.BOOLEAN);
+        return current != null ? current : true;
+    }
 }
index f4b639786cbca24cb2ed4ef0289c05cac910bbd5..562dd24bb7d22108ae4e810bd42174c5ff6fc18b 100644 (file)
@@ -80,7 +80,6 @@ public class DiagramRegionsTableUI extends Composite {
             
             @Override
             public void doubleClick(DoubleClickEvent event) {
-                LOGGER.info("event " +  event);
                 TreeSelection selection = (TreeSelection) viewer.getSelection();
                 DiagramRegion region = (DiagramRegion) selection.getFirstElement();
                 ZoomToRegionHandler.zoomTo(viewer.getControl(), getDisplay(), region.getResource());
index 1fff18d1efbd5a3e34cdc4b793f9fd587332be34..4ad66198c7146c21b7b5089f50d875cbe7743965 100644 (file)
@@ -17,12 +17,16 @@ import org.eclipse.e4.ui.model.application.ui.menu.MToolBar;
 import org.eclipse.e4.ui.services.EMenuService;
 import org.eclipse.e4.ui.workbench.modeling.ESelectionService;
 import org.eclipse.swt.widgets.Composite;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
  * @author Jani Simomaa
  */
 public class DiagramRegionsTableView {
 
+    private static final Logger LOGGER = LoggerFactory.getLogger(DiagramRegionsTableView.class);
+
     DiagramRegionsTableUI ui;
 
     /**
@@ -65,7 +69,8 @@ public class DiagramRegionsTableView {
     public void postConstruct(ESelectionService selectionService, Composite parent, EMenuService menuService) {
         // System.out.println("construct MPTV");
         this.ui = new DiagramRegionsTableUI(selectionService, parent, 0);
-        menuService.registerContextMenu(this.ui.getTree(), POPUP_ID);
+        if (!(menuService.registerContextMenu(this.ui.getTree(), POPUP_ID)))
+            LOGGER.warn("Could not register context menu {}", POPUP_ID);
     }
 
     @PreDestroy
index 47290bd7b2fff40e1e161715aa22f7dd7db71146..7a1e105bee7599f6f8483e0c99de45600ced8b6f 100644 (file)
@@ -57,10 +57,10 @@ public class ZoomToRegionHandler {
             @Named(IServiceConstants.ACTIVE_PART) MPart part,
             @Named(IServiceConstants.ACTIVE_SELECTION) ISelection selection) {
         DiagramRegion region = ISelectionUtils.filterSingleSelection(selection, DiagramRegion.class);
-        zoomTo(part, activeShell.getDisplay(), region.getResource());
+        zoomTo((Control) part.getWidget(), activeShell.getDisplay(), region.getResource());
     }
 
-    public static void zoomTo(MPart part, Display display, Resource region) {
+    public static void zoomTo(Control control, Display display, Resource region) {
         Resource dia;
         try {
             dia = Simantics.getSession().syncRequest(new UniqueRead<Resource>() {
@@ -76,7 +76,7 @@ public class ZoomToRegionHandler {
             IEditorPart activeEditor = WorkbenchUtils.getActiveEditor();
             LOGGER.info("activeWorkbenchPart {}", beforePerformingDefaultAction);
             LOGGER.info("activeEditor {}", activeEditor);
-            DefaultActions.performDefaultAction((Control)part.getWidget(), dia);
+            DefaultActions.performDefaultAction(control, dia);
             Simantics.getSession().asyncRequest(new ReadRequest() {
                 
                 @Override
@@ -90,7 +90,7 @@ public class ZoomToRegionHandler {
                             try {
                                 Thread.sleep(150);
                             } catch (InterruptedException e) {
-                                e.printStackTrace();
+                                LOGGER.error("Could not sleep", e);
                             }
                             afterPerformingDefaultAction = WorkbenchUtils.getActiveEditor();
                             LOGGER.info("afterActiveWorkbenchPart {}", afterPerformingDefaultAction);
@@ -118,7 +118,7 @@ public class ZoomToRegionHandler {
                 }
             });
         } catch (DatabaseException e) {
-            e.printStackTrace();
+            LOGGER.error("Could not zoom to region", e);
         }
     }
 }
index 57f31ae4a5f70d2b004930b63b9760e11c9a3d79..98a3ea4f47aa7d78df6a4e0f864f5ccc58e082f9 100644 (file)
@@ -149,7 +149,7 @@ public final class DiagramRegions {
                 points[0] = moveX;
                 points[1] = moveY;
                 // Fall into....
-
+                break;
             case PathIterator.SEG_LINETO:
                 thisX = points[0];
                 thisY = points[1];