module GUI.GraphDisplay
(convertGraph, initializeConverter)
where
import Static.DevGraph
import GUI.GraphMenu
import GUI.GraphTypes
import GUI.GraphLogic (updateGraph)
import GUI.GraphAbstraction
import qualified GUI.HTkUtils as HTk
import Data.IORef
import qualified Data.Map as Map (lookup)
import Control.Monad
import Interfaces.DataTypes
initializeConverter :: IO (GInfo, HTk.HTk)
initializeConverter :: IO (GInfo, HTk)
initializeConverter = do
HTk
wishInst <- [Config HTk] -> IO HTk
HTk.initHTk [Config HTk
HTk.withdrawMainWin]
GInfo
gInfo <- IO GInfo
emptyGInfo
(GInfo, HTk) -> IO (GInfo, HTk)
forall (m :: * -> *) a. Monad m => a -> m a
return (GInfo
gInfo, HTk
wishInst)
convertGraph :: ConvFunc
convertGraph :: ConvFunc
convertGraph gInfo :: GInfo
gInfo title :: String
title showLib :: LibFunc
showLib = do
let ln :: LibName
ln = GInfo -> LibName
libName GInfo
gInfo
IntState
ost <- IORef IntState -> IO IntState
forall a. IORef a -> IO a
readIORef (IORef IntState -> IO IntState) -> IORef IntState -> IO IntState
forall a b. (a -> b) -> a -> b
$ GInfo -> IORef IntState
intState GInfo
gInfo
case IntState -> Maybe IntIState
i_state IntState
ost of
Nothing -> String -> IO ()
forall a. HasCallStack => String -> a
error "Something went wrong, no library loaded"
Just ist :: IntIState
ist -> do
let libEnv :: LibEnv
libEnv = IntIState -> LibEnv
i_libEnv IntIState
ist
case LibName -> LibEnv -> Maybe DGraph
forall k a. Ord k => k -> Map k a -> Maybe a
Map.lookup LibName
ln LibEnv
libEnv of
Just dgraph :: DGraph
dgraph -> do
ConvFunc
initializeGraph GInfo
gInfo String
title LibFunc
showLib
Bool -> IO () -> IO ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless (DGraph -> Bool
isEmptyDG DGraph
dgraph) (IO () -> IO ()) -> IO () -> IO ()
forall a b. (a -> b) -> a -> b
$ GInfo -> [DGChange] -> IO ()
updateGraph GInfo
gInfo (DGraph -> [DGChange]
convert DGraph
dgraph)
Nothing -> String -> IO ()
forall a. HasCallStack => String -> a
error (String -> IO ()) -> String -> IO ()
forall a b. (a -> b) -> a -> b
$ "development graph with libname " String -> String -> String
forall a. [a] -> [a] -> [a]
++ LibName -> String
forall a. Show a => a -> String
show LibName
ln
String -> String -> String
forall a. [a] -> [a] -> [a]
++ " does not exist"
initializeGraph :: GInfo -> String -> LibFunc -> IO ()
initializeGraph :: ConvFunc
initializeGraph gInfo :: GInfo
gInfo title :: String
title showLib :: LibFunc
showLib = do
IntState
ost <- IORef IntState -> IO IntState
forall a. IORef a -> IO a
readIORef (IORef IntState -> IO IntState) -> IORef IntState -> IO IntState
forall a b. (a -> b) -> a -> b
$ GInfo -> IORef IntState
intState GInfo
gInfo
case IntState -> Maybe IntIState
i_state IntState
ost of
Nothing -> () -> IO ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
Just _ -> do
let title' :: String
title' = String
title String -> String -> String
forall a. [a] -> [a] -> [a]
++ " for " String -> String -> String
forall a. [a] -> [a] -> [a]
++ LibName -> String
forall a. Show a => a -> String
show (GInfo -> LibName
libName GInfo
gInfo)
GInfo -> String -> ConvFunc -> LibFunc -> IO ()
createGraph GInfo
gInfo String
title' ConvFunc
convertGraph LibFunc
showLib