]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
Merge "Workaround for missing selection highlights on SVG diagrams"
authorHannu Niemistö <hannu.niemisto@semantum.fi>
Wed, 18 Oct 2017 12:04:57 +0000 (15:04 +0300)
committerGerrit Code Review <gerrit2@www.simantics.org>
Wed, 18 Oct 2017 12:04:57 +0000 (15:04 +0300)
bundles/org.simantics.modeling/scl/Simantics/Diagram.scl
bundles/org.simantics.modeling/scl/Simantics/DiagramMapping.scl
bundles/org.simantics.scenegraph/src/org/simantics/scenegraph/g2d/events/NodeEventHandler.java
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/compilation/Elaboration.java
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/errors/Locations.java
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/parsing/types/TApplyAst.java
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/module/ImportDeclaration.java
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/module/repository/ModuleRepository.java
bundles/org.simantics.scl.osgi/scl/Extras/HashMap.scl
bundles/org.simantics.scl.ui/src/org/simantics/scl/ui/editor/completion/SCLTextEditorEnvironment.java

index 0ee3e9d28ec03afeec9aff59d69097643472df72..8276962eac7d4aefab138355327ee3d364cd3ffe 100644 (file)
@@ -188,8 +188,6 @@ pathNameOf diagram = do
 diagramResourceOf :: Diagram -> <ReadGraph> Resource
 diagramResourceOf d = singleObject d MOD.CompositeToDiagram
 
-import "Extras/HashMap" as Map
-
 """Constructs a transformation for a diagram element."""
 mapDiagramElement :: (a -> <e> b) -> (a -> <e> b) -> (a -> <e> Maybe b) -> (a -> <e> b) -> DiagramElement a -> <e> DiagramElement b
 mapDiagramElement mapComponentType mapTerminal mapAttribute mapFlagType diagramElement =
