1 // Created on: 1994-10-12
2 // Created by: Jean Yves LEBEY
3 // Copyright (c) 1994-1999 Matra Datavision
4 // Copyright (c) 1999-2012 OPEN CASCADE SAS
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.
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.
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.
22 #include <TopOpeBRep_EdgesFiller.ixx>
23 #include <TopOpeBRep_PointGeomTool.hxx>
24 #include <TopOpeBRep_Point2d.hxx>
26 #include <TopOpeBRepDS_Transition.hxx>
27 #include <TopOpeBRepDS_Config.hxx>
28 #include <TopOpeBRepDS_Point.hxx>
29 #include <TopOpeBRepDS_EXPORT.hxx>
30 #include <TopOpeBRepDS_TKI.hxx>
31 #include <TopOpeBRepDS_InterferenceTool.hxx>
32 #include <TopOpeBRepTool_EXPORT.hxx>
33 #include <TopOpeBRepDS.hxx>
34 #include <BRep_Tool.hxx>
37 #include <TopOpeBRep_define.hxx>
40 #include <TopOpeBRepDS_reDEB.hxx>
41 extern Standard_Boolean TopOpeBRepDS_GettraceEDSF();
42 extern Standard_Boolean TopOpeBRepDS_GettraceDSF();
43 extern Standard_Boolean TopOpeBRep_GettraceEEFF();
44 Standard_EXPORT void debefre(const Standard_Integer IE) {cout<<"+++ debefre E"<<IE<<endl;}
45 Standard_EXPORT void debposesd(void) {/*cout<<"+++ debposesd"<<endl;*/}
46 Standard_EXPORT void debposnesd(void) {cout<<"+++ debposnesd"<<endl;}
47 Standard_EXPORT void debeeff() {}
50 #define M_REVERSED(O) (O == TopAbs_REVERSED)
51 #define M_FORWARD( O) (O == TopAbs_FORWARD)
52 #define M_INTERNAL(O) (O == TopAbs_INTERNAL)
53 #define M_EXTERNAL(O) (O == TopAbs_EXTERNAL)
55 //=======================================================================
56 //function : TopOpeBRep_EdgesFiller
58 //=======================================================================
59 TopOpeBRep_EdgesFiller::TopOpeBRep_EdgesFiller() : myPDS(NULL),myPEI(NULL) {}
63 //=======================================================================
66 //=======================================================================
67 void TopOpeBRep_EdgesFiller::Insert(const TopoDS_Shape& E1,const TopoDS_Shape& E2,TopOpeBRep_EdgesIntersector& EDGINT,const Handle(TopOpeBRepDS_HDataStructure)& HDS)
70 myPDS = &(HDS->ChangeDS());
71 myE1 = TopoDS::Edge(E1);
72 myE2 = TopoDS::Edge(E2);
78 Standard_Boolean trc = TopOpeBRepDS_GettraceDSF();
79 trc = trc || TopOpeBRepDS_GettraceEDSF();
80 trc = trc || TopOpeBRep_GettraceEEFF();
82 if (TopOpeBRep_GettraceEEFF()) debeeff();
83 TCollection_AsciiString str="EdgesFiller dim";str=str+myPEI->Dimension();
84 myPEI->Dump(str,myPDS->Shape(myE1),myPDS->Shape(myE2));
87 Standard_Boolean esd = myPEI->SameDomain();
88 if (esd) myPDS->FillShapesSameDomain(E1,E2);
91 myPEI->InitPoint(); if ( !myPEI->MorePoint() ) return;
93 // --- Add <E1,E2> in BDS
94 Standard_Integer E1index = myPDS->AddShape(E1,1);
95 Standard_Integer E2index = myPDS->AddShape(E2,2);
97 // --- get list of interferences connected to edges <E1>,<E2>
98 TopOpeBRepDS_ListOfInterference& EIL1 = myPDS->ChangeShapeInterferences(E1);
100 Handle(TopOpeBRepDS_Interference) EPI; //edge/point interference
101 Handle(TopOpeBRepDS_Interference) EVI; //edge/vertex interference
103 // TopOpeBRepDS_Transition TposF,TposL;
105 for (; myPEI->MorePoint(); myPEI->NextPoint() ) {
106 const TopOpeBRep_Point2d P2D = myPEI->Point();
107 Standard_Real par1 = P2D.Parameter(1);
108 Standard_Real par2 = P2D.Parameter(2);
109 Standard_Integer if1 = 0; if ( ! myF1.IsNull() ) if1 = myPDS->AddShape(myF1,1);
110 Standard_Integer if2 = 0; if ( ! myF2.IsNull() ) if2 = myPDS->AddShape(myF2,2);
113 Standard_Boolean pointofsegment = P2D.IsPointOfSegment();
118 if (pointofsegment && esd) debposesd();
119 else if (pointofsegment && !esd) debposnesd();
123 TopOpeBRepDS_Transition T1 = P2D.Transition(1);
124 TopOpeBRepDS_Transition T2 = P2D.Transition(2);
126 SetShapeTransition(P2D,T1,T2);
128 Standard_Boolean isvertex1 = P2D.IsVertex(1);
129 TopoDS_Vertex V1; if (isvertex1) V1 = P2D.Vertex(1);
130 Standard_Boolean isvertex2 = P2D.IsVertex(2);
131 TopoDS_Vertex V2; if (isvertex2) V2 = P2D.Vertex(2);
132 Standard_Boolean isvertex = isvertex1 || isvertex2;
135 if (isvertex1 && isvertex2) {
136 gp_Pnt P3D1 = BRep_Tool::Pnt(V1);
137 gp_Pnt P3D2 = BRep_Tool::Pnt(V2);
138 Standard_Real tol1 = BRep_Tool::Tolerance(V1);
139 Standard_Real tol2 = BRep_Tool::Tolerance(V2);
140 Standard_Real dpp = P3D1.Distance(P3D2);
141 if (dpp> tol1+tol2) {
143 cout<<"*** TopOpeBRep_EdgesFiller : isvertex1 && isvertex2 : P3D non confondus"<<endl;
144 cout<<"point PV1 "<<P3D1.X()<<" "<<P3D1.Y()<<" "<<P3D1.Z()<<endl;
145 cout<<"point PV2 "<<P3D2.X()<<" "<<P3D2.Y()<<" "<<P3D2.Z()<<endl;
151 // xpu : 080498 : CTS20072 (e12,e3,p8)
152 // edgesintersector called for tolerances = 0.
153 // facesintersector called for greater tolerances
154 // we assume facesintersector's ouput data to be valid
155 // and we use it for correcting edgesintersector's ouput data
156 TopOpeBRepDS_ListIteratorOfListOfInterference itloI1( myPDS->ShapeInterferences(E1) );
157 Standard_Integer G; TopOpeBRepDS_Kind K;
158 Standard_Boolean found = GetGeometry(itloI1,P2D,G,K);
159 if (!found) MakeGeometry(P2D,G,K);
161 Standard_Boolean foundpoint = (found) && (K == TopOpeBRepDS_POINT);
163 Standard_Boolean foundvertex = (found) && (K == TopOpeBRepDS_VERTEX);
165 Standard_Boolean isnewpoint = (!found) && (K == TopOpeBRepDS_POINT);
166 Standard_Boolean isnewvertex = (!found) && (K == TopOpeBRepDS_VERTEX);
168 Standard_Boolean faulty = (isvertex && isnewpoint) || (!isvertex && isnewvertex);
171 cout<<"- - - faulty EdgesFiller : G "<<G<<" K ";TopOpeBRepDS::Print(K,cout);cout.flush();
172 cout<<" isvertex="<<isvertex;cout.flush();
173 cout<<" isop="<<foundpoint<<" isov="<<foundvertex;cout.flush();
174 cout<<" isnp="<<isnewpoint<<" isnv="<<isnewvertex<<endl;cout.flush();
178 if (isvertex && foundpoint) {
179 Standard_Integer is = 1, ns = myPDS->NbShapes();
181 const TopoDS_Shape& s = myPDS->Shape(is);
182 if (s.ShapeType() != TopAbs_EDGE) continue;
183 const TopoDS_Edge& e = TopoDS::Edge(s);
185 TopOpeBRepDS_ListOfInterference linew;
186 TopOpeBRepDS_ListOfInterference& li = myPDS->ChangeShapeInterferences(e); TopOpeBRepDS_ListIteratorOfListOfInterference it(li);
189 Handle(TopOpeBRepDS_Interference) I=it.Value(); TopOpeBRepDS_Kind ki=I->GeometryType(); Standard_Integer gi=I->Geometry();
190 Handle(Standard_Type) DTI = I->DynamicType();
191 Standard_Boolean iscpi = (DTI == STANDARD_TYPE(TopOpeBRepDS_CurvePointInterference)) ;
192 Standard_Boolean condcpi = ((ki==TopOpeBRepDS_POINT) && (gi==G) && iscpi);
193 if (condcpi) { // remplacer G,K de I par le vertex courant
198 Handle(TopOpeBRepDS_CurvePointInterference) epi = Handle(TopOpeBRepDS_CurvePointInterference)::DownCast(I);
199 const TopOpeBRepDS_Transition& tevi = epi->Transition();
200 Standard_Integer sevi = epi->Support();
202 Standard_Integer gevi;
204 Standard_Integer gevi=0;
206 if (isvertex1) gevi = myPDS->AddShape(V1,1);
207 else if (isvertex2) gevi = myPDS->AddShape(V2,2);
208 Standard_Boolean bevi = Standard_False;
209 TopOpeBRepDS_Config cevi = TopOpeBRepDS_UNSHGEOMETRY;
210 Standard_Real pevi = epi->Parameter();
212 Handle(TopOpeBRepDS_Interference) evi;
213 evi = TopOpeBRepDS_InterferenceTool::MakeEdgeVertexInterference(tevi,sevi,gevi,bevi,cevi,pevi);
214 const TopOpeBRepDS_Kind& kevi = epi->SupportType();
215 evi->SupportType(kevi);
218 TopOpeBRepDS::Print(K,G,cout,"TopOpeBRep_EdgesFiller : remplacer "," ");
219 TopOpeBRepDS::Print(TopOpeBRepDS_VERTEX,gevi,cout,"par "," dans les courbes NYI\n");
228 if (!linew.IsEmpty()) {
229 myHDS->StoreInterferences(linew,is,"EdgesFiller modif : ");
232 } // (isvertex && foundpoint)
235 const TopoDS_Vertex& VV1 = V1;
236 // const TopoDS_Vertex& VV1 = TopoDS::Vertex(V1);
237 const TopoDS_Edge& EE1 = TopoDS::Edge(E1);
238 par1 = BRep_Tool::Parameter(VV1,EE1);
242 const TopoDS_Vertex& VV2 = V2;
243 // const TopoDS_Vertex& VV2 = TopoDS::Vertex(V2);
244 const TopoDS_Edge& EE2 = TopoDS::Edge(E2);
245 par2 = BRep_Tool::Parameter(VV2,EE2);
248 if ( isvertex1 && isvertex2 ) {
249 myPDS->FillShapesSameDomain(V1,V2);
252 Standard_Integer DSPindex;
253 Standard_Boolean EPIfound;
257 TopOpeBRepDS_Kind KKK;
258 TopOpeBRepDS_ListIteratorOfListOfInterference itEIL1(EIL1);
259 EPIfound = GetGeometry(itEIL1,P2D,DSPindex,KKK);
260 if ( ! EPIfound ) MakeGeometry(P2D,DSPindex,KKK);
262 SetShapeTransition(P2D,T1,T2);
264 if (KKK == TopOpeBRepDS_POINT) {
265 EPI = StorePI(P2D,T1,E2index,DSPindex,par1,1);
266 EPI = StorePI(P2D,T2,E1index,DSPindex,par2,2);
268 else if ( KKK == TopOpeBRepDS_VERTEX) {
269 Standard_Integer Vindex = DSPindex;
270 Standard_Boolean bevi = Standard_False;
271 TopOpeBRepDS_Config cevi = TopOpeBRepDS_UNSHGEOMETRY;
272 EVI = StoreVI(P2D,T1,E2index,Vindex,bevi,cevi,par1,1);
273 EVI = StoreVI(P2D,T2,E1index,Vindex,bevi,cevi,par2,2);
280 SetShapeTransition(P2D,T1,T2);
283 const TopoDS_Shape V = V1;
284 Standard_Integer Vindex = myPDS->AddShape(V,1);
285 TopOpeBRepDS_Config SSC = P2D.EdgesConfig();
286 EVI = StoreVI(P2D,T1,E2index,Vindex,Standard_True,SSC,par1,1);
287 EVI = StoreVI(P2D,T2,E1index,Vindex,Standard_False,SSC,par2,2);
291 const TopoDS_Shape V = V2;
292 Standard_Integer Vindex = myPDS->AddShape(V,2);
293 TopOpeBRepDS_Config SSC = P2D.EdgesConfig();
294 EVI = StoreVI(P2D,T1,E2index,Vindex,Standard_False,SSC,par1,1);
295 EVI = StoreVI(P2D,T2,E1index,Vindex,Standard_True,SSC,par2,2);
302 RecomputeInterferences(myE1,myLI1);
303 RecomputeInterferences(myE2,myLI2);
311 //=======================================================================
312 //function : SetShapeTransition
314 //=======================================================================
315 void TopOpeBRep_EdgesFiller::SetShapeTransition(const TopOpeBRep_Point2d& P2D,
316 TopOpeBRepDS_Transition& T1,TopOpeBRepDS_Transition& T2) const
318 Standard_Boolean pointofsegment = P2D.IsPointOfSegment();
319 Standard_Boolean esd = myPEI->SameDomain();
320 Standard_Integer ie1=0,ie2=0,if1=0,if2=0;
322 if (pointofsegment && esd) {
323 T1.ShapeBefore(TopAbs_EDGE);T1.ShapeAfter(TopAbs_EDGE);
324 T2.ShapeBefore(TopAbs_EDGE);T2.ShapeAfter(TopAbs_EDGE);
325 if ( ! myE1.IsNull() ) ie1 = myPDS->AddShape(myE1,1);
326 if ( ! myE2.IsNull() ) ie2 = myPDS->AddShape(myE2,2);
327 if ( ! myE2.IsNull() ) T1.Index(ie2);
328 if ( ! myE1.IsNull() ) T2.Index(ie1);
331 T1.ShapeBefore(TopAbs_FACE);T1.ShapeAfter(TopAbs_FACE);
332 T2.ShapeBefore(TopAbs_FACE);T2.ShapeAfter(TopAbs_FACE);
333 if ( ! myF1.IsNull() ) if1 = myPDS->AddShape(myF1,1);
334 if ( ! myF2.IsNull() ) if2 = myPDS->AddShape(myF2,2);
335 if ( ! myF1.IsNull() ) T2.Index(if1);
336 if ( ! myF2.IsNull() ) T1.Index(if2);
340 //=======================================================================
341 //function : GetGeometry
343 //=======================================================================
344 Standard_Boolean TopOpeBRep_EdgesFiller::GetGeometry(TopOpeBRepDS_ListIteratorOfListOfInterference& IT,const TopOpeBRep_Point2d& P2D,Standard_Integer& G,TopOpeBRepDS_Kind& K) const
347 TopOpeBRepDS_Point DSP = TopOpeBRep_PointGeomTool::MakePoint(P2D);
348 Standard_Boolean b = myHDS->GetGeometry(IT,DSP,G,K);
352 //=======================================================================
353 //function : MakeGeometry
355 //=======================================================================
356 Standard_Boolean TopOpeBRep_EdgesFiller::MakeGeometry(const TopOpeBRep_Point2d& P2D,Standard_Integer& G,TopOpeBRepDS_Kind& K) const
358 Standard_Boolean isvertex1 = P2D.IsVertex(1);
359 Standard_Boolean isvertex2 = P2D.IsVertex(2);
360 if (isvertex1 && isvertex2) {
361 Standard_Integer G1 = myPDS->AddShape(P2D.Vertex(1),1);
362 myPDS->AddShape(P2D.Vertex(2),2);
364 K = TopOpeBRepDS_VERTEX;
366 else if (isvertex1) {
367 G = myPDS->AddShape(P2D.Vertex(1),1);
368 K = TopOpeBRepDS_VERTEX;
370 else if (isvertex2) {
371 G = myPDS->AddShape(P2D.Vertex(2),2);
372 K = TopOpeBRepDS_VERTEX;
375 G = myPDS->AddPoint(TopOpeBRep_PointGeomTool::MakePoint(P2D));
376 K = TopOpeBRepDS_POINT;
378 return Standard_True;
381 //=======================================================================
384 //=======================================================================
385 void TopOpeBRep_EdgesFiller::Face(const Standard_Integer ISI,const TopoDS_Shape& F)
387 if (ISI == 1) myF1 = TopoDS::Face(F);
388 else if (ISI == 2) myF2 = TopoDS::Face(F);
389 else Standard_Failure::Raise("Face(i,f) : ISI incorrect");
392 //=======================================================================
395 //=======================================================================
396 const TopoDS_Shape& TopOpeBRep_EdgesFiller::Face(const Standard_Integer ISI) const
398 if (ISI == 1) return myF1;
399 else if (ISI == 2) return myF2;
400 else Standard_Failure::Raise("Face(i) : ISI incorrect");
404 //=======================================================================
407 //=======================================================================
408 Handle(TopOpeBRepDS_Interference) TopOpeBRep_EdgesFiller::StorePI(const TopOpeBRep_Point2d& P2D,
409 const TopOpeBRepDS_Transition& T,const Standard_Integer SI,const Standard_Integer GI,
410 const Standard_Real param,const Standard_Integer IEmother)
412 Handle(TopOpeBRepDS_Interference) I = TopOpeBRepDS_InterferenceTool::MakeEdgeInterference(T,TopOpeBRepDS_EDGE,SI,TopOpeBRepDS_POINT,GI,param);
413 TopoDS_Shape Emother;
414 if (IEmother == 1) Emother = myE1;
415 else if (IEmother == 2) Emother = myE2;
416 myHDS->StoreInterference(I,Emother);
417 Standard_Boolean b = ToRecompute(P2D,I,IEmother);
418 if (b) StoreRecompute(I,IEmother);
422 //=======================================================================
425 //=======================================================================
426 Handle(TopOpeBRepDS_Interference) TopOpeBRep_EdgesFiller::StoreVI(const TopOpeBRep_Point2d& P2D,
427 const TopOpeBRepDS_Transition& T,const Standard_Integer EI,const Standard_Integer VI,
428 const Standard_Boolean VisB,const TopOpeBRepDS_Config C,
429 const Standard_Real param,const Standard_Integer IEmother)
431 Handle(TopOpeBRepDS_Interference) I = TopOpeBRepDS_InterferenceTool::MakeEdgeVertexInterference(T,EI,VI,VisB,C,param);
432 TopoDS_Shape Emother;
433 if (IEmother == 1) Emother = myE1;
434 else if (IEmother == 2) Emother = myE2;
435 myHDS->StoreInterference(I,Emother);
436 Standard_Boolean b = ToRecompute(P2D,I,IEmother);
437 if (b) StoreRecompute(I,IEmother);
441 //=======================================================================
442 //function : ToRecompute
444 //=======================================================================
445 Standard_Boolean TopOpeBRep_EdgesFiller::ToRecompute(const TopOpeBRep_Point2d& P2D,const Handle(TopOpeBRepDS_Interference)& /*I*/,const Standard_Integer /*IEmother*/)
447 Standard_Boolean b = Standard_True;
448 Standard_Boolean pointofsegment = P2D.IsPointOfSegment();
449 Standard_Boolean esd = myPEI->SameDomain();
450 b = b && (pointofsegment && !esd);
454 //=======================================================================
455 //function : StoreRecompute
457 //=======================================================================
458 void TopOpeBRep_EdgesFiller::StoreRecompute(const Handle(TopOpeBRepDS_Interference)& I,const Standard_Integer IEmother)
460 if (IEmother == 1) myLI1.Append(I);
461 else if (IEmother == 2) myLI2.Append(I);
464 //=======================================================================
465 //function : RecomputeInterferences
467 //=======================================================================
468 void TopOpeBRep_EdgesFiller::RecomputeInterferences(const TopoDS_Edge& E,TopOpeBRepDS_ListOfInterference& LI)
470 if (LI.IsEmpty()) return;
472 TopOpeBRepDS_TKI tki; tki.FillOnGeometry(LI);
475 Standard_Integer EIX = myPDS->Shape(E); Standard_Boolean TRC=DSREDUEDGETRCE(EIX);
476 if (TRC) cout<<endl<<"RecomputeInterferences E"<<EIX<<" <- "<<LI.Extent()<<endl;
477 if (TRC) tki.DumpTKIIterator("","\n");
478 if (TRC) debefre(EIX);
481 for (tki.Init(); tki.More(); tki.Next()) {
482 TopOpeBRepDS_Kind K; Standard_Integer G; tki.Value(K,G);
483 TopOpeBRepDS_ListOfInterference& loi = tki.ChangeValue(K,G); TopOpeBRepDS_ListOfInterference Rloi;
484 Standard_Integer nloi = loi.Extent();
485 if (nloi == 0) continue;
488 if (nloi > 1) {cout<<"TopOpeBRep_EdgesFiller : > 1 I on UNUN/F on E"<<EIX<<" A FAIRE"<<endl;}
491 Handle(TopOpeBRepDS_Interference)& iloi = loi.First();
492 TopOpeBRepDS_Transition& TU = iloi->ChangeTransition();
493 Standard_Integer ifb = TU.IndexBefore();
494 Standard_Integer ifa = TU.IndexAfter();
495 const TopoDS_Face& fb = TopoDS::Face(myPDS->Shape(ifb));
498 if (ifb != ifa) {cout<<"TopOpeBRep_EdgesFiller : ifb != ifa on E"<<EIX<<" NYI"<<endl;}
501 Standard_Real pE = FDS_Parameter(iloi); TopOpeBRepDS_Transition TN;
502 TN.ShapeBefore(TU.ShapeBefore());TN.IndexBefore(TU.IndexBefore());
503 TN.ShapeAfter(TU.ShapeAfter());TN.IndexAfter(TU.IndexAfter());
506 Standard_Boolean ok =
508 FDS_stateEwithF2d(*myPDS,E,pE,K,G,fb,TN);
512 TopOpeBRepDS_ListOfInterference l1;l1.Append(iloi);
513 TopOpeBRepDS_TKI dt;dt.FillOnGeometry(l1);dt.DumpTKIIterator("","");
515 cout<<" ";TU.Dump(cout);cout<<endl;
516 cout<<"--> ";TN.Dump(cout);cout<<endl;
519 cout<<"--> TN ko"<<endl;
525 } // RecomputeInterferences