Adding test cases from chl grid
[occt.git] / src / QABugs / QABugs_18.cxx
CommitLineData
b311480e 1// Created on: 2002-03-19
2// Created by: QA Admin
3// Copyright (c) 2002-2012 OPEN CASCADE SAS
4//
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.
9//
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.
12//
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.
19
7fd59977 20
1cd84fee 21#include <QABugs.hxx>
7fd59977 22
23#include <Draw_Interpretor.hxx>
24#include <DBRep.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
31#include <ViewerTest_Tool.hxx>
32#include <V3d_Viewer.hxx>
33#include <V3d_View.hxx>
34
35#include <ViewerTest_Tool.hxx>
36#include <V3d_Viewer.hxx>
37#include <V3d_View.hxx>
38#include <PCollection_HExtendedString.hxx>
39
40#include <TDocStd_Application.hxx>
41#include <TDocStd_Document.hxx>
42#include <DDocStd.hxx>
43#include <CDF.hxx>
44
45#include <Resource_Manager.hxx>
7fd59977 46#include <TopoDS_Wire.hxx>
47#include <BRepTools_WireExplorer.hxx>
48#include <TopoDS_Vertex.hxx>
49#include <TopoDS.hxx>
50#include <BRep_Tool.hxx>
51#include <TopExp.hxx>
52#include <Geom_Curve.hxx>
53#include <GCPnts_UniformAbscissa.hxx>
54#include <GeomAdaptor_Curve.hxx>
91a16bc7 55#include <Standard_Assert.hxx>
7fd59977 56
57#define DEFAULT_COLOR Quantity_NOC_GOLDENROD
58
59static Quantity_NameOfColor GetColorFromName( const char *name, Standard_Boolean& Found)
60{
61 Quantity_NameOfColor ret = DEFAULT_COLOR;
62
63 Found = Standard_False;
64 Standard_CString colstring;
65 for(Standard_Integer i=0;i<=514 && !Found;i++)
66 {
67 colstring = Quantity_Color::StringName(Quantity_NameOfColor(i));
68 if (!strcasecmp(name,colstring)) {
69 ret = (Quantity_NameOfColor)i;
70 Found = Standard_True;
71 break;
72 }
73 }
74
75 return ret;
76}
77
7fd59977 78static Standard_Integer BUC60851 (Draw_Interpretor& di, Standard_Integer /*argc*/, const char ** /*argv*/)
79{
80 Handle(AIS_InteractiveContext) context= ViewerTest_Tool::MakeContext ("buc60851");
81 ViewerTest_Tool::InitViewerTest (context);
82 Handle(V3d_Viewer) aV3dViewer= context->CurrentViewer();
83 Handle(V3d_View) aV3d_View = aV3dViewer->ActiveView();
84 for (Standard_Integer i=0;i<1000;++i) {
85 aV3d_View->TriedronDisplay();
86 aV3d_View->TriedronErase();
87 }
88 aV3d_View->TriedronDisplay();
89
90 return 0;
91}
92
93static Standard_Integer OCC216 (Draw_Interpretor& di, Standard_Integer /*argc*/, const char ** /*argv*/)
94{
95 Handle(PCollection_HExtendedString) HExtendedString = new PCollection_HExtendedString("");
96 HExtendedString.Nullify();
97 di << "OCC216: Deleting PCollection_HExtendedString initialized by empty string : OK" <<"\n";
98
99 return 0;
100}
101
102static Standard_Integer OCC267 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
103{
104 if ( argc != 3) {
105 di << "ERROR OCC267: Usage : " << argv[0] << " DOC path" << "\n";
106 return 1;
107 }
108
109 Handle(TDocStd_Document) D;
110 if (!DDocStd::GetDocument(argv[1],D)) return 1;
111 TCollection_ExtendedString path (argv[2]);
112 Handle(TDocStd_Application) A;
113 if (!DDocStd::Find(A)) return 1;
114
15e8b082
M
115 PCDM_StoreStatus theStatus = A->SaveAs(D,path);
116 if (theStatus == PCDM_SS_OK ) {
117 di << "OCC267 : PCDM_StoreStatus = PCDM_SS_OK" << "\n";
7fd59977 118 } else {
15e8b082 119 di << "OCC267 : PCDM_StoreStatus = Bad_Store_Status" << "\n";
7fd59977 120 }
121
122 return 0;
123}
124
125static Standard_Integer OCC181 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
126{
127 if ( argc != 5) {
128 di << "ERROR OCC181: Usage : " << argv[0] << " FileName path1 path2 verbose=0/1" << "\n";
129 return 1;
130 }
131 Standard_CString aFileName = argv[1];
132 Standard_CString aDir1 = argv[2];
133 Standard_CString aDir2 = argv[3];
134 Standard_Integer verboseInt = atoi(argv[4]);
135
136 Standard_Boolean verboseBool = Standard_False;
137 if (verboseInt != 0) {
138 verboseBool = Standard_True;
139 }
140
141 TCollection_AsciiString Env1, Env2, CSF_ = "set env(CSF_";
142 Env1 = CSF_ + aFileName + "UserDefaults) " + aDir1;
143 Env2 = CSF_ + aFileName + "UserDefaults) " + aDir2;
144
145 di.Eval(Env1.ToCString());
146
147 Resource_Manager aManager(aFileName, verboseBool);
148
149 di.Eval(Env2.ToCString());
150
151 Standard_Boolean aStatus = aManager.Save();
152
153 if (aStatus) {
154 di << "\nOCC181 : Status = TRUE" << "\n";
155 } else {
156 di << "\nOCC181 : Status = FALSE" << "\n";
157 }
158
159 return 0;
160}
161
7fd59977 162static Standard_Real delta_percent (Standard_Real a, Standard_Real b)
163{
164 Standard_Real result;
165 if (b != 0.) {
166 result = fabs( (a - b) / b ) * 100.;
167 } else if (a != 0.) {
168 result = fabs( (a - b) / a ) * 100.;
169 } else {
170 result = 0.;
171 }
172 return result;
173}
174
175static Standard_Integer OCC367 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
176{
177 if ( argc != 7) {
178 di << "ERROR : Usage : " << argv[0] << " shape step goodX goodY goodZ percent_tolerance" << "\n";
179 return 1;
180 }
181
182 TopoDS_Wire myTopoDSWire = TopoDS::Wire(DBRep::Get(argv[1]));
183 Standard_Real l = atof(argv[2]);
184 Standard_Real goodX = atof(argv[3]);
185 Standard_Real goodY = atof(argv[4]);
186 Standard_Real goodZ = atof(argv[5]);
187 Standard_Real percent = atof(argv[6]);
188 Standard_Boolean Status = Standard_False;
189
190 // Find the first vertex of the wire
191 BRepTools_WireExplorer wire_exp(myTopoDSWire);
192 TopoDS_Vertex vlast;
193 {
194 TopoDS_Vertex vw1, vw2;
195 TopExp::Vertices(myTopoDSWire,vw1,vw2);
196 TopoDS_Vertex ve1, ve2;
197 TopoDS_Edge edge = TopoDS::Edge(wire_exp.Current());
198 TopExp::Vertices(edge,ve1,ve2);
199 if (vw1.IsSame(ve1) || vw1.IsSame(ve2))
200 vlast = vw1;
201 else {
91a16bc7 202 Standard_ASSERT_RAISE(vw2.IsSame(ve1) || vw2.IsSame(ve2), "Disconnected vertices");
7fd59977 203 vlast = vw2;
204 }
205 }
206 Standard_Integer EdgeIndex = 0;
207 Standard_Real FirstEdgeX, FirstEdgeY, FirstEdgeZ, deltaX, deltaY, deltaZ;
208 FirstEdgeX = FirstEdgeY = FirstEdgeZ = deltaX = deltaY = deltaZ = 0.;
209 for ( ; wire_exp.More(); wire_exp.Next())
210 {
211 EdgeIndex++;
212 di << "\n\n New Edge \n" << "\n";
213 Standard_Real newufirst, newulast;
214 TopoDS_Edge edge = TopoDS::Edge(wire_exp.Current());
215 Standard_Real ufirst, ulast;
216 Handle(Geom_Curve) acurve;
217 TopoDS_Vertex ve1, ve2;
218 TopExp::Vertices(edge,ve1,ve2);
219 if (ve1.IsSame(vlast))
220 {
221 acurve = BRep_Tool::Curve(edge, ufirst, ulast);
222 newufirst = ufirst;
223 newulast = ulast;
224 vlast = ve2;
225 }
226 else
227 {
91a16bc7
K
228 Standard_ASSERT_RAISE(ve2.IsSame(vlast), "Not the same vertex");
229 Standard_ASSERT_RAISE(wire_exp.Orientation() == TopAbs_REVERSED, "Wire should be REVERSED");
7fd59977 230 acurve = BRep_Tool::Curve( edge, ufirst, ulast );
231 newufirst = acurve->ReversedParameter( ufirst );
232 newulast = acurve->ReversedParameter( ulast );
233 acurve = acurve->Reversed( );
234 vlast = ve1;
235 }
236
237 GeomAdaptor_Curve curve;
238 GCPnts_UniformAbscissa algo;
239 curve.Load(acurve);
240 algo.Initialize( curve, l, newufirst, newulast );
241 if (!algo.IsDone())
242 di << "Not Done!!!" << "\n";
243 Standard_Integer maxIndex =algo.NbPoints();
244 for (Standard_Integer Index = 1; Index<=maxIndex;Index++) {
245 Standard_Real t = algo.Parameter(Index);
246 gp_Pnt pt3 = curve.Value(t);
247 di << "Parameter t = " << t << "\n";
248 di << "Value Pnt = " << pt3.X()<<" " <<pt3.Y()<<" " << pt3.Z() << "\n";
249 if (EdgeIndex == 1 && Index == maxIndex) {
250 FirstEdgeX = pt3.X();
251 FirstEdgeY = pt3.Y();
252 FirstEdgeZ = pt3.Z();
253 deltaX = delta_percent(FirstEdgeX, goodX);
254 deltaY = delta_percent(FirstEdgeY, goodY);
255 deltaZ = delta_percent(FirstEdgeZ, goodZ);
256 if (deltaX <= percent && deltaY <= percent && deltaZ <= percent) {
257 Status = Standard_True;
258 }
259 }
260 }
261 }
262 di << "\n\nFirstEdge = " << FirstEdgeX <<" " << FirstEdgeY <<" " << FirstEdgeZ << "\n";
263 di << "deltaX = " << deltaX << " deltaY = " << deltaY << " deltaZ = " << deltaZ << "\n";
264 if (Status) {
265 di << argv[0] << " : OK" << "\n";
266 } else {
267 di << argv[0] << " : ERROR" << "\n";
268 }
269
270 return 0;
271}
272
273static Standard_Integer OCC71bug (Draw_Interpretor& di, Standard_Integer /*argc*/, const char ** argv)
274{
275 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
276 if(aContext.IsNull()) {
277 di << argv[0] << "ERROR : use 'vinit' command before " << "\n";
278 return 1;
279 }
280
281 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
282 V3dView->EnableGLLight( Standard_False );
283 V3dView->TriedronDisplay(Aspect_TOTP_LEFT_LOWER, Quantity_NOC_WHITE, 0.07);
284 aContext->UpdateCurrentViewer();
285 return 0;
286}
287
1cd84fee 288void QABugs::Commands_18(Draw_Interpretor& theCommands) {
1365140b 289 const char *group = "QABugs";
7fd59977 290
291 theCommands.Add("BUC60851", "BUC60851", __FILE__, BUC60851, group);
292 theCommands.Add("OCC216", "OCC216", __FILE__, OCC216, group);
293 theCommands.Add("OCC267", "OCC267 DOC path", __FILE__, OCC267, group);
294 theCommands.Add("OCC181", "OCC181 FileName path1 path2 verbose=0/1", __FILE__, OCC181, group);
7fd59977 295 theCommands.Add("OCC367", "OCC367 shape step goodX goodY goodZ percent_tolerance", __FILE__, OCC367, group);
296 theCommands.Add("OCC71", "OCC71", __FILE__, OCC71bug, group);
7fd59977 297
298 return;
299}