0033661: Data Exchange, Step Import - Tessellated GDTs are not imported
[occt.git] / src / Intrv / Intrv_Intervals.cxx
1 // Created on: 1991-12-13
2 // Created by: Christophe MARION
3 // Copyright (c) 1991-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
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
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.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16
17 #ifndef No_Exception
18 #define No_Exception
19 #endif
20
21
22 #include <Intrv_Intervals.hxx>
23
24 //                   **---------****             Other
25 //     ***-----*                                 IsBefore
26 //     ***------------*                          IsJustBefore
27 //     ***-----------------*                     IsOverlappingAtStart
28 //     ***------------------------*              IsJustEnclosingAtEnd
29 //     ***-----------------------------------*   IsEnclosing
30 //                  ***----*                     IsJustOverlappingAtStart
31 //                  ***-----------*              IsSimilar
32 //                  ***----------------------*   IsJustEnclosingAtStart
33 //                       ***-*                   IsInside
34 //                       ***------*              IsJustOverlappingAtEnd
35 //                       ***-----------------*   IsOverlappingAtEnd
36 //                                ***--------*   IsJustAfter
37 //                                     ***---*   IsAfter
38 //=======================================================================
39 //function : Intrv_Intervals
40 //purpose  :
41 //=======================================================================
42 Intrv_Intervals::Intrv_Intervals ()
43 {}
44
45 //=======================================================================
46 //function : Intrv_Intervals
47 //purpose  :
48 //=======================================================================
49
50 Intrv_Intervals::Intrv_Intervals (const Intrv_Interval& Int)
51 { myInter.Append(Int); }
52
53 //=======================================================================
54 //function : Intersect
55 //purpose  :
56 //=======================================================================
57
58 void Intrv_Intervals::Intersect (const Intrv_Interval& Tool)
59 {
60   Intrv_Intervals Inter(Tool);
61   Intersect(Inter);
62 }
63
64 //=======================================================================
65 //function : Intersect
66 //purpose  :
67 //=======================================================================
68
69 void Intrv_Intervals::Intersect (const Intrv_Intervals& Tool)
70 {
71   Intrv_Intervals XUni(*this);
72   XUni.XUnite(Tool);
73   Unite(Tool);
74   Subtract(XUni);
75 }
76
77 //=======================================================================
78 //function : Subtract
79 //purpose  :
80 //=======================================================================
81
82 void Intrv_Intervals::Subtract (const Intrv_Interval& Tool)
83 {
84   Standard_Integer index = 1;
85
86   while (index <= myInter.Length()) {
87
88     switch (Tool.Position (myInter(index))) {
89
90     case Intrv_Before :
91       index = myInter.Length();                       // sortir
92       break;
93
94     case Intrv_JustBefore :
95       myInter(index).CutAtStart
96         (Tool.End  (),Tool.TolEnd  ());               // modifier le debut
97       index = myInter.Length();                       // sortir
98       break;
99
100     case Intrv_OverlappingAtStart :
101     case Intrv_JustOverlappingAtStart :
102       myInter(index).SetStart
103         (Tool.End  (),Tool.TolEnd  ());               // garder la fin
104       index = myInter.Length();                       // sortir
105       break;
106
107     case Intrv_JustEnclosingAtEnd :
108     case Intrv_Enclosing :
109     case Intrv_Similar :
110     case Intrv_JustEnclosingAtStart :
111       myInter.Remove(index);                          // detruire et
112       index--;                                        // continuer
113       break;
114
115     case Intrv_Inside :
116       myInter.InsertAfter(index,myInter(index));
117       myInter(index  ).SetEnd
118         (Tool.Start(),Tool.TolStart());               // garder le debut
119       myInter(index+1).SetStart
120         (Tool.End  (),Tool.TolEnd  ());               // garder la fin
121       index = myInter.Length();                       // sortir
122       break;
123
124     case Intrv_JustOverlappingAtEnd :
125     case Intrv_OverlappingAtEnd :
126       myInter(index).SetEnd
127         (Tool.Start(),Tool.TolStart());               // garder le debut
128       break;                                          // continuer
129
130     case Intrv_JustAfter :
131       myInter(index).CutAtEnd
132         (Tool.Start(),Tool.TolStart());               // modifier la fin
133       break;                                          // continuer
134
135     case Intrv_After :
136       break;                                          // continuer
137
138     }
139     index++;
140   }
141 }
142
143 //=======================================================================
144 //function : Subtract
145 //purpose  :
146 //=======================================================================
147
148 void Intrv_Intervals::Subtract (const Intrv_Intervals& Tool)
149 {
150   Standard_Integer index;
151   for (index = 1; index <= Tool.myInter.Length(); index++)
152     Subtract (Tool.myInter(index));
153 }
154
155 //=======================================================================
156 //function : Unite
157 //purpose  :
158 //=======================================================================
159
160 void Intrv_Intervals::Unite (const Intrv_Interval& Tool)
161 {
162   Standard_Boolean Inserted = Standard_False;
163   Intrv_Interval Tins(Tool);
164   Standard_Integer index = 1;
165
166   while (index <= myInter.Length()) {
167
168     switch (Tins.Position (myInter(index))) {
169         
170     case Intrv_Before :
171       Inserted = Standard_True;
172       myInter.InsertBefore(index,Tins);               // inserer avant et
173       index = myInter.Length();                       // sortir
174       break;
175
176     case Intrv_JustBefore :
177     case Intrv_OverlappingAtStart :
178       Inserted = Standard_True;
179       myInter(index).SetStart
180         (Tins.Start(),Tins.TolStart());               // changer le debut
181       index = myInter.Length();                       // sortir
182       break;
183
184     case Intrv_Similar :
185       Tins.FuseAtStart(myInter(index).Start(),
186                        myInter(index).TolStart());    // modifier le debut
187       Standard_FALLTHROUGH
188     case Intrv_JustEnclosingAtEnd :
189       Tins.FuseAtEnd  (myInter(index).End  (),
190                        myInter(index).TolEnd  ());    // modifier la fin
191       Standard_FALLTHROUGH
192     case Intrv_Enclosing :
193       myInter.Remove(index);                          // detruire et
194       index--;                                        // continuer
195       break;
196
197     case Intrv_JustOverlappingAtEnd :
198       Tins.SetStart   (myInter(index).Start(),
199                        myInter(index).TolStart());    // changer le debut
200       Tins.FuseAtEnd  (myInter(index).End  (),
201                        myInter(index).TolEnd  ());    // modifier la fin
202       myInter.Remove(index);                          // detruire et
203       index--;                                        // continuer
204       break;
205
206     case Intrv_JustOverlappingAtStart :
207       Inserted = Standard_True;
208       myInter(index).FuseAtStart
209         (Tins.Start(),Tins.TolStart());               // modifier le debut
210       index = myInter.Length();                       // sortir
211       break;
212
213     case Intrv_JustEnclosingAtStart :
214       Tins.FuseAtStart(myInter(index).Start(),
215                        myInter(index).TolStart());    // modifier le debut
216       myInter.Remove(index);                          // detruire et
217       index--;                                        // continuer
218       break;
219
220     case Intrv_Inside :
221       Inserted = Standard_True;
222       index = myInter.Length();                       // sortir
223       break;
224
225     case Intrv_OverlappingAtEnd :
226     case Intrv_JustAfter :
227       Tins.SetStart(myInter(index).Start(),
228                     myInter(index).TolStart());       // changer le debut
229       myInter.Remove(index);                          // detruire et
230       index--;                                        // continuer
231       break;
232
233     case Intrv_After :
234       break;                                          // continuer
235
236     }
237     index++;
238   }
239   if ( !Inserted ) myInter.Append (Tins);
240 }
241
242 //=======================================================================
243 //function : Unite
244 //purpose  :
245 //=======================================================================
246
247 void Intrv_Intervals::Unite (const Intrv_Intervals& Tool)
248 {
249   Standard_Integer index;
250   for (index = 1; index<=Tool.myInter.Length(); index++)
251     Unite (Tool.myInter(index));
252 }
253
254 //=======================================================================
255 //function : XUnite
256 //purpose  :
257 //=======================================================================
258
259 void Intrv_Intervals::XUnite (const Intrv_Interval& Tool)
260 {
261   Intrv_Intervals Inter(Tool);
262   XUnite(Inter);
263 }
264
265 //=======================================================================
266 //function : XUnite
267 //purpose  :
268 //=======================================================================
269
270 void Intrv_Intervals::XUnite (const Intrv_Intervals& Tool)
271 {
272   Intrv_Intervals Sub2(Tool);
273   Sub2.Subtract(*this);
274   Subtract(Tool);
275   Unite(Sub2);
276 }
277