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