]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
Merge "(refs #7751) Added orElseM"
authorHannu Niemistö <hannu.niemisto@semantum.fi>
Wed, 7 Feb 2018 12:34:18 +0000 (14:34 +0200)
committerGerrit Code Review <gerrit2@www.simantics.org>
Wed, 7 Feb 2018 12:34:18 +0000 (14:34 +0200)
bundles/org.simantics.g2d/src/org/simantics/g2d/diagram/DiagramHints.java
bundles/org.simantics.g2d/src/org/simantics/g2d/diagram/participant/ElementPainter.java
bundles/org.simantics.modeling/scl/Simantics/SharedOntologies.scl
bundles/org.simantics.modeling/src/org/simantics/modeling/ModelingUtils.java
bundles/org.simantics.scenegraph/src/org/simantics/scenegraph/g2d/nodes/SelectionNode.java

index 6152c168e70f09e57d517249c92d8c9a01804972..367cebcce67fb91caba55ad502c9c1050e75508e 100644 (file)
@@ -179,4 +179,11 @@ public class DiagramHints {
      */
     public static final Key POPUP_MENU_HIDDEN              = new KeyOf(Long.class, "POPUP_MENU_HIDDEN");
 
+    /**
+     * For specifying a user-defined padding for selections
+     *
+     * @since 1.33.0
+     */
+    public static final Key SELECTION_PADDING_SCALE_FACTOR = new KeyOf(Double.class, "SELECTION_PADDING_SCALE_FACTOR");
+
 }
index d35bfadb04ba2fd7e92eefaaa4b5f7feda40440d..ba575c630ffb1aff08024fe8e482d2f5423c8116 100644 (file)
@@ -1090,6 +1090,9 @@ public class ElementPainter extends AbstractDiagramParticipant implements Compos
         } else {
             SelectionNode s = selectionNode.getOrCreateNode(getNodeId("shape", e), SelectionNode.class);
             s.init(selectionTransform, bounds, color);
+            Double paddingFactor = diagram.getHint(DiagramHints.SELECTION_PADDING_SCALE_FACTOR);
+            if (paddingFactor != null)
+                s.setPaddingFactor(paddingFactor);
         }
     }
 
index 6b365d04ad984483872bfb06f49f5084ff1e5278..212a4fbaf0011b130f69efdd2c772d0f3b58ac2b 100644 (file)
@@ -129,6 +129,7 @@ querySharedOntologyType dummy = do
 importJava "org.simantics.modeling.ModelingUtils" where
     importSharedOntologyWithUI :: Variable -> <ReadGraph> ()
     importSharedOntology :: String -> ()
+    importSharedOntology2 :: String -> <Proc> [Resource]
     createSharedOntologyWithUI :: Resource -> <ReadGraph> ()
     unlinkSharedOntologyWithUI :: Variable -> [Resource] -> <ReadGraph> ()
     createNewVersionWithUI :: Resource -> <ReadGraph> ()
index a43220f0677a0efc3b6c54a3f4b2c39caded4b83..2053a8fe3e19619eb47bf8e2df2842c24c38aceb 100644 (file)
@@ -100,6 +100,7 @@ import org.simantics.db.layer0.adapter.impl.ImportAdvisorFactory;
 import org.simantics.db.layer0.genericrelation.DependenciesRelation.DependencyChangesRequest;
 import org.simantics.db.layer0.genericrelation.DependencyChanges;
 import org.simantics.db.layer0.genericrelation.IndexedRelations;
+import org.simantics.db.layer0.migration.MigratedImportResult;
 import org.simantics.db.layer0.migration.MigrationUtils;
 import org.simantics.db.layer0.request.ActivateModel;
 import org.simantics.db.layer0.request.ActiveModels;
@@ -1450,18 +1451,27 @@ public class ModelingUtils {
        
     }
     
-    public static void importSharedOntology(String fileName) throws Exception {
+    public static MigratedImportResult importSharedOntologyWithResult(String fileName) throws Exception {
        try {
                DataContainer dc = DataContainers.readFile(new File(fileName));
                TransferableGraph1 tg = (TransferableGraph1)dc.content.getValue(TransferableGraph1.BINDING);
                Variant draftStatus = dc.metadata.get(DraftStatusBean.EXTENSION_KEY);
-               MigrationUtils.importSharedOntology(Simantics.getSession(), tg, draftStatus == null);
+               return MigrationUtils.importSharedOntology(Simantics.getSession(), tg, draftStatus == null);
        } catch (Exception e) {
                Logger.defaultLogError(e);
                throw e;
        }
     }
     
+    public static void importSharedOntology(String fileName) throws Exception {
+       importSharedOntologyWithResult(fileName);
+    }
+
+    public static List<Resource> importSharedOntology2(String fileName) throws Exception {
+       MigratedImportResult result = importSharedOntologyWithResult(fileName);
+       return new ArrayList<Resource>(result.roots);
+    }
+    
     public static void importSharedOntologyWithUI(ReadGraph graph, final Variable variable) throws DatabaseException {
        
        Display.getDefault().asyncExec(new Runnable() {
index 445a66fe3e9b5a7d431042c677f7323f12ee1ba5..bd09c45745be9ab675d25f0bb073caca8cc85b0d 100644 (file)
@@ -36,10 +36,15 @@ public class SelectionNode extends G2DNode implements Decoration {
     protected transient BasicStroke scaledStroke;
     protected transient double previousScaleRecip = Double.NaN;
     private boolean ignore = false;
+    private double paddingFactor = 5.0;
 
     public void setIgnore(boolean value) {
         ignore = value;
     }
+    
+    public void setPaddingFactor(double factor) {
+        paddingFactor = factor;
+    }
   
     @SyncField({"transform", "bounds", "color"})
     public void init(AffineTransform transform, Rectangle2D bounds, Color color) {
@@ -78,7 +83,7 @@ public class SelectionNode extends G2DNode implements Decoration {
         }
         g.setStroke(scaledStroke);
 
-        double padding = 5.0 * scaleRecip;
+        double padding = paddingFactor * scaleRecip;
         double paddingX = padding;
         double paddingY = padding;