OpendTect-6_4  6.4
cmddriver.h
Go to the documentation of this file.
1 #ifndef cmddriver_h
2 #define cmddriver_h
3 
4 /*+
5 ________________________________________________________________________
6 
7  (C) dGB Beheer B.V.; (LICENSE) http://opendtect.org/OpendTect_license.txt
8  Author: Bert Bril
9  Date: Sep 2005
10  RCS: $Id$
11 ________________________________________________________________________
12 
13 -*/
14 
15 #include "uicmddrivermod.h"
16 #include "bufstringset.h"
17 #include "od_iostream.h"
18 #include "separstr.h"
19 #include "strmdata.h"
20 #include "thread.h"
21 #include "uimainwin.h"
22 
23 #include "cmddriverbasics.h"
24 #include "searchkey.h"
25 
26 class FilePath;
27 class StreamData;
28 class uiObject;
29 class uiMenu;
30 class uiTaskRunner;
31 
32 namespace CmdDrive
33 {
34  class Activator;
35  class IdentifierManager;
36  class ExprInterpreter;
37  class WildcardManager;
38  class MenuTracer;
39 
40 #define mLogStrm \
41  if ( drv_.logStream().isOK() ) drv_.logStream()
42 
43 #define mTimeStrm \
44  mLogStrm << "[" << Time::getTimeString() << "]\t"
45 
46 #define mParseMsgStrm(tag) \
47  if ( !drv_.streamBlocked(true,tag) ) \
48  mLogStrm << "\t" << (tag) << " [parse]: "
49 
50 #define mParseStrm(warn) mParseMsgStrm( warn ? "WARN" : "ERROR" )
51 #define mParseErrStrm mParseStrm( false )
52 #define mParseWarnStrm mParseStrm( true )
53 
54 #define mWinMsgStrm(tag) \
55  if ( !drv_.streamBlocked(false,tag) ) \
56  mLogStrm << "\t" << (tag) << " [" << drv_.curWinTitle() << "]:\n\t\t"
57 
58 #define mWinStrm(warn) mWinMsgStrm( warn ? "WARN " : "ERROR" )
59 #define mWinErrStrm mWinStrm( false )
60 #define mWinWarnStrm mWinStrm( true )
61 
62 
63 mExpClass(uiCmdDriver) ModalStatus
64 {
65 public:
66  bool operator==(const ModalStatus&) const;
67  bool operator!=(const ModalStatus&) const;
68 
74 };
75 
76 
77 mExpClass(uiCmdDriver) Action
78 {
79 public:
80  Action(const char* line)
81  : line_(line), gotoidx_(-1)
82  , insertidx_(-1) {}
83 
85  int gotoidx_;
87 };
88 
89 
90 mExpClass(uiCmdDriver) MenuInfo
91 {
92 public:
95  int ison_;
97 };
98 
99 
101 
102 
103 mExpClass(uiCmdDriver) CmdDriver : public CallBacker
105 public:
106  friend class Command;
107  friend class ExprInterpreter;
108  friend class Function;
109  friend class MenuTracer;
110 
111  CmdDriver(uiMainWin& applwin);
112  ~CmdDriver();
113 
114  bool getActionsFromFile(const char*);
115  bool insertActionsFromFile(const char*);
116 
117  bool execute();
118  void abort() { abort_ = true; }
119  void pause(bool yn=true);
120  const char* errMsg() const { return errmsg_.str();}
121 
122  const char* outputDir() const { return outdir_; }
123  void setOutputDir(const char* od) { outdir_ = od; }
124 
125  static const char* defaultLogFilename();
126  const char* logFileName() const { return logfnm_; }
127  void setLogFileName(const char* fnm) { logfnm_ = fnm; }
128  void clearLog() { logstream_.close(); }
129 
130  enum LogModeTag { LogBasic, LogNormal, LogAll };
131  void setLogMode(LogModeTag tag) { logmode_ = tag; }
132 
133  enum OnErrorTag { Stop, Recover };
134  void setOnError(OnErrorTag tag) { onerror_ = tag; }
135 
136  void setCaseSensitive(bool yn) { casesensitive_ = yn; }
137  void skipGreyOuts(bool yn=true) { skipgreyouts_ = yn; }
138 
139  bool isCaseSensitive() const { return casesensitive_; }
140  OnErrorTag onError() const { return onerror_; }
141  bool greyOutsSkipped() const { return skipgreyouts_; }
142 
143  void setSleep(float time,
144  bool regular=true);
145  void setWait(float time,
146  bool regular=true);
147 
148  static bool nowExecuting();
149 
150  enum RecoveryTag { NoClue, CloseCurWin, NextCmd,
151  NextAssertion };
152 
153  enum InterceptMode { Click, ItemInfo, NodeInfo };
154 
157 
158 protected:
159 
161  uiMainWin* applWin() { return applwin_; }
162  const uiMainWin* applWin() const { return applwin_; }
163 
164  void exitApplCB( CallBacker* );
165 
166  const uiObject* localSearchEnv() const { return localsearchenv_; }
167 
168  bool doLocalAction(uiObject* localenv,const char* actstr);
169  bool tryAction(const char* identname,const char* actstr);
170 
171  void prepareForResume();
172  void prepareForAbort();
173 
174  bool abort_;
175  bool pause_;
176  bool resume_;
177 
178  bool prepareActivate(Activator*);
179  void finishActivate();
180  void waitForClearance();
181 
182  void prepareIntercept(const FileMultiString& mnupath,
183  int onoff,InterceptMode=Click);
184  bool didInterceptSucceed(const char* objnm);
185  const MenuInfo& interceptedMenuInfo() const;
186 
187  void reInit();
188 
197 
199  WildcardManager& wildcardMan() { return *wcm_; }
200 
202  IdentifierManager& identifierMan() { return *idm_; }
203 
204  const WildcardManager& wildcardMan() const;
205  const IdentifierManager& identifierMan() const;
206 
209 
211  ExprInterpreter& exprInterpreter() { return *eip_; }
212 
213  void logErrMsg();
214  void updateLogStrm();
216 
217  bool addActions(ObjectSet<Action>&,const char*);
220 
221  int curActionIdx() const { return actionidx_; }
222  bool insertProcedure(int defidx);
223 
224  void moveActionIdx(int nrlines);
225  int lastActionIdxMove() const { return lastmove_; }
227 
228  void end();
229  void jump(int extralines=0);
231 
232  void mkThread(CallBacker*);
233  bool doAction(const char*);
234 
237 
240  bool goingToChangeUiObj() const { return uiobjchange_; }
241 
244 
247 
251  bool verifyWinAssert(const char* newwinstr=0);
252 
255  bool verifyWinState(const char* newwinstr=0,
256  WinStateType newwinstate=NoState);
257 
259  bool recover();
261  void setRecoveryStep(RecoveryTag rt) { recoverystep_ = rt; }
262 
263  static const char* locateCmdMark(const char* actstr);
264 
265  bool switchCurWin(const uiMainWin*);
267  const uiMainWin* curWin() const { return winstack_.topWin(true); }
268 
270  bool openQDlg() const { return openqdialog_; }
271 
273  bool activityStopped(bool checkprocessing=true,
274  bool checktimers=true);
275 
276  bool waitForTimers();
277  bool waitForProcessing();
279 
280  void getModalStatus(ModalStatus&);
281  void storeModalStatus();
283 
287 
288  void activateDone(CallBacker* activator);
289  void timerStartsCB(CallBacker* timer);
290  void timerStoppedCB(CallBacker* timer);
291  void timerShootsCB(CallBacker* timer);
292  void timerShotCB(CallBacker* timer);
293 
294  void forceQtToCatchUp();
295  // Delay to assure that Qt has finished all previous
296  // display, hide and outgrey tasks initiated by the
297  // GUI thread.
298 
299  enum InterceptStatus { NoInterception, InterceptError,
300  InterceptReady };
307 
308  void dynamicMenuInterceptor(CallBacker*);
309  bool dispatchDynamicMenu(uiMenu*);
310 
311  void interactCB(CallBacker*);
312  void executeFinishedCB(CallBacker*);
313  void killTaskRunnerCB(CallBacker*);
314 
316  void interact(const InteractSpec*);
317 
321 
322 
323 public:
324  // interface for output stream macros
325  od_ostream& logStream() { return logstream_; }
326  const char* curWinTitle(int aliasnr=0) const;
327 
328  bool streamBlocked(bool parse,const char* tag);
329  // Does tryout management as side-effect!
330 
331 };
332 
333 
334 }; // namespace CmdDrive
335 
336 
337 #endif
#define mExpClass(module)
Definition: commondefs.h:160
int wildmodalclosedstamp_
Definition: cmddriver.h:278
User interface main window.
Definition: uimainwin.h:36
ObjectSet< Action > actions_
Definition: cmddriver.h:218
To be able to send and/or receive CallBacks, inherit from this class.
Definition: callback.h:272
bool openQDlg() const
Definition: cmddriver.h:270
od_ostream & logStream()
Definition: cmddriver.h:325
OD class for stream write common access to the user log file, or std::cout in batch progs...
Definition: od_ostream.h:26
float pendingsleep_
Definition: cmddriver.h:242
const char * str() const
Definition: odstring.h:48
Threads::Thread * execthr_
Definition: cmddriver.h:194
bool goingToChangeUiObj() const
Definition: cmddriver.h:240
BufferString winstatewin_
Definition: cmddriver.h:253
A lock of a type that (hopefully) suits your needs. To use it, you need the Locker class...
Definition: threadlock.h:53
bool operator==(const ArrayNDInfo &a1, const ArrayNDInfo &a2)
Definition: arrayndinfo.h:53
FilePath & outfp_
Definition: cmddriver.h:196
float regularsleep_
Definition: cmddriver.h:243
Command Drive
Definition: canvascommands.h:22
const char * outputDir() const
Definition: cmddriver.h:122
uiMainWin::ActModalTyp activetype_
Definition: cmddriver.h:69
#define mODTextTranslationClass(clss)
Definition: uistring.h:38
const char * errMsg() const
Definition: cmddriver.h:120
bool winassertsafe_
Definition: cmddriver.h:250
void abort()
Definition: cmddriver.h:118
int gotoidx_
Definition: cmddriver.h:85
RecoveryTag
Definition: cmddriver.h:150
int tryoutval_
Definition: cmddriver.h:208
BufferString winassertion_
Definition: cmddriver.h:248
bool isCaseSensitive() const
Definition: cmddriver.h:139
ExprInterpreter & exprInterpreter()
Definition: cmddriver.h:211
ObjectSet< const CallBacker > timeoutlist_
Definition: cmddriver.h:320
Definition: command.h:186
Definition: searchkey.h:57
WinStateType winstatetype_
Definition: cmddriver.h:254
bool curactjumped_
Definition: cmddriver.h:230
const uiObject * localSearchEnv() const
Definition: cmddriver.h:166
InterceptStatus
Definition: cmddriver.h:299
Definition: cmddriver.h:100
int lastmove_
Definition: cmddriver.h:226
bool abort_
Definition: cmddriver.h:174
od_ostream & logstream_
Definition: cmddriver.h:195
Definition: cmddriver.h:100
OnErrorTag onerror_
Definition: cmddriver.h:258
Threads::Lock cmddrvlock_
Definition: cmddriver.h:272
ActModalTyp
Definition: uimainwin.h:154
Action(const char *line)
Definition: cmddriver.h:80
Definition: cmddriver.h:133
od
Definition: strattransl.h:17
ExprInterpreter * eip_
Definition: cmddriver.h:210
bool casesensitive_
Definition: cmddriver.h:235
The base class for most UI elements.
Definition: uiobj.h:38
int lastActionIdxMove() const
Definition: cmddriver.h:225
Set of BufferString objects.
Definition: bufstringset.h:28
IdentifierManager * idm_
Definition: cmddriver.h:201
int prevnrproc_
Definition: cmddriver.h:286
const InteractSpec * interactspec_
Definition: cmddriver.h:315
Definition: interpretexpr.h:24
void setLogMode(LogModeTag tag)
Definition: cmddriver.h:131
LogModeTag
Definition: cmddriver.h:130
bool pause_
Definition: cmddriver.h:175
Definition: callback.h:254
SeparString with backquotes as separators, use in most ascii files.
Definition: separstr.h:119
void setCaseSensitive(bool yn)
Definition: cmddriver.h:136
bool uiobjchange_
Definition: cmddriver.h:239
const uiMainWin * topWin(bool ignorecmddriverwins=false) const
float regularwait_
Definition: cmddriver.h:246
BufferString logfnm_
Definition: cmddriver.h:191
WinStateType
Definition: cmddriver.h:100
OnErrorTag
Definition: cmddriver.h:133
Is the base class for all threads. Start it by creating it and give it the function or CallBack to ex...
Definition: thread.h:283
Definition: cmddriver.h:299
void setRecoveryStep(RecoveryTag rt)
Definition: cmddriver.h:261
void setOutputDir(const char *od)
Definition: cmddriver.h:123
Definition: cmddriverbasics.h:197
Definition: cmddriver.h:130
ObjectSet< const char > tryoutstack_
Definition: cmddriver.h:207
Definition: cmddriver.h:100
uiObject * localsearchenv_
Definition: cmddriver.h:236
const uiMainWin * applWin() const
Definition: cmddriver.h:162
int insertidx_
Definition: cmddriver.h:86
ObjectSet< const CallBacker > timerlist_
Definition: cmddriver.h:319
WindowStack winstack_
Definition: cmddriver.h:266
BufferString line_
Definition: cmddriver.h:84
bool resume_
Definition: cmddriver.h:176
void skipGreyOuts(bool yn=true)
Definition: cmddriver.h:137
InterceptStatus interceptstatus_
Definition: cmddriver.h:301
Holds data to use and close an iostream.
Definition: strmdata.h:28
BufferString errmsg_
Definition: cmddriver.h:193
float pendingwait_
Definition: cmddriver.h:245
uiMainWin * activewin_
Definition: cmddriver.h:70
BufferString text_
Definition: cmddriver.h:96
Definition: uimenu.h:65
bool operator!=(const ArrayNDInfo &a1, const ArrayNDInfo &a2)
Definition: arrayndinfo.h:62
Definition: cmddriver.h:90
BufferString outdir_
Definition: cmddriver.h:190
Definition: identifierman.h:23
IdentifierManager & identifierMan()
Definition: cmddriver.h:202
int curActionIdx() const
Definition: cmddriver.h:221
BufferStringSet signatures_
Definition: cmddriver.h:73
File pathname tools.
Definition: filepath.h:34
const uiMainWin * curWin() const
Definition: cmddriver.h:267
OD::String with its own variable length buffer. The buffer has a guaranteed minimum size...
Definition: bufstring.h:40
RecoveryTag recoverystep_
Definition: cmddriver.h:260
int nrmodalwins_
Definition: cmddriver.h:72
bool openqdialog_
Definition: cmddriver.h:269
Definition: uitaskrunner.h:26
Notifier< CmdDriver > executeFinished
Definition: cmddriver.h:156
BufferString cmdfnm_
Definition: cmddriver.h:192
bool greyOutsSkipped() const
Definition: cmddriver.h:141
BufferString errmsg_
Definition: horizontracker.h:119
Definition: cmdfunction.h:28
int interceptonoff_
Definition: cmddriver.h:304
LogModeTag logmode_
Definition: cmddriver.h:215
bool skipgreyouts_
Definition: cmddriver.h:238
CmdDriver & drv_
Definition: cmddriver.h:189
int siblingnr_
Definition: cmddriver.h:94
WildcardManager & wildcardMan()
Definition: cmddriver.h:199
uiMainWin * applWin()
Definition: cmddriver.h:161
void setOnError(OnErrorTag tag)
Definition: cmddriver.h:134
void setLogFileName(const char *fnm)
Definition: cmddriver.h:127
ObjectSet< const CallBacker > activatorlist_
Definition: cmddriver.h:318
uiMainWin * applwin_
Definition: cmddriver.h:160
OnErrorTag onError() const
Definition: cmddriver.h:140
Notifier< CmdDriver > interactRequest
Definition: cmddriver.h:155
int ison_
Definition: cmddriver.h:95
Definition: cmddriverbasics.h:178
Definition: command.h:223
Definition: cmddriver.h:77
bool interceptmenu_
Definition: cmddriver.h:305
InterceptMode interceptmode_
Definition: cmddriver.h:303
ModalStatus prevmodalstat_
Definition: cmddriver.h:285
uiTaskRunner * uitaskrunner_
Definition: cmddriver.h:71
Definition: cmddriver.h:63
MenuInfo interceptmenuinfo_
Definition: cmddriver.h:306
int nrchildren_
Definition: cmddriver.h:93
int actionidx_
Definition: cmddriver.h:219
FileMultiString interceptmenupath_
Definition: cmddriver.h:302
const char * logFileName() const
Definition: cmddriver.h:126
WildcardManager * wcm_
Definition: cmddriver.h:198
BufferStringSet wildmodalsignatures_
Definition: cmddriver.h:282
Definition: cmddriver.h:100
bool winassertcs_
Definition: cmddriver.h:249
void clearLog()
Definition: cmddriver.h:128
InterceptMode
Definition: cmddriver.h:153
Definition: cmddriver.h:103
Definition: command.h:35
ModalStatus curmodalstat_
Definition: cmddriver.h:284
Definition: cmddriver.h:100

Generated at for the OpendTect seismic interpretation project. Copyright (C): dGB Beheer B. V. 2019