1 /**********************************************************
2 * Version $Id$
3 *********************************************************/
4
5 ///////////////////////////////////////////////////////////
6 // //
7 // SAGA //
8 // //
9 // System for Automated Geoscientific Analyses //
10 // //
11 // Application Programming Interface //
12 // //
13 // Library: SAGA_API //
14 // //
15 //-------------------------------------------------------//
16 // //
17 // shapes_selection.cpp //
18 // //
19 // Copyright (C) 2005 by Olaf Conrad //
20 // //
21 //-------------------------------------------------------//
22 // //
23 // This file is part of 'SAGA - System for Automated //
24 // Geoscientific Analyses'. //
25 // //
26 // This library is free software; you can redistribute //
27 // it and/or modify it under the terms of the GNU Lesser //
28 // General Public License as published by the Free //
29 // Software Foundation, either version 2.1 of the //
30 // License, or (at your option) any later version. //
31 // //
32 // This library is distributed in the hope that it will //
33 // be useful, but WITHOUT ANY WARRANTY; without even the //
34 // implied warranty of MERCHANTABILITY or FITNESS FOR A //
35 // PARTICULAR PURPOSE. See the GNU Lesser General Public //
36 // License for more details. //
37 // //
38 // You should have received a copy of the GNU Lesser //
39 // General Public License along with this program; if //
40 // not, see <http://www.gnu.org/licenses/>. //
41 // //
42 //-------------------------------------------------------//
43 // //
44 // contact: Olaf Conrad //
45 // Institute of Geography //
46 // University of Goettingen //
47 // Goldschmidtstr. 5 //
48 // 37077 Goettingen //
49 // Germany //
50 // //
51 // e-mail: oconrad@saga-gis.org //
52 // //
53 ///////////////////////////////////////////////////////////
54
55 //---------------------------------------------------------
56
57
58 ///////////////////////////////////////////////////////////
59 // //
60 // //
61 // //
62 ///////////////////////////////////////////////////////////
63
64 //---------------------------------------------------------
65 #include "shapes.h"
66
67
68 ///////////////////////////////////////////////////////////
69 // //
70 // //
71 // //
72 ///////////////////////////////////////////////////////////
73
74 //---------------------------------------------------------
Select(int Index,bool bInvert)75 bool CSG_Shapes::Select(int Index, bool bInvert)
76 {
77 return( CSG_Table::Select(Index, bInvert) );
78 }
79
80 //---------------------------------------------------------
Select(CSG_Shape * pShape,bool bInvert)81 bool CSG_Shapes::Select(CSG_Shape *pShape, bool bInvert)
82 {
83 return( CSG_Table::Select(pShape, bInvert) );
84 }
85
86 //---------------------------------------------------------
Select(TSG_Rect Extent,bool bInvert)87 bool CSG_Shapes::Select(TSG_Rect Extent, bool bInvert)
88 {
89 if( !bInvert )
90 {
91 CSG_Table::Select();
92 }
93
94 for(int i=0; i<Get_Count(); i++)
95 {
96 if( Get_Shape(i)->Intersects(Extent) )
97 {
98 CSG_Table::Select(i, true);
99 }
100 }
101
102 return( Get_Selection_Count() > 0 );
103 }
104
105 //---------------------------------------------------------
Select(TSG_Point Point,bool bInvert)106 bool CSG_Shapes::Select(TSG_Point Point, bool bInvert)
107 {
108 if( Get_Type() != SHAPE_TYPE_Polygon )
109 {
110 return( Select(CSG_Rect(Point, Point), bInvert) );
111 }
112
113 if( !bInvert )
114 {
115 CSG_Table::Select();
116 }
117
118 for(int i=0; i<Get_Count(); i++)
119 {
120 if( ((CSG_Shape_Polygon *)Get_Shape(i))->Contains(Point) )
121 {
122 CSG_Table::Select(i, true);
123 }
124 }
125
126 return( Get_Selection_Count() > 0 );
127 }
128
129 //---------------------------------------------------------
Get_Selection_Extent(void)130 const CSG_Rect & CSG_Shapes::Get_Selection_Extent(void)
131 {
132 if( Get_Selection_Count() > 0 )
133 {
134 m_Extent_Selected = Get_Selection(0)->Get_Extent();
135
136 for(int i=1; i<(int)Get_Selection_Count(); i++)
137 {
138 m_Extent_Selected.Union(Get_Selection(i)->Get_Extent());
139 }
140 }
141 else
142 {
143 m_Extent_Selected.Assign(0.0, 0.0, 0.0, 0.0);
144 }
145
146 return( m_Extent_Selected );
147 }
148
149
150 ///////////////////////////////////////////////////////////
151 // //
152 // //
153 // //
154 ///////////////////////////////////////////////////////////
155
156 //---------------------------------------------------------
157