A composition table is used when abstracting the graph and composing
multiple edges. It looks like this
'[("normal","normal","normal"),
("normal","inclusion","normal"),
("inclusion","normal","normal"),
("inclusion","inclusion","inclusion")]'
A ginfo can be created with initgraphs. The graph is then created with
(convertGraph,GraphMem,ConversionMaps,initializeConverter)
displayTheoryWithWarning,
createInfoDisplayWithTwoButtons,
import
GUI.Taxonomy (displayConceptGraph,displaySubsortGraph)
import Broadcaster(newSimpleBroadcaster,applySimpleUpdate)
import Sources(toSimpleSource)
import DialogWin (useHTk)
{- Maps used to track which node resp edge of the abstract graph
correspondes with which of the development graph and vice versa and
one Map to store which libname belongs to which development graph-}
data ConversionMaps = ConversionMaps {
dgAndabstrNode :: DGraphAndAGraphNode,
dgAndabstrEdge :: DGraphAndAGraphEdge,
libname2dg :: LibEnv} deriving Show
instance Pretty ConversionMaps where
data GraphMem = GraphMem {
-- | types of the Maps above
type DGraphAndAGraphEdge =
InjMap.InjMap (LIB_NAME, (Descr, Descr, String)) Descr
InternalNames { showNames :: Bool,
updater :: [(String,(String -> String) -> IO ())] }
{ libEnvIORef :: IORef LibEnv
, descrIORef :: IORef Descr
, conversionMapsIORef :: IORef ConversionMaps
, gi_LIB_NAME :: LIB_NAME
, gi_GraphInfo :: GraphInfo
, internalNamesIORef :: IORef InternalNames -- show internal names?
, gi_hetcatsOpts :: HetcatsOpts
, visibleNodesIORef :: IORef [[Node]]
, proofGUIMVar :: GUIMVar
initializeConverter :: IO (IORef GraphMem,
HTk.HTk)
initGraphInfo <- initgraphs
graphMem <- (newIORef GraphMem{nextGraphId = 0,
graphInfo = initGraphInfo})
return (graphMem,wishInst)
-- | converts the development graph given by its libname into an abstract
-- graph and returns the descriptor of the latter, the graphInfo it is
-- contained in and the conversion maps (see above)
convertGraph :: IORef GraphMem -> LIB_NAME -> LibEnv -> HetcatsOpts
-> String -- ^ title of graph
-> IO (Descr, GraphInfo, ConversionMaps)
convertGraph graphMem libname libEnv opts title =
do let convMaps = ConversionMaps
{{-dg2abstrNode =
Map.empty::DGraphToAGraphNode,
abstr2dgNode =
Map.empty::AGraphToDGraphNode,
dg2abstrEdge =
Map.empty::DGraphToAGraphEdge,
abstr2dgEdge =
Map.empty::AGraphToDGraphEdge,-}
do let dgraph = devGraph gctx
(abstractGraph,grInfo,convRef) <-
initializeGraph graphMem libname dgraph convMaps
return (abstractGraph, grInfo,convMaps)
do newConvMaps <- convertNodes convMaps abstractGraph
finalConvMaps <- convertEdges newConvMaps abstractGraph
writeIORef convRef finalConvMaps
return (abstractGraph, grInfo, finalConvMaps)
Nothing -> error ("development graph with libname "
-- | initializes an empty abstract graph with the needed node and edge types,
-- return type equals the one of convertGraph
initializeGraph :: IORef GraphMem -> LIB_NAME -> DGraph -> ConversionMaps
-> GlobalContext -> HetcatsOpts
-> String -- ^ title of graph
-> IO (Descr,GraphInfo,IORef ConversionMaps)
initializeGraph ioRefGraphMem ln dGraph convMaps _ opts title = do
graphMem <- readIORef ioRefGraphMem
convRef <- newIORef convMaps
showInternalNames <- newIORef (InternalNames False [])
initEnv = libname2dg convMaps
ioRefProofStatus <- newIORef initEnv
let gid = nextGraphId graphMem
actGraphInfo = graphInfo graphMem
gInfo = GInfo {libEnvIORef = ioRefProofStatus,
conversionMapsIORef = convRef,
gi_GraphInfo = actGraphInfo,
internalNamesIORef = showInternalNames,
visibleNodesIORef = ioRefVisibleNodes,
file = rmSuffix (libNameToFile opts ln) ++ prfSuffix
coral = getColor opts "Coral"
green = getColor opts "Green"
steelblue = getColor opts "Steelblue"
lightblue = getColor opts "Lightblue"
yellow = getColor opts "Yellow"
lightgreen = getColor opts "Lightgreen"
grey = getColor opts "Grey"
makegraph (title ++ " for " ++ show ln)
evnt <- fileDialogStr "Open..." file
openProofStatus ln filePath ioRefProofStatus convRef opts
Nothing -> fail "Could not open file."
(Just (saveProofStatus ln file ioRefProofStatus opts))
-- action on "save as...:"
evnt <- newFileDialogStr "Save as..." file
saveProofStatus ln filePath ioRefProofStatus opts
Nothing -> fail "Could not save file."
[GlobalMenu (Menu Nothing
Menu (Just "Unnamed nodes")
(do (intrn::InternalNames) <- readIORef showInternalNames
let showThem = not $ showNames intrn
showItrn s = if showThem then s else ""
mapM_ (\(s,upd) -> upd (\_ -> showItrn s))
writeIORef showInternalNames
$ intrn {showNames = showThem}
redisplay gid actGraphInfo
<- hideSetOfNodeTypes gid
"locallyEmpty__open_cons__internal",
"locallyEmpty__proven_cons__internal"]
Nothing -> do redisplay gid actGraphInfo
(do descr <- readIORef event
showIt gid descr actGraphInfo
redisplay gid actGraphInfo
(return . return . automatic ln))
Button "Global Subsumption"
(return . return . globSubsume ln))
Button "Global Decomposition"
(return . return . globDecomp ln))
(return . return . localInference ln))
Button "Local Decomposition (merge of rules)"
(return . return . locDecomp ln))
Button "Composition (merge of rules)"
(return . return . composition ln))
Button "Composition - creating new links"
compositionCreatingEdges ln))
Button "Hide Theorem Shift"
interactiveHideTheoremShift ln))
Button "Theorem Hide Shift"
(return . return . theoremHideShift ln))
(openTranslateGraph (libname2dg convMaps) ln opts
$ (getDGLogic (libname2dg convMaps)))
Button "Show Logic Graph"
(showLogicGraph daVinciSort)
Button "Show Library Graph"
le <- readIORef (libEnvIORef gInfo)
showLibGraph opts ln le $
(gid2, gv, _) <- convertGraph ioRefGraphMem
createLocalMenuNodeTypeSpec coral ioRefSubtreeEvents
actGraphInfo ioRefGraphMem gInfo
createLocalMenuNodeTypeSpec coral ioRefSubtreeEvents
actGraphInfo ioRefGraphMem gInfo
("locallyEmpty__open_cons__spec",
createLocalMenuNodeTypeSpec coral ioRefSubtreeEvents
actGraphInfo ioRefGraphMem gInfo
("locallyEmpty__proven_cons__spec",
createLocalMenuNodeTypeSpec green ioRefSubtreeEvents
actGraphInfo ioRefGraphMem gInfo
createLocalMenuNodeTypeInternal coral gInfo
("proven_cons__internal",
createLocalMenuNodeTypeInternal coral gInfo
("locallyEmpty__open_cons__internal",
createLocalMenuNodeTypeInternal coral gInfo
("locallyEmpty__proven_cons__internal",
createLocalMenuNodeTypeInternal green gInfo
createLocalMenuNodeTypeDgRef coral actGraphInfo
ioRefGraphMem graphMem gInfo
createLocalMenuNodeTypeDgRef green
actGraphInfo ioRefGraphMem graphMem gInfo
-- the link types (share strings to avoid typos)
$$$ createLocalEdgeMenu gInfo
$$$ emptyArcTypeParms :: DaVinciArcTypeParms EdgeValue),
Solid $$$ Color steelblue
$$$ createLocalEdgeMenu gInfo
$$$ emptyArcTypeParms :: DaVinciArcTypeParms EdgeValue),
Solid $$$ Color lightblue
$$$ createLocalEdgeMenu gInfo
$$$ emptyArcTypeParms :: DaVinciArcTypeParms EdgeValue),
$$$ createLocalEdgeMenu gInfo
$$$ emptyArcTypeParms :: DaVinciArcTypeParms EdgeValue),
$$$ createLocalEdgeMenuThmEdge gInfo
$$$ createLocalMenuValueTitleShowConservativity
$$$ emptyArcTypeParms :: DaVinciArcTypeParms EdgeValue),
$$$ createLocalEdgeMenuThmEdge gInfo
$$$ createLocalMenuValueTitleShowConservativity
$$$ emptyArcTypeParms :: DaVinciArcTypeParms EdgeValue),
$$$ createLocalEdgeMenuThmEdge gInfo
$$$ createLocalMenuValueTitleShowConservativity
$$$ emptyArcTypeParms :: DaVinciArcTypeParms EdgeValue),
$$$ createLocalEdgeMenuThmEdge gInfo
$$$ createLocalMenuValueTitleShowConservativity
$$$ emptyArcTypeParms :: DaVinciArcTypeParms EdgeValue),
$$$ createLocalEdgeMenuThmEdge gInfo
$$$ createLocalMenuValueTitleShowConservativity
$$$ emptyArcTypeParms :: DaVinciArcTypeParms EdgeValue),
$$$ createLocalEdgeMenuThmEdge gInfo
$$$ createLocalMenuValueTitleShowConservativity
$$$ emptyArcTypeParms :: DaVinciArcTypeParms EdgeValue),
$$$ createLocalEdgeMenuThmEdge gInfo
$$$ createLocalMenuValueTitleShowConservativity
$$$ emptyArcTypeParms :: DaVinciArcTypeParms EdgeValue),
$$$ createLocalEdgeMenuThmEdge gInfo
$$$ createLocalMenuValueTitleShowConservativity
$$$ emptyArcTypeParms :: DaVinciArcTypeParms EdgeValue),
$$$ createLocalEdgeMenuThmEdge gInfo
$$$ emptyArcTypeParms :: DaVinciArcTypeParms EdgeValue),
Solid $$$ Color lightgreen
$$$ createLocalEdgeMenuThmEdge gInfo
$$$ emptyArcTypeParms :: DaVinciArcTypeParms EdgeValue),
-- > ######### welche Farbe fuer reference ##########
$$$ createLocalEdgeMenu gInfo
$$$ emptyArcTypeParms :: DaVinciArcTypeParms EdgeValue)]
writeIORef ioRefGraphMem graphMem{nextGraphId = gid+1}
graphMem'<- readIORef ioRefGraphMem
return (descr,graphInfo graphMem',convRef)
-- | Generates the CompTable
makeCompTable :: [String] -> CompTable
concat $ map (\ x -> makeComp x ls False ) ls
makeComp :: String -> [String] -> Bool -> CompTable
makeComp s (xs:r) b = case b of
True -> (s, xs, xs) : makeComp s r b
False -> (s, xs, s) : makeComp s r (s == xs)
-- | Converts colors to grey
getColor :: HetcatsOpts -> String -> String
| not $ uncolored opts = color
| color == "Coral" = "darkgrey"
| color == "Green" = "lightgrey"
| color == "Steelblue" = "steelgrey"
| color == "Lightblue" = "lightsteelgrey"
| color == "Yellow" = "darksteelgrey"
| color == "Lightgreen" = "grey"
-- | Undo one step of the History
undo :: GInfo -> LibEnv -> IO ()
undo (GInfo {libEnvIORef = ioRefProofStatus,
conversionMapsIORef = convRef,
gi_GraphInfo = actGraphInfo
oldEnv <- readIORef ioRefProofStatus
gctx = lookupGlobalContext ln oldEnv
initgctx = lookupGlobalContext ln initEnv
phist = proofHistory gctx
if phist == [emptyHistory] then return ()
rhist' = lastchange:rhist
gctx' = (applyProofHistory phist' initgctx ) {redoHistory = rhist'}
writeIORef ioRefProofStatus newEnv
remakeGraph convRef gid actGraphInfo dgraph ln
-- | redo one step of the redoHistory
redo :: GInfo -> LibEnv -> IO ()
redo (GInfo {libEnvIORef = ioRefProofStatus,
conversionMapsIORef = convRef,
gi_GraphInfo = actGraphInfo
oldEnv <- readIORef ioRefProofStatus
gctx = lookupGlobalContext ln oldEnv
initgctx = lookupGlobalContext ln initEnv
phist = proofHistory gctx
if rhist == [emptyHistory] then return ()
phist' = nextchange:phist
gctx' = (applyProofHistory phist' initgctx) {redoHistory = rhist'}
writeIORef ioRefProofStatus newEnv
remakeGraph convRef gid actGraphInfo dgraph ln
type ModTimeMap =
Map.Map LIB_NAME ClockTime
-- | reloads the Library of the DevGraph
reload (GInfo {libEnvIORef = ioRefProofStatus,
conversionMapsIORef = convRef,
gi_GraphInfo = actGraphInfo,
oldle <- readIORef ioRefProofStatus
mtm = foldl (\ m ln' ->
Map.insert ln' (getModTime $ getLIB_ID ln') m)
reloadLib ioRefProofStatus opts mtm ln
le <- readIORef ioRefProofStatus
dgraph = devGraph $ lookupGlobalContext ln le
writeIORef ioRefProofStatus le
remakeGraph convRef gid actGraphInfo dgraph ln
-- | Reloads a Libfile if nessesary
reloadLib :: IORef LibEnv -> HetcatsOpts -> ModTimeMap -> LIB_NAME
reloadLib iorle opts mtm ln = do
-- libdeps = map (snd) $ getDep ln oldle
libdeps = map (snd) $ filter (\(ln',_) -> ln' == ln) $
Rel.toList $
Just fn <- existsAnSource opts $ rmSuffix $ libNameToFile opts ln
res <- mapM (reloadLib iorle opts mtm) libdeps
newmt <- getModificationTime fn
libupdate = foldl (\ u r -> if r then True else u) False res
oldmt = getModTime $ getLIB_ID ln
putIfVerbose opts 1 $ "Info ModTime: " ++ show newmt ++ " " ++ show oldmt
case libupdate || oldmt < newmt of -- || oldmt /= oldmt' of
mres <- anaLibExt opts fn le'
fail $ "Could not read original development graph from '"
-- | Deletes the old edges and nodes of the Graph and makes new ones
remakeGraph :: IORef ConversionMaps -> Descr -> GraphInfo -> DGraph -> LIB_NAME
remakeGraph convRef gid actginfo dgraph ln = do
(gs,ev_cnt) <- readIORef actginfo
Just (_, g) = find (\ (gid', _) -> gid' == gid) gs
gs' = deleteBy (\ (gid1,_) (gid2,_) -> gid1 == gid2) (gid,g) gs
-- reads and delets the old nodes and edges
mapM_ (deleteArc og) $ map (\ (_,_,_,x) -> x) $ map snd $
AGV.edges g
mapM_ (deleteNode og) $ map snd $ map snd $
AGV.nodes g
-- stores the graph without nodes and edges in the GraphInfo
writeIORef actginfo ((gid,g'):gs',ev_cnt)
-- creates new nodes and edges
convMaps <- readIORef convRef
newConvMaps <- convertNodes convMaps gid actginfo dgraph ln
finalConvMaps <- convertEdges newConvMaps gid actginfo dgraph ln
-- writes the ConversionMap and redisplays the graph
writeIORef convRef finalConvMaps
performProofAction :: IORef Descr -> Descr -> GraphInfo -> IO () -> IO ()
performProofAction event gid actGraphInfo proofAction =
do descr <- readIORef event
(
AGV.Result _ errorMsg) <- checkHasHiddenNodes gid
("Proof calculus deactivated!\n"
++"Please show the whole graph before "
++"performing further proof actions")
saveProofStatus :: LIB_NAME -> FilePath -> IORef LibEnv -> HetcatsOpts -> IO ()
saveProofStatus ln file ioRefProofStatus opts = encapsulateWaitTermAct $ do
proofStatus <- readIORef ioRefProofStatus
writeShATermFile file (ln, lookupHistory ln proofStatus)
putIfVerbose opts 2 $ "Wrote " ++ file
-- | implementation of open menu, read in a proof status
openProofStatus :: LIB_NAME -> FilePath -> IORef LibEnv
-> HetcatsOpts -> IO (Descr, GraphInfo, ConversionMaps)
openProofStatus ln file ioRefProofStatus convRef opts = do
mh <- readVerbose opts ln file
$ "Could not read proof status from file '"
let libfile = libNameToFile opts ln
m <- anaLib opts { outtypes = [] } libfile
$ "Could not read original development graph from '"
$ "Could not get original development graph for '"
oldEnv <- readIORef ioRefProofStatus
(applyProofHistory h gctx) oldEnv
writeIORef ioRefProofStatus proofStatus
initGraphInfo <- initgraphs
graphMem' <- (newIORef GraphMem{nextGraphId = 0,
graphInfo = initGraphInfo})
(gid, actGraphInfo, convMaps)
<- convertGraph graphMem' ln proofStatus opts
writeIORef convRef convMaps
redisplay gid actGraphInfo
return (gid, actGraphInfo, convMaps)
-- | apply a rule of the development graph calculus
proofMenu (GInfo {libEnvIORef = ioRefProofStatus,
conversionMapsIORef = convRef,
gi_GraphInfo = actGraphInfo,
visibleNodesIORef = ioRefVisibleNodes}) proofFun = do
filled <- tryPutMVar guiMVar Nothing
then readMVar guiMVar >>=
(maybe (putIfVerbose hOpts 4 "proofMenu: ignored Nothing")
"proofMenu: Ignored Proof command; "++
"maybe a proof window is still open?"
proofStatus <- readIORef ioRefProofStatus
putIfVerbose hOpts 4 "Proof started via \"Proofs\" menu"
putIfVerbose hOpts 4 "Analyzing result of proof"
Nothing -> mapM_ (putStrLn . show) ds
Just newProofStatus -> do
let newGlobContext = lookupGlobalContext ln newProofStatus
history = proofHistory newGlobContext
writeIORef ioRefProofStatus newProofStatus
convMaps <- readIORef convRef
<- applyChanges gid ln actGraphInfo descr ioRefVisibleNodes
convMapsAux {libname2dg =
Map.insert ln newGlobContext (libname2dg convMapsAux)}
writeIORef event newDescr
writeIORef convRef newConvMaps
redisplay gid actGraphInfo
mGUIMVar <- tryTakeMVar guiMVar
maybe (fail $ "should be filled with Nothing after "++
proofMenuSef :: GInfo -> (LibEnv -> LibEnv) -> IO ()
proofMenuSef gInfo proofFun = proofMenu gInfo (return . return . proofFun)
-- -------------------------------------------------------------
-- methods to create the local menus of the different nodetypes
-- -------------------------------------------------------------
type NodeDescr = (String, Descr, Descr)
-- | local menu for the nodetypes spec and locallyEmpty_spec
createLocalMenuNodeTypeSpec :: String -> IORef (
Map.Map Descr Descr)
-> GraphInfo -> IORef GraphMem -> GInfo
-> DaVinciNodeTypeParms NodeDescr
createLocalMenuNodeTypeSpec color ioRefSubtreeEvents actGraphInfo
gInfo@(GInfo {conversionMapsIORef = convRef,
visibleNodesIORef = ioRefVisibleNodes}) =
$$$ ValueTitle (\ (s,_,_) -> return s)
$$$ LocalMenu (Menu (Just "node menu")
[createLocalMenuButtonShowSignature gInfo,
createLocalMenuButtonShowLocalAx gInfo,
createLocalMenuButtonShowTheory gInfo,
createLocalMenuButtonTranslateTheory gInfo,
createLocalMenuTaxonomy gInfo,
createLocalMenuButtonShowSublogic gInfo,
createLocalMenuButtonShowNodeOrigin gInfo,
createLocalMenuButtonShowProofStatusOfNode gInfo,
createLocalMenuButtonProveAtNode gInfo,
createLocalMenuButtonCCCAtNode gInfo,
createLocalMenuButtonShowJustSubtree ioRefSubtreeEvents
convRef ioRefVisibleNodes ioRefGraphMem
createLocalMenuButtonUndoShowJustSubtree ioRefVisibleNodes
ioRefSubtreeEvents actGraphInfo,
-- createLocalMenuButtonShowSpec gInfo, -- not fully implemented yet!
createLocalMenuButtonShowNumberOfNode
]) -- ??? Should be globalized somehow
-- | local menu for the nodetypes internal and locallyEmpty_internal
createLocalMenuNodeTypeInternal :: String -> GInfo
-> DaVinciNodeTypeParms NodeDescr
createLocalMenuNodeTypeInternal color
gInfo@(GInfo {internalNamesIORef = showInternalNames}) =
$$$ ValueTitleSource (\ (s,_,_) -> do
b <- newSimpleBroadcaster ""
intrn <- readIORef showInternalNames
let upd = (s,applySimpleUpdate b)
writeIORef showInternalNames
$ intrn {updater = upd:updater intrn}
return $ toSimpleSource b)
$$$ LocalMenu (Menu (Just "node menu")
[createLocalMenuButtonShowSpec gInfo,
createLocalMenuButtonShowNumberOfNode,
createLocalMenuButtonShowSignature gInfo,
createLocalMenuButtonShowLocalAx gInfo,
createLocalMenuButtonShowTheory gInfo,
createLocalMenuButtonTranslateTheory gInfo,
createLocalMenuTaxonomy gInfo,
createLocalMenuButtonShowSublogic gInfo,
createLocalMenuButtonShowProofStatusOfNode gInfo,
createLocalMenuButtonProveAtNode gInfo,
createLocalMenuButtonCCCAtNode gInfo,
createLocalMenuButtonShowNodeOrigin gInfo])
-- | local menu for the nodetypes dg_ref and locallyEmpty_dg_ref
createLocalMenuNodeTypeDgRef :: String -> GraphInfo -> IORef GraphMem
-> DaVinciNodeTypeParms NodeDescr
createLocalMenuNodeTypeDgRef color actGraphInfo
$$$ ValueTitle (\ (s,_,_) -> return s)
$$$ LocalMenu (Menu (Just "node menu")
[createLocalMenuButtonShowSignature gInfo,
createLocalMenuButtonShowTheory gInfo,
createLocalMenuButtonProveAtNode gInfo,
createLocalMenuButtonShowProofStatusOfNode gInfo,
createLocalMenuButtonShowNumberOfNode,
createLocalMenuButtonShowNumberOfRefNode gInfo,
Button "Show referenced library"
do convMaps <- readIORef $ conversionMapsIORef gInfo
(refDescr, newGraphInfo, _) <-
showReferencedLibrary ioRefGraphMem descr
--writeIORef convRef newConvMaps
graphMem{graphInfo = newGraphInfo,
nextGraphId = refDescr +1}
redisplay refDescr newGraphInfo
type ButtonMenu a = MenuPrim (Maybe String) (a -> IO ())
-- | menu button for local menus
createMenuButton :: String -> (Descr -> DGraphAndAGraphNode -> DGraph -> IO ())
-> GInfo -> ButtonMenu NodeDescr
createMenuButton title menuFun gInfo =
do convMaps <- readIORef $ conversionMapsIORef gInfo
ps <- readIORef $ libEnvIORef gInfo
let dGraph = lookupDGraph (gi_LIB_NAME gInfo) ps
(dgAndabstrNode convMaps)
createLocalMenuButtonShowSpec :: GInfo -> ButtonMenu NodeDescr
createLocalMenuButtonShowSpec = createMenuButton "Show spec" showSpec
createLocalMenuButtonShowSignature :: GInfo -> ButtonMenu NodeDescr
createLocalMenuButtonShowSignature =
createMenuButton "Show signature" getSignatureOfNode
createLocalMenuButtonShowTheory :: GInfo -> ButtonMenu NodeDescr
createLocalMenuButtonShowTheory gInfo =
createMenuButton "Show theory" (getTheoryOfNode gInfo) gInfo
createLocalMenuButtonShowLocalAx :: GInfo -> ButtonMenu NodeDescr
createLocalMenuButtonShowLocalAx gInfo =
createMenuButton "Show local axioms" (getLocalAxOfNode gInfo) gInfo
createLocalMenuButtonTranslateTheory :: GInfo -> ButtonMenu NodeDescr
createLocalMenuButtonTranslateTheory gInfo =
createMenuButton "Translate theory" (translateTheoryOfNode gInfo) gInfo
create a sub Menu for taxonomy visualisation
createLocalMenuTaxonomy :: GInfo -> ButtonMenu NodeDescr
createLocalMenuTaxonomy ginfo =
(Menu (Just "Taxonomy graphs")
[createMenuButton "Subsort graph"
(passTh displaySubsortGraph) ginfo,
createMenuButton "Concept graph"
(passTh displayConceptGraph) ginfo])
where passTh displayFun descr ab2dgNode dgraph =
do r <- lookupTheoryOfNode (libEnvIORef ginfo)
displayFun (showDoc n "") gth
showDiags defaultHetcatsOpts ds
createLocalMenuButtonShowSublogic :: GInfo -> ButtonMenu NodeDescr
createLocalMenuButtonShowSublogic gInfo =
createMenuButton "Show sublogic"
(getSublogicOfNode $ libEnvIORef gInfo) gInfo
createLocalMenuButtonShowNodeOrigin :: GInfo -> ButtonMenu NodeDescr
createLocalMenuButtonShowNodeOrigin =
createMenuButton "Show origin" showOriginOfNode
createLocalMenuButtonShowProofStatusOfNode :: GInfo -> ButtonMenu NodeDescr
createLocalMenuButtonShowProofStatusOfNode gInfo =
createMenuButton "Show proof status" (showProofStatusOfNode gInfo) gInfo
createLocalMenuButtonProveAtNode :: GInfo -> ButtonMenu NodeDescr
createLocalMenuButtonProveAtNode gInfo =
createMenuButton "Prove" (proveAtNode False gInfo) gInfo
createLocalMenuButtonCCCAtNode :: GInfo -> ButtonMenu NodeDescr
createLocalMenuButtonCCCAtNode gInfo =
createMenuButton "Check consistency" (proveAtNode True gInfo) gInfo
createLocalMenuButtonShowJustSubtree :: IORef (
Map.Map Descr Descr)
-> IORef ConversionMaps -> IORef [[Node]] -> IORef GraphMem -> GraphInfo
createLocalMenuButtonShowJustSubtree ioRefSubtreeEvents convRef
ioRefVisibleNodes ioRefGraphMem actGraphInfo =
(Button "Show just subtree"
do subtreeEvents <- readIORef ioRefSubtreeEvents
"it is already just the subtree of node "
do convMaps <- readIORef convRef
visibleNodes <- readIORef ioRefVisibleNodes
(eventDescr,newVisibleNodes,errorMsg) <-
showJustSubtree ioRefGraphMem
descr gid convMaps visibleNodes
Nothing -> do let newSubtreeEvents =
writeIORef ioRefSubtreeEvents
writeIORef ioRefVisibleNodes
redisplay gid actGraphInfo
Just stext -> putStrLn stext
createLocalMenuButtonUndoShowJustSubtree :: IORef [[Node]]
-> IORef (
Map.Map Descr Descr) -> GraphInfo -> ButtonMenu NodeDescr
createLocalMenuButtonUndoShowJustSubtree ioRefVisibleNodes
ioRefSubtreeEvents actGraphInfo =
(Button "Undo show just subtree"
do visibleNodes <- readIORef ioRefVisibleNodes
case (tail visibleNodes) of
"Complete graph is already shown"
newVisibleNodes@(_ : _) ->
do subtreeEvents <- readIORef ioRefSubtreeEvents
do showIt gid hide_event actGraphInfo
writeIORef ioRefSubtreeEvents
writeIORef ioRefVisibleNodes
redisplay gid actGraphInfo
Nothing -> do putStrLn "undo not possible"
createLocalMenuButtonShowIDOfEdge :: GInfo -> ButtonMenu EdgeValue
createLocalMenuButtonShowIDOfEdge _ =
(Button "Show ID of this edge"
(\ (_,descr,maybeLEdge) ->
do showIDOfEdge descr maybeLEdge
createLocalMenuButtonShowNumberOfNode :: ButtonMenu NodeDescr
createLocalMenuButtonShowNumberOfNode =
(Button "Show number of node"
createLocalMenuButtonShowNumberOfRefNode :: GInfo -> ButtonMenu NodeDescr
createLocalMenuButtonShowNumberOfRefNode =
createMenuButton "Show number of referenced node" getNumberOfRefNode
getNumberOfRefNode :: Descr -> DGraphAndAGraphNode -> DGraph -> IO()
getNumberOfRefNode descr dgAndabstrNodeMap dgraph =
let dgnode = lab' (context dgraph node)
in createTextDisplay title (show (dgn_node dgnode)) [
HTk.size(10,10)]
Nothing -> error ("node with descriptor "
++ " has no corresponding node in the development graph")
-- -------------------------------------------------------------
-- methods to create the local menus for the edges
-- -------------------------------------------------------------
createLocalEdgeMenu :: GInfo -> LocalMenu EdgeValue
createLocalEdgeMenu gInfo =
LocalMenu (Menu (Just "edge menu")
[createLocalMenuButtonShowMorphismOfEdge gInfo,
createLocalMenuButtonShowOriginOfEdge gInfo,
createLocalMenuButtonCheckconservativityOfEdge gInfo,
createLocalMenuButtonShowIDOfEdge gInfo]
createLocalEdgeMenuThmEdge :: GInfo -> LocalMenu EdgeValue
createLocalEdgeMenuThmEdge gInfo =
LocalMenu (Menu (Just "thm egde menu")
[ createLocalMenuButtonShowMorphismOfEdge gInfo,
createLocalMenuButtonShowOriginOfEdge gInfo,
createLocalMenuButtonShowProofStatusOfThm gInfo,
createLocalMenuButtonCheckconservativityOfEdge gInfo,
createLocalMenuButtonShowIDOfEdge gInfo]
createLocalMenuButtonShowMorphismOfEdge :: GInfo -> ButtonMenu EdgeValue
createLocalMenuButtonShowMorphismOfEdge _ =
(\ (_,descr,maybeLEdge) ->
do showMorphismOfEdge descr maybeLEdge
createLocalMenuButtonShowOriginOfEdge :: GInfo -> ButtonMenu EdgeValue
createLocalMenuButtonShowOriginOfEdge _ =
(\ (_,descr,maybeLEdge) ->
do showOriginOfEdge descr maybeLEdge
createLocalMenuButtonCheckconservativityOfEdge :: GInfo -> ButtonMenu EdgeValue
createLocalMenuButtonCheckconservativityOfEdge gInfo =
(Button "Check conservativity (preliminary)"
(\ (_, descr, maybeLEdge) ->
do checkconservativityOfEdge descr gInfo maybeLEdge
createLocalMenuButtonShowProofStatusOfThm :: GInfo -> ButtonMenu EdgeValue
createLocalMenuButtonShowProofStatusOfThm _ =
(Button "Show proof status"
(\ (_,descr,maybeLEdge) ->
do showProofStatusOfThm descr maybeLEdge
createLocalMenuValueTitleShowConservativity :: ValueTitle EdgeValue
createLocalMenuValueTitleShowConservativity =
GlobalThm _ c status -> return (showCons c status)
LocalThm _ c status -> return (showCons c status)
showCons :: Conservativity -> ThmLinkStatus -> String
(_,LeftOpen) -> (show c) ++ "?"
-- ------------------------------
-- end of local menu definitions
-- ------------------------------
showSpec :: Descr -> DGraphAndAGraphNode -> DGraph -> IO ()
showSpec descr dgAndabstrNodeMap dgraph =
let sp = dgToSpec dgraph node
Res.Result ds Nothing -> show $ vcat $ map pretty ds
{- | auxiliary method for debugging. shows the number of the given node
in the abstraction graph -}
getNumberOfNode :: Descr -> IO()
let title = "Number of node"
-- make the node number consistent
in createTextDisplay title (showDoc (descr-1) "") [
HTk.size(10,10)]
{- | outputs the signature of a node in a window;
used by the node menu defined in initializeGraph -}
-- lllllllllllllllllllllllllllllll
getSignatureOfNode :: Descr -> DGraphAndAGraphNode -> DGraph -> IO()
getSignatureOfNode descr dgAndabstrNodeMap dgraph =
let dgnode = lab' (context dgraph node)
title = "Signature of "++showName (dgn_name dgnode)
in createTextDisplay title (showDoc (dgn_sign dgnode) "")
Nothing -> error ("node with descriptor "
++ " has no corresponding node in the development graph")
fetches the theory from a node inside the IO Monad
(added by KL based on code in getTheoryOfNode) -}
lookupTheoryOfNode :: IORef LibEnv -> Descr -> DGraphAndAGraphNode ->
lookupTheoryOfNode proofStatusRef descr dgAndabstrNodeMap _ = do
libEnv <- readIORef proofStatusRef
maybeToResult nullRange ("Node "++show descr++" not found")
gth <- computeTheory libEnv ln node
{- | outputs the local axioms of a node in a window;
used by the node menu defined in initializeGraph-}
getLocalAxOfNode :: GInfo -> Descr -> DGraphAndAGraphNode -> DGraph -> IO()
getLocalAxOfNode _ descr dgAndabstrNodeMap dgraph = do
do let dgnode = lab' (context dgraph node)
DGNode _ gth _ _ _ _ _ ->
displayTheory "Local Axioms" node dgraph gth
createTextDisplay ("Local Axioms of "++ showName name)
"no local axioms (reference node to other library)"
Nothing -> error ("node with descriptor "
++ " has no corresponding node in the development graph")
{- | outputs the theory of a node in a window;
used by the node menu defined in initializeGraph-}
getTheoryOfNode :: GInfo -> Descr -> DGraphAndAGraphNode -> DGraph -> IO()
getTheoryOfNode gInfo descr dgAndabstrNodeMap dgraph = do
r <- lookupTheoryOfNode (libEnvIORef gInfo) descr dgAndabstrNodeMap dgraph
showDiags (gi_hetcatsOpts gInfo) ds
(showName $ dgn_name $ lab' (context dgraph n))
(addHasInHidingWarning dgraph n)
displayTheory :: String -> Node -> DGraph -> G_theory
displayTheory ext node dgraph gth =
(showName $ dgn_name $ lab' (context dgraph node))
{- | translate the theory of a node in a window;
used by the node menu defined in initializeGraph-}
translateTheoryOfNode :: GInfo -> Descr -> DGraphAndAGraphNode -> DGraph -> IO()
translateTheoryOfNode gInfo@(GInfo {gi_hetcatsOpts = opts})
descr dgAndabstrNodeMap dgraph = do
libEnv <- readIORef $ libEnvIORef gInfo
maybeToResult nullRange ("Node "++show descr++" not found")
th <- computeTheory libEnv ln node
do G_theory lid sign _ sens _ <- return th
-- find all comorphism paths starting from lid
let paths = findComorphismPaths logicGraph (sublogicOfTh th)
-- let the user choose one
sel <- lift $ listBox "Choose a logic translation"
_ -> liftR $ fail "no logic translation chosen"
Comorphism cid <- return (paths!!i)
let lidS = sourceLogic cid
sign' <- coerceSign lid lidS "" sign
sens' <- coerceThSens lid lidS "" sens
-- translate theory along chosen comorphism
liftR $ wrapMapTheory cid (sign', toNamedList sens')
(showName $ dgn_name $ lab' (context dgraph node))
(addHasInHidingWarning dgraph node)
(G_theory lidT sign'' 0 (toThSens sens1) 0)
$ displayTheory "Translated theory" node dgraph
(G_theory lidT sign'' 0 (toThSens sens1) 0)-}
{- | outputs the sublogic of a node in a window;
used by the node menu defined in initializeGraph-}
----------------------------------------------------------
getSublogicOfNode :: IORef LibEnv -> Descr -> DGraphAndAGraphNode
getSublogicOfNode proofStatusRef descr dgAndabstrNodeMap dgraph = do
libEnv <- readIORef proofStatusRef
let dgnode = lab' (context dgraph node)
(DGNode nname _ _ _ _ _ _) -> nname
in case computeTheory libEnv ln node of
let logstr = show $ sublogicOfTh th
title = "Sublogic of "++showName name
in createTextDisplay title logstr [
HTk.size(30,10)]
error ("Could not compute theory for sublogic computation: "++
Nothing -> error ("node with descriptor "
++ " has no corresponding node in the development graph")
-- | prints the origin of the node
showOriginOfNode :: Descr -> DGraphAndAGraphNode -> DGraph -> IO()
showOriginOfNode descr dgAndabstrNodeMap dgraph =
do let dgnode = lab' (context dgraph node)
DGNode name _ _ _ orig _ _ ->
let title = "Origin of node "++showName name
in createTextDisplay title
DGRef _ _ _ _ _ _ -> error "showOriginOfNode: no DGNode"
Nothing -> error ("node with descriptor "
++ " has no corresponding node in the development graph")
-- | Show proof status of a node
showProofStatusOfNode :: GInfo -> Descr -> DGraphAndAGraphNode -> DGraph -> IO()
showProofStatusOfNode _ descr dgAndabstrNodeMap dgraph =
do let dgnode = lab' (context dgraph node)
let stat = showStatusAux dgnode
let title = "Proof status of node "++showName (dgn_name dgnode)
createTextDisplay title stat [
HTk.size(105,55)]
Nothing -> error ("node with descriptor "
++ " has no corresponding node in the development graph")
showStatusAux :: DGNodeLab -> String
case dgn_theory dgnode of
in "Proven proof goals:\n"
++ if not $ hasOpenConsStatus True dgnode
then showDoc (dgn_cons_status dgnode)
"is the conservativity status of this node"
++ "\nOpen proof goals:\n"
++ if hasOpenConsStatus False dgnode
then showDoc (dgn_cons_status dgnode)
"should be the conservativity status of this node"
-- | start local theorem proving or consistency checking at a node
proveAtNode :: Bool -> GInfo -> Descr -> DGraphAndAGraphNode -> DGraph -> IO()
gInfo@(GInfo {gi_LIB_NAME = ln, proofGUIMVar = guiMVar})
Just libNode -> if (checkCons
|| not (hasIncomingHidingEdge dgraph $ snd libNode))
proofMenu gInfo (basicInferenceNode checkCons
logicGraph libNode ln guiMVar)
"This node has incoming hiding links!!!"
(proofMenu gInfo (basicInferenceNode checkCons
logicGraph libNode ln guiMVar))
Nothing -> error ("node with descriptor "
++ " has no corresponding node in the development graph")
-- | print the id of the edge
showIDOfEdge :: Descr -> Maybe (LEdge DGLinkLab) -> IO()
showIDOfEdge _ (Just (_, _, linklab)) =
createTextDisplay "ID of Edge" (show $ dgl_id linklab) [
HTk.size(30,10)]
showIDOfEdge descr Nothing =
createTextDisplay "Error"
("edge "++(show descr)++" has no corresponding edge"
++ "in the development graph") [
HTk.size(30,10)]
-- | print the morphism of the edge
showMorphismOfEdge :: Descr -> Maybe (LEdge DGLinkLab) -> IO()
showMorphismOfEdge _ (Just (_,_,linklab)) =
createTextDisplay "Signature morphism"
((showDoc (dgl_morphism linklab) "")++hidingMorph)
hidingMorph = case (dgl_type linklab) of
(HidingThm morph _) -> "\n ++++++ \n"
showMorphismOfEdge descr Nothing =
createTextDisplay "Error"
("edge "++(show descr)++" has no corresponding edge"
++ "in the development graph") [
HTk.size(30,10)]
-- | print the origin of the edge
showOriginOfEdge :: Descr -> Maybe (LEdge DGLinkLab) -> IO()
showOriginOfEdge _ (Just (_,_,linklab)) =
createTextDisplay "Origin of link"
(showDoc (dgl_origin linklab) "") [
HTk.size(30,10)]
showOriginOfEdge descr Nothing =
createTextDisplay "Error"
("edge "++(show descr)++" has no corresponding edge"
++ "in the development graph") [
HTk.size(30,10)]
-- | print the proof base of the edge
showProofStatusOfThm :: Descr -> Maybe (LEdge DGLinkLab) -> IO()
showProofStatusOfThm _ (Just ledge) =
(showDoc (getProofStatusOfThm ledge) "\n")
showProofStatusOfThm descr Nothing =
putStrLn ("edge "++(show descr)++" has no corresponding edge"
++ "in the development graph")
-- | check conservativity of the edge
checkconservativityOfEdge :: Descr -> GInfo -> Maybe (LEdge DGLinkLab) -> IO()
checkconservativityOfEdge _ gInfo
(Just (source,target,linklab)) = do
libEnv <- readIORef $ libEnvIORef gInfo
let dgraph = lookupDGraph (gi_LIB_NAME gInfo) libEnv
dgtar = lab' (context dgraph target)
DGNode _ (G_theory lid _ _ sens _) _ _ _ _ _ ->
case dgl_morphism linklab of
GMorphism cid _ _ morphism2 _ -> do
morphism2' <- coerceMorphism (targetLogic cid) lid
"checkconservativityOfEdge" morphism2
let th = case computeTheory libEnv (gi_LIB_NAME gInfo) source of
_ -> error "checkconservativityOfEdge: computeTheory"
G_theory lid1 sign1 _ sens1 _ <- return th
sens2 <- coerceThSens lid1 lid "" sens1
conservativityCheck lid (sign2, toNamedList sens2)
morphism2' $ toNamedList sens
Just(Just True) -> "The link is conservative"
Just(Just False) -> "The link is not conservative"
_ -> "Could not determine whether link is conservative"
myDiags = unlines (map show ds)
createTextDisplay "Result of conservativity check"
(showRes ++ "\n" ++ myDiags) [
HTk.size(50,50)]
DGRef _ _ _ _ _ _ -> error "checkconservativityOfEdge: no DGNode"
checkconservativityOfEdge descr _ Nothing =
createTextDisplay "Error"
("edge " ++ show descr ++ " has no corresponding edge "
++ "in the development graph") [
HTk.size(30,10)]
getProofStatusOfThm :: (LEdge DGLinkLab) -> ThmLinkStatus
getProofStatusOfThm (_,_,label) =
(LocalThm proofStatus _ _) -> proofStatus
(GlobalThm proofStatus _ _) -> proofStatus
(HidingThm _ proofStatus) -> proofStatus -- richtig?
-- (FreeThm GMorphism Bool) - keinen proofStatus?
_ -> error "the given edge is not a theorem"
{- | converts the nodes of the development graph, if it has any,
and returns the resulting conversion maps
if the graph is empty the conversion maps are returned unchanged-}
-- lllllllllllllllllllllll
convertNodes :: ConversionMaps -> Descr -> GraphInfo -> DGraph
-> LIB_NAME -> IO ConversionMaps
convertNodes convMaps descr grInfo dgraph libname
| isEmpty dgraph = do return convMaps
| otherwise = convertNodesAux convMaps
{- | auxiliary function for convertNodes if the given list of nodes is
emtpy, it returns the conversion maps unchanged otherwise it adds the
converted first node to the abstract graph and to the affected
conversion maps and afterwards calls itself with the remaining node
convertNodesAux :: ConversionMaps -> Descr -> GraphInfo ->
[LNode DGNodeLab] -> LIB_NAME -> IO ConversionMaps
convertNodesAux convMaps _ _ [] _ = return convMaps
convertNodesAux convMaps descr grInfo ((node,dgnode) : lNodes) libname =
do let nodetype = getDGNodeType dgnode
(dgAndabstrNode convMaps)
} descr grInfo lNodes libname
{- | converts the edges of the development graph
works the same way as convertNods does-}
convertEdges :: ConversionMaps -> Descr -> GraphInfo -> DGraph
-> LIB_NAME -> IO ConversionMaps
convertEdges convMaps descr grInfo dgraph libname
| isEmpty dgraph = do return convMaps
| otherwise = convertEdgesAux convMaps
-- | auxiliary function for convertEges
convertEdgesAux :: ConversionMaps -> Descr -> GraphInfo ->
[LEdge DGLinkLab] -> LIB_NAME -> IO ConversionMaps
convertEdgesAux convMaps _ _ [] _ = return convMaps
convertEdgesAux convMaps descr grInfo (ledge@(src,tar,edgelab) : lEdges)
case (srcnode,tarnode) of
AGV.Result newDescr msg <- addlink descr (getDGLinkType edgelab)
"" (Just ledge) s t grInfo
newConvMaps <- convertEdgesAux convMaps
(src, tar, showDoc edgelab ""))
newDescr (dgAndabstrEdge convMaps)
} descr grInfo lEdges libname
_ -> error "Cannot find nodes"
-- | show library referened by a DGRef node (=node drawn as a box)
showReferencedLibrary :: IORef GraphMem -> Descr -> Descr -> GraphInfo
-> ConversionMaps -> HetcatsOpts
-> IO (Descr, GraphInfo, ConversionMaps)
showReferencedLibrary graphMem descr _ _ convMaps opts =
do let dgraph = devGraph gctx
(_,(DGRef _ refLibname _ _ _ _)) =
labNode' (context dgraph node)
convertGraph graphMem refLibname (libname2dg convMaps)
Nothing -> error ("The referenced library ("
error ("Selected node belongs to unknown library: "
error ("there is no node with the descriptor "
where libname2dgMap = libname2dg convMaps
-- | prune displayed graph to subtree of selected node
showJustSubtree :: IORef GraphMem -> Descr -> Descr -> ConversionMaps
-> [[Node]]-> IO (Descr, [[Node]], Maybe String)
showJustSubtree ioRefGraphMem descr abstractGraph convMaps visibleNodes =
Just (libname,parentNode) ->
do let dgraph = devGraph gctx
allNodes = getNodeDescriptors (head visibleNodes)
dgNodesOfSubtree = nub (parentNode:(getNodesOfSubtree dgraph
(head visibleNodes) parentNode))
-- the selected node (parentNode) shall not be hidden either,
-- and we already know its descriptor (descr)
nodesOfSubtree = getNodeDescriptors dgNodesOfSubtree
nodesToHide = filter (`notElem` nodesOfSubtree) allNodes
graphMem <- readIORef ioRefGraphMem
AGV.Result eventDescr errorMsg <- hidenodes abstractGraph
nodesToHide (graphInfo graphMem)
return (eventDescr, (dgNodesOfSubtree:visibleNodes), errorMsg)
Just text -> return (-1,text)
Nothing -> return (eventDescr,
("showJustSubtree: Selected node belongs to unknown library: "
error ("showJustSubtree: there is no node with the descriptor "
where libname2dgMap = libname2dg convMaps
getNodeDescriptors :: [Node] -> LIB_NAME -> ConversionMaps -> [Descr]
getNodeDescriptors [] _ _ = []
getNodeDescriptors (node:nodelist) libname convMaps =
--case
Map.lookup (libname,node) (dg2abstrNode convMaps) of
Just descr -> descr:(getNodeDescriptors nodelist libname convMaps)
Nothing -> error ("getNodeDescriptors: There is no descriptor for dgnode "
getNodesOfSubtree :: DGraph -> [Node] -> Node -> [Node]
getNodesOfSubtree dgraph visibleNodes node =
(concat (map (getNodesOfSubtree dgraph remainingVisibleNodes) predOfNode))
[n| n <- (pre dgraph node), elem n visibleNodes]
remainingVisibleNodes = [n| n <- visibleNodes, notElem n predOfNode]
-- | apply the changes history to the displayed development graph
applyHistory :: Descr -> LIB_NAME -> GraphInfo -> Descr -> IORef [[Node]]
-> [([DGRule],[DGChange])]
-> IO (Descr, ConversionMaps)
applyHistory gid libname grInfo eventDescr ioRefVisibleNodes
applyChangesAux gid libname grInfo ioRefVisibleNodes
(eventDescr, convMaps) changes
where changes = removeContraryChanges (concatMap snd history)
-- | apply the changes of first history item (computed by proof rules,
-- see folder Proofs) to the displayed development graph
applyChanges :: Descr -> LIB_NAME -> GraphInfo -> Descr -> IORef [[Node]]
-> [([DGRule],[DGChange])]
-> IO (Descr, ConversionMaps)
applyChanges _ _ _ eventDescr _ convMaps [] = return (eventDescr,convMaps)
applyChanges gid libname grInfo eventDescr ioRefVisibleNodes
convMaps (historyElem:_) =
-- trace (concat $ map showDGRule (fst historyElem)) $
applyChangesAux gid libname grInfo ioRefVisibleNodes
(eventDescr, convMaps) changes
where changes = removeContraryChanges (snd historyElem)
showDGRule :: DGRule -> String
showDGRule TheoremHideShift = "TheoremHideShift "
showDGRule (HideTheoremShift _) = "HideTheoremShift "
showDGRule Borrowing = "Borrowing "
showDGRule ConsShift = "ConsShift "
showDGRule DefShift = "DefShift "
showDGRule MonoShift = "MonoShift "
showDGRule DefToMono = "DefToMono "
showDGRule MonoToCons = "MonoToCons "
showDGRule FreeIsMono = "FreeIsMono "
showDGRule MonoIsFree = "MonoIsFree "
showDGRule (GlobDecomp _) = "GlobDecomp "
showDGRule (LocDecomp _) = "LocalDecomp "
showDGRule (LocInference _) = "LocInference "
showDGRule (GlobSubsumption _) = "GlobSubsumption "
showDGRule (Composition _) = "Composition "
showDGRule LocalInference = "LocalInference "
showDGRule (BasicInference _ _) = "BasicInference "
showDGRule (BasicConsInference _ _) = "BasicConsInference "
-- | auxiliary function for applyChanges
applyChangesAux :: Descr -> LIB_NAME -> GraphInfo -> IORef [[Node]]
-> (Descr, ConversionMaps)
-> IO (Descr, ConversionMaps)
applyChangesAux gid libname grInfo ioRefVisibleNodes
(eventDescr, convMaps) changeList =
[] -> return (eventDescr, convMaps)
--putStrLn ("applyChangesAux:\n"++show changes)
visibleNodes <- readIORef ioRefVisibleNodes
(newVisibleNodes, newEventDescr, newConvMaps) <-
applyChangesAux2 gid libname grInfo visibleNodes
eventDescr convMaps changes
{-trace (show $ dgAndabstrEdge newConvMaps) $-}
writeIORef ioRefVisibleNodes newVisibleNodes
return (newEventDescr, newConvMaps)
-- | auxiliary function for applyChanges
applyChangesAux2 :: Descr -> LIB_NAME -> GraphInfo -> [[Node]] -> Descr
-> ConversionMaps -> [DGChange]
-> IO ([[Node]], Descr, ConversionMaps)
applyChangesAux2 _ _ _ visibleNodes eventDescr convMaps [] =
return (visibleNodes, eventDescr+1, convMaps)
applyChangesAux2 gid libname grInfo visibleNodes _ convMaps (change:changes) =
SetNodeLab _ (node, newLab) -> do
let nodetype = getDGNodeType newLab
nodename = getDGNodeName newLab
changeNodeType gid abstrNode nodetype grInfo
let newConvMaps = convMaps {dgAndabstrNode =
InjMap.updateBWithA dgNode descr (dgAndabstrNode convMaps)}
dgAndabstrNode =
InjMap.insert dgNode descr (dgAndabstrNode convMaps)
applyChangesAux2 gid libname grInfo visibleNodes (descr+1) newConvMaps changes
error ("applyChangesAux2: could not set node " ++ (show node)
++" with name " ++ (show (nodename)) ++ "\n"
Nothing -> error ("applyChangesAux2: could not set node "
++ (show node) ++ " with name "
++ (show nodename) ++": " ++
"node does not exist in abstraction graph")
InsertNode (node, nodelab) -> do
let nodetype = getDGNodeType nodelab
nodename = getDGNodeName nodelab
addnode gid nodetype nodename grInfo
do let dgNode = (libname,node)
newVisibleNodes = map (node :) visibleNodes
convMaps {{-dg2abstrNode =
Map.insert descr dgNode (abstr2dgNode convMaps),-}
dgAndabstrNode =
InjMap.insert dgNode descr (dgAndabstrNode convMaps)
applyChangesAux2 gid libname grInfo newVisibleNodes (descr+1)
error ("applyChangesAux2: could not add node " ++ (show node)
++" with name " ++ (show (nodename)) ++ "\n"
DeleteNode (node, nodelab) -> do
let nodename = getDGNodeName nodelab
AGV.Result descr err <- delnode gid abstrNode grInfo
let newVisibleNodes = map (filter (/= node)) visibleNodes
convMaps {{-dg2abstrNode =
dgAndabstrNode =
InjMap.delete dgnode abstrNode (dgAndabstrNode convMaps)
applyChangesAux2 gid libname grInfo newVisibleNodes (descr+1)
Just msg -> error ("applyChangesAux2: could not delete node "
++ (show node) ++ " with name "
++ (show nodename) ++ "\n"
Nothing -> error ("applyChangesAux2: could not delte node "
++ (show node) ++ " with name "
++ (show nodename) ++": " ++
"node does not exist in abstraction graph")
InsertEdge ledge@(src,tgt,edgelab) ->
do let dgAndabstrNodeMap = dgAndabstrNode convMaps
--let dg2abstrNodeMap = dg2abstrNode convMaps
(Just abstrSrc, Just abstrTgt) ->
do let dgEdge = (libname, (src,tgt,showDoc edgelab ""))
Just y -> putStrLn $ show y
--trace (show $ isProven ledge) $ putStrLn $ show x
addlink gid (getDGLinkType edgelab)
"" (Just ledge) abstrSrc abstrTgt grInfo
do let newConvMaps = convMaps
Map.insert descr dgEdge (abstr2dgEdge convMaps),-}
dgAndabstrEdge =
InjMap.insert dgEdge descr (dgAndabstrEdge convMaps)
applyChangesAux2 gid libname grInfo visibleNodes
(descr+1) newConvMaps changes
error ("applyChangesAux2: could not add link from "
++ (show src) ++ " to " ++ (show tgt) ++ ":\n"
error ("applyChangesAux2: could not add link " ++ (show src)
++ " to " ++ (show tgt) ++ ": illegal end nodes")
DeleteEdge (src,tgt,edgelab) ->
do let dgEdge = (libname, (src,tgt,showDoc edgelab ""))
dgAndabstrEdgeMap = dgAndabstrEdge convMaps
-- dg2abstrEdgeMap = dg2abstrEdge convMaps
do
AGV.Result descr err <- dellink gid abstrEdge grInfo
do let newConvMaps = convMaps
applyChangesAux2 gid libname grInfo visibleNodes
(descr+1) newConvMaps changes
"applyChangesAux2: could not delete edge "
++ shows abstrEdge ":\n" ++ msg
{-trace ((show $
InjMap.getAToB dgAndabstrEdgeMap)++ "\nThe to be deleted edge is:\n" ++(show dgEdge)) $ -}
Nothing -> error $ "applyChangesAux2: deleted edge from "
++ shows src " to " ++ shows tgt
" of type " ++ showDoc (dgl_type edgelab)
" and origin " ++ shows (dgl_origin edgelab)
++ "graph does not exist in abstraction graph"
-- | display a window of translated graph with maximal sublogic.
openTranslateGraph :: LibEnv
openTranslateGraph libEnv ln opts (
Res.Result diagsSl mSublogic) =
-- if a error existed by the search of maximal sublogicn
if hasErrors diagsSl then
do errorMess (unlines $ map show $
filter (relevantDiagKind . diagKind) diagsSl)
let paths = findComorphismPaths logicGraph sublogic
do errorMess "This graph has no comorphism to translation."
sel <- lift $ listBox "Choose a logic translation"
_ -> liftR $ fail "no logic translation chosen"
aComor <- return (paths!!(fromJust i))
case libEnv_translation libEnv aComor of
do showDiags opts (diagsSl ++ diagsR ++ diagsTrans)
if hasErrors (diagsR ++ diagsTrans) then
errorMess (unlines $ map show $
filter (relevantDiagKind . diagKind)
(\gm -> convertGraph gm ln newLibEnv opts
do errorMess (unlines $ map show $
filter (relevantDiagKind . diagKind)
(diagsSl ++ diagsR ++ diagsTrans))
Nothing -> do errorMess "the maximal sublogic is not found."
where relevantDiagKind Error = True
relevantDiagKind Warning = (verbose opts) >= 2
relevantDiagKind Hint = (verbose opts) >= 4
relevantDiagKind Debug = (verbose opts) >= 5
relevantDiagKind MessageW = False
dg_showGraphAux :: (IORef GraphMem -> IO (Descr, GraphInfo, ConversionMaps))
dg_showGraphAux convFct = do
initGraphInfo <- initgraphs
graphMem <- (newIORef GraphMem{nextGraphId = 0,
graphInfo = initGraphInfo})
useHTk -- All messages are displayed in TK dialog windows
(gid, gv, _cmaps) <- convFct graphMem