@@ -234,9 +232,9 @@ createDiagramR (ExistingDiagram diagram') joinMap elementSpecs = runProc do
     configuration = diagram'
     diagram = compositeToDiagram' configuration
     hasName = L0.HasName
-    componentMap = Map.fromList [ (c `relatedValue` hasName :: String, c)
-                                | c <- children configuration
-                                ]
+    componentMap = MMap.fromEntryList [ (c `relatedValue` hasName :: String, c)
+                                      | c <- children configuration
+                                      ]
     denyByPredicate diagram L0.ConsistsOf
     elements = setElements (DiagramInfo diagram configuration componentMap) joinMap elementSpecs
     claimRelatedValue diagram DIA.HasModCount 
@@ -246,7 +244,7 @@ createDiagramR (ExistingDiagram diagram') joinMap elementSpecs = runProc do
 createDiagramR (NewDiagram model path folderType compositeType) joinMap elementSpecs = (runProc do
     configuration = createConfiguration ()    
     diagram = compositeToDiagram' configuration
-    elements = setElements (DiagramInfo diagram configuration (Map.create ())) joinMap elementSpecs
+    elements = setElements (DiagramInfo diagram configuration (MMap.create ())) joinMap elementSpecs
     claimRelatedValue diagram DIA.HasModCount 
         (fromInteger (length elements) :: Long)
     (configuration, elements)
@@ -304,19 +302,19 @@ importJava "org.simantics.modeling.utils.JoinMap" where
     
 /*
 createJoin :: (Dynamic -> <WriteGraph> Resource) -> Dynamic -> <Proc,WriteGraph> Resource
-createJoin joinMap key = if Map.contains joinMap key
-                         then Map.unsafeGet joinMap key
+createJoin joinMap key = if MMap.containsKey joinMap key
+                         then MMap.unsafeGet joinMap key
                          else do
                              j = newEntity [
                                  hasType STR.ConnectionJoin
                                ]
-                             Map.put joinMap key j 
+                             MMap.put joinMap key j 
                              j
 */
 data DiagramInfo = DiagramInfo
                        Resource                // diagram
                        Resource                // configuration
-                       (Map.T String Resource) // existing components
+                       (MMap.T String Resource) // existing components
 
 """
 Sets the elements of the diagram. Diagram is assumed to be empty,
@@ -336,7 +334,7 @@ setElements (DiagramInfo diagram configuration componentMap) joinMap elementSpec
     for (zip elementSpecs elements) setConnectionName
     elements
 ) where
-    elementMap = Map.create ()
+    elementMap = MMap.create ()
     idRef = ref (0 :: Integer)
 
     isConnectionResource r = isInstanceOf r DIA.Connection
@@ -349,8 +347,8 @@ setElements (DiagramInfo diagram configuration componentMap) joinMap elementSpec
         idRef := id + 1
         show id
     createElement (Component componentType name position properties) = do
-        component = if Map.contains componentMap name 
-                    then Map.unsafeGet componentMap name 
+        component = if MMap.containsKey componentMap name 
+                    then MMap.unsafeGet componentMap name 
                     else newEntity [
                         hasName name,
                         hasParent configuration,
@@ -371,13 +369,13 @@ setElements (DiagramInfo diagram configuration componentMap) joinMap elementSpec
                 MOD.ElementToComponent
                 component
         ]
-        Map.put elementMap name element
+        MMap.put elementMap name element
         Just element
     newOrMappedElement eName = do
-        element = match Map.get elementMap eName with
+        element = match MMap.get elementMap eName with
             Just element -> element
             Nothing -> newEntity []
-        Map.put elementMap eName element
+        MMap.put elementMap eName element
         element
     createElement (SimpleConnection aName ar bName br _) = do
         connection = newEntity [
@@ -421,7 +419,7 @@ setElements (DiagramInfo diagram configuration componentMap) joinMap elementSpec
           then do
             claim flag DIA.ExternalFlag flag
           else ()
-        Map.put elementMap name flag
+        MMap.put elementMap name flag
         Just flag
     createElement (Connection nodeSpecs edges _) = do
         connection = newEntity [
@@ -505,7 +503,7 @@ setElements (DiagramInfo diagram configuration componentMap) joinMap elementSpec
             hasFont font
         ]
     createElement (Monitor label (Just (MonitorReference componentName suffix)) (MonitorVisuals font strokeWidth hAlign vAlign) position) = do
-        match (Map.get elementMap componentName) with
+        match (MMap.get elementMap componentName) with
           Nothing -> Nothing // Monitored component is not on the same diagram as the monitor. Not supported by this routine.
           Just element -> do
             component = singleObject element MOD.ElementToComponent
@@ -705,11 +703,11 @@ elementsOfR diagram = filterJust $ map readElement'
         nodeResources = connectors + routeLines
         nodeResourceWithIds = zip nodeResources [0..length nodeResources-1]
         edges = runProc do
-            rMap = Map.fromList nodeResourceWithIds
+            rMap = MMap.fromEntryList nodeResourceWithIds
             edgesOf (node,i) = 
                 [ Edge i j
                 | r <- node # DIA.AreConnected
-                , j = Map.unsafeGet rMap r
+                , j = MMap.unsafeGet rMap r
                 , j > i ]
             concatMap edgesOf nodeResourceWithIds
         
index a612aca96cc089003b0aa514e932ee32d9ade642..0c184489565cabbc0eeb4a587d1653d5eb6141b4 100644 (file)
@@ -1,5 +1,4 @@
 import "Simantics/DB"
-import "Extras/HashMap" as Map
 import "Simantics/Entity"
 import "Simantics/Model"
 import "Simantics/Diagram"
@@ -7,19 +6,19 @@ import "Simantics/Diagram"
 import "http://www.simantics.org/Modeling-1.2" as MOD
 import "http://www.simantics.org/ModelingTemplate2d-1.0" as TMPL
 
-applyConnectionTypes :: Map.T (DiagramElement Resource) (Resource,Resource) -> <Proc,WriteGraph,ReadGraph> ()
+applyConnectionTypes :: MMap.T (DiagramElement Resource) (Resource,Resource) -> <Proc,WriteGraph,ReadGraph> ()
 applyConnectionTypes elementMap = 
     let
         isConnection ((Connection _ _ _),_) = True
         isConnection _ = False
-    in iter (\(a,(source,target)) -> applyConnectionType target) (filter isConnection (Map.entries elementMap))
+    in iter (\(a,(source,target)) -> applyConnectionType target) (filter isConnection (MMap.entries elementMap))
    
 
 // ----
 
-doElementPostProcessing (elementMap :: Map.T (DiagramElement Resource) (Resource,Resource))
+doElementPostProcessing (elementMap :: MMap.T (DiagramElement Resource) (Resource,Resource))
                         (elementPostProcessing :: DiagramElement Resource -> Resource -> Resource -> <Proc,ReadGraph,WriteGraph> ()) = do
-    list = sortByCluster (Map.entries elementMap) (\(a,(source,target)) -> target)
+    list = sortByCluster (MMap.entries elementMap) (\(a,(source,target)) -> target)
     iter (\(a,(source,target)) -> elementPostProcessing a source target) list
 
 translateDiagrams (sourceModel :: Model)
@@ -31,7 +30,7 @@ translateDiagrams (sourceModel :: Model)
                  (elementPostProcessing :: DiagramElement Resource -> Resource -> Resource -> <Proc,ReadGraph,WriteGraph> ()) 
                  (sourceDiagrams :: [Diagram]) = do
                  
-  elementMap = Map.create() :: Map.T (DiagramElement Resource) (Resource,Resource)
+  elementMap = MMap.create () :: MMap.T (DiagramElement Resource) (Resource,Resource)
 
   // Join map contains all joins of the model
   joinMap = createJoinMap ()
@@ -60,7 +59,7 @@ translateDiagram (sourceModel :: Model)
                  (compositeType :: Resource)
                  (f :: Diagram -> <ReadGraph> [(DiagramElement Resource,Resource)])
                  (joinMap :: Dynamic -> <WriteGraph> Resource)
-                 (elementMap :: Map.T (DiagramElement Resource) (Resource,Resource))
+                 (elementMap :: MMap.T (DiagramElement Resource) (Resource,Resource))
                  (diagramPostProcessing :: Diagram -> Diagram -> <Proc,ReadGraph,WriteGraph> ()) 
                  (sourceDiagram :: Diagram) = do
   disableDependencies 
@@ -96,9 +95,9 @@ makeSpec targetModel sourceDiagram folderType compositeType =
 getTargetDiagram (targetModel :: Model) (sourceDiagram :: Diagram) =
     (possibleDiagram targetModel $ pathOf sourceDiagram) :: Maybe Diagram
 
-store :: Map.T (DiagramElement Resource) (Resource,Resource) -> (DiagramElement Resource) -> Resource -> Resource -> <Proc,WriteGraph,ReadGraph> ()
+store :: MMap.T (DiagramElement Resource) (Resource,Resource) -> (DiagramElement Resource) -> Resource -> Resource -> <Proc,WriteGraph,ReadGraph> ()
 store elementMap a b c = do
-  Map.put elementMap a (b,c)
+  MMap.put elementMap a (b,c)
   ()
 
 getTargetComponent (targetDiagram :: Diagram) (sourceComponent :: Resource) =
@@ -110,7 +109,7 @@ translateDiagram2 (targetModel :: Model)
                   (compositeType :: Resource)
                   (f :: Diagram -> <ReadGraph> [(DiagramElement Resource,Resource)]) 
                   (joinMap :: Dynamic -> <WriteGraph> Resource)
-                  (elementMap ::  Map.T (DiagramElement Resource) (Resource,Resource)) = do
+                  (elementMap ::  MMap.T (DiagramElement Resource) (Resource,Resource)) = do
   spec = makeSpec targetModel sourceDiagram folderType compositeType
   elementSpecs = f sourceDiagram
   in1 = (filter (not . isReferring) elementSpecs + filter isReferring elementSpecs)
index ec0a4fe5f1a35182901cdb311c9fe7186356b83f..1c1ac8a37a7b523ace66705188f148c1972ed763 100644 (file)
@@ -12,6 +12,7 @@
 package org.simantics.scenegraph.g2d.events;
 
 import java.awt.Component;
+import java.awt.GraphicsEnvironment;
 import java.awt.dnd.DnDConstants;
 import java.awt.dnd.DragGestureEvent;
 import java.awt.dnd.DragGestureListener;
@@ -35,6 +36,8 @@ import org.simantics.scenegraph.g2d.events.MouseEvent.MouseButtonPressedEvent;
 import org.simantics.scenegraph.g2d.events.MouseEvent.MouseDragBegin;
 import org.simantics.scenegraph.g2d.events.adapter.AWTMouseEventAdapter;
 import org.simantics.scenegraph.g2d.events.command.CommandEvent;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
  * Delivers events (mouse, key, focus, command, time) to scene graph nodes that
@@ -44,6 +47,8 @@ import org.simantics.scenegraph.g2d.events.command.CommandEvent;
  */
 public class NodeEventHandler implements IEventHandler {
 
+    private static final Logger LOGGER = LoggerFactory.getLogger(NodeEventHandler.class);
+
     private static final boolean DEBUG_EVENTS       = false;
     private static final boolean DEBUG_HANDLER_SORT = false;
 
@@ -197,12 +202,6 @@ public class NodeEventHandler implements IEventHandler {
      */
     protected G2DSceneGraph               sg;
 
-    /**
-     * For proper initiation of native DnD operations within this AWT-based
-     * scenegraph system.
-     */
-    protected DragSource                  ds = new DragSource();
-
     public NodeEventHandler(G2DSceneGraph sg) {
         this.sg = sg;
     }
@@ -222,6 +221,11 @@ public class NodeEventHandler implements IEventHandler {
     }
 
     public void setRootPane(Component rootPane) {
+        if (GraphicsEnvironment.isHeadless()) {
+            LOGGER.info("Disabling DragSource in headless environments");
+            return;
+        }
+        final DragSource ds = new DragSource();
         final DragSourceListener dsl = new DragSourceListener() {
             @Override
             public void dropActionChanged(DragSourceDragEvent dsde) {
index f7f745841460bdbfc30aacbd0a35b5174620208f..5a82823a1b27f2d8a200bb8d1c03a8ce8ffc64a6 100644 (file)
@@ -206,9 +206,9 @@ public class Elaboration {
                                try {
                                        String absoluteModuleName = ModuleUtils.resolveAbsolutePath(moduleName, relativeImport.moduleName);
                     ImportDeclaration absoluteImport = new ImportDeclaration(
+                            relativeImport.location,
                             absoluteModuleName, relativeImport.localName,
                             relativeImport.reexport, relativeImport.spec);
-                    absoluteImport.location = relativeImport.location;
                     absoluteImports.add(absoluteImport);
                                } catch (InvalidModulePathException e) {
                                        errorLog.log(relativeImport.location, e.getMessage());
index 3a77cf3250d7c1f58bd17c2e2fcbd8ac164bb9db..70c258b9bab1fa89ae816c97d1bb02d7290441b6 100644 (file)
@@ -48,4 +48,11 @@ public class Locations {
             localEnd = begin-end;
         return location(begin+localBegin, begin+localEnd);
     }
+
+    public static String toString(long location) {
+        if(location == NO_LOCATION)
+            return "NO LOCATION";
+        else
+            return beginOf(location) + "-" + endOf(location);
+    }
 }
index 3c77000757f67b96d56a2f4f6a5125888a4a8300..1aeba20713063dc70728bf443b907fdbb491b951 100644 (file)
@@ -49,15 +49,19 @@ public class TApplyAst extends TypeAst {
                 return Types.metaVar(Kinds.STAR);
             }
             if(alias != null) {
-                if(parameters.length != alias.getArity()) {
+                int arity = alias.getArity();
+                if(parameters.length < arity) {
                     context.getErrorLog().log(location, "Wrong number of parameters are given to the type alias. Expected " +
-                            alias.getArity() + " parameters, got " + parameters.length + " parameters.");
+                            arity + " parameters, got " + parameters.length + " parameters.");
                     return Types.metaVar(Kinds.metaVar());
                 }
-                Type[] parameterTypes = new Type[parameters.length];
-                for(int i=0;i<parameters.length;++i)
+                Type[] parameterTypes = new Type[arity];
+                for(int i=0;i<arity;++i)
                     parameterTypes[i] = parameters[i].toType(context, Kinds.metaVar());
-                return alias.body.replace(alias.parameters, parameterTypes);
+                Type result = alias.body.replace(alias.parameters, parameterTypes);
+                for(int i=arity;i<parameters.length;++i)
+                    result = Types.apply(result, parameters[i].toType(context, Kinds.metaVar()));
+                return result;
             }
         }
         
index 21d7104051b133957c17b813a1a2a778ac2334f3..77ac5e78e21bae50d2edf8a175427b35c59758ab 100644 (file)
@@ -53,6 +53,11 @@ public class ImportDeclaration extends DeclarationAst {
         this.spec = DEFAULT_SPEC;
     }
     
+    public ImportDeclaration(long location, String moduleName, String localName, boolean reexport, ImportSpec spec) {
+        this(moduleName, localName, reexport);
+        this.location = location;
+    }
+    
     public ImportDeclaration(String moduleName, String localName, boolean reexport, ImportSpec spec) {
         if(spec == null)
             throw new NullPointerException();
index 089f2c26c95469e639176ed9f50136b91a9c46c7..7c3de572f78456db563a65011d64953a26cb546b 100644 (file)
@@ -20,6 +20,7 @@ import org.simantics.scl.compiler.errors.CompilationError;
 import org.simantics.scl.compiler.errors.DoesNotExist;
 import org.simantics.scl.compiler.errors.Failable;
 import org.simantics.scl.compiler.errors.Failure;
+import org.simantics.scl.compiler.errors.Locations;
 import org.simantics.scl.compiler.errors.Success;
 import org.simantics.scl.compiler.module.ImportDeclaration;
 import org.simantics.scl.compiler.module.Module;
@@ -37,6 +38,7 @@ import org.simantics.scl.compiler.top.ValueNotFound;
 import org.simantics.scl.compiler.types.Types;
 
 import gnu.trove.map.hash.THashMap;
+import gnu.trove.map.hash.TObjectLongHashMap;
 import gnu.trove.procedure.TObjectObjectProcedure;
 import gnu.trove.set.hash.THashSet;
 
@@ -261,11 +263,11 @@ public class ModuleRepository {
         THashMap<String, ModuleEntry> result = new THashMap<String, ModuleEntry>();
         Collection<ImportFailure> failures = null;
         
-        THashSet<String> originalImports = new THashSet<String>(); 
+        TObjectLongHashMap<String> originalImports = new TObjectLongHashMap<String>(); 
         ArrayList<ImportDeclaration> stack = new ArrayList<ImportDeclaration>(imports.length);
         for(ImportDeclaration import_ : imports) {
             stack.add(import_);
-            originalImports.add(import_.moduleName);
+            originalImports.put(import_.moduleName, import_.location);
         }
         while(!stack.isEmpty()) {
             ImportDeclaration import_ = stack.remove(stack.size()-1);
@@ -278,8 +280,10 @@ public class ModuleRepository {
                     stack.addAll(compilationResult.getResult().getDependencies());
                     if(originalImport) {
                         String deprecation = compilationResult.getResult().getDeprecation();
-                        if(deprecation != null && compilationContext != null)
-                            compilationContext.errorLog.logWarning(import_.location, "Deprecated module " + import_.moduleName   + (deprecation.isEmpty() ? "." : ": " + deprecation));
+                        if(deprecation != null && compilationContext != null) {
+                            long location = originalImport ? originalImports.get(import_.moduleName) : Locations.NO_LOCATION;
+                            compilationContext.errorLog.logWarning(location, "Deprecated module " + import_.moduleName   + (deprecation.isEmpty() ? "." : ": " + deprecation));
+                        }
                     }
                 }
                 else {
index e055c81c32e37727013a1d8b750de5cf71f88d5a..76ab15c6c384d5f15197c506a70b6021dbcc9aa1 100644 (file)
@@ -1,23 +1,31 @@
-import "StandardLibrary" hiding (contains)
+module {
+    deprecated = "Use module MMap instead."
+}
 
-importJava "gnu.trove.map.hash.THashMap" where
-    data T a b
-    
-    @JavaName "<init>"
-    create :: () -> <Proc> T a b
-    put :: T a b -> a -> b -> <Proc> Maybe b
-    get :: T a b -> a -> <Proc> Maybe b
-    @JavaName get
-    unsafeGet :: T a b -> a -> <Proc> b
+import "MMap" as MMap
+
+type T = MMap.T
+
+create :: () -> <Proc> T a b
+create = MMap.create
+
+put :: T a b -> a -> b -> <Proc> Maybe b
+put = MMap.put
+
+get :: T a b -> a -> <Proc> Maybe b
+get = MMap.get
+
+unsafeGet :: T a b -> a -> <Proc> b
+unsafeGet = MMap.unsafeGet
     
-    contains :: T a b -> a -> <Proc> Boolean
-    size :: T a b -> <Proc> Integer
+contains :: T a b -> a -> <Proc> Boolean
+contains = MMap.containsKey
+
+size :: T a b -> <Proc> Integer
+size = MMap.size
     
-importJava "org.simantics.scl.osgi.map.HashMapUtils" where 
-    entries :: T a b -> <Proc> [(a,b)]
+entries :: T a b -> <Proc> [(a,b)]
+entries = MMap.entries
 
 fromList :: [(a,b)] -> <Proc> T a b
-fromList entries = do
-    result = create ()
-    for entries (\(k,v) -> do put result k v; ())
-    result 
\ No newline at end of file
+fromList = MMap.fromEntryList
index de335f0f944c3ba7135b5ba6900398f6cd91b4c5..98b51917744aaa43d7f179a0712e72b23bfdb29a 100644 (file)
@@ -108,6 +108,7 @@ public class SCLTextEditorEnvironment {
                        try {
                                String absoluteModuleName = ModuleUtils.resolveAbsolutePath(moduleName, relativeImport.moduleName);
                 absoluteImports.add(new ImportDeclaration(
+                        relativeImport.location,
                         absoluteModuleName, relativeImport.localName,
                         relativeImport.reexport, relativeImport.spec));
                        } catch (InvalidModulePathException e) {