PrintAs.hs revision 239330cd665aac95fcf9cf95449594c96667cbc2
8267b99c0d7a187abe6f87ad50530dc08f5d1cdcAndy Gimblett{- |
8267b99c0d7a187abe6f87ad50530dc08f5d1cdcAndy GimblettModule : $Header$
e071fb22ea9923a2a4ff41184d80ca46b55ee932Till MossakowskiDescription : print the abstract syntax of FreeCAD terms
8267b99c0d7a187abe6f87ad50530dc08f5d1cdcAndy GimblettCopyright : (c) Robert Savu and Uni Bremen 2011
8267b99c0d7a187abe6f87ad50530dc08f5d1cdcAndy GimblettLicense : GPLv2 or higher, see LICENSE.txt
8267b99c0d7a187abe6f87ad50530dc08f5d1cdcAndy Gimblett
8267b99c0d7a187abe6f87ad50530dc08f5d1cdcAndy GimblettMaintainer : Robert.Savu@dfki.de
8267b99c0d7a187abe6f87ad50530dc08f5d1cdcAndy GimblettStability : experimental
8267b99c0d7a187abe6f87ad50530dc08f5d1cdcAndy GimblettPortability : portable
8267b99c0d7a187abe6f87ad50530dc08f5d1cdcAndy Gimblett
8267b99c0d7a187abe6f87ad50530dc08f5d1cdcAndy GimblettPrinting of the abstract syntax of FreeCAD terms
020cdb5dad6b871aba61136a0e1567c00426de87Andy Gimblett-}
020cdb5dad6b871aba61136a0e1567c00426de87Andy Gimblett
020cdb5dad6b871aba61136a0e1567c00426de87Andy Gimblettmodule FreeCAD.PrintAs where
020cdb5dad6b871aba61136a0e1567c00426de87Andy Gimblett
2cf5a456da8bb3a2bbb695414d8304426e3bd277Andy Gimblettimport FreeCAD.As
020cdb5dad6b871aba61136a0e1567c00426de87Andy Gimblettimport Common.DocUtils
020cdb5dad6b871aba61136a0e1567c00426de87Andy Gimblettimport Common.Doc
020cdb5dad6b871aba61136a0e1567c00426de87Andy Gimblettimport Common.Id
020cdb5dad6b871aba61136a0e1567c00426de87Andy Gimblett
020cdb5dad6b871aba61136a0e1567c00426de87Andy Gimblett-- | Pretty printing 'Double'
020cdb5dad6b871aba61136a0e1567c00426de87Andy Gimblettinstance Pretty Double where
020cdb5dad6b871aba61136a0e1567c00426de87Andy Gimblett pretty = sidDoc . mkSimpleId . show
020cdb5dad6b871aba61136a0e1567c00426de87Andy Gimblett
020cdb5dad6b871aba61136a0e1567c00426de87Andy Gimblettinstance Pretty Vector3 where
020cdb5dad6b871aba61136a0e1567c00426de87Andy Gimblett pretty v = pretty (x v, y v, z v)
020cdb5dad6b871aba61136a0e1567c00426de87Andy Gimblett
020cdb5dad6b871aba61136a0e1567c00426de87Andy Gimblettinstance Pretty Matrix33 where
020cdb5dad6b871aba61136a0e1567c00426de87Andy Gimblett pretty m = vcat [lparen <+> rows, rparen] where
020cdb5dad6b871aba61136a0e1567c00426de87Andy Gimblett rows = vcat [row1, row2, row3]
020cdb5dad6b871aba61136a0e1567c00426de87Andy Gimblett row a b c = sepByCommas $ map pretty [a m, b m, c m]
020cdb5dad6b871aba61136a0e1567c00426de87Andy Gimblett row1 = row a11 a12 a13
020cdb5dad6b871aba61136a0e1567c00426de87Andy Gimblett row2 = row a21 a22 a23
020cdb5dad6b871aba61136a0e1567c00426de87Andy Gimblett row3 = row a31 a32 a33
020cdb5dad6b871aba61136a0e1567c00426de87Andy Gimblett
020cdb5dad6b871aba61136a0e1567c00426de87Andy Gimblett
020cdb5dad6b871aba61136a0e1567c00426de87Andy Gimblettinstance Pretty Vector4 where
2cf5a456da8bb3a2bbb695414d8304426e3bd277Andy Gimblett pretty v = parens $ sepByCommas $ map pretty [q0 v, q1 v, q2 v, q3 v]
020cdb5dad6b871aba61136a0e1567c00426de87Andy Gimblett
020cdb5dad6b871aba61136a0e1567c00426de87Andy Gimblettinstance Pretty Placement where
020cdb5dad6b871aba61136a0e1567c00426de87Andy Gimblett pretty p1 =
020cdb5dad6b871aba61136a0e1567c00426de87Andy Gimblett brackets $ sepBySemis [pretty $ position p1, pretty $ orientation p1]
020cdb5dad6b871aba61136a0e1567c00426de87Andy Gimblett
020cdb5dad6b871aba61136a0e1567c00426de87Andy GimblettprintBO:: BaseObject -> Doc
2cf5a456da8bb3a2bbb695414d8304426e3bd277Andy GimblettprintBO (Box h w l) = text "Box" <+> (vcat[hrow, wrow, lrow]) where
020cdb5dad6b871aba61136a0e1567c00426de87Andy Gimblett hrow = hcat [ text "Height ", pretty h]
020cdb5dad6b871aba61136a0e1567c00426de87Andy Gimblett wrow = hcat [ text "Width ", pretty w]
020cdb5dad6b871aba61136a0e1567c00426de87Andy Gimblett lrow = hcat [ text "Length ", pretty l]
020cdb5dad6b871aba61136a0e1567c00426de87Andy GimblettprintBO (Cylinder a h r) = text "Cylinder" <+> (vcat[arow, hrow, rrow]) where
020cdb5dad6b871aba61136a0e1567c00426de87Andy Gimblett arow = hcat [ text "Angle ", pretty a]
2cf5a456da8bb3a2bbb695414d8304426e3bd277Andy Gimblett hrow = hcat [ text "Heigth ", pretty h]
2cf5a456da8bb3a2bbb695414d8304426e3bd277Andy Gimblett rrow = hcat [ text "Radius ", pretty r]
2cf5a456da8bb3a2bbb695414d8304426e3bd277Andy GimblettprintBO (Sphere a1 a2 a3 r)=text "Sphere" <+>
020cdb5dad6b871aba61136a0e1567c00426de87Andy Gimblett (vcat[a1row, a2row, a3row, rrow]) where
020cdb5dad6b871aba61136a0e1567c00426de87Andy Gimblett a1row = hcat [ text "Angle1 ", pretty a1]
020cdb5dad6b871aba61136a0e1567c00426de87Andy Gimblett a2row = hcat [ text "Angle2 ", pretty a2]
020cdb5dad6b871aba61136a0e1567c00426de87Andy Gimblett a3row = hcat [ text "Angle3 ", pretty a3]
020cdb5dad6b871aba61136a0e1567c00426de87Andy Gimblett rrow = hcat [ text "Radius ", pretty r]
020cdb5dad6b871aba61136a0e1567c00426de87Andy GimblettprintBO (Cone a r1 r2 h) = text "Cone" <+> (vcat[arow, brow, hrow, rrow]) where
020cdb5dad6b871aba61136a0e1567c00426de87Andy Gimblett arow = hcat [ text "Angle ", pretty a]
020cdb5dad6b871aba61136a0e1567c00426de87Andy Gimblett brow = hcat [ text "Radius1 ", pretty r1]
020cdb5dad6b871aba61136a0e1567c00426de87Andy Gimblett hrow = hcat [ text "Radius2 ", pretty r2]
020cdb5dad6b871aba61136a0e1567c00426de87Andy Gimblett rrow = hcat [ text "Heigth ", pretty h]
020cdb5dad6b871aba61136a0e1567c00426de87Andy GimblettprintBO (Torus t1 t2 t3 t4 t5) = text "Torus" <+>
020cdb5dad6b871aba61136a0e1567c00426de87Andy Gimblett (vcat[t1r, t2r, t3r, t4r, t5r]) where
020cdb5dad6b871aba61136a0e1567c00426de87Andy Gimblett t1r = hcat [ text "Angle1 ", pretty t1]
020cdb5dad6b871aba61136a0e1567c00426de87Andy Gimblett t2r = hcat [ text "Angle2 ", pretty t2]
020cdb5dad6b871aba61136a0e1567c00426de87Andy Gimblett t3r = hcat [ text "Angle3 ", pretty t3]
t4r = hcat [ text "Radius1 ", pretty t4]
t5r = hcat [ text "Radius2 ", pretty t5]
printBO (Line a) = text "Line" <+> hcat [ text "Length ", pretty a]
printBO (Circle a h r) = text "Circle" <+> (vcat[arow, hrow, rrow]) where
arow = hcat [ text "sAngle ", pretty a]
hrow = hcat [ text "eAngle ", pretty h]
rrow = hcat [ text "Radius ", pretty r]
printBO (Rectangle h w) = text "Rectangle" <+> (vcat[hrow, wrow]) where
hrow = hcat [ text "Heigth ", pretty h]
wrow = hcat [ text "Width ", pretty w]
instance Pretty BaseObject where
pretty bo = printBO bo
printObject:: Object -> Doc
printObject (BaseObject bo) = pretty bo
printObject ( Cut eo1 eo2) = text "Cut" <+> vcat[pretty eo1, pretty eo2]
printObject ( Common eo1 eo2) = text "Common" <+> vcat[pretty eo1, pretty eo2]
printObject ( Fusion eo1 eo2) = text "Fusion" <+> vcat[pretty eo1, pretty eo2]
printObject ( Section eo1 eo2) = text "Section" <+> vcat[pretty eo1, pretty eo2]
printObject ( Extrusion eo d) = text "Extrusion" <+> vcat[pretty eo, pretty d]
instance Pretty Object where
pretty obj = printObject obj
printEO:: ExtendedObject -> Doc
printEO (Placed po) = pretty po
printEO (Ref s) = text s
printPO:: PlacedObject -> Doc
printPO (PlacedObject plc obj) = vcat[pretty obj, text "place" <+> pretty plc]
printDoc:: Document -> Doc
printDoc a = vcat $ map pretty a
instance Pretty ExtendedObject where
pretty eo = printEO eo
instance Pretty PlacedObject where
pretty po = printPO po
instance Pretty NamedObject where
pretty no = lbrack $+$ space <+>
hcat[doubleQuotes $ pretty $ name no, colon, space, pretty $ object no]
$+$ rbrack
instance GetRange NamedObject
instance Pretty Sign where
pretty = pretty . objects