2 // Created: Tue Mar 19 15:20:44 2002
4 // <qa@umnox.nnov.matra-dtv.fr>
8 #define Viewer2dTest QAViewer2dTest
11 #include <QAUsinor.hxx>
13 #include <Draw_Interpretor.hxx>
15 #include <DrawTrSurf.hxx>
16 #include <AIS_InteractiveContext.hxx>
17 #include <ViewerTest.hxx>
18 #include <AIS_Shape.hxx>
19 #include <TopoDS_Shape.hxx>
21 #include <ViewerTest_Tool.hxx>
22 #include <V3d_Viewer.hxx>
23 #include <V3d_View.hxx>
25 #include <ViewerTest_Tool.hxx>
26 #include <V3d_Viewer.hxx>
27 #include <V3d_View.hxx>
28 #include <PCollection_HExtendedString.hxx>
30 #include <TDocStd_Application.hxx>
31 #include <TDocStd_Document.hxx>
32 #include <DDocStd.hxx>
35 #include <Resource_Manager.hxx>
38 #include <QAViewer2dTest.hxx>
40 #include <Viewer2dTest.hxx>
43 #include <V2d_View.hxx>
44 #include <AIS2D_InteractiveObject.hxx>
45 #include <Graphic2d_SetOfMarkers.hxx>
47 #include <AIS2D_InteractiveContext.hxx>
48 #include <V2d_Viewer.hxx>
50 #include <TopoDS_Wire.hxx>
51 #include <BRepTools_WireExplorer.hxx>
52 #include <TopoDS_Vertex.hxx>
54 #include <BRep_Tool.hxx>
56 #include <Geom_Curve.hxx>
57 #include <GCPnts_UniformAbscissa.hxx>
58 #include <GeomAdaptor_Curve.hxx>
61 #define DEFAULT_COLOR Quantity_NOC_GOLDENROD
63 static Quantity_NameOfColor GetColorFromName( const char *name, Standard_Boolean& Found)
65 Quantity_NameOfColor ret = DEFAULT_COLOR;
67 Found = Standard_False;
68 Standard_CString colstring;
69 for(Standard_Integer i=0;i<=514 && !Found;i++)
71 colstring = Quantity_Color::StringName(Quantity_NameOfColor(i));
72 if (!strcasecmp(name,colstring)) {
73 ret = (Quantity_NameOfColor)i;
74 Found = Standard_True;
83 static Standard_Integer BUC60851 (Draw_Interpretor& di, Standard_Integer /*argc*/, const char ** /*argv*/)
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();
93 aV3d_View->TriedronDisplay();
98 static Standard_Integer OCC216 (Draw_Interpretor& di, Standard_Integer /*argc*/, const char ** /*argv*/)
100 Handle(PCollection_HExtendedString) HExtendedString = new PCollection_HExtendedString("");
101 HExtendedString.Nullify();
102 di << "OCC216: Deleting PCollection_HExtendedString initialized by empty string : OK" <<"\n";
107 static Standard_Integer OCC267 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
110 di << "ERROR OCC267: Usage : " << argv[0] << " DOC path" << "\n";
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;
120 CDF_StoreStatus theStatus = A->SaveAs(D,path);
121 if (theStatus == CDF_SS_OK ) {
122 di << "OCC267 : CDF_StoreStatus = CDF_SS_OK" << "\n";
124 di << "OCC267 : CDF_StoreStatus = Bad_Store_Status" << "\n";
130 static Standard_Integer OCC181 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
133 di << "ERROR OCC181: Usage : " << argv[0] << " FileName path1 path2 verbose=0/1" << "\n";
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]);
141 Standard_Boolean verboseBool = Standard_False;
142 if (verboseInt != 0) {
143 verboseBool = Standard_True;
146 TCollection_AsciiString Env1, Env2, CSF_ = "set env(CSF_";
147 Env1 = CSF_ + aFileName + "UserDefaults) " + aDir1;
148 Env2 = CSF_ + aFileName + "UserDefaults) " + aDir2;
150 di.Eval(Env1.ToCString());
152 Resource_Manager aManager(aFileName, verboseBool);
154 di.Eval(Env2.ToCString());
156 Standard_Boolean aStatus = aManager.Save();
159 di << "\nOCC181 : Status = TRUE" << "\n";
161 di << "\nOCC181 : Status = FALSE" << "\n";
167 static Standard_Integer OCC402bug (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
169 Handle(AIS2D_InteractiveContext) aContext = Viewer2dTest::GetAIS2DContext();
170 if(aContext.IsNull()) {
171 di << "ERROR: Use 'v2dinit' command before " << argv[0] << "\n";
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";
180 Standard_Integer IndexMarker = atoi(argv[1]);
181 if (IndexMarker <= 0) {
182 di << "ERROR : IndexMarker>0" << "\n";
186 Standard_Integer TypeOfDetectionInteger = atoi(argv[2]);
187 AIS2D_TypeOfDetection TypeOfDetection;
188 switch (TypeOfDetectionInteger) {
194 TypeOfDetection = (AIS2D_TypeOfDetection) TypeOfDetectionInteger;
197 di << "ERROR : TypeOfDetection=0/1/2/3/4" << "\n";
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;
209 PlaneAngle = atof(argv[7]);
212 Handle(V2d_View) View = Viewer2dTest::CurrentView();
213 //Handle(V2d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
215 Handle(AIS2D_InteractiveObject) obj = new AIS2D_InteractiveObject();
216 Handle(Graphic2d_SetOfMarkers) markers = new Graphic2d_SetOfMarkers( obj );
218 markers->Add(IndexMarker, X, Y, Width, Height, PlaneAngle);
220 aContext->Display( obj, Standard_False );
221 obj->SetHighlightMode( TypeOfDetection );
222 //aContext->SetDetectionMode( TypeOfDetection );
229 static Standard_Real delta_percent (Standard_Real a, Standard_Real b)
231 Standard_Real result;
233 result = fabs( (a - b) / b ) * 100.;
234 } else if (a != 0.) {
235 result = fabs( (a - b) / a ) * 100.;
242 static Standard_Integer OCC367 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
245 di << "ERROR : Usage : " << argv[0] << " shape step goodX goodY goodZ percent_tolerance" << "\n";
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;
257 // Find the first vertex of the wire
258 BRepTools_WireExplorer wire_exp(myTopoDSWire);
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))
269 assert(vw2.IsSame(ve1) || vw2.IsSame(ve2));
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())
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))
288 acurve = BRep_Tool::Curve(edge, ufirst, ulast);
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( );
304 GeomAdaptor_Curve curve;
305 GCPnts_UniformAbscissa algo;
307 algo.Initialize( curve, l, newufirst, newulast );
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;
329 di << "\n\nFirstEdge = " << FirstEdgeX <<" " << FirstEdgeY <<" " << FirstEdgeZ << "\n";
330 di << "deltaX = " << deltaX << " deltaY = " << deltaY << " deltaZ = " << deltaZ << "\n";
332 di << argv[0] << " : OK" << "\n";
334 di << argv[0] << " : ERROR" << "\n";
340 static Standard_Integer OCC71bug (Draw_Interpretor& di, Standard_Integer /*argc*/, const char ** argv)
342 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
343 if(aContext.IsNull()) {
344 di << argv[0] << "ERROR : use 'vinit' command before " << "\n";
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();
355 static Standard_Integer OCC403bug (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
357 Handle(AIS2D_InteractiveContext) aContext = Viewer2dTest::GetAIS2DContext();
358 if(aContext.IsNull()) {
359 di << "ERROR: Use 'v2dinit' command before " << argv[0] << "\n";
364 di << "ERROR : Usage : " << argv[0] << " ColorName1 ColorName2" << "\n";
368 Standard_Boolean Found;
369 Quantity_NameOfColor NameOfColor1 = GetColorFromName(argv[1] ,Found);
371 di << "ERROR: " << argv[1] << " - color not found" << "\n";
374 Quantity_NameOfColor NameOfColor2 = GetColorFromName(argv[2] ,Found);
376 di << "ERROR: " << argv[2] << " - color not found" << "\n";
380 Quantity_Color Color1(NameOfColor1);
381 Quantity_Color Color2(NameOfColor2);
383 Handle(V2d_View) View = Viewer2dTest::CurrentView();
384 Handle(V2d_Viewer) Viewer = View->Viewer();
385 Viewer->SetGridColor(Color1, Color2);
390 static Standard_Integer OCC404bug (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
392 Handle(AIS2D_InteractiveContext) aContext = Viewer2dTest::GetAIS2DContext();
393 if(aContext.IsNull()) {
394 di << "ERROR: Use 'v2dinit' command before " << argv[0] << "\n";
398 di << "ERROR : Usage : " << argv[0] << " R G B" << "\n";
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]);
406 Quantity_Color Color;
407 Color.SetValues(R1, R2, R3, Quantity_TOC_RGB);
409 Handle(V2d_View) View = Viewer2dTest::CurrentView();
410 View->SetBackground(Color);
416 void QAUsinor::Commands(Draw_Interpretor& theCommands) {
417 char *group = "QAUsinor";
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);