summaryrefslogtreecommitdiff
path: root/src/TopOpeBRepDS/TopOpeBRepDS_EdgeInterferenceTool.cxx
blob: 2314e4e06fc2f500813db7c7d74cdcd623ebacbc (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
// File:	TopOpeBRepDS_EdgeInterferenceTool.cxx
// Created:	Tue Nov  8 14:52:21 1994
// Author:	Jean Yves LEBEY
//		<jyl@bravox>

#include <TopOpeBRepDS_EdgeInterferenceTool.ixx>

#include <TopOpeBRepDS_CurvePointInterference.hxx>
#include <TopOpeBRepDS_EdgeVertexInterference.hxx>
#include <BRepLProp_CLProps.hxx>
#include <BRep_Tool.hxx>
#include <TopoDS_Iterator.hxx>
#include <Precision.hxx>
#include <TopoDS.hxx>
#include <TopOpeBRepTool_ShapeTool.hxx>
#include <Standard_ProgramError.hxx>

#ifdef DEB
Standard_EXPORT Standard_Boolean TopOpeBRepDS_GettracePEI();
#endif

//=======================================================================
//function : TopOpeBRepDS_EdgeInterferenceTool
//purpose  : 
//=======================================================================

 TopOpeBRepDS_EdgeInterferenceTool::TopOpeBRepDS_EdgeInterferenceTool()
{
}

static Standard_Real Parameter(const Handle(TopOpeBRepDS_Interference)& I)
{ 
  Standard_Real p = 0; 
  if      ( I->IsKind(STANDARD_TYPE(TopOpeBRepDS_EdgeVertexInterference)) )
    p = Handle(TopOpeBRepDS_EdgeVertexInterference)::DownCast(I)->Parameter();
  else if ( I->IsKind(STANDARD_TYPE(TopOpeBRepDS_CurvePointInterference)) )
    p = Handle(TopOpeBRepDS_CurvePointInterference)::DownCast(I)->Parameter();
  else {
#ifdef DEB
    cout<<"EdgeInterference : mauvais type d'interference"<<endl;
#endif
    Standard_ProgramError::Raise("TopOpeBRepDS_EdgeInterferenceTool1");
  }
  return p;
}
  

//=======================================================================
//function : Init
//purpose  : 
//=======================================================================

void TopOpeBRepDS_EdgeInterferenceTool::Init
(const TopoDS_Shape& E, const Handle(TopOpeBRepDS_Interference)& I)
{
  myEdgeOrientation = E.Orientation();
  myEdgeOriented    = I->Support();
  
  // NYI 971219 : on ne tient pas compte de l'orientation de E = arete-mere de l'interference I
  if (myEdgeOrientation == TopAbs_INTERNAL || 
      myEdgeOrientation == TopAbs_EXTERNAL) {
    return;
  }
  
  // la premiere arete orientee est gardee dans myEdgeOriented pour MAJ de
  // l'arete croisee dans l'interference resultat.

  // par = parametre sur l'arete croisee
  Standard_Real par = ::Parameter(I);
  gp_Dir T,N; Standard_Real C;
  TopOpeBRepTool_ShapeTool::EdgeData(E,par,T,N,C);
  myTool.Reset(T,N,C);
}

//=======================================================================
//function : Add
//purpose  : 
//=======================================================================

void TopOpeBRepDS_EdgeInterferenceTool::Add
(const TopoDS_Shape& E,
 const TopoDS_Shape& V,
 const Handle(TopOpeBRepDS_Interference)& I)
{
  TopAbs_Orientation Eori = E.Orientation();
  if (Eori == TopAbs_INTERNAL || 
      Eori == TopAbs_EXTERNAL) {
    return;
  }

  // premiere interference sur arete orientee : Init
  if (myEdgeOrientation == TopAbs_INTERNAL || 
      myEdgeOrientation == TopAbs_EXTERNAL) {
    Init(E,I);
    return;
  }

  // V est un sommet de E ?
  Standard_Boolean VofE = Standard_False;
  TopoDS_Iterator it(E,Standard_False);
  for ( ; it.More(); it.Next() ) {
    const TopoDS_Shape& S = it.Value();
    if ( S.IsSame(V) ) {
      VofE = Standard_True; 
      break;
    }
  }
 
#ifdef DEB
  if (TopOpeBRepDS_GettracePEI() && !VofE) {
    cout<<"===================== VofE = False"<<endl;
  }
#endif 

  // V est un sommet de E
  const TopoDS_Vertex& VV = TopoDS::Vertex(V);
  const TopoDS_Edge& EE = TopoDS::Edge(E);
  Standard_Real par = BRep_Tool::Parameter(VV,EE);
  
  gp_Dir T,N; Standard_Real C;
  Standard_Real tol = TopOpeBRepTool_ShapeTool::EdgeData(E,par,T,N,C);
  TopAbs_Orientation oriloc = I->Transition().Orientation(TopAbs_IN);
  TopAbs_Orientation oritan = it.Value().Orientation();
  myTool.Compare(tol,T,N,C,oriloc,oritan);
}

//=======================================================================
//function : Add
//purpose  : 
//=======================================================================

void TopOpeBRepDS_EdgeInterferenceTool::Add
(const TopoDS_Shape& E,
// const TopOpeBRepDS_Point& P,
 const TopOpeBRepDS_Point& ,
 const Handle(TopOpeBRepDS_Interference)& I)
{
  TopAbs_Orientation Eori = E.Orientation();
  if (Eori == TopAbs_INTERNAL || 
      Eori == TopAbs_EXTERNAL) {
    return;
  }

  // premiere interference sur arete orientee : Init
  if (myEdgeOrientation == TopAbs_INTERNAL || 
      myEdgeOrientation == TopAbs_EXTERNAL) {
    Init(E,I);
    return;
  }

  Standard_Real par = ::Parameter(I);
  
  gp_Dir T,N; Standard_Real C;
  Standard_Real tol = TopOpeBRepTool_ShapeTool::EdgeData(E,par,T,N,C);
  TopAbs_Orientation oriloc = I->Transition().Orientation(TopAbs_IN);
  TopAbs_Orientation oritan = TopAbs_INTERNAL;
  myTool.Compare(tol,T,N,C,oriloc,oritan);
}

//=======================================================================
//function : Transition
//purpose  : 
//=======================================================================

void TopOpeBRepDS_EdgeInterferenceTool::Transition
(const Handle(TopOpeBRepDS_Interference)& I) const 
{
  TopOpeBRepDS_Transition& T = I->ChangeTransition();

  if (myEdgeOrientation == TopAbs_INTERNAL) {
    T.Set(TopAbs_IN,TopAbs_IN);
  }
  else if (myEdgeOrientation == TopAbs_EXTERNAL) {
    T.Set(TopAbs_OUT,TopAbs_OUT);
  }
  else {
    I->Support(myEdgeOriented);
    T.Set(myTool.StateBefore(),myTool.StateAfter());
  }
}