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

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