1 // Created on: 1991-06-24
2 // Created by: Didier PIFFAULT
3 // Copyright (c) 1991-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
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.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
19 #include <gp_Pnt2d.hxx>
20 #include <Intf_Interference.hxx>
21 #include <Intf_SectionLine.hxx>
22 #include <Intf_SectionPoint.hxx>
23 #include <Intf_TangentZone.hxx>
24 #include <Standard_OutOfRange.hxx>
26 //=======================================================================
27 //function : Intf_Interference
28 //purpose : Initialize for a deferred interference.
29 //=======================================================================
30 Intf_Interference::Intf_Interference (const Standard_Boolean Self)
35 //=======================================================================
36 //function : SelfInterference
37 //purpose : Reset interference before perform with a new...
38 //=======================================================================
40 void Intf_Interference::SelfInterference (const Standard_Boolean Self)
49 //=======================================================================
51 //purpose : Insert a tangent zone in the list of the interference
52 //=======================================================================
54 Standard_Boolean Intf_Interference::Insert(const Intf_TangentZone& LaZone)
56 if (myTZones.Length()<=0) return Standard_False;
57 Standard_Integer lzin=0; // Index in the list of the zone of interest.
58 Standard_Integer lunp=0; // Index of the 1st stop point in this zone.
59 Standard_Integer lotp=0; // Index of the 2nd stop point in this zone.
60 Standard_Integer lunl=0; // Index of the 1st point of the new zone.
61 Standard_Integer lotl=0; // Index of the 2nd point of the new zone.
62 Standard_Boolean same=Standard_False; // Search direction of the stop of the new zone.
63 Standard_Boolean Inserted=Standard_True; // Has the insertion succeeded ?
64 Standard_Integer npcz=-1; // Number of points in the current zone
65 Standard_Integer nplz=LaZone.NumberOfPoints(); // in the new zone
67 // Loop on TangentZone :
68 for (Standard_Integer Iz=1; Iz<=myTZones.Length(); Iz++) {
70 // Loop on edges of the TangentZone :
71 npcz=myTZones(Iz).NumberOfPoints();
72 Standard_Integer Ipz0, Ipz1, Ipz2;
73 for (Ipz1=1; Ipz1<=npcz; Ipz1++) {
75 if (Ipz0<=0) Ipz0=npcz;
78 // Loop on edges of the new TangentZone and search of the
79 // corresponding point or edge:
80 Standard_Integer Ilz1, Ilz2;
81 for (Ilz1=1; Ilz1<=nplz; Ilz1++) {
84 if ((myTZones(Iz).GetPoint(Ipz1)).IsEqual
85 (LaZone.GetPoint(Ilz1))) {
86 if ((myTZones(Iz).GetPoint(Ipz0)).IsEqual
87 (LaZone.GetPoint(Ilz2))) {
96 else if ((myTZones(Iz).GetPoint(Ipz2)).IsEqual
97 (LaZone.GetPoint(Ilz2))) {
118 Standard_Integer Ilc;
120 for (Ilc=lotl+1; (((Ilc-1)%nplz)+1)!=lunl; Ilc++) {
121 myTZones(lzin).InsertBefore
122 (lotp, LaZone.GetPoint(((Ilc-1)%nplz)+1));
128 Standard_Boolean loop=Standard_False;
129 for (Ilc=lunl; ; Ilc++) {
130 myTZones(lzin).InsertBefore(lunp,
131 LaZone.GetPoint((((Ilc-1)%nplz)+1)));
133 if (loop && (((Ilc-1)%nplz)+1)==lunl) break;
139 Inserted =Standard_False;
143 Intf_TangentZone theNew=myTZones(lzin);
144 myTZones.Remove(lzin);
146 myTZones.Append(theNew);
151 //=======================================================================
154 //=======================================================================
156 void Intf_Interference::Insert(const Intf_SectionPoint& pdeb,
157 const Intf_SectionPoint& pfin)
159 Standard_Boolean Inserted=Standard_False;
160 Standard_Integer TheLS=0;
161 Standard_Boolean Begin=Standard_False;
162 Intf_SectionPoint TheBout(pfin);
163 Standard_Integer ils, nd, nf;
165 for (ils=1; ils<=mySLines.Length(); ils++) {
166 Intf_SectionLine& SL=mySLines(ils);
170 if (nf>1) SL.Close();
171 Inserted=Standard_True;
177 if (nf==1) SL.Close();
178 Inserted=Standard_True;
180 Begin=Standard_False;
184 Inserted=Standard_True;
191 Inserted=Standard_True;
193 Begin=Standard_False;
200 Intf_SectionLine LaLS;
203 mySLines.Append(LaLS);
207 for (ils=1; ils<=mySLines.Length(); ils++) {
209 nd=mySLines(ils).IsEnd(TheBout);
212 mySLines(TheLS).Reverse();
214 mySLines(ils).Prepend(mySLines(TheLS));
219 mySLines(TheLS).Reverse();
221 mySLines(ils).Append(mySLines(TheLS));
227 mySLines.Remove(TheLS);
231 mySLines(TheLS).Prepend(TheBout);
233 mySLines(TheLS).Append(TheBout);
240 //----------------------------------------------------
242 //----------------------------------------------------
243 Standard_Boolean Intf_Interference::Contains
244 (const Intf_SectionPoint& LePnt) const
247 for (Standard_Integer l=1; l<=mySLines.Length(); l++) {
248 if (mySLines(l).Contains(LePnt)) return Standard_True;
250 for (Standard_Integer t=1; t<=myTZones.Length(); t++) {
251 //-- myTZones(t).Dump(2);
252 if (myTZones(t).Contains(LePnt)) return Standard_True;
254 return Standard_False;
258 //----------------------------------------------------
260 //----------------------------------------------------
261 void Intf_Interference::Dump() const
263 cout << "Mes SectionPoint :" << endl;
264 for (Standard_Integer p=1; p<=mySPoins.Length(); p++) {
267 cout << "Mes SectionLine :" << endl;
268 for (Standard_Integer l=1; l<=mySLines.Length(); l++) {
271 cout << "Mes TangentZone :" << endl;
272 for (Standard_Integer t=1; t<=myTZones.Length(); t++) {