Merge "Fixed Path2D creation to work with overlapping RoutePoints"
authorTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Thu, 20 Feb 2020 11:35:13 +0000 (11:35 +0000)
committerGerrit Code Review <gerrit2@simantics>
Thu, 20 Feb 2020 11:35:13 +0000 (11:35 +0000)
bundles/org.simantics.diagram/src/org/simantics/diagram/elements/TextElementHandler.java
bundles/org.simantics.diagram/src/org/simantics/diagram/elements/TextElementNoBounds.java
bundles/org.simantics.modeling.ontology/graph/Modeling.pgraph
bundles/org.simantics.modeling/scl/Simantics/Testing.scl
bundles/org.simantics.modeling/src/org/simantics/modeling/ContentDumps.java [new file with mode: 0644]
bundles/org.simantics.modeling/src/org/simantics/modeling/utils/DumpOntologyStructure.java
bundles/org.simantics.modeling/src/org/simantics/modeling/utils/HeadlessComponentTypePropertiesResultRequest.java
bundles/org.simantics.structural2/src/org/simantics/structural2/ConnectionImpl2.java

index a39ef4f5790ccd7556d976350d6883c8818a7277..192b0ea5d09588c783561dc1133d5ad571af5823 100644 (file)
@@ -52,10 +52,14 @@ public class TextElementHandler extends TextElementNoBounds implements InternalS
         super(originX, originY, horizontalAlignment, borderWidth, paddingX, paddingY, editable);
     }
     
+    public TextElementHandler(double originX, double originY, Alignment horizontalAlignment, double borderWidth,
+                       double paddingX, double paddingY, boolean editable, double scale) {
+               super(originX, originY, horizontalAlignment, borderWidth, paddingX, paddingY, editable, scale);
+       }
 
