Version: 0.6.0
core.h
1 /******************************************************************************
2  * Project: wxGIS (GIS)
3  * Purpose: core header.
4  * Author: Dmitry Baryshnikov (aka Bishop), polimax@mail.ru
5  ******************************************************************************
6 * Copyright (C) 2009-2012,2014 Dmitry Baryshnikov
7 *
8 * This program is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20  ****************************************************************************/
21 #pragma once
22 
23 #include "wxgis/base.h"
24 
25 #define wgDELETE(p,func) if(p != NULL) {p->func; delete p; p = NULL;}
26 #define wsDELETE(p) if(p != NULL) {p->Release(); p = NULL;}
27 #define wsSET(mp, p) if(p != NULL) { mp = p; mp->Reference();}else{mp = NULL;}
28 #define wsGET(p) if(p != NULL){p->Reference(); return p;} else{return NULL;}
29 #define RtlZeroMemory(Destination,Length) memset((Destination),0,(Length))
30 
31 #define __YEAR__ ((((__DATE__ [7] - '0') * 10 + (__DATE__ [8] - '0')) * 10 \
32 + (__DATE__ [9] - '0')) * 10 + (__DATE__ [10] - '0'))
33 
34 #define VENDOR wxT("wxgis")
35 
43 enum wxGISEnumConfigKey
44 {
45  enumGISHKLM = 0x0001,
46  enumGISHKCU = 0x0002,
47  //,
48  //enumGISHKCC = 0x0004,
49  //enumGISHKCR = 0x0008,
50  enumGISHKAny = enumGISHKLM | enumGISHKCU
51 };
52 
60 enum wxGISEnumMessageType
61 {
62  enumGISMessageUnk = 0,
63  enumGISMessageErr,
64  enumGISMessageNorm,
65  enumGISMessageQuestion,
66  enumGISMessageInfo,
67  enumGISMessageWarning,
68  enumGISMessageTitle,
69  enumGISMessageOK,
70  enumGISMessageSend,
71  enumGISMessageReceive
72 };
73 
74 typedef struct _message
75 {
76  wxGISEnumMessageType eType;
77  wxString sMessage;
78 } MESSAGE;
79 
87 {
88 public:
92  virtual ~IProgressor(void){};
93  //pure virtual
99  virtual bool ShowProgress(bool bShow) = 0;
100  //
105  virtual void SetRange(int range) = 0;
110  virtual int GetRange(void) const = 0;
115  virtual void SetValue(int value) = 0;
120  virtual int GetValue(void) const = 0;
121  //
125  virtual void Play(void) = 0;
129  virtual void Stop(void) = 0;
135  virtual void SetYield(bool bYield = false) = 0;
136 };
137 
145 {
146 public:
150  ITrackCancel(void) : m_bIsCanceled(false), m_pProgressor(NULL){};
154  virtual ~ITrackCancel(void){};
155  virtual void Cancel(void)
156  {
157  m_bIsCanceled = true;
158  };
159  virtual bool Continue(void){return !m_bIsCanceled;};
160  virtual void Reset(void){m_bIsCanceled = false;};
161  virtual IProgressor* const GetProgressor(void){return m_pProgressor;};
162  virtual void SetProgressor(IProgressor* pProgressor){m_pProgressor = pProgressor; };
163  virtual void PutMessage(const wxString &sMessage, size_t nIndex, wxGISEnumMessageType eType){};
164  virtual wxString GetLastMessage(void){return wxEmptyString;};
165 protected:
166  bool m_bIsCanceled;
167  IProgressor* m_pProgressor;
168 };
169 
170 static bool CreateAndRunThread(wxThread* const pThread, wxString sClassName = wxEmptyString, const wxString sThreadName = wxEmptyString, int nPriority = WXTHREAD_DEFAULT_PRIORITY)
171 {
172  wxCHECK_MSG(pThread, false, wxT("Input wxThread pointer is null"));
173 
174  if(sClassName.IsEmpty())
175  sClassName = wxString(_("wxGISCore"));
176  if ( pThread->Create() != wxTHREAD_NO_ERROR )
177  {
178  wxLogError(_("%s: Can't create %s Thread!"), sClassName.c_str(), sThreadName.c_str());
179  return false;
180  }
181  pThread->SetPriority(nPriority);
182  if(pThread->Run() != wxTHREAD_NO_ERROR )
183  {
184  wxLogError(_("%s: Can't run %s Thread!"), sClassName.c_str(), sThreadName.c_str());
185  return false;
186  }
187  return true;
188 }
189 
196 enum wxGISEnumTaskStateType
197 {
198  enumGISTaskUnk = 0,
199  enumGISTaskWork,
200  enumGISTaskDone,
201  enumGISTaskQuered,
202  enumGISTaskPaused,
203  enumGISTaskError
204 };
205 
212 enum wxGISEnumReturnType
213 {
214  enumGISReturnkUnk = 0,
215  enumGISReturnOk,
216  enumGISReturnFailed,
217  enumGISReturnTimeout
218 };
219 
220 //FLT_EPSILON DBL_EPSILON
221 inline bool IsDoubleEquil( double a, double b, double epsilon = EPSILON )
222 {
223  const double diff = a - b;
224  return diff > -epsilon && diff <= epsilon;
225 }
226 
virtual ~IProgressor(void)
A destructor.
Definition: core.h:92
virtual void Stop(void)=0
Stop undefined progressor state.
virtual void SetValue(int value)=0
Set progressor position.
virtual void SetYield(bool bYield=false)=0
SetYield Yields control to pending messages in the windowing system.
virtual ~ITrackCancel(void)
A destructor.
Definition: core.h:154
A TrackCancel interface class.
Definition: core.h:144
Definition: core.h:74
virtual bool ShowProgress(bool bShow)=0
Show/hide progressor.
Definition: core.h:92
ITrackCancel(void)
A constructor.
Definition: core.h:150
virtual void SetRange(int range)=0
Set progressor range.
virtual void Play(void)=0
Start undefined progressor state.
Definition: core.h:86
virtual int GetRange(void) const =0
Set progressor range.
virtual int GetValue(void) const =0
Get progressor position.