Show
Ignore:
Timestamp:
07.01.2009 14:11:49 (11 months ago)
Author:
rpascanu
Message:

Changes to GUI to use common datatypes in Interfaces

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/GUI/GraphLogic.hs

    r11173 r11229  
    107107import Control.Concurrent.MVar 
    108108 
     109import Interfaces.History 
     110import Interfaces.DataTypes 
     111 
    109112-- | Locks the global lock and runs function 
    110113runAndLock :: GInfo -> IO () -> IO () 
     
    127130-- | Undo one step of the History 
    128131undo :: GInfo -> Bool -> IO () 
    129 undo gInfo@(GInfo { globalHist = gHist 
    130                   , gi_GraphInfo = actGraph 
    131                   }) isUndo = do 
    132   (guHist, grHist) <- takeMVar gHist 
    133   case if isUndo then guHist else grHist of 
    134     [] -> do 
    135        GA.showTemporaryMessage actGraph "History is empty..." 
    136        putMVar gHist (guHist, grHist) 
    137     lns : gHist' -> do 
    138       undoDGraphs gInfo isUndo lns 
    139       putMVar gHist $ if isUndo then (gHist', reverse lns : grHist) 
    140                                 else (reverse lns : guHist, gHist') 
    141  
    142 undoDGraphs :: GInfo -> Bool -> [LIB_NAME] -> IO () 
    143 undoDGraphs g u = mapM_ $ undoDGraph g u 
    144  
    145 undoDGraph :: GInfo -> Bool -> LIB_NAME -> IO () 
    146 undoDGraph gInfo@(GInfo { libEnvIORef = ioRefProofStatus 
    147                         , gi_GraphInfo = actGraph 
    148                         }) isUndo ln = do 
    149   GA.showTemporaryMessage actGraph $ 
    150         (if isUndo then "Un" else "Re") ++ "do last change to " 
    151         ++ show ln ++ "..." 
    152   lockGlobal gInfo 
    153   le <- readIORef ioRefProofStatus 
    154   let 
    155     dg = lookupDGraph ln le 
    156     (dg', changes) = (if isUndo then undoHistStep else redoHistStep) dg 
    157   writeIORef ioRefProofStatus $ Map.insert ln dg' le 
    158   case openlock dg' of 
    159     Nothing -> return () 
    160     Just lock -> do 
    161       mvar <- tryTakeMVar lock 
    162       case mvar of 
    163         Nothing -> return () 
    164         Just applyHist -> do 
    165           applyHist changes 
    166           putMVar lock applyHist 
    167   unlockGlobal gInfo 
     132undo gInfo@(GInfo { gi_GraphInfo = actGraph }) isUndo =  
     133 do 
     134  intSt <- readIORef $ intState gInfo 
     135  let nwSt = if isUndo then undoOneStep intSt else redoOneStep intSt  
     136  writeIORef (intState gInfo) nwSt 
     137  remakeGraph gInfo 
    168138 
    169139-- | reloads the Library of the DevGraph 
    170140reload :: GInfo -> IO() 
    171 reload gInfo@(GInfo { libEnvIORef = ioRefProofStatus 
    172                     , gi_LIB_NAME = ln 
    173                     , gi_hetcatsOpts = opts 
     141reload gInfo@(GInfo { gi_hetcatsOpts = opts 
    174142                    , gi_GraphInfo = actGraphInfo 
    175143                    }) = do 
    176144  lockGlobal gInfo 
    177   oldle <- readIORef ioRefProofStatus 
    178   let 
    179     libdeps = Rel.toList $ Rel.intransKernel $ Rel.transClosure $ Rel.fromList 
     145  oldst <- readIORef $ intState gInfo 
     146  case i_state oldst of  
     147   Nothing -> do  
     148               unlockGlobal gInfo 
     149               return () 
     150   Just ist -> do 
     151    let 
     152     oldle = i_libEnv ist 
     153     ln = i_ln ist 
     154     libdeps =Rel.toList$ Rel.intransKernel$ Rel.transClosure$ Rel.fromList 
    180155              $ getLibDeps oldle 
    181   ioruplibs <- newIORef ([] :: [LIB_NAME]) 
    182   writeIORef ioruplibs [] 
    183   reloadLibs ioRefProofStatus opts libdeps ioruplibs ln 
    184   unlockGlobal gInfo 
    185   libs <- readIORef ioruplibs 
    186   case libs of 
    187     [] -> GA.showTemporaryMessage actGraphInfo "Reload not needed!" 
    188     _ -> remakeGraph gInfo 
     156    ioruplibs <- newIORef ([] :: [LIB_NAME]) 
     157    writeIORef ioruplibs [] 
     158    reloadLibs (intState gInfo) opts libdeps ioruplibs ln 
     159    unlockGlobal gInfo 
     160    libs <- readIORef ioruplibs 
     161    case libs of 
     162      [] -> GA.showTemporaryMessage actGraphInfo "Reload not needed!" 
     163      _ -> remakeGraph gInfo 
    189164 
    190165-- | Creates a list of all LIB_NAME pairs, which have a dependency 
     
    199174 
    200175-- | Reloads a library 
    201 reloadLib :: IORef LibEnv -> HetcatsOpts -> IORef [LIB_NAME] -> LIB_NAME 
     176reloadLib :: IORef IntState -> HetcatsOpts -> IORef [LIB_NAME] -> LIB_NAME 
    202177          -> IO () 
    203 reloadLib iorle opts ioruplibs ln = do 
    204   mfile <- existsAnSource opts {intype = GuessIn} 
     178reloadLib iorst opts ioruplibs ln = do 
     179 ost <- readIORef iorst  
     180 case i_state ost of  
     181  Nothing -> return () 
     182  Just ist -> do 
     183   mfile <- existsAnSource opts {intype = GuessIn} 
    205184           $ rmSuffix $ libNameToFile opts ln 
    206   case mfile of 
     185   case mfile of 
    207186    Nothing -> return () 
    208187    Just file -> do 
    209       le <- readIORef iorle 
     188      let le = i_libEnv ist 
    210189      mFunc <- case openlock $ lookupDGraph ln le of 
    211190        Just lock -> tryTakeMVar lock 
     
    224203                                     "Reload: Can't set openlock in DevGraph" 
    225204            Nothing -> return () 
    226           writeIORef iorle $ newle 
     205          let nwst = ost { i_state = Just ist {  
     206                                       i_libEnv = newle } } 
     207          writeIORef iorst $ nwst 
    227208        Nothing -> 
    228209          errorDialog "Error" $ "Error when reloading file " ++ show file 
    229210 
    230211-- | Reloads libraries if nessesary 
    231 reloadLibs :: IORef LibEnv -> HetcatsOpts -> [(LIB_NAME, LIB_NAME)] 
     212reloadLibs :: IORef IntState -> HetcatsOpts -> [(LIB_NAME, LIB_NAME)] 
    232213           -> IORef [LIB_NAME] -> LIB_NAME -> IO Bool 
    233 reloadLibs iorle opts deps ioruplibs ln = do 
    234   uplibs <- readIORef ioruplibs 
    235   case elem ln uplibs of 
     214reloadLibs iorst opts deps ioruplibs ln = do 
     215 ost <- readIORef iorst 
     216 case i_state ost of  
     217  Nothing -> return False 
     218  Just ist -> do 
     219   uplibs <- readIORef ioruplibs 
     220   case elem ln uplibs of 
    236221    True -> return True 
    237222    False -> do 
    238223      let 
    239224        deps' = map (snd) $ filter (\ (ln',_) -> ln == ln') deps 
    240       res <- mapM (reloadLibs iorle opts deps ioruplibs) deps' 
     225      res <- mapM (reloadLibs iorst opts deps ioruplibs) deps' 
    241226      let 
    242227        libupdate = foldl (\ u r -> if r then True else u) False res 
    243228      case libupdate of 
    244229        True -> do 
    245           reloadLib iorle opts ioruplibs ln 
     230          reloadLib iorst opts ioruplibs ln 
    246231          return True 
    247232        False -> do 
    248           le <- readIORef iorle 
    249           let 
    250             newln:_ = filter (ln ==) $ Map.keys le 
    251           mfile <- existsAnSource opts $ rmSuffix $ libNameToFile opts ln 
    252           case mfile of 
    253             Nothing -> return False 
    254             Just file -> do 
    255               newmt <- getModificationTime file 
    256               let 
     233          ost' <- readIORef iorst 
     234          case i_state ost' of  
     235           Nothing -> return False 
     236           Just ist' -> do 
     237            let le = i_libEnv ist' 
     238            let 
     239             newln:_ = filter (ln ==) $ Map.keys le 
     240            mfile <- existsAnSource opts $ rmSuffix $ libNameToFile opts ln 
     241            case mfile of 
     242              Nothing -> return False 
     243              Just file -> do 
     244               newmt <- getModificationTime file 
     245               let 
    257246                libupdate' = (getModTime $ getLIB_ID newln) < newmt 
    258               case libupdate' of 
     247               case libupdate' of 
    259248                False -> return False 
    260249                True -> do 
    261                   reloadLib iorle opts ioruplibs ln 
     250                  reloadLib iorst opts ioruplibs ln 
    262251                  return True 
    263252 
    264253-- | Deletes the old edges and nodes of the Graph and makes new ones 
    265254remakeGraph :: GInfo -> IO () 
    266 remakeGraph gInfo@(GInfo { libEnvIORef = ioRefProofStatus 
    267                          , gi_LIB_NAME = ln 
    268                          , gi_GraphInfo = actGraphInfo 
     255remakeGraph gInfo@(GInfo { gi_GraphInfo = actGraphInfo 
    269256                         }) = do 
    270   le <- readIORef ioRefProofStatus 
    271   let 
    272     dgraph = lookupDGraph ln le 
    273   showNodes gInfo 
    274   GA.clear actGraphInfo 
    275   convert actGraphInfo dgraph 
    276   hideNodes gInfo 
     257  ost <- readIORef $ intState gInfo 
     258  case i_state ost of  
     259   Nothing -> return () 
     260   Just ist -> do 
     261    let le = i_libEnv ist 
     262        ln = i_ln ist 
     263        dgraph = lookupDGraph ln le 
     264    showNodes gInfo 
     265    GA.clear actGraphInfo 
     266    convert actGraphInfo dgraph 
     267    hideNodes gInfo 
    277268 
    278269-- | Toggles to display internal node names 
     
    301292-- | hides all unnamed internal nodes that are proven 
    302293hideNodes :: GInfo -> IO () 
    303 hideNodes (GInfo { libEnvIORef = ioRefProofStatus 
    304                  , gi_LIB_NAME = ln 
    305                  , gi_GraphInfo = actGraphInfo 
     294hideNodes gInfo@(GInfo { gi_GraphInfo = actGraphInfo 
    306295                 }) = do 
    307296  hhn <- GA.hasHiddenNodes actGraphInfo 
    308   case hhn of 
    309     True -> 
    310       GA.showTemporaryMessage actGraphInfo "Nodes already hidden ..." 
    311     False -> do 
    312       GA.showTemporaryMessage actGraphInfo "Hiding unnamed nodes..." 
    313       le <- readIORef ioRefProofStatus 
    314       let dg = lookupDGraph ln le 
    315           nodes = selectNodesByType dg [DGNodeType 
     297  ost <- readIORef $ intState gInfo 
     298  case i_state ost of  
     299   Nothing -> return () 
     300   Just ist -> do  
     301    case hhn of 
     302     True -> 
     303       GA.showTemporaryMessage actGraphInfo "Nodes already hidden ..." 
     304     False -> do 
     305       GA.showTemporaryMessage actGraphInfo "Hiding unnamed nodes..." 
     306       let le = i_libEnv ist 
     307           ln = i_ln ist 
     308           dg = lookupDGraph ln le 
     309           nodes = selectNodesByType dg [DGNodeType 
    316310                                         {nonRefType = NonRefType 
    317311                                           {isProvenCons = True 
    318312                                           , isInternalSpec = True} 
    319313                                         , isLocallyEmpty = True}] 
    320           edges = getCompressedEdges dg nodes 
    321       GA.hideNodes actGraphInfo nodes edges 
     314           edges = getCompressedEdges dg nodes 
     315       GA.hideNodes actGraphInfo nodes edges 
    322316 
    323317-- | selects all nodes of a type with outgoing edges 
     
    382376-- | Let the user select a Node to focus 
    383377focusNode :: GInfo -> IO () 
    384 focusNode GInfo { libEnvIORef = ioRefProofStatus 
    385                 , gi_LIB_NAME = ln 
    386                 , gi_GraphInfo = grInfo } = do 
    387   le <- readIORef ioRefProofStatus 
    388   idsnodes <- filterM (fmap not . GA.isHiddenNode grInfo . fst) 
     378focusNode gInfo@(GInfo { gi_GraphInfo = grInfo }) = do 
     379 ost <- readIORef $ intState gInfo 
     380 case i_state ost of  
     381  Nothing -> return () 
     382  Just ist -> do 
     383   let le = i_libEnv ist 
     384       ln = i_ln ist 
     385   idsnodes <- filterM (fmap not . GA.isHiddenNode grInfo . fst) 
    389386                    $ labNodesDG $ lookupDGraph ln le 
    390   selection <- listBox "Select a node to focus" 
    391     $ map (\ (n, l) -> shows n " " ++ getDGNodeName l) idsnodes 
    392   case selection of 
     387   selection <- listBox "Select a node to focus" 
     388     $ map (\ (n, l) -> shows n " " ++ getDGNodeName l) idsnodes 
     389   case selection of 
    393390    Just idx -> GA.focusNode grInfo $ fst $ idsnodes !! idx 
    394391    Nothing -> return () 
    395392 
    396393translateGraph :: GInfo -> ConvFunc -> LibFunc -> IO () 
    397 translateGraph (GInfo {libEnvIORef = ioRefProofStatus, 
    398                        gi_LIB_NAME = ln, 
    399                        gi_hetcatsOpts = opts 
     394translateGraph gInfo@(GInfo { gi_hetcatsOpts = opts 
    400395                      }) convGraph showLib = do 
    401   le <- readIORef ioRefProofStatus 
    402   openTranslateGraph le ln opts (getDGLogic le) convGraph showLib 
     396 ost <- readIORef $ intState gInfo 
     397 case i_state ost of  
     398  Nothing -> return () 
     399  Just ist -> do  
     400   let le = i_libEnv ist 
     401       ln = i_ln ist 
     402   openTranslateGraph le ln opts (getDGLogic le) convGraph showLib 
    403403 
    404404showLibGraph :: GInfo -> LibFunc -> IO () 
     
    431431 
    432432saveProofStatus :: GInfo -> FilePath -> IO () 
    433 saveProofStatus (GInfo { libEnvIORef = ioRefProofStatus 
    434                        , gi_LIB_NAME = ln 
    435                        , gi_hetcatsOpts = opts 
     433saveProofStatus gInfo@(GInfo { gi_hetcatsOpts = opts 
    436434                       }) file = encapsulateWaitTermAct $ do 
    437     proofStatus <- readIORef ioRefProofStatus 
     435  ost <- readIORef $ intState gInfo 
     436  case i_state ost of  
     437   Nothing -> return () 
     438   Just ist -> do  
     439    let proofStatus = i_libEnv ist 
     440        ln = i_ln ist 
    438441    writeShATermFile file (ln, lookupHistory ln proofStatus) 
    439442    putIfVerbose opts 2 $ "Wrote " ++ file 
     
    442445openProofStatus :: GInfo -> FilePath -> ConvFunc -> LibFunc 
    443446                -> IO () 
    444 openProofStatus gInfo@(GInfo { libEnvIORef = ioRefProofStatus 
    445                              , gi_LIB_NAME = ln 
    446                              , gi_hetcatsOpts = opts 
     447openProofStatus gInfo@(GInfo { gi_hetcatsOpts = opts 
    447448                             }) file convGraph showLib = do 
     449 ost <- readIORef $ intState gInfo 
     450 case i_state ost of  
     451  Nothing -> return () 
     452  Just ist -> do 
     453    let ln = i_ln ist 
    448454    mh <- readVerbose opts ln file 
    449455    case mh of 
     
    462468                Just dg -> do 
    463469                    lockGlobal gInfo 
    464                     oldEnv <- readIORef ioRefProofStatus 
    465                     let proofStatus = Map.insert ln 
     470                    let oldEnv = i_libEnv ist 
     471                        proofStatus = Map.insert ln 
    466472                                      (applyProofHistory h dg) oldEnv 
    467                     writeIORef ioRefProofStatus proofStatus 
     473                        nwst = ost { i_state = Just ist { 
     474                                      i_libEnv = proofStatus } } 
     475                    writeIORef (intState gInfo) nwst 
    468476                    unlockGlobal gInfo 
    469477                    gInfo' <- copyGInfo gInfo ln 
     
    475483                    GA.activateGraphWindow actGraphInfo 
    476484 
    477 -- | apply a rule of the development graph calculus 
     485-- | apply a rule of the development graph calculus  
    478486proofMenu :: GInfo 
    479487             -> (LibEnv -> IO (Res.Result LibEnv)) 
    480488             -> IO () 
    481 proofMenu gInfo@(GInfo { libEnvIORef = ioRefProofStatus 
    482                        , gi_LIB_NAME = ln 
    483                        , gi_GraphInfo = actGraphInfo 
     489proofMenu gInfo@(GInfo { gi_GraphInfo = actGraphInfo 
    484490                       , gi_hetcatsOpts = hOpts 
    485491                       , proofGUIMVar = guiMVar 
    486                        , globalHist = gHist 
    487492                       }) proofFun = do 
    488   filled <- tryPutMVar guiMVar Nothing 
    489   if not filled 
     493 ost <- readIORef $ intState gInfo 
     494 case i_state ost of  
     495  Nothing -> return () 
     496  Just ist -> do 
     497   let ln = i_ln ist 
     498   filled <- tryPutMVar guiMVar Nothing 
     499   if not filled 
    490500    then readMVar guiMVar >>= 
    491501                  (maybe (putIfVerbose hOpts 0 "proofMenu: ignored Nothing") 
     
    497507    else do 
    498508      lockGlobal gInfo 
    499       proofStatus <- readIORef ioRefProofStatus 
     509      let proofStatus = i_libEnv ist 
    500510      putIfVerbose hOpts 4 "Proof started via \"Proofs\" menu" 
    501511      Res.Result ds res <- proofFun proofStatus 
     
    508518          let newGr = lookupDGraph ln newProofStatus 
    509519              history = snd $ splitHistory (lookupDGraph ln proofStatus) newGr 
    510           (guHist, grHist) <- takeMVar gHist 
    511520          doDump hOpts "PrintHistory" $ do 
    512521            putStrLn "History" 
    513522            print $ prettyHistory history 
    514           putMVar gHist 
    515            (calcGlobalHistory proofStatus newProofStatus : guHist, grHist) 
     523          let lln = map (\x-> [DgCommandChange x]) $ calcGlobalHistory  
     524                                                   proofStatus newProofStatus 
     525              nst = foldl (add2history "dg rule") ost lln  
     526      --        (calcGlobalHistory proofStatus newProofStatus : guHist, grHist) 
    516527          applyChanges actGraphInfo $ reverse 
    517528            $ flatHistory history 
    518           writeIORef ioRefProofStatus newProofStatus 
     529          let nwst = nst { i_state = Just ist { i_libEnv=newProofStatus}} 
     530          writeIORef (intState gInfo) nwst 
    519531          unlockGlobal gInfo 
    520532          hideShowNames gInfo False 
     
    545557   fetches the theory from a node inside the IO Monad 
    546558   (added by KL based on code in getTheoryOfNode) -} 
    547 lookupTheoryOfNode :: IORef LibEnv -> LIB_NAME -> Int 
     559lookupTheoryOfNode :: LibEnv -> LIB_NAME -> Int 
    548560                   -> IO (Res.Result (LibEnv, Node, G_theory)) 
    549 lookupTheoryOfNode proofStatusRef ln descr = do 
    550   libEnv <- readIORef proofStatusRef 
     561lookupTheoryOfNode libEnv ln descr = do 
    551562  return $ do 
    552563    (libEnv', gth) <- computeTheory True libEnv ln descr 
     
    562573used by the node menu defined in initializeGraph-} 
    563574getTheoryOfNode :: GInfo -> Int -> DGraph -> IO () 
    564 getTheoryOfNode gInfo@(GInfo { gi_LIB_NAME = ln 
    565                              , gi_GraphInfo = actGraphInfo 
    566                              , libEnvIORef = le 
     575getTheoryOfNode gInfo@(GInfo { gi_GraphInfo = actGraphInfo 
    567576                             }) descr dgraph = do 
    568  r <- lookupTheoryOfNode le ln descr 
    569  case r of 
    570   Res.Result ds res -> do 
    571     showDiagMess (gi_hetcatsOpts gInfo) ds 
    572     case res of 
     577 ost <- readIORef $ intState gInfo 
     578 case i_state ost of  
     579  Nothing -> return () 
     580  Just ist -> do 
     581   let le = i_libEnv ist 
     582       ln = i_ln ist 
     583   r <- lookupTheoryOfNode le ln descr 
     584   case r of 
     585    Res.Result ds res -> do 
     586     showDiagMess (gi_hetcatsOpts gInfo) ds 
     587     case res of 
    573588      (Just (le', n, gth)) -> do 
    574589        lockGlobal gInfo 
     
    576591                                 (addHasInHidingWarning dgraph n) gth 
    577592        let newGr = lookupDGraph ln le' 
    578         libEnv <- readIORef le 
    579         let history = snd $ splitHistory (lookupDGraph ln libEnv) newGr 
     593        let history = snd $ splitHistory (lookupDGraph ln le) newGr 
    580594        applyChanges actGraphInfo $ reverse $ flatHistory history 
    581         writeIORef le le' 
     595        let nwst = ost { i_state = Just $ist { i_libEnv = le'} } 
     596        writeIORef (intState gInfo) nwst 
    582597        unlockGlobal gInfo 
    583598      _ -> return () 
     
    587602translateTheoryOfNode :: GInfo -> Int -> DGraph -> IO () 
    588603translateTheoryOfNode 
    589   gInfo@(GInfo {gi_hetcatsOpts = opts, libEnvIORef = le}) node dgraph = do 
    590     libEnv <- readIORef le 
    591     let Res.Result ds mEnv = computeTheory False libEnv (gi_LIB_NAME gInfo) node 
     604  gInfo@(GInfo {gi_hetcatsOpts = opts}) node dgraph = do 
     605 ost <- readIORef $ intState gInfo 
     606 case i_state ost of  
     607  Nothing -> return () 
     608  Just ist -> do 
     609    let libEnv = i_libEnv ist 
     610        ln = i_ln ist 
     611        Res.Result ds mEnv = computeTheory False libEnv ln node 
    592612    case mEnv of 
    593613      Just (_, th@(G_theory lid sign _ sens _)) -> do 
     
    645665-- | start local theorem proving or consistency checking at a node 
    646666proveAtNode :: Bool -> GInfo -> Int -> DGraph -> IO () 
    647 proveAtNode checkCons gInfo@(GInfo { libEnvIORef = ioRefProofStatus 
    648                                    , gi_LIB_NAME = ln 
    649                                    , commandHist = ch }) descr dgraph = do 
    650   let dgn = labDG dgraph descr 
    651       libNode = (ln,descr) 
    652   (dgraph',dgn') <- case hasLock dgn of 
     667proveAtNode checkCons gInfo descr dgraph = do 
     668 ost <- readIORef $ intState gInfo 
     669 case i_state ost of  
     670  Nothing -> return () 
     671  Just ist -> do 
     672   let ln = i_ln ist 
     673       le = i_libEnv ist 
     674       dgn = labDG dgraph descr 
     675       libNode = (ln,descr) 
     676   (dgraph',dgn') <- case hasLock dgn of 
    653677    True -> return (dgraph, dgn) 
    654678    False -> do 
    655679      lockGlobal gInfo 
    656       le <- readIORef ioRefProofStatus 
    657680      (dgraph',dgn') <- initLocking (lookupDGraph ln le) (descr, dgn) 
    658       writeIORef ioRefProofStatus $ Map.insert ln dgraph' le 
     681      let nwle = Map.insert ln dgraph' le 
     682          nwst = ost { i_state = Just $ ist { i_libEnv = nwle} } 
     683      writeIORef (intState gInfo) nwst 
    659684      unlockGlobal gInfo 
    660685      return (dgraph',dgn') 
    661   locked <- tryLockLocal dgn' 
    662   case locked of 
     686   locked <- tryLockLocal dgn' 
     687   case locked of 
    663688    False -> do 
    664689      errorDialog "Error" "Proofwindow already open" 
    665690    True -> do 
    666691      let action = do 
    667             le <- readIORef ioRefProofStatus 
    668692            guiMVar <- newMVar Nothing 
    669693            res <- basicInferenceNode checkCons logicGraph libNode ln 
    670                 guiMVar le ch 
     694                guiMVar le 
     695            -- add to history ch 
    671696            runProveAtNode checkCons gInfo (descr, dgn') res 
    672697            unlockLocal dgn' 
     
    685710               -> Res.Result (LibEnv, Res.Result G_theory) -> IO () 
    686711runProveAtNode checkCons gInfo (v, dgnode) res = case maybeResult res of 
    687     Just (le, tres) -> do 
    688         let nodetext = getDGNodeName dgnode ++ " node: " ++ show v 
     712  Just (le, tres) -> do 
     713   ost <- readIORef $ intState gInfo 
     714   case i_state ost of  
     715    Nothing -> return () 
     716    Just ist -> do 
     717        let ln = i_ln ist 
     718            nodetext = getDGNodeName dgnode ++ " node: " ++ show v 
    689719        when checkCons $ case maybeResult tres of 
    690720          Just gth -> createTextSaveDisplay 
     
    695725              $ unlines $ "could not (re-)construct a model" : map diagString ds 
    696726        proofMenu gInfo $ mergeDGNodeLab gInfo 
    697           (v, labDG (lookupDGraph (gi_LIB_NAME gInfo) le) v) 
    698     Nothing -> return () 
     727          (v, labDG (lookupDGraph ln le) v) 
     728  Nothing -> return () 
    699729 
    700730mergeDGNodeLab :: GInfo -> LNode DGNodeLab -> LibEnv -> IO (Res.Result LibEnv) 
    701 mergeDGNodeLab (GInfo{gi_LIB_NAME = ln}) (v, new_dgn) le = do 
    702   let dg = lookupDGraph ln le 
    703       old_dgn = labDG dg v 
    704   return $ do 
     731mergeDGNodeLab gInfo (v, new_dgn) le = do 
     732 ost <- readIORef $ intState gInfo 
     733 case i_state ost of  
     734  Nothing -> return (Result [] (Just le)) 
     735  Just ist -> do 
     736   let ln = i_ln ist 
     737       dg = lookupDGraph ln le 
     738       old_dgn = labDG dg v 
     739   return $ do 
    705740    theory <- joinG_sentences (dgn_theory old_dgn) $ dgn_theory new_dgn 
    706741    let new_dgn' = old_dgn { dgn_theory = theory } 
     
    723758-- | check conservativity of the edge 
    724759checkconservativityOfEdge :: Int -> GInfo -> Maybe (LEdge DGLinkLab) -> IO () 
    725 checkconservativityOfEdge _ gInfo@(GInfo{gi_LIB_NAME = ln, 
    726                                          gi_GraphInfo = _actGraphInfo, 
    727                                          libEnvIORef = le}) 
     760checkconservativityOfEdge _ gInfo@(GInfo{ gi_GraphInfo = _actGraphInfo}) 
    728761                           (Just (source,target,linklab)) = do 
    729   lockGlobal gInfo 
    730   libEnv <- readIORef $ libEnvIORef gInfo 
    731   let libEnv' = case convertToNf ln libEnv target of 
    732                   Result _ (Just lE) -> lE 
    733                   _ -> error "checkconservativityOfEdge: convertToNf" 
    734   let (_, thTar) = 
     762 ost <- readIORef $ intState gInfo 
     763 case i_state ost of  
     764  Nothing -> return () 
     765  Just ist -> do 
     766   let ln = i_ln ist 
     767       libEnv = i_libEnv ist 
     768   lockGlobal gInfo 
     769   let libEnv' = case convertToNf ln libEnv target of 
     770                   Result _ (Just lE) -> lE 
     771                   _ -> error "checkconservativityOfEdge: convertToNf" 
     772   let (_, thTar) = 
    735773        case computeTheory True libEnv' ln target of 
    736774          Res.Result _ (Just th1) -> th1 
    737775          _ -> error "checkconservativityOfEdge: computeTheory" 
    738   G_theory lid _sign _ sensTar _ <- return thTar 
    739   GMorphism cid _ _ morphism2 _ <- return $ dgl_morphism linklab 
    740   Just (GMorphism cid' _ _ morphism3 _) <- return $ 
     776   G_theory lid _sign _ sensTar _ <- return thTar 
     777   GMorphism cid _ _ morphism2 _ <- return $ dgl_morphism linklab 
     778   Just (GMorphism cid' _ _ morphism3 _) <- return $ 
    741779                  dgn_sigma $ labDG (lookupDGraph ln libEnv') target 
    742   morphism2' <- coerceMorphism (targetLogic cid) lid 
     780   morphism2' <- coerceMorphism (targetLogic cid) lid 
    743781                "checkconservativityOfEdge2" morphism2 
    744   morphism3' <- coerceMorphism (targetLogic cid') lid 
     782   morphism3' <- coerceMorphism (targetLogic cid') lid 
    745783                "checkconservativityOfEdge3" morphism3 
    746   let compMor = case comp morphism2' morphism3' of 
    747                Res.Result _ (Just phi) -> phi 
    748                _ -> error "checkconservativtiyOfEdge: comp" 
    749   let (_le', thSrc) = 
    750         case computeTheory False libEnv' (gi_LIB_NAME gInfo) source of 
     784   let compMor = case comp morphism2' morphism3' of 
     785                Res.Result _ (Just phi) -> phi 
     786                _ -> error "checkconservativtiyOfEdge: comp" 
     787   let (_le', thSrc) = 
     788        case computeTheory False libEnv' ln source of 
    751789          Res.Result _ (Just th1) -> th1 
    752790          _ -> error "checkconservativityOfEdge: computeTheory" 
    753   G_theory lid1 sign1 _ sensSrc1 _ <- return thSrc 
    754   sign2 <- coerceSign lid1 lid "checkconservativityOfEdge.coerceSign" sign1 
    755   sensSrc2 <- coerceThSens lid1 lid "checkconservativityOfEdge1" sensSrc1 
    756   let transSensSrc = propagateErrors 
     791   G_theory lid1 sign1 _ sensSrc1 _ <- return thSrc 
     792   sign2 <- coerceSign lid1 lid "checkconservativityOfEdge.coerceSign" sign1 
     793   sensSrc2 <- coerceThSens lid1 lid "checkconservativityOfEdge1" sensSrc1 
     794   let transSensSrc = propagateErrors 
    757795        $ mapThSensValueM (map_sen lid compMor) sensSrc2 
    758   if length (conservativityCheck lid) < 1 
    759    then 
     796   if length (conservativityCheck lid) < 1 
     797    then 
    760798       do 
    761799        infoDialog "Result of conservativity check" 
    762800                   "No conservativity checkers available" 
    763         writeIORef le libEnv' 
     801        let nwst = ost {i_state = Just $ist{ i_libEnv=libEnv'}} 
     802        writeIORef (intState gInfo) nwst 
    764803        unlockGlobal gInfo 
    765    else 
    766     do 
    767      checkerR <- conservativityChoser $ conservativityCheck lid 
    768      if Res.hasErrors $ Res.diags checkerR 
    769       then 
    770        do 
    771         infoDialog "Result of conservativity check" 
    772                    "No conservativity checker chosen" 
    773         writeIORef le libEnv' 
    774         unlockGlobal gInfo 
    775       else 
    776        do 
    777         let chCons =  checkConservativity $ 
    778                       maybe (error "checkconservativityOfEdge4") id 
    779                             $ Res.maybeResult $ checkerR 
    780         let Res.Result ds res = 
    781                 chCons 
    782                    (plainSign sign2, toNamedList sensSrc2) 
    783                    compMor $ toNamedList 
    784                                (sensTar `OMap.difference` transSensSrc) 
    785             showObls [] = "" 
    786             showObls obls = ", provided that the following proof obligations " 
     804    else 
     805     do 
     806      checkerR <- conservativityChoser $ conservativityCheck lid 
     807      if Res.hasErrors $ Res.diags checkerR 
     808       then 
     809        do 
     810         infoDialog "Result of conservativity check" 
     811                    "No conservativity checker chosen" 
     812         let nwst = ost {i_state = Just $ ist { i_libEnv = libEnv'}} 
     813         writeIORef (intState gInfo) nwst 
     814         unlockGlobal gInfo 
     815       else 
     816        do 
     817         let chCons =  checkConservativity $ 
     818                       maybe (error "checkconservativityOfEdge4") id 
     819                             $ Res.maybeResult $ checkerR 
     820         let Res.Result ds res = 
     821                 chCons 
     822                    (plainSign sign2, toNamedList sensSrc2) 
     823                    compMor $ toNamedList 
     824                                (sensTar `OMap.difference` transSensSrc) 
     825             showObls [] = "" 
     826             showObls obls= ", provided that the following proof obligations " 
    787827                            ++ "can be discharged:\n" 
    788828                            ++ concatMap (flip showDoc "\n") obls 
    789             showRes = case res of 
     829             showRes = case res of 
    790830                       Just (Just (cst, obls)) -> "The link is " 
    791831                        ++ showConsistencyStatus cst ++ showObls obls 
    792832                       _ -> "Could not determine whether link is conservative" 
    793             myDiags = showRelDiags 2 ds 
    794         createTextDisplay "Result of conservativity check" 
    795                         (showRes ++ "\n" ++ myDiags) 
    796         let 
     833             myDiags = showRelDiags 2 ds 
     834         createTextDisplay "Result of conservativity check" 
     835                         (showRes ++ "\n" ++ myDiags) 
     836         let 
    797837            consShow = case res of 
    798838                        Just (Just (cst, _)) -> cst 
     
    813853            changes = [ DeleteEdge (source,target,linklab) 
    814854                      , InsertEdge provenEdge ] 
    815         let newGr = lookupDGraph ln libEnv' 
    816             nextGr = changesDGH newGr changes 
    817             newLibEnv = Map.insert ln 
     855         let newGr = lookupDGraph ln libEnv' 
     856             nextGr = changesDGH newGr changes 
     857             newLibEnv = Map.insert ln 
    818858              (groupHistory newGr conservativityRule nextGr) libEnv' 
    819         -- applyChanges actGraphInfo history 
    820         writeIORef le newLibEnv 
    821         unlockGlobal gInfo 
     859         -- applyChanges actGraphInfo history 
     860         let nwst = ost { i_state = Just $ ist { i_libEnv = newLibEnv}} 
     861         writeIORef (intState gInfo) nwst 
     862         unlockGlobal gInfo 
    822863 
    823864checkconservativityOfEdge descr _ Nothing = 
     
    876917-- | show library referened by a DGRef node (=node drawn as a box) 
    877918showReferencedLibrary :: Int -> GInfo -> ConvFunc -> LibFunc -> IO () 
    878 showReferencedLibrary descr gInfo@(GInfo { libEnvIORef = ioRefProofStatus 
    879                                          , gi_LIB_NAME = ln }) 
     919showReferencedLibrary descr gInfo 
    880920                      convGraph showLib = do 
    881   le <- readIORef ioRefProofStatus 
    882   let refNode =  labDG (lookupDGraph ln le) descr 
    883       refLibname = if isDGRef refNode then dgn_libname refNode 
    884                    else error "showReferencedLibrary" 
    885   case Map.lookup refLibname le of 
     921 ost <- readIORef $ intState gInfo 
     922 case i_state ost of  
     923  Nothing -> return () 
     924  Just ist -> do 
     925   let ln = i_ln ist 
     926       le = i_libEnv ist 
     927       refNode =  labDG (lookupDGraph ln le) descr 
     928       refLibname = if isDGRef refNode then dgn_libname refNode 
     929                    else error "showReferencedLibrary" 
     930   case Map.lookup refLibname le of 
    886931    Just _ -> do 
    887932      gInfo' <- copyGInfo gInfo refLibname 
     
    946991                   showDiagMess opts $ diagsSl ++ diagsTrans 
    947992                   dg_showGraphAux 
    948                                    (\gI@(GInfo{libEnvIORef = iorLE}) -> do 
    949                                      writeIORef iorLE newLibEnv 
    950                                      convGraph (gI{ gi_LIB_NAME = ln 
    951                                                   , gi_hetcatsOpts = opts}) 
     993                                   (\gI -> do 
     994                                     ost <- readIORef $ intState gI 
     995                                     let nwst = case i_state ost of 
     996                                                 Nothing -> ost 
     997                                                 Just ist ->  
     998                                                  ost{i_state = Just ist{ 
     999                                                       i_libEnv = newLibEnv, 
     1000                                                       i_ln = ln }} 
     1001                                     writeIORef (intState gI) nwst 
     1002                                     convGraph (gI{ gi_hetcatsOpts = opts}) 
    9521003                                               "translation Graph" showLib) 
    9531004                 Nothing -> myErrMess $ diagsSl ++ diagsTrans 
     
    9721023            -> Map.Map DGEdgeType (EdgePattern GA.EdgeValue, String) -> IO () 
    9731024saveUDGraph gInfo@(GInfo { gi_GraphInfo = graphInfo 
    974                          , gi_LIB_NAME = ln 
    9751025                         , gi_hetcatsOpts = opts 
    9761026                         }) nodemap linkmap = do 
    977   maybeFilePath <- fileSaveDialog ((rmSuffix $ libNameToFile opts ln) ++ ".udg") 
     1027  ost <- readIORef $ intState gInfo 
     1028  case i_state ost of  
     1029   Nothing -> return () 
     1030   Just ist -> do 
     1031    let ln = i_ln ist 
     1032    maybeFilePath <- fileSaveDialog ((rmSuffix $ libNameToFile opts ln) ++ ".udg") 
    9781033                                  [ ("uDrawGraph",["*.udg"]) 
    9791034                                  , ("All Files", ["*"])] Nothing 
    980   case maybeFilePath of 
    981     Just filepath -> do 
     1035    case maybeFilePath of 
     1036     Just filepath -> do 
    9821037      GA.showTemporaryMessage graphInfo "Converting graph..." 
    9831038      nstring <- nodes2String gInfo nodemap linkmap 
    9841039      writeFile filepath nstring 
    9851040      GA.showTemporaryMessage graphInfo $ "Graph stored to " ++ filepath ++ "!" 
    986     Nothing -> GA.showTemporaryMessage graphInfo $ "Aborted!" 
     1041     Nothing -> GA.showTemporaryMessage graphInfo $ "Aborted!" 
    9871042 
    9881043-- | Converts the nodes of the graph to String representation 
     
    9901045             -> Map.Map DGEdgeType (EdgePattern GA.EdgeValue, String) 
    9911046             -> IO String 
    992 nodes2String gInfo@(GInfo { gi_GraphInfo = graphInfo 
    993                           , gi_LIB_NAME = ln 
    994                           , libEnvIORef = ioRefProofStatus 
    995                           }) nodemap linkmap = do 
    996   le <- readIORef ioRefProofStatus 
    997   nodes <- filterM (\(n,_) -> do b <- GA.isHiddenNode graphInfo n 
    998                                  return $ not b) 
     1047nodes2String gInfo@(GInfo { gi_GraphInfo = graphInfo }) nodemap linkmap = do 
     1048 ost <- readIORef $ intState gInfo 
     1049 case i_state ost of  
     1050  Nothing -> return [] 
     1051  Just ist -> do 
     1052   let le = i_libEnv ist 
     1053       ln = i_ln ist 
     1054   nodes <- filterM (\(n,_) -> do b <- GA.isHiddenNode graphInfo n 
     1055                                  return $ not b) 
    9991056                    $ labNodesDG $ lookupDGraph ln le 
    1000   nstring <- foldM (\s node -> do 
     1057   nstring <- foldM (\s node -> do 
    10011058                     s' <- (node2String gInfo nodemap linkmap node) 
    10021059                     return $ s ++ (if s /= "" then ",\n " else "") ++ s') 
    10031060                   "" nodes 
    1004   return $ "[" ++ nstring ++ "]" 
     1061   return $ "[" ++ nstring ++ "]" 
    10051062 
    10061063-- | Converts a node to String representation 
     
    10261083links2String :: GInfo -> Map.Map DGEdgeType (EdgePattern GA.EdgeValue, String) 
    10271084             -> Int -> IO String 
    1028 links2String (GInfo { gi_GraphInfo = graphInfo 
    1029                     , gi_LIB_NAME = ln 
    1030                     , libEnvIORef = ioRefProofStatus 
     1085links2String gInfo@(GInfo { gi_GraphInfo = graphInfo 
    10311086                    })  linkmap nodeid = do 
    1032   le <- readIORef ioRefProofStatus 
    1033   edges <- filterM (\(src,_,edge) -> do 
     1087 ost <- readIORef $ intState gInfo 
     1088 case i_state ost of  
     1089  Nothing -> return [] 
     1090  Just ist -> do  
     1091   let ln = i_ln ist 
     1092       le = i_libEnv ist 
     1093   edges <- filterM (\(src,_,edge) -> do 
    10341094                      let eid = dgl_id edge 
    10351095                      b <- GA.isHiddenEdge graphInfo eid 
    10361096                      return $ (not b) && src == nodeid) 
    10371097                     $ labEdgesDG $ lookupDGraph ln le 
    1038   foldM (\s edge -> do 
     1098   foldM (\s edge -> do 
    10391099          s' <- link2String linkmap edge 
    10401100          return $ s ++ (if s /= "" then ",\n   " else "") ++ s') "" edges