-    @Override
+       @Override
     public Rectangle2D getBounds(IElement e, Rectangle2D size) {
-        return calculateBounds(e, size, horizontalAlignment, SCALE, paddingX, paddingY);
+        return calculateBounds(e, size, horizontalAlignment, scale, paddingX, paddingY);
     }
     
     public static Rectangle2D calculateBounds(
index 6959e8c439f2bbd4d942eae1137682e687952015..376fadc06c9a40cab935eafb421e6e4534510328 100644 (file)
@@ -49,7 +49,7 @@ public class TextElementNoBounds implements SceneGraph, HandleMouseEvent {
     
     protected static final double DEFAULT_PADDING_X = 0.5;
     protected static final double DEFAULT_PADDING_Y = 0.5;
-    protected static final double SCALE = 0.235;
+    protected static final double DEFAULT_SCALE = 0.235;
 
     protected final double originX;
     protected final double originY;
@@ -59,6 +59,7 @@ public class TextElementNoBounds implements SceneGraph, HandleMouseEvent {
     protected final boolean editable;
     protected final double paddingX;
     protected final double paddingY;
+    protected final double scale;
 
 
     public TextElementNoBounds() {
@@ -74,6 +75,10 @@ public class TextElementNoBounds implements SceneGraph, HandleMouseEvent {
     }
     
     public TextElementNoBounds(double originX, double originY, Alignment horizontalAlignment, double borderWidth, double paddingX, double paddingY, boolean editable) {
+       this(originX, originY, horizontalAlignment, borderWidth, paddingX, paddingY, editable, DEFAULT_SCALE);
+    }
+    
+    public TextElementNoBounds(double originX, double originY, Alignment horizontalAlignment, double borderWidth, double paddingX, double paddingY, boolean editable, double scale) {
         if (horizontalAlignment == null)
             throw new NullPointerException("null horizontal alignment");
 
@@ -85,9 +90,9 @@ public class TextElementNoBounds implements SceneGraph, HandleMouseEvent {
         this.editable = editable;
         this.paddingX = paddingX;
         this.paddingY = paddingY;
+        this.scale = scale;
     }
     
-
     @Override
     public void init(final IElement e, G2DParentNode parent) {
         TextNode node = getOrCreateTextNode(e, parent);
@@ -102,7 +107,7 @@ public class TextElementNoBounds implements SceneGraph, HandleMouseEvent {
         Alignment vAlign = ElementUtils.getHintOrDefault(e, ElementHints.KEY_VERTICAL_ALIGN, verticalAlignment);
         Double borderWidth = ElementUtils.getHintOrDefault(e, MonitorClass.KEY_BORDER_WIDTH, this.borderWidth);
 
-        node.init(text, font, color, originX, originY, SCALE);
+        node.init(text, font, color, originX, originY, scale);
         node.setBackgroundColor(fillColor);
         node.setBorderColor(borderColor);
         node.setHorizontalAlignment((byte) hAlign.ordinal());
index dca29f9bf75e38804bccd47ddf5e4c3461d61379..52a37f738ca76566ede5fe44d1589a174c042536 100644 (file)
@@ -536,4 +536,28 @@ MOD.IssueDecorationStyle : DIA.Style
 
 MOD.PreferredDiagramEditorID <R L0.HasProperty : L0.FunctionalRelation
     L0.HasDomain STR.Composite
-    L0.HasRange  L0.String
\ No newline at end of file
+    L0.HasRange  L0.String
+    
+MOD.contentDumpFunction ==> "Resource -> <ReadGraph> Vector Byte" <R L0.HasProperty : L0.FunctionalRelation
+
+// We need to define the function inside this ontology to give it the right evaluation context
+L0.SCLModule
+  MOD.contentDumpFunction
+    MOD.SCLModuleContentDumpFunction
+      @L0.sclValue "sclModuleContentDump" "Resource -> <ReadGraph> Vector Byte"
+
+L0.PGraph
+  MOD.contentDumpFunction
+    MOD.PGraphContentDumpFunction
+      @L0.sclValue "pgraphContentDump" "Resource -> <ReadGraph> Vector Byte"
+
+STR.Component
+  MOD.contentDumpFunction
+    MOD.StructuralComponentContentDumpFunction
+      @L0.sclValue "structuralComponentContentDump" "Resource -> <ReadGraph> Vector Byte"
+      
+SEL.GenericParameterType
+  MOD.contentDumpFunction
+    MOD.GenericParameterTypeContentDumpFunction
+      @L0.sclValue "genericParameterTypeContentDump" "Resource -> <ReadGraph> Vector Byte"
+    
\ No newline at end of file
index ce70dd0341eefa69d6e677bbc6433f40a5cd6a36..5742b4f41bd693c9b490abde6a54931f77849e7d 100644 (file)
@@ -4,3 +4,10 @@ include "Simantics/Variables"
 importJava "org.simantics.modeling.ModelingUtils" where
   withinEpsilon :: Double -> Double -> Double -> String
   exportModel :: Resource -> String -> String -> Integer -> <ReadGraph> ()
+  
+importJava "org.simantics.modeling.ContentDumps" where
+  sclModuleContentDump :: Resource -> <ReadGraph> Vector Byte
+  pgraphContentDump :: Resource -> <ReadGraph> Vector Byte
+  structuralComponentContentDump :: Resource -> <ReadGraph> Vector Byte
+  genericParameterTypeContentDump :: Resource -> <ReadGraph> Vector Byte
+  
diff --git a/bundles/org.simantics.modeling/src/org/simantics/modeling/ContentDumps.java b/bundles/org.simantics.modeling/src/org/simantics/modeling/ContentDumps.java
new file mode 100644 (file)
index 0000000..bc3b65a
--- /dev/null
@@ -0,0 +1,112 @@
+package org.simantics.modeling;
+
+import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
+import java.util.TreeMap;
+import java.util.TreeSet;
+
+import org.simantics.databoard.Bindings;
+import org.simantics.db.ReadGraph;
+import org.simantics.db.Resource;
+import org.simantics.db.common.utils.CommonDBUtils;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.layer0.variable.Variable;
+import org.simantics.db.layer0.variable.Variables;
+import org.simantics.graphfile.ontology.GraphFileResource;
+import org.simantics.layer0.Layer0;
+import org.simantics.modeling.utils.ComponentTypeViewerPropertyInfo;
+import org.simantics.modeling.utils.HeadlessComponentTypePropertiesResultRequest;
+import org.simantics.structural.stubs.StructuralResource2;
+import org.simantics.structural2.variables.Connection;
+import org.simantics.structural2.variables.VariableConnectionPointDescriptor;
+
+public class ContentDumps {
+    
+    private static Charset UTF8 = StandardCharsets.UTF_8;
+
+    public static byte[] sclModuleContentDump(ReadGraph graph, Resource resource) throws DatabaseException {
+        Layer0 L0 = Layer0.getInstance(graph);
+        String def = graph.getRelatedValue(resource, L0.SCLModule_definition, Bindings.STRING); 
+        return def.getBytes(UTF8);
+    }
+
+    public static byte[] pgraphContentDump(ReadGraph graph, Resource resource) throws DatabaseException {
+        Layer0 L0 = Layer0.getInstance(graph);
+        String def = graph.getRelatedValue(resource, L0.PGraph_definition, Bindings.STRING); 
+        return def.getBytes(UTF8);
+    }
+
+    public static byte[] graphFileContentDump(ReadGraph graph, Resource resource) throws DatabaseException {
+        GraphFileResource GF = GraphFileResource.getInstance(graph);
+        return graph.getRelatedValue(resource, GF.HasFiledata, Bindings.BYTE_ARRAY); 
+    }
+
+    public static byte[] structuralComponentContentDump(ReadGraph graph, Resource resource) throws DatabaseException {
+
+        StringBuilder dump = new StringBuilder();
+
+        Variable v = Variables.getVariable(graph, resource);
+        
+        TreeSet<String> types = new TreeSet<>();
+        for(Resource t : graph.getPrincipalTypes(resource)) {
+            types.add(graph.getURI(t));
+        }
+        for(String uri : types) {
+            dump.append(uri);
+            dump.append("\n");
+        }
+
+        TreeMap<String,Variable> properties = new TreeMap<>();
+        for(Variable property : v.getProperties(graph))
+            properties.put(property.getName(graph), property);
+        for(Variable property : properties.values()) {
+            String possibleValue = property.getPossiblePropertyValue(graph, "HasDisplayValue", Bindings.STRING);
+            if(possibleValue != null) {
+                dump.append(property.getName(graph));
+                dump.append(" ");
+                dump.append(possibleValue);
+                dump.append("\n");
+            }
+            if(property.getClassifications(graph).contains(StructuralResource2.URIs.ConnectionRelation)) {
+                dump.append(property.getName(graph));
+                Connection c = property.getValue(graph);
+                TreeSet<String> rvis = new TreeSet<>();
+                for(VariableConnectionPointDescriptor desc : c.getConnectionPointDescriptors(graph, null)) {
+                    rvis.add(desc.getRelativeRVI(graph, v));
+                }
+                for(String rvi : rvis) {
+                    dump.append(" ");
+                    dump.append(rvi);
+                }
+                dump.append("\n");
+            }
+        }
+        return dump.toString().getBytes(UTF8);
+    }
+
+    public static byte[] genericParameterTypeContentDump(ReadGraph graph, Resource resource) throws DatabaseException {
+
+        Layer0 L0 = Layer0.getInstance(graph);
+        StructuralResource2 STR = StructuralResource2.getInstance(graph);
+        Resource componentType = CommonDBUtils.possibleObjectWithType(graph, resource, L0.PartOf, STR.ComponentType);
+        
+        ComponentTypeViewerPropertyInfo pi = HeadlessComponentTypePropertiesResultRequest.readPropertyInfo(graph, resource, componentType, false);
+        StringBuilder dump = new StringBuilder();
+        dump.append(pi.type);
+        dump.append(" ");
+        dump.append(pi.defaultValue);
+        if(pi.unit != null) {
+            dump.append(" ");
+            dump.append(pi.unit);
+        }
+        dump.append(" ");
+        dump.append(pi.label);
+        if(pi.description != null) {
+            dump.append(" ");
+            dump.append(pi.description);
+        }
+        return dump.toString().getBytes(UTF8);
+        
+    }
+
+}
index a2d9e5c1245695dfc1c23f38cb60009e9c1a492d..79622f15e5839bf1cae00c32dc228e75967eb427 100644 (file)
@@ -2,211 +2,102 @@ package org.simantics.modeling.utils;
 
 import java.io.File;
 import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.util.Collection;
 import java.util.HashMap;
-import java.util.HashSet;
 import java.util.Map;
-import java.util.Set;
 import java.util.TreeMap;
-import java.util.TreeSet;
 
-import org.simantics.databoard.Bindings;
+import org.simantics.Simantics;
 import org.simantics.db.ReadGraph;
 import org.simantics.db.Resource;
-import org.simantics.db.common.NamedResource;
 import org.simantics.db.common.utils.CommonDBUtils;
 import org.simantics.db.common.utils.NameUtils;
 import org.simantics.db.exception.DatabaseException;
 import org.simantics.db.layer0.variable.Variable;
 import org.simantics.db.layer0.variable.Variables;
-import org.simantics.graphfile.ontology.GraphFileResource;
 import org.simantics.layer0.Layer0;
-import org.simantics.structural.stubs.StructuralResource2;
-import org.simantics.structural2.variables.Connection;
-import org.simantics.structural2.variables.VariableConnectionPointDescriptor;
+import org.simantics.modeling.ModelingResources;
+import org.simantics.scl.runtime.function.Function;
 import org.simantics.utils.FileUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import gnu.trove.list.array.TByteArrayList;
 
 public class DumpOntologyStructure {
 
+    private static final Logger LOGGER = LoggerFactory.getLogger(DumpOntologyStructure.class);
+
     private Resource ontology;
     
-    private Set<Resource> containers = new HashSet<>(); 
-    private Set<Resource> folders = new HashSet<>();
     private Map<Resource, String> names = new HashMap<>();
     private Map<Resource,Resource> parents = new HashMap<>();
     private Map<Resource, File> libraryFolders = new HashMap<>();
-    private Set<Resource> modules = new HashSet<>();
-    private Map<Resource, String> moduleCodes = new HashMap<>();
-    private Set<Resource> pgraphs = new HashSet<>();
-    private Map<Resource, String> pgraphCodes = new HashMap<>();
-    private Set<Resource> graphFiles = new HashSet<>();
-    private Map<Resource, byte[]> graphFileBytes = new HashMap<>();
-    private Set<Resource> componentTypes = new HashSet<>();
-    private Map<Resource, String> componentTypeDumps = new HashMap<>();
-    private Set<Resource> components = new HashSet<>();
-    private Map<Resource, String> componentDumps = new HashMap<>();
+    private Map<Resource, byte[]> contentDumps = new HashMap<>();
 
     private void readNameAndParent(ReadGraph graph, Resource container, Resource r) throws DatabaseException {
         parents.put(r, container);
         names.put(r, NameUtils.getSafeName(graph, r));
     }
     
-    private void readLibraries(ReadGraph graph, Resource container) throws DatabaseException {
-        Layer0 L0 = Layer0.getInstance(graph);
-        for(Resource r : CommonDBUtils.objectsWithType(graph, container, L0.ConsistsOf, L0.Library)) {
-            folders.add(r);
-            names.put(r, NameUtils.getSafeName(graph, r));
-            parents.put(r, container);
-            readNameAndParent(graph, container, r);
-            readLibraries(graph, r);
-        }
-        containers.addAll(folders);
+    private Collection<Resource> containers() {
+        return parents.values();
     }
     
-    private void readComponentTypes(ReadGraph graph) throws DatabaseException {
-        Layer0 L0 = Layer0.getInstance(graph);
-        StructuralResource2 STR = StructuralResource2.getInstance(graph);
-        for(Resource container : containers) {
-            for(Resource r : CommonDBUtils.objectsWithType(graph, container, L0.ConsistsOf, STR.ComponentType)) {
-                folders.add(r);
-                componentTypes.add(r);
-                readNameAndParent(graph, container, r);
-                ComponentTypePropertiesResult data = graph.syncRequest(new HeadlessComponentTypePropertiesResultRequest(r));
-                StringBuilder dump = new StringBuilder();
-                for(ComponentTypeViewerPropertyInfo pi : data.getProperties()) {
-                    dump.append(pi.name);
-                    dump.append(" ");
-                    dump.append(pi.type);
-                    dump.append(" ");
-                    dump.append(pi.defaultValue);
-                    if(pi.unit != null) {
-                        dump.append(" ");
-                        dump.append(pi.unit);
-                    }
-                    dump.append(" ");
-                    dump.append(pi.label);
-                    if(pi.description != null) {
-                        dump.append(" ");
-                        dump.append(pi.description);
-                    }
-                    dump.append("\n");
-                }
-                for(NamedResource nr : data.getConnectionPoints()) {
-                    dump.append("cp ");
-                    dump.append(nr.getName());
-                    dump.append("\n");
-                }
-                componentTypeDumps.put(r, dump.toString());
-            }
-        }
-        containers.addAll(folders);
-    }
-
-    private void readComposites(ReadGraph graph) throws DatabaseException {
+    private void readHierarchy(ReadGraph graph, Resource container) throws DatabaseException {
         Layer0 L0 = Layer0.getInstance(graph);
-        StructuralResource2 STR = StructuralResource2.getInstance(graph);
-        for(Resource container : containers) {
-            for(Resource r : CommonDBUtils.objectsWithType(graph, container, L0.ConsistsOf, STR.Composite)) {
-                folders.add(r);
+        for(Resource r : CommonDBUtils.objectsWithType(graph, container, L0.ConsistsOf, L0.Entity)) {
+            try {
                 readNameAndParent(graph, container, r);
+                readHierarchy(graph, r);
+            } catch (DatabaseException e) {
+                LOGGER.error("Error while reading content dump hierarchy for " + r, e);
             }
         }
-        containers.addAll(folders);
     }
 
-    private void readComponents(ReadGraph graph) throws DatabaseException {
-        Layer0 L0 = Layer0.getInstance(graph);
-        StructuralResource2 STR = StructuralResource2.getInstance(graph);
-        for(Resource container : containers) {
-            for(Resource r : CommonDBUtils.objectsWithType(graph, container, L0.ConsistsOf, STR.Component)) {
-                if(folders.contains(r))
-                    continue;
-                components.add(r);
-                readNameAndParent(graph, container, r);
-                Variable v = Variables.getVariable(graph, r);
-                TreeMap<String,Variable> properties = new TreeMap<>();
-                for(Variable property : v.getProperties(graph))
-                    properties.put(property.getName(graph), property);
-                StringBuilder dump = new StringBuilder();
-                for(Variable property : properties.values()) {
-                    String possibleValue = property.getPossiblePropertyValue(graph, "HasDisplayValue", Bindings.STRING);
-                    if(possibleValue != null) {
-                        dump.append(property.getName(graph));
-                        dump.append(" ");
-                        dump.append(possibleValue);
-                        dump.append("\n");
-                    }
-                    if(property.getClassifications(graph).contains(StructuralResource2.URIs.ConnectionRelation)) {
-                        dump.append(property.getName(graph));
-                        Connection c = property.getValue(graph);
-                        TreeSet<String> rvis = new TreeSet<>();
-                        for(VariableConnectionPointDescriptor desc : c.getConnectionPointDescriptors(graph, null)) {
-                            rvis.add(desc.getRelativeRVI(graph, v));
-                        }
-                        for(String rvi : rvis) {
-                            dump.append(" ");
-                            dump.append(rvi);
+    private void readGeneric(ReadGraph graph) throws DatabaseException {
+        ModelingResources MOD = ModelingResources.getInstance(graph);
+        for(Resource r : parents.keySet()) {
+            if(contentDumps.containsKey(r))
+                continue;
+            TByteArrayList result = new TByteArrayList();
+            try {
+                TreeMap<String,Resource> sortedTypes = new TreeMap<>();
+                for(Resource type : graph.getTypes(r)) {
+                    String uri = graph.getPossibleURI(type);
+                    if(uri != null)
+                        sortedTypes.put(uri, type);
+                }
+                for(Resource type : sortedTypes.values()) {
+                    try {
+                        Variable typeVariable = Variables.getVariable(graph, type);
+                        @SuppressWarnings("rawtypes")
+                        Function f = typeVariable.getPossiblePropertyValue(graph, MOD.contentDumpFunction);
+                        if(f != null) {
+                            @SuppressWarnings("unchecked")
+                            byte[] dump = (byte[])Simantics.applySCLRead(graph, f, r);
+                            if(dump != null) {
+                                result.add(dump);
+                            }
                         }
-                        dump.append("\n");
+                    } catch (DatabaseException e) {
+                        LOGGER.error("Error while computing content dump for " + r, e);
                     }
                 }
-                componentDumps.put(r, dump.toString());
-            }
-        }
-    }
-
-    private void readSCLModules(ReadGraph graph) throws DatabaseException {
-        Layer0 L0 = Layer0.getInstance(graph);
-        for(Resource container : containers) {
-            for(Resource r : CommonDBUtils.objectsWithType(graph, container, L0.ConsistsOf, L0.SCLModule)) {
-                String code = graph.getPossibleRelatedValue(r, L0.SCLModule_definition, Bindings.STRING);
-                if(code != null) {
-                    moduleCodes.put(r, code);
-                }
-                modules.add(r);
-                readNameAndParent(graph, container, r);
-            }
-        }
-    }
-    
-    private void readPGraphs(ReadGraph graph) throws DatabaseException {
-        Layer0 L0 = Layer0.getInstance(graph);
-        for(Resource container : containers) {
-            for(Resource r : CommonDBUtils.objectsWithType(graph, container, L0.ConsistsOf, L0.PGraph)) {
-                String code = graph.getPossibleRelatedValue(r, L0.PGraph_definition, Bindings.STRING);
-                if(code != null) {
-                    pgraphCodes.put(r, code);
-                }
-                pgraphs.add(r);
-                readNameAndParent(graph, container, r);
-            }
-        }
-    }
-
-    private void readGraphFiles(ReadGraph graph) throws DatabaseException {
-        Layer0 L0 = Layer0.getInstance(graph);
-        GraphFileResource GF = GraphFileResource.getInstance(graph);
-        for(Resource container : containers) {
-            for(Resource r : CommonDBUtils.objectsWithType(graph, container, L0.ConsistsOf, GF.File)) {
-                byte[] bytes = graph.getPossibleRelatedValue(r, GF.HasFiledata, Bindings.BYTE_ARRAY);
-                if(bytes != null) {
-                    graphFileBytes.put(r, bytes);
-                }
-                graphFiles.add(r);
-                readNameAndParent(graph, container, r);
+                if(result.size() > 0)
+                    contentDumps.put(r, result.toArray());
+            } catch (DatabaseException e) {
+                LOGGER.error("Error while computing content dump for " + r, e);
             }
         }
     }
 
     public void read(ReadGraph graph, Resource ontology) throws DatabaseException {
         this.ontology = ontology;
-        containers.add(ontology);
-        readLibraries(graph, ontology);
-        readComponentTypes(graph);
-        readComposites(graph);
-        readComponents(graph);
-        readSCLModules(graph);
-        readPGraphs(graph);
-        readGraphFiles(graph);
+        readHierarchy(graph, ontology);
+        readGeneric(graph);
     }
     
     private File escapeFile(File file) {
@@ -223,69 +114,58 @@ public class DumpOntologyStructure {
         if(folder.exists())
             FileUtils.deleteAll(folder);
         folder.mkdirs();
-        writeLibraries(folder);
-        writeSCLModules(folder);
-        writePGraphs(folder);
-        writeGraphFiles(folder);
-        writeComponentTypes(folder);
-        writeComponents(folder);
+        writeDirectories(folder);
+        writeResources(folder);
     }
     
     private File getFolder(File root, Resource library) {
         if(ontology.equals(library))
             return root;
         Resource parent = parents.get(library);
+        if(parent == null)
+            throw new IllegalStateException("null parent for " + library);
         File parentFolder = getFolder(root, parent);
         return new File(parentFolder, FileUtils.escapeFileName(names.get(library))); 
     }
-    
-    private File getParentFolder(File root, Resource r) {
-        Resource parent = parents.get(r);
-        return getFolder(root, parent);
-    }
 
-    private File getFile(File root, Resource r) {
-        return new File(getParentFolder(root, r), FileUtils.escapeFileName(names.get(r)));
+    private File getFile(File rootFolder, Resource r) {
+        Resource parent = parents.get(r);
+        File folder = getFolder(rootFolder, parent);
+        return new File(folder, FileUtils.escapeFileName(names.get(r)));
     }
 
-    private void writeLibraries(File rootFolder) {
-        for(Resource library : folders) {
+    private void writeDirectories(File rootFolder) {
+        for(Resource library : containers()) {
             File folder = getFolder(rootFolder, library);
             folder.mkdirs();
             libraryFolders.put(library, folder);
         }
     }
-    
-    private void writeSCLModules(File rootFolder) throws IOException {
-        for(Resource r : modules) {
-            FileUtils.writeFile(getFile(rootFolder, r), moduleCodes.get(r).getBytes());
+
+    private void writeResources(File rootFolder) throws IOException {
+        for(Resource r : parents.keySet()) {
+            writeResource(rootFolder, r);
         }
     }
     
-    private void writePGraphs(File rootFolder) throws IOException {
-        for(Resource r : pgraphs) {
-            FileUtils.writeFile(getFile(rootFolder, r), pgraphCodes.get(r).getBytes());
-        }
+    private boolean isParent(Resource r) {
+        return parents.values().contains(r);
     }
-
-    private void writeGraphFiles(File rootFolder) throws IOException {
-        for(Resource r : graphFiles) {
-            FileUtils.writeFile(getFile(rootFolder, r), graphFileBytes.get(r));
+    
+    private void writeResource(File rootFolder, Resource resource) throws IOException {
+        byte[] dump = contentDumps.get(resource);
+        if(dump == null)
+            dump = "".getBytes(StandardCharsets.UTF_8);
+        if(isParent(resource)) {
+            if(dump.length > 0)
+                FileUtils.writeFile(new File(getFolder(rootFolder, resource), "__contents__"), dump);
+        } else {
+            write(rootFolder, resource, dump);
         }
     }
 
-    private void writeComponentTypes(File rootFolder) throws IOException {
-        for(Resource r : componentTypes) {
-            File folder = getFolder(rootFolder, r);
-            File file = new File(folder, "__interface__");
-            FileUtils.writeFile(file, componentTypeDumps.get(r).getBytes());
-        }
+    private void write(File rootFolder, Resource resource, byte[] bytes) throws IOException {
+        FileUtils.writeFile(getFile(rootFolder, resource), bytes);
     }
 
-    private void writeComponents(File rootFolder) throws IOException {
-        for(Resource r : components) {
-            FileUtils.writeFile(getFile(rootFolder, r), componentDumps.get(r).getBytes());
-        }
-    }
-    
 }
index a2f7138b44bdd048c8b5dee813d1d9e9bfaaee85..757643dbdfded2aea7b3c2e9a307132fef4f040f 100644 (file)
@@ -52,12 +52,70 @@ public class HeadlessComponentTypePropertiesResultRequest extends UniqueRead<Com
     protected void readSectionSpecificData(ReadGraph graph, ComponentTypeViewerPropertyInfo info) throws DatabaseException {
     }
     
+    public static ComponentTypeViewerPropertyInfo readPropertyInfo(ReadGraph graph, Resource relation, Resource componentType, boolean typeIsImmutable) throws DatabaseException {
+
+        Layer0 L0 = Layer0.getInstance(graph);
+        Layer0X L0X = Layer0X.getInstance(graph);
+        StructuralResource2 STR = StructuralResource2.getInstance(graph);
+
+        String name = graph.getRelatedValue(relation, L0.HasName);
+        String type =  graph.getPossibleRelatedValue(relation, L0.RequiresValueType);
+        String label = graph.getPossibleRelatedValue(relation, L0.HasLabel);
+        if (label == null)
+            label = ""; //$NON-NLS-1$
+        String description = graph.getPossibleRelatedValue(relation, L0.HasDescription);
+        if (description == null)
+            description = ""; //$NON-NLS-1$
+        NumberType numberType = null;
+        if(type == null)
+            type = "Double"; //$NON-NLS-1$
+        String unit = graph.getPossibleRelatedValue(relation, L0X.HasUnit, Bindings.STRING);
+        String defaultValue = "0"; //$NON-NLS-1$
+        String expression = null;
+
+        if(componentType != null) {
+            for(Resource assertion : graph.getAssertedObjects(componentType, relation)) {
+                try {
+                    expression = graph.getPossibleRelatedValue(assertion, L0.SCLValue_expression, Bindings.STRING);
+                    if(expression != null) {
+                        defaultValue = "=" + expression; //$NON-NLS-1$
+                    } else if (graph.sync(new IsEnumeratedValue(assertion))) {
+                        defaultValue = CommonDBUtils.getEnumerationValueName(graph, assertion);
+                    } else {
+                        Datatype dt = getPossibleDatatype(graph, assertion);
+                        if (dt == null)
+                            continue;
+                        if (dt instanceof NumberType)
+                            numberType = (NumberType) dt;
+                        Binding binding = Bindings.getBinding(dt);
+                        Object value = graph.getValue(assertion, binding);
+                        try {
+                            defaultValue = binding.toString(value, true);
+                        } catch (BindingException e) {
+                            ErrorLogger.defaultLogError(e);
+                        }
+                    }
+                } catch(DatabaseException e) {
+                    ErrorLogger.defaultLogError(e);
+                }
+            }
+        }
+
+        String valid = expression != null ? validateMonitorExpression(graph, componentType, relation, expression) : null; 
+
+        boolean immutable = typeIsImmutable || graph.isImmutable(relation);
+        ComponentTypeViewerPropertyInfo info =
+                new ComponentTypeViewerPropertyInfo(relation, name, type, defaultValue, numberType, unit, label, description, expression, valid, immutable);
+
+        return info;
+            
+    }
+    
     @Override
     public ComponentTypePropertiesResult perform(ReadGraph graph) throws DatabaseException {
         List<ComponentTypeViewerPropertyInfo> result = new ArrayList<>();
         List<NamedResource> connectionPoints = new ArrayList<>();
         Layer0 L0 = Layer0.getInstance(graph);
-        Layer0X L0X = Layer0X.getInstance(graph);
         StructuralResource2 STR = StructuralResource2.getInstance(graph);
 
         boolean typeIsImmutable = graph.isImmutable(componentType)
@@ -67,67 +125,22 @@ public class HeadlessComponentTypePropertiesResultRequest extends UniqueRead<Com
 
         for(Resource relation : graph.getObjects(componentType, L0.DomainOf)) {
             if(graph.isSubrelationOf(relation, L0.HasProperty)) {
-                String name = graph.getRelatedValue(relation, L0.HasName);
-                String type =  graph.getPossibleRelatedValue(relation, L0.RequiresValueType);
-                String label = graph.getPossibleRelatedValue(relation, L0.HasLabel);
-                if (label == null)
-                    label = ""; //$NON-NLS-1$
-                String description = graph.getPossibleRelatedValue(relation, L0.HasDescription);
-                if (description == null)
-                    description = ""; //$NON-NLS-1$
-                NumberType numberType = null;
-                if(type == null)
-                    type = "Double"; //$NON-NLS-1$
-                String unit = graph.getPossibleRelatedValue(relation, L0X.HasUnit, Bindings.STRING);
-                String defaultValue = "0"; //$NON-NLS-1$
-                String expression = null;
-                
-                for(Resource assertion : graph.getAssertedObjects(componentType, relation)) {
-                    try {
-                        expression = graph.getPossibleRelatedValue(assertion, L0.SCLValue_expression, Bindings.STRING);
-                        if(expression != null) {
-                               defaultValue = "=" + expression; //$NON-NLS-1$
-                        } else if (graph.sync(new IsEnumeratedValue(assertion))) {
-                            defaultValue = CommonDBUtils.getEnumerationValueName(graph, assertion);
-                        } else {
-                            Datatype dt = getPossibleDatatype(graph, assertion);
-                            if (dt == null)
-                                continue;
-                            if (dt instanceof NumberType)
-                                numberType = (NumberType) dt;
-                            Binding binding = Bindings.getBinding(dt);
-                            Object value = graph.getValue(assertion, binding);
-                            try {
-                                defaultValue = binding.toString(value, true);
-                            } catch (BindingException e) {
-                                ErrorLogger.defaultLogError(e);
-                            }
-                        }
-                    } catch(DatabaseException e) {
-                        ErrorLogger.defaultLogError(e);
-                    }
-                }
-                
-                String valid = expression != null ? validateMonitorExpression(graph, componentType, relation, expression) : null; 
-
-                boolean immutable = typeIsImmutable || graph.isImmutable(relation);
-                ComponentTypeViewerPropertyInfo info =
-                        new ComponentTypeViewerPropertyInfo(relation, name, type, defaultValue, numberType, unit, label, description, expression, valid, immutable);
-                
+                ComponentTypeViewerPropertyInfo info = readPropertyInfo(graph, relation, componentType, typeIsImmutable);
                 readSectionSpecificData(graph, info);
-
                 result.add(info);
-
             } else if (graph.isInstanceOf(relation, STR.ConnectionRelation)) {
                 NamedResource nr = new NamedResource(NameUtils.getSafeName(graph, relation), relation);
                 connectionPoints.add(nr);
             }
         }
+        
         Collections.sort(result);
+        
         return new ComponentTypePropertiesResult(result, connectionPoints, typeIsImmutable);
+        
     }
     
-    private Datatype getPossibleDatatype(ReadGraph graph, Resource literal) throws DatabaseException {
+    private static Datatype getPossibleDatatype(ReadGraph graph, Resource literal) throws DatabaseException {
         Binding binding = Bindings.getBindingUnchecked(Datatype.class);
         for (Resource dataTypeResource : graph.getObjects(literal, Layer0.getInstance(graph).HasDataType)) {
             Datatype dt = graph.getPossibleValue(dataTypeResource, binding);
index af17eeebbd25ec974858fff53f8b953360eec48e..51cd08d53ae39cfd23a5354bf8dd7b2fe6a9ecfa 100644 (file)
@@ -12,6 +12,7 @@
 package org.simantics.structural2;
 
 import java.util.Collection;
+import java.util.Collections;
 import java.util.Set;
 
 import org.simantics.db.ReadGraph;
@@ -97,7 +98,8 @@ public class ConnectionImpl2 implements Connection, Connection2 {
     @Override
     public Collection<VariableConnectionPointDescriptor> getConnectionPointDescriptors(ReadGraph graph,
             Resource relationType) throws DatabaseException {
-        throw new IllegalStateException();
+        return Collections.emptyList();
+        //throw new IllegalStateException();
     }
 
     @Override