SAGA API  v9.5
tool_interactive_base.cpp
Go to the documentation of this file.
1 
3 // //
4 // SAGA //
5 // //
6 // System for Automated Geoscientific Analyses //
7 // //
8 // Application Programming Interface //
9 // //
10 // Library: SAGA_API //
11 // //
12 //-------------------------------------------------------//
13 // //
14 // tool_interactive_base.cpp //
15 // //
16 // Copyright (C) 2005 by Olaf Conrad //
17 // //
18 //-------------------------------------------------------//
19 // //
20 // This file is part of 'SAGA - System for Automated //
21 // Geoscientific Analyses'. //
22 // //
23 // This library is free software; you can redistribute //
24 // it and/or modify it under the terms of the GNU Lesser //
25 // General Public License as published by the Free //
26 // Software Foundation, either version 2.1 of the //
27 // License, or (at your option) any later version. //
28 // //
29 // This library is distributed in the hope that it will //
30 // be useful, but WITHOUT ANY WARRANTY; without even the //
31 // implied warranty of MERCHANTABILITY or FITNESS FOR A //
32 // PARTICULAR PURPOSE. See the GNU Lesser General Public //
33 // License for more details. //
34 // //
35 // You should have received a copy of the GNU Lesser //
36 // General Public License along with this program; if //
37 // not, see <http://www.gnu.org/licenses/>. //
38 // //
39 //-------------------------------------------------------//
40 // //
41 // contact: Olaf Conrad //
42 // Institute of Geography //
43 // University of Goettingen //
44 // Goldschmidtstr. 5 //
45 // 37077 Goettingen //
46 // Germany //
47 // //
48 // e-mail: oconrad@saga-gis.org //
49 // //
51 
52 //---------------------------------------------------------
53 #include "tool.h"
54 
55 
57 // //
58 // //
59 // //
61 
62 //---------------------------------------------------------
63 #define ADD_MESSAGE_EXECUTION(Text, Style) { SG_UI_Msg_Add(Text, true, Style); if( m_pTool->has_GUI() ) { SG_UI_Msg_Add_Execution(Text, true, Style); } }
64 
65 #define ADD_MESSAGE_TIME(Start) { CSG_TimeSpan Time = CSG_DateTime::Now() - Start; CSG_String s;\
66  if( Time.Get_Hours () >= 1 ) { s = Time.Format("%Hh %Mm %Ss"); } else\
67  if( Time.Get_Minutes () >= 1 ) { s = Time.Format( "%Mm %Ss"); } else\
68  if( Time.Get_Seconds () >= 1 ) { s = Time.Format( "%Ss"); } else\
69  if( Time.Get_Milliseconds() >= 1 ) { s = Time.Format("%l ") + _TL("milliseconds"); } else { s = _TL("less than 1 millisecond"); }\
70  SG_UI_Msg_Add_Execution(CSG_String::Format("\n[%s] %s %s", m_pTool->Get_Name().c_str(), _TL("finished in"), s.c_str()), false);\
71 }
72 
73 
75 // //
76 // //
77 // //
79 
80 //---------------------------------------------------------
82 {
83  m_pTool = NULL;
84 
85  m_Keys = 0;
86  m_Drag_Mode = TOOL_INTERACTIVE_DRAG_BOX;
87 
88  m_Point .Assign(0., 0.);
89  m_Point_Last.Assign(0., 0.);
90 }
91 
92 //---------------------------------------------------------
94 {}
95 
96 
98 // //
100 
101 //---------------------------------------------------------
103 {
104  return( m_Projection.Create(Projection) );
105 }
106 
107 //---------------------------------------------------------
109 {
110  if( !m_pTool || m_pTool->m_bExecutes )
111  {
112  return( false );
113  }
114 
115  m_pTool->m_bError_Ignore = false;
116  m_pTool->m_bExecutes = true;
117  m_Point_Last = m_Point;
118  m_Point = ptWorld;
119  m_Keys = Keys;
120 
121  CSG_DateTime Started(CSG_DateTime::Now());
122  bool bResult = On_Execute_Position(m_Point, Mode);
123  if( bResult ) ADD_MESSAGE_TIME(Started);
124 
125  m_Keys = 0;
126  m_pTool->m_bExecutes = false;
127 
128  m_pTool->_Synchronize_DataObjects();
129 
131 
132  return( bResult );
133 }
134 
136 {
137  return( false );
138 }
139 
140 //---------------------------------------------------------
141 bool CSG_Tool_Interactive_Base::Execute_Keyboard(int Character, int Keys)
142 {
143  if( !m_pTool || m_pTool->m_bExecutes )
144  {
145  return( false );
146  }
147 
148  m_pTool->m_bError_Ignore = false;
149  m_pTool->m_bExecutes = true;
150  m_Keys = Keys;
151 
152  CSG_DateTime Started(CSG_DateTime::Now());
153  bool bResult = On_Execute_Keyboard(Character);
154  if( bResult ) ADD_MESSAGE_TIME(Started);
155 
156  m_Keys = 0;
157  m_pTool->m_bExecutes = false;
158 
159  m_pTool->_Synchronize_DataObjects();
160 
162 
163  return( bResult );
164 }
165 
167 {
168  return( false );
169 }
170 
171 //---------------------------------------------------------
173 {
174  if( !m_pTool || m_pTool->m_bExecutes )
175  {
176  return( false );
177  }
178 
179  m_pTool->m_bError_Ignore = false;
180  m_pTool->m_bExecutes = true;
181 
182  CSG_DateTime Started(CSG_DateTime::Now());
183  bool bResult = On_Execute_Finish();
184  if( bResult ) ADD_MESSAGE_TIME(Started);
185 
186  m_pTool->m_bExecutes = false;
187 
188  m_pTool->_Synchronize_DataObjects();
189 
191 
192  ADD_MESSAGE_EXECUTION(CSG_String::Format("[%s] %s", m_pTool->Get_Name().c_str(), bResult
193  ? _TL("Interactive tool execution has been stopped")
194  : _TL("Interactive tool execution failed")),
196  );
197 
198  return( bResult );
199 }
200 
202 {
203  return( true );
204 }
205 
206 
208 // //
210 
211 //---------------------------------------------------------
213 {
214  m_Drag_Mode = Drag_Mode;
215 }
216 
217 
219 // //
220 // //
221 // //
223 
224 //---------------------------------------------------------
CSG_Tool_Interactive_Base::CSG_Tool_Interactive_Base
CSG_Tool_Interactive_Base(void)
Definition: tool_interactive_base.cpp:81
ADD_MESSAGE_TIME
#define ADD_MESSAGE_TIME(Start)
Definition: tool_interactive_base.cpp:65
ADD_MESSAGE_EXECUTION
#define ADD_MESSAGE_EXECUTION(Text, Style)
Definition: tool_interactive_base.cpp:63
_TL
#define _TL(s)
Definition: api_core.h:1489
CSG_Tool_Interactive_Base::On_Execute_Keyboard
virtual bool On_Execute_Keyboard(int Character)
Definition: tool_interactive_base.cpp:166
CSG_DateTime::Now
static CSG_DateTime Now(void)
Definition: datetime.cpp:581
CSG_Tool_Interactive_Base::On_Execute_Finish
virtual bool On_Execute_Finish(void)
Definition: tool_interactive_base.cpp:201
SG_UI_MSG_STYLE_SUCCESS
@ SG_UI_MSG_STYLE_SUCCESS
Definition: api_core.h:1505
CSG_Tool_Interactive_Base::~CSG_Tool_Interactive_Base
virtual ~CSG_Tool_Interactive_Base(void)
Definition: tool_interactive_base.cpp:93
SG_UI_Process_Set_Okay
bool SG_UI_Process_Set_Okay(bool bOkay)
Definition: api_callback.cpp:230
CSG_Tool_Interactive_Base::Execute_Position
bool Execute_Position(CSG_Point ptWorld, TSG_Tool_Interactive_Mode Mode, int Keys)
Definition: tool_interactive_base.cpp:108
CSG_Tool::Get_Name
const CSG_String & Get_Name(void) const
Definition: tool.cpp:132
CSG_Tool_Interactive_Base::Execute_Keyboard
bool Execute_Keyboard(int Character, int Keys)
Definition: tool_interactive_base.cpp:141
TSG_Tool_Interactive_Mode
TSG_Tool_Interactive_Mode
Definition: tool.h:457
tool.h
SG_UI_MSG_STYLE_FAILURE
@ SG_UI_MSG_STYLE_FAILURE
Definition: api_core.h:1506
CSG_Tool_Interactive_Base::Execute_Finish
bool Execute_Finish(void)
Definition: tool_interactive_base.cpp:172
CSG_Point
Definition: geo_tools.h:135
CSG_Tool_Interactive_Base::Set_Drag_Mode
void Set_Drag_Mode(int Drag_Mode)
Definition: tool_interactive_base.cpp:212
CSG_Tool_Interactive_Base::Set_Projection
bool Set_Projection(const CSG_Projection &Projection)
Definition: tool_interactive_base.cpp:102
CSG_Point::Assign
virtual void Assign(double x, double y)
Definition: geo_classes.cpp:86
CSG_DateTime
Definition: datetime.h:183
CSG_String::Format
static CSG_String Format(const char *Format,...)
Definition: api_string.cpp:270
CSG_Projection
Definition: geo_tools.h:824
TOOL_INTERACTIVE_DRAG_BOX
@ TOOL_INTERACTIVE_DRAG_BOX
Definition: tool.h:480
CSG_String::c_str
const SG_Char * c_str(void) const
Definition: api_string.cpp:236
SG_UI_Process_Set_Ready
bool SG_UI_Process_Set_Ready(void)
Definition: api_callback.cpp:306
CSG_Projection::Create
bool Create(const CSG_Projection &Projection)
Definition: projections.cpp:96
CSG_Tool_Interactive_Base::On_Execute_Position
virtual bool On_Execute_Position(CSG_Point ptWorld, TSG_Tool_Interactive_Mode Mode)
Definition: tool_interactive_base.cpp:135