OpendTect  6.3
cmdcomposer.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: March 2009
9 ________________________________________________________________________
10 
11 -*/
12 
13 #include "uicmddrivermod.h"
14 #include "callback.h"
15 #include "bufstringset.h"
16 #include "factory.h"
17 
18 class uiMainWin;
19 
20 
21 namespace CmdDrive
22 {
23 
24 class CmdRecorder;
25 class CmdRecEvent;
26 
27 
28 mExpClass(uiCmdDriver) Classifier
29 {
30 public:
31  virtual ~Classifier() {}
32  virtual const char* name() const = 0;
33  virtual bool approved(const CallBacker*) const = 0;
34 };
35 
36 #define mDeclClassifierClass(callerclass) \
37 \
38 class callerclass##Classifier : public Classifier \
39 { \
40 public: \
41 \
42  static const char* className() { return #callerclass; } \
43  const char* name() const { return className(); } \
44 \
45  bool approved(const CallBacker* caller) const \
46  { return dynamic_cast<const callerclass*>(caller); } \
47 };
48 
49 
50 mExpClass(uiCmdDriver) CmdComposer : public CallBacker
52 public:
53 
55  static void initStandardComposers();
56  static BufferString factoryKey(const CallBacker* caller,
57  const char* extrakey=0);
58 
60  ~CmdComposer();
61 
62  virtual const char* name() = 0;
63 
64  virtual bool greedy() const;
65  virtual bool accept(const CmdRecEvent&);
66  virtual void updateInternalState() {};
67  virtual bool tryToFinish();
68  bool stateUpdateNeeded() { return updateflag_; }
69  bool done() const { return done_; }
70 
71  bool traceSrcWin(CmdRecEvent&) const;
72 
73  void objClosed(CallBacker*) { objclosed_ = true; }
74  void testCB(CallBacker*);
75 
76 protected:
77 
78  static BufferString createFactoryKey(const Classifier*,const char* keyword);
79 
80  virtual void init() {};
81 
82  const uiMainWin* applWin() const;
83 
84  void addToEventList(const CmdRecEvent&);
85  void shrinkEventList(int firstnr=1, int lastnr=-1);
86  int eventNameIdx(const BufferStringSet& eventnames,
87  const CmdRecEvent&) const;
88 
89  void insertWindowCaseExec(const CmdRecEvent&,
90  bool casedep = false) const;
91 
92  void srcWinClosed(CallBacker*);
93 
94  void notDone() { done_ = false; }
95  void refuseAndQuitDone() { done_ = true; }
96 
98 
100  bool quitflag_;
102 
106 
108 
111 
112 private:
113  bool done_;
114 };
115 
116 
117 #define mStartDeclComposerClassNoAccept(mod,cmdkey,parentclass) \
118 \
119 mExpClass(mod) cmdkey##CmdComposer : public parentclass \
120 { \
121 public: \
122  cmdkey##CmdComposer(CmdRecorder& cmdrec) \
123  : parentclass(cmdrec) \
124  { init(); } \
125 \
126  static const char* keyWord() { return #cmdkey; } \
127  virtual const char* name() { return keyWord(); } \
128 
129 #define mStartDeclComposerClass(mod,cmdkey,parentclass,callerclass) \
130 \
131  mStartDeclComposerClassNoAccept(mod,cmdkey,parentclass) \
132  mDeclClassifierClass(callerclass) \
133 \
134  virtual bool accept(const CmdRecEvent&); \
135 \
136  static CmdComposer* createInstance(CmdRecorder& cmdrec) \
137  { return new cmdkey##CmdComposer(cmdrec); } \
138  static void initClass() \
139  { factory().addCreator( createInstance, \
140  createFactoryKey(new callerclass##Classifier(), \
141  keyWord()) ); }
142 
143 #define mStartDeclComposerClassWithInit(mod,cmdkey,parentclass,callerclass) \
144  mStartDeclComposerClass(mod,cmdkey,parentclass,callerclass) \
145  virtual void init();
146 
147 #define mEndDeclComposerClass \
148 };
149 
150 
151 //====== CmdComposer macros ==================================================
152 
153 
154 #define mRefuseAndQuit() \
155 { \
156  quitflag_ = true; \
157  if ( stackwasempty_ ) \
158  refuseAndQuitDone(); \
159 \
160  return false; \
161 }
162 
163 
164 #define mCompleteAndQuitIfEventNested( ev, notifierstr ) \
165 \
166  if ( quitflag_ ) \
167  return true; \
168  else if ( ev.begin_ && !stackwasempty_ && \
169  stringEndsWithCI(notifierstr,ev.msg_) ) \
170  { \
171  ignoreflag_ = false; \
172  quitflag_ = true; \
173  }
174 
175 
176 #define mNotifyTest( objclass, uiobject, notifiername ) \
177 { \
178  mDynamicCastGet( objclass*, uiclassobj, uiobject ); \
179  if ( uiclassobj ) \
180  uiclassobj->notifiername.notify( mCB(this,CmdComposer,testCB) ); \
181 }
182 
183 
184 #define mGetInputString( inpptr, txt, haschanged ) \
185 \
186  BufferString inpstr; \
187  char* inpptr = inpstr.getCStr(); \
188  if ( haschanged ) \
189  { \
190  inpstr = " "; inpstr += txt; \
191  mSkipBlanks( inpptr ); \
192  char* endptr; \
193  strtod( inpptr, &endptr ); \
194  const char* nextword = endptr; \
195  mSkipBlanks( nextword ); \
196  if ( inpptr!=endptr && !*nextword ) \
197  { \
198  *endptr = '\0'; \
199  inpstr += " "; \
200  } \
201  else \
202  { \
203  mDressUserInputString( inpstr, sInputStr ); \
204  IdentifierManager().tryFilePathPlaceholders( inpstr ); \
205  inpstr += "\" "; \
206  inpptr = inpstr.getCStr(); \
207  *inpptr = '"'; \
208  } \
209  }
210 
211 #define mWriteInputCmd( haschanged, txt, enter ) \
212 { \
213  mGetInputString( inpptr, txt, haschanged ); \
214  if ( haschanged || enter ) \
215  { \
216  insertWindowCaseExec( *eventlist_[0] ); \
217  mRecOutStrm << "Input \"" << eventlist_[0]->keystr_ << "\" " \
218  << inpptr << (enter ? "Enter" : "Hold") << od_endl; \
219  } \
220 }
221 
222 
223 #define mGetItemName( uiobj,sizefunc,textfunc,curitemidx,curitemname,casedep ) \
224 \
225  BufferString curitemname = uiobj->textfunc( curitemidx ); \
226  mDressNameString( curitemname, sItemName ); \
227  bool casedep = false; \
228  { \
229  int nrmatches = 0; \
230  int selnr = 0; \
231 \
232  for ( int itmidx=0; itmidx<uiobj->sizefunc(); itmidx++ ) \
233  { \
234  const char* itmtxt = uiobj->textfunc( itmidx ); \
235  if ( SearchKey(curitemname,false).isMatching(itmtxt) ) \
236  { \
237  if ( SearchKey(curitemname,true).isMatching(itmtxt) ) \
238  { \
239  nrmatches++; \
240  if ( itmidx == curitemidx ) \
241  selnr = nrmatches; \
242  } \
243  else \
244  casedep = true; \
245  } \
246  } \
247 \
248  if ( selnr && nrmatches>1 ) \
249  { \
250  curitemname += "#"; curitemname += selnr; \
251  } \
252  }
253 
254 
255 }; // namespace CmdDrive
#define mExpClass(module)
Definition: commondefs.h:157
User interface main window.
Definition: uimainwin.h:34
bool updateflag_
Definition: cmdcomposer.h:101
Inherit from this class to be able to send and/or receive CallBacks.
Definition: callback.h:182
Command Drive
Definition: canvascommands.h:20
virtual void updateInternalState()
Definition: cmdcomposer.h:66
#define mODTextTranslationClass(clss)
Definition: uistring.h:37
void objClosed(CallBacker *)
Definition: cmdcomposer.h:73
bool done() const
Definition: cmdcomposer.h:69
BufferStringSet bursteventnames_
Definition: cmdcomposer.h:109
Set of BufferString objects.
Definition: bufstringset.h:25
BufferStringSet voideventnames_
Definition: cmdcomposer.h:110
bool ignoreflag_
Definition: cmdcomposer.h:99
#define mDefineFactory1ParamInClass(T, P, funcname)
Definition: factory.h:445
Definition: cmdrecorder.h:69
Set of pointers to objects.
Definition: commontypes.h:28
TypeSet< int > refnrstack_
Definition: cmdcomposer.h:103
bool objclosed_
Definition: cmdcomposer.h:105
Definition: cmdcomposer.h:28
Definition: cmdrecorder.h:33
bool stateUpdateNeeded()
Definition: cmdcomposer.h:68
Definition: cmdcomposer.h:50
bool quitflag_
Definition: cmdcomposer.h:100
CmdRecorder & rec_
Definition: cmdcomposer.h:97
virtual ~Classifier()
Definition: cmdcomposer.h:31
OD::String with its own variable length buffer. The buffer has a guaranteed minimum size...
Definition: bufstring.h:38
void notDone()
Definition: cmdcomposer.h:94
virtual void init()
Definition: cmdcomposer.h:80
void refuseAndQuitDone()
Definition: cmdcomposer.h:95
bool done_
Definition: cmdcomposer.h:113
ObjectSet< CmdRecEvent > eventlist_
Definition: cmdcomposer.h:107
bool stackwasempty_
Definition: cmdcomposer.h:104

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