]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
Moved LinkSVGImage implementation to new location. 34/534/1
authorKalle Kondelin <kalle.kondelin@vtt.fi>
Thu, 18 May 2017 12:06:44 +0000 (15:06 +0300)
committerKalle Kondelin <kalle.kondelin@vtt.fi>
Thu, 18 May 2017 13:00:13 +0000 (16:00 +0300)
Activated linkImage scl function because it is used by existing scl scripts.
Had to move implementation because compiler error/warning:
A cycle was detected in the build path of project...

refs #6916

Change-Id: I2017051816010128002017051816010128006666

bundles/org.simantics.image.ui/META-INF/MANIFEST.MF
bundles/org.simantics.image.ui/scl/Simantics/Image.scl
bundles/org.simantics.image.ui/src/org/simantics/image/ui/LinkSvgImage.java [new file with mode: 0644]
bundles/org.simantics.image.ui/src/org/simantics/image/ui/SCLImage.java
bundles/org.simantics.modeling.template2d.ui/META-INF/MANIFEST.MF
bundles/org.simantics.modeling.template2d.ui/src/org/simantics/modeling/template2d/ui/function/LinkSVGImage.java
bundles/org.simantics.modeling/src/org/simantics/modeling/typicals/rules/PageSettingsTypicalRule.java

index 92903842164ed499fbbf71659a6205a8fa6aaf24..8ab7fee894f05c3070ceef2f7e5dfc3cd36d84b8 100644 (file)
@@ -11,7 +11,9 @@ Require-Bundle: org.simantics.ui;bundle-version="1.0.0",
  org.simantics.layer0.utils;bundle-version="1.1.0",
  org.simantics.browsing.ui.swt;bundle-version="1.1.0",
  org.simantics.image2.ontology;bundle-version="1.0.0",
- org.simantics.scenegraph;bundle-version="1.1.1"
+ org.simantics.scenegraph;bundle-version="1.1.1",
+ org.simantics.diagram;bundle-version="1.1.1",
+ org.simantics.modeling.template2d.ontology;bundle-version="1.0.0"
 Bundle-ActivationPolicy: lazy
 Bundle-RequiredExecutionEnvironment: JavaSE-1.8
 Export-Package: org.simantics.image.ui,
index 4bebf357b55d14de2efd81f7c915ba7a2f9d16b9..7b12c1a8e6d5a52dcbd946e5c73cfc5d17738225 100644 (file)
@@ -3,11 +3,11 @@ import "Simantics/Misc"
 import "Simantics/Library"
 
 type Image = Resource
+type SVGImage = Resource
 
 importJava "org.simantics.image.ui.SCLImage" where
     @JavaName importImageFromFile
     importImage :: File -> Library -> <WriteGraph> Image
