0024927: Getting rid of "Persistent" functionality -- Code
[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
26 #include <V3d_Viewer.hxx>
27 #include <V3d_View.hxx>
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>
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>
44 #include <Standard_Assert.hxx>
45
46 #define DEFAULT_COLOR    Quantity_NOC_GOLDENROD
47
48 static Standard_Integer OCC267 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
49 {
50   if ( argc != 3) {
51     di << "ERROR OCC267: Usage : " << argv[0] << " DOC path" << "\n";
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]);
58   Handle(TDocStd_Application) A;
59   if (!DDocStd::Find(A)) return 1;
60
61   PCDM_StoreStatus theStatus = A->SaveAs(D,path);
62   if (theStatus == PCDM_SS_OK ) {
63     di << "OCC267 : PCDM_StoreStatus = PCDM_SS_OK" << "\n";
64   } else {
65     di << "OCC267 : PCDM_StoreStatus = Bad_Store_Status" << "\n";
66   }
67
68   return 0;
69 }
70
71 static Standard_Integer OCC181 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
72 {
73   if ( argc != 5) {
74     di << "ERROR OCC181: Usage : " << argv[0] << " FileName path1 path2 verbose=0/1" << "\n";
75     return 1;
76   }
77   Standard_CString aFileName = argv[1];
78   Standard_CString aDir1 = argv[2];
79   Standard_CString aDir2 = argv[3];
80   Standard_Integer verboseInt = Draw::Atoi(argv[4]);
81
82   Standard_Boolean verboseBool = Standard_False;
83   if (verboseInt != 0) {
84    verboseBool = Standard_True;
85   }
86
87   TCollection_AsciiString Env1, Env2, CSF_ = "set env(CSF_";
88   Env1 = CSF_ + aFileName + "UserDefaults) " + aDir1;
89   Env2 = CSF_ + aFileName + "UserDefaults) " + aDir2;
90
91   di.Eval(Env1.ToCString());
92
93   Resource_Manager aManager(aFileName, verboseBool);
94
95   di.Eval(Env2.ToCString());
96
97   Standard_Boolean aStatus = aManager.Save();
98
99   if (aStatus) {
100     di << "\nOCC181 : Status = TRUE" << "\n";
101   } else {
102     di << "\nOCC181 : Status = FALSE" << "\n";
103   }
104
105   return 0;
106 }
107
108 static Standard_Real delta_percent (Standard_Real a, Standard_Real b)
109 {
110   Standard_Real result;
111   if (b != 0.) {
112     result = fabs( (a - b) / b ) * 100.;
113   } else if (a != 0.) {
114     result = fabs( (a - b) / a ) * 100.;
115   } else {
116     result = 0.;
117   }
118   return result;
119 }
120
121 static Standard_Integer OCC367 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
122 {
123   if ( argc != 7) {
124     di << "ERROR : Usage : " << argv[0] << " shape step goodX goodY goodZ percent_tolerance" << "\n";
125     return 1;
126   }
127
128   TopoDS_Wire myTopoDSWire = TopoDS::Wire(DBRep::Get(argv[1]));
129   Standard_Real l = Draw::Atof(argv[2]);
130   Standard_Real goodX = Draw::Atof(argv[3]);
131   Standard_Real goodY = Draw::Atof(argv[4]);
132   Standard_Real goodZ = Draw::Atof(argv[5]);
133   Standard_Real percent = Draw::Atof(argv[6]);
134   Standard_Boolean Status = Standard_False;
135
136   // Find the first vertex of the wire
137   BRepTools_WireExplorer wire_exp(myTopoDSWire);
138   TopoDS_Vertex vlast;
139   {
140     TopoDS_Vertex vw1, vw2;
141     TopExp::Vertices(myTopoDSWire,vw1,vw2);
142     TopoDS_Vertex ve1, ve2;
143     TopoDS_Edge edge = TopoDS::Edge(wire_exp.Current());
144     TopExp::Vertices(edge,ve1,ve2);
145     if (vw1.IsSame(ve1) || vw1.IsSame(ve2))
146       vlast = vw1;
147     else {
148       Standard_ASSERT_RAISE(vw2.IsSame(ve1) || vw2.IsSame(ve2), "Disconnected vertices");
149       vlast = vw2;
150     }
151   }
152   Standard_Integer EdgeIndex = 0;
153   Standard_Real FirstEdgeX, FirstEdgeY, FirstEdgeZ, deltaX, deltaY, deltaZ;
154   FirstEdgeX = FirstEdgeY = FirstEdgeZ = deltaX = deltaY = deltaZ = 0.;
155   for ( ; wire_exp.More(); wire_exp.Next())
156     {
157       EdgeIndex++;
158       di << "\n\n New Edge \n"   << "\n";
159       Standard_Real newufirst, newulast;
160       TopoDS_Edge edge = TopoDS::Edge(wire_exp.Current());
161       Standard_Real ufirst, ulast;
162       Handle(Geom_Curve) acurve;
163       TopoDS_Vertex ve1, ve2;
164       TopExp::Vertices(edge,ve1,ve2);
165       if (ve1.IsSame(vlast))
166         {
167           acurve = BRep_Tool::Curve(edge, ufirst, ulast);
168           newufirst = ufirst;
169           newulast  = ulast;
170           vlast = ve2;
171         }
172       else
173         {
174           Standard_ASSERT_RAISE(ve2.IsSame(vlast), "Not the same vertex");
175           Standard_ASSERT_RAISE(wire_exp.Orientation() == TopAbs_REVERSED, "Wire should be REVERSED");
176           acurve = BRep_Tool::Curve( edge, ufirst, ulast );
177           newufirst = acurve->ReversedParameter( ufirst );
178           newulast  = acurve->ReversedParameter( ulast );
179           acurve = acurve->Reversed( );
180           vlast = ve1;
181         }
182       
183       GeomAdaptor_Curve   curve;
184       GCPnts_UniformAbscissa  algo;
185       curve.Load(acurve);
186       algo.Initialize( curve, l, newufirst, newulast );
187       if (!algo.IsDone())
188         di << "Not Done!!!"   << "\n";
189       Standard_Integer maxIndex =algo.NbPoints();
190       for (Standard_Integer Index = 1; Index<=maxIndex;Index++) {
191         Standard_Real t = algo.Parameter(Index);
192         gp_Pnt      pt3 = curve.Value(t);
193         di << "Parameter t = " << t   << "\n";
194         di << "Value Pnt = " << pt3.X()<<" " <<pt3.Y()<<" " << pt3.Z()  << "\n";
195         if (EdgeIndex == 1 && Index == maxIndex) {
196           FirstEdgeX = pt3.X();
197           FirstEdgeY = pt3.Y();
198           FirstEdgeZ = pt3.Z();
199           deltaX = delta_percent(FirstEdgeX, goodX);
200           deltaY = delta_percent(FirstEdgeY, goodY);
201           deltaZ = delta_percent(FirstEdgeZ, goodZ);
202           if (deltaX <= percent && deltaY <= percent && deltaZ <= percent) {
203             Status = Standard_True;
204           }
205         }
206       }
207     }
208   di << "\n\nFirstEdge = " << FirstEdgeX <<" " << FirstEdgeY <<" " << FirstEdgeZ << "\n";
209   di << "deltaX = " << deltaX << " deltaY = " << deltaY << " deltaZ = " << deltaZ << "\n";
210   if (Status) {
211     di << argv[0] << " : OK" << "\n";
212   } else {
213     di << argv[0] << " : ERROR" << "\n";
214   }
215
216   return 0;
217 }
218
219 static Standard_Integer OCC71bug (Draw_Interpretor& di, Standard_Integer /*argc*/, const char ** argv)
220 {
221   Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
222   if(aContext.IsNull()) { 
223     di << argv[0] << "ERROR : use 'vinit' command before " << "\n";
224     return 1;
225   }
226
227   Handle(V3d_View) V3dView = ViewerTest::CurrentView();
228   V3dView->EnableGLLight( Standard_False );  
229   V3dView->TriedronDisplay(Aspect_TOTP_LEFT_LOWER, Quantity_NOC_WHITE, 0.07);
230   aContext->UpdateCurrentViewer();
231   return 0;
232 }
233
234 void QABugs::Commands_18(Draw_Interpretor& theCommands) {
235   const char *group = "QABugs";
236
237   theCommands.Add("OCC267", "OCC267 DOC path", __FILE__, OCC267, group);
238   theCommands.Add("OCC181", "OCC181 FileName path1 path2 verbose=0/1", __FILE__, OCC181, group);
239   theCommands.Add("OCC367", "OCC367 shape step goodX goodY goodZ percent_tolerance", __FILE__, OCC367, group);
240   theCommands.Add("OCC71", "OCC71", __FILE__, OCC71bug, group);
241
242   return;
243 }