X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.scl.tutorial%2Fscl%2FTutorial%2F2.08%20%28Solution%29%20Polyline.md;fp=bundles%2Forg.simantics.scl.tutorial%2Fscl%2FTutorial%2F2.08%20%28Solution%29%20Polyline.md;h=6926c4878be210ffe37da46db4e0f53a4d736c90;hb=39fd9bd29b18a2f7abe62fb13da3359b3618dda7;hp=0000000000000000000000000000000000000000;hpb=f024c0a7208e379a82f0ab51a71a123f9bb2a2bb;p=simantics%2Fplatform.git 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 index 000000000..6926c4878 --- /dev/null +++ b/bundles/org.simantics.scl.tutorial/scl/Tutorial/2.08 (Solution) Polyline.md @@ -0,0 +1,40 @@ +## Polyline solution + +~~~ +import "Apros/Legacy" + +connect (ma,ca) (mb,cb) = aconnect ma ca mb cb + +addPolyline :: String -> String -> (Double,Double) -> [(Double,Double)] -> () +addPolyline diagram name position xyPoints = ignore $ addRecursively 1 position xyPoints + where + addRecursively n position xyPoints | length xyPoints <= 30 = + addSmallPolyline n position xyPoints + addRecursively n (x,y) xyPoints = do + swPoint = fst (xyPoints!29) + brName = name + "_BR" + show n + lvName = name + "_LV" + show n + swName = name + "_SW" + show n + aadd diagram "BranchAnalog" brName (x-20, y+5) + aadd diagram "LV_CHECKER" lvName (x, y) + amodi lvName "LVC_LIMIT_VALUE" (fst (xyPoints!29)) + aadd diagram "ANALOG_SWITCH" swName (x+20, y+5) + (in1, out1) = addSmallPolyline n (x, y+10) (take 30 xyPoints) + (in2, out2) = addRecursively (n+1) (x, y+20) (drop 29 xyPoints) + connect (brName, "AMUX_OUTPUT_SIGN(1)") (lvName, "LVC_INPUT_SIGN") + connect (brName, "AMUX_OUTPUT_SIGN(2)") in1 + connect (brName, "AMUX_OUTPUT_SIGN(4)") in2 + connect (lvName, "LVC_OUTPUT_SIGN_1") (swName, "SWITCH_CONTROL_S") + connect out1 (swName, "SWITCH_INP_SIGN_1") + connect out2 (swName, "SWITCH_INP_SIGN_2") + ((brName, "AMUX_INPUT_SIGN"), (swName, "SWITCH_OUTP_SIGN")) + addSmallPolyline n position xyPoints = do + fullName = name + "_" + show n + aadd diagram "Polyline" fullName position + for [1..length xyPoints] $ \i -> do + (x,y) = xyPoints!(i-1) + amodi fullName "FUNCTION_X_COORDINATE(\(i))" x + amodi fullName "FUNCTION_Y_COORDINATE(\(i))" y + amodi fullName "FUNCTION_OK(\(i))" True + ((fullName, "FUNCTION_INPUT_SIGN"), (fullName, "FUNCTION_OUTPUT_SIGN")) +~~~ \ No newline at end of file