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

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