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