]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.scl.tutorial/scl/Tutorial/2.09 (Solution) Pipelines again.md
Import org.simantics.scl.tutorial from incubator SVN repo
[simantics/platform.git] / bundles / org.simantics.scl.tutorial / scl / Tutorial / 2.09 (Solution) Pipelines again.md
diff --git a/bundles/org.simantics.scl.tutorial/scl/Tutorial/2.09 (Solution) Pipelines again.md b/bundles/org.simantics.scl.tutorial/scl/Tutorial/2.09 (Solution) Pipelines again.md
new file mode 100644 (file)
index 0000000..d614d53
--- /dev/null
@@ -0,0 +1,35 @@
+## Pipelines again solution\r
+\r
+~~~\r
+import "Simantics/DB"\r
+import "http://www.simantics.org/Layer0-1.1" as L0\r
+import "http://www.simantics.org/Modeling-1.2" as MOD\r
+import "http://www.simantics.org/Diagram-2.2" as DIA\r
+import "http://www.apros.fi/Combustion/Configuration-6.0" as Conf\r
+\r
+swap (x,y) = (y,x)\r
+\r
+connectPoint1 :: Resource -> <ReadGraph> Resource\r
+connectPoint1 r = do\r
+    c = singleObject r Conf.Relations.PI12_CONNECT_POINT_1_1_1\r
+    singleObject c Conf.Relations.SelfPOINT.Inverse\r
+\r
+connectPoint2 :: Resource -> <ReadGraph> Resource\r
+connectPoint2 r = do\r
+    c = singleObject r Conf.Relations.PI12_CONNECT_POINT_2_1_1\r
+    singleObject c Conf.Relations.SelfPOINT.Inverse\r
+\r
+readDiagram :: Resource -> <ReadGraph,Proc> ()\r
+readDiagram dia = do\r
+    points = filter (flip isInstanceOf Conf.ModuleTypes.POINT) (dia # L0.ConsistsOf)\r
+    indexedPoints = zip [0..length points] points\r
+    for indexedPoints $ \(i,r) -> do\r
+        trans = relatedValue (singleObject r MOD.ComponentToElement) DIA.HasTransform :: [Double]\r
+        print "POINT;\(i);\(relatedValue r Conf.Relations.PO11_ELEV :: Float);\(trans!4);\(trans!5)"\r
+    pointByResource = index (map swap indexedPoints)\r
+    pipes = filter (flip isInstanceOf Conf.ModuleTypes.PIPE) (dia # L0.ConsistsOf)\r
+    for pipes $ \r -> do\r
+        id1 = fromJust (pointByResource (connectPoint1 r))\r
+        id2 = fromJust (pointByResource (connectPoint2 r))\r
+        print "PIPE;\(id1);\(id2);\(relatedValue r Conf.Relations.PI12_LENGTH :: Float)"\r
+~~~
\ No newline at end of file