3cc158f471fb37a8fbb73ec9f9304fd475b5f17dRobert Savu{- |
e9458b1a7a19a63aa4c179f9ab20f4d50681c168Jens ElknerModule : ./FreeCAD/XMLPrinter.hs
3cc158f471fb37a8fbb73ec9f9304fd475b5f17dRobert SavuDescription : XML Printer function for FreeCAD datatypes
3cc158f471fb37a8fbb73ec9f9304fd475b5f17dRobert SavuCopyright : (c) Robert Savu and Uni Bremen 2011
3cc158f471fb37a8fbb73ec9f9304fd475b5f17dRobert SavuLicense : GPLv2 or higher, see LICENSE.txt
3cc158f471fb37a8fbb73ec9f9304fd475b5f17dRobert Savu
3cc158f471fb37a8fbb73ec9f9304fd475b5f17dRobert SavuMaintainer : Robert.Savu@dfki.de
3cc158f471fb37a8fbb73ec9f9304fd475b5f17dRobert SavuStability : experimental
3cc158f471fb37a8fbb73ec9f9304fd475b5f17dRobert SavuPortability : portable
3cc158f471fb37a8fbb73ec9f9304fd475b5f17dRobert Savu
3cc158f471fb37a8fbb73ec9f9304fd475b5f17dRobert SavuDeclaration of the abstract datatypes of FreeCAD terms
3cc158f471fb37a8fbb73ec9f9304fd475b5f17dRobert Savu-}
3cc158f471fb37a8fbb73ec9f9304fd475b5f17dRobert Savu
3cc158f471fb37a8fbb73ec9f9304fd475b5f17dRobert Savu
53a3042e1da2253fd3f103bfef4deb47fc0bf6a6Ewaryst Schulzmodule FreeCAD.XMLPrinter where
43afc12b21eb01c8b513f694502881c92bf938baRobert Savu
43afc12b21eb01c8b513f694502881c92bf938baRobert Savuimport Text.XML.Light
43afc12b21eb01c8b513f694502881c92bf938baRobert Savuimport FreeCAD.As
53a3042e1da2253fd3f103bfef4deb47fc0bf6a6Ewaryst Schulzimport qualified Data.Set as Set
43afc12b21eb01c8b513f694502881c92bf938baRobert Savu
53a3042e1da2253fd3f103bfef4deb47fc0bf6a6Ewaryst SchulzexportXMLFC :: Sign -> String
53a3042e1da2253fd3f103bfef4deb47fc0bf6a6Ewaryst SchulzexportXMLFC = ppTopElement . doc2XML . Set.toList . objects
3cc158f471fb37a8fbb73ec9f9304fd475b5f17dRobert Savu
43afc12b21eb01c8b513f694502881c92bf938baRobert SavumakeAttr :: String -> String -> Attr
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von SchroedermakeAttr key = Attr (unqual key)
43afc12b21eb01c8b513f694502881c92bf938baRobert Savu
43afc12b21eb01c8b513f694502881c92bf938baRobert Savudoc2XML :: Document -> Element
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von Schroederdoc2XML list = unode "document" (map sendNamedObj list)
43afc12b21eb01c8b513f694502881c92bf938baRobert Savu
43afc12b21eb01c8b513f694502881c92bf938baRobert SavusendNamedObj :: NamedObject -> Element
5c1eefb64cc6b96cac1615a69adf0cf2e738eca5Robert SavusendNamedObj no = add_attr att (unode "Object" (getNOChildren no)) where
5c1eefb64cc6b96cac1615a69adf0cf2e738eca5Robert Savu att = Attr (unqual "name") (name no)
43afc12b21eb01c8b513f694502881c92bf938baRobert Savu
43afc12b21eb01c8b513f694502881c92bf938baRobert SavugetNOChildren :: NamedObject -> [Element]
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von SchroedergetNOChildren no = [makePlaceElem place, makeObjElem obj] where
43afc12b21eb01c8b513f694502881c92bf938baRobert Savu pobj = object no
43afc12b21eb01c8b513f694502881c92bf938baRobert Savu obj = o pobj
43afc12b21eb01c8b513f694502881c92bf938baRobert Savu place = p pobj
43afc12b21eb01c8b513f694502881c92bf938baRobert Savu
43afc12b21eb01c8b513f694502881c92bf938baRobert SavumakePlaceElem :: Placement -> Element
239330cd665aac95fcf9cf95449594c96667cbc2Robert SavumakePlaceElem pl = unode "placement" attrList
43afc12b21eb01c8b513f694502881c92bf938baRobert Savu where
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von Schroeder attrList = [xAt, yAt, zAt, q0At, q1At, q2At, q3At]
43afc12b21eb01c8b513f694502881c92bf938baRobert Savu mkp a b = Attr (unqual a) (show b)
43afc12b21eb01c8b513f694502881c92bf938baRobert Savu mko a b = Attr (unqual a) (show b)
43afc12b21eb01c8b513f694502881c92bf938baRobert Savu xAt = mkp "x" (x $ position pl)
43afc12b21eb01c8b513f694502881c92bf938baRobert Savu yAt = mkp "y" (y $ position pl)
43afc12b21eb01c8b513f694502881c92bf938baRobert Savu zAt = mkp "z" (z $ position pl)
43afc12b21eb01c8b513f694502881c92bf938baRobert Savu q0At = mko "q0" (q0 $ orientation pl)
43afc12b21eb01c8b513f694502881c92bf938baRobert Savu q1At = mko "q1" (q1 $ orientation pl)
43afc12b21eb01c8b513f694502881c92bf938baRobert Savu q2At = mko "q2" (q2 $ orientation pl)
43afc12b21eb01c8b513f694502881c92bf938baRobert Savu q3At = mko "q3" (q3 $ orientation pl)
43afc12b21eb01c8b513f694502881c92bf938baRobert Savu
562c5d54c9a424f7ca9f5d5b5af519a15a8ec15bChristian MaedermkNumAtt :: Show a => String -> a -> Attr
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von SchroedermkNumAtt key num = Attr (unqual key) (show num)
43afc12b21eb01c8b513f694502881c92bf938baRobert Savu
43afc12b21eb01c8b513f694502881c92bf938baRobert SavumakeObjElem :: Object -> Element
43afc12b21eb01c8b513f694502881c92bf938baRobert SavumakeObjElem obj = case obj of
43afc12b21eb01c8b513f694502881c92bf938baRobert Savu BaseObject bo -> makeBOElem bo
faaf1ee888c6ac9f6f2ced2a4883eca2368ac2e4Robert Savu Cut eo1 eo2 -> mk2refs "cut" eo1 eo2
faaf1ee888c6ac9f6f2ced2a4883eca2368ac2e4Robert Savu Common eo1 eo2 -> mk2refs "common" eo1 eo2
faaf1ee888c6ac9f6f2ced2a4883eca2368ac2e4Robert Savu Fusion eo1 eo2 -> mk2refs "fusion" eo1 eo2
faaf1ee888c6ac9f6f2ced2a4883eca2368ac2e4Robert Savu Section eo1 eo2 -> mk2refs "section" eo1 eo2
9e3bc669d4a84ef7401c7b95b1f2ee31a4cfdd5aRobert Savu Extrusion eo1 v3 -> mk1refs "extrusion" eo1 v3
43afc12b21eb01c8b513f694502881c92bf938baRobert Savu where
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von Schroeder mkRefAtt key eo = Attr (unqual key) (getEORef eo)
239330cd665aac95fcf9cf95449594c96667cbc2Robert Savu mk2refs consType ref1 ref2 =
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von Schroeder unode consType [mkRefAtt "base" ref1, mkRefAtt "tool" ref2]
239330cd665aac95fcf9cf95449594c96667cbc2Robert Savu mk1refs consType ref v3 =
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von Schroeder unode consType [mkRefAtt "base" ref, mkNumAtt "xval" (x v3),
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von Schroeder mkNumAtt "yval" (y v3), mkNumAtt "zval" (z v3)]
43afc12b21eb01c8b513f694502881c92bf938baRobert Savu
43afc12b21eb01c8b513f694502881c92bf938baRobert SavugetEORef :: ExtendedObject -> String
43afc12b21eb01c8b513f694502881c92bf938baRobert SavugetEORef eo = case eo of
43afc12b21eb01c8b513f694502881c92bf938baRobert Savu Ref s -> s
6363d5e793d536b0e0cb11971310a50a26684bb3Robert Savu Placed _ -> error "cannot get reference"
43afc12b21eb01c8b513f694502881c92bf938baRobert Savu
43afc12b21eb01c8b513f694502881c92bf938baRobert SavumakeBOElem :: BaseObject -> Element
43afc12b21eb01c8b513f694502881c92bf938baRobert SavumakeBOElem obj = case obj of
239330cd665aac95fcf9cf95449594c96667cbc2Robert Savu Box a1 a2 a3 ->
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von Schroeder unode "box" [mkNumAtt "height" a1, mkNumAtt "width" a2,
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von Schroeder mkNumAtt "length" a3]
239330cd665aac95fcf9cf95449594c96667cbc2Robert Savu Cylinder a1 a2 a3 ->
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von Schroeder unode "cylinder" [mkNumAtt "angle" a1,
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von Schroeder mkNumAtt "height" a2, mkNumAtt "radius" a3]
239330cd665aac95fcf9cf95449594c96667cbc2Robert Savu Sphere a1 a2 a3 a4 ->
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von Schroeder unode "sphere" [mkNumAtt "angle1" a1,
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von Schroeder mkNumAtt "angle2" a2, mkNumAtt "angle3" a3,
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von Schroeder mkNumAtt "radius" a4]
43afc12b21eb01c8b513f694502881c92bf938baRobert Savu Cone a1 a2 a3 a4 ->
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von Schroeder unode "cone" [mkNumAtt "angle" a1, mkNumAtt "radius1" a2,
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von Schroeder mkNumAtt "radius2" a3, mkNumAtt "height" a4]
43afc12b21eb01c8b513f694502881c92bf938baRobert Savu Torus a1 a2 a3 a4 a5 ->
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von Schroeder unode "torus" [mkNumAtt "angle1" a1,
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von Schroeder mkNumAtt "angle2" a2, mkNumAtt "angle3" a3,
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von Schroeder mkNumAtt "radius1" a4, mkNumAtt "radius2" a5]
43afc12b21eb01c8b513f694502881c92bf938baRobert Savu Line a1 -> unode "line" (mkNumAtt "length" a1)
239330cd665aac95fcf9cf95449594c96667cbc2Robert Savu Circle a1 a2 a3 ->
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von Schroeder unode "circle" [mkNumAtt "startang" a1,
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von Schroeder mkNumAtt "endang" a2, mkNumAtt "radius" a3]
239330cd665aac95fcf9cf95449594c96667cbc2Robert Savu Rectangle a1 a2 ->
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von Schroeder unode "rectangle" [mkNumAtt "height" a1,
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von Schroeder mkNumAtt "length" a2]