1 // Created on: 1997-02-14
2 // Created by: Jean Yves LEBEY
3 // Copyright (c) 1997-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 <TopExp_Explorer.hxx>
20 #include <TColStd_DataMapIteratorOfDataMapOfIntegerListOfInteger.hxx>
21 #include <TColStd_DataMapOfIntegerListOfInteger.hxx>
22 #include <TColStd_ListIteratorOfListOfInteger.hxx>
23 #include <TColStd_ListOfInteger.hxx>
24 #include <BRepAdaptor_Curve.hxx>
25 #include <BRepAdaptor_Surface.hxx>
26 #include <BRep_Tool.hxx>
27 #include <BRepClass3d_SolidClassifier.hxx>
28 #include <TopoDS_Shell.hxx>
29 #include <TopoDS_Solid.hxx>
31 #include <Precision.hxx>
32 #include <Geom_Curve.hxx>
33 #include <Geom_Surface.hxx>
34 #include <GeomAPI_ProjectPointOnSurf.hxx>
35 #include <BRepTools.hxx>
37 #include <TopOpeBRepTool_ShapeTool.hxx>
38 #include <TopOpeBRepTool_EXPORT.hxx>
39 #include <TopOpeBRepTool_TOOL.hxx>
41 #include <TopOpeBRepDS_FaceEdgeInterference.hxx>
42 #include <TopOpeBRepDS_define.hxx>
43 #include <TopOpeBRepDS_ProcessInterferencesTool.hxx>
44 #include <TopOpeBRepDS_FaceEdgeInterference.hxx>
45 #include <TopOpeBRepDS_FaceInterferenceTool.hxx>
46 #include <TopOpeBRepDS_ListOfShapeOn1State.hxx>
47 #include <TopOpeBRepDS_DataMapOfShapeListOfShapeOn1State.hxx>
48 #include <TopOpeBRepTool_ShapeClassifier.hxx>
49 #include <TopOpeBRepTool_PShapeClassifier.hxx>
50 #include <TopOpeBRepDS_ShapeShapeInterference.hxx>
52 Standard_EXPORT void FUN_UNKFstasta(const TopoDS_Face& FF,const TopoDS_Face& FS,
53 const TopoDS_Edge& EE,const Standard_Boolean EEofFF,
54 TopAbs_State& stateb,TopAbs_State& statea,
55 TopOpeBRepTool_PShapeClassifier pClassif);
57 #define MDShfei Handle(TopOpeBRepDS_FaceEdgeInterference)
58 #define MAKEFEI(IJKLM) (Handle(TopOpeBRepDS_FaceEdgeInterference)::DownCast(IJKLM))
61 extern Standard_Boolean TopOpeBRepDS_GetcontextNOPFI();
62 extern Standard_Boolean TopOpeBRepDS_GettracePFI();
63 extern Standard_Boolean TopOpeBRepDS_GettracePI();
64 extern Standard_Boolean TopOpeBRepDS_GettraceSPSX(const Standard_Integer);
65 static Standard_Boolean TRCF(const Standard_Integer F) {
66 Standard_Boolean b1 = TopOpeBRepDS_GettracePFI();
67 Standard_Boolean b2 = TopOpeBRepDS_GettracePI();
68 Standard_Boolean b3 = TopOpeBRepDS_GettraceSPSX(F);
69 return (b1 || b2 || b3);
71 static void debredunkf(const Standard_Integer /*i*/){};
74 Standard_EXPORT Standard_Boolean FUN_Parameters(const gp_Pnt& Pnt,const TopoDS_Shape& F,Standard_Real& u,Standard_Real& v);
75 Standard_EXPORT Standard_Boolean FUN_Parameters(const Standard_Real& Param,const TopoDS_Shape& E,const TopoDS_Shape& F,Standard_Real& u,Standard_Real& v);
77 //=======================================================================
79 // purpose : The compute of transition face <F> /face <FS>,
81 // prequesitory : <E> is IN 2dmatter(F) and IN 2dmatter(FS)
82 //=======================================================================
84 Standard_EXPORT Standard_Boolean FUN_mkTonF(const TopoDS_Face& F, const TopoDS_Face& FS, const TopoDS_Edge& E,
85 TopOpeBRepDS_Transition& T)
87 Standard_Boolean isdgE = BRep_Tool::Degenerated(E);
88 if (isdgE) return Standard_False;
89 T.Set(TopAbs_UNKNOWN,TopAbs_UNKNOWN);
91 Standard_Real tola = 1.e-6; // nyitol
92 Standard_Real f,l; FUN_tool_bounds(E,f,l);
93 const Standard_Real PAR_T = 0.456789;
94 Standard_Real pmil = (1.-PAR_T)*f + PAR_T*l;
98 ok = TopOpeBRepTool_TOOL::TggeomE(pmil,E,tgE);
99 //modified by NIZNHY-PKV Fri Aug 4 10:59:44 2000 f
101 return Standard_False;
103 //modified by NIZNHY-PKV Fri Aug 4 10:59:48 2000 t
106 ok = FUN_tool_parF(E,pmil,F,uvF);
108 return Standard_False;
111 ok = FUN_tool_parF(E,pmil,FS,uvFS);
113 return Standard_False;
115 gp_Dir ngF = FUN_tool_nggeomF(uvF,F);
116 Standard_Real xx = Abs(ngF.Dot(tgE));
117 Standard_Boolean tgt = (Abs(1-xx) < tola);
118 if (tgt) return Standard_False;
121 ok = TopOpeBRepTool_TOOL::Nt(uvFS,FS, ntFS);
123 return Standard_False;
124 gp_Dir beafter = ngF^tgE;
125 Standard_Real yy = beafter.Dot(ntFS);
126 Standard_Boolean unk = (Abs(yy) < tola);
128 return Standard_False;
130 if (yy < 0.) T.Set(TopAbs_FORWARD);
131 else T.Set(TopAbs_REVERSED);
132 return Standard_True;
136 //------------------------------------------------------
137 // FUN_edgeofface : True si le edge E est un edge de F
138 Standard_EXPORT Standard_Boolean FUN_edgeofface
139 //------------------------------------------------------
140 (const TopoDS_Shape& E,const TopoDS_Shape& F)
142 Standard_Boolean isv = Standard_False;
144 for (ex.Init(F,TopAbs_EDGE); ex.More(); ex.Next())
145 // for (TopExp_Explorer ex(F,TopAbs_EDGE); ex.More(); ex.Next())
146 if (ex.Current().IsSame(E) ) {
153 //------------------------------------------------------
154 Standard_EXPORT Standard_Boolean FUN_keepFinterference
155 //------------------------------------------------------
156 (const TopOpeBRepDS_DataStructure& DS,const Handle(TopOpeBRepDS_Interference)& I,const TopoDS_Shape& F)
158 TopOpeBRepDS_Kind GT1,ST1; Standard_Integer G1,S1; FDS_data(I,GT1,G1,ST1,S1);
160 Standard_Boolean res = Standard_True;
161 if ( I->IsKind(STANDARD_TYPE(TopOpeBRepDS_FaceEdgeInterference)) ) {
163 const TopoDS_Shape& EG = DS.Shape(I->Geometry());
164 // I rejetee si son edge-geometrie est une arete de la face qui accede I.
165 Standard_Boolean k3 = ! ::FUN_edgeofface(EG,F);
172 //------------------------------------------------------
173 Standard_EXPORT void FUN_unkeepFdoubleGBoundinterferences
174 //------------------------------------------------------
175 (TopOpeBRepDS_ListOfInterference& LI,const TopOpeBRepDS_DataStructure& /*BDS*/,
177 const Standard_Integer SIX)
179 const Standard_Integer )
183 Standard_Boolean TRC=TRCF(SIX);
186 TopOpeBRepDS_ListIteratorOfListOfInterference it1;
188 // process interferences of LI with VERTEX geometry
191 while (it1.More() ) {
192 Handle(TopOpeBRepDS_Interference)& I1 = it1.Value();
193 TopOpeBRepDS_Kind GT1,ST1; Standard_Integer G1,S1;
194 const TopOpeBRepDS_Transition& T1 = I1->Transition();
195 Standard_Boolean isunk1 = T1.IsUnknown();
196 if (isunk1) { it1.Next(); continue; }
198 FDS_data(I1,GT1,G1,ST1,S1);
199 Handle(TopOpeBRepDS_ShapeShapeInterference) SSI1 = Handle(TopOpeBRepDS_ShapeShapeInterference)::DownCast(I1);
200 if (SSI1.IsNull()) { it1.Next(); continue; }
202 Standard_Boolean isB1 = SSI1->GBound();
204 TopOpeBRepDS_ListIteratorOfListOfInterference it2(it1);
206 Standard_Boolean cond1 = Standard_False;
207 Standard_Boolean cond2 = Standard_False;
209 while ( it2.More() ) {
210 const Handle(TopOpeBRepDS_Interference)& I2 = it2.Value();
211 TopOpeBRepDS_Kind GT2,ST2; Standard_Integer G2,S2;
212 const TopOpeBRepDS_Transition& T2 = I2->Transition();
213 Standard_Boolean isunk2 = T2.IsUnknown();
214 if (isunk2) { it2.Next(); continue; }
216 FDS_data(I2,GT2,G2,ST2,S2);
217 Handle(TopOpeBRepDS_ShapeShapeInterference) SSI2 = Handle(TopOpeBRepDS_ShapeShapeInterference)::DownCast(I2);
218 if ( SSI2.IsNull() ) { it2.Next(); continue; }
220 Standard_Boolean isB2 = SSI2->GBound();
221 cond2 = (GT2 == GT1 && GT1 == TopOpeBRepDS_EDGE && G2 == G1 &&
222 ST2 == ST1 && ST1 == TopOpeBRepDS_FACE && S2 != S1 &&
227 if(TRC){cout<<"face "<<SIX<<" : G2 "<< G2 <<" GBound ";I2->Dump(cout);cout<<endl;}
229 cond1 = Standard_True;
237 if(TRC){cout<<"face "<<SIX<<" : G1 "<< G1 <<" GBound ";I1->Dump(cout);cout<<endl;}
244 } // FUN_unkeepFdoubleGBoundinterferences
246 //------------------------------------------------------
247 Standard_EXPORT void FUN_resolveFUNKNOWN
248 //------------------------------------------------------
249 (TopOpeBRepDS_ListOfInterference& LI,TopOpeBRepDS_DataStructure& BDS,
250 const Standard_Integer SIX,
251 const TopOpeBRepDS_DataMapOfShapeListOfShapeOn1State& MEsp,
252 TopOpeBRepTool_PShapeClassifier pClassif)
255 Standard_Boolean TRC=TRCF(SIX); if (TRC) debredunkf(SIX);
256 Standard_Boolean modif = Standard_False;
259 const TopoDS_Shape& F = BDS.Shape(SIX);
260 TopOpeBRepDS_ListIteratorOfListOfInterference it1;
262 const TopoDS_Face& FF = TopoDS::Face(F);
263 // Standard_Real fE,lE; BRep_Tool::Range(EE,fE,lE);
265 // process interferences of LI with UNKNOWN transition
267 for (it1.Initialize(LI); it1.More(); it1.Next() ) {
268 Handle(TopOpeBRepDS_Interference)& I1 = it1.Value();
269 const TopOpeBRepDS_Transition& T1 = I1->Transition();
270 Standard_Boolean isunk = T1.IsUnknown();
271 if (!isunk) continue;
274 modif = Standard_True;
275 if(TRC){debredunkf(SIX);TCollection_AsciiString s="F";s=s+SIX+" T UNKNOWN ";I1->Dump(cout,s,"\n");}
278 TopOpeBRepDS_Kind GT1,ST1; Standard_Integer G1,S1; TopAbs_ShapeEnum tsb1,tsa1; Standard_Integer isb1,isa1;
279 FDS_Idata(I1,tsb1,isb1,tsa1,isa1,GT1,G1,ST1,S1);
280 Standard_Boolean idt = (tsb1==TopAbs_FACE && tsa1==TopAbs_FACE
281 && GT1==TopOpeBRepDS_EDGE && ST1==TopOpeBRepDS_FACE);
282 Standard_Boolean idi = (isb1==S1 && isa1==S1);
283 Standard_Boolean etgf = idt && idi; // face tangent a une face en 1 edge
286 const TopoDS_Edge& EE = TopoDS::Edge(BDS.Shape(G1));
287 Standard_Real fE,lE; BRep_Tool::Range(EE,fE,lE);
290 if(TRC){debredunkf(SIX);TCollection_AsciiString s="F";s=s+SIX+" etgf ";I1->Dump(cout,s,"\n");}
293 Handle(TopOpeBRepDS_FaceEdgeInterference) fei = MAKEFEI(I1);
294 if (fei.IsNull()) continue;
296 const TopoDS_Face& FS = TopoDS::Face(BDS.Shape(S1));
298 // if (!go) continue;
300 // la face FF transitionne par la transition T1.IsUnknown()
301 // en l'arete EE par rapport a la face FS.
302 // range de EE = [fE,lE].
303 // EE est une arete de FF ou non.
304 // EE est une arete de section.
305 // EE est une arete de couture.
306 Standard_Boolean isEEGB = fei->GBound();
307 Standard_Boolean isEEsp = MEsp.IsBound(EE);
308 TopoDS_Edge EEsp = EE;
310 const TopOpeBRepDS_ListOfShapeOn1State& los1 = MEsp.Find(EE);
311 isEEsp = los1.IsSplit();
313 const TopTools_ListOfShape& los = los1.ListOnState();
314 Standard_Integer n = los.Extent();
316 EEsp = TopoDS::Edge(los.First());
317 if (!EEsp.IsSame(EE)) isEEGB = Standard_False;
319 // MSV: treat the case of multiple splits:
320 // select the split which lies on both faces
321 TopTools_ListIteratorOfListOfShape it(los);
322 for (; it.More(); it.Next()) {
323 const TopoDS_Edge& aE = TopoDS::Edge(it.Value());
324 Standard_Real f,l; FUN_tool_bounds(aE,f,l);
325 const Standard_Real PAR_T = 0.456789;
326 Standard_Real pmil = (1.-PAR_T)*f + PAR_T*l;
328 if (FUN_tool_parF(aE,pmil,FF,uvF) && FUN_tool_parF(aE,pmil,FS,uvF)) {
337 Standard_Boolean isSO = Standard_True;
338 if (!EEsp.IsSame(EE))
339 if (!FUN_tool_curvesSO(EEsp,EE,isSO)) continue;
341 TopAbs_State stateb,statea;
342 TopOpeBRepDS_Transition T; Standard_Boolean ok = FUN_mkTonF(FF,FS,EEsp,T); //xpu230498
343 if (ok) {stateb = T.Before(); statea =T.After();} //xpu230498
345 TopOpeBRepTool_PShapeClassifier pClass = 0;
347 // MSV: find Solids of the same object rank as FS
348 // to determine transition relatively solid rather then face
349 // if possible (see pb. in CFE002 C2, when SIX==13)
350 Standard_Integer rankFS = BDS.AncestorRank(S1);
351 TopoDS_Shape aSRef = BDS.Shape(rankFS);
352 TopExp_Explorer ex(aSRef,TopAbs_SOLID);
355 pClass->SetReference(aSRef);
358 FUN_UNKFstasta(FF,FS,EEsp,isEEGB,stateb,statea,pClass);
360 if (stateb==TopAbs_UNKNOWN || statea==TopAbs_UNKNOWN) continue;
362 TopOpeBRepDS_Transition& newT1 = I1->ChangeTransition();
364 TopAbs_State stmp = stateb; stateb = statea; statea = stmp;
366 newT1.Set(stateb,statea,tsb1,tsa1);
369 if(TRC){debredunkf(SIX);TCollection_AsciiString s="F";s=s+SIX+" T corrected ";I1->Dump(cout,s,"\n");}
375 if(TRC && modif){ FDS_dumpLI(LI,"apres correction UNKNOWN : "); }
378 FUN_unkeepUNKNOWN(LI,BDS,SIX);
381 if(TRC && modif){ FDS_dumpLI(LI,"sans suppression UNKNOWN residuels : "); }
385 //========================== DEB start
387 //Standard_IMPORT void FUN_ComputeGeomData(const TopoDS_Shape& F,const Standard_Real& u,const Standard_Real& v,gp_Dir& Norm);
388 //------------------------------------------------------
389 // Automatic testing for complex faces interference on line with cylinders and planes xpu NYI: general case
390 //------------------------------------------------------
391 Standard_Boolean TestTransition(const TopOpeBRepDS_Transition& T,const TopoDS_Face& F,const TopoDS_Edge& E,const TopoDS_Solid& So) // DEB only
394 b = T.Before(); a = T.After();
396 BRepAdaptor_Curve ac(E);
397 GeomAbs_CurveType ctyp = ac.GetType();
398 // TCollection_AsciiString nt; TestTopOpeDraw_TTOT::CurveToString(ctyp,nt);
399 if (ctyp != GeomAbs_Line) {
400 // cout << " Case "<<nt;
401 cout <<" not treated"<<endl;
402 return Standard_True;
404 BRepAdaptor_Surface as(F);
405 GeomAbs_SurfaceType styp = as.GetType();
406 // TestTopOpeDraw_TTOT::CurveToString(styp,nt);
407 if (!((styp == GeomAbs_Plane)||(styp == GeomAbs_Cylinder))) {
408 // cout << " Case "<<nt;
409 cout<<" not treated"<<endl;
410 return Standard_True;
412 Standard_Real du = TopOpeBRepTool_ShapeTool::Tolerance(E); du *= 5.; // edge tolerance
413 Standard_Real u, v, up, vp, p = (ac.FirstParameter() + ac.LastParameter())*.5;
414 gp_Pnt pnt, pntnorm; // middle point on edge
415 gp_Vec tgt, beafter; // curve tangent vector at pnt
416 gp_Dir normS; // normal and direction (Before, After) on reference surface.
419 Standard_Boolean prodone = FUN_Parameters(pnt, F, u, v); // DEB u, v pntnorm coordinates on F
421 cout<<" not treated : prendre un point sur le common des aretes de section SDM"<<endl;
422 return Standard_True;
425 // FUN_ComputeGeomData (F, u, v, normS);
427 normS = FUN_tool_nggeomF(gp_Pnt2d(u,v), F);
428 beafter = normS^gp_Vec(tgt); beafter.Scale(du); // beafter of length du
429 pntnorm = gp_Pnt(pnt.XYZ()).Translated(beafter); // (pnt, pntnorm) = du*beafter
430 FUN_Parameters(pntnorm, F, up, vp); // DEB up, vp pntnorm coordinates on F
432 gp_Pnt pAfter, pBefore;
433 as.D0(up, vp, pAfter);
434 as.D0(up-2*(up-u), vp -2*(vp-v), pBefore);
436 Standard_Boolean transok;
437 TopAbs_State stb, sta;
438 BRepClass3d_SolidClassifier classif(So);
440 classif.Perform(pBefore, Precision::Confusion()); stb = classif.State();
441 classif.Perform(pAfter, Precision::Confusion()); sta = classif.State();
442 transok = (stb == b)&&(sta == a);
445 cout<<"States found by classifier :"<<endl;
447 TopAbs::Print(stb, cout);
449 TopAbs::Print(sta, cout);
457 //========================== DEB end