summaryrefslogtreecommitdiff
path: root/src/TopOpeBRep/TopOpeBRep_VPointInter.cxx
blob: 3e180ca8d77b26be6c31de66e068268d867589af (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
// File:	TopOpeBRep_VPointInter.cxx
// Created:	Wed Nov 10 18:56:49 1993
// Author:	Jean Yves LEBEY
// Copyright: OPEN CASCADE 1993

#include <TopOpeBRep_VPointInter.ixx>

#include <Standard_DomainError.hxx>
#include <TopOpeBRepTool_ShapeTool.hxx>
#include <TopOpeBRep_FFTransitionTool.hxx>
#include <TopOpeBRepDS_Transition.hxx>
#include <TopoDS_Edge.hxx>
#include <TopoDS_Face.hxx>
#include <TopoDS.hxx>
#include <BRepAdaptor_HCurve2d.hxx>
#include <BRepTopAdaptor_HVertex.hxx>
#include <Adaptor3d_HVertex.hxx>
#include <Adaptor2d_HCurve2d.hxx>
#include <BRepAdaptor_Curve2d.hxx>
#include <TCollection_AsciiString.hxx>
#include <gp_Pnt2d.hxx>
#include <Precision.hxx>
#include <TopOpeBRep_define.hxx>

#ifdef DEB
Standard_IMPORT Standard_Boolean TopOpeBRepDS_GettraceDSFK(); 
static TCollection_AsciiString PRODINP("dinp ");
#endif

//=======================================================================
//function : SetPoint
//purpose  : 
//=======================================================================
void TopOpeBRep_VPointInter::SetPoint(const IntPatch_Point& P)
{
  myPPOI = (IntPatch_Point*)&P;

  Standard_Boolean isOn1 = P.IsOnDomS1(); 
  Standard_Boolean isOn2 = P.IsOnDomS2();
  if (isOn1 && isOn2) myShapeIndex = 3;
  else if (isOn2)     myShapeIndex = 2;
  else if (isOn1)     myShapeIndex = 1;
  else                myShapeIndex = 0;
}

//=======================================================================
//function : ArcOnS1
//purpose  : 
//=======================================================================
const TopoDS_Shape&  TopOpeBRep_VPointInter::ArcOnS1() const
{
  const Handle(Adaptor2d_HCurve2d)& HAHC2 = myPPOI->ArcOnS1();
  const BRepAdaptor_Curve2d& BRAC2P = *((BRepAdaptor_Curve2d*)&(HAHC2->Curve2d()));
  return BRAC2P.Edge();
}

//=======================================================================
//function : ArcOnS2
//purpose  : 
//=======================================================================
const TopoDS_Shape&  TopOpeBRep_VPointInter::ArcOnS2() const
{
  const Handle(Adaptor2d_HCurve2d)& HAHC2 = myPPOI->ArcOnS2();
  const BRepAdaptor_Curve2d& BRAC2P = *((BRepAdaptor_Curve2d*)&(HAHC2->Curve2d()));
  return BRAC2P.Edge();
}

//=======================================================================
//function : VertexOnS1
//purpose  : 
//=======================================================================
const TopoDS_Shape& TopOpeBRep_VPointInter::VertexOnS1() const
{
  if ( !myPPOI->IsVertexOnS1() )
    Standard_DomainError::Raise("TopOpeBRep_VPointInter::VertexOnS1");

  const Handle(BRepTopAdaptor_HVertex)* HBRTAHV = (Handle(BRepTopAdaptor_HVertex)*)&(myPPOI->VertexOnS1());
  return (*HBRTAHV)->Vertex();
}

//=======================================================================
//function : VertexOnS2
//purpose  : 
//=======================================================================
const TopoDS_Shape& TopOpeBRep_VPointInter::VertexOnS2() const 
{
  if ( !myPPOI->IsVertexOnS2() )
    Standard_DomainError::Raise("TopOpeBRep_VPointInter::VertexOnS2");

  const Handle(BRepTopAdaptor_HVertex)* HBRTAHV = (Handle(BRepTopAdaptor_HVertex)*)&(myPPOI->VertexOnS2());
  return (*HBRTAHV)->Vertex();
}

//=======================================================================
//function : State
//purpose  : 
//=======================================================================
void TopOpeBRep_VPointInter::State(const TopAbs_State S,const Standard_Integer I)
{
  if      (I == 1) myState1 = S;
  else if (I == 2) myState2 = S;
  else Standard_DomainError::Raise("TopOpeBRep_VPointInter::State");
  UpdateKeep();
}

//=======================================================================
//function : State
//purpose  : 
//=======================================================================
TopAbs_State TopOpeBRep_VPointInter::State(const Standard_Integer I) const
{
  if      (I == 1) return myState1;
  else if (I == 2) return myState2;
  else { Standard_DomainError::Raise("TopOpeBRep_VPointInter::State"); return TopAbs_UNKNOWN; }
}

//=======================================================================
//function : EdgeON
//purpose  : 
//=======================================================================
void TopOpeBRep_VPointInter::EdgeON(const TopoDS_Shape& Eon,const Standard_Real Par,const Standard_Integer I)
{
  if      (I == 1) {
    myEdgeON1 = Eon;
    myEdgeONPar1 = Par;
  }
  else if (I == 2) {
    myEdgeON2 = Eon;
    myEdgeONPar2 = Par;
  }
}

//=======================================================================
//function : EdgeON
//purpose  : 
//=======================================================================
const TopoDS_Shape& TopOpeBRep_VPointInter::EdgeON(const Standard_Integer I) const
{
  if      (I == 1) return myEdgeON1;
  else if (I == 2) return myEdgeON2;
  else Standard_DomainError::Raise("TopOpeBRep_VPointInter::EdgeON");
  return myNullShape;
}

//=======================================================================
//function : EdgeONParameter
//purpose  : 
//=======================================================================
Standard_Real TopOpeBRep_VPointInter::EdgeONParameter(const Standard_Integer I) const
{
  if      (I == 1) return myEdgeONPar1;
  else if (I == 2) return myEdgeONPar2;
  else Standard_DomainError::Raise("TopOpeBRep_VPointInter::EdgeONParameter");
  return 0.;
}

//=======================================================================
//function : Edge
//purpose  : 
//=======================================================================
const TopoDS_Shape& TopOpeBRep_VPointInter::Edge(const Standard_Integer I) const
{
  if      (I == 1 && IsOnDomS1() ) return ArcOnS1(); 
  else if (I == 2 && IsOnDomS2() ) return ArcOnS2(); 

  return myNullShape;
}

//=======================================================================
//function : EdgeParameter
//purpose  : 
//=======================================================================
Standard_Real TopOpeBRep_VPointInter::EdgeParameter(const Standard_Integer I) const
{
  if      (I == 1 && IsOnDomS1() ) return ParameterOnArc1();
  else if (I == 2 && IsOnDomS2() ) return ParameterOnArc2();
  return 0.;
}

//=======================================================================
//function : EdgeParameter
//purpose  : 
//=======================================================================
gp_Pnt2d TopOpeBRep_VPointInter::SurfaceParameters(const Standard_Integer I) const
{ 
  Standard_Real u = 0., v = 0.;
  //if      (I == 1 && IsOnDomS1() ) ParametersOnS1(u,v);
  //else if (I == 2 && IsOnDomS1() ) ParametersOnS2(u,v);
  if      (I == 1 ) ParametersOnS1(u,v);
  else if (I == 2 ) ParametersOnS2(u,v);
  gp_Pnt2d p2d(u,v);
  return p2d;
}

//=======================================================================
//function : IsVertex
//purpose  : 
//=======================================================================
Standard_Boolean TopOpeBRep_VPointInter::IsVertex(const Standard_Integer I) const
{
  if      ( I == 0 )                   return Standard_False;
  if      ( I == 1 && IsVertexOnS1() ) return Standard_True;
  else if ( I == 2 && IsVertexOnS2() ) return Standard_True;
  return Standard_False;
}

//=======================================================================
//function : Vertex
//purpose  : 
//=======================================================================
const TopoDS_Shape& TopOpeBRep_VPointInter::Vertex(const Standard_Integer I) const
{
  if      ( I == 1 && IsVertexOnS1() ) return VertexOnS1();
  else if ( I == 2 && IsVertexOnS2() ) return VertexOnS2();
  return myNullShape;
}

//=======================================================================
//function : UpdateKeep
//purpose  :
//=======================================================================
void TopOpeBRep_VPointInter::UpdateKeep() 
{
#define M_SINON(s) (((s) == TopAbs_IN) || ((s) == TopAbs_ON))
  
  TopAbs_State pos1 = State(1);
  TopAbs_State pos2 = State(2);

  Standard_Integer SI = ShapeIndex();

#ifdef DEB
  Standard_Boolean condition; 
#else
  Standard_Boolean condition=Standard_False; 
#endif
  if      (SI == 1) condition = M_SINON(pos2);
  else if (SI == 2) condition = M_SINON(pos1);
  else if (SI == 0) condition = M_SINON(pos1) && M_SINON(pos2);
  else if (SI == 3) condition = M_SINON(pos1) && M_SINON(pos2);
  // NYI : SI == 3 --> le VP devrait toujours etre Keep() (par definition)
  
  myKeep = condition;
}

//=======================================================================
//function : EqualpP
//purpose  : returns <True> if the 3d points and the parameters of the
//           VPoints are same.
//=======================================================================
Standard_Boolean TopOpeBRep_VPointInter::EqualpP(const TopOpeBRep_VPointInter& VP) const
{
  Standard_Real p1 = ParameterOnLine();
  Standard_Real p2 = VP.ParameterOnLine();      
  Standard_Boolean pequal = fabs(p1-p2) < Precision::PConfusion();
  gp_Pnt P1 = Value(); gp_Pnt P2 = VP.Value();
  Standard_Real Ptol1 = Tolerance(), Ptol2 = VP.Tolerance();
  Standard_Real Ptol = (Ptol1 > Ptol2) ? Ptol1 : Ptol2;
  Standard_Boolean Pequal = P1.IsEqual(P2,Ptol);
  Standard_Boolean pPequal = ( pequal && Pequal );
  return pPequal;  
}

//=======================================================================
//function : 
//purpose  : 
//=======================================================================
Standard_Boolean TopOpeBRep_VPointInter::ParonE(const TopoDS_Edge& E,Standard_Real& par) const
{
  Standard_Boolean found = Standard_False;
  if (IsOnDomS1()) { 
    if(E.IsSame(ArcOnS1())) found = Standard_True;
    if (found) {par = ParameterOnArc1(); return found;}
  }
  if (IsOnDomS2()) { 
    if(E.IsSame(ArcOnS2())) found = Standard_True;
    if (found) {par = ParameterOnArc2(); return found;}
  }

  for (Standard_Integer i = 1; i <= 2; i++) {
    if (State(i) != TopAbs_ON) continue;
    if (EdgeON(i).IsSame(E)) {
      par = EdgeONParameter(i); 
      return Standard_True;
    }
  }
  return found;
}

//=======================================================================
//function : DumpEdge
//purpose  : 
//=======================================================================
Standard_OStream& TopOpeBRep_VPointInter::Dump(const Standard_Integer I,const TopoDS_Face& F,Standard_OStream& OS) const
{
  const TopoDS_Edge& E = TopoDS::Edge(Edge(I)); 
#ifdef DEB
  Standard_Real Epar =
#endif
             EdgeParameter(I); 
#ifdef DEB
  TopAbs_Orientation O =
#endif
           E.Orientation();
#ifdef DEB
  Standard_Boolean closingedge = 
#endif
                    TopOpeBRepTool_ShapeTool::Closed(E,F);

#ifdef DEB
  if (closingedge) OS<<"on closing edge "; else OS<<"on edge "; TopAbs::Print(O,cout);
  cout<<" of "<<I<<" : par : "<<Epar<<endl;
  TopOpeBRepDS_Transition T = TopOpeBRep_FFTransitionTool::ProcessLineTransition(*this,I,O);
  OS<<"line transition ";
  if (closingedge) OS<<"on closing edge "; else OS<<"on edge "; TopAbs::Print(O,cout);
  OS<<" of "<<I<<" : "; T.Dump(OS);OS<<endl;
#endif
  
  return OS;
}

//=======================================================================
//function : Dump
//purpose  : 
//=======================================================================
Standard_OStream& TopOpeBRep_VPointInter::Dump(const TopoDS_Face& FF1,const TopoDS_Face& FF2,Standard_OStream& OS) const
{
#ifdef DEB
  const TopoDS_Face& F1 = TopoDS::Face(FF1);
  const TopoDS_Face& F2 = TopoDS::Face(FF2);
  OS<<"VP "<<myIndex<<" on "<<myShapeIndex<<" :";
  Standard_Real Cpar = ParameterOnLine(); OS<<" on curve : "<<Cpar; 
  if (!myKeep) OS<<" NOT kept";
  OS<<endl;
  const gp_Pnt& P = Value(); 
  OS<<PRODINP<<"P"<<myIndex<<" "; OS<<P.X()<<" "<<P.Y()<<" "<<P.Z();
  OS<<"; #draw"<<endl;
   
  if (TopOpeBRepDS_GettraceDSFK()) { Standard_Real u,v;
    ParametersOnS1(u,v); OS<<"u1,v1 : "<<u<<" "<<v; OS<<"   ";
    ParametersOnS2(u,v); OS<<"u2,v2 : "<<u<<" "<<v; OS<<endl;
  }
  
  if (IsVertexOnS1()) { OS<<"is vertex of 1"<<endl; }
  if (IsVertexOnS2()) { OS<<"is vertex of 2"<<endl; }
  if (IsMultiple())   { OS<<"is multiple"<<endl; }
  if (IsInternal())   { OS<<"is internal"<<endl; }

  if      (myShapeIndex == 1) { 
    Dump(1,F1,OS); 
  }
  else if (myShapeIndex == 2) { 
    Dump(2,F2,OS); 
  }
  else if (myShapeIndex == 3) { 
    Dump(1,F1,OS);
    Dump(2,F2,OS); 
  }

#endif

  return OS;
}

//=======================================================================
//function : PThePointOfIntersectionDummy
//purpose  : 
//=======================================================================
TopOpeBRep_PThePointOfIntersection TopOpeBRep_VPointInter::PThePointOfIntersectionDummy() const
{
  return myPPOI;
}