fcd50ed0f526645ca50bad2170e3b98b911b7678Ewaryst Schulz{- |
e9458b1a7a19a63aa4c179f9ab20f4d50681c168Jens ElknerModule : ./FreeCAD/PrintAs.hs
fcd50ed0f526645ca50bad2170e3b98b911b7678Ewaryst SchulzDescription : print the abstract syntax of FreeCAD terms
fcd50ed0f526645ca50bad2170e3b98b911b7678Ewaryst SchulzCopyright : (c) Robert Savu and Uni Bremen 2011
fcd50ed0f526645ca50bad2170e3b98b911b7678Ewaryst SchulzLicense : GPLv2 or higher, see LICENSE.txt
fcd50ed0f526645ca50bad2170e3b98b911b7678Ewaryst Schulz
fcd50ed0f526645ca50bad2170e3b98b911b7678Ewaryst SchulzMaintainer : Robert.Savu@dfki.de
fcd50ed0f526645ca50bad2170e3b98b911b7678Ewaryst SchulzStability : experimental
fcd50ed0f526645ca50bad2170e3b98b911b7678Ewaryst SchulzPortability : portable
fcd50ed0f526645ca50bad2170e3b98b911b7678Ewaryst Schulz
fcd50ed0f526645ca50bad2170e3b98b911b7678Ewaryst SchulzPrinting of the abstract syntax of FreeCAD terms
fcd50ed0f526645ca50bad2170e3b98b911b7678Ewaryst Schulz-}
fcd50ed0f526645ca50bad2170e3b98b911b7678Ewaryst Schulz
fcd50ed0f526645ca50bad2170e3b98b911b7678Ewaryst Schulzmodule FreeCAD.PrintAs where
fcd50ed0f526645ca50bad2170e3b98b911b7678Ewaryst Schulz
fcd50ed0f526645ca50bad2170e3b98b911b7678Ewaryst Schulzimport FreeCAD.As
fcd50ed0f526645ca50bad2170e3b98b911b7678Ewaryst Schulzimport Common.DocUtils
fcd50ed0f526645ca50bad2170e3b98b911b7678Ewaryst Schulzimport Common.Doc
fcd50ed0f526645ca50bad2170e3b98b911b7678Ewaryst Schulzimport Common.Id
fcd50ed0f526645ca50bad2170e3b98b911b7678Ewaryst Schulz
fcd50ed0f526645ca50bad2170e3b98b911b7678Ewaryst Schulz-- | Pretty printing 'Double'
fcd50ed0f526645ca50bad2170e3b98b911b7678Ewaryst Schulzinstance Pretty Double where
fcd50ed0f526645ca50bad2170e3b98b911b7678Ewaryst Schulz pretty = sidDoc . mkSimpleId . show
fcd50ed0f526645ca50bad2170e3b98b911b7678Ewaryst Schulz
fcd50ed0f526645ca50bad2170e3b98b911b7678Ewaryst Schulzinstance Pretty Vector3 where
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von Schroeder pretty v = pretty (x v, y v, z v)
fcd50ed0f526645ca50bad2170e3b98b911b7678Ewaryst Schulz
fcd50ed0f526645ca50bad2170e3b98b911b7678Ewaryst Schulzinstance Pretty Matrix33 where
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von Schroeder pretty m = vcat [lparen <+> rows, rparen] where
fcd50ed0f526645ca50bad2170e3b98b911b7678Ewaryst Schulz rows = vcat [row1, row2, row3]
fcd50ed0f526645ca50bad2170e3b98b911b7678Ewaryst Schulz row a b c = sepByCommas $ map pretty [a m, b m, c m]
fcd50ed0f526645ca50bad2170e3b98b911b7678Ewaryst Schulz row1 = row a11 a12 a13
fcd50ed0f526645ca50bad2170e3b98b911b7678Ewaryst Schulz row2 = row a21 a22 a23
fcd50ed0f526645ca50bad2170e3b98b911b7678Ewaryst Schulz row3 = row a31 a32 a33
b3df7e69d4d6066fdfae0a8a2f3b4a161eaaf540Robert Savu
b3df7e69d4d6066fdfae0a8a2f3b4a161eaaf540Robert Savu
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savuinstance Pretty Vector4 where
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savu pretty v = parens $ sepByCommas $ map pretty [q0 v, q1 v, q2 v, q3 v]
b3df7e69d4d6066fdfae0a8a2f3b4a161eaaf540Robert Savu
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savuinstance Pretty Placement where
239330cd665aac95fcf9cf95449594c96667cbc2Robert Savu pretty p1 =
239330cd665aac95fcf9cf95449594c96667cbc2Robert Savu brackets $ sepBySemis [pretty $ position p1, pretty $ orientation p1]
b3df7e69d4d6066fdfae0a8a2f3b4a161eaaf540Robert Savu
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von SchroederprintBO :: BaseObject -> Doc
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von SchroederprintBO (Box h w l) = text "Box" <+> vcat [hrow, wrow, lrow] where
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savu hrow = hcat [ text "Height ", pretty h]
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savu wrow = hcat [ text "Width ", pretty w]
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savu lrow = hcat [ text "Length ", pretty l]
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von SchroederprintBO (Cylinder a h r) = text "Cylinder" <+> vcat [arow, hrow, rrow] where
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savu arow = hcat [ text "Angle ", pretty a]
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savu hrow = hcat [ text "Heigth ", pretty h]
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savu rrow = hcat [ text "Radius ", pretty r]
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von SchroederprintBO (Sphere a1 a2 a3 r) = text "Sphere" <+>
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von Schroeder vcat [a1row, a2row, a3row, rrow] where
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savu a1row = hcat [ text "Angle1 ", pretty a1]
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savu a2row = hcat [ text "Angle2 ", pretty a2]
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savu a3row = hcat [ text "Angle3 ", pretty a3]
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savu rrow = hcat [ text "Radius ", pretty r]
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von SchroederprintBO (Cone a r1 r2 h) = text "Cone" <+> vcat [arow, brow, hrow, rrow] where
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savu arow = hcat [ text "Angle ", pretty a]
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savu brow = hcat [ text "Radius1 ", pretty r1]
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savu hrow = hcat [ text "Radius2 ", pretty r2]
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savu rrow = hcat [ text "Heigth ", pretty h]
b3df7e69d4d6066fdfae0a8a2f3b4a161eaaf540Robert SavuprintBO (Torus t1 t2 t3 t4 t5) = text "Torus" <+>
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von Schroeder vcat [t1r, t2r, t3r, t4r, t5r] where
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savu t1r = hcat [ text "Angle1 ", pretty t1]
3051a3502f027f3d7bb750a1d7a6b1b43cdd2a86Robert Savu t2r = hcat [ text "Angle2 ", pretty t2]
3051a3502f027f3d7bb750a1d7a6b1b43cdd2a86Robert Savu t3r = hcat [ text "Angle3 ", pretty t3]
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savu t4r = hcat [ text "Radius1 ", pretty t4]
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savu t5r = hcat [ text "Radius2 ", pretty t5]
ad306df140215d8fb88d14bbb7d685011e0f770bRobert SavuprintBO (Line a) = text "Line" <+> hcat [ text "Length ", pretty a]
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von SchroederprintBO (Circle a h r) = text "Circle" <+> vcat [arow, hrow, rrow] where
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savu arow = hcat [ text "sAngle ", pretty a]
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savu hrow = hcat [ text "eAngle ", pretty h]
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savu rrow = hcat [ text "Radius ", pretty r]
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von SchroederprintBO (Rectangle h w) = text "Rectangle" <+> vcat [hrow, wrow] where
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savu hrow = hcat [ text "Heigth ", pretty h]
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savu wrow = hcat [ text "Width ", pretty w]
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savu
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savuinstance Pretty BaseObject where
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von Schroeder pretty = printBO
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savu
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von SchroederprintObject :: Object -> Doc
ad306df140215d8fb88d14bbb7d685011e0f770bRobert SavuprintObject (BaseObject bo) = pretty bo
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von SchroederprintObject ( Cut eo1 eo2) = text "Cut" <+> vcat [pretty eo1, pretty eo2]
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von SchroederprintObject ( Common eo1 eo2) = text "Common" <+> vcat [pretty eo1, pretty eo2]
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von SchroederprintObject ( Fusion eo1 eo2) = text "Fusion" <+> vcat [pretty eo1, pretty eo2]
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von SchroederprintObject ( Section eo1 eo2) = text "Section" <+> vcat [pretty eo1, pretty eo2]
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von SchroederprintObject ( Extrusion eo d) = text "Extrusion" <+> vcat [pretty eo, pretty d]
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savu
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savuinstance Pretty Object where
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von Schroeder pretty = printObject
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savu
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von SchroederprintEO :: ExtendedObject -> Doc
ad306df140215d8fb88d14bbb7d685011e0f770bRobert SavuprintEO (Placed po) = pretty po
ad306df140215d8fb88d14bbb7d685011e0f770bRobert SavuprintEO (Ref s) = text s
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savu
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von SchroederprintPO :: PlacedObject -> Doc
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von SchroederprintPO (PlacedObject plc obj) = vcat [pretty obj, text "place" <+> pretty plc]
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savu
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von SchroederprintDoc :: Document -> Doc
239330cd665aac95fcf9cf95449594c96667cbc2Robert SavuprintDoc a = vcat $ map pretty a
239330cd665aac95fcf9cf95449594c96667cbc2Robert Savu
239330cd665aac95fcf9cf95449594c96667cbc2Robert Savuinstance Pretty ExtendedObject where
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von Schroeder pretty = printEO
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savu
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savuinstance Pretty PlacedObject where
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von Schroeder pretty = printPO
b3df7e69d4d6066fdfae0a8a2f3b4a161eaaf540Robert Savu
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savuinstance Pretty NamedObject where
b3df7e69d4d6066fdfae0a8a2f3b4a161eaaf540Robert Savu pretty no = lbrack $+$ space <+>
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von Schroeder hcat [doubleQuotes $ pretty $ name no, colon, space, pretty $ object no]
b3df7e69d4d6066fdfae0a8a2f3b4a161eaaf540Robert Savu $+$ rbrack
0a03acf9fa28e6ff00f4d7c9c6acbae64cf09c56Ewaryst Schulz
0a03acf9fa28e6ff00f4d7c9c6acbae64cf09c56Ewaryst Schulzinstance GetRange NamedObject
0a03acf9fa28e6ff00f4d7c9c6acbae64cf09c56Ewaryst Schulz
0a03acf9fa28e6ff00f4d7c9c6acbae64cf09c56Ewaryst Schulzinstance Pretty Sign where
0a03acf9fa28e6ff00f4d7c9c6acbae64cf09c56Ewaryst Schulz pretty = pretty . objects