-  
-//  HN: does not exist  
-//    @JavaName linkImage
-//    linkImage :: SVGImage -> Image -> <WriteGraph> ()
\ No newline at end of file
+
+    @JavaName linkImage
+    linkImage :: SVGImage -> Image -> <WriteGraph> ()
diff --git a/bundles/org.simantics.image.ui/src/org/simantics/image/ui/LinkSvgImage.java b/bundles/org.simantics.image.ui/src/org/simantics/image/ui/LinkSvgImage.java
new file mode 100644 (file)
index 0000000..2e30e76
--- /dev/null
@@ -0,0 +1,189 @@
+package org.simantics.image.ui;
+
+import java.util.Vector;
+
+import org.simantics.databoard.Bindings;
+import org.simantics.db.ReadGraph;
+import org.simantics.db.Resource;
+import org.simantics.db.WriteGraph;
+import org.simantics.db.common.request.ReadRequest;
+import org.simantics.db.common.request.WriteRequest;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.layer0.variable.Variable;
+import org.simantics.db.layer0.variable.Variables;
+import org.simantics.diagram.function.PredefinedVariables;
+import org.simantics.diagram.stubs.DiagramResource;
+import org.simantics.image2.ontology.ImageResource;
+import org.simantics.modeling.template2d.ontology.Template2dResource;
+import org.simantics.project.ontology.ProjectResource;
+import org.simantics.simulation.ontology.SimulationResource;
+import org.simantics.utils.ui.dialogs.ShowMessage;
+
+public class LinkSvgImage {
+
+    public static void linkSVGImage(WriteGraph graph, final Resource parent, final Resource child) {
+
+        final String[] uri = {null};
+        final String[] msg = {null};
+        final String errmsg = "Creation of image reference failed. Activate an experiment and try to copy and paste an image again.";
+
+        try {
+            graph.syncRequest(new ReadRequest() {
+                @Override
+                public void run(ReadGraph g) throws DatabaseException {
+                    if (parent == null || child == null) {
+                        msg[0] = errmsg;
+                        return;
+                    }
+                    //Layer0 L0 = Layer0.getInstance(g);
+                    ImageResource IMG = ImageResource.getInstance(g);
+                    if (!g.isInstanceOf(child, IMG.SvgImage)){
+                        msg[0] = errmsg;
+                        return;
+                    }
+
+                    Variable parentV = Variables.getVariable(g, parent);
+                    if (parentV == null){
+                        msg[0] = errmsg;
+                        return;
+                    }
+
+                    Vector<Variable> grandOfParent = new Vector<Variable>();
+                    Variable tmp = parentV;
+                    do {
+                        grandOfParent.add(0, tmp);
+                        tmp = tmp.getParent(g);
+                    }
+                    while (tmp != null);
+
+//                  System.err.println(parentV.getURI(g));
+//                  String parentUri = parentV.getURI(g);
+
+                    Variable childV = Variables.getVariable(g, child);
+                    String childUri = null;
+                    if (childV == null){
+                        msg[0] = errmsg;
+                        return;
+                    }
+
+                    Vector<Variable> grandOfChild = new Vector<Variable>();
+                    tmp = childV;
+                    do {
+                        grandOfChild.add(0, tmp);
+                        tmp = tmp.getParent(g);
+                    }
+                    while (tmp != null);
+
+                    int k = -1; // index of the most nearest common parent
+                    int maxLen = (grandOfChild.size() < grandOfParent.size())? grandOfChild.size() : grandOfParent.size();
+                    for (int i = 0;i < maxLen; i++){
+                        if (grandOfChild.get(i).equals(grandOfParent.get(i)))
+                            k++;
+                        else
+                            break;
+                    }
+                    if (k == -1) // no common parent
+                    {
+                        msg[0] = errmsg;
+                        return;
+                    }
+                    //StructuralResource2 STR = StructuralResource2.getInstance(g);
+                    SimulationResource SIMU = SimulationResource.getInstance(g);
+                    ProjectResource PROJ = ProjectResource.getInstance(g);
+                    Template2dResource TEPLATE2D = Template2dResource.getInstance(g);
+                    Resource root = g.getRootLibrary();;
+                    Resource type = null;
+                    String predefined = null;
+                    Resource res = null;
+                    for (;k >= 0;k--){
+                        tmp = grandOfChild.get(k);
+                        res = tmp.getRepresents(g);
+                        if (res.equals(root)){
+                            predefined = PredefinedVariables.root;
+                            break;
+                        }
+                        type = g.getPossibleType(res, SIMU.Model);
+                        if (type != null){
+                            predefined = PredefinedVariables.model;
+                            break;
+                        }
+                        type = g.getPossibleType(res, PROJ.Project);
+                        if (type != null){
+                            predefined = PredefinedVariables.project;
+                            break;
+                        }
+                        type = g.getPossibleType(res, TEPLATE2D.DrawingTemplate);
+                        if (type != null){
+                            predefined = PredefinedVariables.template;
+                            break;
+                        }
+                    }
+                    if (predefined == null) // no predefined common parent
+                    {
+                        msg[0] = errmsg;
+                        return;
+                    }
+                    Variable resV = Variables.getVariable(g, res);
+                    String resUri = resV.getURI(g);
+
+                    childUri = childV.getURI(g);
+//                  System.err.println(childUri);
+
+                    Resource childModel = Variables.getModel(g, childV);
+                    Resource parentModel = Variables.getModel(g, parentV);
+                    if (childModel == null || parentModel == null){
+                        msg[0] = errmsg;
+                        return;
+                    }
+
+                    if (!parentModel.equals(childModel)){
+                        msg[0] = errmsg;
+                        return;
+                    }
+
+//                  Variable modelV = Variables.getVariable(g, childModel);
+//                  if (modelV == null){
+//                      msg[0] = errmsg[0];
+//                      return;
+//                  }
+//
+//                  String modelUri = modelV.getURI(g);
+
+                    if (childUri.startsWith(resUri)){
+                        uri[0] = childUri.substring(resUri.length());
+                        uri[0] = "pre:/" + predefined + uri[0];
+//                      System.err.println(uri);
+                    }
+                }
+            });
+            graph.syncRequest(new WriteRequest() {
+                @Override
+                public void perform(WriteGraph g) throws DatabaseException {
+                    if (uri == null || parent == null){
+                        msg[0] = errmsg;
+                        return;
+                    }
+                    DiagramResource DIA = DiagramResource.getInstance(g);
+                    Template2dResource TEMPLATE2D = Template2dResource.getInstance(g);
+
+                    Resource var = g.getPossibleObject(parent, DIA.Scenegraph_SVGImage_document);
+                    if (var == null){
+                        msg[0] = "Creation of image reference failed. Only SVG images are supported for now.";
+                        return;
+                    }
+
+                    g.claimLiteral(var, TEMPLATE2D.Profiles_VariableReference_path, uri[0] + "#data", Bindings.STRING);
+                }
+            });
+            if (msg[0] != null){
+                ShowMessage.showWarning("Warning", msg[0]);
+            }
+        } catch (Exception e) {
+            // TODO: handle exception
+            e.printStackTrace();
+        }
+
+    }
+
+
+}
index 1bb12a4d7af85cdfbce0336fbec043b5dd3b5c9a..1632653a3f435982f035b2f402ba3e0448f5c0fb 100644 (file)
@@ -8,16 +8,16 @@ import org.simantics.db.WriteGraph;
 import org.simantics.db.exception.DatabaseException;
 
 public class SCLImage {
-       
+
        public static Resource importImageFromFile(WriteGraph graph, File image, Resource target) throws DatabaseException, IOException {
-               
+
                ImageSource src = ImportImagesActionFactory.toImageSource(image);
                CreateImage img = new CreateImage(target, src);
                Resource imageResource = img.doImage(graph, target, src);
                return imageResource;
        }
-       
-//     public static void linkImage(WriteGraph graph, Resource parent, Resource child) {
-//             LinkSVGImage.linkSVGImage(graph, parent, child);
-//     }
-}
\ No newline at end of file
+
+    public static void linkImage(WriteGraph graph, Resource parent, Resource child) {
+        LinkSvgImage.linkSVGImage(graph, parent, child);
+    }
+}
index 93a01f258f61a64337ab84ed84c0733df7bd6b6a..7290f034b5a370790b60cebfec404cb856271165 100644 (file)
@@ -19,7 +19,8 @@ Require-Bundle: org.simantics.layer0.utils;bundle-version="0.8.0",
  org.simantics.modeling.template2d.ontology;bundle-version="1.0.0",
  org.simantics.annotation.ontology;bundle-version="1.0.0",
  org.simantics.graph.db;bundle-version="[1.1.9,2.0.0)",
