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

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