1 // Created on: 2002-07-18
2 // Created by: QA Admin
3 // Copyright (c) 2002-2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
7 // This library is free software; you can redistribute it and / or modify it
8 // under the terms of the GNU Lesser General Public version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
19 #include <Draw_Interpretor.hxx>
21 #include <DrawTrSurf.hxx>
22 #include <AIS_InteractiveContext.hxx>
23 #include <ViewerTest.hxx>
24 #include <AIS_Shape.hxx>
25 #include <TopoDS_Shape.hxx>
26 #include <TopoDS_Vertex.hxx>
28 #include <TopExp_Explorer.hxx>
29 #include <TopoDS_Face.hxx>
31 #include <BRepBndLib.hxx>
33 #include <BRep_Tool.hxx>
34 #include <BRepAlgoAPI_Section.hxx>
35 #include <BRepAlgo_Section.hxx>
36 #include <Precision.hxx>
37 #include <Standard_ErrorHandler.hxx>
41 //=======================================================================
44 //=======================================================================
45 static Standard_Integer OCC527(Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
50 // 1. Verify amount of arguments of the command
51 //if (argc < 2) { di << "OCC527 FAULTY. Use : OCC527 shape "; return 0;}
52 if (argc < 2 || argc > 3) {
53 di << "Usage : " << argv[0] << " shape [BRepAlgoAPI/BRepAlgo = 1/0]" << "\n";
56 Standard_Boolean IsBRepAlgoAPI = Standard_True;
58 Standard_Integer IsB = Draw::Atoi(argv[2]);
60 IsBRepAlgoAPI = Standard_False;
61 //#if ! defined(BRepAlgo_def04)
62 // di << "Error: There is not BRepAlgo_Section class" << "\n";
68 // 2. Get selected shape
69 TopoDS_Shape aShape = DBRep::Get(argv[1]);
70 if(aShape.IsNull()) { di << "OCC527 FAULTY. Entry shape is NULL"; return 0;}
72 // 3. Explode entry shape on faces and build sections from Zmin to Zmax with step aStep
73 const Standard_Real Zmin = -40.228173882121, Zmax = 96.408126285268, aStep = 1.0;
74 char str[100]; str[0] = 0; Sprintf(str,"Test range: [%f, %f] with step %f\n",Zmin,Zmax,aStep); di << str;
76 TopExp_Explorer aExp1;
77 for (aExp1.Init(aShape,TopAbs_FACE); aExp1.More(); aExp1.Next())
80 str[0] = 0; Sprintf(str,"Face #%d: \t",nbf++); di << str;
81 TopoDS_Face aFace = TopoDS::Face(aExp1.Current());
83 // Build BndBox in order to avoid try of building section
84 // if plane of the one does not intersect BndBox of the face
86 BRepBndLib::Add(aFace,aFaceBox);
87 Standard_Real X1,X2,Y1,Y2,Z1,Z2;
88 aFaceBox.Get(X1,Y1,Z1,X2,Y2,Z2);
90 // Build sections from Zmin to Zmax with step aStep
91 Standard_Boolean wasBuilt = Standard_False;
92 double gmaxdist = 0.0, gzmax = Zmax;
93 for (double zcur = Zmax; zcur > Zmin; zcur -= aStep)
95 // If plane of the section does not intersect BndBox of the face do nothing
96 if(zcur < Z1 || zcur > Z2 ) continue;
98 // Build current section
99 gp_Pln pl(0,0,1,-zcur);
100 //#if ! defined(BRepAlgoAPI_def01)
101 // BRepAlgoAPI_Section aSection(aFace,pl,Standard_False);
103 // BRepAlgo_Section aSection(aFace,pl,Standard_False);
105 // aSection.Approximation(Standard_True);
107 // // If section was built meassure distance between vertexes and plane of the one. Max distance is stored.
108 // if (aSection.IsDone())
110 Standard_Boolean IsDone;
111 TopoDS_Shape aResult;
113 di << "BRepAlgoAPI_Section aSection(aFace,pl,Standard_False)" <<"\n";
114 BRepAlgoAPI_Section aSection(aFace,pl,Standard_False);
115 aSection.Approximation(Standard_True);
117 IsDone = aSection.IsDone();
118 aResult = aSection.Shape();
120 di << "BRepAlgo_Section aSection(aFace,pl,Standard_False)" <<"\n";
121 BRepAlgo_Section aSection(aFace,pl,Standard_False);
122 aSection.Approximation(Standard_True);
124 IsDone = aSection.IsDone();
125 aResult = aSection.Shape();
130 // TopoDS_Shape aResult = aSection.Shape();
131 if (!aResult.IsNull())
133 double lmaxdist = 0.0;
134 TopExp_Explorer aExp2;
135 for (aExp2.Init(aResult,TopAbs_VERTEX); aExp2.More(); aExp2.Next())
137 TopoDS_Vertex aV = TopoDS::Vertex(aExp2.Current());
138 Standard_Real toler = BRep_Tool::Tolerance(aV);
139 double dist = pl.Distance(BRep_Tool::Pnt(aV));
140 if (dist > lmaxdist) lmaxdist = dist;
141 wasBuilt = Standard_True;
142 // If section was built check distance beetwen vertexes and plane of the one
146 // if(gmaxdist > Precision::Confusion())
147 // Sprintf(str,"Dist=%f, Param=%f FAULTY\n",gmaxdist,gzmax);
149 // Sprintf(str,"Dist=%f, Param=%f\n",gmaxdist,gzmax);
151 Sprintf(str,"Dist=%f, Toler=%f, Param=%f FAULTY\n",dist,toler,gzmax);
153 Sprintf(str,"Dist=%f, Toler=%f, Param=%f\n",dist,toler,gzmax);
155 // else Sprintf(str,"No result\n");
158 if (lmaxdist > gmaxdist)
168 catch (Standard_Failure) {di << "OCC527 Exception \n" ;return 0;}
173 #include <StlMesh_Mesh.hxx>
174 #include <StlTransfer.hxx>
175 //=======================================================================
178 //=======================================================================
179 static Standard_Integer OCC1048 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
181 // Verify amount of arguments of the command
182 if (argc < 2) { di << "Usage : " << argv[0] <<" shape"; return 1;}
184 TopoDS_Shape aShape = DBRep::Get(argv[1]);
186 Standard_Real theDeflection = 0.006;
187 Handle(StlMesh_Mesh) theStlMesh = new StlMesh_Mesh;
188 StlTransfer::BuildIncrementalMesh(aShape, theDeflection, Standard_False, theStlMesh);
190 Standard_Integer NBTRIANGLES = theStlMesh->NbTriangles();
191 di<<"Info: Number of triangles = "<<NBTRIANGLES<<"\n";
196 void QABugs::Commands_2(Draw_Interpretor& theCommands) {
197 const char *group = "QABugs";
199 //theCommands.Add("OCC527", "OCC527 shape", __FILE__, OCC527, group);
200 theCommands.Add("OCC527", "OCC527 shape [BRepAlgoAPI/BRepAlgo = 1/0]", __FILE__, OCC527, group);
201 theCommands.Add("OCC1048", "OCC1048 shape", __FILE__, OCC1048, group);