SAGA API v9.10
Loading...
Searching...
No Matches
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//---------------------------------------------------------
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
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
139
140//---------------------------------------------------------
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
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
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//---------------------------------------------------------
bool SG_UI_Process_Set_Ready(void)
bool SG_UI_Process_Set_Okay(bool bOkay)
@ SG_UI_MSG_STYLE_FAILURE
Definition api_core.h:1585
@ SG_UI_MSG_STYLE_SUCCESS
Definition api_core.h:1584
#define _TL(s)
Definition api_core.h:1568
static CSG_DateTime Now(void)
Definition datetime.cpp:585
static CSG_String Format(const char *Format,...)
virtual bool On_Execute_Position(CSG_Point ptWorld, TSG_Tool_Interactive_Mode Mode)
bool Set_Projection(const CSG_Projection &Projection)
bool Execute_Keyboard(int Character, int Keys)
bool Execute_Position(CSG_Point ptWorld, TSG_Tool_Interactive_Mode Mode, int Keys)
virtual bool On_Execute_Keyboard(int Character)
#define ADD_MESSAGE_EXECUTION(Text, Style)
@ TOOL_INTERACTIVE_DRAG_BOX
Definition tool.h:496
TSG_Tool_Interactive_Mode
Definition tool.h:473
#define ADD_MESSAGE_TIME(Start)