root/trunk/PGIP/DataTypesUtils.hs @ 11229

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

Changes to GUI to use common datatypes in Interfaces

Line 
1{- |
2Module      :$Header$
3Description : utilitary functions used throughout the CMDL interface
4Copyright   : uni-bremen and DFKI
5License     : similar to LGPL, see HetCATS/LICENSE.txt or LIZENZ.txt
6Maintainer  : r.pascanu@jacobs-university.de
7Stability   : provisional
8Portability : portable
9
10PGIP.Utils contains different basic functions that are
11used throughout the CMDL interface and could not be found in
12Prelude
13
14-}
15
16module PGIP.DataTypesUtils
17         ( getAllNodes
18         , obtainGoalNodeList
19         , getAllGoalNodes
20         , getAllGoalEdges
21         , getTh
22         , baseChannels
23         , genErrorMsg
24         , genMessage
25         , generatePrompter
26         , add2hist
27         , getIdComorphism
28         ) where
29
30
31import Interfaces.DataTypes
32import Interfaces.Utils
33import Interfaces.History
34import PGIP.Utils
35import PGIP.DataTypes
36import Common.Result
37import Data.List
38import Data.Graph.Inductive.Graph
39import Static.GTheory
40import Static.DevGraph
41import Proofs.TheoremHideShift
42import System.IO
43
44import Proofs.AbstractState
45import Proofs.TheoremHideShift
46
47import Static.GTheory
48import Static.DevGraph
49
50import Common.Result
51
52import Data.Graph.Inductive.Graph
53import Data.List
54
55
56import Common.Result
57import Logic.Comorphism
58import Logic.Grothendieck
59
60
61add2hist :: [UndoRedoElem] -> CMDL_State ->  CMDL_State
62add2hist descr st
63 = let intst = add2history [] (intState st)  descr
64   in st {
65         intState = intst }
66
67-- | Given a list of selected theory generate an Id comorphism to the
68-- first selected theory
69getIdComorphism :: [Int_NodeInfo] -> Maybe AnyComorphism
70getIdComorphism ls
71 = case ls of
72    [] -> Nothing
73    (Element st _):_ ->
74       case sublogicOfTheory st of
75        (G_sublogics lid sub) -> Just $ Comorphism (mkIdComorphism lid sub)
76
77
78-- | Generates the string containing the prompter
79generatePrompter :: CMDL_State -> String
80generatePrompter st
81 = case i_state $ intState st of
82    Nothing ->  prompterHead $ prompter st
83    Just ist ->
84     let pst = prompter st
85         els = case elements ist of
86                []  -> []
87                el:[] -> case el of
88                          Element sm _ ->"."++(theoryName sm)
89                el:_ -> case el of
90                          Element sm _ ->"." ++(theoryName sm)++ ".."
91         cm = case elements ist of
92               [] -> []
93               _-> case cComorphism ist of
94                    Nothing -> []
95                    Just cm' ->
96                     case getIdComorphism $ elements ist of
97                      Nothing -> []
98                      Just ocm ->
99                        case cm' == ocm of
100                          True -> []
101                          False -> "*"
102     in (delExtension $ fileLoaded pst) ++ els ++ cm ++ (prompterHead pst)
103
104
105-- | Given a list of node names and the list of all nodes
106-- the function returns all the nodes that have their name
107-- in the name list but are also goals
108obtainGoalNodeList :: CMDL_State -> [String] -> [LNode DGNodeLab]
109                                 -> ([String],[LNode DGNodeLab])
110obtainGoalNodeList state input ls
111 = let (l1,l2) = obtainNodeList input ls
112       l2' = filter (\(nb,nd) ->
113                       let nwth = getTh Dont_translate nb state
114                       in case nwth of
115                           Nothing -> False
116                           Just th -> nodeContainsGoals (nb,nd) th) l2
117   in (l1,l2')
118
119
120-- | Returns the list of all nodes that are goals,
121-- taking care of the up to date status
122getAllGoalNodes :: CMDL_State ->  [LNode DGNodeLab]
123getAllGoalNodes st
124 = case i_state $ intState st of
125    Nothing -> []
126    Just ist ->
127      filter (\(nb,nd) ->
128             let nwth = getTh Dont_translate nb st
129             in case nwth of
130                 Nothing -> False
131                 Just th -> nodeContainsGoals (nb,nd) th) $
132                                 getAllNodes $ ist
133
134-- | Returns the list of all goal edges taking care of the
135-- up to date status
136getAllGoalEdges :: CMDL_State -> [LEdge DGLinkLab]
137getAllGoalEdges st
138 = case i_state $ intState st of
139    Nothing -> []
140    Just ist ->
141      filter edgeContainsGoals $ getAllEdges $ ist
142
143
144--local function that computes the theory of a node
145--that takes into consideration translated theories in
146--the selection too and returns the theory as a string
147getTh :: CMDL_UseTranslation -> Int -> CMDL_State -> Maybe G_theory
148getTh useTrans x st
149 = let
150    -- compute the theory for a given node
151       fn n = case i_state $ intState st of
152               Nothing -> Nothing
153               Just ist ->
154                case computeTheory False (i_libEnv ist) (i_ln ist) n of
155                 Result _ (Just (_, th)) -> Just th
156                 _                       -> Nothing
157
158   in
159    case useTrans of
160     Dont_translate -> fn x
161     Do_translate ->
162      case i_state $ intState st of
163       Nothing -> Nothing
164       Just ist ->
165        case elements ist of
166         [] -> fn x
167         _ ->
168          case find (\y -> case y of
169                          Element _ z -> z == x) $
170                  elements ist of
171           Nothing -> fn x
172           Just _ ->
173            case cComorphism ist of
174             Nothing -> fn x
175             Just cm ->
176              case fn x of
177               Nothing -> Nothing
178               Just sth->
179                case mapG_theory cm sth of
180                  Result _ Nothing -> Just sth
181                  Result _ (Just sth') -> Just sth'
182
183
184-- | Generates the base channels to be used (stdin and stdout)
185baseChannels :: [CMDL_Channel]
186baseChannels
187 = let ch_in  = CMDL_Channel {
188                  chName       = "stdin",
189                  chType       = ChStdin,
190                  chHandler    = stdin,
191                  chSocket     = Nothing,
192                  chProperties = ChRead
193                  }
194       ch_out = CMDL_Channel {
195                  chName       = "stdout",
196                  chType       = ChStdout,
197                  chHandler    = stdout,
198                  chSocket     = Nothing,
199                  chProperties = ChWrite
200                  }
201   in ch_in : ch_out : []
202
203
204genErrorMsg :: String -> CMDL_State -> CMDL_State
205genErrorMsg msg st
206 = st {
207      output = CMDL_Message {
208         outputMsg = [],
209         warningMsg = [],
210         errorMsg = msg
211         }
212     }
213
214genMessage :: String -> String -> CMDL_State -> CMDL_State
215genMessage warnings msg st
216 = st{
217      output = CMDL_Message {
218        outputMsg = msg,
219        warningMsg = warnings,
220        errorMsg = []
221        }
222     }
223
Note: See TracBrowser for help on using the browser.