root/trunk/GUI/GraphDisplay.hs @ 11229

Revision 11229, 3.7 kB (checked in by rpascanu, 11 months ago)

Changes to GUI to use common datatypes in Interfaces

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1{- |
2Module      :  $Header$
3Description :  Central GUI for Hets, with display of development graph
4Copyright   :  (c) Jorina Freya Gerken, Till Mossakowski, Uni Bremen 2002-2006
5License     :  similar to LGPL, see HetCATS/LICENSE.txt or LIZENZ.txt
6
7Maintainer  :  till@informatik.uni-bremen.de
8Stability   :  provisional
9Portability :  non-portable (imports Logic)
10
11Conversion of development graphs from Logic.DevGraph
12   to abstract graphs of the graph display interface
13
14A composition table is used when abstracting the graph and composing
15multiple edges. It looks like this
16
17@
18 [(\"normal\",\"normal\",\"normal\"),
19 (\"normal\",\"inclusion\",\"normal\"),
20 (\"inclusion\",\"normal\",\"normal\"),
21 (\"inclusion\",\"inclusion\",\"inclusion\")]
22@
23
24A ginfo can be created with initgraphs. The graph is then created with
25addnode and addlink.
26
27-}
28
29module GUI.GraphDisplay
30    (convertGraph,initializeConverter)
31    where
32
33import Static.DevGraph
34
35import GUI.GraphMenu
36import GUI.GraphTypes
37import GUI.GraphLogic( convert, applyChanges, hideNodes)
38import qualified GUI.GraphAbstraction as GA
39
40import qualified GUI.HTkUtils as HTk
41
42import Data.IORef
43import qualified Data.Map as Map(lookup, insert)
44import Control.Concurrent.MVar
45
46import Interfaces.DataTypes
47
48initializeConverter :: IO (GInfo,HTk.HTk)
49initializeConverter = do
50  wishInst <- HTk.initHTk [HTk.withdrawMainWin]
51  gInfo <- emptyGInfo
52  return (gInfo,wishInst)
53
54{- | converts the development graph given by its libname into an
55    abstract graph and returns the descriptor of the latter, the
56    graphInfo it is contained in and the conversion maps. -}
57convertGraph :: ConvFunc
58convertGraph gInfo@(GInfo { gi_GraphInfo = actGraphInfo
59                          , windowCount = wc
60                          }) title showLib = do
61 ost <- readIORef $ intState gInfo
62 case i_state ost of
63  Nothing -> error "Something went wrong, no library loaded"
64  Just ist -> do
65   let libEnv = i_libEnv ist
66       libname = i_ln ist
67   case Map.lookup libname libEnv of
68    Just dgraph -> do
69      case openlock dgraph of
70        Just lock -> do
71          notopen <- tryPutMVar lock $ \ hist -> do
72            hhn <- GA.hasHiddenNodes actGraphInfo
73            case hhn of
74              True -> do
75                GA.showAll actGraphInfo
76                applyChanges actGraphInfo hist
77                hideNodes gInfo
78              False ->
79                applyChanges actGraphInfo hist
80            GA.redisplay actGraphInfo
81          case notopen of
82            True -> do
83              count <- takeMVar wc
84              putMVar wc $ count + 1
85              initializeGraph gInfo title showLib
86              if (isEmptyDG dgraph) then return ()
87                else do
88                  convert actGraphInfo dgraph
89                  return ()
90            False -> error $ "development graph with libname " ++ show libname
91                             ++" is already open"
92        Nothing -> do
93          lock <- newEmptyMVar
94          let nwle = Map.insert libname dgraph{openlock = Just lock} libEnv
95              nwst = ost { i_state = Just $ ist { i_libEnv = nwle}}
96          writeIORef (intState gInfo) nwst
97          convertGraph gInfo title showLib
98    Nothing -> error $ "development graph with libname " ++ show libname
99                       ++" does not exist"
100
101-- | initializes an empty abstract graph with the needed node and edge types,
102-- return type equals the one of convertGraph
103initializeGraph :: GInfo -> String -> LibFunc -> IO ()
104initializeGraph gInfo title showLib = do
105 ost <- readIORef $ intState gInfo
106 case i_state ost of
107  Nothing -> return ()
108  Just ist -> do
109   let ln = i_ln ist
110       title' = (title ++ " for " ++ show ln)
111   createGraph gInfo title' (convertGraph) (showLib)
Note: See TracBrowser for help on using the browser.