1 // Created on: 2002-07-18
2 // Created by: QA Admin
3 // Copyright (c) 2002-2012 OPEN CASCADE SAS
5 // The content of this file is subject to the Open CASCADE Technology Public
6 // License Version 6.5 (the "License"). You may not use the content of this file
7 // except in compliance with the License. Please obtain a copy of the License
8 // at http://www.opencascade.org and read it completely before using this file.
10 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
11 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
13 // The Original Code and all software distributed under the License is
14 // distributed on an "AS IS" basis, without warranty of any kind, and the
15 // Initial Developer hereby disclaims all such warranties, including without
16 // limitation, any warranties of merchantability, fitness for a particular
17 // purpose or non-infringement. Please see the License for the specific terms
18 // and conditions governing the rights and limitations under the License.
23 #include <Draw_Interpretor.hxx>
25 #include <DrawTrSurf.hxx>
26 #include <AIS_InteractiveContext.hxx>
27 #include <ViewerTest.hxx>
28 #include <AIS_Shape.hxx>
29 #include <TopoDS_Shape.hxx>
30 #include <TopoDS_Vertex.hxx>
32 #include <TopExp_Explorer.hxx>
33 #include <TopoDS_Face.hxx>
35 #include <BRepBndLib.hxx>
37 #include <BRep_Tool.hxx>
38 #include <BRepAlgoAPI_Section.hxx>
39 #include <BRepAlgo_Section.hxx>
40 #include <Precision.hxx>
41 #include <Standard_ErrorHandler.hxx>
45 //=======================================================================
48 //=======================================================================
49 static Standard_Integer OCC527(Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
54 // 1. Verify amount of arguments of the command
55 //if (argc < 2) { di << "OCC527 FAULTY. Use : OCC527 shape "; return 0;}
56 if (argc < 2 || argc > 3) {
57 di << "Usage : " << argv[0] << " shape [BRepAlgoAPI/BRepAlgo = 1/0]" << "\n";
60 Standard_Boolean IsBRepAlgoAPI = Standard_True;
62 Standard_Integer IsB = Draw::Atoi(argv[2]);
64 IsBRepAlgoAPI = Standard_False;
65 //#if ! defined(BRepAlgo_def04)
66 // di << "Error: There is not BRepAlgo_Section class" << "\n";
72 // 2. Get selected shape
73 TopoDS_Shape aShape = DBRep::Get(argv[1]);
74 if(aShape.IsNull()) { di << "OCC527 FAULTY. Entry shape is NULL"; return 0;}
76 // 3. Explode entry shape on faces and build sections from Zmin to Zmax with step aStep
77 const Standard_Real Zmin = -40.228173882121, Zmax = 96.408126285268, aStep = 1.0;
78 char str[100]; str[0] = 0; Sprintf(str,"Test range: [%f, %f] with step %f\n",Zmin,Zmax,aStep); di << str;
80 TopExp_Explorer aExp1;
81 for (aExp1.Init(aShape,TopAbs_FACE); aExp1.More(); aExp1.Next())
84 str[0] = 0; Sprintf(str,"Face #%d: \t",nbf++); di << str;
85 TopoDS_Face aFace = TopoDS::Face(aExp1.Current());
87 // Build BndBox in order to avoid try of building section
88 // if plane of the one does not intersect BndBox of the face
90 BRepBndLib::Add(aFace,aFaceBox);
91 Standard_Real X1,X2,Y1,Y2,Z1,Z2;
92 aFaceBox.Get(X1,Y1,Z1,X2,Y2,Z2);
94 // Build sections from Zmin to Zmax with step aStep
95 Standard_Boolean wasBuilt = Standard_False;
96 double gmaxdist = 0.0, gzmax = Zmax;
97 for (double zcur = Zmax; zcur > Zmin; zcur -= aStep)
99 // If plane of the section does not intersect BndBox of the face do nothing
100 if(zcur < Z1 || zcur > Z2 ) continue;
102 // Build current section
103 gp_Pln pl(0,0,1,-zcur);
104 //#if ! defined(BRepAlgoAPI_def01)
105 // BRepAlgoAPI_Section aSection(aFace,pl,Standard_False);
107 // BRepAlgo_Section aSection(aFace,pl,Standard_False);
109 // aSection.Approximation(Standard_True);
111 // // If section was built meassure distance between vertexes and plane of the one. Max distance is stored.
112 // if (aSection.IsDone())
114 Standard_Boolean IsDone;
115 TopoDS_Shape aResult;
117 di << "BRepAlgoAPI_Section aSection(aFace,pl,Standard_False)" <<"\n";
118 BRepAlgoAPI_Section aSection(aFace,pl,Standard_False);
119 aSection.Approximation(Standard_True);
121 IsDone = aSection.IsDone();
122 aResult = aSection.Shape();
124 di << "BRepAlgo_Section aSection(aFace,pl,Standard_False)" <<"\n";
125 BRepAlgo_Section aSection(aFace,pl,Standard_False);
126 aSection.Approximation(Standard_True);
128 IsDone = aSection.IsDone();
129 aResult = aSection.Shape();
134 // TopoDS_Shape aResult = aSection.Shape();
135 if (!aResult.IsNull())
137 double lmaxdist = 0.0;
138 double lmaxtoler = 0.0;
139 TopExp_Explorer aExp2;
140 for (aExp2.Init(aResult,TopAbs_VERTEX); aExp2.More(); aExp2.Next())
142 TopoDS_Vertex aV = TopoDS::Vertex(aExp2.Current());
143 Standard_Real toler = BRep_Tool::Tolerance(aV);
144 double dist = pl.Distance(BRep_Tool::Pnt(aV));
145 if (dist > lmaxdist) lmaxdist = dist;
146 wasBuilt = Standard_True;
147 // If section was built check distance beetwen vertexes and plane of the one
151 // if(gmaxdist > Precision::Confusion())
152 // Sprintf(str,"Dist=%f, Param=%f FAULTY\n",gmaxdist,gzmax);
154 // Sprintf(str,"Dist=%f, Param=%f\n",gmaxdist,gzmax);
156 Sprintf(str,"Dist=%f, Toler=%f, Param=%f FAULTY\n",dist,toler,gzmax);
158 Sprintf(str,"Dist=%f, Toler=%f, Param=%f\n",dist,toler,gzmax);
160 // else Sprintf(str,"No result\n");
163 if (lmaxdist > gmaxdist)
173 catch (Standard_Failure) {di << "OCC527 Exception \n" ;return 0;}
178 #include <StlMesh_Mesh.hxx>
179 #include <StlTransfer.hxx>
180 //=======================================================================
183 //=======================================================================
184 static Standard_Integer OCC1048 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
186 // Verify amount of arguments of the command
187 if (argc < 2) { di << "Usage : " << argv[0] <<" shape"; return 1;}
189 TopoDS_Shape aShape = DBRep::Get(argv[1]);
191 Standard_Real theDeflection = 0.006;
192 Handle(StlMesh_Mesh) theStlMesh = new StlMesh_Mesh;
193 StlTransfer::BuildIncrementalMesh(aShape, theDeflection, Standard_False, theStlMesh);
195 Standard_Integer NBTRIANGLES = theStlMesh->NbTriangles();
196 di<<"Info: Number of triangles = "<<NBTRIANGLES<<"\n";
201 void QABugs::Commands_2(Draw_Interpretor& theCommands) {
202 const char *group = "QABugs";
204 //theCommands.Add("OCC527", "OCC527 shape", __FILE__, OCC527, group);
205 theCommands.Add("OCC527", "OCC527 shape [BRepAlgoAPI/BRepAlgo = 1/0]", __FILE__, OCC527, group);
206 theCommands.Add("OCC1048", "OCC1048 shape", __FILE__, OCC1048, group);