]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.scl.tutorial/scl/Tutorial/2.08 (Solution) Polyline.md
Import org.simantics.scl.tutorial from incubator SVN repo
[simantics/platform.git] / bundles / org.simantics.scl.tutorial / scl / Tutorial / 2.08 (Solution) Polyline.md
diff --git a/bundles/org.simantics.scl.tutorial/scl/Tutorial/2.08 (Solution) Polyline.md b/bundles/org.simantics.scl.tutorial/scl/Tutorial/2.08 (Solution) Polyline.md
new file mode 100644 (file)
index 0000000..6926c48
--- /dev/null
@@ -0,0 +1,40 @@
+## Polyline solution\r
+\r
+~~~\r
+import "Apros/Legacy"\r
+\r
+connect (ma,ca) (mb,cb) = aconnect ma ca mb cb\r
+\r
+addPolyline :: String -> String -> (Double,Double) -> [(Double,Double)] -> <Proc> ()\r
+addPolyline diagram name position xyPoints = ignore $ addRecursively 1 position xyPoints\r
+  where\r
+    addRecursively n position xyPoints | length xyPoints <= 30 = \r
+        addSmallPolyline n position xyPoints\r
+    addRecursively n (x,y) xyPoints = do\r
+        swPoint = fst (xyPoints!29)\r
+        brName = name + "_BR" + show n\r
+        lvName = name + "_LV" + show n\r
+        swName = name + "_SW" + show n\r
+        aadd diagram "BranchAnalog" brName (x-20, y+5) \r
+        aadd diagram "LV_CHECKER" lvName (x, y)\r
+        amodi lvName "LVC_LIMIT_VALUE" (fst (xyPoints!29))\r
+        aadd diagram "ANALOG_SWITCH" swName (x+20, y+5)\r
+        (in1, out1) = addSmallPolyline n     (x, y+10) (take 30 xyPoints)\r
+        (in2, out2) = addRecursively   (n+1) (x, y+20) (drop 29 xyPoints)\r
+        connect (brName, "AMUX_OUTPUT_SIGN(1)") (lvName, "LVC_INPUT_SIGN")\r
+        connect (brName, "AMUX_OUTPUT_SIGN(2)") in1       \r
+        connect (brName, "AMUX_OUTPUT_SIGN(4)") in2\r
+        connect (lvName, "LVC_OUTPUT_SIGN_1")   (swName, "SWITCH_CONTROL_S")\r
+        connect out1                            (swName, "SWITCH_INP_SIGN_1")\r
+        connect out2                            (swName, "SWITCH_INP_SIGN_2")\r
+        ((brName, "AMUX_INPUT_SIGN"), (swName, "SWITCH_OUTP_SIGN"))    \r
+    addSmallPolyline n position xyPoints = do\r
+        fullName = name + "_" + show n\r
+        aadd diagram "Polyline" fullName position\r
+        for [1..length xyPoints] $ \i -> do\r
+            (x,y) = xyPoints!(i-1)\r
+            amodi fullName "FUNCTION_X_COORDINATE(\(i))" x\r
+            amodi fullName "FUNCTION_Y_COORDINATE(\(i))" y\r
+            amodi fullName "FUNCTION_OK(\(i))"           True\r
+        ((fullName, "FUNCTION_INPUT_SIGN"), (fullName, "FUNCTION_OUTPUT_SIGN")) \r
+~~~
\ No newline at end of file