b311480e |
1 | // Created on: 1995-12-08 |
2 | // Created by: Jean Yves LEBEY |
3 | // Copyright (c) 1995-1999 Matra Datavision |
973c2be1 |
4 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e |
5 | // |
973c2be1 |
6 | // This file is part of Open CASCADE Technology software library. |
b311480e |
7 | // |
d5f74e42 |
8 | // This library is free software; you can redistribute it and/or modify it under |
9 | // the terms of the GNU Lesser General Public License version 2.1 as published |
973c2be1 |
10 | // by the Free Software Foundation, with special exception defined in the file |
11 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
12 | // distribution for complete text of the license and disclaimer of any warranty. |
b311480e |
13 | // |
973c2be1 |
14 | // Alternatively, this file may be used under the terms of Open CASCADE |
15 | // commercial license or contractual agreement. |
7fd59977 |
16 | |
42cf5bc1 |
17 | |
7fd59977 |
18 | #include <TopOpeBRepDS_Curve.hxx> |
42cf5bc1 |
19 | #include <TopOpeBRepDS_CurveExplorer.hxx> |
20 | #include <TopOpeBRepDS_DataStructure.hxx> |
7fd59977 |
21 | |
22 | #define MYDS (*((TopOpeBRepDS_DataStructure*)myDS)) |
23 | static TopOpeBRepDS_Curve* CEX_PEMPTY = NULL; |
24 | |
25 | //======================================================================= |
26 | //function : TopOpeBRepDS_CurveExplorer |
27 | //purpose : |
28 | //======================================================================= |
29 | |
30 | TopOpeBRepDS_CurveExplorer::TopOpeBRepDS_CurveExplorer() |
31 | : myIndex(1), |
32 | myMax(0), |
33 | myDS(NULL), |
34 | myFound(Standard_False), |
35 | myFindKeep(Standard_False) |
36 | { |
37 | } |
38 | |
39 | //======================================================================= |
40 | //function : TopOpeBRepDS_CurveExplorer |
41 | //purpose : |
42 | //======================================================================= |
43 | |
44 | TopOpeBRepDS_CurveExplorer::TopOpeBRepDS_CurveExplorer |
45 | (const TopOpeBRepDS_DataStructure& DS, |
46 | const Standard_Boolean FindKeep) |
47 | { |
48 | Init(DS,FindKeep); |
49 | } |
50 | |
51 | //======================================================================= |
52 | //function : Init |
53 | //purpose : |
54 | //======================================================================= |
55 | |
56 | void TopOpeBRepDS_CurveExplorer::Init |
57 | (const TopOpeBRepDS_DataStructure& DS, |
58 | const Standard_Boolean FindKeep) |
59 | { |
60 | myDS = (TopOpeBRepDS_DataStructure*)&DS; |
61 | myIndex = 1; |
62 | myMax = DS.NbCurves(); |
63 | myFindKeep = FindKeep; |
64 | Find(); |
65 | } |
66 | |
67 | |
68 | //======================================================================= |
69 | //function : Find |
70 | //purpose : |
71 | //======================================================================= |
72 | |
73 | void TopOpeBRepDS_CurveExplorer::Find() |
74 | { |
75 | myFound = Standard_False; |
76 | while (myIndex <= myMax) { |
77 | if (myFindKeep) { |
78 | myFound = IsCurveKeep(myIndex); |
79 | } |
80 | else { |
81 | myFound = IsCurve(myIndex); |
82 | } |
83 | if (myFound) break; |
84 | else myIndex++; |
85 | } |
86 | } |
87 | |
88 | //======================================================================= |
89 | //function : More |
90 | //purpose : |
91 | //======================================================================= |
92 | |
93 | Standard_Boolean TopOpeBRepDS_CurveExplorer::More() const |
94 | { |
95 | return myFound; |
96 | } |
97 | |
98 | //======================================================================= |
99 | //function : Next |
100 | //purpose : |
101 | //======================================================================= |
102 | |
103 | void TopOpeBRepDS_CurveExplorer::Next() |
104 | { |
105 | myIndex++; |
106 | Find(); |
107 | } |
108 | |
109 | //======================================================================= |
110 | //function : Curve |
111 | //purpose : |
112 | //======================================================================= |
113 | |
114 | const TopOpeBRepDS_Curve& TopOpeBRepDS_CurveExplorer::Curve()const |
115 | { |
116 | if ( myFound ) { |
117 | return MYDS.Curve(myIndex); |
118 | } |
119 | else { |
120 | if ( CEX_PEMPTY == NULL ) { |
121 | CEX_PEMPTY = new TopOpeBRepDS_Curve(); |
122 | } |
123 | return *CEX_PEMPTY; |
124 | } |
125 | } |
126 | |
127 | //======================================================================= |
128 | //function : IsCurve |
129 | //purpose : |
130 | //======================================================================= |
131 | |
132 | Standard_Boolean TopOpeBRepDS_CurveExplorer::IsCurve |
133 | (const Standard_Integer I)const |
134 | { |
135 | Standard_Boolean b = MYDS.myCurves.IsBound(I); |
136 | return b; |
137 | } |
138 | |
139 | //======================================================================= |
140 | //function : IsCurveKeep |
141 | //purpose : |
142 | //======================================================================= |
143 | |
144 | Standard_Boolean TopOpeBRepDS_CurveExplorer::IsCurveKeep |
145 | (const Standard_Integer I)const |
146 | { |
147 | Standard_Boolean b = MYDS.myCurves.IsBound(I); |
148 | if (b) b = MYDS.Curve(I).Keep(); |
149 | return b; |
150 | } |
151 | |
152 | |
153 | //======================================================================= |
154 | //function : Curve |
155 | //purpose : |
156 | //======================================================================= |
157 | |
158 | const TopOpeBRepDS_Curve& TopOpeBRepDS_CurveExplorer::Curve |
159 | (const Standard_Integer I)const |
160 | { |
161 | if ( IsCurve(I) ) { |
162 | const TopOpeBRepDS_Curve& C = MYDS.Curve(I); |
163 | return C; |
164 | } |
165 | |
166 | if ( CEX_PEMPTY == NULL ) { |
167 | CEX_PEMPTY = new TopOpeBRepDS_Curve(); |
168 | } |
169 | return *CEX_PEMPTY; |
170 | } |
171 | |
172 | //======================================================================= |
173 | //function : NbCurve |
174 | //purpose : |
175 | //======================================================================= |
176 | |
177 | Standard_Integer TopOpeBRepDS_CurveExplorer::NbCurve() |
178 | { |
179 | myIndex = 1; myMax = MYDS.NbCurves(); |
180 | Find(); |
181 | Standard_Integer n = 0; |
182 | for (; More(); Next() ) n++; |
183 | return n; |
184 | } |
185 | |
186 | //======================================================================= |
187 | //function : Index |
188 | //purpose : |
189 | //======================================================================= |
190 | |
191 | Standard_Integer TopOpeBRepDS_CurveExplorer::Index()const |
192 | { |
193 | return myIndex; |
194 | } |