SAGA API  v9.5
tool_grid_interactive.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_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 // //
51 
52 //---------------------------------------------------------
53 #include "tool.h"
54 
55 
57 // //
58 // //
59 // //
61 
62 //---------------------------------------------------------
64 {
65  m_pTool = this;
66 }
67 
68 //---------------------------------------------------------
70 {
71 }
72 
73 
75 // //
77 
78 //---------------------------------------------------------
79 bool CSG_Tool_Grid_Interactive::Get_Grid_Pos(int &x, int &y) const
80 {
81  if( !Get_System().is_Valid() )
82  {
83  x = 0; y = 0; return( false );
84  }
85 
86  bool bResult = true;
87 
88  x = (int)(0.5 + (Get_xPosition() - Get_XMin()) / Get_Cellsize());
89  if ( x < 0 ) { x = 0 ; bResult = false; }
90  else if( x >= Get_NX() ) { x = Get_NX() - 1; bResult = false; }
91 
92  y = (int)(0.5 + (Get_yPosition() - Get_YMin()) / Get_Cellsize());
93  if ( y < 0 ) { y = 0 ; bResult = false; }
94  else if( y >= Get_NY() ) { y = Get_NY() - 1; bResult = false; }
95 
96  return( bResult );
97 }
98 
99 //---------------------------------------------------------
101 {
102  if( Get_System().is_Valid() )
103  {
104  int x = (int)(0.5 + (Get_xPosition() - Get_XMin()) / Get_Cellsize());
105 
106  return( x < 0 ? 0 : x < Get_NX() ? x : Get_NX() - 1 );
107  }
108 
109  return( 0 );
110 }
111 
112 //---------------------------------------------------------
114 {
115  if( Get_System().is_Valid() )
116  {
117  int y = (int)(0.5 + (Get_yPosition() - Get_YMin()) / Get_Cellsize());
118 
119  return( y < 0 ? 0 : y < Get_NY() ? y : Get_NY() - 1 );
120  }
121 
122  return( 0 );
123 }
124 
125 
127 // //
128 // //
129 // //
131 
132 //---------------------------------------------------------
CSG_Tool_Grid_Interactive::Get_xGrid
int Get_xGrid(void) const
Definition: tool_grid_interactive.cpp:100
CSG_Tool_Grid::Get_NY
int Get_NY(void) const
Definition: tool.h:407
CSG_Tool_Interactive_Base::Get_yPosition
double Get_yPosition(void) const
Definition: tool.h:526
CSG_Tool_Grid::Get_YMin
double Get_YMin(void) const
Definition: tool.h:410
CSG_Tool_Interactive_Base::Get_xPosition
double Get_xPosition(void) const
Definition: tool.h:525
tool.h
CSG_Tool_Grid_Interactive::Get_Grid_Pos
bool Get_Grid_Pos(int &x, int &y) const
Definition: tool_grid_interactive.cpp:79
CSG_Tool_Grid_Interactive::Get_yGrid
int Get_yGrid(void) const
Definition: tool_grid_interactive.cpp:113
CSG_Tool_Grid::Get_NX
int Get_NX(void) const
Definition: tool.h:406
CSG_Tool_Grid::Get_XMin
double Get_XMin(void) const
Definition: tool.h:409
CSG_Tool_Grid::Get_System
const CSG_Grid_System & Get_System(void) const
Definition: tool.h:394
CSG_Tool_Grid::Get_Cellsize
double Get_Cellsize(void) const
Definition: tool.h:413
CSG_Tool_Grid_Interactive::~CSG_Tool_Grid_Interactive
virtual ~CSG_Tool_Grid_Interactive(void)
Definition: tool_grid_interactive.cpp:69
CSG_Tool_Grid_Interactive::CSG_Tool_Grid_Interactive
CSG_Tool_Grid_Interactive(void)
Definition: tool_grid_interactive.cpp:63