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