OpendTect  6.6
command.h
Go to the documentation of this file.
1 #pragma once
2 
3 /*+
4 ________________________________________________________________________
5 
6  (C) dGB Beheer B.V.; (LICENSE) http://opendtect.org/OpendTect_license.txt
7  Author: Jaap Glas
8  Date: February 2009
9  RCS: $Id$
10  ________________________________________________________________________
11 
12 -*/
13 
14 #include "uicmddrivermod.h"
15 #include "factory.h"
16 #include "identifierman.h"
17 #include "objectfinder.h"
18 #include "uidialog.h"
19 #include "uimainwin.h"
20 #include "uitreeview.h"
21 #include "cmddriver.h"
22 #include "timefun.h"
23 #include "uistring.h"
24 
25 class uiActionContainer;
26 class uiAction;
27 
28 namespace CmdDrive
29 {
30 
31 class Activator;
32 
33 
34 mExpClass(uiCmdDriver) Command
35 {
36 public:
37 
39  static void initStandardCommands();
40  static BufferString factoryKey(const char* name);
41 
42  Command(CmdDriver& cmddrv)
43  : drv_(cmddrv)
44  {}
45  virtual ~Command() {}
46 
47  virtual const char* name() const = 0;
48  virtual bool act(const char* parstr) = 0;
49 
50  virtual bool isOpenQDlgCommand() const { return true; }
51  virtual bool isLocalEnvCommand() const { return false; }
52  virtual bool isVisualCommand() const { return true; }
53  virtual bool isUiObjChangeCommand() const { return false; }
54 
55  static bool isQuestionName(const char*,CmdDriver&);
56 
57  enum FormTag { NoForm=0, Text, Number, Colour, Value, Angle,
58  Minimum, Maximum, Step, Percentage, FilePath };
59 
60 protected:
61 
62  static BufferString createFactoryKey(const char* keyword);
63 
66 
67  const char* outputDir() const;
68 
70  const uiMainWin* curWin() const;
71  bool openQDlg() const;
72 
74 
76  bool verifyWinAssert(const char* newwinstr=0);
77  bool verifyWinState(const char* newwinstr=0,
78  WinStateType newwinstate=NoState);
79 
81 
82  void setCaseSensitive(bool yn);
83  bool isCaseSensitive() const;
84  void skipGreyOuts(bool yn=true);
85  bool greyOutsSkipped() const;
86  bool goingToChangeUiObj() const;
87 
88  void setSleep(float time,bool regular);
89  void setWait(float time,bool regular);
90 
91  const uiObject* localSearchEnv() const;
92  bool doLocalAction(uiObject* localenv,const char* actstr);
93  bool tryAction(const char* identname,const char* actstr);
94 
98 
99  void prepareIntercept(const FileMultiString& menupath,
100  int onoff,
102 
103  bool didInterceptSucceed(const char* objnm);
105 
106  void interact(const InteractSpec*);
107 
111 
112  void end();
113  void jump(int extralines=0);
114  int lastActionIdxMove() const;
115 
116  int curActionIdx() const;
117  bool insertProcedure(int defidx);
118 };
119 
120 
121 #define mStartDeclCmdClassNoActNoEntry(mod,cmdkey,parentclass) \
122 \
123 mExpClass(mod) cmdkey##Cmd : public parentclass \
124 { mODTextTranslationClass(cmdkey##Cmd); \
125 public: \
126  cmdkey##Cmd(CmdDriver& cmddrv) \
127  : parentclass(cmddrv) \
128  {} \
129 \
130  static const char* keyWord() { return #cmdkey; } \
131  virtual const char* name() const { return keyWord(); }
132 
133 #define mStartDeclCmdClassNoAct(mod,cmdkey,parentclass) \
134 \
135  mStartDeclCmdClassNoActNoEntry(mod,cmdkey,parentclass) \
136 \
137  static Command* createInstance(CmdDriver& cmddrv) \
138  { return new cmdkey##Cmd(cmddrv); } \
139  static void initClass() \
140  { factory().addCreator( createInstance, \
141  createFactoryKey(keyWord()) ); }
142 
143 #define mStartDeclCmdClassNoEntry(mod,cmdkey,parentclass) \
144  mStartDeclCmdClassNoActNoEntry(mod,cmdkey,parentclass) \
145  virtual bool act(const char* parstr);
146 
147 #define mStartDeclCmdClass( mod,cmdkey,parentclass) \
148  mStartDeclCmdClassNoAct(mod,cmdkey,parentclass) \
149  virtual bool act(const char* parstr);
150 
151 #define mEndDeclCmdClass \
152 };
153 
154 
155 mStartDeclCmdClassNoActNoEntry( uiCmdDriver, UiObject, Command )
156  virtual bool isOpenQDlgCommand() const { return false; }
157  virtual bool isLocalEnvCommand() const { return true; }
158  virtual bool isUiObjChangeCommand() const { return true; }
160 
161 mStartDeclCmdClassNoActNoEntry( uiCmdDriver,UiObjQuestion, Command )
162  virtual bool isOpenQDlgCommand() const { return false; }
163  virtual bool isLocalEnvCommand() const { return true; }
164  virtual bool isVisualCommand() const { return false; }
166 
168  virtual bool isVisualCommand() const { return false; }
170 
171 
172 //====== Activator ==========================================================
173 
174 /* The Activator base class handles the GUI thread callback after calling the
175  uiMainWin::activateInGUIThread( mCB(activator,Activator,actCB), busywait )
176  function. Its actCB(cber) function contains the code that must be executed
177  in the GUI thread to prevent Qt from crashing.
178 
179  Apart from pointers or references to ui-objects, the Activator subclasses
180  should be careful declaring pointer or reference data members. Copying is
181  preferable, since their initialization by local variables will be unsafe
182  in case activateInGUIThread(.,.) is going to be called with busywait=false.
183 */
184 
185 mExpClass(uiCmdDriver) Activator : public CallBacker
186 {
187 public:
188  virtual ~Activator() {};
189  virtual void actCB(CallBacker*) = 0;
190 };
191 
192 
193 mExpClass(uiCmdDriver) CloseActivator: public Activator
194 {
195 public:
197  : actmainwin_( const_cast<uiMainWin&>(uimw) )
198  {}
199  void actCB(CallBacker* cb)
200  { actmainwin_.close(); }
201 protected:
203 };
204 
205 
207 {
208 public:
209  CloseQDlgActivator(int retval)
210  : actretval_( retval )
211  {}
212  void actCB(CallBacker* cb)
213  { uiMainWin::closeActiveModalQDlg(actretval_); }
214 protected:
216 };
217 
218 
219 //====== Menu tracer ==========================================================
220 
221 
222 mExpClass(uiCmdDriver) MenuTracer
223 {
224 public:
226  CmdDriver& cmddrv)
227  : startmenu_(mnu), drv_(cmddrv)
228  {}
229 
230  bool findItem(const FileMultiString& menupath,
231  const uiAction*& curitem,int* curitmidx=0) const;
232  bool getMenuInfo(const FileMultiString& menupath,
233  bool allowroot,MenuInfo&) const;
234 
235 protected:
236 
239 
240  int nrItems(const FileMultiString& menupath) const;
241  bool greyOutsSkipped() const;
242  bool goingToChangeUiObj() const;
243 };
244 
245 
246 //====== Parsing macros =======================================================
247 
248 #define mParDQuoted( argnm, parstr, parnext, argstr, emptycheck, optional ) \
249 \
250  BufferString argstr; \
251  const char* parnext = StringProcessor(parstr).parseDQuoted( argstr ); \
252  if ( (!optional && !parnext) || (emptycheck && parnext && !*argstr) ) \
253  { \
254  mParseErrStrm << (parnext ? "Empty " : "No ") << argnm \
255  << " specified" << od_endl; \
256  return false; \
257  } \
258  if ( !parnext ) \
259  parnext = parstr;
260 
261 
262 #define mParDisambiguatorRet( argnm, str, selnr, retfld ) \
263  int selnr = StringProcessor(str).removeNumAppendix(); \
264  if ( mIsUdf(selnr) ) \
265  { \
266  mParseErrStrm << "Non-zero integer required to disambiguate " \
267  << argnm << ": \"" << str << "\"" << od_endl; \
268  return retfld; \
269  }
270 
271 #define mParDisambiguator( argnm, str, selnr ) \
272  mParDisambiguatorRet( argnm, str, selnr, false )
273 
274 
275 #define mParStrErrRet( objnm,nrfound,nrgrey,str,selnr,strnm,ambicheck,retfld ) \
276 \
277  const int overflow = (!selnr ? 1 : abs(selnr)) - nrfound; \
278 \
279  if ( overflow>0 || (!selnr && ambicheck && nrfound>1) ) \
280  { \
281  if ( nrfound && overflow>0 ) \
282  mWinErrStrm << "Impossible to select " << objnm << ": #" << selnr \
283  << od_endl; \
284 \
285  BufferString dispstr = str; \
286  dispstr.replace( "\a", "*" ); \
287  mWinErrStrm << "Found " << nrfound \
288  << (greyOutsSkipped() ? " enabled " : " ") << objnm \
289  << "(s) defined by " << strnm << ": \"" << dispstr \
290  << "\"" << od_endl; \
291 \
292  if ( greyOutsSkipped() && overflow>0 && overflow<=nrgrey ) \
293  mWinWarnStrm << "Did find " << nrgrey << " disabled " << objnm \
294  << "(s) defined by " << strnm << ": \"" << dispstr \
295  << "\"" << od_endl; \
296 \
297  return retfld; \
298  }
299 
300 #define mKeepSelection( objsfound, selnr ) \
301 { \
302  if ( selnr ) \
303  { \
304  const int selidx = selnr>0 ? selnr-1 : selnr+objsfound.size(); \
305  for ( int idx=objsfound.size()-1; idx>=0; idx-- ) \
306  { \
307  if ( idx != selidx ) \
308  objsfound.removeSingle( idx ); \
309  } \
310  } \
311 }
312 
313 #define mParStrPreRet(objnm,objsfound,nrgrey,str,selnr,strnm,ambicheck,retfld) \
314 { \
315  const int nrfound = objsfound.size(); \
316  mParStrErrRet( objnm,nrfound,nrgrey,str,selnr,strnm,ambicheck,retfld ) \
317  mKeepSelection( objsfound, selnr ); \
318 } \
319 
320 #define mParStrPre( objnm, objsfound, nrgrey, str, selnr, strnm, ambicheck ) \
321  mParStrPreRet(objnm, objsfound, nrgrey, str, selnr, strnm, ambicheck, false)
322 
323 
324 #define mDisabilityCheck( objnm, nrobjs, disabled ) \
325 \
326  if ( goingToChangeUiObj() && (disabled) ) \
327  { \
328  mWinErrStrm << (nrobjs>1 ? "Some s" : "S") << "elected " \
329  << objnm << (nrobjs>1 ? "s are" : " is") \
330  << " disabled for manipulation" << od_endl; \
331  return false; \
332  }
333 
334 
335 #define mParKeyStrInit( objnm, parstr, parnext, keys, selnr ) \
336 \
337  mParDQuoted(objnm " keystring", parstr, parnext, keys##str, false, false); \
338  mParDisambiguator( objnm " keystring", keys##str, selnr ); \
339  mGetEscConvertedFMS( keys, keys##str, false );
340 
341 #define mParKeyStrPre( objnm, objsfound, nrgrey, keys, selnr ) \
342  mParStrPre( objnm, objsfound, nrgrey, keys.buf(), selnr, "key(s)", true ); \
343  mDisabilityCheck( objnm, 1, !UIEntity(objsfound[0]).sensitive() ); \
344  ObjectFinder wcmobjfinder( *curWin(), isCaseSensitive(), &wildcardMan() ); \
345  wcmobjfinder.selectNodes( objsfound, keys );
346 
347 #define mParOptPathStrInit( objnm, parstr, parnext, path, optional ) \
348  mParDQuoted( objnm " path", parstr, parnext, path##str, false, optional ); \
349  mGetEscConvertedFMS( path, path##str, false );
350 
351 #define mParPathStrInit( objnm, parstr, parnext, path ) \
352  mParOptPathStrInit( objnm, parstr, parnext, path, false )
353 
354 #define mParWinStrInit( objnm, parstr, parnext, winstr, selnr, optional ) \
355  mParDQuoted( objnm " name", parstr, parnext, winstr, true, optional ); \
356  mParDisambiguator( objnm " name", winstr, selnr );
357 
358 
359 #define mParWinStrPre( windowlist, winstr, selnr, errorcheck ) \
360 \
361  ObjectSet<uiMainWin> windowlist; \
362  mSearchKey(winstr).getMatchingWindows( applWin(), windowlist ); \
363  if ( errorcheck ) \
364  { \
365  mParStrPre( "window", windowlist, 0, winstr, selnr, "string", true ) \
366  mSearchKey(winstr).getMatchingWindows( applWin(), windowlist, \
367  &wildcardMan() ); \
368  } \
369  else \
370  mKeepSelection( windowlist, selnr );
371 
372 // no selection at all: itemnr = mUdf(int)
373 // No selection number: itemnr = 0
374 // No item name: itemstr = "\a"
375 
376 #define mParItemSelInit( objnm, parstr, parnext, itemstr, itemnr, optional ) \
377 \
378  mParDQuoted( BufferString(objnm," name"), parstr, parnext, itemstr, \
379  false, true ); \
380  mParDisambiguator( BufferString(objnm," name"), itemstr, itemnr ); \
381  if ( parnext == parstr ) \
382  { \
383  const int num = strtol( parstr, const_cast<char**>(&parnext), 0 ); \
384 \
385  if ( num || (optional && parnext==parstr) ) \
386  { \
387  itemnr = !num ? mUdf(int) : num; \
388  itemstr = "\a"; \
389  } \
390  else \
391  { \
392  mParseErrStrm << "Name or non-zero integer needed to select " \
393  << objnm << od_endl; \
394  return false; \
395  } \
396  }
397 
398 
399 /* Internal onoff variables: on=1, off=-1, unspecified/unswitchable=0
400 
401  Beware this differs from the identifier value returned by any
402  'Is...On'-question command in scripts! (off=0, unswitchable=-1)
403 */
404 
405 #define mParOnOffInit( parstr, parnext, onoff ) \
406 \
407  BufferString onoffword; \
408  const char* parnext = getNextWord( parstr, onoffword.getCStr() ); \
409  mSkipBlanks( parnext ); \
410 \
411  int onoff = 0; \
412  if ( onoffword=="1" || mMatchCI(onoffword,"On") ) \
413  onoff = 1; \
414  if ( onoffword=="0" || mMatchCI(onoffword,"Off") ) \
415  onoff = -1; \
416  if ( !onoff ) \
417  parnext = parstr; \
418 
419 #define mParOnOffPre( objnm, onoff, checked, checkable ) \
420 { \
421  const bool ischeckable = (checkable); \
422  if ( onoff!=0 && !ischeckable ) \
423  { \
424  mWinWarnStrm << "This " << objnm << " has no on/off switch" \
425  << od_endl; \
426  onoff = 0; \
427  } \
428 \
429  const bool ischecked = (checked); \
430  if ( onoff == (ischecked ? 1 : -1) ) \
431  { \
432  mWinErrStrm << "This " << objnm << " was switched " \
433  << (onoff==1 ? "on" : "off") << " already" << od_endl; \
434  setRecoveryStep( CmdDriver::NextCmd ); \
435  return false; \
436  } \
437 }
438 
439 #define mParOnOffPost( objnm, onoff, checked ) \
440 { \
441  const bool ischecked = (checked); \
442  if ( onoff == (ischecked ? -1 : 1) ) \
443  { \
444  mWinWarnStrm << "Switching " << (onoff==1 ? "on" : "off") \
445  << " this " << objnm << " has been overruled" \
446  << od_endl; \
447  } \
448 }
449 
450 
451 #define mParInputStr( objnm, parstr, parnext, inpstr, optional ) \
452 \
453  BufferString filepathword; \
454  const char* extraparstr = getNextWord( parstr, filepathword.getCStr() ); \
455  mSkipBlanks( extraparstr ); \
456  if ( !mMatchCI(filepathword,"FilePath") ) \
457  extraparstr = parstr; \
458 \
459  mParDQuoted( objnm, extraparstr, parnext, inpbufstr, false, true ); \
460  if ( parnext == extraparstr ) \
461  { \
462  if ( extraparstr != parstr ) \
463  { \
464  mParseErrStrm << "FilePath-option expects double-quoted input " \
465  << "string" << od_endl; \
466  return false; \
467  } \
468  const double inpnum = strtod( parstr, const_cast<char**>(&parnext) ); \
469  inpbufstr = toString( inpnum ); \
470  } \
471  else \
472  { \
473  if ( extraparstr != parstr ) \
474  StringProcessor(inpbufstr).makeDirSepIndep(); \
475 \
476  StringProcessor(inpbufstr).removeCmdFileEscapes(); \
477  } \
478 \
479  const char* inpstr = parnext==parstr ? 0 : inpbufstr.buf(); \
480  if ( !optional && !inpstr ) \
481  { \
482  mParseErrStrm << "Double-quoted string or numeric argument " \
483  << "expected as input" << od_endl; \
484  return false; \
485  }
486 
487 
488 #define mParSteps( parstr, parnext, nrsteps, minval, defval ) \
489 \
490  char* parnext; \
491  int nrsteps = strtol( parstr, &parnext, 0 ); \
492  if ( parnext!=parstr && nrsteps<minval ) \
493  { \
494  mParseWarnStrm << "Number of steps should be at least " << minval \
495  << od_endl; \
496  } \
497  if ( parnext==parstr || nrsteps<minval ) \
498  nrsteps = defval;
499 
500 
501 #define mPopUpWinInLoopCheck( prevwin ) \
502 \
503  if ( openQDlg() || curWin()!=prevwin ) \
504  { \
505  mWinErrStrm << "Next step blocked by popped-up modal window" \
506  << od_endl; \
507  return false; \
508  }
509 
510 
511 #define mMatchMouseTag( tag, mousetagptr, clicktags ) \
512 \
513  if ( FixedString(mousetagptr).startsWith(tag) ) \
514  { \
515  clicktags.add( tag ); \
516  mousetagptr += strlen( tag ); \
517  }
518 
519 #define mParMouse( parstr, parnext, clicktags, defaulttag ) \
520 \
521  mSkipBlanks( parstr ); \
522  BufferStringSet clicktags; \
523  const char* parnext = parstr; \
524  mMatchMouseTag( "Ctrl", parnext, clicktags ); \
525  mMatchMouseTag( "Double", parnext, clicktags ); \
526 \
527  mMatchMouseTag( "Left", parnext, clicktags ) \
528  else mMatchMouseTag( "Right", parnext, clicktags ) \
529  else \
530  clicktags.add( clicktags.isEmpty() ? defaulttag : "Left" ); \
531 \
532  if ( *parnext && !iswspace(*parnext) ) \
533  parnext = parstr; \
534 
535 
536 #define mButtonCmdMouseTagCheck( clicktags ) \
537 \
538  if ( clicktags.isPresent("Right") || clicktags.isPresent("Double") ) \
539  { \
540  mParseWarnStrm << "Double or Right mouse-click has no (lasting) " \
541  << "effect on check-box" << od_endl; \
542  }
543 
544 
545 #define mParExpr( isarg, identnm, parstr, parnext, valstr, prescan ) \
546 \
547  BufferString valstr; \
548  const char* parnext = exprInterpreter().process( parstr, valstr, isarg ); \
549 \
550  if ( !parnext || (!(prescan) && *exprInterpreter().errMsg()) ) \
551  { \
552  mTimeStrm << "EVAL: " << exprInterpreter().breakPrefix(); \
553  mLogStrm << " ..." << od_endl; \
554  if ( exprInterpreter().isParseError() ) \
555  { \
556  mParseErrStrm << exprInterpreter().errMsg() << od_endl; \
557  } \
558  else \
559  mWinErrStrm << exprInterpreter().errMsg() << od_endl; \
560  \
561  return false; \
562  } \
563 \
564  if ( !(prescan) && ((isarg) || !exprInterpreter().isResultTrivial()) ) \
565  { \
566  mTimeStrm << "EVAL: " << exprInterpreter().parsedExpr(); \
567  StringProcessor strproc( valstr ); \
568  const char* quote = strproc.convertToDouble() ? "" : "\""; \
569  mLogStrm << " -->> " << identnm << (isarg ? "'" : "") \
570  << (FixedString(identnm).isEmpty() ? "" : " = " ) \
571  << quote << valstr << quote << od_endl; \
572  }
573 
574 #define mParIdentInit( parstr, parnext, identnm, allowdummy ) \
575 \
576  BufferString firstarg, identnm; \
577  const char* parnext = getNextWord( parstr, firstarg.getCStr() ); \
578  if ( firstarg != "_dummyvar" ) \
579  parnext = StringProcessor(parstr).parseIdentifier( identnm ); \
580  else if ( allowdummy ) \
581  identnm = firstarg; \
582  else \
583  { \
584  mParseErrStrm << "Missing identifier" << od_endl; \
585  return false; \
586  } \
587 \
588  if ( parnext && *parnext == '[' ) \
589  { \
590  mParseErrStrm << "If an array variable a[i] was intended, " \
591  << "use index substitution a_$i$ instead" << od_endl; \
592  return false; \
593  } \
594  if ( !parnext || firstarg!=identnm ) \
595  { \
596  mParseErrStrm << "Invalid identifier: " << firstarg << od_endl; \
597  return false; \
598  } \
599  if ( identifierMan().isPredefined(identnm) ) \
600  { \
601  mParseWarnStrm << "Reassigning a predefined identifier: " \
602  << identnm << od_endl; \
603  }
604 
605 #define mParEscIdentPost( identnm, val, args, addesc ) \
606 { \
607  mSkipBlanks( args ); \
608  identifierMan().set( identnm, val ); \
609  BufferString valstr = identifierMan().getValue( identnm ); \
610  StringProcessor strproc( valstr ); \
611  if ( addesc ) \
612  strproc.addCmdFileEscapes(StringProcessor::sAllEscSymbols()); \
613  \
614  identifierMan().set( identnm, strproc.buf() ); \
615  const char* quote = strproc.convertToDouble() ? "" : "\""; \
616  mTimeStrm << "Q&A: " << name() << (*args ? " " : "") << args \
617  << " -->> " << identnm << " = " << quote << strproc.buf() \
618  << quote << od_endl; \
619 }
620 
621 #define mParIdentPost( identnm, val, args ) \
622  mParEscIdentPost( identnm, val, args, true )
623 
624 
625 #define mParCase( parstr, parnext, casesensitive, optional ) \
626 \
627  BufferString argword; \
628  const char* parnext = getNextWord( parstr, argword.getCStr() ); \
629  bool casesensitive = false; \
630 \
631  if ( mMatchCI(argword,"Sensitive") ) \
632  casesensitive = true; \
633  else if ( !mMatchCI(argword,"Insensitive") ) \
634  { \
635  if ( !optional ) \
636  { \
637  mParseErrStrm << "Case-argument not in {Sensitive, Insensitive}" \
638  << od_endl; \
639  return false; \
640  } \
641  parnext = parstr; \
642  }
643 
644 #define mParExtraFormInit( parstr, parnext, form, extrastr ) \
645 \
646  BufferString formword; \
647  FileMultiString fms( extrastr ); \
648  const char* parnext = getNextWord( parstr, formword.getCStr() ); \
649  FormTag form = NoForm; \
650  if ( mMatchCI(formword,"Text") ) \
651  form = Text; \
652  if ( mMatchCI(formword,"Number") && fms.indexOf("Number")>=0 ) \
653  form = Number; \
654  if ( mMatchCI(formword,"Color") && fms.indexOf("Color")>=0 ) \
655  form = Colour; \
656  if ( mMatchCI(formword,"Value") && fms.indexOf("Value")>=0 ) \
657  form = Value; \
658  if ( mMatchCI(formword,"Angle") && fms.indexOf("Angle")>=0 ) \
659  form = Angle; \
660  if ( mMatchCI(formword,"Minimum") && fms.indexOf("Minimum")>=0 ) \
661  form = Minimum; \
662  if ( mMatchCI(formword,"Maximum") && fms.indexOf("Maximum")>=0 ) \
663  form = Maximum; \
664  if ( mMatchCI(formword,"Step") && fms.indexOf("Step")>=0 ) \
665  form = Step; \
666  if ( mMatchCI(formword,"Percentage") && fms.indexOf("Percentage")>=0 ) \
667  form = Percentage; \
668  if ( mMatchCI(formword,"FilePath") && fms.indexOf("FilePath")>=0 ) \
669  form = FilePath; \
670  if ( form == NoForm ) \
671  parnext = parstr;
672 
673 #define mParFormInit( parstr, parnext, form ) \
674  mParExtraFormInit( parstr, parnext, form, "Number" )
675 
676 #define mParForm( answer, form, text, other ) \
677 \
678  BufferString answer; \
679  if ( form==NoForm || form==Text ) \
680  { \
681  answer = text; \
682  StringProcessor(answer).cleanUp(); \
683  } \
684  else \
685  answer = other;
686 
687 #define mParExtraForm( answer, form, extratag, extra ) \
688 \
689  if ( form == extratag ) \
690  answer = extra;
691 
692 
693 #define mParFramed( parstr, parnext, framed ) \
694 \
695  BufferString frameword; \
696  const char* parnext = getNextWord( parstr, frameword.getCStr() ); \
697  bool framed = true; \
698  if ( mMatchCI(frameword,"Selected") ) \
699  framed = false; \
700  else if ( !mMatchCI(frameword,"Framed") ) \
701  parnext = parstr;
702 
703 
704 #define mParTail( partail ) \
705 \
706  mSkipBlanks( partail ); \
707  if ( (partail) && *(partail) ) \
708  { \
709  mParseErrStrm << "Command line ends with unexpected argument(s): " \
710  << (partail) << od_endl; \
711  return false; \
712  }
713 
714 
715 //====== MenuTracer macros ==================================================
716 
717 #define mFindMenuItem( menupath, startmenu, curitem ) \
718 \
719  const uiAction* curitem; \
720  if ( !MenuTracer(startmenu,drv_).findItem(menupath,curitem) ) \
721  return false;
722 
723 #define mGetMenuInfo( menupath, allowroot, startmenu, mnuinfo ) \
724 \
725  MenuInfo mnuinfo; \
726  if ( !MenuTracer(startmenu,drv_).getMenuInfo(menupath,allowroot,mnuinfo) ) \
727  return false;
728 
729 
730 //====== ObjectFinder macros ==================================================
731 
732 #define mFindObjs3Base( objsfound, objcls1, objcls2, objcls3, keys, warn ) \
733 \
734  ObjectSet<const CallBacker> objsfound; \
735 { \
736  ObjectFinder objfinder( *curWin(), isCaseSensitive() ); \
737  if ( localSearchEnv() ) \
738  objfinder.findNodes( localSearchEnv(), &objsfound ); \
739  else \
740  objfinder.findNodes( ObjectFinder::Everything, &objsfound ); \
741 \
742  for ( int idx=objsfound.size()-1; idx>=0; idx-- ) \
743  { \
744  mDynamicCastGet( const objcls1*, uiobj1, objsfound[idx] ); \
745  mDynamicCastGet( const objcls2*, uiobj2, objsfound[idx] ); \
746  mDynamicCastGet( const objcls3*, uiobj3, objsfound[idx] ); \
747  if ( !uiobj1 && !uiobj2 && !uiobj3 ) \
748  objsfound.removeSingle( idx ); \
749  } \
750 \
751  int errkeyidx; \
752  const bool dowarn = (warn); \
753  if ( !objfinder.selectNodes(objsfound, keys, &errkeyidx) && dowarn ) \
754  { \
755  mWinWarnStrm << "No object with key \"" << keys[errkeyidx] << "\" in " \
756  << ( localSearchEnv() ? "local search environment" \
757  : "current window" ) << od_endl; \
758  } \
759 }
760 
761 #define mFindObjs2Base( objsfound, objcls1, objcls2, keys, warn ) \
762  mFindObjs3Base( objsfound, objcls1, objcls1, objcls2, keys, warn )
763 
764 #define mFindObjsBase( objsfound, objclass, keys ) \
765  mFindObjs2Base( objsfound, objclass, objclass, keys, true )
766 
767 #define mFindObjects3( objsfound, objcls1, objcls2, objcls3, keys, nrgrey ) \
768  mFindObjs3Base( objsfound, objcls1, objcls2, objcls3, keys, true ); \
769  const int nrgrey = ObjectFinder::deleteGreys(objsfound, greyOutsSkipped());
770 
771 #define mFindObjects2( objsfound, objcls1, objcls2, keys, nrgrey ) \
772  mFindObjs2Base( objsfound, objcls1, objcls2, keys, true ); \
773  const int nrgrey = ObjectFinder::deleteGreys(objsfound, greyOutsSkipped());
774 
775 #define mFindObjects( objsfound, objclass, keys, nrgrey ) \
776  mFindObjsBase( objsfound, objclass, keys ); \
777  const int nrgrey = ObjectFinder::deleteGreys(objsfound, greyOutsSkipped());
778 
779 #define mFindListTableObjs( objnm, objsfound, objclass, keys, nrgrey ) \
780 \
781  mFindObjsBase( objsfound, objclass, keys ); \
782  mFindObjs2Base( objsfound2, objclass, uiTreeView, keys, false ); \
783  const bool uilviewonly = objsfound.isEmpty() && !objsfound2.isEmpty(); \
784  const bool uilviewcloser = !objsfound.isEmpty() && \
785  objsfound2.indexOf(objsfound[0])<0; \
786  if ( uilviewonly || uilviewcloser ) \
787  { \
788  mWinWarnStrm << "Skipped " << objsfound2.size() << " tree(s) " \
789  << (uilviewcloser ? "more closely" : "") \
790  << " defined by key(s): \"" << keys.buf() \
791  << "\". Possibly resembling a " << objnm \
792  << ", but requiring a \"Tree\"-command" << od_endl; \
793  } \
794  const int nrgrey = ObjectFinder::deleteGreys(objsfound, greyOutsSkipped());
795 
796 
797 //====== Activate macros ======================================================
798 
799 #define mActivateInGUIThread( cb, busywait ) \
800 { \
801  uiMainWin* applwin = applWin(); \
802  if ( applwin ) \
803  applwin->activateInGUIThread( cb, busywait ); \
804 }
805 
806 
807 #define mActInGUIThread( typ, constructorcall, waitclear ) \
808 { \
809  typ##Activator* activator = new typ##constructorcall; \
810  if ( prepareActivate(activator) ) \
811  { \
812  CallBack cb = mCB( activator, typ##Activator, actCB ); \
813  mActivateInGUIThread( cb, false ); \
814  finishActivate(); \
815 \
816  if ( waitclear ) \
817  waitForClearance(); \
818  } \
819  else \
820  delete activator; \
821 }
822 
823 
824 #define mActivate( acttyp, constructorcall ) \
825  mActInGUIThread( acttyp, constructorcall, true )
826 
827 #define mActivateNoClearance( acttyp, constructorcall ) \
828  mActInGUIThread( acttyp, constructorcall, false )
829 
830 
831 }; // namespace CmdDrive
832 
CmdDrive::MenuTracer::MenuTracer
MenuTracer(const uiActionContainer &mnu, CmdDriver &cmddrv)
Definition: command.h:225
CmdDrive::Command::finishActivate
void finishActivate()
CmdDrive::MenuTracer::goingToChangeUiObj
bool goingToChangeUiObj() const
uiMainWin
User interface main window.
Definition: uimainwin.h:35
CmdDrive::MenuTracer::greyOutsSkipped
bool greyOutsSkipped() const
CmdDrive::Command::act
virtual bool act(const char *parstr)=0
CmdDrive::Command::isQuestionName
static bool isQuestionName(const char *, CmdDriver &)
factory.h
uistring.h
CmdDrive::CmdDriver::Click
@ Click
Definition: cmddriver.h:152
CmdDrive::Command::setWait
void setWait(float time, bool regular)
CmdDrive::Command::interact
void interact(const InteractSpec *)
CmdDrive::CmdDriver
Definition: cmddriver.h:103
CmdDrive::MenuInfo
Definition: cmddriver.h:90
CmdDrive::Command::didInterceptSucceed
bool didInterceptSucceed(const char *objnm)
CmdDrive::MenuTracer::startmenu_
const uiActionContainer & startmenu_
Definition: command.h:238
mEndDeclCmdClass
#define mEndDeclCmdClass
Definition: command.h:151
CmdDrive::Command::mDefineFactory1ParamInClass
mDefineFactory1ParamInClass(Command, CmdDriver &, factory)
CmdDrive::Command::jump
void jump(int extralines=0)
CmdDrive::Command::setOnError
void setOnError(CmdDriver::OnErrorTag)
CmdDrive::Command::applWin
uiMainWin * applWin()
CmdDrive::ExprInterpreter
Definition: interpretexpr.h:24
CmdDrive::Command::waitForClearance
void waitForClearance()
mExpClass
#define mExpClass(module)
Definition: commondefs.h:177
FilePath
File pathname tools.
Definition: filepath.h:34
CmdDrive::CloseQDlgActivator::actretval_
int actretval_
Definition: command.h:215
identifierman.h
CmdDrive::Command::~Command
virtual ~Command()
Definition: command.h:45
FileMultiString
SeparString with backquotes as separators, use in most ascii files.
Definition: separstr.h:223
CmdDrive::Command::isUiObjChangeCommand
virtual bool isUiObjChangeCommand() const
Definition: command.h:53
CmdDrive::IdentifierManager
Definition: identifierman.h:23
CmdDrive::UiObjQuestionCmd::isLocalEnvCommand
virtual bool isLocalEnvCommand() const
Definition: command.h:163
CmdDrive::CloseQDlgActivator::CloseQDlgActivator
CloseQDlgActivator(int retval)
Definition: command.h:209
uimainwin.h
CmdDrive::MenuTracer::getMenuInfo
bool getMenuInfo(const FileMultiString &menupath, bool allowroot, MenuInfo &) const
CallBacker
Inherit from this class to be able to send and/or receive CallBacks.
Definition: callback.h:185
uiMainWin::closeActiveModalQDlg
static void closeActiveModalQDlg(int retval)
CmdDrive::Command::isLocalEnvCommand
virtual bool isLocalEnvCommand() const
Definition: command.h:51
CmdDrive::Command::end
void end()
CmdDrive::Activator::actCB
virtual void actCB(CallBacker *)=0
CmdDrive::Command::identifierMan
IdentifierManager & identifierMan()
CmdDrive::Command::prepareIntercept
void prepareIntercept(const FileMultiString &menupath, int onoff, CmdDriver::InterceptMode=CmdDriver::Click)
File::Text
@ Text
Definition: file.h:122
mStartDeclCmdClassNoActNoEntry
#define mStartDeclCmdClassNoActNoEntry(mod, cmdkey, parentclass)
Definition: command.h:121
CmdDrive::Command::isVisualCommand
virtual bool isVisualCommand() const
Definition: command.h:52
sKey::Maximum
FixedString Maximum()
Definition: keystrs.h:211
CmdDrive::Command::verifyWinAssert
bool verifyWinAssert(const char *newwinstr=0)
CmdDrive::NoState
@ NoState
Definition: cmddriver.h:99
CmdDrive::MenuTracer
Definition: command.h:223
CmdDrive::CloseQDlgActivator::actCB
void actCB(CallBacker *cb)
Definition: command.h:212
CmdDrive::Command::setCaseSensitive
void setCaseSensitive(bool yn)
CmdDrive::Command::verifyWinState
bool verifyWinState(const char *newwinstr=0, WinStateType newwinstate=NoState)
CmdDrive::CloseActivator::CloseActivator
CloseActivator(const uiMainWin &uimw)
Definition: command.h:196
CmdDrive::Command::outputDir
const char * outputDir() const
CmdDrive::Command::createFactoryKey
static BufferString createFactoryKey(const char *keyword)
CmdDrive::CloseActivator::actmainwin_
uiMainWin & actmainwin_
Definition: command.h:202
OD::JSON::Number
@ Number
Definition: odjson.h:40
objectfinder.h
CmdDrive::Command::interceptedMenuInfo
const MenuInfo & interceptedMenuInfo() const
CmdDrive::Command::openQDlg
bool openQDlg() const
uiActionContainer
Definition: uiaction.h:170
CmdDrive::MenuTracer::findItem
bool findItem(const FileMultiString &menupath, const uiAction *&curitem, int *curitmidx=0) const
CmdDrive::Activator::~Activator
virtual ~Activator()
Definition: command.h:188
CmdDrive::UiObjQuestionCmd::isVisualCommand
virtual bool isVisualCommand() const
Definition: command.h:164
CmdDrive::UiObjectCmd::isUiObjChangeCommand
virtual bool isUiObjChangeCommand() const
Definition: command.h:158
CmdDrive::CmdDriver::RecoveryTag
RecoveryTag
Definition: cmddriver.h:149
CmdDrive::Command::setRecoveryStep
void setRecoveryStep(CmdDriver::RecoveryTag)
Angle
Definition: angles.h:24
CmdDrive::Command::FormTag
FormTag
Definition: command.h:57
CmdDrive::CloseActivator::actCB
void actCB(CallBacker *cb)
Definition: command.h:199
CmdDrive::Command::drv_
CmdDriver & drv_
Definition: command.h:64
CmdDrive::UiObjectCmd::isLocalEnvCommand
virtual bool isLocalEnvCommand() const
Definition: command.h:157
CmdDrive::Command::factoryKey
static BufferString factoryKey(const char *name)
CmdDrive::InteractSpec
Definition: cmddriverbasics.h:197
CmdDrive::WinStateType
WinStateType
Definition: cmddriver.h:99
CmdDrive::Command::curWin
const uiMainWin * curWin() const
uidialog.h
CmdDrive::Command::isOpenQDlgCommand
virtual bool isOpenQDlgCommand() const
Definition: command.h:50
CmdDrive::MenuTracer::nrItems
int nrItems(const FileMultiString &menupath) const
CmdDrive::Command::Value
@ Value
Definition: command.h:57
CmdDrive::CmdDriver::InterceptMode
InterceptMode
Definition: cmddriver.h:152
CmdDrive::Command::setSleep
void setSleep(float time, bool regular)
CmdDrive::Command::isCaseSensitive
bool isCaseSensitive() const
uitreeview.h
CmdDrive::Command::prepareActivate
bool prepareActivate(Activator *)
BufferString
OD::String with its own variable length buffer. The buffer has a guaranteed minimum size.
Definition: bufstring.h:40
CmdDrive::Command::name
virtual const char * name() const =0
sKey::Minimum
FixedString Minimum()
Definition: keystrs.h:213
uiObject
The base class for most UI elements.
Definition: uiobj.h:38
CmdDrive::Command::Command
Command(CmdDriver &cmddrv)
Definition: command.h:42
CmdDrive::Command::Step
@ Step
Definition: command.h:58
CmdDrive
Command Drive
Definition: canvascommands.h:22
CmdDrive::CloseQDlgActivator
Definition: command.h:207
CmdDrive::CmdDriver::OnErrorTag
OnErrorTag
Definition: cmddriver.h:132
CmdDrive::Command::exprInterpreter
ExprInterpreter & exprInterpreter()
CmdDrive::Command::lastActionIdxMove
int lastActionIdxMove() const
CmdDrive::Command::goingToChangeUiObj
bool goingToChangeUiObj() const
CmdDrive::Command::skipGreyOuts
void skipGreyOuts(bool yn=true)
CmdDrive::Command::insertProcedure
bool insertProcedure(int defidx)
CmdDrive::Command::onError
CmdDriver::OnErrorTag onError() const
CmdDrive::Command
Definition: command.h:35
CmdDrive::Command::wildcardMan
WildcardManager & wildcardMan()
CmdDrive::Command::curActionIdx
int curActionIdx() const
CmdDrive::MenuTracer::drv_
CmdDriver & drv_
Definition: command.h:237
CmdDrive::Command::switchCurWin
bool switchCurWin(uiMainWin *)
timefun.h
CmdDrive::CloseActivator
Definition: command.h:194
CmdDrive::Command::tryAction
bool tryAction(const char *identname, const char *actstr)
CmdDrive::Command::doLocalAction
bool doLocalAction(uiObject *localenv, const char *actstr)
CmdDrive::WildcardManager
Definition: searchkey.h:57
cmddriver.h
CmdDrive::Activator
Definition: command.h:186
CmdDrive::Command::initStandardCommands
static void initStandardCommands()
CmdDrive::Command::localSearchEnv
const uiObject * localSearchEnv() const
CmdDrive::Command::greyOutsSkipped
bool greyOutsSkipped() const

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