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.h                         //
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 #ifndef HEADER_INCLUDED__SAGA_API__tool_H
54 #define HEADER_INCLUDED__SAGA_API__tool_H
55 
56 
57 ///////////////////////////////////////////////////////////
58 //														 //
59 //														 //
60 //														 //
61 ///////////////////////////////////////////////////////////
62 
63 //---------------------------------------------------------
64 /** \file tool.h
65 * The definition of the base classes for any SAGA tool.
66 * @see CSG_Tool
67 * @see CSG_Tool_Grid
68 * @see CSG_Tool_Interactive
69 * @see CSG_Tool_Library
70 * @see CSG_Tool_Library_Manager
71 */
72 
73 
74 ///////////////////////////////////////////////////////////
75 //														 //
76 //														 //
77 //														 //
78 ///////////////////////////////////////////////////////////
79 
80 //---------------------------------------------------------
81 #include "parameters.h"
82 
83 
84 ///////////////////////////////////////////////////////////
85 //														 //
86 //														 //
87 //														 //
88 ///////////////////////////////////////////////////////////
89 
90 //---------------------------------------------------------
91 typedef enum ESG_Summary_Format
92 {
93 	SG_SUMMARY_FMT_FLAT		= 0,
94 	SG_SUMMARY_FMT_HTML,
95 	SG_SUMMARY_FMT_XML
96 }
97 TSG_Summary_Format;
98 
99 //---------------------------------------------------------
100 typedef enum ESG_Tool_Type
101 {
102 	TOOL_TYPE_Base			= 0,
103 	TOOL_TYPE_Interactive,
104 	TOOL_TYPE_Grid,
105 	TOOL_TYPE_Grid_Interactive,
106 	TOOL_TYPE_Chain
107 }
108 TSG_Tool_Type;
109 
110 //---------------------------------------------------------
111 typedef enum ESG_Tool_Error
112 {
113 	TOOL_ERROR_Unknown		= 0,
114 	TOOL_ERROR_Calculation
115 }
116 TSG_Tool_Error;
117 
118 //---------------------------------------------------------
119 typedef enum ESG_Tool_Script_Type
120 {
121 	TOOL_SCRIPT_CMD_SHELL	= 0,
122 	TOOL_SCRIPT_CMD_BATCH,
123 	TOOL_SCRIPT_PYTHON,
124 	TOOL_SCRIPT_CHAIN
125 }
126 TSG_Tool_Script_Type;
127 
128 
129 ///////////////////////////////////////////////////////////
130 //														 //
131 //						CSG_Tool						 //
132 //														 //
133 ///////////////////////////////////////////////////////////
134 
135 //---------------------------------------------------------
136 /**
137   * CSG_Tool is the base class for all executable SAGA tools.
138   * @see CSG_Parameters
139   * @see CSG_Tool_Interactive
140   * @see CSG_Tool_Grid
141   * @see CSG_Tool_Grid_Interactive
142 */
143 //---------------------------------------------------------
144 class SAGA_API_DLL_EXPORT CSG_Tool
145 {
146 	friend class CSG_Tool_Interactive_Base;
147 	friend class CSG_Tool_Library_Interface;
148 	friend class CSG_Tool_Chain;
149 
150 public:
151 
152 	CSG_Tool(void);
153 	virtual ~CSG_Tool(void);
154 
155 	virtual void				Destroy						(void);
156 
Get_Type(void)157 	virtual TSG_Tool_Type		Get_Type					(void)	const	{	return( TOOL_TYPE_Base );	}
158 
Get_ID(void)159 	const CSG_String &			Get_ID						(void)	const	{	return( m_ID );	}
160 
161 	const CSG_String &			Get_Library					(void)	const;
162 	const CSG_String &			Get_File_Name				(void)	const;	// Returns the file name of the tool's library or, if this is a tool chain, the associated XML file.
163 	const CSG_String &			Get_Name					(void)	const;
164 	const CSG_String &			Get_Author					(void)	const;
165 	const CSG_String &			Get_Version					(void)	const;
166 	const CSG_String &			Get_Description				(void)	const;
167 	const CSG_Strings &			Get_References				(void)	const;
Get_Icon(void)168 	const SG_Char *				Get_Icon					(void)	{	return( NULL );	}
169 	CSG_String					Get_Summary					(bool bParameters = true, const CSG_String &Menu = "", const CSG_String &Description = "", int Format = SG_SUMMARY_FMT_HTML);
170 
Get_MenuPath(void)171 	virtual CSG_String			Get_MenuPath				(void)	{	return( SG_T("") );	}
172 	virtual CSG_String			Get_MenuPath				(bool bSolved);
173 
Get_Parameters_Count(void)174 	int							Get_Parameters_Count		(void)	{	return( m_npParameters );	}
Get_Parameters(void)175 	CSG_Parameters *			Get_Parameters				(void)	{	return( &Parameters );	}
Get_Parameters(int i)176 	CSG_Parameters *			Get_Parameters				(int i)	{	return( i >= 0 && i < m_npParameters ? m_pParameters[i] : NULL );	}
177 	CSG_Parameters *			Get_Parameters				(const CSG_String &Identifier);
178 
Get_Parameter(const CSG_String & ID)179 	CSG_Parameter *				Get_Parameter				(const CSG_String &ID)	const	{	return( Parameters(ID) );	}
Get_Parameter(const char * ID)180 	CSG_Parameter *				Get_Parameter				(const char       *ID)	const	{	return( Parameters(ID) );	}
Get_Parameter(const wchar_t * ID)181 	CSG_Parameter *				Get_Parameter				(const wchar_t    *ID)	const	{	return( Parameters(ID) );	}
182 	bool						Set_Parameter				(const CSG_String &ID, CSG_Parameter   *pValue);
183 	bool						Set_Parameter				(const char       *ID, CSG_Parameter   *pValue);
184 	bool						Set_Parameter				(const wchar_t    *ID, CSG_Parameter   *pValue);
185 	bool						Set_Parameter				(const CSG_String &ID, int               Value, int Type = PARAMETER_TYPE_Undefined);
186 	bool						Set_Parameter				(const char       *ID, int               Value, int Type = PARAMETER_TYPE_Undefined);
187 	bool						Set_Parameter				(const wchar_t    *ID, int               Value, int Type = PARAMETER_TYPE_Undefined);
188 	bool						Set_Parameter				(const CSG_String &ID, double            Value, int Type = PARAMETER_TYPE_Undefined);
189 	bool						Set_Parameter				(const char       *ID, double            Value, int Type = PARAMETER_TYPE_Undefined);
190 	bool						Set_Parameter				(const wchar_t    *ID, double            Value, int Type = PARAMETER_TYPE_Undefined);
191 	bool						Set_Parameter				(const CSG_String &ID, void             *Value, int Type = PARAMETER_TYPE_Undefined);
192 	bool						Set_Parameter				(const char       *ID, void             *Value, int Type = PARAMETER_TYPE_Undefined);
193 	bool						Set_Parameter				(const wchar_t    *ID, void             *Value, int Type = PARAMETER_TYPE_Undefined);
194 	bool						Set_Parameter				(const CSG_String &ID, const CSG_String &Value, int Type = PARAMETER_TYPE_Undefined);
195 	bool						Set_Parameter				(const char       *ID, const CSG_String &Value, int Type = PARAMETER_TYPE_Undefined);
196 	bool						Set_Parameter				(const wchar_t    *ID, const CSG_String &Value, int Type = PARAMETER_TYPE_Undefined);
197 	bool						Set_Parameter				(const CSG_String &ID, const char       *Value, int Type = PARAMETER_TYPE_Undefined);
198 	bool						Set_Parameter				(const char       *ID, const char       *Value, int Type = PARAMETER_TYPE_Undefined);
199 	bool						Set_Parameter				(const wchar_t    *ID, const char       *Value, int Type = PARAMETER_TYPE_Undefined);
200 	bool						Set_Parameter				(const CSG_String &ID, const wchar_t    *Value, int Type = PARAMETER_TYPE_Undefined);
201 	bool						Set_Parameter				(const char       *ID, const wchar_t    *Value, int Type = PARAMETER_TYPE_Undefined);
202 	bool						Set_Parameter				(const wchar_t    *ID, const wchar_t    *Value, int Type = PARAMETER_TYPE_Undefined);
203 
204 	bool						Reset						(void);
205 	bool						Reset_Grid_System			(void);
206 	bool						Set_Grid_System				(const CSG_Grid_System &System);
207 
208 	bool						Update_Parameter_States		(void);
209 
210 	void						Set_Callback				(bool bActive = true);
211 	bool						Set_Manager					(class CSG_Data_Manager *pManager);
212 
213 	bool						Settings_Push				(class CSG_Data_Manager *pManager = NULL);
214 	bool						Settings_Pop				(void);
215 
do_Sync_Projections(void)216 	virtual bool				do_Sync_Projections			(void)	const	{	return( true  );	}
217 
needs_GUI(void)218 	virtual bool				needs_GUI					(void)	const	{	return( false );	}
219 	bool						has_GUI						(void)	const;
220 
is_Grid(void)221 	virtual bool				is_Grid						(void)	const	{	return( false );	}
is_Interactive(void)222 	virtual bool				is_Interactive				(void)	const	{	return( false );	}
is_Progress(void)223 	bool						is_Progress					(void)	const	{	return( SG_UI_Process_Get_Okay(false) );	}
is_Executing(void)224 	bool						is_Executing				(void)	const	{	return( m_bExecutes );	}
225 
226 	void						Set_Show_Progress			(bool bOn = true);
227 
On_Before_Execution(void)228 	virtual bool				On_Before_Execution			(void)	{	return( true );	}
On_After_Execution(void)229 	virtual bool				On_After_Execution			(void)	{	return( true );	}
230 
231 	bool						Execute						(bool bAddHistory = false);
232 
Get_Execution_Info(void)233 	const SG_Char *				Get_Execution_Info			(void)	const	{	return( m_Execution_Info );	}
234 
235 	CSG_String					Get_Script					(TSG_Tool_Script_Type Type, bool bHeader, bool bAllParameters = false);
236 
237 
238 protected:
239 
240 	CSG_Parameters				Parameters;
241 
242 	CSG_MetaData				History_Supplement;
243 
244 
245 	//-----------------------------------------------------
246 	void						Set_Name					(const CSG_String &String);
247 	void						Set_Author					(const CSG_String &String);
248 	void						Set_Version					(const CSG_String &String);
249 	void						Set_Description				(const CSG_String &String);
250 
251 	void						Add_Reference				(const CSG_String &Authors, const CSG_String &Year, const CSG_String &Title, const CSG_String &Where, const SG_Char *Link = NULL, const SG_Char *Link_Text = NULL);
252 	void						Add_Reference				(const CSG_String &Link, const SG_Char *Link_Text = NULL);
253 
254 	//-----------------------------------------------------
255 	virtual bool				On_Execute					(void)	= 0;
256 
257 	virtual int					On_Parameter_Changed		(CSG_Parameters *pParameters, CSG_Parameter *pParameter);
258 	virtual int					On_Parameters_Enable		(CSG_Parameters *pParameters, CSG_Parameter *pParameter);
259 
Get_Parameter_Changed(void)260 	TSG_PFNC_Parameter_Changed	Get_Parameter_Changed		(void)	{	return( _On_Parameter_Changed );	}
261 
262 	//-----------------------------------------------------
263 	CSG_Parameters *			Add_Parameters				(const CSG_String &Identifier, const CSG_String &Name, const CSG_String &Description);
264 	bool						Dlg_Parameters				(const CSG_String &Identifier);
265 	bool						Dlg_Parameters				(CSG_Parameters *pParameters, const CSG_String &Caption);
266 
267 	//-----------------------------------------------------
268 	virtual bool				Set_Progress				(double Percent)				const;
269 	virtual bool				Set_Progress				(double Position, double Range)	const;
270 
271 	bool						Stop_Execution				(bool bDialog = true);
272 
273 	void						Message_Dlg					(const CSG_String &Text, const SG_Char *Caption = NULL);
274 	bool						Message_Dlg_Confirm			(const CSG_String &Text, const SG_Char *Caption = NULL);
275 
276 	void						Message_Add					(const CSG_String &Text, bool bNewLine = true);
277 	void						Message_Fmt					(const char    *Format, ...);
278 	void						Message_Fmt					(const wchar_t *Format, ...);
279 
280 	bool						Error_Set					(TSG_Tool_Error Error_ID = TOOL_ERROR_Unknown);
281 	bool						Error_Set					(const CSG_String &Text);
282 	bool						Error_Fmt					(const char    *Format, ...);
283 	bool						Error_Fmt					(const wchar_t *Format, ...);
284 
285 	//-----------------------------------------------------
286 	bool						DataObject_Add				(CSG_Data_Object *pDataObject, bool bUpdate = false);
287 
288 	void						DataObject_Update_All		(void);
289 
290 	bool						DataObject_Set_History		(CSG_Parameter *pParameter, CSG_MetaData *pHistory = NULL);
291 
292 	bool						Get_Projection				(CSG_Projection &Projection)	const;
293 
294 
295 public:	// static functions...
296 
297 	static bool					Process_Get_Okay			(bool bBlink = false);
298 	static void					Process_Set_Text			(const CSG_String &Text);
299 	static void					Process_Set_Text			(const char    *Format, ...);
300 	static void					Process_Set_Text			(const wchar_t *Format, ...);
301 
302 	static bool					DataObject_Update			(CSG_Data_Object *pDataObject                                , int Show = SG_UI_DATAOBJECT_UPDATE_ONLY);
303 	static bool					DataObject_Update			(CSG_Data_Object *pDataObject, double Minimum, double Maximum, int Show = SG_UI_DATAOBJECT_UPDATE_ONLY);
304 
305 	static bool					DataObject_Get_Colors		(CSG_Data_Object *pDataObject, CSG_Colors &Colors);
306 	static bool					DataObject_Set_Colors		(CSG_Data_Object *pDataObject, const CSG_Colors &Colors);
307 	static bool					DataObject_Set_Colors		(CSG_Data_Object *pDataObject, int nColors, int Palette = SG_COLORS_DEFAULT, bool bRevert = false);
308 
309 	static bool					DataObject_Get_Parameters	(CSG_Data_Object *pDataObject, CSG_Parameters &Parameters);
310 	static bool					DataObject_Set_Parameters	(CSG_Data_Object *pDataObject, CSG_Parameters &Parameters);
311 	static bool					DataObject_Set_Parameters	(CSG_Data_Object *pDataObject, CSG_Data_Object *pCopy);
312 
313 	static CSG_Parameter *		DataObject_Get_Parameter	(CSG_Data_Object *pDataObject, const CSG_String &ID);
314 	static bool					DataObject_Set_Parameter	(CSG_Data_Object *pDataObject, CSG_Parameter *pParameter);
315 	static bool					DataObject_Set_Parameter	(CSG_Data_Object *pDataObject, CSG_Data_Object *pCopy, const CSG_String &ID);
316 	static bool					DataObject_Set_Parameter	(CSG_Data_Object *pDataObject, const CSG_String &ID, int            Value);
317 	static bool					DataObject_Set_Parameter	(CSG_Data_Object *pDataObject, const CSG_String &ID, double         Value);
318 	static bool					DataObject_Set_Parameter	(CSG_Data_Object *pDataObject, const CSG_String &ID, void          *Value);
319 	static bool					DataObject_Set_Parameter	(CSG_Data_Object *pDataObject, const CSG_String &ID, const SG_Char *Value);
320 	static bool					DataObject_Set_Parameter	(CSG_Data_Object *pDataObject, const CSG_String &ID, double loVal, double hiVal);	// Range Parameter
321 
322 
323 private:
324 
325 	bool						m_bExecutes, m_bError_Ignore, m_bShow_Progress, m_bWithGUI;
326 
327 	int							m_npParameters;
328 
329 	CSG_Array					m_Settings_Stack;
330 
331 	CSG_Parameters				**m_pParameters;
332 
333 	CSG_String					m_ID, m_Library, m_Library_Menu, m_File_Name, m_Author, m_Version, m_Execution_Info;
334 
335 
336 	bool						_Synchronize_DataObjects	(void);
337 
338 	CSG_String					_Get_Script_CMD				(bool bHeader, bool bAllParameters, TSG_Tool_Script_Type Type);
339 	void						_Get_Script_CMD				(CSG_String &Script, CSG_Parameters *pParameters, bool bAllParameters);
340 
341 	CSG_String					_Get_Script_Python			(bool bHeader, bool bAllParameters);
342 	void						_Get_Script_Python			(CSG_String &Script, CSG_Parameters *pParameters, bool bAllParameters, const CSG_String &Prefix = "");
343 
344 	CSG_MetaData				_Get_Output_History			(void);
345 	void						_Set_Output_History			(void);
346 
347 	void						_Update_Parameter_States	(CSG_Parameters *pParameters);
348 
349 	static int					_On_Parameter_Changed		(CSG_Parameter *pParameter, int Flags);
350 
351 };
352 
353 
354 ///////////////////////////////////////////////////////////
355 //														 //
356 //					CSG_Tool_Grid						 //
357 //														 //
358 ///////////////////////////////////////////////////////////
359 
360 //---------------------------------------------------------
361 /**
362   * CSG_Tool_Grid.
363 */
364 //---------------------------------------------------------
365 class SAGA_API_DLL_EXPORT CSG_Tool_Grid : public CSG_Tool
366 {
367 public:
368 	CSG_Tool_Grid(void);
369 	virtual ~CSG_Tool_Grid(void);
370 
Get_Type(void)371 	virtual TSG_Tool_Type		Get_Type				(void)	const	{	return( TOOL_TYPE_Grid );	}
372 
Get_System(void)373 	const CSG_Grid_System &		Get_System				(void)	const	{	return( *Parameters.Get_Grid_System() );	}
374 	bool						Set_System				(const CSG_Grid_System &System);
375 
is_Grid(void)376 	virtual bool				is_Grid					(void)	const	{	return( true );	}
377 
378 
379 protected:
380 
381 	virtual bool				Set_Progress_NCells		(sLong iCell)					const;
382 	virtual bool				Set_Progress			(int    iRow)					const;
383 	virtual bool				Set_Progress			(double Position, double Range)	const;
384 
385 	//-----------------------------------------------------
Get_NX(void)386 	int							Get_NX					(void)						const	{	return( Get_System().Get_NX      () );	}
Get_NY(void)387 	int							Get_NY					(void)						const	{	return( Get_System().Get_NY      () );	}
Get_NCells(void)388 	sLong						Get_NCells				(void)						const	{	return( Get_System().Get_NCells  () );	}
Get_XMin(void)389 	double						Get_XMin				(void)						const	{	return( Get_System().Get_XMin    () );	}
Get_YMin(void)390 	double						Get_YMin				(void)						const	{	return( Get_System().Get_YMin    () );	}
Get_XMax(void)391 	double						Get_XMax				(void)						const	{	return( Get_System().Get_XMax    () );	}
Get_YMax(void)392 	double						Get_YMax				(void)						const	{	return( Get_System().Get_YMax    () );	}
Get_Cellsize(void)393 	double						Get_Cellsize			(void)						const	{	return( Get_System().Get_Cellsize() );	}
Get_Cellarea(void)394 	double						Get_Cellarea			(void)						const	{	return( Get_System().Get_Cellarea() );	}
395 
Get_Length(int i)396 	double						Get_Length				(int i)						const	{	return( Get_System().Get_Length    (i)     );	}
Get_UnitLength(int i)397 	double						Get_UnitLength			(int i)						const	{	return( Get_System().Get_UnitLength(i)     );	}
is_InGrid(int x,int y)398 	bool						is_InGrid				(int x, int y)				const	{	return(	Get_System().is_InGrid(x, y)       );	}
is_InGrid(int x,int y,int Rand)399 	bool						is_InGrid				(int x, int y, int Rand)	const	{	return(	Get_System().is_InGrid(x, y, Rand) );	}
400 
401 	static int					Get_xTo					(int i, int x = 0)	{	return( CSG_Grid_System::Get_xTo  (i, x) );	}
402 	static int					Get_yTo					(int i, int y = 0)	{	return( CSG_Grid_System::Get_yTo  (i, y) );	}
403 	static int					Get_xFrom				(int i, int x = 0)	{	return( CSG_Grid_System::Get_xFrom(i, x) );	}
404 	static int					Get_yFrom				(int i, int y = 0)	{	return( CSG_Grid_System::Get_yFrom(i, y) );	}
405 
406 	//-----------------------------------------------------
407 	void						Lock_Create				(void);
408 	void						Lock_Destroy			(void);
409 
is_Locked(int x,int y)410 	bool						is_Locked				(int x, int y)	{	return( Lock_Get(x, y) != 0 );	}
Lock_Get(int x,int y)411 	char						Lock_Get				(int x, int y)	{	return( m_pLock && x >= 0 && x < Get_NX() && y >= 0 && y < Get_NY() ? m_pLock->asChar(x, y) : 0 );	}
412 
413 	void						Lock_Set				(int x, int y, char Value = 1)
414 	{
415 		if( m_pLock && x >= 0 && x < Get_NX() && y >= 0 && y < Get_NY() )
416 		{
417 			m_pLock->Set_Value(x, y, Value);
418 		}
419 	}
420 
421 
422 private:
423 
424 	CSG_Grid					*m_pLock;
425 
426 };
427 
428 
429 ///////////////////////////////////////////////////////////
430 //														 //
431 //				CSG_Tool_Interactive_Base				 //
432 //														 //
433 ///////////////////////////////////////////////////////////
434 
435 //---------------------------------------------------------
436 typedef enum ESG_Tool_Interactive_Mode
437 {
438 	TOOL_INTERACTIVE_UNDEFINED		= 0,
439 	TOOL_INTERACTIVE_LDOWN,
440 	TOOL_INTERACTIVE_LUP,
441 	TOOL_INTERACTIVE_LDCLICK,
442 	TOOL_INTERACTIVE_MDOWN,
443 	TOOL_INTERACTIVE_MUP,
444 	TOOL_INTERACTIVE_MDCLICK,
445 	TOOL_INTERACTIVE_RDOWN,
446 	TOOL_INTERACTIVE_RUP,
447 	TOOL_INTERACTIVE_RDCLICK,
448 	TOOL_INTERACTIVE_MOVE,
449 	TOOL_INTERACTIVE_MOVE_LDOWN,
450 	TOOL_INTERACTIVE_MOVE_MDOWN,
451 	TOOL_INTERACTIVE_MOVE_RDOWN
452 }
453 TSG_Tool_Interactive_Mode;
454 
455 //---------------------------------------------------------
456 typedef enum ESG_Tool_Interactive_DragMode
457 {
458 	TOOL_INTERACTIVE_DRAG_NONE		= 0,
459 	TOOL_INTERACTIVE_DRAG_LINE,
460 	TOOL_INTERACTIVE_DRAG_BOX,
461 	TOOL_INTERACTIVE_DRAG_CIRCLE
462 }
463 TSG_Tool_Interactive_DragMode;
464 
465 //---------------------------------------------------------
466 #define TOOL_INTERACTIVE_KEY_LEFT	0x01
467 #define TOOL_INTERACTIVE_KEY_MIDDLE	0x02
468 #define TOOL_INTERACTIVE_KEY_RIGHT	0x04
469 #define TOOL_INTERACTIVE_KEY_SHIFT	0x08
470 #define TOOL_INTERACTIVE_KEY_ALT	0x10
471 #define TOOL_INTERACTIVE_KEY_CTRL	0x20
472 
473 //---------------------------------------------------------
474 /**
475   * CSG_Tool_Interactive_Base.
476 */
477 //---------------------------------------------------------
478 class SAGA_API_DLL_EXPORT CSG_Tool_Interactive_Base
479 {
480 	friend class CSG_Tool_Interactive;
481 	friend class CSG_Tool_Grid_Interactive;
482 
483 public:
484 	CSG_Tool_Interactive_Base(void);
485 	virtual ~CSG_Tool_Interactive_Base(void);
486 
487 	bool						Execute_Position		(CSG_Point ptWorld, TSG_Tool_Interactive_Mode Mode, int Keys);
488 	bool						Execute_Keyboard		(int Character, int Keys);
489 	bool						Execute_Finish			(void);
490 
Get_Drag_Mode(void)491 	int							Get_Drag_Mode			(void)	{	return( m_Drag_Mode );	}
492 
493 
494 protected:
495 
496 	virtual bool				On_Execute_Position		(CSG_Point ptWorld, TSG_Tool_Interactive_Mode Mode);
497 	virtual bool				On_Execute_Keyboard		(int Character);
498 	virtual bool				On_Execute_Finish		(void);
499 
Get_Position(void)500 	CSG_Point &					Get_Position			(void)	{	return( m_Point );				}
Get_xPosition(void)501 	double						Get_xPosition			(void)	{	return( m_Point.Get_X() );		}
Get_yPosition(void)502 	double						Get_yPosition			(void)	{	return( m_Point.Get_Y() );		}
503 
Get_Position_Last(void)504 	CSG_Point &					Get_Position_Last		(void)	{	return( m_Point_Last );			}
Get_xPosition_Last(void)505 	double						Get_xPosition_Last		(void)	{	return( m_Point_Last.Get_X() );	}
Get_yPosition_Last(void)506 	double						Get_yPosition_Last		(void)	{	return( m_Point_Last.Get_Y() );	}
507 
is_Shift(void)508 	bool						is_Shift				(void)	{	return( (m_Keys & TOOL_INTERACTIVE_KEY_SHIFT) != 0 );	}
is_Alt(void)509 	bool						is_Alt					(void)	{	return( (m_Keys & TOOL_INTERACTIVE_KEY_ALT)   != 0 );	}
is_Ctrl(void)510 	bool						is_Ctrl					(void)	{	return( (m_Keys & TOOL_INTERACTIVE_KEY_CTRL)  != 0 );	}
511 
512 	void						Set_Drag_Mode			(int Drag_Mode);
513 
514 
515 private:
516 
517 	int							m_Keys, m_Drag_Mode;
518 
519 	CSG_Point					m_Point, m_Point_Last;
520 
521 	CSG_Tool					*m_pTool;
522 
523 };
524 
525 
526 ///////////////////////////////////////////////////////////
527 //														 //
528 //				CSG_Tool_Interactive					 //
529 //														 //
530 ///////////////////////////////////////////////////////////
531 
532 //---------------------------------------------------------
533 /**
534   * CSG_Tool_Interactive.
535 */
536 //---------------------------------------------------------
537 class SAGA_API_DLL_EXPORT CSG_Tool_Interactive : public CSG_Tool_Interactive_Base, public CSG_Tool
538 {
539 public:
540 	CSG_Tool_Interactive(void);
541 	virtual ~CSG_Tool_Interactive(void);
542 
Get_Type(void)543 	virtual TSG_Tool_Type		Get_Type				(void)	const	{	return( TOOL_TYPE_Interactive );	}
544 
needs_GUI(void)545 	virtual bool				needs_GUI				(void)	const	{	return( true );	}
546 
is_Interactive(void)547 	virtual bool				is_Interactive			(void)	const	{	return( true );	}
548 
549 };
550 
551 
552 ///////////////////////////////////////////////////////////
553 //														 //
554 //				CSG_Tool_Grid_Interactive				 //
555 //														 //
556 ///////////////////////////////////////////////////////////
557 
558 //---------------------------------------------------------
559 /**
560   * CSG_Tool_Grid_Interactive.
561 */
562 //---------------------------------------------------------
563 class SAGA_API_DLL_EXPORT CSG_Tool_Grid_Interactive : public CSG_Tool_Interactive_Base, public CSG_Tool_Grid
564 {
565 public:
566 	CSG_Tool_Grid_Interactive(void);
567 	virtual ~CSG_Tool_Grid_Interactive(void);
568 
Get_Type(void)569 	virtual TSG_Tool_Type		Get_Type				(void)	const	{	return( TOOL_TYPE_Grid_Interactive );	}
570 
needs_GUI(void)571 	virtual bool				needs_GUI				(void)	const	{	return( true );	}
572 
is_Interactive(void)573 	virtual bool				is_Interactive			(void)	const	{	return( true );	}
574 
575 
576 protected:
577 
578 	bool						Get_Grid_Pos			(int &x, int &y);
579 
580 	int							Get_xGrid				(void);
581 	int							Get_yGrid				(void);
582 
583 };
584 
585 
586 ///////////////////////////////////////////////////////////
587 //														 //
588 //			Tool Library Interface Definitions			 //
589 //														 //
590 ///////////////////////////////////////////////////////////
591 
592 //---------------------------------------------------------
593 typedef enum ESG_TLB_Info
594 {
595 	TLB_INFO_Name	= 0,
596 	TLB_INFO_Description,
597 	TLB_INFO_Author,
598 	TLB_INFO_Version,
599 	TLB_INFO_Menu_Path,
600 	TLB_INFO_Category,
601 	TLB_INFO_User,
602 	TLB_INFO_File,
603 	TLB_INFO_Library,
604 	TLB_INFO_SAGA_Version,
605 	TLB_INFO_Count
606 }
607 TSG_TLB_Info;
608 
609 //---------------------------------------------------------
610 typedef CSG_Tool *	(* TSG_PFNC_TLB_Create_Tool)	(int i);
611 typedef CSG_String	(* TSG_PFNC_TLB_Get_Info   )	(int i);
612 
613 //---------------------------------------------------------
614 class SAGA_API_DLL_EXPORT CSG_Tool_Library_Interface
615 {
616 public:
617 	CSG_Tool_Library_Interface(void);
618 	virtual ~CSG_Tool_Library_Interface(void);
619 
620 	bool						Create					(const CSG_String &Version, const CSG_String &TLB_Path, TSG_PFNC_TLB_Get_Info Fnc_Info, TSG_PFNC_TLB_Create_Tool Fnc_Create_Tool);
621 	bool						Destroy					(void);
622 
623 	const CSG_String &			Get_Info				(int ID);
624 
625 	int							Get_Count				(void);
626 	CSG_Tool *					Get_Tool				(int i);
627 
628 	CSG_Tool *					Create_Tool				(int i, bool bWithGUI = false);
629 	bool						Delete_Tool				(CSG_Tool *pTool);
630 	bool						Delete_Tools			(void);
631 
632 
633 private:
634 
635 	CSG_Strings					m_Info;
636 
637 	CSG_Array_Pointer			m_Tools, m_xTools;
638 
639 	TSG_PFNC_TLB_Create_Tool	m_Fnc_Create_Tool;
640 
641 };
642 
643 //---------------------------------------------------------
644 #define SYMBOL_TLB_Initialize			"TLB_Initialize"
645 typedef bool							(* TSG_PFNC_TLB_Initialize)		(const SG_Char *);
646 
647 #define SYMBOL_TLB_Finalize				"TLB_Finalize"
648 typedef bool							(* TSG_PFNC_TLB_Finalize)		(void);
649 
650 #define SYMBOL_TLB_Get_Interface		"TLB_Get_Interface"
651 typedef CSG_Tool_Library_Interface *	(* TSG_PFNC_TLB_Get_Interface)	(void);
652 
653 //---------------------------------------------------------
654 #define TLB_INTERFACE_SKIP_TOOL			((CSG_Tool *)0x1)
655 
656 //---------------------------------------------------------
657 #define TLB_INTERFACE_INITIALIZE	CSG_Tool_Library_Interface	TLB_Interface;\
658 \
659 extern "C" _SAGA_DLL_EXPORT CSG_Tool_Library_Interface *	TLB_Get_Interface   (void)\
660 {\
661 	return( &TLB_Interface );\
662 }\
663 \
664 extern "C" _SAGA_DLL_EXPORT bool TLB_Initialize	(const SG_Char *TLB_Path)\
665 {\
666 	return( TLB_Interface.Create(SAGA_VERSION, TLB_Path, Get_Info, Create_Tool) );\
667 }\
668 
669 //---------------------------------------------------------
670 #define TLB_INTERFACE_FINALIZE		extern "C" _SAGA_DLL_EXPORT bool TLB_Finalize	(void)\
671 {\
672 	return( true );\
673 }\
674 
675 //---------------------------------------------------------
676 #define TLB_INTERFACE	TLB_INTERFACE_INITIALIZE TLB_INTERFACE_FINALIZE
677 
678 //---------------------------------------------------------
679 #ifndef SWIG
680 
681 extern CSG_Tool_Library_Interface	TLB_Interface;
682 
683 #endif	// #ifdef SWIG
684 
685 
686 ///////////////////////////////////////////////////////////
687 //														 //
688 //														 //
689 //														 //
690 ///////////////////////////////////////////////////////////
691 
692 //---------------------------------------------------------
693 #endif // #ifndef HEADER_INCLUDED__SAGA_API__tool_H
694