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