1 // Created on: 1997-04-10
2 // Created by: Prestataire Mary FABIEN
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.
18 #include <BRep_Tool.hxx>
20 #include <Standard_Type.hxx>
21 #include <TCollection_AsciiString.hxx>
22 #include <TColStd_IndexedMapOfInteger.hxx>
24 #include <TopoDS_Shape.hxx>
25 #include <TopoDS_Vertex.hxx>
26 #include <TopOpeBRepDS.hxx>
27 #include <TopOpeBRepDS_Check.hxx>
28 #include <TopOpeBRepDS_CheckStatus.hxx>
29 #include <TopOpeBRepDS_CurvePointInterference.hxx>
30 #include <TopOpeBRepDS_DataMapIteratorOfDataMapOfCheckStatus.hxx>
31 #include <TopOpeBRepDS_DataMapOfCheckStatus.hxx>
32 #include <TopOpeBRepDS_EdgeVertexInterference.hxx>
33 #include <TopOpeBRepDS_HDataStructure.hxx>
34 #include <TopOpeBRepDS_Interference.hxx>
35 #include <TopOpeBRepDS_InterferenceTool.hxx>
36 #include <TopOpeBRepDS_Kind.hxx>
37 #include <TopOpeBRepDS_ListIteratorOfListOfInterference.hxx>
38 #include <TopOpeBRepDS_ListOfInterference.hxx>
39 #include <TopOpeBRepDS_PointExplorer.hxx>
40 #include <TopOpeBRepTool_ShapeTool.hxx>
41 #include <TopTools_ListIteratorOfListOfShape.hxx>
42 #include <TopTools_ListOfShape.hxx>
45 IMPLEMENT_STANDARD_RTTIEXT(TopOpeBRepDS_Check,Standard_Transient)
47 //=======================================================================
50 //=======================================================================
51 TopOpeBRepDS_Check::TopOpeBRepDS_Check(const Handle(TopOpeBRepDS_HDataStructure)& HDS)
54 myMapSurfaceStatus.Clear();
55 myMapCurveStatus.Clear();
56 myMapPointStatus.Clear();
57 myMapShapeStatus.Clear();
60 //=======================================================================
63 //=======================================================================
65 TopOpeBRepDS_Check::TopOpeBRepDS_Check()
67 myMapSurfaceStatus.Clear();
68 myMapCurveStatus.Clear();
69 myMapPointStatus.Clear();
70 myMapShapeStatus.Clear();
73 //=======================================================================
75 //purpose : Check Integrity
76 //=======================================================================
77 Standard_Boolean CheckEdgeParameter(const Handle(TopOpeBRepDS_HDataStructure)& myHDS);
78 Standard_Boolean TopOpeBRepDS_Check::ChkIntg()
80 const TopOpeBRepDS_DataStructure& DS = myHDS->DS();
81 Standard_Boolean bI=Standard_False;
82 // Check the integrity of the DS
83 Standard_Integer i,nshape = DS.NbShapes();
84 for (i = 1; i <= nshape; i++) {
85 // Integrity of Interferences : Check support and geometry
86 const TopOpeBRepDS_ListOfInterference& LI = DS.ShapeInterferences(i);
87 bI = ChkIntgInterf(LI);
89 Standard_Integer nsurface = DS.NbSurfaces();
90 for (i = 1; i <= nsurface; i++) {
91 // Integrity of Interferences : Check support and geometry
92 const TopOpeBRepDS_ListOfInterference& LI = DS.SurfaceInterferences(i);
93 bI = bI && ChkIntgInterf(LI);
96 Standard_Integer ncurve = DS.NbCurves();
97 for (i = 1; i <= ncurve; i++) {
98 // Integrity of Interferences : Check support and geometry
99 const TopOpeBRepDS_ListOfInterference& LI = DS.CurveInterferences(i);
100 bI = bI && ChkIntgInterf(LI);
103 Standard_Integer npoint = DS.NbPoints();
104 for (i = 1; i <= npoint; i++) {
105 // Integrity of Interferences : Check support and geometry
106 const TopOpeBRepDS_ListOfInterference& LI = DS.PointInterferences(i);
107 bI = bI && ChkIntgInterf(LI);
110 // CheckEdgeParameter();
111 CheckEdgeParameter(myHDS);
116 //=======================================================================
117 //function : ChkIntgInterf
119 //=======================================================================
121 Standard_Boolean TopOpeBRepDS_Check::ChkIntgInterf
122 (const TopOpeBRepDS_ListOfInterference& LI)
124 TopOpeBRepDS_ListIteratorOfListOfInterference it1;
126 Standard_Boolean IsOK = Standard_True;
127 while (it1.More() ) {
128 Handle(TopOpeBRepDS_Interference)& I1 = it1.Value();
129 IsOK = IsOK && CheckDS(I1->Support(), I1->SupportType());
130 IsOK = IsOK && CheckDS(I1->Geometry(), I1->GeometryType());
136 //=======================================================================
139 //=======================================================================
141 Standard_Boolean TopOpeBRepDS_Check::CheckDS(const Standard_Integer I,
142 const TopOpeBRepDS_Kind K)
146 case TopOpeBRepDS_SURFACE :
148 if(myHDS->NbSurfaces() < I) {
149 if(myMapSurfaceStatus.IsBound(I))
150 myMapSurfaceStatus.UnBind(I);
151 myMapSurfaceStatus.Bind(I, TopOpeBRepDS_NOK);
152 return Standard_False;
154 if(!myMapSurfaceStatus.IsBound(I))
155 myMapSurfaceStatus.Bind(I,TopOpeBRepDS_OK);
156 return Standard_True;
158 case TopOpeBRepDS_CURVE :
160 if(myHDS->NbCurves() < I) {
161 if(myMapCurveStatus.IsBound(I))
162 myMapCurveStatus.UnBind(I);
163 myMapCurveStatus.Bind(I, TopOpeBRepDS_NOK);
164 return Standard_False;
167 if(!myMapCurveStatus.IsBound(I))
168 myMapCurveStatus.Bind(I,TopOpeBRepDS_OK);
169 return Standard_True;
171 case TopOpeBRepDS_POINT :
173 if(myHDS->NbPoints() < I) {
174 if(myMapPointStatus.IsBound(I))
175 myMapPointStatus.UnBind(I);
176 myMapPointStatus.Bind(I, TopOpeBRepDS_NOK);
177 return Standard_False;
179 if(!myMapPointStatus.IsBound(I))
180 myMapPointStatus.Bind(I,TopOpeBRepDS_OK);
181 return Standard_True;
189 if(myHDS->NbShapes() < I) {
190 if(myMapShapeStatus.IsBound(I))
191 myMapShapeStatus.UnBind(I);
192 myMapShapeStatus.Bind(I,TopOpeBRepDS_NOK);
193 return Standard_False;
195 const TopoDS_Shape& S =myHDS->Shape(I);
197 TopAbs_ShapeEnum se=TopAbs_COMPOUND;
200 case TopOpeBRepDS_SOLID : se = TopAbs_SOLID; break;
201 case TopOpeBRepDS_SHELL : se = TopAbs_SHELL; break;
202 case TopOpeBRepDS_FACE : se = TopAbs_FACE; break;
203 case TopOpeBRepDS_WIRE : se = TopAbs_WIRE; break;
204 case TopOpeBRepDS_EDGE : se = TopAbs_EDGE; break;
205 case TopOpeBRepDS_VERTEX : se = TopAbs_VERTEX;break;
209 if(S.ShapeType() != se) {
210 if(myMapShapeStatus.IsBound(I))
211 myMapShapeStatus.UnBind(I);
212 myMapShapeStatus.Bind(I,TopOpeBRepDS_NOK);
213 return Standard_False;
215 if(!myMapShapeStatus.IsBound(I))
216 myMapShapeStatus.Bind(I,TopOpeBRepDS_OK);
217 return Standard_True;;
220 //=======================================================================
221 //function : ChkIntgSamDom
223 //=======================================================================
225 Standard_Boolean TopOpeBRepDS_Check::ChkIntgSamDom()
227 Standard_Boolean b = Standard_True, bb = Standard_False;
228 TopOpeBRepDS_DataStructure& BDS = myHDS->ChangeDS();
229 Standard_Integer NbSh = myHDS->NbShapes(), i, Curr, Loc;
230 for(i = 1;i <= NbSh; i++) {
231 // Verifie que les Shapes de mySameDomaine existe bien dans la DS
232 const TopoDS_Shape& Sind = myHDS->Shape(i);
233 const TopTools_ListOfShape& losi = BDS.ShapeSameDomain(Sind);
234 if(!CheckShapes(losi)) {
238 // Verification de SameDomaineRef
239 Curr = BDS.SameDomainRef(i);
240 Loc = BDS.SameDomainRef(Curr);
241 if(Curr && (Curr != Loc)) {
246 // Verification du type des differents Shapes SameDomain
247 const TopoDS_Shape& Sref = myHDS->Shape(Curr);
248 if(Sind.ShapeType() != Sref.ShapeType()) {
252 // Verifier que ShapeSameDomain(Sref) contient bien Sind
253 // sauf si Sind == Sref
255 const TopTools_ListOfShape& losr = BDS.ShapeSameDomain(Sref);
256 TopTools_ListIteratorOfListOfShape liolos;
257 liolos.Initialize(losr);
258 while (liolos.More() ) {
259 const TopoDS_Shape& Sh = liolos.Value();
260 Loc = myHDS->Shape(Sh);
276 //=======================================================================
277 //function : CheckShapes
279 //=======================================================================
281 Standard_Boolean TopOpeBRepDS_Check::CheckShapes
282 (const TopTools_ListOfShape& LS ) const
284 Standard_Integer index;
285 TopTools_ListIteratorOfListOfShape it(LS);
287 const TopoDS_Shape& itS = it.Value();
288 index = myHDS->Shape(itS);
289 if (!index) return Standard_False;
292 return Standard_True;
295 //=======================================================================
296 //function : OneVertexOnPnt
298 //=======================================================================
300 Standard_Boolean TopOpeBRepDS_Check::OneVertexOnPnt(){
301 Standard_Boolean b = Standard_True;
302 // Standard_Integer i, j, k;
303 Standard_Integer i, j;
304 Standard_Integer Curr1, Curr2, sdr1, sdr2;
305 Standard_Integer NbVe = 0, NbPo = myHDS->NbPoints();
306 // Standard_Real tol, tol1, tol2, Dist;
307 Standard_Real tol1, tol2, Dist;
308 TColStd_IndexedMapOfInteger vert;
310 for(i = 1;i <= myHDS->NbShapes();i++) {
311 const TopoDS_Shape& S = myHDS->Shape(i);
312 if((S.ShapeType() == TopAbs_VERTEX) &&
316 NbVe = vert.Extent();
317 for(i = 1;i <= NbVe; i++) {
318 Curr1 = vert.FindKey(i);
319 const TopoDS_Shape& S1 = myHDS->Shape(Curr1);
320 sdr1 = myHDS->SameDomainReference(S1);
321 for(j = i+1;j <= NbVe; j++) {
322 Curr2 = vert.FindKey(j);
323 const TopoDS_Shape& S2 = myHDS->Shape(Curr2);
324 sdr2 = myHDS->SameDomainReference(S2);
325 tol1 = TopOpeBRepTool_ShapeTool::Tolerance(S1);
326 tol2 = TopOpeBRepTool_ShapeTool::Tolerance(S2);
327 const gp_Pnt& P1 = TopOpeBRepTool_ShapeTool::Pnt(S1);
328 const gp_Pnt& P2 = TopOpeBRepTool_ShapeTool::Pnt(S2);
329 Dist = P1.Distance(P2);
330 if(Dist <= tol1 + tol2) {
335 else if(sdr1 == sdr2) {
339 TopOpeBRepDS_PointExplorer PE(myHDS->DS());
340 for(;PE.More(); PE.Next()) {
341 const TopOpeBRepDS_Point& dsPnt = PE.Point();
342 const gp_Pnt& Pnt1 = dsPnt.Point();
343 tol1 = dsPnt.Tolerance();
344 tol2 = TopOpeBRepTool_ShapeTool::Tolerance(S1);
345 const gp_Pnt& Pnt2 = TopOpeBRepTool_ShapeTool::Pnt(S1);
346 Dist = Pnt1.Distance(Pnt2);
347 if(Dist <= tol1 + tol2) {
352 for(i = 1;i <= NbPo; i++) {
353 TopOpeBRepDS_PointExplorer PE(myHDS->DS());
355 const TopOpeBRepDS_Point& dsPnt1 = myHDS->Point(i);
356 for(j = i+1;j < NbPo;j++) {
357 const TopOpeBRepDS_Point& dsPnt2 = myHDS->Point(j);
358 if(dsPnt1.IsEqual(dsPnt2)) {
367 //=======================================================================
368 //function : CheckEdgeParameter
370 //=======================================================================
372 ///Standard_Boolean TopOpeBRepDS_Check::CheckEdgeParameter() const
373 Standard_Boolean CheckEdgeParameter(const Handle(TopOpeBRepDS_HDataStructure)& myHDS)
375 TopOpeBRepDS_ListIteratorOfListOfInterference it1;
376 const TopOpeBRepDS_DataStructure& DS = myHDS->DS();
377 Standard_Integer i,nshape = DS.NbShapes();
378 Standard_Boolean IsOK = Standard_True;
379 for (i = 1; i <= nshape; i++) {
380 // Integrity of Interferences : Check parameter of EdgeInterferences
381 const TopOpeBRepDS_ListOfInterference& LI = DS.ShapeInterferences(i);
383 while (it1.More() ) {
384 Handle(TopOpeBRepDS_Interference)& I1 = it1.Value();
385 Handle(TopOpeBRepDS_EdgeVertexInterference) EVI =
386 Handle(TopOpeBRepDS_EdgeVertexInterference)::DownCast(I1);
388 Standard_Integer Param = (Standard_Integer ) EVI->Parameter();
390 IsOK = Standard_False;
397 Standard_Integer ncurve = DS.NbCurves();
398 for (i = 1; i <= ncurve; i++) {
399 // Integrity of Interferences : Check parameter of CurvesInterferences
400 const TopOpeBRepDS_ListOfInterference& LI = DS.CurveInterferences(i);
402 while (it1.More() ) {
403 const Handle(TopOpeBRepDS_Interference)& I1 = it1.Value();
404 Handle(TopOpeBRepDS_CurvePointInterference) CPI (Handle(TopOpeBRepDS_CurvePointInterference)::DownCast(I1));
406 Standard_Integer Param =
407 (Standard_Integer ) TopOpeBRepDS_InterferenceTool::Parameter(CPI);
409 IsOK = Standard_False;
419 //=======================================================================
420 //function : PrintIntg
422 //=======================================================================
423 Standard_OStream& TopOpeBRepDS_Check::PrintIntg(Standard_OStream& OS)
425 OS<<std::endl<<std::endl<<"************************************************"<<std::endl;
426 OS<<"state of the DS : (only the tested elements)"<<std::endl<<std::endl;
428 //Display of the geometry
429 PrintMap(myMapSurfaceStatus, "Surface", OS);
430 PrintMap(myMapCurveStatus, "Curve", OS);
431 PrintMap(myMapPointStatus, "Point", OS);
433 //display of the topology
434 TopOpeBRepDS_DataMapIteratorOfDataMapOfCheckStatus DMI(myMapShapeStatus);
435 TopOpeBRepDS_DataMapOfCheckStatus MapVertex, MapEdge, MapWire, MapFace, MapSolid;
437 // different Map keep their index of myMapShapeStatus
438 for(DMI.Reset();DMI.More();DMI.Next()) {
440 const TopoDS_Shape& S =myHDS->Shape(i);
441 switch(S.ShapeType()) {
442 case TopAbs_VERTEX: MapVertex.Bind(i, DMI.Value()); break;
443 case TopAbs_EDGE: MapEdge.Bind(i, DMI.Value()); break;
444 case TopAbs_WIRE: MapWire.Bind(i, DMI.Value()); break;
445 case TopAbs_FACE: MapFace.Bind(i, DMI.Value()); break;
446 case TopAbs_SOLID: MapSolid.Bind(i, DMI.Value()); break;
452 PrintMap(MapVertex, "Vertex", OS);
453 PrintMap(MapEdge, "Edge", OS);
454 PrintMap(MapWire, "Wire", OS);
455 PrintMap(MapFace, "Face", OS);
456 PrintMap(MapSolid, "Solid", OS);
458 OS<<std::endl<<std::endl;
462 //=======================================================================
463 //function : PrintMap
465 //=======================================================================
467 Standard_OStream& TopOpeBRepDS_Check::PrintMap(TopOpeBRepDS_DataMapOfCheckStatus& MapStat,
468 const Standard_CString eltstr,
469 Standard_OStream& OS)
471 TopOpeBRepDS_DataMapIteratorOfDataMapOfCheckStatus DMI(MapStat);
472 DMI.Initialize(MapStat);
474 Standard_Boolean b = Standard_True;
475 OS<<" "<<eltstr<<"\t(/"<<MapStat.Extent()<<")\tnumber ";
477 PrintElts(MapStat, TopOpeBRepDS_OK, b, OS);
478 if(!b) OS<<" = OK"<<std::endl;
479 PrintElts(MapStat, TopOpeBRepDS_NOK, b, OS);
480 if(!b) OS<<" = NOK"<<std::endl;
485 //=======================================================================
486 //function : PrintElts
487 //purpose : Print the elements in the state stat of MapStat
488 //=======================================================================
489 Standard_OStream& TopOpeBRepDS_Check::PrintElts(TopOpeBRepDS_DataMapOfCheckStatus& MapStat,
490 const TopOpeBRepDS_CheckStatus Stat,
492 Standard_OStream& OS)
494 TopOpeBRepDS_DataMapIteratorOfDataMapOfCheckStatus DMI(MapStat);
495 Standard_Boolean bb = !b;
498 TopOpeBRepDS_CheckStatus s;
499 for(DMI.Reset();DMI.More();DMI.Next()) {
504 if(bb){OS<<"\t\tnumber ";bb=!bb;}
511 //=======================================================================
514 //=======================================================================
515 Standard_OStream& TopOpeBRepDS_Check::Print
516 (const TopOpeBRepDS_CheckStatus stat,
517 Standard_OStream& OS)
520 case TopOpeBRepDS_OK: OS<<"OK";break;
521 case TopOpeBRepDS_NOK: OS<<"NOK";break;
527 //=======================================================================
528 //function : PrintShape
530 //=======================================================================
531 Standard_OStream& TopOpeBRepDS_Check::PrintShape
532 (const TopAbs_ShapeEnum SE,
533 Standard_OStream& OS)
536 case TopAbs_SOLID : OS<<"Solid "; break;
537 case TopAbs_SHELL : OS<<"Shell "; break;
538 case TopAbs_FACE : OS<<"Face "; break;
539 case TopAbs_WIRE : OS<<"Wire "; break;
540 case TopAbs_EDGE : OS<<"Edge "; break;
541 case TopAbs_VERTEX : OS<<"Vertex"; break;
548 //=======================================================================
549 //function : PrintShape
551 //=======================================================================
552 Standard_OStream& TopOpeBRepDS_Check::PrintShape
553 (const Standard_Integer index,
554 Standard_OStream& OS)
556 if(myHDS->NbShapes() < index) {
557 OS<<"**PB**IN**TopOpeBRepDS_Check::PrintShape** ";
560 if(!myMapShapeStatus.IsBound(index)) {
561 OS<<"NO CHECK HAS PROCESSING"<<std::endl;
570 //=======================================================================
573 //=======================================================================
575 const Handle(TopOpeBRepDS_HDataStructure)& TopOpeBRepDS_Check::HDS()const
581 //=======================================================================
582 //function : ChangeHDS
584 //=======================================================================
586 Handle(TopOpeBRepDS_HDataStructure)& TopOpeBRepDS_Check::ChangeHDS()