b311480e |
1 | // Created on: 1996-03-07 |
2 | // Created by: Jean Yves LEBEY |
3 | // Copyright (c) 1996-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 | |
17 | #include <TopOpeBRepDS_samdom.hxx> |
18 | |
19 | #include <TopExp.hxx> |
20 | #include <TopoDS.hxx> |
21 | #include <TopOpeBRepDS_define.hxx> |
22 | |
23 | static TopTools_IndexedDataMapOfShapeListOfShape *Gps1 = NULL; |
24 | static TopTools_IndexedDataMapOfShapeListOfShape *Gps2 = NULL; |
25 | //modified by NIZNHY-PKV Sun Dec 15 17:57:12 2002 f |
26 | //static Handle(TopOpeBRepDS_HDataStructure) Ghds; |
27 | static Handle(TopOpeBRepDS_HDataStructure)* Ghds; |
28 | //modified by NIZNHY-PKV Sun Dec 15 17:57:18 2002 t |
29 | |
30 | //modified by NIZNHY-PKV Sun Dec 15 17:41:43 2002 f |
31 | //======================================================================= |
32 | //function :FDSSDM_Close |
33 | //purpose : |
34 | //======================================================================= |
1d0a9d4d |
35 | void FDSSDM_Close() |
7fd59977 |
36 | { |
37 | if (Gps1) { |
38 | delete Gps1; |
39 | Gps1=NULL; |
40 | } |
41 | // |
42 | if (Gps2) { |
43 | delete Gps2; |
44 | Gps2=NULL; |
45 | } |
46 | } |
47 | //modified by NIZNHY-PKV Sun Dec 15 17:56:02 2002 t |
48 | //======================================================================= |
49 | //function :FDSSDM_prepare |
50 | //purpose : |
51 | //======================================================================= |
52 | Standard_EXPORT void FDSSDM_prepare(const Handle(TopOpeBRepDS_HDataStructure)& HDS) |
53 | { |
54 | if (Gps1 == NULL) { |
55 | Gps1 = (TopTools_IndexedDataMapOfShapeListOfShape*) new TopTools_IndexedDataMapOfShapeListOfShape(); |
56 | } |
57 | if (Gps2 == NULL) { |
58 | Gps2 = (TopTools_IndexedDataMapOfShapeListOfShape*) new TopTools_IndexedDataMapOfShapeListOfShape(); |
59 | } |
60 | //modified by NIZNHY-PKV Sun Dec 15 17:58:28 2002 f |
61 | //Ghds = HDS; |
62 | void *anAddr=(void *) &HDS; |
63 | Ghds = (Handle(TopOpeBRepDS_HDataStructure)*) anAddr; |
64 | //modified by NIZNHY-PKV Sun Dec 15 17:58:31 2002 t |
65 | Gps1->Clear(); |
66 | Gps2->Clear(); |
67 | Standard_Integer i,n = HDS->NbShapes(); |
68 | for (i=1; i<=n; i++) { |
69 | const TopoDS_Shape& s = HDS->Shape(i); |
70 | Standard_Boolean hsd = HDS->HasSameDomain(s); if (!hsd) continue; |
71 | TopTools_ListOfShape thelist, thelist1; |
72 | if (!Gps1->Contains(s)) Gps1->Add(s, thelist); |
73 | if (!Gps2->Contains(s)) Gps2->Add(s, thelist1); |
74 | TopTools_ListOfShape& LS1 = Gps1->ChangeFromKey(s); |
75 | TopTools_ListOfShape& LS2 = Gps2->ChangeFromKey(s); |
76 | FDSSDM_makes1s2(s,LS1,LS2); |
77 | } |
78 | } //prepare |
79 | //======================================================================= |
80 | //function :FDSSDM_makes1s2 |
81 | //purpose : |
82 | //======================================================================= |
83 | Standard_EXPORT void FDSSDM_makes1s2(const TopoDS_Shape& S, |
84 | TopTools_ListOfShape& L1, |
85 | TopTools_ListOfShape& L2) |
86 | //L1 = S1, complete lists L1,L2 with the shapes of the DS having same domain |
87 | { |
88 | //modified by NIZNHY-PKV Sun Dec 15 17:59:11 2002 f |
89 | //const Handle(TopOpeBRepDS_HDataStructure)& HDS = Ghds; |
90 | const Handle(TopOpeBRepDS_HDataStructure)& HDS = *Ghds; |
91 | //modified by NIZNHY-PKV Sun Dec 15 17:59:15 2002 t |
92 | L1.Append(S); |
93 | |
94 | Standard_Integer i; |
95 | Standard_Integer nl1 = L1.Extent(), nl2 = L2.Extent(); |
96 | |
97 | while ( nl1 > 0 || nl2 > 0 ) { |
98 | |
99 | TopTools_ListIteratorOfListOfShape it1(L1); |
100 | for (i=1 ; i<=nl1; i++) { |
101 | const TopoDS_Shape& S1 = it1.Value(); |
102 | // HDS->Shape(S1); |
103 | TopTools_ListIteratorOfListOfShape itsd(HDS->SameDomain(S1)); |
104 | for (; itsd.More(); itsd.Next() ) { |
105 | const TopoDS_Shape& S2 = itsd.Value(); |
106 | // HDS->Shape(S2); |
107 | Standard_Boolean found = FDSSDM_contains(S2,L2); |
108 | if ( ! found ) { |
109 | L2.Prepend(S2); |
110 | nl2++; |
111 | } |
112 | } |
113 | it1.Next(); |
114 | } |
115 | nl1 = 0; |
116 | |
117 | TopTools_ListIteratorOfListOfShape it2(L2); |
118 | for (i=1 ; i<=nl2; i++) { |
119 | const TopoDS_Shape& S2 = it2.Value(); |
120 | // HDS->Shape(S2); |
121 | TopTools_ListIteratorOfListOfShape itsd(HDS->SameDomain(S2)); |
122 | for (; itsd.More(); itsd.Next() ) { |
123 | const TopoDS_Shape& S1 = itsd.Value(); |
124 | // HDS->Shape(S1); |
125 | Standard_Boolean found = FDSSDM_contains(S1,L1); |
126 | if ( ! found ) { |
127 | L1.Prepend(S1); |
128 | nl1++; |
129 | } |
130 | } |
131 | it2.Next(); |
132 | } |
133 | |
134 | nl2 = 0; |
135 | } |
136 | } // makes1s2 |
137 | //======================================================================= |
138 | //function :FDSSDM_s1s2makesordor |
139 | //purpose : |
140 | //======================================================================= |
141 | Standard_EXPORT void FDSSDM_s1s2makesordor(const TopTools_ListOfShape& LS1, |
142 | const TopTools_ListOfShape& LS2, |
143 | TopTools_ListOfShape& LSO, |
144 | TopTools_ListOfShape& LDO) |
145 | { |
146 | //modified by NIZNHY-PKV Sun Dec 15 17:59:37 2002 f |
147 | //const Handle(TopOpeBRepDS_HDataStructure)& HDS = Ghds; |
148 | const Handle(TopOpeBRepDS_HDataStructure)& HDS = *Ghds; |
149 | //modified by NIZNHY-PKV Sun Dec 15 17:59:43 2002 t |
150 | TopTools_ListIteratorOfListOfShape it(LS1); if (!it.More()) return; |
151 | const TopoDS_Shape& sref = it.Value(); |
536a3cb8 |
152 | HDS->SameDomainReference(sref); |
7fd59977 |
153 | TopOpeBRepDS_Config oref = HDS->SameDomainOrientation(sref); |
154 | |
155 | for (it.Initialize(LS1); it.More(); it.Next() ) { |
156 | const TopoDS_Shape& s = it.Value(); |
157 | TopOpeBRepDS_Config o = HDS->SameDomainOrientation(s); |
158 | // HDS->Shape(s); |
159 | if ( o == oref && !FDSSDM_contains(s,LSO) ) LSO.Append(s); |
160 | else if ( o != oref && !FDSSDM_contains(s,LDO) ) LDO.Append(s); |
161 | } |
162 | |
163 | for (it.Initialize(LS2); it.More(); it.Next() ) { |
164 | const TopoDS_Shape& s = it.Value(); |
165 | TopOpeBRepDS_Config o = HDS->SameDomainOrientation(s); |
166 | // HDS->Shape(s); |
167 | if ( o == oref && !FDSSDM_contains(s,LSO) ) LSO.Append(s); |
168 | else if ( o != oref && !FDSSDM_contains(s,LDO) ) LDO.Append(s); |
169 | } |
170 | } // s1s2makesordor |
171 | |
172 | Standard_EXPORT Standard_Boolean FDSSDM_hass1s2(const TopoDS_Shape& S) |
173 | { |
174 | Standard_Boolean b1 = Gps1->Contains(S); |
175 | Standard_Boolean b2 = Gps2->Contains(S); |
176 | Standard_Boolean b = (b1 && b2); |
177 | return b; |
178 | } // hass1s2 |
179 | |
180 | Standard_EXPORT void FDSSDM_s1s2(const TopoDS_Shape& S,TopTools_ListOfShape& LS1,TopTools_ListOfShape& LS2) |
181 | { |
182 | LS1.Clear(); LS2.Clear(); |
183 | Standard_Boolean b = FDSSDM_hass1s2(S); |
184 | if (!b) { |
185 | FDSSDM_makes1s2(S,LS1,LS2); |
186 | return; |
187 | } |
188 | const TopTools_ListOfShape& L1 = Gps1->FindFromKey(S); |
189 | const TopTools_ListOfShape& L2 = Gps2->FindFromKey(S); |
190 | FDSSDM_copylist(L1,LS1); |
191 | FDSSDM_copylist(L2,LS2); |
192 | } // s1s2 |
193 | |
194 | Standard_EXPORT void FDSSDM_sordor(const TopoDS_Shape& S,TopTools_ListOfShape& LSO,TopTools_ListOfShape& LDO) |
195 | { |
196 | LSO.Clear(); LDO.Clear(); |
197 | TopTools_ListOfShape LS1,LS2; |
198 | FDSSDM_s1s2(S,LS1,LS2); |
199 | FDSSDM_s1s2makesordor(LS1,LS2,LSO,LDO); |
200 | } // sordor |
201 | |
202 | Standard_EXPORT Standard_Boolean FDSSDM_contains(const TopoDS_Shape& S,const TopTools_ListOfShape& L) |
203 | // True if S IsSame a shape of list L. |
204 | { |
205 | for (TopTools_ListIteratorOfListOfShape it(L); it.More(); it.Next() ) { |
206 | const TopoDS_Shape& SL = it.Value(); |
207 | Standard_Boolean issame = SL.IsSame(S); |
208 | if ( issame ) return Standard_True; |
209 | } |
210 | return Standard_False; |
211 | } // contains |
212 | |
213 | Standard_EXPORT void FDSSDM_copylist(const TopTools_ListOfShape& Lin,const Standard_Integer I1,const Standard_Integer I2,TopTools_ListOfShape& Lou) |
214 | // copie des elements [i1..i2] de Lin dans Lou. 1er element de Lin = index 1 |
215 | { |
216 | TopTools_ListIteratorOfListOfShape it(Lin); |
217 | Standard_Integer nadd = 0; |
218 | for ( Standard_Integer i = 1; it.More(); it.Next(),i++ ) { |
219 | const TopoDS_Shape& EL = it.Value(); |
220 | if ( i >= I1 && i <= I2 ) { |
221 | Lou.Append(EL); |
222 | nadd++; |
223 | } |
224 | } |
225 | } // copylist |
226 | |
227 | Standard_EXPORT void FDSSDM_copylist(const TopTools_ListOfShape& Lin,TopTools_ListOfShape& Lou) |
228 | // copy de Lin dans Lou |
229 | { |
230 | const Standard_Integer I1 = 1; |
231 | const Standard_Integer I2 = Lin.Extent(); |
232 | FDSSDM_copylist(Lin,I1,I2,Lou); |
233 | } // copylist |