{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE LambdaCase #-}
module Graphics.Implicit.Export (
export2,
export3,
OutputFormat(SVG, SCAD, PNG, GCode, ASCIISTL, STL, THREEJS, OBJ, DXF),
writeObject,
formatObject,
writeSVG,
writeSTL,
writeBinSTL,
writeOBJ,
writeTHREEJS,
writeGCodeHacklabLaser,
writeDXF2,
writeSCAD2,
writeSCAD3,
writePNG,
)
where
import Prelude (FilePath, IO, (.), ($), (<>), show, error)
import Graphics.Implicit.Definitions (SymbolicObj2, SymbolicObj3, ℝ, Polyline, TriangleMesh, NormedTriangleMesh)
import Data.Text.Lazy (Text)
import qualified Data.Text.Lazy.IO as LT (writeFile)
import qualified Data.ByteString.Lazy as LBS (writeFile)
import Graphics.Implicit.Export.DiscreteAproxable (DiscreteAproxable, discreteAprox)
import qualified Graphics.Implicit.Export.PolylineFormats as PolylineFormats (svg, hacklabLaserGCode, dxf2)
import qualified Graphics.Implicit.Export.TriangleMeshFormats as TriangleMeshFormats (stl, binaryStl, jsTHREE)
import qualified Graphics.Implicit.Export.NormedTriangleMeshFormats as NormedTriangleMeshFormats (obj)
import qualified Graphics.Implicit.Export.SymbolicFormats as SymbolicFormats (scad2, scad3)
import qualified Codec.Picture as ImageFormatCodecs (DynamicImage, savePngImage)
import Graphics.Implicit.Export.OutputFormat (OutputFormat(SVG, SCAD, PNG, GCode, ASCIISTL, STL, THREEJS, OBJ, DXF))
writeObject :: (DiscreteAproxable obj aprox)
=> ℝ
-> (aprox -> Text)
-> FilePath
-> obj
-> IO ()
writeObject :: forall obj aprox.
DiscreteAproxable obj aprox =>
ℝ -> (aprox -> Text) -> [Char] -> obj -> IO ()
writeObject ℝ
res aprox -> Text
formatWriter [Char]
filename obj
obj =
let
aprox :: Text
aprox = forall obj aprox.
DiscreteAproxable obj aprox =>
ℝ -> (aprox -> Text) -> obj -> Text
formatObject ℝ
res aprox -> Text
formatWriter obj
obj
in [Char] -> Text -> IO ()
LT.writeFile [Char]
filename Text
aprox
writeObject' :: (DiscreteAproxable obj aprox)
=> ℝ
-> (FilePath -> aprox -> IO ())
-> FilePath
-> obj
-> IO ()
writeObject' :: forall obj aprox.
DiscreteAproxable obj aprox =>
ℝ -> ([Char] -> aprox -> IO ()) -> [Char] -> obj -> IO ()
writeObject' ℝ
res [Char] -> aprox -> IO ()
formatWriter [Char]
filename obj
obj =
[Char] -> aprox -> IO ()
formatWriter [Char]
filename (forall obj aprox. DiscreteAproxable obj aprox => ℝ -> obj -> aprox
discreteAprox ℝ
res obj
obj)
formatObject :: (DiscreteAproxable obj aprox)
=> ℝ
-> (aprox -> Text)
-> obj
-> Text
formatObject :: forall obj aprox.
DiscreteAproxable obj aprox =>
ℝ -> (aprox -> Text) -> obj -> Text
formatObject ℝ
res aprox -> Text
formatWriter = aprox -> Text
formatWriter forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall obj aprox. DiscreteAproxable obj aprox => ℝ -> obj -> aprox
discreteAprox ℝ
res
writeSVG :: DiscreteAproxable obj [Polyline] => ℝ -> FilePath -> obj -> IO ()
writeSVG :: forall obj.
DiscreteAproxable obj [Polyline] =>
ℝ -> [Char] -> obj -> IO ()
writeSVG ℝ
res = forall obj aprox.
DiscreteAproxable obj aprox =>
ℝ -> (aprox -> Text) -> [Char] -> obj -> IO ()
writeObject ℝ
res [Polyline] -> Text
PolylineFormats.svg
writeDXF2 :: DiscreteAproxable obj [Polyline] => ℝ -> FilePath -> obj -> IO ()
writeDXF2 :: forall obj.
DiscreteAproxable obj [Polyline] =>
ℝ -> [Char] -> obj -> IO ()
writeDXF2 ℝ
res = forall obj aprox.
DiscreteAproxable obj aprox =>
ℝ -> (aprox -> Text) -> [Char] -> obj -> IO ()
writeObject ℝ
res [Polyline] -> Text
PolylineFormats.dxf2
writeSTL :: DiscreteAproxable obj TriangleMesh => ℝ -> FilePath -> obj -> IO ()
writeSTL :: forall obj.
DiscreteAproxable obj TriangleMesh =>
ℝ -> [Char] -> obj -> IO ()
writeSTL ℝ
res = forall obj aprox.
DiscreteAproxable obj aprox =>
ℝ -> (aprox -> Text) -> [Char] -> obj -> IO ()
writeObject ℝ
res TriangleMesh -> Text
TriangleMeshFormats.stl
writeBinSTL :: DiscreteAproxable obj TriangleMesh => ℝ -> FilePath -> obj -> IO ()
writeBinSTL :: forall obj.
DiscreteAproxable obj TriangleMesh =>
ℝ -> [Char] -> obj -> IO ()
writeBinSTL ℝ
res [Char]
file obj
obj = [Char] -> ByteString -> IO ()
LBS.writeFile [Char]
file forall a b. (a -> b) -> a -> b
$ TriangleMesh -> ByteString
TriangleMeshFormats.binaryStl forall a b. (a -> b) -> a -> b
$ forall obj aprox. DiscreteAproxable obj aprox => ℝ -> obj -> aprox
discreteAprox ℝ
res obj
obj
writeOBJ :: DiscreteAproxable obj NormedTriangleMesh => ℝ -> FilePath -> obj -> IO ()
writeOBJ :: forall obj.
DiscreteAproxable obj NormedTriangleMesh =>
ℝ -> [Char] -> obj -> IO ()
writeOBJ ℝ
res = forall obj aprox.
DiscreteAproxable obj aprox =>
ℝ -> (aprox -> Text) -> [Char] -> obj -> IO ()
writeObject ℝ
res NormedTriangleMesh -> Text
NormedTriangleMeshFormats.obj
writeTHREEJS :: DiscreteAproxable obj TriangleMesh => ℝ -> FilePath -> obj -> IO ()
writeTHREEJS :: forall obj.
DiscreteAproxable obj TriangleMesh =>
ℝ -> [Char] -> obj -> IO ()
writeTHREEJS ℝ
res = forall obj aprox.
DiscreteAproxable obj aprox =>
ℝ -> (aprox -> Text) -> [Char] -> obj -> IO ()
writeObject ℝ
res TriangleMesh -> Text
TriangleMeshFormats.jsTHREE
writeGCodeHacklabLaser :: DiscreteAproxable obj [Polyline] => ℝ -> FilePath -> obj -> IO ()
writeGCodeHacklabLaser :: forall obj.
DiscreteAproxable obj [Polyline] =>
ℝ -> [Char] -> obj -> IO ()
writeGCodeHacklabLaser ℝ
res = forall obj aprox.
DiscreteAproxable obj aprox =>
ℝ -> (aprox -> Text) -> [Char] -> obj -> IO ()
writeObject ℝ
res [Polyline] -> Text
PolylineFormats.hacklabLaserGCode
writeSCAD3 :: ℝ -> FilePath -> SymbolicObj3 -> IO ()
writeSCAD3 :: ℝ -> [Char] -> SymbolicObj3 -> IO ()
writeSCAD3 ℝ
res [Char]
filename SymbolicObj3
obj = [Char] -> Text -> IO ()
LT.writeFile [Char]
filename forall a b. (a -> b) -> a -> b
$ ℝ -> SymbolicObj3 -> Text
SymbolicFormats.scad3 ℝ
res SymbolicObj3
obj
writeSCAD2 :: ℝ -> FilePath -> SymbolicObj2 -> IO ()
writeSCAD2 :: ℝ -> [Char] -> SymbolicObj2 -> IO ()
writeSCAD2 ℝ
res [Char]
filename SymbolicObj2
obj = [Char] -> Text -> IO ()
LT.writeFile [Char]
filename forall a b. (a -> b) -> a -> b
$ ℝ -> SymbolicObj2 -> Text
SymbolicFormats.scad2 ℝ
res SymbolicObj2
obj
writePNG :: DiscreteAproxable obj ImageFormatCodecs.DynamicImage => ℝ -> FilePath -> obj -> IO ()
writePNG :: forall obj.
DiscreteAproxable obj DynamicImage =>
ℝ -> [Char] -> obj -> IO ()
writePNG ℝ
res = forall obj aprox.
DiscreteAproxable obj aprox =>
ℝ -> ([Char] -> aprox -> IO ()) -> [Char] -> obj -> IO ()
writeObject' ℝ
res [Char] -> DynamicImage -> IO ()
ImageFormatCodecs.savePngImage
export3 :: OutputFormat -> ℝ -> FilePath -> SymbolicObj3 -> IO ()
export3 :: OutputFormat -> ℝ -> [Char] -> SymbolicObj3 -> IO ()
export3 = \case
OutputFormat
ASCIISTL -> forall obj.
DiscreteAproxable obj TriangleMesh =>
ℝ -> [Char] -> obj -> IO ()
writeSTL
OutputFormat
STL -> forall obj.
DiscreteAproxable obj TriangleMesh =>
ℝ -> [Char] -> obj -> IO ()
writeBinSTL
OutputFormat
SCAD -> ℝ -> [Char] -> SymbolicObj3 -> IO ()
writeSCAD3
OutputFormat
OBJ -> forall obj.
DiscreteAproxable obj NormedTriangleMesh =>
ℝ -> [Char] -> obj -> IO ()
writeOBJ
OutputFormat
PNG -> forall obj.
DiscreteAproxable obj DynamicImage =>
ℝ -> [Char] -> obj -> IO ()
writePNG
OutputFormat
THREEJS -> forall obj.
DiscreteAproxable obj TriangleMesh =>
ℝ -> [Char] -> obj -> IO ()
writeTHREEJS
OutputFormat
fmt -> forall a. HasCallStack => [Char] -> a
error forall a b. (a -> b) -> a -> b
$ [Char]
"Unrecognized 3D format: " forall a. Semigroup a => a -> a -> a
<> forall a. Show a => a -> [Char]
show OutputFormat
fmt
export2 :: OutputFormat -> ℝ -> FilePath -> SymbolicObj2 -> IO ()
export2 :: OutputFormat -> ℝ -> [Char] -> SymbolicObj2 -> IO ()
export2 = \case
OutputFormat
SVG -> forall obj.
DiscreteAproxable obj [Polyline] =>
ℝ -> [Char] -> obj -> IO ()
writeSVG
OutputFormat
DXF -> forall obj.
DiscreteAproxable obj [Polyline] =>
ℝ -> [Char] -> obj -> IO ()
writeDXF2
OutputFormat
SCAD -> ℝ -> [Char] -> SymbolicObj2 -> IO ()
writeSCAD2
OutputFormat
PNG -> forall obj.
DiscreteAproxable obj DynamicImage =>
ℝ -> [Char] -> obj -> IO ()
writePNG
OutputFormat
GCode -> forall obj.
DiscreteAproxable obj [Polyline] =>
ℝ -> [Char] -> obj -> IO ()
writeGCodeHacklabLaser
OutputFormat
fmt -> forall a. HasCallStack => [Char] -> a
error forall a b. (a -> b) -> a -> b
$ [Char]
"Unrecognized 2D format: " forall a. Semigroup a => a -> a -> a
<> forall a. Show a => a -> [Char]
show OutputFormat
fmt