0031763: Foundation Classes - reporting of progress within parallel algorithms
[occt.git] / src / QABugs / QABugs_11.cxx
CommitLineData
b311480e 1// Created on: 2002-03-20
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.
b311480e 15
7fd59977 16#include <stdio.h>
17
1cd84fee 18#include <QABugs.hxx>
7fd59977 19
91322f44 20#include <Draw.hxx>
7fd59977 21#include <Draw_Interpretor.hxx>
22#include <DBRep.hxx>
23#include <DrawTrSurf.hxx>
24#include <AIS_InteractiveContext.hxx>
25#include <ViewerTest.hxx>
26#include <AIS_Shape.hxx>
27#include <TopoDS_Shape.hxx>
28
543a9964 29#include <Geom_Surface.hxx>
7fd59977 30#include <Geom_Axis2Placement.hxx>
31#include <gp.hxx>
32#include <gp_Trsf.hxx>
33#include <AIS_Trihedron.hxx>
34#include <BRepPrimAPI_MakeBox.hxx>
35#include <Graphic3d_MaterialAspect.hxx>
36#include <ViewerTest_DoubleMapOfInteractiveAndName.hxx>
37#include <TopoDS_Solid.hxx>
38#include <BRepPrimAPI_MakeSphere.hxx>
39#include <BRepPrimAPI_MakeCone.hxx>
40#include <BRepPrimAPI_MakeCylinder.hxx>
41#include <IGESToBRep_Reader.hxx>
42#include <TopExp_Explorer.hxx>
43#include <TopoDS.hxx>
44#include <GCPnts_UniformDeflection.hxx>
45#include <BRepAdaptor_Curve.hxx>
46#include <IGESToBRep.hxx>
47#include <V3d_Viewer.hxx>
48#include <BRepAdaptor_CompCurve.hxx>
49#include <GCPnts_AbscissaPoint.hxx>
50#include <Standard_ErrorHandler.hxx>
51#include <Standard_Overflow.hxx>
52#include <Standard_Underflow.hxx>
53#include <Standard_DivideByZero.hxx>
54#include <OSD_SIGSEGV.hxx>
55#include <OSD_Exception_ACCESS_VIOLATION.hxx>
56#include <OSD_Exception_STACK_OVERFLOW.hxx>
57#include <OSD.hxx>
7e785937 58#include <OSD_Timer.hxx>
44b80414 59#include <OSD_ThreadPool.hxx>
7e785937 60#include <OSD_Parallel.hxx>
7fd59977 61#include <STEPCAFControl_Writer.hxx>
62#include <STEPControl_StepModelType.hxx>
63#include <Interface_Static.hxx>
64#include <IFSelect_ReturnStatus.hxx>
65#include <Standard_Failure.hxx>
66#include <TColgp_HArray1OfPnt2d.hxx>
67#include <Geom2dAPI_Interpolate.hxx>
68#include <Geom2d_BSplineCurve.hxx>
69#include <Geom2dConvert_BSplineCurveToBezierCurve.hxx>
70#include <Geom2d_BezierCurve.hxx>
71#include <BRep_Tool.hxx>
72#include <GeomProjLib.hxx>
73#include <Geom2dAPI_InterCurveCurve.hxx>
74#include <IntRes2d_IntersectionSegment.hxx>
75#include <TDataStd_RealArray.hxx>
76#include <TDF_CopyLabel.hxx>
77#include <NCollection_Vector.hxx>
78#include <TColStd_Array1OfInteger.hxx>
79#include <Geom_BSplineCurve.hxx>
80#include <TColgp_Array1OfPnt.hxx>
7a324550 81#include <AIS_ColorScale.hxx>
7fd59977 82#include <AIS_ListOfInteractive.hxx>
83#include <AIS_ListIteratorOfListOfInteractive.hxx>
84#include <ViewerTest_DoubleMapOfInteractiveAndName.hxx>
85#include <ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName.hxx>
86#include <BRepBuilderAPI_MakePolygon.hxx>
87#include <gp_GTrsf.hxx>
88#include <Poly_Triangulation.hxx>
89#include <IGESControl_Reader.hxx>
90#include <IGESData_IGESModel.hxx>
91#include <IGESData_IGESEntity.hxx>
92#include <V3d_View.hxx>
7c104885 93#include <BRepFeat_SplitShape.hxx>
94#include <BRepAlgoAPI_Section.hxx>
d09dda09 95#include <TColStd_PackedMapOfInteger.hxx>
23fe70ec 96#include <Message.hxx>
97#include <Draw_Printer.hxx>
7fd59977 98
d538d7a2 99#if ! defined(_WIN32)
7fd59977 100extern ViewerTest_DoubleMapOfInteractiveAndName& GetMapOfAIS();
101#else
102Standard_EXPORT ViewerTest_DoubleMapOfInteractiveAndName& GetMapOfAIS();
103#endif
104
105static Standard_Integer OCC128 (Draw_Interpretor& di, Standard_Integer /*argc*/, const char ** argv)
106{
107 Handle(AIS_InteractiveContext) myAISContext = ViewerTest::GetAISContext();
108 if(myAISContext.IsNull()) {
109 di << "use 'vinit' command before " << argv[0] ;
110 return 1;
111 }
112
113 Handle(Geom_Axis2Placement) aTrihedronAxis = new Geom_Axis2Placement(gp::XOY());
114
115 gp_Trsf trsf1;
116 trsf1.SetTranslation(gp_Vec(100, 100, 0));
117 aTrihedronAxis->Transform(trsf1);
118 Handle(AIS_Trihedron) myTrihedron = new AIS_Trihedron(aTrihedronAxis);
119 myTrihedron->SetColor(Quantity_NOC_LIGHTSTEELBLUE4);
120 myTrihedron->SetSize(100);
121 myAISContext->Display(myTrihedron, Standard_True);
122
123// TopoDS_Shape shape1 = (TopoDS_Shape) BRepPrimAPI_MakeBox(50,50,50);
124 TopoDS_Shape shape1 = BRepPrimAPI_MakeBox(50,50,50).Shape();
125 Handle(AIS_Shape) AS = new AIS_Shape(shape1);
126 AS->SetDisplayMode(1);
127 Graphic3d_MaterialAspect mat(Graphic3d_NOM_PLASTIC);
128 AS->SetMaterial(mat);
129 AS->SetColor(Quantity_NOC_RED);
0577ae8c 130 myAISContext->Display (AS, Standard_False);
7fd59977 131
132 gp_Trsf TouchTrsf;
133 TouchTrsf.SetTranslation(gp_Vec(20, 20, 0));
134
135 myAISContext->ResetLocation(AS);
136 myAISContext->SetLocation(AS , TouchTrsf) ;
137 myAISContext->Redisplay(AS, Standard_True);
138
139 return 0;
140}
141
142 // Remove as bad version of QAAddOrRemoveSelected from QADraw
143//static Standard_Integer OCC129 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
144//{
145// if( argc != 3) {
146// di<<"Usage : " << argv[0] << " shape islocal\n";
147// return 1;
148// }
149// //get AIS_Shape:
150// Handle(AIS_InteractiveContext) anAISCtx = ViewerTest::GetAISContext();
151//
152// // ViewerTest_DoubleMapOfInteractiveAndName& aMap =
153// // ViewerTest::GetDataMapOfAIS ();
154// ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
155//
156// TCollection_AsciiString aName(argv[1]);
157// Handle(AIS_InteractiveObject) AISObj;
158//
159// if(aMap.IsBound2(aName)) {
160// AISObj = aMap.Find2(aName);
161// if(AISObj.IsNull()){
162// di<<"No interactive object \n";
163// return 1;
164// }
165//
166// Standard_Integer aNum = -1;
167//
91322f44 168// if(Draw::Atoi(argv[2])) {
7fd59977 169// aNum = anAISCtx->OpenLocalContext();
170// }
171//
172// if(anAISCtx->HasOpenedContext()){
173// anAISCtx->InitSelected();
174// anAISCtx->AddOrRemoveSelected(AISObj);
175// }
176// else {
177// anAISCtx->InitCurrent();
178// anAISCtx->AddOrRemoveCurrentObject(AISObj);
179// }
180//
181// if(aNum >= 0) {
182// // anAISCtx->CloseLocalContext(aNum);
183// }
184//
185// return 0;
186// }
187// //select this shape:
188// else {
189// di<<"Use 'vdisplay' before";
190// return 1;
191// }
192//}
193
194static Standard_Integer OCC136 (Draw_Interpretor& di, Standard_Integer argc, const char ** /*argv*/)
195{
196 if(argc > 1){
197 di<<"Usage: OCC136\n";
198 return 1;
199 }
200
201 //create some primitives:
202 // Two basic points:
203 Standard_Real Size=100;
204 gp_Pnt P0(0,0,0), P1(Size,Size,Size);
205 //box
206 TopoDS_Solid aBox = BRepPrimAPI_MakeBox(P0,P1);
207 //sphere
208 TopoDS_Solid aSphere = BRepPrimAPI_MakeSphere (Size*0.5);
209 //cone
210 gp_Ax2 anAx2(P1, gp_Dir(1,1,1));
211 TopoDS_Solid aCone = BRepPrimAPI_MakeCone(anAx2, Size*0.7, Size*0.3, Size);
212 //cylinder
213 anAx2.SetLocation(gp_Pnt(Size,0,0));
214 anAx2.SetDirection(gp_Dir(-1,-1,1));
215 TopoDS_Solid aCyl = BRepPrimAPI_MakeCylinder(anAx2, Size*0.5, Size);
216
217 Handle(AIS_InteractiveContext) anAISCtx = ViewerTest::GetAISContext();
218 if(anAISCtx.IsNull()){
219 di<<"Null interactive context. Use 'vinit' at first.\n";
220 return 1;
221 }
222
0577ae8c 223 anAISCtx->EraseAll (Standard_False);
7fd59977 224
225 //load primitives to context
c3282ec1 226 Handle(AIS_InteractiveObject) aSh1 = new AIS_Shape(aBox);
0577ae8c 227 anAISCtx->Display (aSh1, Standard_False);
7fd59977 228
c3282ec1 229 Handle(AIS_InteractiveObject) aSh2 = new AIS_Shape(aSphere);
0577ae8c 230 anAISCtx->Display (aSh2, Standard_False);
7fd59977 231
c3282ec1 232 Handle(AIS_InteractiveObject) aSh3 = new AIS_Shape(aCone);
0577ae8c 233 anAISCtx->Display (aSh3, Standard_False);
7fd59977 234
c3282ec1 235 Handle(AIS_InteractiveObject) aSh4 = new AIS_Shape(aCyl);
0577ae8c 236 anAISCtx->Display (aSh4, Standard_False);
7fd59977 237
238 //set selected
c3282ec1 239 anAISCtx->InitSelected();
0577ae8c 240 anAISCtx->AddOrRemoveSelected (aSh1, Standard_False);
241 anAISCtx->AddOrRemoveSelected (aSh2, Standard_False);
242 anAISCtx->AddOrRemoveSelected (aSh3, Standard_False);
243 anAISCtx->AddOrRemoveSelected (aSh4, Standard_False);
7fd59977 244
245 //remove all this objects from context
2195ab96 246 anAISCtx->Remove (aSh1, Standard_False);
247 anAISCtx->Remove (aSh2, Standard_False);
248 anAISCtx->Remove (aSh3, Standard_False);
249 anAISCtx->Remove (aSh4, Standard_False);
0577ae8c 250
251 anAISCtx->UpdateCurrentViewer();
7fd59977 252 return 0;
253}
254
255static int BUC60610(Draw_Interpretor& di, Standard_Integer argc, const char ** argv) {
256 if(argc < 2){
257 printf("Usage: %s iges_input [name]\n",argv[0]);
258 return(1);
259 }
1d47d8d0 260 Standard_Character *Ch = NULL;
7fd59977 261
262 if(argc > 2) {
263 Ch = new Standard_Character[strlen(argv[2])+3];
264 }
265 IGESToBRep_Reader IR;
266 IR.LoadFile (argv[1]);
267 IR.Clear();
268 IR.TransferRoots();
269 TopoDS_Shape aTopShape = IR.OneShape();
270 TopExp_Explorer ex(aTopShape, TopAbs_EDGE);
271 Standard_Integer i=0;
272 for( ; ex.More(); ex.Next()){
273 const TopoDS_Edge &E = TopoDS::Edge(ex.Current());
274 BRepAdaptor_Curve aCurve(E);
275 GCPnts_UniformDeflection plin(aCurve, 0.1);
276 di << "Num points = " << plin.NbPoints() << "\n";
277 if(argc > 2) {
278 i++;
91322f44 279 Sprintf(Ch,"%s_%i",argv[2],1);
7fd59977 280 DBRep::Set(Ch,E);
281 }
282 }
283 return (1);
284}
285
7fd59977 286//====================================================
287//
288// Following code is inserted from
289// /dn03/KAS/dev/QAopt/src/QADraw/QADraw_TOPOLOGY.cxx
290// ( 75455 Apr 16 18:59)
291//
292//====================================================
293
294//OCC105
295#include <BRepTools_WireExplorer.hxx>
296#include <BRep_Tool.hxx>
297#include <GCPnts_UniformAbscissa.hxx>
298#include <TopExp.hxx>
299
300//
301// usage : OCC105 shape
302//
303// comments:
304//GCPnts_UniformAbscissa returns bad end point foe first edge. Its value is
305
306//Value Pnt = -338.556216693211 -394.465571897208 0
307//should be
308//Value Pnt = -307.47165394 -340.18073533 0
309
310static int OCC105(Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
311{
312 if (argc != 2){
313 di<<"Usage : OCC105 shape\n";
314 return 1;
315 }
316// TopoDS_Wire myTopoDSWire = TopoDS::Wire(DBRep::Get("aa.brep"));
317 TopoDS_Wire myTopoDSWire = TopoDS::Wire(DBRep::Get(argv[1]));
91322f44 318 Standard_Real l = 0.5; //Draw::Atof(argv[2]);
7fd59977 319 // Find the first vertex of the wire
320 BRepTools_WireExplorer wire_exp(myTopoDSWire);
321 TopoDS_Vertex vlast;
322 {
323 TopoDS_Vertex vw1, vw2;
324 TopExp::Vertices(myTopoDSWire,vw1,vw2);
325 TopoDS_Vertex ve1, ve2;
326 TopoDS_Edge edge = TopoDS::Edge(wire_exp.Current());
327 TopExp::Vertices(edge,ve1,ve2);
328 if (vw1.IsSame(ve1) || vw1.IsSame(ve2))
329 vlast = vw1;
330 else {
331// assert(vw2.IsSame(ve1) || vw2.IsSame(ve2));
332 vlast = vw2;
333 }
334 }
335 for ( ; wire_exp.More(); wire_exp.Next())
336 {
337 di << "\n\n New Edge \n" << "\n";
338 Standard_Real newufirst, newulast;
339 TopoDS_Edge edge = TopoDS::Edge(wire_exp.Current());
340 Standard_Real ufirst, ulast;
341 Handle(Geom_Curve) acurve;
342 TopoDS_Vertex ve1, ve2;
343 TopExp::Vertices(edge,ve1,ve2);
344 if (ve1.IsSame(vlast))
345 {
346 acurve = BRep_Tool::Curve(edge, ufirst, ulast);
347 newufirst = ufirst;
348 newulast = ulast;
349 vlast = ve2;
350 }
351 else
352 {
353// assert(ve2.IsSame(vlast));
354// assert ( wire_exp.Orientation( ) == TopAbs_REVERSED );
355 acurve = BRep_Tool::Curve( edge, ufirst, ulast );
356 newufirst = acurve->ReversedParameter( ufirst );
357 newulast = acurve->ReversedParameter( ulast );
358 acurve = acurve->Reversed( );
359 vlast = ve1;
360 }
361
362 GeomAdaptor_Curve curve;
363 GCPnts_UniformAbscissa algo;
364 curve.Load(acurve);
365 algo.Initialize( curve, l, newufirst, newulast );
366 if (!algo.IsDone())
367 di << "Not Done!!!" << "\n";
368 for (Standard_Integer Index = 1; Index<=algo.NbPoints();Index++) {
369 Standard_Real t = algo.Parameter(Index);
370 gp_Pnt pt3 = curve.Value(t);
371 di << "Parameter t = " << t << "\n";
372 di << "Value Pnt = " << pt3.X()<<" " <<pt3.Y()<<" " << pt3.Z() << "\n";
373 }
374 }
375 return 0;
376
377}
378
379#include <TColStd_SequenceOfTransient.hxx>
380#include <GeomFill_Pipe.hxx>
381static int pipe_OCC9 (Draw_Interpretor& di,
382 Standard_Integer n, const char ** a)
383{
384 if (n < 6) {
586db386 385 di << "Usage: " << a[0] << " result path cur1 cur2 radius [tolerance]\n";
7fd59977 386 return 1;
387 }
388
389 TColStd_SequenceOfTransient aCurveSeq;
390 Standard_Integer i;
391 for (i=2 ; i<=4; i++) {
392 Handle(Geom_Curve) aC = Handle(Geom_Curve)::DownCast( DrawTrSurf::Get(a[i]) );
393 if (aC.IsNull()) {
586db386 394 di << a[i] << " is not a curve\n";
7fd59977 395 return 1;
396 }
397 aCurveSeq.Append(aC);
398 }
399
400 GeomFill_Pipe aPipe(Handle(Geom_Curve)::DownCast( aCurveSeq(1) ),
401 Handle(Geom_Curve)::DownCast( aCurveSeq(2) ),
402 Handle(Geom_Curve)::DownCast( aCurveSeq(3) ),
91322f44 403 Draw::Atof (a[5]) );
7fd59977 404
405 if (n == 7) {
91322f44 406 aPipe.Perform(Draw::Atof (a[6]), Standard_True);
7fd59977 407 } else {
408 aPipe.Perform(Standard_True/*, Standard_True*/);
409 }
410
a8b52677 411 if (!aPipe.IsDone()) {
412 di << "GeomFill_Pipe cannot make a surface\n";
413 return 1;
414 }
415
7fd59977 416 Handle(Geom_Surface) aSurf = aPipe.Surface();
417
418 DrawTrSurf::Set(a[1], aSurf);
419 return 0;
420}
421
422//======================================================================
423// OCC125
424// usage : OCC125 shell
425//======================================================================
426#include <ShapeFix_Shell.hxx>
427
428Standard_Integer OCC125(Draw_Interpretor& di ,
429 Standard_Integer n,
430 const char ** a)
431{
432 if (n!=2) {
433 di<<" Use OCC125 shell";
434 return 1;
435 }
436
437 TopoDS_Shape S = DBRep::Get(a[1]);
438
439 if (S.IsNull()) {
440 di<<" Null shape is not allowed";
441 return 1;
442 }
443
444 TopAbs_ShapeEnum aT;
445 aT=S.ShapeType();
446 if (aT!=TopAbs_SHELL) {
447 di<<" Shape Type must be SHELL";
448 return 1;
449 }
450
451 const TopoDS_Shell& aShell = TopoDS::Shell(S);
452 //
453 Standard_Boolean isAccountMultiConex, bNonManifold, bResult;
454
455 isAccountMultiConex=Standard_True;
456 bNonManifold=Standard_False;
457
458 Handle (ShapeFix_Shell) aFix = new ShapeFix_Shell(aShell);
459 bResult=aFix->FixFaceOrientation(aShell, isAccountMultiConex, bNonManifold);
460
461 di<<"bResult="<<(Standard_Integer)bResult;
462
463 TopoDS_Shape aShape;
464 aShape=aFix->Shape();
465
466 TCollection_AsciiString aName(a[1]), aDef("_sh"), aRName;
467 aRName=aName;
468 aRName=aRName+aDef;
469 DBRep::Set (aRName.ToCString(), aShape);
470 di<<aRName.ToCString();
471 //
472 return 0;
473}
474
475#include <BRepLib_FindSurface.hxx>
476#include <BRepBuilderAPI_MakeFace.hxx>
477Standard_Integer OCC157(Draw_Interpretor& di,
478 Standard_Integer n,
479 const char ** a)
480//static Standard_Integer findplanarsurface(Draw_Interpretor&, Standard_Integer n, const char ** a)
481{
482 if (n<3) {
586db386 483 di << "bad number of arguments\n";
7fd59977 484 return 1;
485 }
486
487 // try to read a shape:
488 TopoDS_Shape inputShape=DBRep::Get(a[2]);
489 if (inputShape.IsNull() || inputShape.ShapeType() != TopAbs_WIRE) {
586db386 490 di << "Invalid input shape\n";
7fd59977 491 return 1;
492 }
91322f44 493 Standard_Real toler = Draw::Atof(a[3]);
7fd59977 494 TopoDS_Wire aWire = TopoDS::Wire(inputShape);
495 BRepLib_FindSurface FS(aWire, toler, Standard_True);
496 if(FS.Found()) {
586db386 497 di<<"OCC157: OK; Planar surface is found\n";
7fd59977 498 Handle(Geom_Surface) aSurf = FS.Surface();
499 BRepBuilderAPI_MakeFace aMakeFace(aSurf,aWire,Standard_True);
500 if(aMakeFace.IsDone()) {
501 TopoDS_Face aFace = aMakeFace.Face();
502 DBRep::Set(a[1],aFace);
503 }
504 }
505 else di<<"OCC157: ERROR; Planar surface is not found with toler = "<<toler <<"\n";
506 return 0;
507
508}
509
510// #include <MyCommandsCMD.h>
511#include <ShapeFix_Shape.hxx>
512#include <BRepOffset_MakeOffset.hxx>
513#include <BRepOffsetAPI_MakeOffset.hxx>
514#include <BRepOffset_Mode.hxx>
515#include <GeomAbs_JoinType.hxx>
516#include <AIS_Shape.hxx>
517
518#include <BRepTools.hxx>
519
520Standard_Integer OCC165(Draw_Interpretor& di ,
521 Standard_Integer n,
522 const char ** a)
523
524
525//=======================================================================
526
527// static int YOffset (Draw_Interpretor& di, Standard_Integer argc, const char ** argv);
528
529// void MyOffsets_Commands(Draw_Interpretor& theCommands)
530// {
531// theCommands.Add("yoffset" , "yoffset" , __FILE__, YOffset, " Offset on Z Direction");
532// }
533
534//=======================================================================
535
536// static int YOffset (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
537 {
538 if (n > 2)
539 {
586db386 540 di <<"Usage : " << a[0] << " [file]\n";
7fd59977 541 return 1;
542 }
543 di.Eval ("axo");
544
545#define _OFFSET_TELCO_
546#ifdef _OFFSET_TELCO_
547
548 Standard_CString file = a[1];
549
550 BRep_Builder aBuilder;
551 TopoDS_Shape theShape;
552 //BRepTools::Read(theShape, Standard_CString("/dn02/users_SUN/inv/3/OCC165/2d_tr_line.brep"), aBuilder);
553 BRepTools::Read(theShape, file, aBuilder);
554 DBRep::Set("shape", theShape);
555
556 TopoDS_Wire theWire = TopoDS::Wire(theShape);
557
558 Standard_Real anOffset = 1.5;
559
560#else
561
562 Standard_Real xA = 0.0, xB = 200.0, xC = 200.0, xD = 0.0,
563 yA = 0.0, yB = 0.0, yC = 200.0, yD = 200.0,
564 zA = 0.0, zB = 0.0, zC = 0.0, zD = 0.0;
565
566 BRepBuilderAPI_MakePolygon theSquare;
567 TopoDS_Vertex theA = BRepBuilderAPI_MakeVertex(gp_Pnt(xA, yA, zA));
568 theSquare.Add(theA);
569 TopoDS_Vertex theB = BRepBuilderAPI_MakeVertex(gp_Pnt(xB, yB, zB));
570 theSquare.Add(theB);
571 TopoDS_Vertex theC = BRepBuilderAPI_MakeVertex(gp_Pnt(xC, yC, zC));
572 theSquare.Add(theC);
573 TopoDS_Vertex theD = BRepBuilderAPI_MakeVertex(gp_Pnt(xD, yD, zD));
574 theSquare.Add(theD);
575
576 theSquare.Close();
577 TopoDS_Wire theWire = theSquare.Wire();
578
579 Standard_Real anOffset = 10;
580
581
582#endif /* _OFFSET_TELCO_ */
583
584
585 TopoDS_Face theFace = BRepBuilderAPI_MakeFace(theWire).Face();
586 DBRep::Set("face", theFace);
587
588
589 Standard_Real anAlt = 0.;
590 GeomAbs_JoinType theJoin = GeomAbs_Intersection;
591//GeomAbs_Intersection; //GeomAbs_Arc;
592 BRepOffsetAPI_MakeOffset aMakeOffset(theFace, theJoin);
593 aMakeOffset.AddWire(theWire);
594
595 aMakeOffset.Perform(anOffset, anAlt);
596
597 TopoDS_Shape theOffsetShapePos = aMakeOffset.Shape();
598 DBRep::Set("offset", theOffsetShapePos);
599 return 0;
600// return TCL_OK;
601}
602
603#include<BRepAlgoAPI_Cut.hxx>
7fd59977 604
605#include<BRepPrimAPI_MakeHalfSpace.hxx>
7fd59977 606#include<Geom_CartesianPoint.hxx>
607#include<AIS_Point.hxx>
608
609#include <BRepBuilderAPI_MakeEdge.hxx>
610#include <BRepBuilderAPI_MakeWire.hxx>
611#include <BRepBuilderAPI_MakeFace.hxx>
612
613static Standard_Integer OCC297 (Draw_Interpretor& di,Standard_Integer /*argc*/, const char ** argv )
614
615{
7fd59977 616 Handle(AIS_InteractiveContext) myAISContext = ViewerTest::GetAISContext();
431d0f18 617 if (myAISContext.IsNull()) {
7fd59977 618 di << "use 'vinit' command before " << argv[0] << "\n";
619 return -1;
620 }
431d0f18 621
622 gp_Pnt pt1_(250., 250., 0.);
623 gp_Pnt pt2_(-250., 250., 0.);
624 gp_Pnt pt3_(-250., -250., 0.);
625 gp_Pnt pt4_(250., -250., 0.);
626 BRepBuilderAPI_MakeEdge edg1_(pt1_, pt2_);
627 BRepBuilderAPI_MakeEdge edg2_(pt2_, pt3_);
628 BRepBuilderAPI_MakeEdge edg3_(pt3_, pt4_);
629 BRepBuilderAPI_MakeEdge edg4_(pt4_, pt1_);
630
631 BRepBuilderAPI_MakeWire wire_(edg1_, edg2_, edg3_, edg4_);
632 BRepBuilderAPI_MakeFace face_(wire_);
633 TopoDS_Face sh_ = face_.Face();
634
635 int up = 1;
636
637 gp_Pnt g_pnt;
638 if (up)
639 g_pnt = gp_Pnt(0, 0, -100);
640 else
641 g_pnt = gp_Pnt(0, 0, 100);
7fd59977 642
431d0f18 643 myAISContext->EraseAll(Standard_False);
644 Handle(Geom_CartesianPoint) GEOMPoint = new Geom_CartesianPoint(g_pnt);
645 Handle(AIS_Point) AISPoint = new AIS_Point(GEOMPoint);
646 myAISContext->Display(AISPoint, Standard_True);
7fd59977 647
431d0f18 648 BRepPrimAPI_MakeHalfSpace half_(sh_, g_pnt);
649 TopoDS_Solid sol1_ = half_.Solid();
7fd59977 650
431d0f18 651 DBRep::Set("Face", sol1_);
7fd59977 652
431d0f18 653 gp_Ax1 ax1_(gp_Pnt(0., 0., -100.), gp_Dir(0., 0., 1.));
7fd59977 654
431d0f18 655 Standard_Real x = 0., y = 0., z = -80.;
7fd59977 656
431d0f18 657 BRepPrimAPI_MakeBox box(gp_Pnt(x, y, z), gp_Pnt(x + 150, y + 200, z + 200));
7fd59977 658
431d0f18 659 DBRep::Set("Box", box.Shape());
7fd59977 660
661 return 0;
662
663}
431d0f18 664
7fd59977 665#include<GProp_GProps.hxx>
666#include<BRepGProp.hxx>
667
668static Standard_Integer OCC305 (Draw_Interpretor& di,Standard_Integer argc, const char ** argv )
669
670{
6d1a5d3a 671 if (argc != 2)
7fd59977 672 {
586db386 673 di <<"Usage : " << argv[0] << " file\n";
7fd59977 674 return 1;
675 }
676 Standard_CString file = argv[1];
677
678 Handle(AIS_InteractiveContext) myAISContext = ViewerTest::GetAISContext();
679 if(myAISContext.IsNull()) {
680 di << "use 'vinit' command before " << argv[0] << "\n";
681 return -1;
682 }
683
684TopoDS_Shape sh;
685BRep_Builder builder;
686//BRepTools::Read(sh, "/dn02/users_SUN/inv/3/OCC305/testc.brep", builder);
687BRepTools::Read(sh, file, builder);
688
689TopoDS_Wire wire;
690builder.MakeWire(wire);
691TopoDS_Edge ed;
692TopoDS_Vertex vt1, vt2;
693TopExp_Explorer wex(sh, TopAbs_EDGE);
694for(;wex.More();wex.Next())
695{
696 ed = TopoDS::Edge(wex.Current());
697 TopExp::Vertices(ed, vt1, vt2);
698 builder.UpdateVertex(vt1, 0.01);
699 builder.UpdateVertex(vt2, 0.01);
700 builder.UpdateEdge(ed, 0.01);
701 builder.Add(wire, ed);
702
703
704 GProp_GProps lprop;
705 BRepGProp::LinearProperties(ed, lprop);
706 printf("\n length = %f", lprop.Mass());
707}
708 DBRep::Set("Wire",wire);
709// Handle(AIS_Shape) res = new AIS_Shape( wire );
710// aContext->SetColor( res, Quantity_NOC_RED );
711// aContext->Display( res );
712
713// BRepOffsetAPI_MakeOffset off(wire, GeomAbs_Arc);
714// off.Perform(0.5, 0);
715
716// printf("\n IsDone = %d", off.IsDone());
717// sh = off.Shape();
718// res = new AIS_Shape( sh );
719// aContext->SetColor( res, Quantity_NOC_GREEN );
720// aContext->Display( res );
721
722 return 0;
723
724}
725
726static Standard_Integer OCC166 (Draw_Interpretor& di, Standard_Integer /*argc*/, const char ** argv)
727{
728
729 Handle(AIS_InteractiveContext) myAISContext = ViewerTest::GetAISContext();
730 if(myAISContext.IsNull()) {
731 di << "use 'vinit' command before " << argv[0];
732 return 1;
733 }
734
735 BRepPrimAPI_MakeBox aBox(gp_Pnt(0, 0, 0), 100, 100, 100);
736 Handle(AIS_Shape) anAISBox = new AIS_Shape(aBox.Shape());
c3282ec1 737 myAISContext->SetAutoActivateSelection (Standard_False);
7fd59977 738 myAISContext->Display(anAISBox, 1);
404c8936 739
c3282ec1 740 TColStd_ListOfInteger anActivatedModes;
741 myAISContext->ActivatedModes (anAISBox, anActivatedModes);
742 if(anActivatedModes.Extent() != 1 || anActivatedModes.First() != -1 )
7fd59977 743 return 1;
744
745 return 0;
746}
747
748#include <TDocStd_Document.hxx>
749#include <DDocStd.hxx>
15e8b082 750#include <PCDM_StoreStatus.hxx>
7fd59977 751#include <TDocStd_Application.hxx>
752
753static Standard_Integer OCC381_Save (Draw_Interpretor& di, Standard_Integer nb, const char ** a)
754{
755 if (nb != 2) {
586db386 756 di << "Usage: " << a[0] << " Doc\n";
7fd59977 757 return 1;
758 }
759
760 Handle(TDocStd_Document) D;
761 if (!DDocStd::GetDocument(a[1],D)) return 1;
762
6fe96f84 763 Handle(TDocStd_Application) A = DDocStd::GetApplication();
7fd59977 764
765 TCollection_ExtendedString theStatusMessage;
766 if (!D->IsSaved()) {
586db386 767 di << "this document has never been saved\n";
7fd59977 768 return 0;
769 }
15e8b082
M
770 PCDM_StoreStatus theStatus = A->Save(D, theStatusMessage);
771 if (theStatus != PCDM_SS_OK ) {
7fd59977 772 switch ( theStatus ) {
566f8441 773 case PCDM_SS_DriverFailure: {
586db386 774 di << "Error saving document: Could not store , no driver found to make it\n";
566f8441 775 break ;
776 }
777 case PCDM_SS_WriteFailure: {
586db386 778 di << "Error saving document: Write access failure\n";
566f8441 779 break;
780 }
781 case PCDM_SS_Failure: {
586db386 782 di << "Error saving document: Write failure\n" ;
566f8441 783 break;
784 }
785 case PCDM_SS_Doc_IsNull: {
586db386 786 di << "Error saving document: No document to save\n";
566f8441 787 break ;
788 }
789 case PCDM_SS_No_Obj: {
586db386 790 di << "Error saving document: No objects written\n";
566f8441 791 break;
792 }
793 case PCDM_SS_Info_Section_Error: {
586db386 794 di << "Error saving document: Write info section failure\n" ;
566f8441 795 break;
796 }
797 default:
798 break;
7fd59977 799 }
800 return 1;
801 }
802 return 0;
803}
804
805static Standard_Integer OCC381_SaveAs (Draw_Interpretor& di, Standard_Integer nb, const char ** a)
806{
807 if (nb != 3) {
586db386 808 di << "Usage: " << a[0] << " Doc Path\n";
7fd59977 809 return 1;
810 }
811
812 Handle(TDocStd_Document) D;
813 if (!DDocStd::GetDocument(a[1],D)) return 1;
814
815 TCollection_ExtendedString path (a[2]);
6fe96f84 816 Handle(TDocStd_Application) A = DDocStd::GetApplication();
7fd59977 817
818 TCollection_ExtendedString theStatusMessage;
15e8b082
M
819 PCDM_StoreStatus theStatus = A->SaveAs(D,path, theStatusMessage);
820 if (theStatus != PCDM_SS_OK ) {
7fd59977 821 switch ( theStatus ) {
566f8441 822 case PCDM_SS_DriverFailure: {
586db386 823 di << "Error saving document: Could not store , no driver found to make it\n";
566f8441 824 break ;
825 }
826 case PCDM_SS_WriteFailure: {
586db386 827 di << "Error saving document: Write access failure\n";
566f8441 828 break;
829 }
830 case PCDM_SS_Failure: {
586db386 831 di << "Error saving document: Write failure\n" ;
566f8441 832 break;
833 }
834 case PCDM_SS_Doc_IsNull: {
586db386 835 di << "Error saving document: No document to save\n";
566f8441 836 break ;
837 }
838 case PCDM_SS_No_Obj: {
586db386 839 di << "Error saving document: No objects written\n";
566f8441 840 break;
841 }
842 case PCDM_SS_Info_Section_Error: {
586db386 843 di << "Error saving document: Write info section failure\n" ;
566f8441 844 break;
845 }
846 default:
847 break;
7fd59977 848 }
849 return 1;
850 }
851
852 return 0;
853}
854
855#include <BRepClass3d_SolidClassifier.hxx>
856
64531d9c 857Standard_Integer OCC299bug (Draw_Interpretor& theDi,
858 Standard_Integer theArgNb,
859 const char** theArgVec)
7fd59977 860{
64531d9c 861 if (theArgNb < 3)
862 {
863 theDi << "Usage : " << theArgVec[0] << " Solid Point [Tolerance=1.e-7]\n";
7fd59977 864 return -1;
865 }
866
64531d9c 867 TopoDS_Shape aS = DBRep::Get (theArgVec[1]);
868 if (aS.IsNull())
869 {
870 theDi << " Null Shape is not allowed here\n";
7fd59977 871 return 1;
872 }
64531d9c 873 else if (aS.ShapeType() != TopAbs_SOLID)
874 {
875 theDi << " Shape type must be SOLID\n";
7fd59977 876 return 1;
877 }
64531d9c 878
879 gp_Pnt aP (8., 9., 10.);
880 if (!DrawTrSurf::GetPoint (theArgVec[2], aP))
881 {
882 theDi << " Null Point is not allowed here\n";
7fd59977 883 return 1;
884 }
64531d9c 885 const Standard_Real aTol = (theArgNb == 4) ? Draw::Atof (theArgVec[3]) : 1.e-7;
7fd59977 886
64531d9c 887 BRepClass3d_SolidClassifier aSC (aS);
888 aSC.Perform (aP, aTol);
7fd59977 889
64531d9c 890 switch (aSC.State())
891 {
892 case TopAbs_IN: theDi << "The point is IN shape\n"; return 0;
893 case TopAbs_OUT: theDi << "The point is OUT of shape\n"; return 0;
894 case TopAbs_ON: theDi << "The point is ON shape\n"; return 0;
895 case TopAbs_UNKNOWN:
896 default: theDi << "The point is UNKNOWN shape\n"; return 0;
897 }
7fd59977 898}
899
900#include <OSD_Process.hxx>
901#include <OSD_Path.hxx>
902
903static Standard_Integer OCC309bug (Draw_Interpretor& di, Standard_Integer nb, const char ** a)
904{
905 if (nb != 1) {
906 di << "Usage: " << a[0] << "\n";
907 return 1;
908 }
909 OSD_Process p;
910 OSD_Path d = p.CurrentDirectory();
911 TCollection_AsciiString s;
912 d.SystemName(s);
586db386 913 di << "*" << s.ToCString() << "*\n";
7fd59977 914 d.UpTrek();
915 d.SystemName(s);
586db386 916 di << "*" << s.ToCString() << "*\n";
7fd59977 917 return 0;
918}
919
920static Standard_Integer OCC310bug (Draw_Interpretor& di, Standard_Integer nb, const char ** a)
921{
922 if (nb != 1) {
923 di << "Usage: " << a[0] << "\n";
924 return 1;
925 }
926 OSD_Path p("/where/you/want/tmp/qwerty/tmp/");
927 di << p.Trek().ToCString() << "\n";
928 p.UpTrek();
929 di << p.Trek().ToCString() << "\n";
930 return 0;
931}
932
933#include <BRepAlgoAPI_Fuse.hxx>
934#include <BRepAlgoAPI_Common.hxx>
7fd59977 935
936static Standard_Integer OCC277bug (Draw_Interpretor& di, Standard_Integer nb, const char ** a)
937{
431d0f18 938 if(nb != 1) {
939 di << "Usage : " << a[0] << "\n";
7fd59977 940 return 1;
941 }
7fd59977 942
943 BRepPrimAPI_MakeBox box1( 100, 100, 100 );
944 BRepPrimAPI_MakeBox box2( gp_Pnt( 50, 50,50 ), 200, 200, 200 );
945
946 TopoDS_Shape shape1 = box1.Shape();
947 TopoDS_Shape shape2 = box2.Shape();
948
7fd59977 949 TopoDS_Shape fuse,comm;
431d0f18 950 di << "fuse = BRepAlgoAPI_Fuse( shape1, shape2 )\n";
951 di << "comm = BRepAlgoAPI_Common( shape1, shape2 )\n";
952 fuse = BRepAlgoAPI_Fuse(shape1, shape2).Shape();
953 comm = BRepAlgoAPI_Common(shape1, shape2).Shape();
7fd59977 954
955 return 0;
956}
957
7fd59977 958#include <DDocStd_DrawDocument.hxx>
959#include <TDataStd_Name.hxx>
960#include <Draw.hxx>
961#include <XCAFDoc_ShapeTool.hxx>
962#include <XCAFDoc_DocumentTool.hxx>
963#include <TDF_LabelSequence.hxx>
964#include <TPrsStd_AISPresentation.hxx>
965#include <TDF_Data.hxx>
966#include <TDF_Label.hxx>
967#include <XCAFPrs_Driver.hxx>
968
969//------------------------------------------------------------------------------------------
970// name : OCC363
971// Purpose :
972//------------------------------------------------------------------------------------------
973static Standard_Integer OCC363 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
974{
975 try
976 {
977 OCC_CATCH_SIGNALS
978 // 1. Verufy amount of arguments
979 if(argc < 3) { di <<"Error OCC363 : Use : OCC363 document filename\n"; return 1; }
980
981 // 2. Retrieve DDocStd application
6fe96f84 982 Handle(TDocStd_Application) App = DDocStd::GetApplication();
7fd59977 983
984 // 3. Open document
985 TCollection_ExtendedString name(argv[2]);
986 Handle(TDocStd_Document) Doc;
15e8b082 987 if(App->Open(name, Doc) != PCDM_RS_OK) { di << "Error OCC363 : document was not opened successfully\n"; return 1;}
7fd59977 988 Handle(DDocStd_DrawDocument) DD = new DDocStd_DrawDocument(Doc);
989 TDataStd_Name::Set(Doc->GetData()->Root(),argv[1]);
990 Draw::Set(argv[1],DD);
991
992 // 4. Create prsentations
993 Handle(XCAFDoc_ShapeTool) shapes = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
994 TDF_LabelSequence seq;
995 shapes->GetFreeShapes ( seq );
996 Handle(TPrsStd_AISPresentation) prs;
997 for ( Standard_Integer i=1; i <= seq.Length(); i++ )
998 if ( ! seq.Value(i).FindAttribute ( TPrsStd_AISPresentation::GetID(), prs ) )
999 prs = TPrsStd_AISPresentation::Set(seq.Value(i),XCAFPrs_Driver::GetID());
1000 }
a738b534 1001 catch(Standard_Failure const&) { di << "FAULTY OCC363 : Exception during reading document.\n";return 0;}
7fd59977 1002
1003 di << "OCC363 OK\n";
1004 return 0;
1005}
1006
1007// Must use OCC299
1008////======================================================================================
1009//// Function : OCC372
1010//// Purpose :
1011////======================================================================================
1012//static Standard_Integer OCC372 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
1013//{
1014// try
1015// {
1016// OCC_CATCH_SIGNALS
1017// // 1. Verufy amount of arguments
1018// if(argc < 2) {di << "OCC372 FAULTY. Use : OCC372 brep-file";return 0;}
1019//
1020// // 2. Read solid
1021// BRep_Builder B;
1022// TopoDS_Shape Ref;
1023// BRepTools::Read(Ref, argv[1], B);
1024//
1025// // 3. Calculate location of aP3d in relation to the solid
1026// gp_Pnt aP3d(6311.4862583184, -2841.3092756034, 16.461053497188);
1027// BRepClass3d_SolidClassifier SC(Ref);
1028// SC.Perform(aP3d, 1e-7);
1029//
1030// // 4. Check returned state. The point must be inside the solid.
1031// TopAbs_State aState=SC.State();
1032// switch (aState)
1033// {
1034// case TopAbs_OUT:
1035// di<<"OCC372 FAULTY. aState = TopAbs_OUT";
1036// return 0;
1037// case TopAbs_ON:
1038// di<<"OCC372 FAULTY. aState = TopAbs_ON";
1039// return 0;
1040// case TopAbs_IN:
1041// di<<"OCC372 OK. aState = TopAbs_IN" ;
1042// return 0;
1043// default:
1044// di<<"OCC372 FAULTY. aState = UNKNOWN";
1045// return 0;
1046// }
1047// }
1048// catch (Standard_Failure) { di<<"OCC372 FAULTY. Exception raised"; }
1049//
1050// return 0;
1051//}
1052
1053#include <BRepTopAdaptor_FClass2d.hxx>
1054
1055//======================================================================================
1056// Function : OCC377
1057// Purpose :
1058//======================================================================================
1059static Standard_Integer OCC377 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
1060{
1061 try
1062 {
1063 OCC_CATCH_SIGNALS
1064 // 1. Verify validity of arguments
1065 if ( argc < 1 ) {di << "Error OCC377. Use OCC377 file x y precuv \n";return 0;}
1066
1067 // 2. Initialize parameters
1068 gp_Pnt2d p2d;
91322f44 1069 p2d.SetX ( Draw::Atof(argv[2]) );
1070 p2d.SetY ( Draw::Atof(argv[3]) );
1071 Standard_Real precuv = Draw::Atof (argv[4] );
7fd59977 1072
1073 // 3. Read shape
1074 BRep_Builder B;
1075 TopoDS_Shape Shape;
1076 BRepTools::Read ( Shape, argv[1], B );
1077
1078 // 4. Verify whether enrtry point is on wire and reversed ones (indeed results of veridying must be same)
1079 TopExp_Explorer exp;
1080 Standard_Integer i=1;
1081 for (exp.Init(Shape.Oriented(TopAbs_FORWARD),TopAbs_WIRE); exp.More(); exp.Next(), i++)
1082 {
1083 // 4.1. Verify whether enrtry point is on wire
1084 const TopoDS_Wire& wir = TopoDS::Wire(exp.Current());
1085 TopoDS_Face newFace = TopoDS::Face(Shape.EmptyCopied());
1086
1087 TopAbs_Orientation orWire = wir.Orientation();
1088 newFace.Orientation(TopAbs_FORWARD);
1089 B.Add(newFace,wir);
1090
1091 BRepTopAdaptor_FClass2d FClass2d1(newFace,precuv);
1092 TopAbs_State stat1 = FClass2d1.PerformInfinitePoint();
1093 //di << "Wire " << i << ": Infinite point is " <<
1094 // ( stat1 == TopAbs_IN ? "IN" : stat1 == TopAbs_OUT ? "OUT" : stat1 == TopAbs_ON ? "ON" : "UNKNOWN" ) << "\n";
1095
1096 TCollection_AsciiString TmpString;
1097 stat1 == TopAbs_IN ? TmpString.AssignCat("IN") : stat1 == TopAbs_OUT ? TmpString.AssignCat("OUT") : stat1 == TopAbs_ON ? TmpString.AssignCat("ON") : TmpString.AssignCat("UNKNOWN");
1098 di << "Wire " << i << ": Infinite point is " << TmpString.ToCString() << "\n";
1099
1100 stat1 = FClass2d1.Perform(p2d);
1101 //di << "Wire " << i << ": point ( " << p2d.X() << ", " << p2d.Y() << " ) is " <<
1102 // ( stat1 == TopAbs_IN ? "IN" : stat1 == TopAbs_OUT ? "OUT" : stat1 == TopAbs_ON ? "ON" : "UNKNOWN" ) << "\n";
1103
1104 TmpString.Clear();
1105 stat1 == TopAbs_IN ? TmpString.AssignCat("IN") : stat1 == TopAbs_OUT ? TmpString.AssignCat("OUT") : stat1 == TopAbs_ON ? TmpString.AssignCat("ON") : TmpString.AssignCat("UNKNOWN");
1106 di << "Wire " << i << ": point ( " << p2d.X() << ", " << p2d.Y() << " ) is " << TmpString.ToCString() << "\n";
1107
1108 // 4.2. Verify whether enrtry point is on reversed wire
1109 newFace = TopoDS::Face(Shape.EmptyCopied());
1110 newFace.Orientation(TopAbs_FORWARD);
1111 orWire = TopAbs::Reverse(orWire);
1112 B.Add(newFace,wir.Oriented(orWire));
1113 BRepTopAdaptor_FClass2d FClass2d2(newFace,precuv);
1114 TopAbs_State stat2 = FClass2d2.PerformInfinitePoint();
1115 //di << "Reversed Wire " << i << ": Infinite point is " <<
1116 // ( stat2 == TopAbs_IN ? "IN" : stat2 == TopAbs_OUT ? "OUT" : stat2 == TopAbs_ON ? "ON" : "UNKNOWN" ) << "\n";
1117
1118 TmpString.Clear();
1119 stat2 == TopAbs_IN ? TmpString.AssignCat("IN") : stat2 == TopAbs_OUT ? TmpString.AssignCat("OUT") : stat2 == TopAbs_ON ? TmpString.AssignCat("ON") : TmpString.AssignCat("UNKNOWN");
1120 di << "Reversed Wire " << i << ": Infinite point is " << TmpString.ToCString() << "\n";
1121
1122 stat2 = FClass2d2.Perform(p2d);
1123 //di << "Reversed Wire " << i << ": point ( " << p2d.X() << ", " << p2d.Y() << " ) is " <<
1124 // ( stat2 == TopAbs_IN ? "IN" : stat2 == TopAbs_OUT ? "OUT" : stat2 == TopAbs_ON ? "ON" : "UNKNOWN" ) << "\n";
1125
1126 TmpString.Clear();
1127 stat2 == TopAbs_IN ? TmpString.AssignCat("IN") : stat2 == TopAbs_OUT ? TmpString.AssignCat("OUT") : stat2 == TopAbs_ON ? TmpString.AssignCat("ON") : TmpString.AssignCat("UNKNOWN");
1128 di << "Reversed Wire " << i << ": point ( " << p2d.X() << ", " << p2d.Y() << " ) is " << TmpString.ToCString() << "\n";
1129
1130 // 4.3. Compare results (they must be same)
586db386 1131 if(stat1 ==stat2) di << "OCC377 OK\n";
1132 else {di << "OCC377 FAULTY\n"; return 0;}
7fd59977 1133 }
1134 }
a738b534 1135 catch(Standard_Failure const&)
7fd59977 1136 {
1137 di << "OCC377 Exception";
1138 }
1139
1140 return 0;
1141}
1142
1143#include <ShapeUpgrade_ShapeDivideAngle.hxx>
1144#include <ShapeBuild_ReShape.hxx>
1145
1146//=======================================================================
1147//function : OCC22
1148//purpose :
1149//=======================================================================
1150static Standard_Integer OCC22 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
1151{
1152 try
1153 {
1154 OCC_CATCH_SIGNALS
1155 // 1. Verify arguments of the command
1156 if (argc < 5) { di << "OCC22 FAULTY. Use : OCC22 Result Shape CompoundOfSubshapesToBeDivided ConsiderLocation"; return 0;}
1157
1158 Standard_Boolean aConsiderLocation;
1159 if(strcmp(argv[4], "0")==0) aConsiderLocation = Standard_False;
1160 else aConsiderLocation = Standard_True;
1161
1162 // 2. Iniitialize aShapeUpgrade
c6541a0c 1163 ShapeUpgrade_ShapeDivideAngle aShapeUpgrade(M_PI/2.);
7fd59977 1164 // precision
1165 aShapeUpgrade.SetPrecision (Precision::Confusion());
1166 // tolerance
1167 aShapeUpgrade.SetMaxTolerance(0.1);
1168 // subshapes to be divided
1169 TopoDS_Shape aSubShapesToBeDivided = DBRep::Get(argv[3]);
1170 if(aSubShapesToBeDivided.IsNull()) {di << "OCC22 FAULTY. Compound of subshapes to be divided is not exist. Please, verify input values. \n";return 0;}
1171 aShapeUpgrade.Init(aSubShapesToBeDivided);
1172 // context
1173 Handle(ShapeBuild_ReShape) aReshape = new ShapeBuild_ReShape;
1174 aShapeUpgrade.SetContext(aReshape);
1175 if(aConsiderLocation) aReshape->ModeConsiderLocation() = Standard_True;
1176
1177 // 3. Perform splitting
1178 if (aShapeUpgrade.Perform (Standard_False)) di << "Upgrade_SplitRevolution_Done \n";
1179 else if (aShapeUpgrade.Status (ShapeExtend_OK)) di << "Upgrade_SplitRevolution_OK \n";
1180 else if (aShapeUpgrade.Status (ShapeExtend_FAIL)) { di << "OCC22 FAULTY. Operation failed. Angle was not divided\n";return 0;}
1181
1182 // 4. Perform rebuilding shape
1183 // 4.1. Retrieve Shape
1184 TopoDS_Shape anInitShape = DBRep::Get(argv[2]);
1185 if(anInitShape.IsNull()) { di << "OCC22 FAULTY. Initial shape is not exist. Please verify input values \n"; return 0;}
1186 // 4.2 Rebuid retrieved shape
1187 TopoDS_Shape aResultShape = aReshape->Apply(anInitShape);
1188 // 4.3. Create result Draw shape
1189 DBRep::Set(argv[1], aResultShape);
1190 }
a738b534 1191 catch (Standard_Failure const&) {di << "OCC22 Exception \n" ;return 0;}
7fd59977 1192
1193 return 0;
1194}
1195
1196
1197#include <ShapeProcess_OperLibrary.hxx>
1198#include <ShapeProcess_ShapeContext.hxx>
1199#include <ShapeProcess.hxx>
1200
1201#include <TopTools_DataMapIteratorOfDataMapOfShapeShape.hxx>
1202#include <BRepMesh_IncrementalMesh.hxx>
7bd071ed 1203#include <IMeshTools_Parameters.hxx>
7fd59977 1204
1205//=======================================================================
1206//function : OCC24
1207//purpose :
1208//=======================================================================
1209static Standard_Integer OCC24 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
1210{
1211 try
1212 {
1213 OCC_CATCH_SIGNALS
1214 // 1. Verify amount of arguments of the command
1215 if (argc < 6) { di << "OCC24 FAULTY. Use : OCC22 Result Shape CompoundOfSubshapes ResourceFileName SequenceName"; return 0;}
1216
1217 // 2. Retrieve parameters
1218 // initial shape
1219 TopoDS_Shape anInitShape = DBRep::Get(argv[2]);
1220 if(anInitShape.IsNull()) { di << "OCC24 FAULTY. Initial shape is not exist. Please verify input values \n"; return 0;}
1221 // compound of subshapes
1222 TopoDS_Shape aSubShapes = DBRep::Get(argv[3]);
1223 if(aSubShapes.IsNull()) {di << "OCC24 FAULTY. Compound of subshapes is not exist. Please, verify input values. \n";return 0;}
1224 // name of resource file
1225 const char* aResourceFile = argv[4];
1226 // name of sequence from resource file to be executed
1227 const char* aSequenceName = argv[5];
1228
1229 // 3. Initialize ShapeContext and perform sequence of operation specified with resource file
1230 ShapeProcess_OperLibrary::Init();
1231 Handle(ShapeProcess_ShapeContext) aShapeContext = new ShapeProcess_ShapeContext (aSubShapes, aResourceFile);
1232 aShapeContext->SetDetalisation (TopAbs_EDGE);
1233 ShapeProcess::Perform (aShapeContext, aSequenceName);
1234
1235 // 4. Rebuild initil shape in accordance with performed operation
1236 Handle(ShapeBuild_ReShape) aReshape = new ShapeBuild_ReShape;
1237 TopTools_DataMapIteratorOfDataMapOfShapeShape anIter (aShapeContext->Map());
1238 for (; anIter.More(); anIter.Next())
1239 aReshape->Replace(anIter.Key(), anIter.Value());
1240 TopoDS_Shape aResultShape = aReshape->Apply(anInitShape);
1241
1242 // 5 Create resultant Draw shape
1243 DBRep::Set(argv[1], aResultShape);
1244
1245 }
a738b534 1246 catch (Standard_Failure const&) {di << "OCC24 Exception \n" ;return 0;}
7fd59977 1247
1248 return 0;
1249}
1250
1251//=======================================================================
1252//function : OCC369
1253//purpose : Verify whether exception occurs during building mesh
1254//=======================================================================
1255static Standard_Integer OCC369(Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
1256{
1257 try
1258 {
1259 OCC_CATCH_SIGNALS
1260 // 1. Verify amount of arguments of the command
1261 if (argc < 2) { di << "OCC369 FAULTY. Use : OCC369 Shape \n"; return 0;}
1262
1263 // 2. Retrieve shape
1264 TopoDS_Shape aShape = DBRep::Get(argv[1]);
1265 if(aShape.IsNull()) {di << "OCC369 FAULTY. Entry shape is NULL \n"; return 0;}
1266
1267 // 3. Build mesh
7bd071ed 1268 IMeshTools_Parameters aMeshParams;
1269 aMeshParams.Relative = Standard_True;
e71669c6 1270 aMeshParams.Deflection = 0.2;
7bd071ed 1271 aMeshParams.Angle = M_PI / 6.0;
e71669c6 1272 BRepMesh_IncrementalMesh aMesh(aShape, aMeshParams);
7fd59977 1273
1274 }
a738b534 1275 catch (Standard_Failure const&) {di << "OCC369 Exception \n" ;return 0;}
7fd59977 1276
1277 di << "OCC369 OK \n";
1278 return 0;
1279}
1280
1281#include <math_Vector.hxx>
1282#include <math_Matrix.hxx>
1283static Standard_Integer OCC524 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
1284{
1285 if(argc != 9){
1286 di<<"Usage : " << argv[0] << " LowerVector UpperVector InitialValueVector LowerRowMatrix UpperRowMatrix LowerColMatrix UpperColMatrix InitialValueMatrix\n";
1287 return 1;
1288 }
91322f44 1289 Standard_Integer LowerVector = Draw::Atoi(argv[1]);
1290 Standard_Integer UpperVector = Draw::Atoi(argv[2]);
1291 Standard_Real InitialValueVector = Draw::Atof(argv[3]);
1292 Standard_Integer LowerRowMatrix = Draw::Atoi(argv[4]);
1293 Standard_Integer UpperRowMatrix = Draw::Atoi(argv[5]);
1294 Standard_Integer LowerColMatrix = Draw::Atoi(argv[6]);
1295 Standard_Integer UpperColMatrix = Draw::Atoi(argv[7]);
1296 Standard_Real InitialValueMatrix = Draw::Atof(argv[8]);
7fd59977 1297
1298 math_Vector Vector1(LowerVector, UpperVector);
1299 math_Vector Vector2(LowerVector, UpperVector);
1300
1301 math_Vector Vector(LowerVector, UpperVector, InitialValueVector);
1302 math_Matrix Matrix(LowerRowMatrix, UpperRowMatrix, LowerColMatrix, UpperColMatrix, InitialValueMatrix);
1303
04232180 1304 //Vector.Dump(std::cout);
1305 //std::cout<<std::endl;
7fd59977 1306
04232180 1307 //Matrix.Dump(std::cout);
1308 //std::cout<<std::endl;
7fd59977 1309
1310 Vector1.Multiply(Vector, Matrix);
1311
04232180 1312 //Vector1.Dump(std::cout);
7fd59977 1313 Standard_SStream aSStream1;
1314 Vector1.Dump(aSStream1);
1315 di << aSStream1;
1316 di<<"\n";
1317
d2d893b8
RL
1318 if (Matrix.RowNumber() > 1) {
1319 Matrix(Matrix.LowerRow() + 1, Matrix.LowerCol()) += 1.;
1320 }
7fd59977 1321 Vector2.TMultiply(Vector, Matrix);
1322
04232180 1323 //Vector2.Dump(std::cout);
7fd59977 1324 Standard_SStream aSStream2;
1325 Vector2.Dump(aSStream2);
1326 di << aSStream2;
1327 di<<"\n";
1328
1329 return 0;
1330}
1331
1332#include <GeomPlate_BuildPlateSurface.hxx>
1333//=======================================================================
1334//function : OCC525
1335//purpose :
1336//=======================================================================
1337static Standard_Integer OCC525(Draw_Interpretor& di, Standard_Integer /*argc*/, const char ** /*argv*/)
1338{
e8e26df0 1339 GeomPlate_BuildPlateSurface aBuilder;
1340 aBuilder.Perform();
1341
1342 if (aBuilder.IsDone())
7fd59977 1343 {
e8e26df0 1344 di << "Error in OCC525. Null result is expected.\n";
1345 }
1346 else
1347 {
1348 di << "OCC525 OK \n";
7fd59977 1349 }
7fd59977 1350
7fd59977 1351 return 0;
1352}
1353
7fd59977 1354#include <BRepPrimAPI_MakeWedge.hxx>
1355#include <gce_MakeRotation.hxx>
1356#include <gce_MakeTranslation.hxx>
1357#include <BRepBuilderAPI_Transform.hxx>
1358#include <BRepPrimAPI_MakeWedge.hxx>
7fd59977 1359//=======================================================================
1360//function : OCC578
1361//purpose :
1362//=======================================================================
1363static Standard_Integer OCC578 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
1364{
431d0f18 1365 if(argc != 4) {
1366 di << "Usage : " << argv[0] << " shape1 shape2 shape3\n";
7fd59977 1367 return 1;
1368 }
7fd59977 1369
1370 gp_Pnt P0(0,0,0.0);
1371 double xperiod = 1.0;
1372 double yperiod = 1.0;
1373 double sub_thick = 0.5;
1374
1375 // mask_substrate
1376 //TopoDS_Shape substrate = BRepPrimAPI_MakeBox( P0, xperiod, yperiod, sub_thick );
1377 TopoDS_Shape substrate = BRepPrimAPI_MakeBox( P0, xperiod, yperiod, sub_thick ).Shape();
1378
1379 // --------------------------------------------------------------------
1380
1381 // wedge
1382 //TopoDS_Shape wedge1 = BRepPrimAPI_MakeWedge(0.5, 0.05, 0.5,
1383 // 0.1, 0.1 , 0.4, 0.4 );
1384 TopoDS_Shape wedge1 = BRepPrimAPI_MakeWedge(0.5, 0.05, 0.5,
1385 0.1, 0.1 , 0.4, 0.4 ).Shape();
1386
1387 gp_Trsf rotate = gce_MakeRotation ( gp_Pnt(0.0,0.0,0.0),
1388 gp_Dir(1.0,0.0,0.0),
1389 1.570795 );
1390
1391 gp_Trsf translate = gce_MakeTranslation(gp_Pnt( 0.0, -0.5, 0.0),
1392 gp_Pnt( 0.25, 0.25, 0.5)
1393 );
1394
1395 rotate.PreMultiply( translate );
1396
1397 TopoDS_Shape wedge1a = BRepBuilderAPI_Transform( wedge1, rotate );
1398
1399 if (wedge1a.IsNull()) {
1400 di<<" Null shape1 is not allowed\n";
1401 return 1;
1402 }
1403 DBRep::Set(argv[1], wedge1a);
1404
1405 // --------------------------------------------------------------------
1406
1407 // wedge top
1408 //TopoDS_Shape wedge2 = BRepPrimAPI_MakeWedge(0.5, 0.3, 0.5,
1409 // 0.1, 0.1 , 0.4, 0.4 );
1410 TopoDS_Shape wedge2 = BRepPrimAPI_MakeWedge(0.5, 0.3, 0.5,
1411 0.1, 0.1 , 0.4, 0.4 ).Shape();
1412
1413 gp_Trsf rotate2 = gce_MakeRotation ( gp_Pnt(0.0,0.0,0.0),
1414 gp_Dir(1.0,0.0,0.0),
1415 1.570795 * 3.0 );
1416
1417 gp_Trsf translate2 = gce_MakeTranslation(gp_Pnt( 0.0, 0.0, 0.0),
1418 gp_Pnt( 0.25, 0.25, 0.5)
1419 );
1420
1421 rotate2.PreMultiply( translate2 );
1422
1423 TopoDS_Shape wedge2a = BRepBuilderAPI_Transform( wedge2, rotate2 );
1424
1425 if (wedge2a.IsNull()) {
1426 di<<" Null shape2 is not allowed\n";
1427 return 1;
1428 }
1429 DBRep::Set(argv[2], wedge2a);
1430
1431
1432 // combine wedges
431d0f18 1433 di << "wedge_common = BRepAlgoAPI_Fuse(wedge1a , wedge2a)\n";
1434 TopoDS_Shape wedge_common = BRepAlgoAPI_Fuse(wedge1a , wedge2a).Shape();
7fd59977 1435
431d0f18 1436 di << "sub_etch1 = BRepAlgoAPI_Cut(substrate, wedge_common)\n";
1437 TopoDS_Shape sub_etch1 = BRepAlgoAPI_Cut(substrate, wedge_common).Shape();
1438
7fd59977 1439 if (sub_etch1.IsNull()) {
1440 di<<" Null shape3 is not allowed\n";
1441 return 1;
1442 }
1443 DBRep::Set(argv[3], sub_etch1);
1444
1445 return 0;
1446}
1447
7fd59977 1448#include <Standard_GUID.hxx>
1449//=======================================================================
1450//function : OCC669
1451//purpose :
1452//=======================================================================
1453static Standard_Integer OCC669 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
1454{
1455 if(argc != 2){
1456 di<<"Usage : " << argv[0] << " GUID\n";
1457 return -1;
1458 }
1459 Standard_GUID guid(argv[1]);
04232180 1460 //guid.ShallowDump(std::cout);
7fd59977 1461 Standard_SStream aSStream;
1462 guid.ShallowDump(aSStream);
1463 di << aSStream;
1464 di<<"\n";
1465 return 0;
1466}
1467
1468#include <XCAFDoc.hxx>
1469//=======================================================================
1470//function : OCC738_ShapeRef
1471//purpose :
1472//=======================================================================
1473static Standard_Integer OCC738_ShapeRef (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
1474{
1475 if(argc != 1){
1476 di<<"Usage : " << argv[0] << "\n";
1477 return -1;
1478 }
1479 const Standard_GUID& guid = XCAFDoc::ShapeRefGUID ();
04232180 1480 //guid.ShallowDump(std::cout);
7fd59977 1481 Standard_SStream aSStream;
1482 guid.ShallowDump(aSStream);
1483 di << aSStream;
1484 return 0;
1485}
1486
1487//=======================================================================
1488//function : OCC738_Assembly
1489//purpose :
1490//=======================================================================
1491static Standard_Integer OCC738_Assembly (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
1492{
1493 if(argc != 1){
1494 di<<"Usage : " << argv[0] << "\n";
1495 return -1;
1496 }
1497 const Standard_GUID& guid = XCAFDoc::AssemblyGUID ();
04232180 1498 //guid.ShallowDump(std::cout);
7fd59977 1499 Standard_SStream aSStream;
1500 guid.ShallowDump(aSStream);
1501 di << aSStream;
1502 return 0;
1503}
1504
1505#if defined(DDataStd_def01)
1506#include <DDataStd_DrawPresentation.hxx>
1507//=======================================================================
1508//function : OCC739_DrawPresentation
1509//purpose :
1510//=======================================================================
1511static Standard_Integer OCC739_DrawPresentation (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
1512{
1513 if(argc != 1){
1514 di<<"Usage : " << argv[0] << "\n";
1515 return -1;
1516 }
1517 const Standard_GUID& guid = DDataStd_DrawPresentation::GetID() ;
04232180 1518 //guid.ShallowDump(std::cout);
7fd59977 1519 Standard_SStream aSStream;
1520 guid.ShallowDump(aSStream);
1521 di << aSStream;
1522 return 0;
1523}
1524#endif
1525
1526//=======================================================================
1527//function : OCC708
1528//purpose :
1529//=======================================================================
1530static Standard_Integer OCC708 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
1531{
1532 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
1533 if(aContext.IsNull()) {
586db386 1534 di << argv[0] << "ERROR : use 'vinit' command before \n";
7fd59977 1535 return 1;
1536 }
1537
1538 if ( argc != 2) {
586db386 1539 di << "ERROR : Usage : " << argv[0] << " shape ; Deactivate the current transformation\n";
7fd59977 1540 return 1;
1541 }
1542
eb4320f2 1543 Standard_Boolean updateviewer = Standard_True;
7fd59977 1544
1545 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
1546
1547 TCollection_AsciiString aName(argv[1]);
1548 Handle(AIS_InteractiveObject) AISObj;
1549
8f521168 1550 if (!aMap.Find2 (aName, AISObj)
1551 || AISObj.IsNull())
1552 {
586db386 1553 di << "Use 'vdisplay' before\n";
7fd59977 1554 return 1;
7fd59977 1555 }
8f521168 1556
1557 AISObj->ResetTransformation();
1558
1559 aContext->Erase(AISObj, updateviewer);
1560 aContext->UpdateCurrentViewer();
1561 aContext->Display(AISObj, updateviewer);
1562 aContext->UpdateCurrentViewer();
7fd59977 1563 return 0;
1564}
1565
1566//=======================================================================
1567//function : OCC670
1568//purpose :
1569//=======================================================================
1570#include <TColStd_Array2OfInteger.hxx>
1571static Standard_Integer OCC670 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
1572{
1573 if(argc != 1){
1574 di<<"Usage : " << argv[0] << "\n";
1575 return -1;
1576 }
8fcb8c07 1577
1578 // check that exception initialized without message string can be safely handled and printed
1579 try {
9775fa61 1580 throw Standard_OutOfRange();
8fcb8c07 1581 }
9775fa61 1582 catch (Standard_Failure const& anException) {
8fcb8c07 1583 std::cout << "Caught successfully: ";
04232180 1584 std::cout << anException << std::endl;
8fcb8c07 1585 }
7fd59977 1586 return 0;
1587}
1588
1589#include <GeomAPI_ProjectPointOnSurf.hxx>
1590//=======================================================================
1591//function : OCC867
1592//purpose :
1593//=======================================================================
1594static Standard_Integer OCC867(Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
1595{
1596 if (argc!=7)
1597 {
1598 di<<"Usage : " << argv[0] << " Point Surface Umin Usup Vmin Vsup \n";
1599 return 1;
1600 }
1601
1602 gp_Pnt aPoint3d;
1603 DrawTrSurf::GetPoint(argv[1],aPoint3d);
1604 Handle (Geom_Surface) aSurface=DrawTrSurf::GetSurface(argv[2]);
91322f44 1605 Standard_Real Umin=Draw::Atof(argv[3]);
1606 Standard_Real Usup=Draw::Atof(argv[4]);
1607 Standard_Real Vmin=Draw::Atof(argv[5]);
1608 Standard_Real Vsup=Draw::Atof(argv[6]);
7fd59977 1609
1610 if (aSurface.IsNull()) {
1611 di << argv[2] << " Null surface \n" ;
1612 return 1;
1613 }
1614
1615 GeomAPI_ProjectPointOnSurf PonSurf;
1616 PonSurf.Init(aSurface, Umin, Usup, Vmin, Vsup);
1617 PonSurf.Perform(aPoint3d);
1618
1619 return 0;
1620}
1621
1622//=======================================================================
1623//function : OCC909
1624//purpose :
1625//=======================================================================
1626static Standard_Integer OCC909 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
1627{
1628 if (argc!=3)
1629 {
1630 di<<"Usage : " << argv[0] << " wire face\n";
1631 return 1;
1632 }
1633
1634 TopoDS_Wire awire = TopoDS::Wire(DBRep::Get(argv[1])); //read the wire
1635 TopoDS_Face aface = TopoDS::Face(DBRep::Get(argv[2])); //read the face
1636 if (awire.IsNull() || aface.IsNull()) {
586db386 1637 di << "Null object\n";
7fd59977 1638 return 1;
1639 }
1640
1641 Standard_Integer count = 0;
1642 TopExp_Explorer TE(awire, TopAbs_VERTEX);
1643 if ( TE.More()) {
1644 BRepTools_WireExplorer WE;
1645 for ( WE.Init(awire,aface); WE.More(); WE.Next()) {
1646 TopoDS_Edge E = WE.Current();
1647 count++;
1648 }
1649 }
1650 di << "Count = " << count << "\n";
1651
1652 return 0;
1653}
1654
1655//=======================================================================
1656//function : OCC921
1657//purpose :
1658//=======================================================================
1659static Standard_Integer OCC921 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
1660{
6d1a5d3a 1661 if (argc != 2)
7fd59977 1662 {
586db386 1663 di <<"Usage : " << argv[0] << " face\n";
7fd59977 1664 return 1;
1665 }
1666 Standard_Real u1, u2, v1, v2;
1667 TopoDS_Face F = TopoDS::Face( DBRep::Get(argv[1]) ); //read the shape
1668 if (F.IsNull())
1669 return 1;
1670 BRepTools::UVBounds(F, u1, u2, v1, v2);
1671 di << "Bounds: " << u1 << " " << u2 << " " << v1 << " " << v2 << "\n";
1672 return 0;
1673}
1674
1675#include <Expr_NamedUnknown.hxx>
1676#include <Expr_GeneralExpression.hxx>
1677#include <Expr_Exponential.hxx>
1bf23e5b 1678#include <ExprIntrp_GenExp.hxx>
7fd59977 1679//=======================================================================
1680//function : OCC902
1681//purpose :
1682//=======================================================================
1683static Standard_Integer OCC902(Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
1684{
6d1a5d3a 1685 if (argc != 2)
7fd59977 1686 {
586db386 1687 di <<"Usage : " << argv[0] << " expression\n";
7fd59977 1688 return 1;
1689 }
1690
1bf23e5b 1691 TCollection_AsciiString anExpStr(argv[1]);
1692 anExpStr.AssignCat("*x");
1693 anExpStr.Prepend("Exp(");
1694 anExpStr.AssignCat(")");
7fd59977 1695
1bf23e5b 1696 Handle(ExprIntrp_GenExp) exprIntrp = ExprIntrp_GenExp::Create();
1697
1698 //
1699 // Create the expression
1700 exprIntrp->Process(anExpStr);
1701
1702 if (!exprIntrp->IsDone())
1703 {
1704 di << "Interpretation of expression " << argv[1] << " failed\n";
1705 return 1;
1706 }
1707
1708
1709 Handle(Expr_GeneralExpression) anExpr = exprIntrp->Expression();
1710 Handle(Expr_NamedUnknown) aVar = new Expr_NamedUnknown("x");
1711 Handle (Expr_GeneralExpression) newExpr = anExpr->Derivative(aVar);
7fd59977 1712
1713
1714 TCollection_AsciiString res = newExpr->String();
1715 Standard_CString resStr = res.ToCString();
1bf23e5b 1716 TCollection_AsciiString res_old = anExpr->String();
7fd59977 1717 Standard_CString res_oldStr = res_old.ToCString();
1718
1719
1720 di << "X = " << argv[1] << "\n";
1721 di << "Y = " << res_oldStr << "\n";
1722 di << "Y' = " << resStr << "\n";
1723
1724 return 0;
1725}
1726
1727#include <DDF.hxx>
1728#include <TPrsStd_AISViewer.hxx>
1729#include <TDF_Label.hxx>
1730#include <TPrsStd_AISPresentation.hxx>
1731//=======================================================================
1732//function : OCC1029_AISTransparency
1733//purpose : OCC1029_AISTransparency (DOC,entry,[real])
1734//=======================================================================
1735
1736static Standard_Integer OCC1029_AISTransparency (Draw_Interpretor& di,
1737 Standard_Integer nb,
1738 const char ** arg)
1739{
1740 if (nb >= 3 ) {
1741 Handle(TDocStd_Document) D;
1742 if (!DDocStd::GetDocument(arg[1],D)) return 1;
1743 TDF_Label L;
1744 if (!DDF::FindLabel(D->GetData(),arg[2],L)) return 1;
1745
1746 Handle(TPrsStd_AISViewer) viewer;
1747 if( !TPrsStd_AISViewer::Find(L, viewer) ) return 1;
1748
1749 Handle(TPrsStd_AISPresentation) prs;
1750 if(L.FindAttribute( TPrsStd_AISPresentation::GetID(), prs) ) {
1751 if( nb == 4 ) {
91322f44 1752 prs->SetTransparency(Draw::Atof(arg[3]));
7fd59977 1753 TPrsStd_AISViewer::Update(L);
1754 }
1755 else {
1756 di << "Transparency = " << prs->Transparency() << "\n";
1757 }
1758 return 0;
1759 }
1760 }
586db386 1761 di << arg[0] << " : Error\n";
7fd59977 1762 return 1;
1763}
1764
7fd59977 1765//=======================================================================
1766//function : OCC1031_AISMaterial
1767//purpose : OCC1031_AISMaterial (DOC,entry,[material])
1768//=======================================================================
1769
1770static Standard_Integer OCC1031_AISMaterial (Draw_Interpretor& di,
1771 Standard_Integer nb,
1772 const char ** arg)
1773{
1774 if (nb >= 3) {
1775 Handle(TDocStd_Document) D;
1776 if (!DDocStd::GetDocument(arg[1],D)) return 1;
1777 TDF_Label L;
1778 if (!DDF::FindLabel(D->GetData(),arg[2],L)) return 1;
1779
1780 Handle(TPrsStd_AISViewer) viewer;
1781 if( !TPrsStd_AISViewer::Find(L, viewer) ) return 1;
1782
1783 Handle(TPrsStd_AISPresentation) prs;
1784 if(L.FindAttribute( TPrsStd_AISPresentation::GetID(), prs) ) {
1785 if( nb == 4 ) {
91322f44 1786 prs->SetMaterial((Graphic3d_NameOfMaterial)Draw::Atoi(arg[3]));
7fd59977 1787 TPrsStd_AISViewer::Update(L);
1788 }
1789 else {
1790 di << "Material = " << prs->Material() << "\n";
1791 }
1792 return 0;
1793 }
1794 }
586db386 1795 di << arg[0] << " : Error\n";
7fd59977 1796 return 1;
1797}
1798
1799//=======================================================================
1800//function : OCC1032_AISWidth
1801//purpose : OCC1032_AISWidth (DOC,entry,[width])
1802//=======================================================================
1803
1804static Standard_Integer OCC1032_AISWidth (Draw_Interpretor& di,
1805 Standard_Integer nb,
1806 const char ** arg)
1807{
1808 if (nb >= 3) {
1809 Handle(TDocStd_Document) D;
1810 if (!DDocStd::GetDocument(arg[1],D)) return 1;
1811 TDF_Label L;
1812 if (!DDF::FindLabel(D->GetData(),arg[2],L)) return 1;
1813
1814 Handle(TPrsStd_AISViewer) viewer;
1815 if( !TPrsStd_AISViewer::Find(L, viewer) ) return 1;
1816
1817 Handle(TPrsStd_AISPresentation) prs;
1818 if(L.FindAttribute( TPrsStd_AISPresentation::GetID(), prs) ) {
1819 if( nb == 4 ) {
91322f44 1820 prs->SetWidth(Draw::Atof(arg[3]));
7fd59977 1821 TPrsStd_AISViewer::Update(L);
1822 }
1823 else {
1824 di << "Width = " << prs->Width() << "\n";
1825 }
1826 return 0;
1827 }
1828 }
586db386 1829 di << arg[0] << " : Error\n";
7fd59977 1830 return 1;
1831}
1832
1833//=======================================================================
1834//function : OCC1033_AISMode
1835//purpose : OCC1033_AISMode (DOC,entry,[mode])
1836//=======================================================================
1837
1838static Standard_Integer OCC1033_AISMode (Draw_Interpretor& di,
1839 Standard_Integer nb,
1840 const char ** arg)
1841{
1842 if (nb >= 3) {
1843 Handle(TDocStd_Document) D;
1844 if (!DDocStd::GetDocument(arg[1],D)) return 1;
1845 TDF_Label L;
1846 if (!DDF::FindLabel(D->GetData(),arg[2],L)) return 1;
1847
1848 Handle(TPrsStd_AISViewer) viewer;
1849 if( !TPrsStd_AISViewer::Find(L, viewer) ) return 1;
1850
1851 Handle(TPrsStd_AISPresentation) prs;
1852 if(L.FindAttribute( TPrsStd_AISPresentation::GetID(), prs) ) {
1853 if( nb == 4 ) {
91322f44 1854 prs->SetMode(Draw::Atoi(arg[3]));
7fd59977 1855 TPrsStd_AISViewer::Update(L);
1856 }
1857 else {
1858 di << "Mode = " << prs->Mode() << "\n";
1859 }
1860 return 0;
1861 }
1862 }
586db386 1863 di << arg[0] << " : Error\n";
7fd59977 1864 return 1;
1865}
1866
1867//=======================================================================
1868//function : OCC1034_AISSelectionMode
1869//purpose : OCC1034_AISSelectionMode (DOC,entry,[selectionmode])
1870//=======================================================================
1871
1872static Standard_Integer OCC1034_AISSelectionMode (Draw_Interpretor& di,
1873 Standard_Integer nb,
1874 const char ** arg)
1875{
1876 if (nb >= 3) {
1877 Handle(TDocStd_Document) D;
1878 if (!DDocStd::GetDocument(arg[1],D)) return 1;
1879 TDF_Label L;
1880 if (!DDF::FindLabel(D->GetData(),arg[2],L)) return 1;
1881
1882 Handle(TPrsStd_AISViewer) viewer;
1883 if( !TPrsStd_AISViewer::Find(L, viewer) ) return 1;
1884
1885 Handle(TPrsStd_AISPresentation) prs;
1886 if(L.FindAttribute( TPrsStd_AISPresentation::GetID(), prs) ) {
1887 if( nb == 4 ) {
91322f44 1888 prs->SetSelectionMode(Draw::Atoi(arg[3]));
7fd59977 1889 TPrsStd_AISViewer::Update(L);
1890 }
1891 else {
1892 di << "SelectionMode = " << prs->SelectionMode() << "\n";
1893 }
1894 return 0;
1895 }
1896 }
586db386 1897 di << arg[0] << " : Error\n";
7fd59977 1898 return 1;
1899}
1900
7fd59977 1901//=======================================================================
1902//function : OCC1487
1903//purpose :
1904//=======================================================================
1905static Standard_Integer OCC1487 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
1906{
431d0f18 1907 if(argc != 5) {
1908 di << "Usage : " << argv[0] << " CylinderVariant(=1/2) cylinder1 cylinder2 cutshape\n";
7fd59977 1909 return 1;
1910 }
7fd59977 1911
91322f44 1912 Standard_Integer CaseNumber = Draw::Atoi(argv[1]);
7fd59977 1913
1914 //BRepPrimAPI_MakeCylinder o_mc1 (gp_Ax2 (gp_Pnt(0,-50,140), gp_Dir(1,0,0)), 50,1000);
1915 gp_Dir myDir(1,0,0);
1916 gp_Pnt myPnt(0,-50,140);
1917 gp_Ax2 myAx2(myPnt, myDir);
1918 BRepPrimAPI_MakeCylinder o_mc1 (myAx2, 50,1000);
1919
1920 TopoDS_Shape cyl1 = o_mc1.Shape();
1921
1922 TopoDS_Shape cyl2;
1923 TopoDS_Shape o_cut_shape;
1924 if (CaseNumber == 1) {
c6541a0c
D
1925 //BRepPrimAPI_MakeCylinder o_mc2 (gp_Ax2 (gp_Pnt(21.65064, -50.0, 127.5),gp_Dir(-sin(M_PI/3), 0.0, 0.5)), 5, 150);
1926 gp_Dir myDir_mc2(-sin(M_PI/3), 0.0, 0.5);
7fd59977 1927 gp_Pnt myPnt_mc2(21.65064, -50.0, 127.5);
1928 gp_Ax2 myAx2_mc2(myPnt_mc2, myDir_mc2);
1929 BRepPrimAPI_MakeCylinder o_mc2 (myAx2_mc2, 5, 150);
1930
1931 cyl2 = o_mc2.Shape();
431d0f18 1932 di << "o_cut_shape = BRepAlgoAPI_Cut (o_mc1.Solid (), o_mc2.Solid ())\n";
1933 o_cut_shape = BRepAlgoAPI_Cut (o_mc1.Solid (), o_mc2.Solid ()).Shape();
7fd59977 1934 } else {
c6541a0c 1935 //BRepPrimAPI_MakeCylinder o_mc2 (gp_Ax2 (gp_Pnt(978.34936, -50.0, 127.5),gp_Dir(sin(M_PI/3), 0.0, 0.5)), 5, 150);
8983c41c 1936 gp_Dir myDir_mc2(sin(M_PI/3), 0.0, 0.5);
1937 gp_Pnt myPnt_mc2(978.34936, -50.0, 127.5);
7fd59977 1938 gp_Ax2 myAx2_mc2(myPnt_mc2, myDir_mc2);
1939 BRepPrimAPI_MakeCylinder o_mc2 (myAx2_mc2, 5, 150);
1940
1941 cyl2 = o_mc2.Shape();
431d0f18 1942 di << "o_cut_shape = BRepAlgoAPI_Cut (o_mc1.Solid (), o_mc2.Solid ())\n";
1943 o_cut_shape = BRepAlgoAPI_Cut (o_mc1.Solid (), o_mc2.Solid ()).Shape();
7fd59977 1944 }
1945
1946 DBRep::Set(argv[2],cyl1);
1947 DBRep::Set(argv[3],cyl2);
1948 DBRep::Set(argv[4],o_cut_shape);
1949
1950 return 0;
1951}
1952
1953#include<TopTools_ListIteratorOfListOfShape.hxx>
1954#include<BRepFilletAPI_MakeFillet.hxx>
1955//=======================================================================
1956//function : OCC1077
1957//purpose :
1958//=======================================================================
1959TopoDS_Shape OCC1077_boolbl(BRepAlgoAPI_BooleanOperation& aBoolenaOperation,const Standard_Real aRadius)
1960{
1961 Standard_Real t3d = 1.e-4;
1962 Standard_Real t2d = 1.e-5;
1963 Standard_Real ta = 1.e-2;
1964 Standard_Real fl = 1.e-3;
1965 Standard_Real tapp_angle = 1.e-2;
1966 GeomAbs_Shape blend_cont = GeomAbs_C1;
1967
1968 TopoDS_Shape ShapeCut = aBoolenaOperation.Shape();
1969
7fd59977 1970 TopTools_ListIteratorOfListOfShape its;
1971
1972 TopoDS_Compound result;
1973 BRep_Builder B;
1974 B.MakeCompound(result);
1975
1976 TopExp_Explorer ex;
1977 for (ex.Init(ShapeCut, TopAbs_SOLID); ex.More(); ex.Next())
1978 {
1979 const TopoDS_Shape& cutsol = ex.Current();
1980
1981 BRepFilletAPI_MakeFillet fill(cutsol);
1982 fill.SetParams(ta, t3d, t2d, t3d, t2d, fl);
1983 fill.SetContinuity(blend_cont, tapp_angle);
7fd59977 1984 its = aBoolenaOperation.SectionEdges();
7fd59977 1985 while (its.More())
1986 {
1987 TopoDS_Edge E = TopoDS::Edge(its.Value());
1988 fill.Add(aRadius, E);
1989 its.Next();
1990 }
1991
1992 fill.Build();
1993 if (fill.IsDone())
1994 {
1995 B.Add(result, fill.Shape());
1996 }
1997 else
1998 {
1999 B.Add(result, cutsol);
2000 }
2001 }
2002 return result;
2003}
2004
2005TopoDS_Shape OCC1077_cut_blend(const TopoDS_Shape& aShapeToCut, const TopoDS_Shape& aTool, const Standard_Real aRadius)
2006{
2007 //return OCC1077_boolbl(BRepAlgoAPI_Cut(aShapeToCut, aTool),aRadius);
2008 BRepAlgoAPI_Cut aCut(aShapeToCut, aTool);
2009 return OCC1077_boolbl(aCut,aRadius);
2010}
2011
2012//TopoDS_Shape OCC1077_common_blend(const TopoDS_Shape& aShape1, const TopoDS_Shape& aShape2, const Standard_Real aRadius)
2013//{
2014// return OCC1077_boolbl(BRepAlgoAPI_Common(aShape1, aShape2),aRadius);
2015//}
2016
2017TopoDS_Shape OCC1077_Bug()
2018{
2019 TopoDS_Shape theBox = BRepPrimAPI_MakeBox(gp_Pnt(-5, - 5, - 5), 10, 10, 10).Shape();
2020 TopoDS_Shape theSphere = BRepPrimAPI_MakeSphere(7).Shape();
2021
2022 TopoDS_Shape theCommon = BRepAlgoAPI_Common(theBox,theSphere);
2023 TopoDS_Shape theCylinder1 = BRepPrimAPI_MakeCylinder(gp_Ax2(gp_Pnt(0, 0, - 10),
2024 gp_Dir(0, 0, 1)), 3, 20).Shape();
2025 TopoDS_Shape theCylinder2 = BRepPrimAPI_MakeCylinder(gp_Ax2(gp_Pnt(-10, 0, 0),
2026 gp_Dir(1, 0, 0)), 3, 20).Shape();
2027 TopoDS_Shape theCylinder3 = BRepPrimAPI_MakeCylinder(gp_Ax2(gp_Pnt(0, - 10, 0),
2028 gp_Dir(0, 1, 0)), 3, 20).Shape();
2029 TopoDS_Shape theTmp1 = OCC1077_cut_blend(theCommon,theCylinder1,0.7);
857ffd5e 2030 Handle(ShapeFix_Shape) fixer = new ShapeFix_Shape(theTmp1);
7fd59977 2031 fixer->Perform();
2032 theTmp1 = fixer->Shape();
2033 TopoDS_Shape theTmp2 = OCC1077_cut_blend(theTmp1,theCylinder2,0.7);
2034 fixer->Init(theTmp2);
2035 fixer->Perform();
2036 theTmp2 = fixer->Shape();
2037 TopoDS_Shape theResult = OCC1077_cut_blend(theTmp2,theCylinder3,0.7);
2038 fixer->Init(theResult);
2039 fixer->Perform();
2040 theResult = fixer->Shape();
2041 return theResult;
2042}
2043
2044static Standard_Integer OCC1077 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
2045{
2046 if(argc < 1 || argc > 2) {
586db386 2047 di << "Usage : " << argv[0] << " result\n";
7fd59977 2048 return 1;
2049 }
2050
2051 TopoDS_Shape S = OCC1077_Bug();
2052 DBRep::Set(argv[1],S);
2053
2054 return 0;
2055}
2056
2057//////////////////////////////////////////////////////////////
2058/*!
2059 * Compute uniform distribution of points using GCPnts_UniformAbscissa
2060 */
2061//////////////////////////////////////////////////////////////
2062static Standard_Integer OCC5739_UniAbs (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
2063{
2064 if (argc < 4)
2065 {
586db386 2066 di << "Usage : " << argv[0] << " name shape step\n";
7fd59977 2067 return 1;
2068 }
2069 const char *name = argv[1];
2070 Adaptor3d_Curve *adapCurve=NULL;
2071 Handle(Geom_Curve) curve = DrawTrSurf::GetCurve(argv[2]);
2072 if (!curve.IsNull())
2073 adapCurve = new GeomAdaptor_Curve(curve);
2074 else
2075 {
2076 TopoDS_Shape wire = DBRep::Get(argv[2]);
2077 if (wire.IsNull() || wire.ShapeType() != TopAbs_WIRE)
2078 {
586db386 2079 di << argv[0] <<" Faulty : incorrect 1st parameter, curve or wire expected\n";
7fd59977 2080 return 1;
2081 }
2082 adapCurve = new BRepAdaptor_CompCurve(TopoDS::Wire(wire));
2083 }
91322f44 2084 double step = Draw::Atof(argv[3]);
7fd59977 2085 GCPnts_UniformAbscissa aUni(*adapCurve, step);
2086 int res;
2087 if (!aUni.IsDone())
2088 {
586db386 2089 di << argv[0] <<" : fail\n";
7fd59977 2090 res = 1;
2091 }
2092 else
2093 {
2094 int i, np = aUni.NbPoints();
2095 for (i=0; i < np; i++)
2096 {
2097 double par = aUni.Parameter(i+1);
2098 gp_Pnt p = adapCurve->Value(par);
2099 char n[20], *pname=n;
91322f44 2100 Sprintf(n,"%s_%d",name,i+1);
7fd59977 2101 DrawTrSurf::Set(pname,p);
2102 di<<pname<<" ";
2103 }
2104 res = 0;
2105 }
2106 delete adapCurve;
2107 return res;
2108}
2109
2110static Standard_Integer OCC6046 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
2111{
2112 if (argc != 3)
2113 {
586db386 2114 di << "Usage : " << argv[0] << " nb_of_vectors size\n";
7fd59977 2115 return 1;
2116 }
2117
91322f44 2118 Standard_Integer nb = Draw::Atoi(argv[1]);
2119 Standard_Integer sz = Draw::Atoi(argv[2]);
7fd59977 2120 Standard_Real val = 10;
2121 math_Vector **pv = new math_Vector *[nb];
2122
586db386 2123 di<<"creating "<<nb<<" vectors "<<sz<<" elements each...\n";
7fd59977 2124 Standard_Integer i;
2125 for (i=0; i < nb; i++) {
2126 pv[i] = new math_Vector (1, sz, val);
2127 if ((i % (nb/10)) == 0) {
2128 di<<" "<<i;
04232180 2129 //std::cout.flush();
7fd59977 2130 di<<"\n";
2131 }
2132 }
586db386 2133 di<<" done\n";
2134 di<<"deleting them ...\n";
7fd59977 2135 for (i=0; i < nb; i++) {
2136 delete pv[i];
2137 if ((i % (nb/10)) == 0) {
2138 di<<" "<<i;
04232180 2139 //std::cout.flush();
7fd59977 2140 di<<"\n";
2141 }
2142 }
586db386 2143 di<<" done\n";
7fd59977 2144
2145 delete [] pv;
2146
2147 return 0;
2148}
2149
2150static Standard_Integer OCC5698 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
2151{
2152 if (argc != 2)
2153 {
586db386 2154 di << "Usage : " << argv[0] << " wire\n";
7fd59977 2155 return 1;
2156 }
2157 TopoDS_Shape shape = DBRep::Get(argv[1],TopAbs_WIRE);
2158 if (shape.IsNull())
2159 return 1;
2160 TopoDS_Wire wire = TopoDS::Wire(shape);
2161 // create curve parameterised by curvilinear distance
2162 BRepAdaptor_CompCurve curve(wire,Standard_True);
2163 Standard_Real length = curve.LastParameter();
2164 Standard_Real need_length = length/2;
2165 gp_Pnt pnt;
2166 curve.D0(need_length,pnt);
2167 // create check_curve parameterised in a general way
2168 BRepAdaptor_CompCurve check_curve(wire);
2169 Standard_Real check_par =
2170 GCPnts_AbscissaPoint(check_curve, need_length, 0).Parameter();
2171 gp_Pnt check_pnt;
2172 check_curve.D0(check_par,check_pnt);
2173 // check that points are coinsiding
2174 Standard_Real error_dist = pnt.Distance(check_pnt);
2175 if (error_dist > Precision::Confusion()) {
04232180 2176 //std::cout.precision(3);
7fd59977 2177 di<<"error_dist = "<<error_dist<<
586db386 2178 " ( "<<error_dist/need_length*100<<" %)\n";
7fd59977 2179 return 0;
2180 }
586db386 2181 di<<"OK\n";
7fd59977 2182 return 0;
2183}
2184
d538d7a2 2185// stack overflow can be successfully handled only on 32-bit Windows
2186#if defined(_WIN32) && !defined(_WIN64)
37e640d5 2187static int StackOverflow (int i = -1)
7fd59977 2188{
2189 char arr[2000];
37e640d5 2190 memset (arr, 0, sizeof(arr));
2191 if (i < 0)
2192 StackOverflow(i-1);
7fd59977 2193 return i;
2194}
d538d7a2 2195#endif
7fd59977 2196
7fd59977 2197// this code does not work with optimize mode on Windows
1bd04b5a 2198#if defined(_MSC_VER) && !defined(__clang__)
7fd59977 2199#pragma optimize( "", off )
2200#endif
2201static Standard_Integer OCC6143 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
2202{
2203 if (argc != 1)
2204 {
04232180 2205 std::cout << "Usage : " << argv[0] << "\n";
7fd59977 2206 return 1;
2207 }
2208 Standard_Boolean Succes;
2209
2210 Succes = Standard_True;
2211 //OSD::SetSignal();
2212
2213 {//==== Test Divide ByZero (Integer) ========================================
2214 try{
2215 OCC_CATCH_SIGNALS
04232180 2216 std::cout << "(Integer) Divide By Zero..." << std::endl;
7fd59977 2217 di << "(Integer) Divide By Zero...";
04232180 2218 //std::cout.flush();
7fd59977 2219 di << "\n";
2220 Standard_Integer res, a =4, b = 0 ;
2221 res = a / b;
f4dee9bb 2222 di << "Error: 4 / 0 = " << res << " - no exception is raised!\n";
7fd59977 2223 Succes = Standard_False;
2224 }
d538d7a2 2225#if defined(SOLARIS) || defined(_WIN32)
a738b534 2226 catch(Standard_DivideByZero const&)
7fd59977 2227#else
a738b534 2228 catch(Standard_NumericError const&)
7fd59977 2229#endif
2230 {
f4dee9bb 2231 di << "Caught, OK\n";
7fd59977 2232 }
9775fa61 2233 catch(Standard_Failure const& anException) {
7fd59977 2234 di << " Caught (";
9775fa61 2235 di << anException.GetMessageString();
586db386 2236 di << ")... KO\n";
7fd59977 2237 Succes = Standard_False;
2238 }
7fd59977 2239 // this case tests if (...) supersedes (Standard_*),
2240 // the normal behaviour is not
2241 catch(...) {
586db386 2242 di<<" unknown exception... (But) Ok\n";
7fd59977 2243 }
7fd59977 2244 }
2245
2246 {//==== Test Divide ByZero (Real) ===========================================
2247 try{
2248 OCC_CATCH_SIGNALS
04232180 2249 std::cout << "(Real) Divide By Zero..." << std::endl;
7fd59977 2250 di << "(Real) Divide By Zero...";
04232180 2251 //std::cout.flush();
7fd59977 2252 di << "\n";
2253 Standard_Real res, a= 4.0, b=0.0;
2254 res = a / b;
f4dee9bb 2255 di << "Error: 4.0 / 0.0 = " << res << " - no exception is raised!\n";
2256 Succes = Standard_False;
7fd59977 2257 }
a738b534 2258 catch(Standard_DivideByZero const&) // Solaris, Windows w/o SSE2
7fd59977 2259 {
f4dee9bb 2260 di << "Caught, OK\n";
11fca7c1 2261 }
a738b534 2262 catch(Standard_NumericError const&) // Linux, Windows with SSE2
11fca7c1 2263 {
c381fda2 2264 di << "Caught, OK\n";
7fd59977 2265 }
9775fa61 2266 catch(Standard_Failure const& anException) {
04232180 2267 //std::cout << " Caught (" << Standard_Failure::Caught() << ")... KO" << std::endl;
7fd59977 2268 di << " Caught (";
9775fa61 2269 di << anException.GetMessageString();
586db386 2270 di << ")... KO\n";
7fd59977 2271 Succes = Standard_False;
2272 }
2273 }
2274
2275 {//==== Test Overflow (Integer) =============================================
2276 try{
2277 OCC_CATCH_SIGNALS
04232180 2278 std::cout << "(Integer) Overflow..." << std::endl;
7fd59977 2279 di << "(Integer) Overflow...";
04232180 2280 //std::cout.flush();
7fd59977 2281 di << "\n";
2282 Standard_Integer res, i=IntegerLast();
2283 res = i + 1;
04232180 2284 //++++ std::cout << " -- "<<res<<"="<<i<<"+1 Does not Caught... KO"<< std::endl;
7fd59977 2285 //++++ Succes = Standard_False;
f4dee9bb 2286 di << "Not caught: " << i << " + 1 = " << res << ", still OK\n";
7fd59977 2287 }
a738b534 2288 catch(Standard_Overflow const&) {
f4dee9bb 2289 di << "Caught, OK\n";
7fd59977 2290 }
9775fa61 2291 catch(Standard_Failure const& anException) {
04232180 2292 //std::cout << " Caught (" << Standard_Failure::Caught() << ")... KO" << std::endl;
7fd59977 2293 di << " Caught (";
9775fa61 2294 di << anException.GetMessageString();
586db386 2295 di << ")... KO\n";
7fd59977 2296 Succes = Standard_False;
2297 }
2298 }
2299
2300 {//==== Test Overflow (Real) ================================================
2301 try{
2302 OCC_CATCH_SIGNALS
04232180 2303 std::cout << "(Real) Overflow..." << std::endl;
7fd59977 2304 di << "(Real) Overflow...";
04232180 2305 //std::cout.flush();
7fd59977 2306 di << "\n";
2307 Standard_Real res, r=RealLast();
2308 res = r * r;
2309
31249d19 2310 (void)sin(1.); //this function tests FPU flags and raises signal (tested on LINUX).
7fd59977 2311
f4dee9bb 2312 di << "Error: " << r << "*" << r << " = " << res << " - no exception is raised!\n";
2313 Succes = Standard_False;
7fd59977 2314 }
a738b534 2315 catch(Standard_Overflow const&) // Solaris, Windows w/o SSE2
7fd59977 2316 {
f4dee9bb 2317 di << "Caught, OK\n";
11fca7c1 2318 }
a738b534 2319 catch(Standard_NumericError const&) // Linux, Windows with SSE2
11fca7c1 2320 {
f4dee9bb 2321 di << "Caught, OK\n";
7fd59977 2322 }
9775fa61 2323 catch(Standard_Failure const& anException) {
04232180 2324 //std::cout << " Caught (" << Standard_Failure::Caught() << ")... KO" << std::endl;
7fd59977 2325 di << " Caught (";
9775fa61 2326 di << anException.GetMessageString();
586db386 2327 di << ")... KO\n";
7fd59977 2328 Succes = Standard_False;
2329 }
2330 }
2331
2332 {//==== Test Underflow (Real) ===============================================
2333 try{
2334 OCC_CATCH_SIGNALS
04232180 2335 std::cout << "(Real) Underflow" << std::endl; // to have message in log even if process crashed
7fd59977 2336 di << "(Real) Underflow";
04232180 2337 //std::cout.flush();
7fd59977 2338 di << "\n";
cf0786da 2339 Standard_Real res, r = RealSmall();
7fd59977 2340 res = r * r;
2341 //res = res + 1.;
04232180 2342 //++++ std::cout<<"-- "<<res<<"="<<r<<"*"<<r<<" Does not Caught... KO"<<std::endl;
7fd59977 2343 //++++ Succes = Standard_False;
f4dee9bb 2344 di << "Not caught: " << r << "*" << r << " = " << res << ", still OK\n";
7fd59977 2345 }
a738b534 2346 catch(Standard_Underflow const&) // could be on Solaris, Windows w/o SSE2
7fd59977 2347 {
f4dee9bb 2348 di << "Exception caught, KO\n";
d538d7a2 2349 Succes = Standard_False;
11fca7c1 2350 }
a738b534 2351 catch(Standard_NumericError const&) // could be on Linux, Windows with SSE2
11fca7c1 2352 {
f4dee9bb 2353 di << "Exception caught, KO\n";
d538d7a2 2354 Succes = Standard_False;
7fd59977 2355 }
9775fa61 2356 catch(Standard_Failure const& anException) {
04232180 2357 //std::cout << " Caught (" << Standard_Failure::Caught() << ")... KO" << std::endl;
7fd59977 2358 di << " Caught (";
9775fa61 2359 di << anException.GetMessageString();
586db386 2360 di << ")... KO\n";
7fd59977 2361 Succes = Standard_False;
2362 }
2363 }
2364
2365 {//==== Test Invalid Operation (Real) ===============================================
2366 try{
2367 OCC_CATCH_SIGNALS
04232180 2368 std::cout << "(Real) Invalid Operation..." << std::endl;
7fd59977 2369 di << "(Real) Invalid Operation...";
04232180 2370 //std::cout.flush();
7fd59977 2371 di << "\n";
2372 Standard_Real res, r=-1;
2373 res = sqrt(r);
f4dee9bb 2374 di << "Error: swrt(-1) = " << res << " - no exception is raised!\n";
2375 Succes = Standard_False;
7fd59977 2376 }
a738b534 2377 catch(Standard_NumericError const&) {
f4dee9bb 2378 di << "Caught, OK\n";
7fd59977 2379 }
9775fa61 2380 catch(Standard_Failure const& anException) {
04232180 2381 //std::cout << " Caught (" << Standard_Failure::Caught() << ")... KO" << std::endl;
7fd59977 2382 di << " Caught (";
9775fa61 2383 di << anException.GetMessageString();
586db386 2384 di << ")... KO\n";
7fd59977 2385 Succes = Standard_False;
2386 }
2387 }
2388
2389 {//==== Test Access Violation ===============================================
2390 try {
2391 OCC_CATCH_SIGNALS
04232180 2392 std::cout << "Segmentation Fault..." << std::endl;
7fd59977 2393 di << "Segmentation Fault...";
04232180 2394 //std::cout.flush();
7fd59977 2395 di << "\n";
2396 int* pint=NULL;
2397 *pint = 4;
f4dee9bb 2398 di << "Error: writing by NULL address - no exception is raised!\n";
7fd59977 2399 Succes = Standard_False;
2400 }
d538d7a2 2401#ifdef _WIN32
a738b534 2402 catch(OSD_Exception_ACCESS_VIOLATION const&)
7fd59977 2403#else
a738b534 2404 catch(OSD_SIGSEGV const&)
7fd59977 2405#endif
2406 {
f4dee9bb 2407 di << "Caught, OK\n";
9775fa61 2408 } catch(Standard_Failure const& anException) {
04232180 2409 //std::cout << " Caught (" << Standard_Failure::Caught() << ")... KO" << std::endl;
7fd59977 2410 di << " Caught (";
9775fa61 2411 di << anException.GetMessageString();
586db386 2412 di << ")... KO\n";
7fd59977 2413 Succes = Standard_False;
2414 }
2415 }
2416
d538d7a2 2417#if defined(_WIN32) && !defined(_WIN64)
7fd59977 2418 {//==== Test Stack Overflow ===============================================
2419 try {
2420 OCC_CATCH_SIGNALS
04232180 2421 std::cout << "Stack Overflow..." << std::endl;
7fd59977 2422 di << "Stack Overflow...";
04232180 2423 //std::cout.flush();
7fd59977 2424 di << "\n";
2425 StackOverflow();
f4dee9bb 2426 di << "Error - no exception is raised!\n";
7fd59977 2427 Succes = Standard_False;
2428 }
a738b534 2429 catch(OSD_Exception_STACK_OVERFLOW const&) {
f4dee9bb 2430 di << "Caught, OK\n";
7fd59977 2431 }
d1d3e057 2432 catch(Standard_Failure const& anException) {
04232180 2433 //std::cout << " Caught (" << Standard_Failure::Caught() << ")... KO" << std::endl;
7fd59977 2434 di << " Caught (";
d1d3e057 2435 di << anException.GetMessageString();
586db386 2436 di << ")... KO\n";
7fd59977 2437 Succes = Standard_False;
2438 }
2439 }
2440#endif
2441
2442 if(Succes) {
586db386 2443 di << "TestExcept: Successfull completion\n";
7fd59977 2444 } else {
586db386 2445 di << "TestExcept: failure\n";
7fd59977 2446 }
2447
2448 return 0;
2449}
44b80414 2450
2451//! Auxiliary functor.
2452struct TestParallelFunctor
2453{
2454 TestParallelFunctor() : myNbNotRaised (0), myNbSigSegv (0), myNbUnknown (0) {}
2455
2456 Standard_Integer NbNotRaised() const { return myNbNotRaised; }
2457 Standard_Integer NbSigSegv() const { return myNbSigSegv; }
2458 Standard_Integer NbUnknown() const { return myNbUnknown; }
2459
2460 void operator() (int theThreadId, int theTaskId) const
2461 {
2462 (void )theThreadId;
2463 (void )theTaskId;
2464
2465 // Test Access Violation
2466 {
2467 try {
2468 OCC_CATCH_SIGNALS
2469 int* pint = NULL;
2470 *pint = 4;
2471 Standard_Atomic_Increment (&myNbNotRaised);
2472 }
2473 #ifdef _WIN32
2474 catch (OSD_Exception_ACCESS_VIOLATION const&)
2475 #else
2476 catch (OSD_SIGSEGV const&)
2477 #endif
2478 {
2479 Standard_Atomic_Increment (&myNbSigSegv);
2480 }
2481 catch (Standard_Failure const& )
2482 {
2483 Standard_Atomic_Increment (&myNbUnknown);
2484 }
2485 }
2486 }
2487private:
2488 mutable volatile Standard_Integer myNbNotRaised;
2489 mutable volatile Standard_Integer myNbSigSegv;
2490 mutable volatile Standard_Integer myNbUnknown;
2491};
2492
2493static Standard_Integer OCC30775 (Draw_Interpretor& theDI, Standard_Integer theNbArgs, const char** )
2494{
2495 if (theNbArgs != 1)
2496 {
2497 std::cout << "Syntax error: wrong number of arguments\n";
2498 return 1;
2499 }
2500
2501 Handle(OSD_ThreadPool) aPool = new OSD_ThreadPool (4);
2502 OSD_ThreadPool::Launcher aLauncher (*aPool, 4);
2503 TestParallelFunctor aFunctor;
2504 aLauncher.Perform (0, 100, aFunctor);
2505 theDI << "NbRaised: " << (aFunctor.NbSigSegv() + aFunctor.NbUnknown()) << "\n"
2506 << "NbNotRaised: " << aFunctor.NbNotRaised() << "\n"
2507 << "NbSigSeg: " << aFunctor.NbSigSegv() << "\n"
2508 << "NbUnknown: " << aFunctor.NbUnknown() << "\n";
2509 return 0;
2510}
2511
1bd04b5a 2512#if defined(_MSC_VER) && !defined(__clang__)
7fd59977 2513#pragma optimize( "", on )
2514#endif
2515
2516static TopoDS_Compound AddTestStructure(int nCount_)
2517{
2518 BRep_Builder B;
2519 int nCount=nCount_;
2520 TopoDS_Compound C;
2521 B.MakeCompound(C);
2522 BRepPrimAPI_MakeBox mkBox(1.0, 2.0, 3.0);
2523 for (int i=0; i<nCount; i++) {
2524 for (int j=0; j<nCount; j++) {
2525 gp_Trsf trsf;
2526 trsf.SetTranslationPart(gp_Vec(5.0*i, 05.0*j, 0.0));
2527 TopLoc_Location topLoc(trsf);
2528 TopoDS_Shape tempShape=mkBox.Shape().Located(topLoc);
2529 B.Add(C, tempShape);
2530 }
2531 }
2532 return C;
2533}
2534
2535static Standard_Integer OCC7141 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
2536{
c48e2889 2537 if (argc != 2 && argc != 3)
2538 {
2539 std::cout << "Usage : " << argv[0] << " [nCount] path\n";
2540 return 1;
2541 }
7fd59977 2542
c48e2889 2543 int nCount = (argc > 2 ? Draw::Atoi(argv[1]) : 10);
2544 TCollection_AsciiString aFilePath (argv[argc > 2 ? 2 : 1]);
7fd59977 2545 STEPCAFControl_Writer writer;
857ffd5e 2546 Handle(TDocStd_Document) document;
7fd59977 2547 document = new TDocStd_Document("Pace Test-StepExporter-");
857ffd5e 2548 Handle(XCAFDoc_ShapeTool) shapeTool;
7fd59977 2549 shapeTool = XCAFDoc_DocumentTool::ShapeTool(document->Main());
2550 shapeTool->AddShape(AddTestStructure(nCount), Standard_True);
2551 STEPControl_StepModelType mode = STEPControl_AsIs;
2552 if (!Interface_Static::SetIVal("write.step.assembly",1)) { //assembly mode
586db386 2553 di << "Failed to set assembly mode for step data\n\n";
7fd59977 2554 return 0;
2555 }
2556 try {
2557 OCC_CATCH_SIGNALS
2558 if( writer.Transfer(document, mode)) {
302f96fb 2559 writer.Write(aFilePath.ToCString());
7fd59977 2560 }
2561 }
a738b534 2562 catch(OSD_Exception_STACK_OVERFLOW const&) {
586db386 2563 di << "Failed : STACK OVERFLOW\n\n";
7fd59977 2564 }
9775fa61 2565 catch (Standard_Failure const& anException) {
586db386 2566 di << "Failed :\n\n";
04232180 2567 //std::cout << Standard_Failure::Caught() << std::endl;
9775fa61 2568 di << anException.GetMessageString();
7fd59977 2569 }
586db386 2570 di << argv[0] << " : Finish\n";
7fd59977 2571
2572 return 0;
2573}
2574
2575static Standard_Integer OCC7372 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
2576{
2577 if (argc != 1)
2578 {
2579 di << "Usage : " << argv[0] << "\n";
2580 return 1;
2581 }
2582
2583 // 1. Create an array of points
2584 Handle(TColgp_HArray1OfPnt2d) ap = new TColgp_HArray1OfPnt2d(1,5);
2585 ap->SetValue(1,gp_Pnt2d(100.0,0.0));
2586 ap->SetValue(2,gp_Pnt2d(100.0,100.0));
2587 ap->SetValue(3,gp_Pnt2d(0.0,100.0));
2588 ap->SetValue(4,gp_Pnt2d(0.0,0.0));
2589 ap->SetValue(5,gp_Pnt2d(50.0,-50.0));
2590
2591 // 2. Create a periodic bspline through these 5 points
2592 Geom2dAPI_Interpolate intp(ap,Standard_True,1e-6);
2593 intp.Perform();
2594 Handle(Geom2d_BSplineCurve) bspline1 = intp.Curve();
2595
2596 // 3. Increase degree of curve from 3 to 8
2597 bspline1->IncreaseDegree(8); // Increase degree to demonstrate the error
2598 Standard_CString CString1 = "BSplineCurve";
2599 DrawTrSurf::Set(CString1,bspline1);
2600
2601 // 4. Convers BSpline curve to Bezier segments
2602 Geom2dConvert_BSplineCurveToBezierCurve bc(bspline1);
2603
2604 // 5. Test the result of conversion
2605 TCollection_AsciiString aRName;
2606 for(Standard_Integer i = 1; i <= bc.NbArcs(); i++) {
2607 Handle(Geom2d_BezierCurve) arc = bc.Arc(i);
2608 aRName="segment_";
2609 aRName=aRName+TCollection_AsciiString(i);
2610 Standard_CString aRNameStr = aRName.ToCString();
2611 DrawTrSurf::Set(aRNameStr,arc);
2612 di << aRNameStr << " ";
2613 }
2614
2615 return 0;
2616}
2617
2618static Standard_Integer OCC8169 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
2619{
2620 if (argc != 4)
2621 {
586db386 2622 di << "Usage : " << argv[0] << " edge1 edge2 plane\n";
7fd59977 2623 return 1;
2624 }
2625 TopoDS_Edge theEdge1 = TopoDS::Edge(DBRep::Get(argv[1],TopAbs_EDGE));
2626 if (theEdge1.IsNull()) {
2627 di << "Invalid input shape " << argv[1] << "\n";
2628 return 1;
2629 }
2630 TopoDS_Edge theEdge2 = TopoDS::Edge(DBRep::Get(argv[2],TopAbs_EDGE));
2631 if (theEdge2.IsNull()) {
2632 di << "Invalid input shape " << argv[2] << "\n";
2633 return 1;
2634 }
2635 TopoDS_Face theFace = TopoDS::Face(DBRep::Get(argv[3],TopAbs_FACE));
2636 if (theFace.IsNull()) {
2637 di << "Invalid input shape " << argv[3] << "\n";
2638 return 1;
2639 }
2640
2641 Handle(Geom_Surface) thePlane = BRep_Tool::Surface(theFace);
2642
2643 Standard_Real aConfusion = Precision::Confusion();
2644 Standard_Real aP1first, aP1last, aP2first, aP2last;
2645
2646 Handle(Geom_Curve) aCurve1 = BRep_Tool::Curve(theEdge1, aP1first, aP1last);
2647 Handle(Geom_Curve) aCurve2 = BRep_Tool::Curve(theEdge2, aP2first, aP2last);
2648 Handle(Geom2d_Curve) aCurve2d1 = GeomProjLib::Curve2d(aCurve1, aP1first, aP1last, thePlane);
2649 Handle(Geom2d_Curve) aCurve2d2 = GeomProjLib::Curve2d(aCurve2, aP2first, aP2last, thePlane);
2650
2651 Geom2dAPI_InterCurveCurve anInter(aCurve2d1, aCurve2d2, aConfusion);
2652
2653 Standard_Integer NbPoints = anInter.NbPoints();
2654
2655 di << "NbPoints = " << NbPoints << "\n" ;
2656
2657 if (NbPoints > 0) {
2658 Standard_Integer i;
2659 for (i=1; i<=NbPoints; i++) {
2660 gp_Pnt2d aPi = anInter.Point(i);
586db386 2661 di << "Point.X(" << i << ") = " << aPi.X() << " Point.Y(" << i << ") = " << aPi.Y() << "\n" ;
7fd59977 2662 }
2663 }
2664
2665 Standard_Integer NbSegments = anInter.NbSegments();
2666
2667 di << "\nNbSegments = " << NbSegments << "\n" ;
2668
2669 if (NbSegments > 0) {
2670 IntRes2d_IntersectionSegment aSegment = anInter.Intersector().Segment(1);
2671
2672 gp_Pnt2d aP1 = aCurve2d1->Value(aSegment.FirstPoint().ParamOnFirst());
2673 gp_Pnt2d aP2 = aCurve2d2->Value(aSegment.FirstPoint().ParamOnSecond());
2674
2675 Standard_Real aDist = aP1.Distance(aP2);
2676
586db386 2677 di << "aP1.X() = " << aP1.X() << " aP1.Y() = " << aP1.Y() << "\n" ;
2678 di << "aP2.X() = " << aP2.X() << " aP2.Y() = " << aP2.Y() << "\n" ;
7fd59977 2679
2680 di << "Distance = " << aDist << "\n" ;
2681
2682 di << "Confusion = " << aConfusion << "\n" ;
2683
2684 if (aDist > aConfusion) {
586db386 2685 di << "\n" << argv[0] << " Faulty\n" ;
7fd59977 2686 } else {
586db386 2687 di << "\n" << argv[0] << " OK\n" ;
7fd59977 2688 }
2689 } else {
586db386 2690 di << "\n" << argv[0] << " OK\n" ;
7fd59977 2691 }
2692
2693 return 0;
2694}
2695static Standard_Integer OCC10138 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
2696{
2697 if (argc != 3)
2698 {
586db386 2699 di << "Usage : " << argv[0] << " lower upper\n";
7fd59977 2700 return 1;
2701 }
2702
91322f44 2703 Standard_Integer LOWER = Draw::Atoi(argv[1]);
2704 Standard_Integer UPPER = Draw::Atoi(argv[2]);
7fd59977 2705
2706 //! 0. Create an empty document with several test labels
2707 Handle(TDocStd_Document) doc = new TDocStd_Document("XmlOcaf");
2708 doc->SetUndoLimit(100);
2709 TDF_Label main_label = doc->Main();
2710 TDF_Label label1 = main_label.FindChild(1, Standard_True);
2711 TDF_Label label2 = main_label.FindChild(2, Standard_True);
2712
2713 //! 1. Set/Get OCAF attribute
2714 doc->OpenCommand();
2715 TDataStd_RealArray::Set(label1, LOWER, UPPER);
2716 Handle(TDataStd_RealArray) array;
2717 if (label1.FindAttribute(TDataStd_RealArray::GetID(), array) &&
2718 array->Lower() == LOWER && array->Upper() == UPPER)
04232180 2719 std::cout<<"1: OK"<<std::endl;
7fd59977 2720 else
2721 {
04232180 2722 std::cout<<"1: Failed.."<<std::endl;
7fd59977 2723 return 1;
2724 }
2725 doc->CommitCommand();
2726
2727 //! 2. Set/Get value
2728 doc->OpenCommand();
2729 Standard_Integer i;
2730 for (i = LOWER; i <= UPPER; i++)
2731 array->SetValue(i, i);
2732 for (i = LOWER; i <= UPPER; i++)
2733 {
2734 if (array->Value(i) != i)
2735 {
04232180 2736 std::cout<<"2: Failed.."<<std::endl;
7fd59977 2737 return 2;
2738 }
2739 }
04232180 2740 std::cout<<"2: OK"<<std::endl;
7fd59977 2741 doc->CommitCommand();
2742
2743 //! 3. Re-init the array
2744 doc->OpenCommand();
2745 array->Init(LOWER + 2, UPPER + 4);
2746 if (array->Lower() != LOWER + 2 && array->Upper() != UPPER + 4)
2747 {
04232180 2748 std::cout<<"3: Failed.."<<std::endl;
7fd59977 2749 return 3;
2750 }
2751 for (i = LOWER + 2; i <= UPPER + 4; i++)
2752 array->SetValue(i, i);
2753 for (i = LOWER + 2; i <= UPPER + 4; i++)
2754 {
2755 if (array->Value(i) != i)
2756 {
04232180 2757 std::cout<<"3: Failed.."<<std::endl;
7fd59977 2758 return 3;
2759 }
2760 }
04232180 2761 std::cout<<"3: OK"<<std::endl;
7fd59977 2762 doc->CommitCommand();
2763
2764 //! 4. Change array
2765 doc->OpenCommand();
2766 Handle(TColStd_HArray1OfReal) arr = new TColStd_HArray1OfReal(LOWER + 5, UPPER + 5);
2767 for (i = LOWER + 5; i <= UPPER + 5; i++)
2768 arr->SetValue(i, i);
2769 array->ChangeArray(arr);
2770 for (i = LOWER + 5; i <= UPPER + 5; i++)
2771 {
2772 if (array->Value(i) != i)
2773 {
04232180 2774 std::cout<<"4: Failed.."<<std::endl;
7fd59977 2775 return 4;
2776 }
2777 }
04232180 2778 std::cout<<"4: OK"<<std::endl;
7fd59977 2779 doc->CommitCommand();
2780
2781 //! 5. Copy the array
2782 doc->OpenCommand();
2783 TDF_CopyLabel copier(label1, label2);
2784 copier.Perform();
2785 if (!copier.IsDone())
2786 {
04232180 2787 std::cout<<"5: Failed.."<<std::endl;
7fd59977 2788 return 5;
2789 }
2790 Handle(TDataStd_RealArray) array2;
2791 if (!label2.FindAttribute(TDataStd_RealArray::GetID(), array2))
2792 {
04232180 2793 std::cout<<"5: Failed.."<<std::endl;
7fd59977 2794 return 5;
2795 }
2796 for (i = LOWER + 5; i <= UPPER + 5; i++)
2797 {
2798 if (array->Value(i) != i)
2799 {
04232180 2800 std::cout<<"5: Failed.."<<std::endl;
7fd59977 2801 return 5;
2802 }
2803 }
04232180 2804 std::cout<<"5: OK"<<std::endl;
7fd59977 2805 doc->CommitCommand();
2806
2807 //! 6. Undo/Redo
2808 //! 6.a: undoes the 5th action: the copied array should disappear
2809 doc->Undo();
2810 if (!label1.FindAttribute(TDataStd_RealArray::GetID(), array) ||
2811 label2.FindAttribute(TDataStd_RealArray::GetID(), array2))
2812 {
04232180 2813 std::cout<<"6.a: Failed.."<<std::endl;
7fd59977 2814 return 6;
2815 }
2816 //! 6.b: undoes the 4th action: the array should be changed to (lower+2,upper+4)
2817 doc->Undo();
2818 if (!label1.FindAttribute(TDataStd_RealArray::GetID(), array) ||
2819 array->Lower() != LOWER + 2 ||
2820 array->Upper() != UPPER + 4)
2821 {
04232180 2822 std::cout<<"6.b: Failed.."<<std::endl;
7fd59977 2823 return 6;
2824 }
2825 for (i = LOWER + 2; i <= UPPER + 4; i++)
2826 {
2827 if (array->Value(i) != i)
2828 {
04232180 2829 std::cout<<"6.b: Failed.."<<std::endl;
7fd59977 2830 return 6;
2831 }
2832 }
2833 //! 6.c: undoes the 3d action: the array should be changed to (lower,upper)
2834 doc->Undo();
2835 if (!label1.FindAttribute(TDataStd_RealArray::GetID(), array) ||
2836 array->Lower() != LOWER ||
2837 array->Upper() != UPPER)
2838 {
04232180 2839 std::cout<<"6.c: Failed.."<<std::endl;
7fd59977 2840 return 6;
2841 }
2842 for (i = LOWER; i <= UPPER; i++)
2843 {
2844 if (array->Value(i) != i)
2845 {
04232180 2846 std::cout<<"6.c: Failed.."<<std::endl;
7fd59977 2847 return 6;
2848 }
2849 }
2850 //! 6.d: undoes and redoes the 2nd action: no change is expected.
2851 doc->Undo();
2852 doc->Redo();
2853 if (!label1.FindAttribute(TDataStd_RealArray::GetID(), array) ||
2854 array->Lower() != LOWER ||
2855 array->Upper() != UPPER)
2856 {
04232180 2857 std::cout<<"6.d: Failed.."<<std::endl;
7fd59977 2858 return 6;
2859 }
2860 for (i = LOWER; i <= UPPER; i++)
2861 {
2862 if (array->Value(i) != i)
2863 {
04232180 2864 std::cout<<"6.d: Failed.."<<std::endl;
7fd59977 2865 return 6;
2866 }
2867 }
04232180 2868 std::cout<<"6: OK"<<std::endl;
7fd59977 2869
2870 //! 7. Re-set the array
2871 doc->OpenCommand();
2872 array = TDataStd_RealArray::Set(label1, LOWER + 1, UPPER + 1);
2873 if (array->Lower() != LOWER + 1 && array->Upper() != UPPER + 1)
2874 {
04232180 2875 std::cout<<"7: Failed.."<<std::endl;
7fd59977 2876 return 7;
2877 }
2878 for (i = LOWER + 1; i <= UPPER + 1; i++)
2879 array->SetValue(i, i);
2880 for (i = LOWER + 1; i <= UPPER + 1; i++)
2881 {
2882 if (array->Value(i) != i)
2883 {
04232180 2884 std::cout<<"7: Failed.."<<std::endl;
7fd59977 2885 return 7;
2886 }
2887 }
04232180 2888 std::cout<<"7: OK"<<std::endl;
7fd59977 2889 doc->CommitCommand();
2890
2891 //! 8.Test of speed: set LOWER and UPPER equal to great integer number and
2892 //! measure the time spent by this test.
2893 //! Good luck!
2894
2895 return 0;
2896}
2897
2898static Standard_Integer OCC7639 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
2899{
2900 Standard_Boolean IsEvenArgc = Standard_True;
2901 if (argc % 2 == 0) {
2902 IsEvenArgc = Standard_True;
2903 } else {
2904 IsEvenArgc = Standard_False;
2905 }
2906
2907 if (argc < 3 || IsEvenArgc)
2908 {
586db386 2909 di << "Usage : " << argv[0] << " index1 value1 ... [indexN valueN]\n";
7fd59977 2910 return 1;
2911 }
2912
2913 Standard_Integer i, aValue, aPosition;
2914 NCollection_Vector<int> vec;
2915 for (i = 0; i < argc - 1; i++) {
2916 i++;
91322f44 2917 aValue = Draw::Atoi(argv[i]);
2918 aPosition = Draw::Atoi(argv[i+1]);
7fd59977 2919 vec.SetValue(aValue, aPosition);
2920 }
2921 NCollection_Vector<int>::Iterator it(vec);
2922 Standard_Integer j;
2923 for (j = 0; it.More(); it.Next(), j++) {
2924 //di << it.Value() << "\n";
2925 di << j << " " << it.Value() << "\n";
2926 }
2927
2928 return 0;
2929}
2930
2931static Standard_Integer OCC8797 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
2932{
2933 if (argc != 1) {
2934 di << "Usage : " << argv[0] << "\n";
2935 return 1;
2936 }
2937
2938 gp_Pnt point(0.0,0.0,0.0);
2939
2940 TColgp_Array1OfPnt poles(0,6);
2941 poles(0)=point;
2942
2943 point.SetCoord(1.0,1.0,0.0);
2944 poles(1)=point;
2945
2946 point.SetCoord(2.0,1.0,0.0);
2947 poles(2)=point;
2948
2949 point.SetCoord(3.0,0.0,0.0);
2950 poles(3)=point;
2951
2952 point.SetCoord(4.0,1.0,0.0);
2953 poles(4)=point;
2954
2955 point.SetCoord(5.0,1.0,0.0);
2956 poles(5)=point;
2957
2958 point.SetCoord(6.0,0.0,0.0);
2959 poles(6)=point;
2960
2961 TColStd_Array1OfReal knots(0,2);
2962 knots(0)=0.0;
2963 knots(1)=0.5;
2964 knots(2)=1.0;
2965
2966 TColStd_Array1OfInteger multi(0,2);
2967 multi(0)=4;
2968 multi(1)=3;
2969 multi(2)=4;
2970
2971 Handle(Geom_BSplineCurve) spline = new Geom_BSplineCurve(poles,knots,multi,3);
2972
2973 //length!! 1.
2974 Standard_Real l_abcissa,l_gprop;
2975 GeomAdaptor_Curve adaptor_spline(spline);
2976 GCPnts_AbscissaPoint temp;
2977 l_abcissa=temp.Length(adaptor_spline);
04232180 2978 std::cout<<"Length Spline(abcissa_Pnt): "<<l_abcissa<<std::endl;
7fd59977 2979
2980 //length!! 2.
2981 TopoDS_Edge edge = BRepBuilderAPI_MakeEdge (spline);
2982 GProp_GProps prop;
2983 BRepGProp::LinearProperties(edge,prop);
2984 l_gprop=prop.Mass();
04232180 2985 std::cout<<"Length Spline(GProp_GProps): "<<l_gprop<<std::endl;
7fd59977 2986
04232180 2987 std::cout<<"Difference (abcissa_Pnt<->GProp_GProps): "<<l_gprop-l_abcissa<<std::endl;
7fd59977 2988
2989 return 0;
2990}
2991
2992static Standard_Integer OCC7068 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
2993{
2994 if (argc != 1)
2995 {
2996 di << "Usage : " << argv[0] << "\n";
2997 return 1;
2998 }
2999
3000 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
3001 if(AISContext.IsNull())
3002 {
3003 di << "use 'vinit' command before " << argv[0] << "\n";
3004 return 1;
3005 }
3006
3007 // ObjectsInside
3008 AIS_ListOfInteractive ListOfIO_1;
3009 AISContext->ObjectsInside(ListOfIO_1);
3010 di<< "ObjectsInside = " << ListOfIO_1.Extent() <<"\n";
3011 if (!ListOfIO_1.IsEmpty() ) {
3012 AIS_ListIteratorOfListOfInteractive iter;
3013 for (iter.Initialize(ListOfIO_1); iter.More() ; iter.Next() ) {
3014 Handle(AIS_InteractiveObject) aIO=iter.Value();
3015 di<< GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
3016 }
3017 }
3018
7fd59977 3019 return 0;
3020}
3021
3022static Standard_Integer OCC11457 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
3023{
3024 if ((argc < 9) || (((argc-3) % 3) != 0))
3025 {
3026 di << "Usage : " << argv[0] << "polygon lastedge x1 y1 z1 x2 y2 z2 ...\n";
3027 return 1;
3028 }
3029 Standard_Integer i, j, np = (argc-3) / 3;
3030 BRepBuilderAPI_MakePolygon W;
3031 j = 3;
3032 for (i = 1; i <= np; i ++) {
91322f44 3033 W.Add(gp_Pnt(Draw::Atof(argv[j]),Draw::Atof(argv[j+1]),Draw::Atof(argv[j+2])));
7fd59977 3034 j += 3;
3035 }
3036 W.Close();
3037 DBRep::Set(argv[1],W.Wire());
3038 DBRep::Set(argv[2],W.Edge());
3039 return 0;
3040}
3041
3042static Standard_Integer OCC13963 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
3043{
3044 if (argc < 5) {
3045 di << "Usage : " << argv[0] << " ratio origin_x origin_y origin_z\n";
3046 return 1;
3047 }
3048 gp_Ax2 aPln (gp_Pnt(0.,0.,0.),
3049 gp_Dir(1., -1., 0.));
3050 gp_GTrsf aTrf;
91322f44 3051 aTrf.SetAffinity (aPln, Draw::Atof(argv[4]));
3052 gp_XYZ aOrigin (Draw::Atof(argv[1]),Draw::Atof(argv[2]),Draw::Atof(argv[3]));
7fd59977 3053 gp_XYZ aResult (aOrigin);
3054 aTrf.Transforms(aResult);
3055 char sbf[512];
91322f44 3056 Sprintf(sbf, "( %8.3f %8.3f %8.3f ) => ( %8.3f %8.3f %8.3f )\n",
7fd59977 3057 aOrigin.X(), aOrigin.Y(), aOrigin.Z(),
3058 aResult.X(), aResult.Y(), aResult.Z());
3059 di<<sbf;
3060 return 0;
3061}
3062
3063Standard_Integer OCC14376(Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
3064{
3065 if (argc < 2) {
3066 di << "Usage : " << argv[0] << " shape [deflection]\n";
3067 return 1;
3068 }
3069
3070 TopoDS_Shape aShape = DBRep::Get(argv[1]);
3071
3072 if (aShape.IsNull()) {
3073 di<<" Null shape is not allowed";
3074 return 1;
3075 }
3076
3077 Standard_Real aDeflection = 0.45110277533;
3078 if (argc > 2) {
91322f44 3079 aDeflection = Draw::Atof(argv[2]);
7fd59977 3080 }
3081 di<<"deflection="<< aDeflection << "\n";
3082
14434f3e 3083 BRepMesh_IncrementalMesh aIMesh(aShape, aDeflection, Standard_False, M_PI / 9.);
7fd59977 3084 TopLoc_Location aLocation;
3085 Handle(Poly_Triangulation) aTriang = BRep_Tool::Triangulation(TopoDS::Face(aShape), aLocation);
3086
3087 if(aTriang.IsNull()) {
3088 di << argv[0] << " : Faulty\n" ;
3089 } else {
3090 di << argv[0] << " : OK\n" ;
3091 di<<"NbNodes="<< aTriang->NbNodes()<< "\n";
3092 di<<"NbTriangles="<< aTriang->NbTriangles()<< "\n";
3093 }
3094 return 0;
3095}
3096
3097static Standard_Integer OCC15489 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
3098{
3099 if (argc != 4) {
3100 di << "Usage : " << argv[0] << " A B C\n";
3101 return 1;
3102 }
3103 try
3104 {
91322f44 3105 gp_Lin2d aLin2d (Draw::Atof(argv[1]),Draw::Atof(argv[2]),Draw::Atof(argv[3]));
7fd59977 3106 gp_Pnt2d anOrigin = aLin2d.Location();
3107 di << "X_0 = " << anOrigin.X() << " Y_0 = " << anOrigin.Y() << "\n" ;
3108 }
a738b534 3109 catch(Standard_ConstructionError const&)
7fd59977 3110 {
3111 di << argv[0] << " Exception: Sqrt(A*A + B*B) <= Resolution from gp\n";
3112 }
3113 return 0;
3114}
3115
3116static Standard_Integer OCC15755 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
3117{
3118 if (argc != 3) {
3119 di << "Usage : " << argv[0] << " file shape\n";
3120 return 1;
3121 }
3122
3123 IGESControl_Reader aReader;
3124 aReader.ReadFile(argv[1]);
3125 aReader.SetReadVisible(Standard_True);
3126 aReader.TransferRoots();
3127
3128 Handle(IGESData_IGESModel) model = aReader.IGESModel();
3129 if (model.IsNull()) {
3130 di << "model.IsNull()\n";
3131 return 1;
3132 }
3133 Standard_Integer nb = model->NbEntities();
3134 for (Standard_Integer i = 1; i <= nb; i ++) {
3135 Handle(IGESData_IGESEntity) ent = model->Entity(i);
3136 Handle(TCollection_HAsciiString) name;
3137 name = ent->NameValue();
3138 Standard_CString aStr = name->ToCString();
3139 di << "NameValue = " << aStr << "\n";
3140 }
3141
3142 TopoDS_Shape shape = aReader.OneShape();
3143 DBRep::Set(argv[2],shape);
3144 return 0;
3145}
3146
3147// For OCC16782 testing
3148#include <AppStd_Application.hxx>
3149#include <TDF_Tool.hxx>
3150#include <TColStd_HArray1OfInteger.hxx>
3151// Iterators
3152#include <TColStd_ListIteratorOfListOfInteger.hxx>
3153#include <TColStd_ListIteratorOfListOfReal.hxx>
3154#include <TDataStd_ListIteratorOfListOfExtendedString.hxx>
3155#include <TDataStd_ListIteratorOfListOfByte.hxx>
3156#include <TDF_ListIteratorOfLabelList.hxx>
3157// Attributes
3158#include <TDataStd_Tick.hxx>
3159#include <TDataStd_IntegerList.hxx>
3160#include <TDataStd_RealList.hxx>
3161#include <TDataStd_ExtStringList.hxx>
3162#include <TDataStd_BooleanList.hxx>
3163#include <TDataStd_ReferenceList.hxx>
3164#include <TDataStd_BooleanArray.hxx>
3165#include <TDataStd_ReferenceArray.hxx>
3166#include <TDataStd_ByteArray.hxx>
3167#include <TDataStd_NamedData.hxx>
3168#include <TDF_Reference.hxx>
3169//
3170Handle(AppStd_Application) app;
3171int TestSetGet(const Handle(TDocStd_Document)& doc)
3172{
3173 // TDataStd_Tick:
3174 // Set
3175 TDataStd_Tick::Set(doc->Main());
3176 // Get
3177 Handle(TDataStd_Tick) tick;
3178 if (!doc->Main().FindAttribute(TDataStd_Tick::GetID(), tick))
3179 return 1;
3180 // Forget
3181 doc->Main().ForgetAttribute(TDataStd_Tick::GetID());
3182 if (doc->Main().IsAttribute(TDataStd_Tick::GetID()))
3183 return 2;
3184 doc->Main().ResumeAttribute(tick);
3185 if (!doc->Main().IsAttribute(TDataStd_Tick::GetID()))
3186 return 3;
3187 // Forget
3188 doc->Main().ForgetAttribute(TDataStd_Tick::GetID());
3189 if (doc->Main().IsAttribute(TDataStd_Tick::GetID()))
3190 return 2;
3191
3192 // TDataStd_IntegerList:
3193 // Set
3194 Handle(TDataStd_IntegerList) setintlist = TDataStd_IntegerList::Set(doc->Main());
3195 setintlist->Append(2);
3196 setintlist->Prepend(1);
3197 setintlist->InsertAfter(3, 2);
3198 setintlist->InsertBefore(0, 1);
3199 setintlist->Append(200);
3200 setintlist->Remove(0);
3201 setintlist->Remove(200);
3202 // Get
3203 Handle(TDataStd_IntegerList) getintlist;
3204 if (!doc->Main().FindAttribute(TDataStd_IntegerList::GetID(), getintlist))
3205 return 1;
3206 if (getintlist->First() != 1)
3207 return 2;
3208 if (getintlist->Last() != 3)
3209 return 3;
3210 const TColStd_ListOfInteger& intlist = getintlist->List();
3211 TColStd_ListIteratorOfListOfInteger itr_intlist(intlist);
3212 for (; itr_intlist.More(); itr_intlist.Next())
3213 {
3214 if (itr_intlist.Value() != 1 &&
3215 itr_intlist.Value() != 2 &&
3216 itr_intlist.Value() != 3)
3217 {
3218 return 4;
3219 }
3220 }
3221 getintlist->Clear();
3222
3223 // TDataStd_RealList:
3224 // Set
3225 Handle(TDataStd_RealList) setdbllist = TDataStd_RealList::Set(doc->Main());
3226 setdbllist->Append(2.5);
3227 setdbllist->Prepend(1.5);
3228 setdbllist->InsertAfter(3.5, 2.5);
3229 setdbllist->InsertBefore(0.5, 1.5);
3230 setdbllist->Append(200.5);
3231 setdbllist->Remove(0.5);
3232 setdbllist->Remove(200.5);
3233 // Get
3234 Handle(TDataStd_RealList) getdbllist;
3235 if (!doc->Main().FindAttribute(TDataStd_RealList::GetID(), getdbllist))
3236 return 1;
3237 if (getdbllist->First() != 1.5)
3238 return 2;
3239 if (getdbllist->Last() != 3.5)
3240 return 3;
3241 const TColStd_ListOfReal& dbllist = getdbllist->List();
3242 TColStd_ListIteratorOfListOfReal itr_dbllist(dbllist);
3243 for (; itr_dbllist.More(); itr_dbllist.Next())
3244 {
3245 if (itr_dbllist.Value() != 1.5 &&
3246 itr_dbllist.Value() != 2.5 &&
3247 itr_dbllist.Value() != 3.5)
3248 {
3249 return 4;
3250 }
3251 }
3252 getdbllist->Clear();
3253
3254 // TDataStd_ExtStringList:
3255 // Set
3256 Handle(TDataStd_ExtStringList) setstrlist = TDataStd_ExtStringList::Set(doc->Main());
3257 setstrlist->Append("Hello");
3258 setstrlist->Prepend("Guten Tag");
3259 setstrlist->InsertAfter("Bonjour", "Guten Tag");
3260 setstrlist->InsertBefore("Bonsoir", "Hello");
3261 setstrlist->Append("Good bye");
3262 setstrlist->Remove("Bonsoir");
3263 setstrlist->Remove("Good bye");
3264 // Get
3265 Handle(TDataStd_ExtStringList) getstrlist;
3266 if (!doc->Main().FindAttribute(TDataStd_ExtStringList::GetID(), getstrlist))
3267 return 1;
3268 if (getstrlist->First() != "Guten Tag")
3269 return 2;
3270 if (getstrlist->Last() != "Hello")
3271 return 3;
3272 const TDataStd_ListOfExtendedString& strlist = getstrlist->List();
3273 TDataStd_ListIteratorOfListOfExtendedString itr_strlist(strlist);
3274 for (; itr_strlist.More(); itr_strlist.Next())
3275 {
3276 if (itr_strlist.Value() != "Guten Tag" &&
3277 itr_strlist.Value() != "Bonjour" &&
3278 itr_strlist.Value() != "Hello")
3279 {
3280 return 4;
3281 }
3282 }
3283 getstrlist->Clear();
3284
3285 // TDataStd_BooleanList:
3286 // Set
3287 Handle(TDataStd_BooleanList) setboollist = TDataStd_BooleanList::Set(doc->Main());
3288 setboollist->Append(Standard_True);
3289 setboollist->Prepend(Standard_False);
3290 // Get
3291 Handle(TDataStd_BooleanList) getboollist;
3292 if (!doc->Main().FindAttribute(TDataStd_BooleanList::GetID(), getboollist))
3293 return 1;
3294 if (getboollist->First() != Standard_False)
3295 return 2;
3296 if (getboollist->Last() != Standard_True)
3297 return 3;
3298 const TDataStd_ListOfByte& boollist = getboollist->List();
dde68833 3299 for (TDataStd_ListIteratorOfListOfByte itr_boollist(boollist); itr_boollist.More(); itr_boollist.Next())
7fd59977 3300 {
dde68833 3301 if (itr_boollist.Value() != 1
3302 && itr_boollist.Value() != 0)
7fd59977 3303 {
3304 return 4;
3305 }
3306 }
3307 getboollist->Clear();
3308
3309 // TDataStd_ReferenceList:
3310 TDF_Label L1 = doc->Main().FindChild(100);
3311 TDF_Label L2 = doc->Main().FindChild(101);
3312 TDF_Label L3 = doc->Main().FindChild(102);
3313 TDF_Label L4 = doc->Main().FindChild(103);
3314 TDF_Label L5 = doc->Main().FindChild(104);
3315 // Set
3316 Handle(TDataStd_ReferenceList) setreflist = TDataStd_ReferenceList::Set(doc->Main());
3317 setreflist->Append(L1);
3318 setreflist->Prepend(L2);
3319 setreflist->InsertAfter(L3, L2);
3320 setreflist->InsertBefore(L4, L1);
3321 setreflist->Append(L5);
3322 setreflist->Remove(L4);
3323 setreflist->Remove(L5);
3324 // Get
3325 Handle(TDataStd_ReferenceList) getreflist;
3326 if (!doc->Main().FindAttribute(TDataStd_ReferenceList::GetID(), getreflist))
3327 return 1;
3328 if (getreflist->First() != L2)
3329 return 2;
3330 if (getreflist->Last() != L1)
3331 return 3;
3332 const TDF_LabelList& reflist = getreflist->List();
3333 TDF_ListIteratorOfLabelList itr_reflist(reflist);
3334 for (; itr_reflist.More(); itr_reflist.Next())
3335 {
3336 if (itr_reflist.Value() != L1 &&
3337 itr_reflist.Value() != L2 &&
3338 itr_reflist.Value() != L3)
3339 {
3340 return 4;
3341 }
3342 }
3343 getreflist->Clear();
3344
3345 // TDataStd_BooleanArray:
3346 // Set
3347 Handle(TDataStd_BooleanArray) setboolarr = TDataStd_BooleanArray::Set(doc->Main(), 12, 16);
3348 setboolarr->SetValue(12, Standard_True);
3349 setboolarr->SetValue(13, Standard_False);
3350 setboolarr->SetValue(14, Standard_False);
3351 setboolarr->SetValue(15, Standard_False);
3352 setboolarr->SetValue(16, Standard_True);
3353 setboolarr->SetValue(14, Standard_True);
3354 // Get
3355 Handle(TDataStd_BooleanArray) getboolarr;
3356 if (!doc->Main().FindAttribute(TDataStd_BooleanArray::GetID(), getboolarr))
3357 return 1;
3358 if (getboolarr->Value(12) != Standard_True)
3359 return 2;
3360 if (getboolarr->Value(13) != Standard_False)
3361 return 2;
3362 if (getboolarr->Value(14) != Standard_True)
3363 return 2;
3364 if (getboolarr->Value(15) != Standard_False)
3365 return 2;
3366 if (getboolarr->Value(16) != Standard_True)
3367 return 2;
3368
3369 // TDataStd_ReferenceArray:
3370 // Set
3371 Handle(TDataStd_ReferenceArray) setrefarr = TDataStd_ReferenceArray::Set(doc->Main(), 0, 4);
3372 setrefarr->SetValue(0, L1);
3373 setrefarr->SetValue(1, L2);
3374 setrefarr->SetValue(2, L3);
3375 setrefarr->SetValue(3, L4);
3376 setrefarr->SetValue(4, L5);
3377 // Get
3378 Handle(TDataStd_ReferenceArray) getrefarr;
3379 if (!doc->Main().FindAttribute(TDataStd_ReferenceArray::GetID(), getrefarr))
3380 return 1;
3381 if (getrefarr->Value(0) != L1)
3382 return 2;
3383 if (getrefarr->Value(1) != L2)
3384 return 2;
3385 if (getrefarr->Value(2) != L3)
3386 return 2;
3387 if (getrefarr->Value(3) != L4)
3388 return 2;
3389 if (getrefarr->Value(4) != L5)
3390 return 2;
3391
3392 // TDataStd_ByteArray:
3393 // Set
3394 Handle(TDataStd_ByteArray) setbytearr = TDataStd_ByteArray::Set(doc->Main(), 12, 16);
3395 setbytearr->SetValue(12, 0);
3396 setbytearr->SetValue(13, 1);
3397 setbytearr->SetValue(14, 2);
3398 setbytearr->SetValue(15, 3);
3399 setbytearr->SetValue(16, 255);
3400 // Get
3401 Handle(TDataStd_ByteArray) getbytearr;
3402 if (!doc->Main().FindAttribute(TDataStd_ByteArray::GetID(), getbytearr))
3403 return 1;
3404 if (getbytearr->Value(12) != 0)
3405 return 2;
3406 if (getbytearr->Value(13) != 1)
3407 return 2;
3408 if (getbytearr->Value(14) != 2)
3409 return 2;
3410 if (getbytearr->Value(15) != 3)
3411 return 2;
3412 if (getbytearr->Value(16) != 255)
3413 return 2;
3414
3415 // TDataStd_NamedData:
3416 // Set:
3417 Handle(TDataStd_NamedData) setnd = TDataStd_NamedData::Set(doc->Main());
3418 setnd->SetInteger("Integer1", 1);
3419 setnd->SetInteger("Integer2", 2);
3420 setnd->SetInteger("Integer3", 8);
3421 setnd->SetInteger("Integer3", 3);
3422 // Get:
3423 Handle(TDataStd_NamedData) getnd;
3424 if (!doc->Main().FindAttribute(TDataStd_NamedData::GetID(), getnd))
3425 return 1;
3426 if (!getnd->HasIntegers())
3427 return 2;
3428 if (!getnd->HasInteger("Integer1"))
3429 return 3;
3430 if (getnd->GetInteger("Integer2") != 2)
3431 return 4;
3432 if (getnd->GetInteger("Integer3") != 3)
3433 return 4;
3434
3435 return 0;
3436}
3437
3438int TestUndoRedo(const Handle(TDocStd_Document)& doc)
3439{
3440 // TDataStd_Tick:
3441 doc->OpenCommand();
3442 Handle(TDataStd_Tick) tick = TDataStd_Tick::Set(doc->Main());
3443 doc->CommitCommand();
3444 if (!doc->Main().IsAttribute(TDataStd_Tick::GetID()))
3445 return 1;
3446 doc->Undo();
3447 if (doc->Main().IsAttribute(TDataStd_Tick::GetID()))
3448 return 2;
3449 doc->Redo();
3450 if (!doc->Main().IsAttribute(TDataStd_Tick::GetID()))
3451 return 3;
3452
3453 // TDataStd_IntegerList:
3454 doc->OpenCommand();
3455 Handle(TDataStd_IntegerList) intlist = TDataStd_IntegerList::Set(doc->Main());
3456 intlist->Append(2);
3457 intlist->Prepend(1);
3458 intlist->InsertBefore(0, 1);
3459 intlist->InsertAfter(3, 2);
3460 doc->CommitCommand();
3461 if (!doc->Main().IsAttribute(TDataStd_IntegerList::GetID()))
3462 return 1;
3463 doc->Undo();
3464 if (!intlist->IsEmpty())
3465 return 2;
3466 doc->Redo();
3467 if (!intlist->Extent())
3468 return 3;
3469 if (intlist->First() != 0)
3470 return 4;
3471 if (intlist->Last() != 3)
3472 return 5;
3473 intlist->Clear();
3474
3475 // TDataStd_RealList:
3476 doc->OpenCommand();
3477 Handle(TDataStd_RealList) dbllist = TDataStd_RealList::Set(doc->Main());
3478 dbllist->Append(2.5);
3479 dbllist->Prepend(1.5);
3480 dbllist->InsertBefore(0.5, 1.5);
3481 dbllist->InsertAfter(3.5, 2.5);
3482 doc->CommitCommand();
3483 if (!doc->Main().IsAttribute(TDataStd_RealList::GetID()))
3484 return 1;
3485 doc->Undo();
3486 if (!dbllist->IsEmpty())
3487 return 2;
3488 doc->Redo();
3489 if (!dbllist->Extent())
3490 return 3;
3491 if (dbllist->First() != 0.5)
3492 return 4;
3493 if (dbllist->Last() != 3.5)
3494 return 5;
3495 dbllist->Clear();
3496
3497 // TDataStd_ExtStringList:
3498 doc->OpenCommand();
3499 Handle(TDataStd_ExtStringList) strlist = TDataStd_ExtStringList::Set(doc->Main());
3500 strlist->Append("Hello");
3501 strlist->Prepend("Guten Tag");
3502 strlist->InsertAfter("Bonjour", "Guten Tag");
3503 strlist->InsertBefore("Bonsoir", "Hello");
3504 doc->CommitCommand();
3505 if (!doc->Main().IsAttribute(TDataStd_ExtStringList::GetID()))
3506 return 1;
3507 doc->Undo();
3508 if (!strlist->IsEmpty())
3509 return 2;
3510 doc->Redo();
3511 if (!strlist->Extent())
3512 return 3;
3513 if (strlist->First() != "Guten Tag")
3514 return 4;
3515 if (strlist->Last() != "Hello")
3516 return 5;
3517 strlist->Clear();
3518
3519 // TDataStd_BooleanList:
3520 doc->OpenCommand();
3521 Handle(TDataStd_BooleanList) boollist = TDataStd_BooleanList::Set(doc->Main());
3522 boollist->Append(Standard_True);
3523 boollist->Prepend(Standard_False);
3524 doc->CommitCommand();
3525 if (!doc->Main().IsAttribute(TDataStd_BooleanList::GetID()))
3526 return 1;
3527 doc->Undo();
3528 if (!boollist->IsEmpty())
3529 return 2;
3530 doc->Redo();
3531 if (!boollist->Extent())
3532 return 3;
3533 if (boollist->First() != Standard_False)
3534 return 4;
3535 if (boollist->Last() != Standard_True)
3536 return 5;
3537 boollist->Clear();
3538
3539 // TDataStd_ReferenceList:
3540 TDF_Label L1 = doc->Main().FindChild(100);
3541 TDF_Label L2 = doc->Main().FindChild(101);
3542 TDF_Label L3 = doc->Main().FindChild(102);
3543 TDF_Label L4 = doc->Main().FindChild(103);
3544 doc->OpenCommand();
3545 Handle(TDataStd_ReferenceList) reflist = TDataStd_ReferenceList::Set(doc->Main());
3546 reflist->Append(L1);
3547 reflist->Prepend(L2);
3548 reflist->InsertBefore(L3, L1);
3549 reflist->InsertAfter(L4, L2);
3550 doc->CommitCommand();
3551 if (!doc->Main().IsAttribute(TDataStd_ReferenceList::GetID()))
3552 return 1;
3553 doc->Undo();
3554 if (!reflist->IsEmpty())
3555 return 2;
3556 doc->Redo();
3557 if (!reflist->Extent())
3558 return 3;
3559 if (reflist->First() != L2)
3560 return 4;
3561 if (reflist->Last() != L1)
3562 return 5;
3563 reflist->Clear();
3564
3565 // TDataStd_BooleanArray:
3566 doc->OpenCommand();
3567 Handle(TDataStd_BooleanArray) boolarr = TDataStd_BooleanArray::Set(doc->Main(), 23, 25);
3568 boolarr->SetValue(23, Standard_True);
3569 boolarr->SetValue(25, Standard_True);
3570 doc->CommitCommand();
3571 doc->OpenCommand();
3572 boolarr = TDataStd_BooleanArray::Set(doc->Main(), 230, 250);
3573 boolarr->SetValue(230, Standard_True);
3574 boolarr->SetValue(250, Standard_True);
3575 doc->CommitCommand();