| 1 |
|
| 2 |
|
| 3 |
import DaVinciTypes hiding (Edge(..) , Node(..)) |
| 4 |
import qualified DaVinciTypes (Edge(..) , Node(..)) |
| 5 |
|
| 6 |
-- |
| 7 |
|
| 8 |
toDV :: NodeMap -> IO () |
| 9 |
toDV nodes |
| 10 |
= writeFile "out.daVinci" (show $ map g2n nodes) |
| 11 |
|
| 12 |
|
| 13 |
-- |
| 14 |
|
| 15 |
show_gsymbol (HappyTok x) = show x |
| 16 |
show_gsymbol t = show t |
| 17 |
|
| 18 |
g2n (n@(s,e,x), []) |
| 19 |
= mk_rhombus id (show_gsymbol x ++ show (s,e)) [] |
| 20 |
where |
| 21 |
id = show n |
| 22 |
|
| 23 |
g2n (n@(s,e,x), [Branch _ bs]) |
| 24 |
= mk_box id (show_gsymbol x ++ show (s,e)) |
| 25 |
$ [ DaVinciTypes.R (NodeId $ show j) | j <- bs ] |
| 26 |
where |
| 27 |
id = show n |
| 28 |
|
| 29 |
g2n (n@(s,e,x), bss) |
| 30 |
= mk_circle id (show_gsymbol x ++ show (s,e)) |
| 31 |
$ [ mk_box (id ++ "." ++ show i) (show_gsymbol x ++ show (s,e)) |
| 32 |
[ DaVinciTypes.R (NodeId $ show j) |
| 33 |
| j <- js ] |
| 34 |
| (i,Branch _ js) <- zip [0..] bss ] |
| 35 |
where |
| 36 |
id = show n |
| 37 |
|
| 38 |
--- |
| 39 |
|
| 40 |
mk_box = mk_node box_t |
| 41 |
mk_circle = mk_node circle_t |
| 42 |
mk_plain = mk_node text_t |
| 43 |
mk_rhombus = mk_node rhombus_t |
| 44 |
|
| 45 |
mk_node :: Attribute -> String -> String -> [DaVinciTypes.Node] |
| 46 |
-> DaVinciTypes.Node |
| 47 |
mk_node a id nm ts |
| 48 |
= DaVinciTypes.N (NodeId id) (Type "") [a,text nm] |
| 49 |
$ [ (mk_edge id n) t | (n,t) <- zip [1..] ts ] |
| 50 |
|
| 51 |
mk_edge id child_no t@(DaVinciTypes.R (NodeId id2)) |
| 52 |
= DaVinciTypes.E (EdgeId eId) (Type "") [] t |
| 53 |
where |
| 54 |
eId = concat [id,":",id2,"(",show child_no,")"] |
| 55 |
|
| 56 |
mk_edge id child_no t@(DaVinciTypes.N (NodeId id2) _ _ _) |
| 57 |
= DaVinciTypes.E (EdgeId eId) (Type "") [] t |
| 58 |
where |
| 59 |
eId = concat [id,":",id2,"(",show child_no,")"] |
| 60 |
|
| 61 |
--- |
| 62 |
|
| 63 |
nodeStyle = A "_GO" |
| 64 |
|
| 65 |
box_t, circle_t, ellipse_t, rhombus_t, text_t, icon_t :: Attribute |
| 66 |
box_t = nodeStyle "box" |
| 67 |
circle_t = nodeStyle "circle" |
| 68 |
ellipse_t = nodeStyle "ellipse" |
| 69 |
rhombus_t = nodeStyle "rhombus" |
| 70 |
text_t = nodeStyle "text" |
| 71 |
icon_t = nodeStyle "icon" |
| 72 |
|
| 73 |
text :: String -> Attribute |
| 74 |
text = A "OBJECT" |
| 75 |
|
| 76 |
|
| 77 |
|