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

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