Integration of OCCT 6.5.0 from SVN
[occt.git] / src / QAUsinor / QAUsinor.cxx
CommitLineData
7fd59977 1// File: QAUsinor.cxx
2// Created: Tue Mar 19 15:20:44 2002
3// Author: QA Admin
4// <qa@umnox.nnov.matra-dtv.fr>
5
6#if defined(WOKC40)
7#define V2D
8#define Viewer2dTest QAViewer2dTest
9#endif
10
11#include <QAUsinor.hxx>
12
13#include <Draw_Interpretor.hxx>
14#include <DBRep.hxx>
15#include <DrawTrSurf.hxx>
16#include <AIS_InteractiveContext.hxx>
17#include <ViewerTest.hxx>
18#include <AIS_Shape.hxx>
19#include <TopoDS_Shape.hxx>
20
21#include <ViewerTest_Tool.hxx>
22#include <V3d_Viewer.hxx>
23#include <V3d_View.hxx>
24
25#include <ViewerTest_Tool.hxx>
26#include <V3d_Viewer.hxx>
27#include <V3d_View.hxx>
28#include <PCollection_HExtendedString.hxx>
29
30#include <TDocStd_Application.hxx>
31#include <TDocStd_Document.hxx>
32#include <DDocStd.hxx>
33#include <CDF.hxx>
34
35#include <Resource_Manager.hxx>
36
37#if defined(WOKC40)
38#include <QAViewer2dTest.hxx>
39#else
40#include <Viewer2dTest.hxx>
41#endif
42
43#include <V2d_View.hxx>
44#include <AIS2D_InteractiveObject.hxx>
45#include <Graphic2d_SetOfMarkers.hxx>
46#include <AIS2D.hxx>
47#include <AIS2D_InteractiveContext.hxx>
48#include <V2d_Viewer.hxx>
49
50#include <TopoDS_Wire.hxx>
51#include <BRepTools_WireExplorer.hxx>
52#include <TopoDS_Vertex.hxx>
53#include <TopoDS.hxx>
54#include <BRep_Tool.hxx>
55#include <TopExp.hxx>
56#include <Geom_Curve.hxx>
57#include <GCPnts_UniformAbscissa.hxx>
58#include <GeomAdaptor_Curve.hxx>
59#include <assert.h>
60
61#define DEFAULT_COLOR Quantity_NOC_GOLDENROD
62
63static Quantity_NameOfColor GetColorFromName( const char *name, Standard_Boolean& Found)
64{
65 Quantity_NameOfColor ret = DEFAULT_COLOR;
66
67 Found = Standard_False;
68 Standard_CString colstring;
69 for(Standard_Integer i=0;i<=514 && !Found;i++)
70 {
71 colstring = Quantity_Color::StringName(Quantity_NameOfColor(i));
72 if (!strcasecmp(name,colstring)) {
73 ret = (Quantity_NameOfColor)i;
74 Found = Standard_True;
75 break;
76 }
77 }
78
79 return ret;
80}
81
82
83static Standard_Integer BUC60851 (Draw_Interpretor& di, Standard_Integer /*argc*/, const char ** /*argv*/)
84{
85 Handle(AIS_InteractiveContext) context= ViewerTest_Tool::MakeContext ("buc60851");
86 ViewerTest_Tool::InitViewerTest (context);
87 Handle(V3d_Viewer) aV3dViewer= context->CurrentViewer();
88 Handle(V3d_View) aV3d_View = aV3dViewer->ActiveView();
89 for (Standard_Integer i=0;i<1000;++i) {
90 aV3d_View->TriedronDisplay();
91 aV3d_View->TriedronErase();
92 }
93 aV3d_View->TriedronDisplay();
94
95 return 0;
96}
97
98static Standard_Integer OCC216 (Draw_Interpretor& di, Standard_Integer /*argc*/, const char ** /*argv*/)
99{
100 Handle(PCollection_HExtendedString) HExtendedString = new PCollection_HExtendedString("");
101 HExtendedString.Nullify();
102 di << "OCC216: Deleting PCollection_HExtendedString initialized by empty string : OK" <<"\n";
103
104 return 0;
105}
106
107static Standard_Integer OCC267 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
108{
109 if ( argc != 3) {
110 di << "ERROR OCC267: Usage : " << argv[0] << " DOC path" << "\n";
111 return 1;
112 }
113
114 Handle(TDocStd_Document) D;
115 if (!DDocStd::GetDocument(argv[1],D)) return 1;
116 TCollection_ExtendedString path (argv[2]);
117 Handle(TDocStd_Application) A;
118 if (!DDocStd::Find(A)) return 1;
119
120 CDF_StoreStatus theStatus = A->SaveAs(D,path);
121 if (theStatus == CDF_SS_OK ) {
122 di << "OCC267 : CDF_StoreStatus = CDF_SS_OK" << "\n";
123 } else {
124 di << "OCC267 : CDF_StoreStatus = Bad_Store_Status" << "\n";
125 }
126
127 return 0;
128}
129
130static Standard_Integer OCC181 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
131{
132 if ( argc != 5) {
133 di << "ERROR OCC181: Usage : " << argv[0] << " FileName path1 path2 verbose=0/1" << "\n";
134 return 1;
135 }
136 Standard_CString aFileName = argv[1];
137 Standard_CString aDir1 = argv[2];
138 Standard_CString aDir2 = argv[3];
139 Standard_Integer verboseInt = atoi(argv[4]);
140
141 Standard_Boolean verboseBool = Standard_False;
142 if (verboseInt != 0) {
143 verboseBool = Standard_True;
144 }
145
146 TCollection_AsciiString Env1, Env2, CSF_ = "set env(CSF_";
147 Env1 = CSF_ + aFileName + "UserDefaults) " + aDir1;
148 Env2 = CSF_ + aFileName + "UserDefaults) " + aDir2;
149
150 di.Eval(Env1.ToCString());
151
152 Resource_Manager aManager(aFileName, verboseBool);
153
154 di.Eval(Env2.ToCString());
155
156 Standard_Boolean aStatus = aManager.Save();
157
158 if (aStatus) {
159 di << "\nOCC181 : Status = TRUE" << "\n";
160 } else {
161 di << "\nOCC181 : Status = FALSE" << "\n";
162 }
163
164 return 0;
165}
166
167static Standard_Integer OCC402bug (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
168{
169 Handle(AIS2D_InteractiveContext) aContext = Viewer2dTest::GetAIS2DContext();
170 if(aContext.IsNull()) {
171 di << "ERROR: Use 'v2dinit' command before " << argv[0] << "\n";
172 return 1;
173 }
174
175 if ( !(argc == 7 || argc == 8) ) {
176 di << "ERROR : Usage : " << argv[0] << " IndexMarker>0 TypeOfDetection=0/1/2/3/4 X Y Width Height [Angle=0.0]" << "\n";
177 return 1;
178 }
179
180 Standard_Integer IndexMarker = atoi(argv[1]);
181 if (IndexMarker <= 0) {
182 di << "ERROR : IndexMarker>0" << "\n";
183 return 1;
184 }
185
186 Standard_Integer TypeOfDetectionInteger = atoi(argv[2]);
187 AIS2D_TypeOfDetection TypeOfDetection;
188 switch (TypeOfDetectionInteger) {
189 case 0:
190 case 1:
191 case 2:
192 case 3:
193 case 4:
194 TypeOfDetection = (AIS2D_TypeOfDetection) TypeOfDetectionInteger;
195 break;
196 default:
197 di << "ERROR : TypeOfDetection=0/1/2/3/4" << "\n";
198 return 1;
199 }
200
201 Quantity_Length X = atof(argv[3]);
202 Quantity_Length Y = atof(argv[4]);
203 Quantity_Length Width = atof(argv[5]);
204 Quantity_Length Height = atof(argv[6]);
205 Quantity_PlaneAngle PlaneAngle;
206 if ( argc == 7) {
207 PlaneAngle = 0.0;
208 } else {
209 PlaneAngle = atof(argv[7]);
210 }
211
212 Handle(V2d_View) View = Viewer2dTest::CurrentView();
213 //Handle(V2d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
214
215 Handle(AIS2D_InteractiveObject) obj = new AIS2D_InteractiveObject();
216 Handle(Graphic2d_SetOfMarkers) markers = new Graphic2d_SetOfMarkers( obj );
217
218 markers->Add(IndexMarker, X, Y, Width, Height, PlaneAngle);
219
220 aContext->Display( obj, Standard_False );
221 obj->SetHighlightMode( TypeOfDetection );
222 //aContext->SetDetectionMode( TypeOfDetection );
223
224 View->Fitall();
225
226 return 0;
227}
228
229static Standard_Real delta_percent (Standard_Real a, Standard_Real b)
230{
231 Standard_Real result;
232 if (b != 0.) {
233 result = fabs( (a - b) / b ) * 100.;
234 } else if (a != 0.) {
235 result = fabs( (a - b) / a ) * 100.;
236 } else {
237 result = 0.;
238 }
239 return result;
240}
241
242static Standard_Integer OCC367 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
243{
244 if ( argc != 7) {
245 di << "ERROR : Usage : " << argv[0] << " shape step goodX goodY goodZ percent_tolerance" << "\n";
246 return 1;
247 }
248
249 TopoDS_Wire myTopoDSWire = TopoDS::Wire(DBRep::Get(argv[1]));
250 Standard_Real l = atof(argv[2]);
251 Standard_Real goodX = atof(argv[3]);
252 Standard_Real goodY = atof(argv[4]);
253 Standard_Real goodZ = atof(argv[5]);
254 Standard_Real percent = atof(argv[6]);
255 Standard_Boolean Status = Standard_False;
256
257 // Find the first vertex of the wire
258 BRepTools_WireExplorer wire_exp(myTopoDSWire);
259 TopoDS_Vertex vlast;
260 {
261 TopoDS_Vertex vw1, vw2;
262 TopExp::Vertices(myTopoDSWire,vw1,vw2);
263 TopoDS_Vertex ve1, ve2;
264 TopoDS_Edge edge = TopoDS::Edge(wire_exp.Current());
265 TopExp::Vertices(edge,ve1,ve2);
266 if (vw1.IsSame(ve1) || vw1.IsSame(ve2))
267 vlast = vw1;
268 else {
269 assert(vw2.IsSame(ve1) || vw2.IsSame(ve2));
270 vlast = vw2;
271 }
272 }
273 Standard_Integer EdgeIndex = 0;
274 Standard_Real FirstEdgeX, FirstEdgeY, FirstEdgeZ, deltaX, deltaY, deltaZ;
275 FirstEdgeX = FirstEdgeY = FirstEdgeZ = deltaX = deltaY = deltaZ = 0.;
276 for ( ; wire_exp.More(); wire_exp.Next())
277 {
278 EdgeIndex++;
279 di << "\n\n New Edge \n" << "\n";
280 Standard_Real newufirst, newulast;
281 TopoDS_Edge edge = TopoDS::Edge(wire_exp.Current());
282 Standard_Real ufirst, ulast;
283 Handle(Geom_Curve) acurve;
284 TopoDS_Vertex ve1, ve2;
285 TopExp::Vertices(edge,ve1,ve2);
286 if (ve1.IsSame(vlast))
287 {
288 acurve = BRep_Tool::Curve(edge, ufirst, ulast);
289 newufirst = ufirst;
290 newulast = ulast;
291 vlast = ve2;
292 }
293 else
294 {
295 assert(ve2.IsSame(vlast));
296 assert ( wire_exp.Orientation( ) == TopAbs_REVERSED );
297 acurve = BRep_Tool::Curve( edge, ufirst, ulast );
298 newufirst = acurve->ReversedParameter( ufirst );
299 newulast = acurve->ReversedParameter( ulast );
300 acurve = acurve->Reversed( );
301 vlast = ve1;
302 }
303
304 GeomAdaptor_Curve curve;
305 GCPnts_UniformAbscissa algo;
306 curve.Load(acurve);
307 algo.Initialize( curve, l, newufirst, newulast );
308 if (!algo.IsDone())
309 di << "Not Done!!!" << "\n";
310 Standard_Integer maxIndex =algo.NbPoints();
311 for (Standard_Integer Index = 1; Index<=maxIndex;Index++) {
312 Standard_Real t = algo.Parameter(Index);
313 gp_Pnt pt3 = curve.Value(t);
314 di << "Parameter t = " << t << "\n";
315 di << "Value Pnt = " << pt3.X()<<" " <<pt3.Y()<<" " << pt3.Z() << "\n";
316 if (EdgeIndex == 1 && Index == maxIndex) {
317 FirstEdgeX = pt3.X();
318 FirstEdgeY = pt3.Y();
319 FirstEdgeZ = pt3.Z();
320 deltaX = delta_percent(FirstEdgeX, goodX);
321 deltaY = delta_percent(FirstEdgeY, goodY);
322 deltaZ = delta_percent(FirstEdgeZ, goodZ);
323 if (deltaX <= percent && deltaY <= percent && deltaZ <= percent) {
324 Status = Standard_True;
325 }
326 }
327 }
328 }
329 di << "\n\nFirstEdge = " << FirstEdgeX <<" " << FirstEdgeY <<" " << FirstEdgeZ << "\n";
330 di << "deltaX = " << deltaX << " deltaY = " << deltaY << " deltaZ = " << deltaZ << "\n";
331 if (Status) {
332 di << argv[0] << " : OK" << "\n";
333 } else {
334 di << argv[0] << " : ERROR" << "\n";
335 }
336
337 return 0;
338}
339
340static Standard_Integer OCC71bug (Draw_Interpretor& di, Standard_Integer /*argc*/, const char ** argv)
341{
342 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
343 if(aContext.IsNull()) {
344 di << argv[0] << "ERROR : use 'vinit' command before " << "\n";
345 return 1;
346 }
347
348 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
349 V3dView->EnableGLLight( Standard_False );
350 V3dView->TriedronDisplay(Aspect_TOTP_LEFT_LOWER, Quantity_NOC_WHITE, 0.07);
351 aContext->UpdateCurrentViewer();
352 return 0;
353}
354
355static Standard_Integer OCC403bug (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
356{
357 Handle(AIS2D_InteractiveContext) aContext = Viewer2dTest::GetAIS2DContext();
358 if(aContext.IsNull()) {
359 di << "ERROR: Use 'v2dinit' command before " << argv[0] << "\n";
360 return 1;
361 }
362
363 if ( argc != 3) {
364 di << "ERROR : Usage : " << argv[0] << " ColorName1 ColorName2" << "\n";
365 return 1;
366 }
367
368 Standard_Boolean Found;
369 Quantity_NameOfColor NameOfColor1 = GetColorFromName(argv[1] ,Found);
370 if ( !Found ) {
371 di << "ERROR: " << argv[1] << " - color not found" << "\n";
372 return 1;
373 }
374 Quantity_NameOfColor NameOfColor2 = GetColorFromName(argv[2] ,Found);
375 if ( !Found ) {
376 di << "ERROR: " << argv[2] << " - color not found" << "\n";
377 return 1;
378 }
379
380 Quantity_Color Color1(NameOfColor1);
381 Quantity_Color Color2(NameOfColor2);
382
383 Handle(V2d_View) View = Viewer2dTest::CurrentView();
384 Handle(V2d_Viewer) Viewer = View->Viewer();
385 Viewer->SetGridColor(Color1, Color2);
386
387 return 0;
388}
389
390static Standard_Integer OCC404bug (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
391{
392 Handle(AIS2D_InteractiveContext) aContext = Viewer2dTest::GetAIS2DContext();
393 if(aContext.IsNull()) {
394 di << "ERROR: Use 'v2dinit' command before " << argv[0] << "\n";
395 return 1;
396 }
397 if ( argc != 4) {
398 di << "ERROR : Usage : " << argv[0] << " R G B" << "\n";
399 return 1;
400 }
401
402 Quantity_Parameter R1 = (Quantity_Parameter) atof(argv[1]);
403 Quantity_Parameter R2 = (Quantity_Parameter) atof(argv[2]);
404 Quantity_Parameter R3 = (Quantity_Parameter) atof(argv[3]);
405
406 Quantity_Color Color;
407 Color.SetValues(R1, R2, R3, Quantity_TOC_RGB);
408
409 Handle(V2d_View) View = Viewer2dTest::CurrentView();
410 View->SetBackground(Color);
411 View->Update();
412
413 return 0;
414}
415
416void QAUsinor::Commands(Draw_Interpretor& theCommands) {
417 char *group = "QAUsinor";
418
419 theCommands.Add("BUC60851", "BUC60851", __FILE__, BUC60851, group);
420 theCommands.Add("OCC216", "OCC216", __FILE__, OCC216, group);
421 theCommands.Add("OCC267", "OCC267 DOC path", __FILE__, OCC267, group);
422 theCommands.Add("OCC181", "OCC181 FileName path1 path2 verbose=0/1", __FILE__, OCC181, group);
423 theCommands.Add("OCC402", "OCC402 TypeOfDetection=0/1/2/3/4 X Y Width Height [Angle=0.0]", __FILE__, OCC402bug, group);
424 theCommands.Add("OCC367", "OCC367 shape step goodX goodY goodZ percent_tolerance", __FILE__, OCC367, group);
425 theCommands.Add("OCC71", "OCC71", __FILE__, OCC71bug, group);
426 theCommands.Add("OCC403", "OCC403 ColorName1 ColorName2", __FILE__, OCC403bug, group);
427 theCommands.Add("OCC404", "OCC404 R G B; Set Background Color", __FILE__, OCC404bug, group);
428
429 return;
430}