PrintAs.hs revision b3df7e69d4d6066fdfae0a8a2f3b4a161eaaf540
fcd50ed0f526645ca50bad2170e3b98b911b7678Ewaryst Schulz{- |
fcd50ed0f526645ca50bad2170e3b98b911b7678Ewaryst SchulzModule : $Header$
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 Schulz
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 Schulz
fcd50ed0f526645ca50bad2170e3b98b911b7678Ewaryst Schulzinstance Pretty Vector3 where
fcd50ed0f526645ca50bad2170e3b98b911b7678Ewaryst Schulz pretty v = pretty (x v, y v, z v)
fcd50ed0f526645ca50bad2170e3b98b911b7678Ewaryst Schulz
fcd50ed0f526645ca50bad2170e3b98b911b7678Ewaryst Schulzinstance Pretty Matrix33 where
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savu 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
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savu pretty p = brackets $sepBySemis [pretty $position p, pretty $orientation p]
b3df7e69d4d6066fdfae0a8a2f3b4a161eaaf540Robert Savu
ad306df140215d8fb88d14bbb7d685011e0f770bRobert SavuprintBO:: BaseObject -> Doc
ad306df140215d8fb88d14bbb7d685011e0f770bRobert SavuprintBO (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]
ad306df140215d8fb88d14bbb7d685011e0f770bRobert SavuprintBO (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]
b3df7e69d4d6066fdfae0a8a2f3b4a161eaaf540Robert SavuprintBO (Sphere a1 a2 a3 r)=text "Sphere" <+>
b3df7e69d4d6066fdfae0a8a2f3b4a161eaaf540Robert Savu (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]
ad306df140215d8fb88d14bbb7d685011e0f770bRobert SavuprintBO (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" <+>
b3df7e69d4d6066fdfae0a8a2f3b4a161eaaf540Robert Savu (vcat[t1r, t2r, t3r, t4r, t5r]) where
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savu t1r = hcat [ text "Angle1 ", pretty t1]
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savu t2r = hcat [ text "Angle1 ", pretty t2]
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savu t3r = hcat [ text "Angle1 ", 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]
ad306df140215d8fb88d14bbb7d685011e0f770bRobert SavuprintBO (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]
ad306df140215d8fb88d14bbb7d685011e0f770bRobert SavuprintBO (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
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savu pretty bo = printBO bo
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savu
ad306df140215d8fb88d14bbb7d685011e0f770bRobert SavuprintObject:: Object -> Doc
ad306df140215d8fb88d14bbb7d685011e0f770bRobert SavuprintObject (BaseObject bo) = pretty bo
ad306df140215d8fb88d14bbb7d685011e0f770bRobert SavuprintObject ( Cut eo1 eo2) = text "Cut" <+> vcat[pretty eo1, pretty eo2]
ad306df140215d8fb88d14bbb7d685011e0f770bRobert SavuprintObject ( Common eo1 eo2) = text "Common" <+> vcat[pretty eo1, pretty eo2]
ad306df140215d8fb88d14bbb7d685011e0f770bRobert SavuprintObject ( Fusion eo1 eo2) = text "Fusion" <+> vcat[pretty eo1, pretty eo2]
ad306df140215d8fb88d14bbb7d685011e0f770bRobert SavuprintObject ( Section eo1 eo2) = text "Section" <+> vcat[pretty eo1, pretty eo2]
b3df7e69d4d6066fdfae0a8a2f3b4a161eaaf540Robert SavuprintObject ( Extrusion eo d) = text "Extrusion" <+> vcat[pretty eo, pretty d]
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savu
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savuinstance Pretty Object where
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savu pretty o = printObject o
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savu
ad306df140215d8fb88d14bbb7d685011e0f770bRobert SavuprintEO:: ExtendedObject -> Doc
ad306df140215d8fb88d14bbb7d685011e0f770bRobert SavuprintEO (Placed po) = pretty po
ad306df140215d8fb88d14bbb7d685011e0f770bRobert SavuprintEO (Ref s) = text s
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savu
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savuinstance Pretty ExtendedObject where
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savu pretty eo = printEO eo
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savu
ad306df140215d8fb88d14bbb7d685011e0f770bRobert SavuprintPO:: PlacedObject -> Doc
ad306df140215d8fb88d14bbb7d685011e0f770bRobert SavuprintPO (PlacedObject p o) = vcat[pretty o, text "place" <+> pretty p]
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savu
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savu
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savuinstance Pretty PlacedObject where
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savu pretty po = printPO po
b3df7e69d4d6066fdfae0a8a2f3b4a161eaaf540Robert Savu
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savuinstance Pretty NamedObject where
b3df7e69d4d6066fdfae0a8a2f3b4a161eaaf540Robert Savu pretty no = lbrack $+$ space <+>
b3df7e69d4d6066fdfae0a8a2f3b4a161eaaf540Robert Savu hcat[doubleQuotes $pretty $name no, colon, space, pretty $object no]
b3df7e69d4d6066fdfae0a8a2f3b4a161eaaf540Robert Savu $+$ rbrack
ad306df140215d8fb88d14bbb7d685011e0f770bRobert SavuprintDoc:: Document -> Doc
b3df7e69d4d6066fdfae0a8a2f3b4a161eaaf540Robert SavuprintDoc a = vcat $ map pretty a