0024129: Eliminate remaining compiler warnings in MSVC++ 2008 32 bit with warning...
[occt.git] / src / TopOpeBRep / TopOpeBRep_VPointInter.cxx
1 // Created on: 1993-11-10
2 // Created by: Jean Yves LEBEY
3 // Copyright (c) 1993-1999 Matra Datavision
4 // Copyright (c) 1999-2012 OPEN CASCADE SAS
5 //
6 // The content of this file is subject to the Open CASCADE Technology Public
7 // License Version 6.5 (the "License"). You may not use the content of this file
8 // except in compliance with the License. Please obtain a copy of the License
9 // at http://www.opencascade.org and read it completely before using this file.
10 //
11 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
13 //
14 // The Original Code and all software distributed under the License is
15 // distributed on an "AS IS" basis, without warranty of any kind, and the
16 // Initial Developer hereby disclaims all such warranties, including without
17 // limitation, any warranties of merchantability, fitness for a particular
18 // purpose or non-infringement. Please see the License for the specific terms
19 // and conditions governing the rights and limitations under the License.
20
21
22 #include <TopOpeBRep_VPointInter.ixx>
23
24 #include <Standard_DomainError.hxx>
25 #include <TopOpeBRepTool_ShapeTool.hxx>
26 #include <TopOpeBRep_FFTransitionTool.hxx>
27 #include <TopOpeBRepDS_Transition.hxx>
28 #include <TopoDS_Edge.hxx>
29 #include <TopoDS_Face.hxx>
30 #include <TopoDS.hxx>
31 #include <BRepAdaptor_HCurve2d.hxx>
32 #include <BRepTopAdaptor_HVertex.hxx>
33 #include <Adaptor3d_HVertex.hxx>
34 #include <Adaptor2d_HCurve2d.hxx>
35 #include <BRepAdaptor_Curve2d.hxx>
36 #include <TCollection_AsciiString.hxx>
37 #include <gp_Pnt2d.hxx>
38 #include <Precision.hxx>
39 #include <TopOpeBRep_define.hxx>
40
41 #ifdef DEB
42 extern Standard_Boolean TopOpeBRepDS_GettraceDSFK(); 
43 static TCollection_AsciiString PRODINP("dinp ");
44 #endif
45
46 //=======================================================================
47 //function : SetPoint
48 //purpose  : 
49 //=======================================================================
50 void TopOpeBRep_VPointInter::SetPoint(const IntPatch_Point& P)
51 {
52   myPPOI = (IntPatch_Point*)&P;
53
54   Standard_Boolean isOn1 = P.IsOnDomS1(); 
55   Standard_Boolean isOn2 = P.IsOnDomS2();
56   if (isOn1 && isOn2) myShapeIndex = 3;
57   else if (isOn2)     myShapeIndex = 2;
58   else if (isOn1)     myShapeIndex = 1;
59   else                myShapeIndex = 0;
60 }
61
62 //=======================================================================
63 //function : ArcOnS1
64 //purpose  : 
65 //=======================================================================
66 const TopoDS_Shape&  TopOpeBRep_VPointInter::ArcOnS1() const
67 {
68   const Handle(Adaptor2d_HCurve2d)& HAHC2 = myPPOI->ArcOnS1();
69   const BRepAdaptor_Curve2d& BRAC2P = *((BRepAdaptor_Curve2d*)&(HAHC2->Curve2d()));
70   return BRAC2P.Edge();
71 }
72
73 //=======================================================================
74 //function : ArcOnS2
75 //purpose  : 
76 //=======================================================================
77 const TopoDS_Shape&  TopOpeBRep_VPointInter::ArcOnS2() const
78 {
79   const Handle(Adaptor2d_HCurve2d)& HAHC2 = myPPOI->ArcOnS2();
80   const BRepAdaptor_Curve2d& BRAC2P = *((BRepAdaptor_Curve2d*)&(HAHC2->Curve2d()));
81   return BRAC2P.Edge();
82 }
83
84 //=======================================================================
85 //function : VertexOnS1
86 //purpose  : 
87 //=======================================================================
88 const TopoDS_Shape& TopOpeBRep_VPointInter::VertexOnS1() const
89 {
90   if ( !myPPOI->IsVertexOnS1() )
91     Standard_DomainError::Raise("TopOpeBRep_VPointInter::VertexOnS1");
92
93   const Handle(BRepTopAdaptor_HVertex)* HBRTAHV = (Handle(BRepTopAdaptor_HVertex)*)&(myPPOI->VertexOnS1());
94   return (*HBRTAHV)->Vertex();
95 }
96
97 //=======================================================================
98 //function : VertexOnS2
99 //purpose  : 
100 //=======================================================================
101 const TopoDS_Shape& TopOpeBRep_VPointInter::VertexOnS2() const 
102 {
103   if ( !myPPOI->IsVertexOnS2() )
104     Standard_DomainError::Raise("TopOpeBRep_VPointInter::VertexOnS2");
105
106   const Handle(BRepTopAdaptor_HVertex)* HBRTAHV = (Handle(BRepTopAdaptor_HVertex)*)&(myPPOI->VertexOnS2());
107   return (*HBRTAHV)->Vertex();
108 }
109
110 //=======================================================================
111 //function : State
112 //purpose  : 
113 //=======================================================================
114 void TopOpeBRep_VPointInter::State(const TopAbs_State S,const Standard_Integer I)
115 {
116   if      (I == 1) myState1 = S;
117   else if (I == 2) myState2 = S;
118   else Standard_DomainError::Raise("TopOpeBRep_VPointInter::State");
119   UpdateKeep();
120 }
121
122 //=======================================================================
123 //function : State
124 //purpose  : 
125 //=======================================================================
126 TopAbs_State TopOpeBRep_VPointInter::State(const Standard_Integer I) const
127 {
128   if      (I == 1) return myState1;
129   else if (I == 2) return myState2;
130   else { Standard_DomainError::Raise("TopOpeBRep_VPointInter::State"); return TopAbs_UNKNOWN; }
131 }
132
133 //=======================================================================
134 //function : EdgeON
135 //purpose  : 
136 //=======================================================================
137 void TopOpeBRep_VPointInter::EdgeON(const TopoDS_Shape& Eon,const Standard_Real Par,const Standard_Integer I)
138 {
139   if      (I == 1) {
140     myEdgeON1 = Eon;
141     myEdgeONPar1 = Par;
142   }
143   else if (I == 2) {
144     myEdgeON2 = Eon;
145     myEdgeONPar2 = Par;
146   }
147 }
148
149 //=======================================================================
150 //function : EdgeON
151 //purpose  : 
152 //=======================================================================
153 const TopoDS_Shape& TopOpeBRep_VPointInter::EdgeON(const Standard_Integer I) const
154 {
155   if      (I == 1) return myEdgeON1;
156   else if (I == 2) return myEdgeON2;
157   else Standard_DomainError::Raise("TopOpeBRep_VPointInter::EdgeON");
158   return myNullShape;
159 }
160
161 //=======================================================================
162 //function : EdgeONParameter
163 //purpose  : 
164 //=======================================================================
165 Standard_Real TopOpeBRep_VPointInter::EdgeONParameter(const Standard_Integer I) const
166 {
167   if      (I == 1) return myEdgeONPar1;
168   else if (I == 2) return myEdgeONPar2;
169   else Standard_DomainError::Raise("TopOpeBRep_VPointInter::EdgeONParameter");
170   return 0.;
171 }
172
173 //=======================================================================
174 //function : Edge
175 //purpose  : 
176 //=======================================================================
177 const TopoDS_Shape& TopOpeBRep_VPointInter::Edge(const Standard_Integer I) const
178 {
179   if      (I == 1 && IsOnDomS1() ) return ArcOnS1(); 
180   else if (I == 2 && IsOnDomS2() ) return ArcOnS2(); 
181
182   return myNullShape;
183 }
184
185 //=======================================================================
186 //function : EdgeParameter
187 //purpose  : 
188 //=======================================================================
189 Standard_Real TopOpeBRep_VPointInter::EdgeParameter(const Standard_Integer I) const
190 {
191   if      (I == 1 && IsOnDomS1() ) return ParameterOnArc1();
192   else if (I == 2 && IsOnDomS2() ) return ParameterOnArc2();
193   return 0.;
194 }
195
196 //=======================================================================
197 //function : EdgeParameter
198 //purpose  : 
199 //=======================================================================
200 gp_Pnt2d TopOpeBRep_VPointInter::SurfaceParameters(const Standard_Integer I) const
201
202   Standard_Real u = 0., v = 0.;
203   //if      (I == 1 && IsOnDomS1() ) ParametersOnS1(u,v);
204   //else if (I == 2 && IsOnDomS1() ) ParametersOnS2(u,v);
205   if      (I == 1 ) ParametersOnS1(u,v);
206   else if (I == 2 ) ParametersOnS2(u,v);
207   gp_Pnt2d p2d(u,v);
208   return p2d;
209 }
210
211 //=======================================================================
212 //function : IsVertex
213 //purpose  : 
214 //=======================================================================
215 Standard_Boolean TopOpeBRep_VPointInter::IsVertex(const Standard_Integer I) const
216 {
217   if      ( I == 0 )                   return Standard_False;
218   if      ( I == 1 && IsVertexOnS1() ) return Standard_True;
219   else if ( I == 2 && IsVertexOnS2() ) return Standard_True;
220   return Standard_False;
221 }
222
223 //=======================================================================
224 //function : Vertex
225 //purpose  : 
226 //=======================================================================
227 const TopoDS_Shape& TopOpeBRep_VPointInter::Vertex(const Standard_Integer I) const
228 {
229   if      ( I == 1 && IsVertexOnS1() ) return VertexOnS1();
230   else if ( I == 2 && IsVertexOnS2() ) return VertexOnS2();
231   return myNullShape;
232 }
233
234 //=======================================================================
235 //function : UpdateKeep
236 //purpose  :
237 //=======================================================================
238 void TopOpeBRep_VPointInter::UpdateKeep() 
239 {
240 #define M_SINON(s) (((s) == TopAbs_IN) || ((s) == TopAbs_ON))
241   
242   TopAbs_State pos1 = State(1);
243   TopAbs_State pos2 = State(2);
244
245   Standard_Integer SI = ShapeIndex();
246
247   Standard_Boolean condition=Standard_False; 
248
249   if      (SI == 1) condition = M_SINON(pos2);
250   else if (SI == 2) condition = M_SINON(pos1);
251   else if (SI == 0) condition = M_SINON(pos1) && M_SINON(pos2);
252   else if (SI == 3) condition = M_SINON(pos1) && M_SINON(pos2);
253   // NYI : SI == 3 --> le VP devrait toujours etre Keep() (par definition)
254   
255   myKeep = condition;
256 }
257
258 //=======================================================================
259 //function : EqualpP
260 //purpose  : returns <True> if the 3d points and the parameters of the
261 //           VPoints are same.
262 //=======================================================================
263 Standard_Boolean TopOpeBRep_VPointInter::EqualpP(const TopOpeBRep_VPointInter& VP) const
264 {
265   Standard_Real p1 = ParameterOnLine();
266   Standard_Real p2 = VP.ParameterOnLine();      
267   Standard_Boolean pequal = fabs(p1-p2) < Precision::PConfusion();
268   gp_Pnt P1 = Value(); gp_Pnt P2 = VP.Value();
269   Standard_Real Ptol1 = Tolerance(), Ptol2 = VP.Tolerance();
270   Standard_Real Ptol = (Ptol1 > Ptol2) ? Ptol1 : Ptol2;
271   Standard_Boolean Pequal = P1.IsEqual(P2,Ptol);
272   Standard_Boolean pPequal = ( pequal && Pequal );
273   return pPequal;  
274 }
275
276 //=======================================================================
277 //function : 
278 //purpose  : 
279 //=======================================================================
280 Standard_Boolean TopOpeBRep_VPointInter::ParonE(const TopoDS_Edge& E,Standard_Real& par) const
281 {
282   Standard_Boolean found = Standard_False;
283   if (IsOnDomS1()) { 
284     if(E.IsSame(ArcOnS1())) found = Standard_True;
285     if (found) {par = ParameterOnArc1(); return found;}
286   }
287   if (IsOnDomS2()) { 
288     if(E.IsSame(ArcOnS2())) found = Standard_True;
289     if (found) {par = ParameterOnArc2(); return found;}
290   }
291
292   for (Standard_Integer i = 1; i <= 2; i++) {
293     if (State(i) != TopAbs_ON) continue;
294     if (EdgeON(i).IsSame(E)) {
295       par = EdgeONParameter(i); 
296       return Standard_True;
297     }
298   }
299   return found;
300 }
301
302 //=======================================================================
303 //function : DumpEdge
304 //purpose  : 
305 //=======================================================================
306 Standard_OStream& TopOpeBRep_VPointInter::Dump(const Standard_Integer I,const TopoDS_Face& F,Standard_OStream& OS) const
307 {
308   const TopoDS_Edge& E = TopoDS::Edge(Edge(I)); 
309 #ifdef DEB
310   Standard_Real Epar =
311 #endif
312              EdgeParameter(I); 
313 #ifdef DEB
314   TopAbs_Orientation O =
315 #endif
316            E.Orientation();
317 #ifdef DEB
318   Standard_Boolean closingedge = 
319 #endif
320                     TopOpeBRepTool_ShapeTool::Closed(E,F);
321
322 #ifdef DEB
323   if (closingedge) OS<<"on closing edge "; else OS<<"on edge "; TopAbs::Print(O,cout);
324   cout<<" of "<<I<<" : par : "<<Epar<<endl;
325   TopOpeBRepDS_Transition T = TopOpeBRep_FFTransitionTool::ProcessLineTransition(*this,I,O);
326   OS<<"line transition ";
327   if (closingedge) OS<<"on closing edge "; else OS<<"on edge "; TopAbs::Print(O,cout);
328   OS<<" of "<<I<<" : "; T.Dump(OS);OS<<endl;
329 #endif
330   
331   return OS;
332 }
333
334 //=======================================================================
335 //function : Dump
336 //purpose  : 
337 //=======================================================================
338 #ifdef DEB
339 Standard_OStream& TopOpeBRep_VPointInter::Dump(const TopoDS_Face& FF1,const TopoDS_Face& FF2,Standard_OStream& OS) const
340 {
341   const TopoDS_Face& F1 = TopoDS::Face(FF1);
342   const TopoDS_Face& F2 = TopoDS::Face(FF2);
343   OS<<"VP "<<myIndex<<" on "<<myShapeIndex<<" :";
344   Standard_Real Cpar = ParameterOnLine(); OS<<" on curve : "<<Cpar; 
345   if (!myKeep) OS<<" NOT kept";
346   OS<<endl;
347   const gp_Pnt& P = Value(); 
348   OS<<PRODINP<<"P"<<myIndex<<" "; OS<<P.X()<<" "<<P.Y()<<" "<<P.Z();
349   OS<<"; #draw"<<endl;
350    
351   if (TopOpeBRepDS_GettraceDSFK()) { Standard_Real u,v;
352     ParametersOnS1(u,v); OS<<"u1,v1 : "<<u<<" "<<v; OS<<"   ";
353     ParametersOnS2(u,v); OS<<"u2,v2 : "<<u<<" "<<v; OS<<endl;
354   }
355   
356   if (IsVertexOnS1()) { OS<<"is vertex of 1"<<endl; }
357   if (IsVertexOnS2()) { OS<<"is vertex of 2"<<endl; }
358   if (IsMultiple())   { OS<<"is multiple"<<endl; }
359   if (IsInternal())   { OS<<"is internal"<<endl; }
360
361   if      (myShapeIndex == 1) { 
362     Dump(1,F1,OS); 
363   }
364   else if (myShapeIndex == 2) { 
365     Dump(2,F2,OS); 
366   }
367   else if (myShapeIndex == 3) { 
368     Dump(1,F1,OS);
369     Dump(2,F2,OS); 
370   }
371 #else
372 Standard_OStream& TopOpeBRep_VPointInter::Dump(const TopoDS_Face&,const TopoDS_Face&,Standard_OStream& OS) const
373 {
374 #endif
375
376   return OS;
377 }
378
379 //=======================================================================
380 //function : PThePointOfIntersectionDummy
381 //purpose  : 
382 //=======================================================================
383 TopOpeBRep_PThePointOfIntersection TopOpeBRep_VPointInter::PThePointOfIntersectionDummy() const
384 {
385   return myPPOI;
386 }