1
2 ///////////////////////////////////////////////////////////
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 // //
50 ///////////////////////////////////////////////////////////
51
52 //---------------------------------------------------------
53 #include "tool.h"
54
55
56 ///////////////////////////////////////////////////////////
57 // //
58 // //
59 // //
60 ///////////////////////////////////////////////////////////
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
74 ///////////////////////////////////////////////////////////
75 // //
76 // //
77 // //
78 ///////////////////////////////////////////////////////////
79
80 //---------------------------------------------------------
CSG_Tool_Interactive_Base(void)81 CSG_Tool_Interactive_Base::CSG_Tool_Interactive_Base(void)
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 //---------------------------------------------------------
~CSG_Tool_Interactive_Base(void)93 CSG_Tool_Interactive_Base::~CSG_Tool_Interactive_Base(void)
94 {}
95
96
97 ///////////////////////////////////////////////////////////
98 // //
99 ///////////////////////////////////////////////////////////
100
101 //---------------------------------------------------------
Execute_Position(CSG_Point ptWorld,TSG_Tool_Interactive_Mode Mode,int Keys)102 bool CSG_Tool_Interactive_Base::Execute_Position(CSG_Point ptWorld, TSG_Tool_Interactive_Mode Mode, int Keys)
103 {
104 if( !m_pTool || m_pTool->m_bExecutes )
105 {
106 return( false );
107 }
108
109 m_pTool->m_bError_Ignore = false;
110 m_pTool->m_bExecutes = true;
111 m_Point_Last = m_Point;
112 m_Point = ptWorld;
113 m_Keys = Keys;
114
115 CSG_DateTime Started(CSG_DateTime::Now());
116 bool bResult = On_Execute_Position(m_Point, Mode);
117 if( bResult ) ADD_MESSAGE_TIME(Started);
118
119 m_Keys = 0;
120 m_pTool->m_bExecutes = false;
121
122 m_pTool->_Synchronize_DataObjects();
123
124 SG_UI_Process_Set_Okay(); SG_UI_Process_Set_Ready();
125
126 return( bResult );
127 }
128
On_Execute_Position(CSG_Point ptWorld,TSG_Tool_Interactive_Mode Mode)129 bool CSG_Tool_Interactive_Base::On_Execute_Position(CSG_Point ptWorld, TSG_Tool_Interactive_Mode Mode)
130 {
131 return( false );
132 }
133
134 //---------------------------------------------------------
Execute_Keyboard(int Character,int Keys)135 bool CSG_Tool_Interactive_Base::Execute_Keyboard(int Character, int Keys)
136 {
137 if( !m_pTool || m_pTool->m_bExecutes )
138 {
139 return( false );
140 }
141
142 m_pTool->m_bError_Ignore = false;
143 m_pTool->m_bExecutes = true;
144 m_Keys = Keys;
145
146 CSG_DateTime Started(CSG_DateTime::Now());
147 bool bResult = On_Execute_Keyboard(Character);
148 if( bResult ) ADD_MESSAGE_TIME(Started);
149
150 m_Keys = 0;
151 m_pTool->m_bExecutes = false;
152
153 m_pTool->_Synchronize_DataObjects();
154
155 SG_UI_Process_Set_Okay(); SG_UI_Process_Set_Ready();
156
157 return( bResult );
158 }
159
On_Execute_Keyboard(int Character)160 bool CSG_Tool_Interactive_Base::On_Execute_Keyboard(int Character)
161 {
162 return( false );
163 }
164
165 //---------------------------------------------------------
Execute_Finish(void)166 bool CSG_Tool_Interactive_Base::Execute_Finish(void)
167 {
168 if( !m_pTool || m_pTool->m_bExecutes )
169 {
170 return( false );
171 }
172
173 m_pTool->m_bError_Ignore = false;
174 m_pTool->m_bExecutes = true;
175
176 CSG_DateTime Started(CSG_DateTime::Now());
177 bool bResult = On_Execute_Finish();
178 if( bResult ) ADD_MESSAGE_TIME(Started);
179
180 m_pTool->m_bExecutes = false;
181
182 m_pTool->_Synchronize_DataObjects();
183
184 SG_UI_Process_Set_Okay(); SG_UI_Process_Set_Ready();
185
186 ADD_MESSAGE_EXECUTION(CSG_String::Format("[%s] %s", m_pTool->Get_Name().c_str(), bResult
187 ? _TL("Interactive tool execution has been stopped")
188 : _TL("Interactive tool execution failed")),
189 bResult ? SG_UI_MSG_STYLE_SUCCESS : SG_UI_MSG_STYLE_FAILURE
190 );
191
192 return( bResult );
193 }
194
On_Execute_Finish(void)195 bool CSG_Tool_Interactive_Base::On_Execute_Finish(void)
196 {
197 return( true );
198 }
199
200
201 ///////////////////////////////////////////////////////////
202 // //
203 ///////////////////////////////////////////////////////////
204
205 //---------------------------------------------------------
Set_Drag_Mode(int Drag_Mode)206 void CSG_Tool_Interactive_Base::Set_Drag_Mode(int Drag_Mode)
207 {
208 m_Drag_Mode = Drag_Mode;
209 }
210
211
212 ///////////////////////////////////////////////////////////
213 // //
214 // //
215 // //
216 ///////////////////////////////////////////////////////////
217
218 //---------------------------------------------------------
219