0024428: Implementation of LGPL license
[occt.git] / src / IntPatch / IntPatch_RLine.cxx
1 // Created on: 1992-04-06
2 // Created by: Jacques GOUSSARD
3 // Copyright (c) 1992-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
9 // under the terms of the GNU Lesser General Public 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 #include <IntPatch_RLine.ixx>
18
19 #include <IntSurf_PntOn2S.hxx>
20 #include <Precision.hxx>
21
22 IntPatch_RLine::IntPatch_RLine (const Standard_Boolean Tang,
23                                 const IntSurf_TypeTrans Trans1,
24                                 const IntSurf_TypeTrans Trans2) :
25   IntPatch_Line(Tang,Trans1,Trans2),
26   fipt(Standard_False),lapt(Standard_False)
27
28 {
29   typ = IntPatch_Restriction;
30   onS2=Standard_False;
31   onS1=Standard_False;
32 }
33
34
35 IntPatch_RLine::IntPatch_RLine (const Standard_Boolean Tang,
36                                 const IntSurf_Situation Situ1,
37                                 const IntSurf_Situation Situ2) :
38   IntPatch_Line(Tang,Situ1,Situ2),
39   fipt(Standard_False),lapt(Standard_False)
40 {
41   typ = IntPatch_Restriction;
42   onS2=Standard_False;
43   onS1=Standard_False;
44 }
45
46
47 IntPatch_RLine::IntPatch_RLine (const Standard_Boolean Tang) :
48   IntPatch_Line(Tang),
49   fipt(Standard_False),lapt(Standard_False)
50
51 {
52   typ = IntPatch_Restriction;
53   onS2=Standard_False;
54   onS1=Standard_False;
55 }
56
57 void IntPatch_RLine::ParamOnS1(Standard_Real& a,Standard_Real& b) const { 
58   if(onS1) { 
59     a=RealLast(); b=-a;
60     for(Standard_Integer i=svtx.Length();i>=1;i--) { 
61       Standard_Real p=svtx(i).ParameterOnLine();
62       if(p<a) a=p;
63       if(p>b) b=p;
64     }
65   }
66   else { 
67     a=b=0.0;
68   }
69 }
70
71 void IntPatch_RLine::ParamOnS2(Standard_Real& a,Standard_Real& b) const { 
72   if(onS2) { 
73     a=RealLast(); b=-a;
74     for(Standard_Integer i=svtx.Length();i>=1;i--) { 
75       Standard_Real p=svtx(i).ParameterOnLine();
76       if(p<a) a=p;
77       if(p>b) b=p;
78     }
79   }
80   else { 
81     a=b=0.0;
82   }
83 }
84
85
86 void IntPatch_RLine::SetArcOnS1(const Handle(Adaptor2d_HCurve2d)& A) { 
87   theArcOnS1 = A;
88   onS1=Standard_True;
89 }
90
91 void IntPatch_RLine::SetArcOnS2(const Handle(Adaptor2d_HCurve2d)& A) { 
92   theArcOnS2 = A;
93   onS2=Standard_True;
94 }
95
96
97 void IntPatch_RLine::SetPoint(const Standard_Integer Index,
98                               const IntPatch_Point& thepoint) { 
99   curv->Value(Index,thepoint.PntOn2S());
100 }
101
102 //void IntPatch_RLine::ComputeVertexParameters(const Standard_Real Tol)
103 void IntPatch_RLine::ComputeVertexParameters(const Standard_Real )
104 {
105   Standard_Integer i,j,nbvtx;//k;
106   
107   Standard_Real ParamMinOnLine,ParamMaxOnLine;
108   if(fipt) { ParamMinOnLine = Vertex(indf).ParameterOnLine(); } else { ParamMinOnLine = -100000.0; } 
109   if(lapt) { ParamMaxOnLine = Vertex(indl).ParameterOnLine(); } else { ParamMaxOnLine =  100000.0; } 
110   Standard_Boolean APointDeleted = Standard_False;
111   //----------------------------------------------------------
112   //--     F i l t r e   s u r   r e s t r i c t i o n s   --
113   //----------------------------------------------------------
114   //-- deux vertex sur la meme restriction et seulement 
115   //-- sur celle ci ne doivent pas avoir le meme parametre
116   //--
117   nbvtx = NbVertex();
118   do { 
119     APointDeleted = Standard_False;
120     for(i=1; (i<=nbvtx) && (APointDeleted==Standard_False) ;i++) { 
121       const IntPatch_Point& VTXi   = svtx.Value(i);
122       if((VTXi.IsOnDomS1()==Standard_True) && (VTXi.IsOnDomS2()==Standard_False)) { 
123         for(j=1; (j<=nbvtx) && (APointDeleted==Standard_False) ;j++) {
124           if(i!=j) { 
125             const IntPatch_Point& VTXj   = svtx.Value(j);
126             if((VTXj.IsOnDomS1()==Standard_True) && (VTXj.IsOnDomS2()==Standard_False)) {
127               if(VTXi.ParameterOnLine() == VTXj.ParameterOnLine()) { 
128                 if(VTXi.ArcOnS1() == VTXj.ArcOnS1()) { 
129                   if(VTXi.ParameterOnArc1() == VTXj.ParameterOnArc1()) { 
130                     svtx.Remove(j);
131                     nbvtx--;
132                     if(lapt) { if(indl>=j) indl--; } 
133                     if(fipt) { if(indf>=j) indf--; } 
134                     APointDeleted = Standard_True;
135                   }
136                 }
137               }
138             }
139           }
140         }
141       }
142     }
143   }
144   while(APointDeleted == Standard_True);
145
146   do { 
147     APointDeleted = Standard_False;
148     for(i=1; (i<=nbvtx) && (APointDeleted==Standard_False) ;i++) { 
149       const IntPatch_Point& VTXi   = svtx.Value(i);
150       if((VTXi.IsOnDomS2()==Standard_True) && (VTXi.IsOnDomS1()==Standard_False)) { 
151         for(j=1; (j<=nbvtx) && (APointDeleted==Standard_False) ;j++) {
152           if(i!=j) { 
153             const IntPatch_Point& VTXj   = svtx.Value(j);
154             if((VTXj.IsOnDomS2()==Standard_True) && (VTXj.IsOnDomS1()==Standard_False)) {
155               if(VTXi.ParameterOnLine() == VTXj.ParameterOnLine()) { 
156                 if(VTXi.ArcOnS2() == VTXj.ArcOnS2()) { 
157                   if(VTXi.ParameterOnArc2() == VTXj.ParameterOnArc2()) { 
158                     svtx.Remove(j);
159                     nbvtx--;
160                     if(lapt) { if(indl>=j) indl--; } 
161                     if(fipt) { if(indf>=j) indf--; } 
162                     APointDeleted = Standard_True;
163                   }
164                 }
165               }
166             }
167           }
168         }
169       }
170     }
171   }
172   while(APointDeleted == Standard_True);
173         
174   nbvtx     = NbVertex();
175
176   //----------------------------------------------------
177   //-- On trie les Vertex 
178   Standard_Boolean SortIsOK;
179   do { 
180     SortIsOK = Standard_True;
181     for(i=2; i<=nbvtx; i++) { 
182       if(svtx.Value(i-1).ParameterOnLine()  > svtx.Value(i).ParameterOnLine()) { 
183         SortIsOK = Standard_False;
184         svtx.Exchange(i-1,i);
185       }
186     }
187   }
188   while(!SortIsOK);
189   
190   do {  
191     APointDeleted = Standard_False;
192     Standard_Boolean restrdiff;
193     for(i=1; i<=nbvtx && (APointDeleted == Standard_False); i++) { 
194       const IntPatch_Point& VTX   = svtx.Value(i);      
195       for(j=1; j<=nbvtx && (APointDeleted == Standard_False) ; j++) { 
196         if(i!=j) { 
197           const IntPatch_Point& VTXM1 = svtx.Value(j);
198           
199           Standard_Boolean kill   = Standard_False;
200           Standard_Boolean killm1 = Standard_False;
201
202           if(VTXM1.ParameterOnLine() == VTX.ParameterOnLine()) { 
203             restrdiff=Standard_False;
204             if(VTXM1.IsOnDomS1() && VTX.IsOnDomS1()) {  //-- OnS1    OnS1
205               if(VTXM1.ArcOnS1() == VTX.ArcOnS1()) {    //-- OnS1 == OnS1
206                 if(VTX.ParameterOnArc1() == VTXM1.ParameterOnArc1()) { 
207                   if(VTXM1.IsOnDomS2()) {                 //-- OnS1 == OnS1  OnS2  
208                     if(VTX.IsOnDomS2()==Standard_False) {   //-- OnS1 == OnS1  OnS2 PasOnS2
209                       kill=Standard_True;   
210                     }
211                     else {
212                       if(VTXM1.ArcOnS2() == VTX.ArcOnS2()) { //-- OnS1 == OnS1  OnS2 == OnS2
213                         if(VTX.ParameterOnArc2() == VTXM1.ParameterOnArc2()) { 
214                           kill=Standard_True;
215                         }
216                       }
217                     }
218                   }
219                   else {                                  //-- OnS1 == OnS1  PasOnS2  
220                     if(VTX.IsOnDomS2()) {                 //-- OnS1 == OnS1  PasOnS2  OnS2
221                       killm1=Standard_True;
222                     }
223                   }
224                 }
225               }
226               else { 
227                 restrdiff=Standard_True;
228               }
229             }
230             
231             if((restrdiff==Standard_False) && (!(kill || killm1))) {
232               if(VTXM1.IsOnDomS2() && VTX.IsOnDomS2()) {  //-- OnS2    OnS2
233                 if(VTXM1.ArcOnS2() == VTX.ArcOnS2()) {    //-- OnS2 == OnS2
234                   if(VTX.ParameterOnArc2() == VTXM1.ParameterOnArc2()) { 
235                     if(VTXM1.IsOnDomS1()) {                 //-- OnS2 == OnS2  OnS1  
236                       if(VTX.IsOnDomS1()==Standard_False) {   //-- OnS2 == OnS2  OnS1 PasOnS1
237                         kill=Standard_True;   
238                       }
239                       else {
240                         if(VTXM1.ArcOnS1() == VTX.ArcOnS1()) { //-- OnS2 == OnS2  OnS1 == OnS1
241                           if(VTX.ParameterOnArc1() == VTXM1.ParameterOnArc1()) { 
242                             kill=Standard_True;
243                           }
244                         }
245                       }
246                     }
247                     else {                                  //-- OnS2 == OnS2  PasOnS1  
248                       if(VTX.IsOnDomS1()) {                 //-- OnS2 == OnS2  PasOnS1  OnS1
249                         killm1=Standard_True;
250                       }
251                     }
252                   }
253                 }
254                 else { 
255                   restrdiff=Standard_True;
256                 }
257               }
258             }
259             if(restrdiff==Standard_False) { 
260               if(kill) { 
261                 APointDeleted = Standard_True;
262                 svtx.Remove(i);
263                 nbvtx--;
264               }
265               else if(killm1) { 
266                 APointDeleted = Standard_True;
267                 svtx.Remove(j);
268                 nbvtx--; 
269               }
270             }
271           }
272         }
273       }
274     }
275   }
276   while(APointDeleted == Standard_True);
277   
278   do {  
279     SortIsOK = Standard_True;
280     for(i=2; i<=nbvtx && SortIsOK; i++) {
281       const IntPatch_Point& Pim1=svtx.Value(i-1);
282       const IntPatch_Point& Pii  =svtx.Value(i);
283       if(Pim1.ParameterOnLine()==Pii.ParameterOnLine()) { 
284         if(   (Pii.IsOnDomS1() == Standard_False)
285            && (Pii.IsOnDomS2() == Standard_False)) { 
286           SortIsOK = Standard_False;
287           svtx.Remove(i);
288           nbvtx--;
289         }
290         else {
291           if(   (Pim1.IsOnDomS1() == Standard_False)
292              && (Pim1.IsOnDomS2() == Standard_False)) { 
293             SortIsOK = Standard_False;
294             svtx.Remove(i-1);
295             nbvtx--;
296           }       
297         }
298       }
299     }
300   }
301   while(!SortIsOK);
302   
303   //----------------------------------------------------
304   //-- On trie les Vertex ( Cas Bizarre )
305   nbvtx = NbVertex();
306   do { 
307     SortIsOK = Standard_True;
308     for(i=2; i<=nbvtx; i++) { 
309       if(svtx.Value(i-1).ParameterOnLine()  > svtx.Value(i).ParameterOnLine()) { 
310         SortIsOK = Standard_False;
311         svtx.Exchange(i-1,i);
312       }
313     }
314   }
315   while(!SortIsOK);
316
317
318   SetFirstPoint(1);
319   SetLastPoint(nbvtx);
320
321
322 #if 0 
323   Standard_Boolean SortIsOK;
324   Standard_Integer nbvtx = NbVertex();
325   do { 
326     SortIsOK = Standard_True;
327     for(Standard_Integer i=2; i<=nbvtx; i++) { 
328       if(svtx.Value(i-1).ParameterOnLine()  > svtx.Value(i).ParameterOnLine()) { 
329         SortIsOK = Standard_False;
330         svtx.Exchange(i,i-1);
331         if(fipt) {
332           if(indf == i)           indf = i-1;
333           else if(indf == (i-1))  indf = i;
334         }
335         if(lapt) {
336           if(indl == i)           indl = i-1;
337           else if(indl == (i-1))  indl = i;
338         }
339       }
340     }
341   }
342   while(!SortIsOK);
343 #endif
344 }
345
346
347
348