summaryrefslogtreecommitdiff
path: root/GenSCAD.hs
diff options
context:
space:
mode:
authorSteven <steven.vasilogianis@gmail.com>2019-03-08 04:36:23 -0500
committerSteven <steven.vasilogianis@gmail.com>2019-03-08 04:36:23 -0500
commit7040c5aa653f11487b1d52e3c7aefc1e41f57136 (patch)
treec1fd0d9c72ea6766616ebc26ad7a891c5d809b82 /GenSCAD.hs
parent3e6c8dede8ac3506dbf9de06ebbb11f4469562ac (diff)
lost tracks
Diffstat (limited to 'GenSCAD.hs')
-rw-r--r--GenSCAD.hs77
1 files changed, 77 insertions, 0 deletions
diff --git a/GenSCAD.hs b/GenSCAD.hs
new file mode 100644
index 0000000..90bcd74
--- /dev/null
+++ b/GenSCAD.hs
@@ -0,0 +1,77 @@
1module GenSCAD
2( placecube
3) where
4
5import Linear.V3
6import Control.Lens
7import Data.List
8import Text.Printf
9import System.IO.Temp
10import System.Process
11
12_V32l :: R3 c1 => c1 c -> [c]
13_V32l c = [c ^. _x, c ^. _y, c ^. _z]
14
15_V32s :: (R3 c1, Show a) => c1 a -> [Char]
16_V32s c = intercalate "," (map show (_V32l c))
17
18-- placecube: OpenSCAD translate cube described by d to place designated by p
19-- placecube (V3 1 2 3, V3 10 20 30) ->
20-- translate([1, 2, 3]) { cube([10, 20, 30]); }
21placecube obj = "translate([ " ++ _V32s(fst obj) ++ " ]) { cube([ " ++ _V32s(snd obj) ++ " ]); }"
22--placecube (p,d) = printf "translate([%d, %d, %d]) { cube([%d, %d, %d]); }" (_V32l p ++ _V32l d)
23
24
25-- take a list of tuples containing positions and dimensions for cubes and
26-- generate corresponding code for rendering in OpenSCAD
27-- genscad [(V3 0 0 0, V3 10 10 10), (V3 20 20 20, V3 10 10 10)] ->
28-- placecube (V3 0 0 0, V3 10 10 10) -> translate ([...]) { cube([...]);}
29-- placecube (V3 20 20 20, V3 10 10 10) -> '
30
31td = [(V3 0 1 2, V3 10 20 30), (V3 50 51 52, V3 11 22 33)]
32
33--genscad :: [(V3 p, V3 d)] -> [Char]
34--genscad objs = concat $ map (++ "\n") $ map placecube objs
35genscad objs = concat $ map (++ "\n") $ map (placecube) objs
36printscad objs = putStrLn $ genscad objs
37--writefilescad objs = withSystemTempFile "genscad" -> fp gsf -> doprintscad objs
38writetempscad objs = writeSystemTempFile "genscad" (genscad objs)
39opentempscad objs = runCommand ("openscad " ++ "foo.scad")
40--opentempscad objs =
41
42-- savegenscad code file -> save generated code file
43-- opensavegenscad code file -> generate scad, save to file, then open in OpenSCAD
44
45-- readEditor :: IO String
46-- readEditor = withSystemTempFile "read-editor" readEditor'
47
48-- -- | Opens a file, fills it some content and returns it's contents after it's saved.
49-- readEditorWith :: String -> IO String
50-- readEditorWith contents = withSystemTempFile "read-editor" $ \fp temph -> do
51-- hPutStr temph contents
52-- hFlush temph
53-- readEditor' fp temph
54
55-- readEditor' :: FilePath -> Handle -> IO String
56-- readEditor' fp temph = do
57-- openEditor fp
58-- hClose temph
59-- readFile fp
60
61
62
63-- compileRunPrint :: FilePath -> Ident -> IO String
64-- compileRunPrint agdap var =
65-- withSystemTempFile "module.mlf" $
66-- \mlfp mlfh -> do
67-- callProcess "stack" ["exec", "agda-ocaml", "--", "-v0", "--mlf", agdap
68-- , "-o", mlfp, "--print-var", var]
69-- runModFile' mlfp mlfh
70
71-- compileRun :: FilePath -> IO String
72-- compileRun agdap =
73-- withSystemTempFile "module.mlf" $
74-- \mlfp mlfh -> do
75-- callProcess "stack" ["exec", "agda-ocaml", "--", "-v0", "--mlf", agdap
76-- , "-o", mlfp]
77-- runModFile' mlfp mlfh