- org.simantics.export.core;bundle-version="1.0.0"
+ org.simantics.export.core;bundle-version="1.0.0",
+ org.simantics.image.ui;bundle-version="1.0.0"
 Bundle-ActivationPolicy: lazy
 Bundle-RequiredExecutionEnvironment: JavaSE-1.8
 Export-Package: org.simantics.modeling.template2d.ui.function
index aa0527f80fd082622ded42dde092681d9c15dd5f..978128630c0e061eda87f2c5dd185935045abbf8 100644 (file)
 package org.simantics.modeling.template2d.ui.function;
 
-import java.util.Vector;
-
-import org.simantics.databoard.Bindings;
-import org.simantics.db.ReadGraph;
 import org.simantics.db.Resource;
 import org.simantics.db.WriteGraph;
-import org.simantics.db.common.request.ReadRequest;
-import org.simantics.db.common.request.WriteRequest;
-import org.simantics.db.exception.DatabaseException;
-import org.simantics.db.layer0.variable.Variable;
-import org.simantics.db.layer0.variable.Variables;
-import org.simantics.diagram.function.PredefinedVariables;
-import org.simantics.diagram.stubs.DiagramResource;
-import org.simantics.image2.ontology.ImageResource;
-import org.simantics.modeling.template2d.ontology.Template2dResource;
-import org.simantics.project.ontology.ProjectResource;
-import org.simantics.simulation.ontology.SimulationResource;
-import org.simantics.utils.ui.dialogs.ShowMessage;
+import org.simantics.image.ui.LinkSvgImage;
 
 public class LinkSVGImage {
-       
-    public static void linkSVGImage(WriteGraph graph, final Resource parent, final Resource child) {
-       
-       final String[] uri = {null};
-       final String[] msg = {null};
-       final String errmsg = "Creation of image reference failed. Activate an experiment and try to copy and paste an image again.";
-       
-       try {
-                       graph.syncRequest(new ReadRequest() {
-                               @Override
-                               public void run(ReadGraph g) throws DatabaseException {
-                                       if (parent == null || child == null) {
-                                               msg[0] = errmsg; 
-                                               return;
-                                       }
-                                       //Layer0 L0 = Layer0.getInstance(g);
-                                       ImageResource IMG = ImageResource.getInstance(g);
-                                       if (!g.isInstanceOf(child, IMG.SvgImage)){
-                                               msg[0] = errmsg; 
-                                               return;
-                                       }
-                                       
-                                       Variable parentV = Variables.getVariable(g, parent);
-                                       if (parentV == null){
-                                               msg[0] = errmsg; 
-                                               return;
-                                       }
-                                       
-                                       Vector<Variable> grandOfParent = new Vector<Variable>();
-                                       Variable tmp = parentV;
-                                       do {
-                                               grandOfParent.add(0, tmp);
-                                               tmp = tmp.getParent(g);
-                                       }
-                                       while (tmp != null);
-                                       
-//                                     System.err.println(parentV.getURI(g));
-//                                     String parentUri = parentV.getURI(g);
-                                       
-                                       Variable childV = Variables.getVariable(g, child);
-                                       String childUri = null;
-                                       if (childV == null){
-                                               msg[0] = errmsg; 
-                                               return;
-                                       }
-                                       
-                                       Vector<Variable> grandOfChild = new Vector<Variable>();
-                                       tmp = childV;
-                                       do {
-                                               grandOfChild.add(0, tmp);
-                                               tmp = tmp.getParent(g);
-                                       }
-                                       while (tmp != null);
-                                       
-                                       int k = -1; // index of the most nearest common parent
-                                       int maxLen = (grandOfChild.size() < grandOfParent.size())? grandOfChild.size() : grandOfParent.size(); 
-                                       for (int i = 0;i < maxLen; i++){
-                                               if (grandOfChild.get(i).equals(grandOfParent.get(i)))
-                                                       k++;
-                                               else
-                                                       break;
-                                       }
-                                       if (k == -1) // no common parent
-                                       {
-                                               msg[0] = errmsg; 
-                                               return;
-                                       }
-                                       //StructuralResource2 STR = StructuralResource2.getInstance(g);
-                                       SimulationResource SIMU = SimulationResource.getInstance(g);
-                                       ProjectResource PROJ = ProjectResource.getInstance(g);
-                    Template2dResource TEPLATE2D = Template2dResource.getInstance(g);
-                                       Resource root = g.getRootLibrary();;
-                                       Resource type = null;
-                                       String predefined = null;
-                                       Resource res = null;
-                                       for (;k >= 0;k--){
-                                               tmp = grandOfChild.get(k);
-                                               res = tmp.getRepresents(g);
-                                               if (res.equals(root)){
-                                                       predefined = PredefinedVariables.root;
-                                                       break;
-                                               }
-                                               type = g.getPossibleType(res, SIMU.Model);
-                                               if (type != null){
-                                                       predefined = PredefinedVariables.model;
-                                                       break;
-                                               }
-                                               type = g.getPossibleType(res, PROJ.Project);
-                                               if (type != null){
-                                                       predefined = PredefinedVariables.project;
-                                                       break;
-                                               }
-                                               type = g.getPossibleType(res, TEPLATE2D.DrawingTemplate);
-                                               if (type != null){
-                                                       predefined = PredefinedVariables.template;
-                                                       break;
-                                               }
-                                       }
-                                       if (predefined == null) // no predefined common parent
-                                       {
-                                               msg[0] = errmsg; 
-                                               return;
-                                       }
-                                       Variable resV = Variables.getVariable(g, res);
-                                       String resUri = resV.getURI(g);
-                                       
-                                       childUri = childV.getURI(g);
-//                                     System.err.println(childUri);
-
-                                       Resource childModel = Variables.getModel(g, childV);
-                                       Resource parentModel = Variables.getModel(g, parentV);
-                                       if (childModel == null || parentModel == null){
-                                               msg[0] = errmsg; 
-                                               return;
-                                       }
-                                       
-                                       if (!parentModel.equals(childModel)){
-                                               msg[0] = errmsg;
-                                               return;
-                                       }
-
-//                                     Variable modelV = Variables.getVariable(g, childModel);
-//                                     if (modelV == null){
-//                                             msg[0] = errmsg[0];
-//                                             return;
-//                                     }
-//                                     
-//                                     String modelUri = modelV.getURI(g);
-
-                                       if (childUri.startsWith(resUri)){
-                                               uri[0] = childUri.substring(resUri.length());
-                                               uri[0] = "pre:/" + predefined + uri[0];
-//                                             System.err.println(uri);
-                                       }
-                               }
-                       });
-                       graph.syncRequest(new WriteRequest() {
-                               @Override
-                               public void perform(WriteGraph g) throws DatabaseException {
-                                       if (uri == null || parent == null){
-                                               msg[0] = errmsg;
-                                               return;
-                                       }
-                                       DiagramResource DIA = DiagramResource.getInstance(g);
-                    Template2dResource TEMPLATE2D = Template2dResource.getInstance(g);
-
-                                       Resource var = g.getPossibleObject(parent, DIA.Scenegraph_SVGImage_document);
-                                       if (var == null){
-                                               msg[0] = "Creation of image reference failed. Only SVG images are supported for now.";
-                                               return;
-                                       }
-                                       
-                                       g.claimLiteral(var, TEMPLATE2D.Profiles_VariableReference_path, uri[0] + "#data", Bindings.STRING);
-                               }
-                       });
-                       if (msg[0] != null){
-                               ShowMessage.showWarning("Warning", msg[0]);
-                       }
-               } catch (Exception e) {
-                       // TODO: handle exception
-                       e.printStackTrace();
-               }
-       
-       }
-       
 
+    public static void linkSVGImage(WriteGraph graph, final Resource parent, final Resource child) {
+        // Moved the implementation to LinkSvgImage because problems compiler warning/error:
+        // A cycle was detected in the build path of project.
+        LinkSvgImage.linkSVGImage(graph, parent, child);
+    }
 }
\ No newline at end of file
index 4ee96f75d8e062fad53dea40bc81e30c997e5b2a..29f06967e26755c6c6b10f057a302766e50cba81 100644 (file)
@@ -25,7 +25,7 @@ public enum PageSettingsTypicalRule implements ITypicalSynchronizationRule {
        public boolean synchronize(WriteGraph graph, Resource template, Resource instance, TypicalInfo info) throws DatabaseException {
                DiagramDesc mdesc = graph.syncRequest(DiagramRequests.getDiagramDesc(template));
                DiagramDesc idesc = graph.syncRequest(DiagramRequests.getDiagramDesc(instance));
-               if (mdesc.equals(idesc))
+               if (null == mdesc || mdesc.equals(idesc))
                        return false;
 
                DiagramGraphUtil.setDiagramDesc(graph, instance, mdesc);