1 // Created by: Peter KURNEV
2 // Copyright (c) 2014 OPEN CASCADE SAS
4 // This file is part of Open CASCADE Technology software library.
6 // This library is free software; you can redistribute it and/or modify it under
7 // the terms of the GNU Lesser General Public License version 2.1 as published
8 // by the Free Software Foundation, with special exception defined in the file
9 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
10 // distribution for complete text of the license and disclaimer of any warranty.
12 // Alternatively, this file may be used under the terms of Open CASCADE
13 // commercial license or contractual agreement.
16 #include <BRep_Tool.hxx>
17 #include <BRepCheck.hxx>
18 #include <BRepCheck_ListOfStatus.hxx>
19 #include <BRepCheck_Solid.hxx>
20 #include <BRepClass3d_SolidClassifier.hxx>
21 #include <Geom_Curve.hxx>
23 #include <MMgt_TShared.hxx>
24 #include <NCollection_Map.hxx>
25 #include <NCollection_Vector.hxx>
26 #include <Precision.hxx>
27 #include <Standard_Type.hxx>
28 #include <TopExp_Explorer.hxx>
29 #include <TopoDS_Builder.hxx>
30 #include <TopoDS_Edge.hxx>
31 #include <TopoDS_Iterator.hxx>
32 #include <TopoDS_Shape.hxx>
33 #include <TopoDS_Shell.hxx>
34 #include <TopoDS_Solid.hxx>
35 #include <TopTools_MapOfShape.hxx>
36 #include <TopTools_ShapeMapHasher.hxx>
38 IMPLEMENT_STANDARD_RTTIEXT(BRepCheck_Solid,BRepCheck_Result)
42 DEFINE_STANDARD_HANDLE(BRepCheck_HSC, MMgt_TShared);
43 //=======================================================================
44 //class : BRepCheck_HSC
46 //=======================================================================
47 class BRepCheck_HSC : public MMgt_TShared {
55 virtual ~BRepCheck_HSC(){
59 BRepClass3d_SolidClassifier& SolidClassifier(){
63 DEFINE_STANDARD_RTTI_INLINE(BRepCheck_HSC,MMgt_TShared);
66 BRepClass3d_SolidClassifier mySC;
70 //=======================================================================
71 //class : BRepCheck_ToolSolid
73 //=======================================================================
74 class BRepCheck_ToolSolid {
79 BRepCheck_ToolSolid() {
80 myIsHole=Standard_False;
81 myPntTol=Precision::Confusion();
82 myPnt.SetCoord(-1.,-1.,-1.);
85 virtual ~BRepCheck_ToolSolid() {
88 void SetSolid(const TopoDS_Solid& aZ) {
92 const TopoDS_Solid& Solid()const {
96 Standard_Boolean IsHole() const {
100 const gp_Pnt& InnerPoint() {
104 Standard_Real CheckTol() const {
109 Standard_Boolean IsOut(BRepCheck_ToolSolid& aOther) {
110 Standard_Boolean bFlag;
113 BRepClass3d_SolidClassifier& aSC=myHSC->SolidClassifier();
115 aSC.Perform(aOther.InnerPoint(), aOther.CheckTol());
117 bFlag=(aState==TopAbs_OUT);
124 Standard_Real aT, aT1, aT2, aPAR_T;
125 TopExp_Explorer aExp;
128 myHSC=new BRepCheck_HSC();
130 BRepClass3d_SolidClassifier& aSC=myHSC->SolidClassifier();
135 aSC.PerformInfinitePoint(::RealSmall());
136 myIsHole=(aSC.State()==TopAbs_IN);
139 aPAR_T=0.43213918; // 10*e^(-PI)
140 aExp.Init(mySolid, TopAbs_EDGE);
141 for (; aExp.More(); aExp.Next()) {
142 const TopoDS_Edge& aE=*((TopoDS_Edge*)&aExp.Current());
143 if (!BRep_Tool::Degenerated(aE)) {
144 Handle(Geom_Curve) aC3D=BRep_Tool::Curve(aE, aT1, aT2);
145 aT=(1.-aPAR_T)*aT1 + aPAR_T*aT2;
146 myPnt=aC3D->Value(aT);
147 myPntTol = BRep_Tool::Tolerance(aE);
154 Standard_Boolean myIsHole;
156 Standard_Real myPntTol;
157 TopoDS_Solid mySolid;
158 Handle(BRepCheck_HSC) myHSC;
161 typedef NCollection_Vector<BRepCheck_ToolSolid>
162 BRepCheck_VectorOfToolSolid;
165 //=======================================================================
166 //function : BRepCheck_Solid
168 //=======================================================================
169 BRepCheck_Solid::BRepCheck_Solid (const TopoDS_Solid& S)
173 //=======================================================================
176 //=======================================================================
177 void BRepCheck_Solid::Blind()
180 // nothing more than in the minimum
181 myBlind = Standard_True;
184 //=======================================================================
185 //function : InContext
187 //=======================================================================
188 void BRepCheck_Solid::InContext(const TopoDS_Shape& )
191 //=======================================================================
194 //=======================================================================
195 void BRepCheck_Solid::Minimum()
200 myMin = Standard_True;
202 Standard_Boolean bFound, bIsHole, bFlag;
203 Standard_Integer i, j, aNbVTS, aNbVTS1, iCntSh, iCntShInt;
205 TopoDS_Iterator aIt, aItF;
207 TopExp_Explorer aExp;
208 TopTools_MapOfShape aMSS;
209 TopAbs_Orientation aOr;
210 BRepCheck_VectorOfToolSolid aVTS;
211 BRepCheck_ListOfStatus thelist;
213 myMap.Bind(myShape, thelist);
214 BRepCheck_ListOfStatus& aLST = myMap(myShape);
215 aLST.Append(BRepCheck_NoError);
217 //-------------------------------------------------
218 // 1. InvalidImbricationOfShells
219 bFound=Standard_False;
220 aExp.Init(myShape, TopAbs_FACE);
221 for (; !bFound && aExp.More(); aExp.Next()) {
222 const TopoDS_Shape& aF=aExp.Current();
224 BRepCheck::Add(myMap(myShape),
225 BRepCheck_InvalidImbricationOfShells);
230 //-------------------------------------------------
232 // - Too many growths,
233 // - There is smt of the solid that is out of solid
236 aIt.Initialize(myShape);
237 for (; aIt.More(); aIt.Next()) {
238 const TopoDS_Shape& aSx=aIt.Value();
240 if (aSx.ShapeType()!=TopAbs_SHELL) {
241 aOr=aSx.Orientation();
242 if (aOr!=TopAbs_INTERNAL) {
243 BRepCheck::Add(myMap(myShape),
244 BRepCheck_BadOrientationOfSubshape);
249 const TopoDS_Shell& aSh=*((TopoDS_Shell*)&aSx);
251 // Skip internal shells
252 bFound=Standard_False;
253 aItF.Initialize(aSh);
254 for (; !bFound && aItF.More(); aItF.Next()) {
255 const TopoDS_Shape& aF=aItF.Value();
256 aOr=aF.Orientation();
257 if (aOr==TopAbs_INTERNAL) {
268 // Skip not closed shells
269 if (!BRep_Tool::IsClosed(aSh)) {
276 BRepCheck_ToolSolid aTS;
280 }//for (; aIt.More(); aIt.Next()) {
282 if (!iCntSh && iCntShInt) {
283 // all shells in the solid are internal
284 BRepCheck::Add(myMap(myShape),
285 BRepCheck_BadOrientationOfSubshape);
294 for (i=0; i<aNbVTS; ++i) {
295 BRepCheck_ToolSolid& aTS=aVTS(i);
298 bIsHole=aTS.IsHole();
303 BRepCheck::Add(myMap(myShape),
304 BRepCheck_EnclosedRegion);
310 bFound=Standard_False;
312 for (i=0; !bFound && i<aNbVTS1; ++i) {
313 BRepCheck_ToolSolid& aTSi=aVTS(i);
315 for (j=i+1; !bFound && j<aNbVTS; ++j) {
316 BRepCheck_ToolSolid& aTSj=aVTS(j);
318 bFlag=aTSi.IsOut(aTSj);
320 // smt of solid is out of solid
321 BRepCheck::Add(myMap(myShape),
322 BRepCheck_SubshapeNotInShape);
328 //myMin = Standard_True;