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_grid_interactive.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 //---------------------------------------------------------
CSG_Tool_Grid_Interactive(void)63 CSG_Tool_Grid_Interactive::CSG_Tool_Grid_Interactive(void)
64 {
65 	m_pTool	= this;
66 }
67 
68 //---------------------------------------------------------
~CSG_Tool_Grid_Interactive(void)69 CSG_Tool_Grid_Interactive::~CSG_Tool_Grid_Interactive(void)
70 {
71 }
72 
73 
74 ///////////////////////////////////////////////////////////
75 //														 //
76 ///////////////////////////////////////////////////////////
77 
78 //---------------------------------------------------------
Get_Grid_Pos(int & x,int & y)79 bool CSG_Tool_Grid_Interactive::Get_Grid_Pos(int &x, int &y)
80 {
81 	if( Get_System().is_Valid() )
82 	{
83 		bool	bResult	= true;
84 
85 		//-------------------------------------------------
86 		x	= (int)(0.5 + (Get_xPosition() - Get_XMin()) / Get_Cellsize());
87 
88 		if( x < 0 )
89 		{
90 			bResult	= false;	x	= 0;
91 		}
92 		else if( x >= Get_NX() )
93 		{
94 			bResult	= false;	x	= Get_NX() - 1;
95 		}
96 
97 		//-------------------------------------------------
98 		y	= (int)(0.5 + (Get_yPosition() - Get_YMin()) / Get_Cellsize());
99 
100 		if( y < 0 )
101 		{
102 			bResult	= false;	y	= 0;
103 		}
104 		else if( y >= Get_NY() )
105 		{
106 			bResult	= false;	y	= Get_NY() - 1;
107 		}
108 
109 		return( bResult );
110 	}
111 
112 	//-----------------------------------------------------
113 	x	= 0;
114 	y	= 0;
115 
116 	return( false );
117 }
118 
119 //---------------------------------------------------------
Get_xGrid(void)120 int CSG_Tool_Grid_Interactive::Get_xGrid(void)
121 {
122 	if( Get_System().is_Valid() )
123 	{
124 		int	x	= (int)(0.5 + (Get_xPosition() - Get_XMin()) / Get_Cellsize());
125 
126 		if( x < 0 )
127 		{
128 			x	= 0;
129 		}
130 		else if( x >= Get_NX() )
131 		{
132 			x	= Get_NX() - 1;
133 		}
134 
135 		return( x );
136 	}
137 
138 	return( 0 );
139 }
140 
141 //---------------------------------------------------------
Get_yGrid(void)142 int CSG_Tool_Grid_Interactive::Get_yGrid(void)
143 {
144 	if( Get_System().is_Valid() )
145 	{
146 		int	y	= (int)(0.5 + (Get_yPosition() - Get_YMin()) / Get_Cellsize());
147 
148 		if( y < 0 )
149 		{
150 			y	= 0;
151 		}
152 		else if( y >= Get_NY() )
153 		{
154 			y	= Get_NY() - 1;
155 		}
156 
157 		return( y );
158 	}
159 
160 	return( 0 );
161 }
162 
163 
164 ///////////////////////////////////////////////////////////
165 //														 //
166 //														 //
167 //														 //
168 ///////////////////////////////////////////////////////////
169 
170 //---------------------------------------------------------
171