0024624: Lost word in license statement in source files
[occt.git] / src / QABugs / QABugs_2.cxx
CommitLineData
b311480e 1// Created on: 2002-07-18
2// Created by: QA Admin
973c2be1 3// Copyright (c) 2002-2014 OPEN CASCADE SAS
b311480e 4//
973c2be1 5// This file is part of Open CASCADE Technology software library.
b311480e 6//
d5f74e42 7// This library is free software; you can redistribute it and/or modify it under
8// the terms of the GNU Lesser General Public License version 2.1 as published
973c2be1 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.
b311480e 12//
973c2be1 13// Alternatively, this file may be used under the terms of Open CASCADE
14// commercial license or contractual agreement.
b311480e 15
1cd84fee 16#include <QABugs.hxx>
7fd59977 17
91322f44 18#include <Draw.hxx>
7fd59977 19#include <Draw_Interpretor.hxx>
20#include <DBRep.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>
27
28#include <TopExp_Explorer.hxx>
29#include <TopoDS_Face.hxx>
30#include <TopoDS.hxx>
31#include <BRepBndLib.hxx>
32#include <gp_Pln.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>
38
39#include <stdio.h>
40
41//=======================================================================
42//function : OCC527
43//purpose :
44//=======================================================================
45static Standard_Integer OCC527(Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
46{
47 try
48 {
49 OCC_CATCH_SIGNALS
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";
54 return 1;
55 }
56 Standard_Boolean IsBRepAlgoAPI = Standard_True;
57 if (argc == 3) {
91322f44 58 Standard_Integer IsB = Draw::Atoi(argv[2]);
7fd59977 59 if (IsB != 1) {
60 IsBRepAlgoAPI = Standard_False;
61//#if ! defined(BRepAlgo_def04)
62// di << "Error: There is not BRepAlgo_Section class" << "\n";
63// return 1;
64//#endif
65 }
66 }
67
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;}
71
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;
91322f44 74 char str[100]; str[0] = 0; Sprintf(str,"Test range: [%f, %f] with step %f\n",Zmin,Zmax,aStep); di << str;
7fd59977 75 int nbf = 0;
76 TopExp_Explorer aExp1;
77 for (aExp1.Init(aShape,TopAbs_FACE); aExp1.More(); aExp1.Next())
78 {
79 // Process one face
91322f44 80 str[0] = 0; Sprintf(str,"Face #%d: \t",nbf++); di << str;
7fd59977 81 TopoDS_Face aFace = TopoDS::Face(aExp1.Current());
82
83 // Build BndBox in order to avoid try of building section
84 // if plane of the one does not intersect BndBox of the face
85 Bnd_Box aFaceBox;
86 BRepBndLib::Add(aFace,aFaceBox);
87 Standard_Real X1,X2,Y1,Y2,Z1,Z2;
88 aFaceBox.Get(X1,Y1,Z1,X2,Y2,Z2);
89
90 // Build sections from Zmin to Zmax with step aStep
7fd59977 91 double gmaxdist = 0.0, gzmax = Zmax;
92 for (double zcur = Zmax; zcur > Zmin; zcur -= aStep)
93 {
94 // If plane of the section does not intersect BndBox of the face do nothing
95 if(zcur < Z1 || zcur > Z2 ) continue;
96
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);
101//#else
102// BRepAlgo_Section aSection(aFace,pl,Standard_False);
103//#endif
104// aSection.Approximation(Standard_True);
105// aSection.Build();
106// // If section was built meassure distance between vertexes and plane of the one. Max distance is stored.
107// if (aSection.IsDone())
108
109 Standard_Boolean IsDone;
110 TopoDS_Shape aResult;
111 if (IsBRepAlgoAPI) {
112 di << "BRepAlgoAPI_Section aSection(aFace,pl,Standard_False)" <<"\n";
113 BRepAlgoAPI_Section aSection(aFace,pl,Standard_False);
114 aSection.Approximation(Standard_True);
115 aSection.Build();
116 IsDone = aSection.IsDone();
117 aResult = aSection.Shape();
118 } else {
119 di << "BRepAlgo_Section aSection(aFace,pl,Standard_False)" <<"\n";
120 BRepAlgo_Section aSection(aFace,pl,Standard_False);
121 aSection.Approximation(Standard_True);
122 aSection.Build();
123 IsDone = aSection.IsDone();
124 aResult = aSection.Shape();
125 }
126
127 if (IsDone)
128 {
129// TopoDS_Shape aResult = aSection.Shape();
130 if (!aResult.IsNull())
131 {
132 double lmaxdist = 0.0;
7fd59977 133 TopExp_Explorer aExp2;
134 for (aExp2.Init(aResult,TopAbs_VERTEX); aExp2.More(); aExp2.Next())
135 {
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;
7fd59977 140 // If section was built check distance beetwen vertexes and plane of the one
141 str[0] =0;
142// if (wasBuilt)
143// {
144// if(gmaxdist > Precision::Confusion())
91322f44 145// Sprintf(str,"Dist=%f, Param=%f FAULTY\n",gmaxdist,gzmax);
7fd59977 146// else
91322f44 147// Sprintf(str,"Dist=%f, Param=%f\n",gmaxdist,gzmax);
7fd59977 148 if(dist > toler)
91322f44 149 Sprintf(str,"Dist=%f, Toler=%f, Param=%f FAULTY\n",dist,toler,gzmax);
7fd59977 150 else
91322f44 151 Sprintf(str,"Dist=%f, Toler=%f, Param=%f\n",dist,toler,gzmax);
7fd59977 152// }
91322f44 153// else Sprintf(str,"No result\n");
7fd59977 154 di << str;
155 }
156 if (lmaxdist > gmaxdist)
157 {
158 gmaxdist = lmaxdist;
159 gzmax = zcur;
160 }
161 }
162 }
163 }
164 }
165 }
166 catch (Standard_Failure) {di << "OCC527 Exception \n" ;return 0;}
167
168 return 0;
169}
170
171#include <StlMesh_Mesh.hxx>
172#include <StlTransfer.hxx>
173//=======================================================================
174//function : OCC1048
175//purpose :
176//=======================================================================
177static Standard_Integer OCC1048 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
178{
179 // Verify amount of arguments of the command
180 if (argc < 2) { di << "Usage : " << argv[0] <<" shape"; return 1;}
181
182 TopoDS_Shape aShape = DBRep::Get(argv[1]);
183
184 Standard_Real theDeflection = 0.006;
185 Handle(StlMesh_Mesh) theStlMesh = new StlMesh_Mesh;
416d4426 186 StlTransfer::BuildIncrementalMesh(aShape, theDeflection, Standard_False, theStlMesh);
7fd59977 187
188 Standard_Integer NBTRIANGLES = theStlMesh->NbTriangles();
189 di<<"Info: Number of triangles = "<<NBTRIANGLES<<"\n";
190
191 return 0;
192}
193
1cd84fee 194void QABugs::Commands_2(Draw_Interpretor& theCommands) {
1365140b 195 const char *group = "QABugs";
7fd59977 196
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);
200 return;
201}