0028643: Coding rules - eliminate GCC compiler warnings -Wmisleading-indentation
[occt.git] / src / QABugs / QABugs_18.cxx
CommitLineData
b311480e 1// Created on: 2002-03-19
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.
7fd59977 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>
7fd59977 25
7fd59977 26#include <V3d_Viewer.hxx>
27#include <V3d_View.hxx>
7fd59977 28
29#include <TDocStd_Application.hxx>
30#include <TDocStd_Document.hxx>
31#include <DDocStd.hxx>
32#include <CDF.hxx>
33
34#include <Resource_Manager.hxx>
7fd59977 35#include <TopoDS_Wire.hxx>
36#include <BRepTools_WireExplorer.hxx>
37#include <TopoDS_Vertex.hxx>
38#include <TopoDS.hxx>
39#include <BRep_Tool.hxx>
40#include <TopExp.hxx>
41#include <Geom_Curve.hxx>
42#include <GCPnts_UniformAbscissa.hxx>
43#include <GeomAdaptor_Curve.hxx>
91a16bc7 44#include <Standard_Assert.hxx>
7fd59977 45
46#define DEFAULT_COLOR Quantity_NOC_GOLDENROD
47
7fd59977 48static Standard_Integer OCC267 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
49{
50 if ( argc != 3) {
586db386 51 di << "ERROR OCC267: Usage : " << argv[0] << " DOC path\n";
7fd59977 52 return 1;
53 }
54
55 Handle(TDocStd_Document) D;
56 if (!DDocStd::GetDocument(argv[1],D)) return 1;
57 TCollection_ExtendedString path (argv[2]);
6fe96f84 58 Handle(TDocStd_Application) A = DDocStd::GetApplication();
7fd59977 59
15e8b082
M
60 PCDM_StoreStatus theStatus = A->SaveAs(D,path);
61 if (theStatus == PCDM_SS_OK ) {
586db386 62 di << "OCC267 : PCDM_StoreStatus = PCDM_SS_OK\n";
7fd59977 63 } else {
586db386 64 di << "OCC267 : PCDM_StoreStatus = Bad_Store_Status\n";
7fd59977 65 }
66
67 return 0;
68}
69
70static Standard_Integer OCC181 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
71{
72 if ( argc != 5) {
586db386 73 di << "ERROR OCC181: Usage : " << argv[0] << " FileName path1 path2 verbose=0/1\n";
7fd59977 74 return 1;
75 }
76 Standard_CString aFileName = argv[1];
77 Standard_CString aDir1 = argv[2];
78 Standard_CString aDir2 = argv[3];
91322f44 79 Standard_Integer verboseInt = Draw::Atoi(argv[4]);
7fd59977 80
81 Standard_Boolean verboseBool = Standard_False;
82 if (verboseInt != 0) {
83 verboseBool = Standard_True;
84 }
85
86 TCollection_AsciiString Env1, Env2, CSF_ = "set env(CSF_";
87 Env1 = CSF_ + aFileName + "UserDefaults) " + aDir1;
88 Env2 = CSF_ + aFileName + "UserDefaults) " + aDir2;
89
90 di.Eval(Env1.ToCString());
91
92 Resource_Manager aManager(aFileName, verboseBool);
93
94 di.Eval(Env2.ToCString());
95
96 Standard_Boolean aStatus = aManager.Save();
97
98 if (aStatus) {
586db386 99 di << "\nOCC181 : Status = TRUE\n";
7fd59977 100 } else {
586db386 101 di << "\nOCC181 : Status = FALSE\n";
7fd59977 102 }
103
104 return 0;
105}
106
f9ac4dc9 107static Standard_Integer OCC27849 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
108{
109 if (argc != 3) {
110 di << "Usage : " << argv[0] << " <environment variable name> <resource name>\n";
111 return 1;
112 }
113 Standard_CString aEnvName = argv[1];
114 Standard_CString aResName = argv[2];
115
116 Resource_Manager aManager (aEnvName);
117 if (aManager.Find (aResName))
118 {
119 di << aManager.Value (aResName);
120 }
121 else
122 {
123 di << "Error: could not find resource " << aResName;
124 }
125
126 return 0;
127}
128
7fd59977 129static Standard_Real delta_percent (Standard_Real a, Standard_Real b)
130{
131 Standard_Real result;
132 if (b != 0.) {
133 result = fabs( (a - b) / b ) * 100.;
134 } else if (a != 0.) {
135 result = fabs( (a - b) / a ) * 100.;
136 } else {
137 result = 0.;
138 }
139 return result;
140}
141
142static Standard_Integer OCC367 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
143{
144 if ( argc != 7) {
586db386 145 di << "ERROR : Usage : " << argv[0] << " shape step goodX goodY goodZ percent_tolerance\n";
7fd59977 146 return 1;
147 }
148
149 TopoDS_Wire myTopoDSWire = TopoDS::Wire(DBRep::Get(argv[1]));
91322f44 150 Standard_Real l = Draw::Atof(argv[2]);
151 Standard_Real goodX = Draw::Atof(argv[3]);
152 Standard_Real goodY = Draw::Atof(argv[4]);
153 Standard_Real goodZ = Draw::Atof(argv[5]);
154 Standard_Real percent = Draw::Atof(argv[6]);
7fd59977 155 Standard_Boolean Status = Standard_False;
156
157 // Find the first vertex of the wire
158 BRepTools_WireExplorer wire_exp(myTopoDSWire);
159 TopoDS_Vertex vlast;
160 {
161 TopoDS_Vertex vw1, vw2;
162 TopExp::Vertices(myTopoDSWire,vw1,vw2);
163 TopoDS_Vertex ve1, ve2;
164 TopoDS_Edge edge = TopoDS::Edge(wire_exp.Current());
165 TopExp::Vertices(edge,ve1,ve2);
166 if (vw1.IsSame(ve1) || vw1.IsSame(ve2))
167 vlast = vw1;
168 else {
91a16bc7 169 Standard_ASSERT_RAISE(vw2.IsSame(ve1) || vw2.IsSame(ve2), "Disconnected vertices");
7fd59977 170 vlast = vw2;
171 }
172 }
173 Standard_Integer EdgeIndex = 0;
174 Standard_Real FirstEdgeX, FirstEdgeY, FirstEdgeZ, deltaX, deltaY, deltaZ;
175 FirstEdgeX = FirstEdgeY = FirstEdgeZ = deltaX = deltaY = deltaZ = 0.;
176 for ( ; wire_exp.More(); wire_exp.Next())
177 {
178 EdgeIndex++;
179 di << "\n\n New Edge \n" << "\n";
180 Standard_Real newufirst, newulast;
181 TopoDS_Edge edge = TopoDS::Edge(wire_exp.Current());
182 Standard_Real ufirst, ulast;
183 Handle(Geom_Curve) acurve;
184 TopoDS_Vertex ve1, ve2;
185 TopExp::Vertices(edge,ve1,ve2);
186 if (ve1.IsSame(vlast))
187 {
188 acurve = BRep_Tool::Curve(edge, ufirst, ulast);
189 newufirst = ufirst;
190 newulast = ulast;
191 vlast = ve2;
192 }
193 else
194 {
91a16bc7
K
195 Standard_ASSERT_RAISE(ve2.IsSame(vlast), "Not the same vertex");
196 Standard_ASSERT_RAISE(wire_exp.Orientation() == TopAbs_REVERSED, "Wire should be REVERSED");
7fd59977 197 acurve = BRep_Tool::Curve( edge, ufirst, ulast );
198 newufirst = acurve->ReversedParameter( ufirst );
199 newulast = acurve->ReversedParameter( ulast );
200 acurve = acurve->Reversed( );
201 vlast = ve1;
202 }
203
204 GeomAdaptor_Curve curve;
205 GCPnts_UniformAbscissa algo;
206 curve.Load(acurve);
207 algo.Initialize( curve, l, newufirst, newulast );
208 if (!algo.IsDone())
209 di << "Not Done!!!" << "\n";
210 Standard_Integer maxIndex =algo.NbPoints();
211 for (Standard_Integer Index = 1; Index<=maxIndex;Index++) {
212 Standard_Real t = algo.Parameter(Index);
213 gp_Pnt pt3 = curve.Value(t);
214 di << "Parameter t = " << t << "\n";
215 di << "Value Pnt = " << pt3.X()<<" " <<pt3.Y()<<" " << pt3.Z() << "\n";
216 if (EdgeIndex == 1 && Index == maxIndex) {
217 FirstEdgeX = pt3.X();
218 FirstEdgeY = pt3.Y();
219 FirstEdgeZ = pt3.Z();
220 deltaX = delta_percent(FirstEdgeX, goodX);
221 deltaY = delta_percent(FirstEdgeY, goodY);
222 deltaZ = delta_percent(FirstEdgeZ, goodZ);
223 if (deltaX <= percent && deltaY <= percent && deltaZ <= percent) {
224 Status = Standard_True;
225 }
226 }
227 }
228 }
229 di << "\n\nFirstEdge = " << FirstEdgeX <<" " << FirstEdgeY <<" " << FirstEdgeZ << "\n";
230 di << "deltaX = " << deltaX << " deltaY = " << deltaY << " deltaZ = " << deltaZ << "\n";
231 if (Status) {
586db386 232 di << argv[0] << " : OK\n";
7fd59977 233 } else {
586db386 234 di << argv[0] << " : ERROR\n";
7fd59977 235 }
236
237 return 0;
238}
239
1cd84fee 240void QABugs::Commands_18(Draw_Interpretor& theCommands) {
1365140b 241 const char *group = "QABugs";
7fd59977 242
7fd59977 243 theCommands.Add("OCC267", "OCC267 DOC path", __FILE__, OCC267, group);
244 theCommands.Add("OCC181", "OCC181 FileName path1 path2 verbose=0/1", __FILE__, OCC181, group);
f9ac4dc9 245 theCommands.Add("OCC27849", "OCC27849 <resource env name> <resource name>", __FILE__, OCC27849, group);
7fd59977 246 theCommands.Add("OCC367", "OCC367 shape step goodX goodY goodZ percent_tolerance", __FILE__, OCC367, group);
7fd59977 247
248 return;
249}