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 double gmaxdist = 0.0, gzmax = Zmax;
92 for (double zcur = Zmax; zcur > Zmin; zcur -= aStep)
94 // If plane of the section does not intersect BndBox of the face do nothing
95 if(zcur < Z1 || zcur > Z2 ) continue;
97 // Build current section
98 gp_Pln pl(0,0,1,-zcur);
99 //#if ! defined(BRepAlgoAPI_def01)
100 // BRepAlgoAPI_Section aSection(aFace,pl,Standard_False);
102 // BRepAlgo_Section aSection(aFace,pl,Standard_False);
104 // aSection.Approximation(Standard_True);
106 // // If section was built meassure distance between vertexes and plane of the one. Max distance is stored.
107 // if (aSection.IsDone())
109 Standard_Boolean IsDone;
110 TopoDS_Shape aResult;
112 di << "BRepAlgoAPI_Section aSection(aFace,pl,Standard_False)" <<"\n";
113 BRepAlgoAPI_Section aSection(aFace,pl,Standard_False);
114 aSection.Approximation(Standard_True);
116 IsDone = aSection.IsDone();
117 aResult = aSection.Shape();
119 di << "BRepAlgo_Section aSection(aFace,pl,Standard_False)" <<"\n";
120 BRepAlgo_Section aSection(aFace,pl,Standard_False);
121 aSection.Approximation(Standard_True);
123 IsDone = aSection.IsDone();
124 aResult = aSection.Shape();
129 // TopoDS_Shape aResult = aSection.Shape();
130 if (!aResult.IsNull())
132 double lmaxdist = 0.0;
133 TopExp_Explorer aExp2;
134 for (aExp2.Init(aResult,TopAbs_VERTEX); aExp2.More(); aExp2.Next())
136 TopoDS_Vertex aV = TopoDS::Vertex(aExp2.Current());
137 Standard_Real toler = BRep_Tool::Tolerance(aV);
138 double dist = pl.Distance(BRep_Tool::Pnt(aV));
139 if (dist > lmaxdist) lmaxdist = dist;
140 // If section was built check distance beetwen vertexes and plane of the one
144 // if(gmaxdist > Precision::Confusion())
145 // Sprintf(str,"Dist=%f, Param=%f FAULTY\n",gmaxdist,gzmax);
147 // Sprintf(str,"Dist=%f, Param=%f\n",gmaxdist,gzmax);
149 Sprintf(str,"Dist=%f, Toler=%f, Param=%f FAULTY\n",dist,toler,gzmax);
151 Sprintf(str,"Dist=%f, Toler=%f, Param=%f\n",dist,toler,gzmax);
153 // else Sprintf(str,"No result\n");
156 if (lmaxdist > gmaxdist)
166 catch (Standard_Failure) {di << "OCC527 Exception \n" ;return 0;}
171 #include <StlMesh_Mesh.hxx>
172 #include <StlTransfer.hxx>
173 //=======================================================================
176 //=======================================================================
177 static Standard_Integer OCC1048 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
179 // Verify amount of arguments of the command
180 if (argc < 2) { di << "Usage : " << argv[0] <<" shape"; return 1;}
182 TopoDS_Shape aShape = DBRep::Get(argv[1]);
184 Standard_Real theDeflection = 0.006;
185 Handle(StlMesh_Mesh) theStlMesh = new StlMesh_Mesh;
186 StlTransfer::BuildIncrementalMesh(aShape, theDeflection, Standard_False, theStlMesh);
188 Standard_Integer NBTRIANGLES = theStlMesh->NbTriangles();
189 di<<"Info: Number of triangles = "<<NBTRIANGLES<<"\n";
194 void QABugs::Commands_2(Draw_Interpretor& theCommands) {
195 const char *group = "QABugs";
197 //theCommands.Add("OCC527", "OCC527 shape", __FILE__, OCC527, group);
198 theCommands.Add("OCC527", "OCC527 shape [BRepAlgoAPI/BRepAlgo = 1/0]", __FILE__, OCC527, group);
199 theCommands.Add("OCC1048", "OCC1048 shape", __FILE__, OCC1048, group);