PrintAs.hs revision ad306df140215d8fb88d14bbb7d685011e0f770b
8a77240a809197c92c0736c431b4b88947a7bac1Christian Maeder{- |
8a77240a809197c92c0736c431b4b88947a7bac1Christian MaederModule : $Header$
6ea54752d184beb92c92fbae17ae9f7dd065d988Christian MaederDescription : print the abstract syntax of FreeCAD terms
306763c67bb99228487345b32ab8c5c6cd41f23cChristian MaederCopyright : (c) Robert Savu and Uni Bremen 2011
3a6c7a7ff823616f56cd3d205fc44664a683effdChristian MaederLicense : GPLv2 or higher, see LICENSE.txt
6ea54752d184beb92c92fbae17ae9f7dd065d988Christian Maeder
98890889ffb2e8f6f722b00e265a211f13b5a861Corneliu-Claudiu ProdescuMaintainer : Robert.Savu@dfki.de
2eeec5240b424984e3ee26296da1eeab6c6d739eChristian MaederStability : experimental
306763c67bb99228487345b32ab8c5c6cd41f23cChristian MaederPortability : portable
306763c67bb99228487345b32ab8c5c6cd41f23cChristian Maeder
f3a94a197960e548ecd6520bb768cb0d547457bbChristian MaederPrinting of the abstract syntax of FreeCAD terms
9f87aabedf02d74917d94fe1ac0300e07d3d4bc2Christian Maeder-}
44fb55f639914f4f531641f32dd4904f15c510a4Till Mossakowski
e9249d3ecd51a2b6a966a58669953e58d703adc6Till Mossakowskimodule FreeCAD.PrintAs where
e9249d3ecd51a2b6a966a58669953e58d703adc6Till Mossakowski
af0cbe339851fc558d2b18cde3666981325e667cTill Mossakowskiimport FreeCAD.As
e9249d3ecd51a2b6a966a58669953e58d703adc6Till Mossakowski
e9249d3ecd51a2b6a966a58669953e58d703adc6Till Mossakowskiimport Common.DocUtils
1bc5dccbf0083a620ae1181c717fea75e4af5e5cChristian Maederimport Common.Doc
556f473448dfcceee22afaa89ed7a364489cdbbbChristian Maederimport Common.Id
1bc5dccbf0083a620ae1181c717fea75e4af5e5cChristian Maeder
1bc5dccbf0083a620ae1181c717fea75e4af5e5cChristian Maeder-- | Pretty printing 'Double'
1bc5dccbf0083a620ae1181c717fea75e4af5e5cChristian Maederinstance Pretty Double where
1bc5dccbf0083a620ae1181c717fea75e4af5e5cChristian Maeder pretty = sidDoc . mkSimpleId . show
1bc5dccbf0083a620ae1181c717fea75e4af5e5cChristian Maeder
1bc5dccbf0083a620ae1181c717fea75e4af5e5cChristian Maeder
556f473448dfcceee22afaa89ed7a364489cdbbbChristian Maederinstance Pretty Vector3 where
1bc5dccbf0083a620ae1181c717fea75e4af5e5cChristian Maeder pretty v = pretty (x v, y v, z v)
1bc5dccbf0083a620ae1181c717fea75e4af5e5cChristian Maeder
1bc5dccbf0083a620ae1181c717fea75e4af5e5cChristian Maederinstance Pretty Matrix33 where
1bc5dccbf0083a620ae1181c717fea75e4af5e5cChristian Maeder pretty m = vcat [lparen <+> rows, rparen] where
556f473448dfcceee22afaa89ed7a364489cdbbbChristian Maeder rows = vcat [row1, row2, row3]
556f473448dfcceee22afaa89ed7a364489cdbbbChristian Maeder row a b c = sepByCommas $ map pretty [a m, b m, c m]
556f473448dfcceee22afaa89ed7a364489cdbbbChristian Maeder row1 = row a11 a12 a13
556f473448dfcceee22afaa89ed7a364489cdbbbChristian Maeder row2 = row a21 a22 a23
556f473448dfcceee22afaa89ed7a364489cdbbbChristian Maeder row3 = row a31 a32 a33
556f473448dfcceee22afaa89ed7a364489cdbbbChristian Maeder
556f473448dfcceee22afaa89ed7a364489cdbbbChristian Maeder
1bc5dccbf0083a620ae1181c717fea75e4af5e5cChristian Maederinstance Pretty Vector4 where
e9249d3ecd51a2b6a966a58669953e58d703adc6Till Mossakowski pretty v = parens $ sepByCommas $ map pretty [q0 v, q1 v, q2 v, q3 v]
e9249d3ecd51a2b6a966a58669953e58d703adc6Till Mossakowski
922819b1c2d383a0fa5d70e1c4aa76667e2f1ca3Christian Maederinstance Pretty Placement where
27166b063721ef1a2efd8f00ab3d9bc820b315fbChristian Maeder pretty p = brackets $sepBySemis [pretty $position p, pretty $orientation p]
19298cbfd6ee2abd904f3181af7760b965b822c3Christian Maeder
9f87aabedf02d74917d94fe1ac0300e07d3d4bc2Christian MaederprintBO:: BaseObject -> Doc
9f87aabedf02d74917d94fe1ac0300e07d3d4bc2Christian MaederprintBO (Box h w l) = text "Box" <+> (vcat[hrow, wrow, lrow]) where
27166b063721ef1a2efd8f00ab3d9bc820b315fbChristian Maeder hrow = hcat [ text "Height ", pretty h]
24a0fbb77b860bc28d25be37ba555fd5746cb6d6Christian Maeder wrow = hcat [ text "Width ", pretty w]
27166b063721ef1a2efd8f00ab3d9bc820b315fbChristian Maeder lrow = hcat [ text "Length ", pretty l]
27166b063721ef1a2efd8f00ab3d9bc820b315fbChristian MaederprintBO (Cylinder a h r) = text "Cylinder" <+> (vcat[arow, hrow, rrow]) where
27166b063721ef1a2efd8f00ab3d9bc820b315fbChristian Maeder arow = hcat [ text "Angle ", pretty a]
27166b063721ef1a2efd8f00ab3d9bc820b315fbChristian Maeder hrow = hcat [ text "Heigth ", pretty h]
63324a97283728a30932828a612c7b0b0f687624Christian Maeder rrow = hcat [ text "Radius ", pretty r]
556f473448dfcceee22afaa89ed7a364489cdbbbChristian MaederprintBO (Sphere a1 a2 a3 r) = text "Sphere" <+> (vcat[a1row, a2row, a3row, rrow]) where
e9249d3ecd51a2b6a966a58669953e58d703adc6Till Mossakowski a1row = hcat [ text "Angle1 ", pretty a1]
59fa9b1349ae1e001d996da732c4ac805c2938e2Christian Maeder a2row = hcat [ text "Angle2 ", pretty a2]
e9249d3ecd51a2b6a966a58669953e58d703adc6Till Mossakowski a3row = hcat [ text "Angle3 ", pretty a3]
e9249d3ecd51a2b6a966a58669953e58d703adc6Till Mossakowski rrow = hcat [ text "Radius ", pretty r]
e9249d3ecd51a2b6a966a58669953e58d703adc6Till MossakowskiprintBO (Cone a r1 r2 h) = text "Cone" <+> (vcat[arow, brow, hrow, rrow]) where
e9249d3ecd51a2b6a966a58669953e58d703adc6Till Mossakowski arow = hcat [ text "Angle ", pretty a]
53310804002cd9e3c9c5844db3b984abcf001788Christian Maeder brow = hcat [ text "Radius1 ", pretty r1]
e9249d3ecd51a2b6a966a58669953e58d703adc6Till Mossakowski hrow = hcat [ text "Radius2 ", pretty r2]
e9249d3ecd51a2b6a966a58669953e58d703adc6Till Mossakowski rrow = hcat [ text "Heigth ", pretty h]
e9249d3ecd51a2b6a966a58669953e58d703adc6Till MossakowskiprintBO (Torus t1 t2 t3 t4 t5) = text "Torus" <+> (vcat[t1r, t2r, t3r, t4r, t5r])
e9249d3ecd51a2b6a966a58669953e58d703adc6Till Mossakowski where
e9249d3ecd51a2b6a966a58669953e58d703adc6Till Mossakowski t1r = hcat [ text "Angle1 ", pretty t1]
e9249d3ecd51a2b6a966a58669953e58d703adc6Till Mossakowski t2r = hcat [ text "Angle1 ", pretty t2]
3a87487c048b275c56e502c4a933273788e8d0bbChristian Maeder t3r = hcat [ text "Angle1 ", pretty t3]
2b565fe5cfb9f99857fd25b52304758d8544e266Mihai Codescu t4r = hcat [ text "Radius1 ", pretty t4]
2b565fe5cfb9f99857fd25b52304758d8544e266Mihai Codescu t5r = hcat [ text "Radius2 ", pretty t5]
2b565fe5cfb9f99857fd25b52304758d8544e266Mihai CodescuprintBO (Line a) = text "Line" <+> hcat [ text "Length ", pretty a]
e9249d3ecd51a2b6a966a58669953e58d703adc6Till MossakowskiprintBO (Circle a h r) = text "Circle" <+> (vcat[arow, hrow, rrow]) where
b5056cf24da461ee868c4be7b803a76b677fa21dChristian Maeder arow = hcat [ text "sAngle ", pretty a]
b5056cf24da461ee868c4be7b803a76b677fa21dChristian Maeder hrow = hcat [ text "eAngle ", pretty h]
4184cb191a9081cb2a9cf3ef5f060f56f0ca5922Till Mossakowski rrow = hcat [ text "Radius ", pretty r]
8731f7b93b26083dc34a2c0937cd6493b42f2c2cTill MossakowskiprintBO (Rectangle h w) = text "Rectangle" <+> (vcat[hrow, wrow]) where
24a0fbb77b860bc28d25be37ba555fd5746cb6d6Christian Maeder hrow = hcat [ text "Heigth ", pretty h]
24a0fbb77b860bc28d25be37ba555fd5746cb6d6Christian Maeder wrow = hcat [ text "Width ", pretty w]
4184cb191a9081cb2a9cf3ef5f060f56f0ca5922Till Mossakowski
b5056cf24da461ee868c4be7b803a76b677fa21dChristian Maederinstance Pretty BaseObject where
b5056cf24da461ee868c4be7b803a76b677fa21dChristian Maeder pretty bo = printBO bo
bba825b39570777866d560bfde3807731131097eKlaus Luettich
b5056cf24da461ee868c4be7b803a76b677fa21dChristian MaederprintObject:: Object -> Doc
b5056cf24da461ee868c4be7b803a76b677fa21dChristian MaederprintObject (BaseObject bo) = pretty bo
b5056cf24da461ee868c4be7b803a76b677fa21dChristian MaederprintObject ( Cut eo1 eo2) = text "Cut" <+> vcat[pretty eo1, pretty eo2]
b5056cf24da461ee868c4be7b803a76b677fa21dChristian MaederprintObject ( Common eo1 eo2) = text "Common" <+> vcat[pretty eo1, pretty eo2]
fd496ec12c6be2731410ea84111f1ff88d8b6384Christian MaederprintObject ( Fusion eo1 eo2) = text "Fusion" <+> vcat[pretty eo1, pretty eo2]
fd496ec12c6be2731410ea84111f1ff88d8b6384Christian MaederprintObject ( Section eo1 eo2) = text "Section" <+> vcat[pretty eo1, pretty eo2]
a89e661aad28f1b39f4fc9f9f9a4d46074234123Christian Maeder
3d86f079b07a6a058cdd6c112d287e01a69d9c0cChristian Maederinstance Pretty Object where
a89e661aad28f1b39f4fc9f9f9a4d46074234123Christian Maeder pretty o = printObject o
b5056cf24da461ee868c4be7b803a76b677fa21dChristian Maeder
b5056cf24da461ee868c4be7b803a76b677fa21dChristian MaederprintEO:: ExtendedObject -> Doc
b5056cf24da461ee868c4be7b803a76b677fa21dChristian MaederprintEO (Placed po) = pretty po
b60a22e76e983e8129c5dae4d713fe2794ed7054Christian MaederprintEO (Ref s) = text s
83b3260413a3b1b7dee1f9c4d3249dec994a875cMihai Codescu
b60a22e76e983e8129c5dae4d713fe2794ed7054Christian Maederinstance Pretty ExtendedObject where
a975722baf6fee1ca3e67df170c732c4abd0a945Christian Maeder pretty eo = printEO eo
a975722baf6fee1ca3e67df170c732c4abd0a945Christian Maeder
a975722baf6fee1ca3e67df170c732c4abd0a945Christian MaederprintPO:: PlacedObject -> Doc
a975722baf6fee1ca3e67df170c732c4abd0a945Christian MaederprintPO (PlacedObject p o) = vcat[pretty o, text "place" <+> pretty p]
63324a97283728a30932828a612c7b0b0f687624Christian Maeder
fd496ec12c6be2731410ea84111f1ff88d8b6384Christian Maeder
a98fd29a06e80e447af26d898044c23497adbc73Mihai Codescuinstance Pretty PlacedObject where
b5056cf24da461ee868c4be7b803a76b677fa21dChristian Maeder pretty po = printPO po
b5056cf24da461ee868c4be7b803a76b677fa21dChristian Maeder
b5056cf24da461ee868c4be7b803a76b677fa21dChristian Maederinstance Pretty NamedObject where
b5056cf24da461ee868c4be7b803a76b677fa21dChristian Maeder pretty no =
b5056cf24da461ee868c4be7b803a76b677fa21dChristian Maeder lbrack $+$ space <+> hcat[doubleQuotes $pretty $name no, colon, space, pretty $object no]
f2c050360525df494e6115073b0edc4c443a847cMihai Codescu $+$ rbrack
b60a22e76e983e8129c5dae4d713fe2794ed7054Christian MaederprintDoc:: Document -> Doc
f2c050360525df494e6115073b0edc4c443a847cMihai CodescuprintDoc a = vcat $ map pretty a
b60a22e76e983e8129c5dae4d713fe2794ed7054Christian Maeder
f2c050360525df494e6115073b0edc4c443a847cMihai Codescu