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.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(void)63 CSG_Tool_Grid::CSG_Tool_Grid(void)
64 	: CSG_Tool()
65 {
66 	m_pLock		= NULL;
67 
68 	Parameters.Use_Grid_System();
69 }
70 
71 //---------------------------------------------------------
~CSG_Tool_Grid(void)72 CSG_Tool_Grid::~CSG_Tool_Grid(void)
73 {
74 	Lock_Destroy();
75 }
76 
77 
78 ///////////////////////////////////////////////////////////
79 //														 //
80 ///////////////////////////////////////////////////////////
81 
82 //---------------------------------------------------------
Set_System(const CSG_Grid_System & System)83 bool CSG_Tool_Grid::Set_System(const CSG_Grid_System &System)
84 {
85 	if( Parameters.Get_Grid_System() )
86 	{
87 		return( Parameters.Get_Grid_System()->Create(System) );
88 	}
89 
90 	return( false );
91 }
92 
93 
94 ///////////////////////////////////////////////////////////
95 //														 //
96 ///////////////////////////////////////////////////////////
97 
98 //---------------------------------------------------------
Set_Progress_NCells(sLong iCell) const99 bool CSG_Tool_Grid::Set_Progress_NCells(sLong iCell)	const
100 {
101 	if( Get_System().is_Valid() )
102 	{
103 		return( CSG_Tool::Set_Progress((double)iCell, (double)Get_NCells()) );
104 	}
105 
106 	return( is_Progress() );
107 }
108 
109 //---------------------------------------------------------
Set_Progress(int iRow) const110 bool CSG_Tool_Grid::Set_Progress(int iRow)	const
111 {
112 	return( CSG_Tool::Set_Progress(iRow, Get_NY() - 1) );
113 }
114 
115 //---------------------------------------------------------
Set_Progress(double Position,double Range) const116 bool CSG_Tool_Grid::Set_Progress(double Position, double Range)	const
117 {
118 	return( CSG_Tool::Set_Progress(Position, Range) );
119 }
120 
121 
122 ///////////////////////////////////////////////////////////
123 //														 //
124 ///////////////////////////////////////////////////////////
125 
126 //---------------------------------------------------------
Lock_Create(void)127 void CSG_Tool_Grid::Lock_Create(void)
128 {
129 	if( Get_System().is_Valid() )
130 	{
131 		if( m_pLock && Get_System().is_Equal(m_pLock->Get_System()) )
132 		{
133 			m_pLock->Assign(0.0);
134 		}
135 		else
136 		{
137 			Lock_Destroy();
138 
139 			m_pLock	= new CSG_Grid(
140 				SG_DATATYPE_Char, Get_NX(), Get_NY(), Get_Cellsize(), Get_XMin(), Get_YMin()
141 			);
142 		}
143 	}
144 }
145 
146 //---------------------------------------------------------
Lock_Destroy(void)147 void CSG_Tool_Grid::Lock_Destroy(void)
148 {
149 	if( m_pLock )
150 	{
151 		delete(m_pLock);
152 
153 		m_pLock	= NULL;
154 	}
155 }
156 
157 
158 ///////////////////////////////////////////////////////////
159 //														 //
160 //														 //
161 //														 //
162 ///////////////////////////////////////////////////////////
163 
164 //---------------------------------------------------------
165