0030697: Draw Harness - Draw_Printer should not be set 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>
7fd59977 94
d538d7a2 95#if ! defined(_WIN32)
7fd59977 96extern ViewerTest_DoubleMapOfInteractiveAndName& GetMapOfAIS();
97#else
98Standard_EXPORT ViewerTest_DoubleMapOfInteractiveAndName& GetMapOfAIS();
99#endif
100
101static Standard_Integer OCC128 (Draw_Interpretor& di, Standard_Integer /*argc*/, const char ** argv)
102{
103 Handle(AIS_InteractiveContext) myAISContext = ViewerTest::GetAISContext();
104 if(myAISContext.IsNull()) {
105 di << "use 'vinit' command before " << argv[0] ;
106 return 1;
107 }
108
109 Handle(Geom_Axis2Placement) aTrihedronAxis = new Geom_Axis2Placement(gp::XOY());
110
111 gp_Trsf trsf1;
112 trsf1.SetTranslation(gp_Vec(100, 100, 0));
113 aTrihedronAxis->Transform(trsf1);
114 Handle(AIS_Trihedron) myTrihedron = new AIS_Trihedron(aTrihedronAxis);
115 myTrihedron->SetColor(Quantity_NOC_LIGHTSTEELBLUE4);
116 myTrihedron->SetSize(100);
117 myAISContext->Display(myTrihedron, Standard_True);
118
119// TopoDS_Shape shape1 = (TopoDS_Shape) BRepPrimAPI_MakeBox(50,50,50);
120 TopoDS_Shape shape1 = BRepPrimAPI_MakeBox(50,50,50).Shape();
121 Handle(AIS_Shape) AS = new AIS_Shape(shape1);
122 AS->SetDisplayMode(1);
123 Graphic3d_MaterialAspect mat(Graphic3d_NOM_PLASTIC);
124 AS->SetMaterial(mat);
125 AS->SetColor(Quantity_NOC_RED);
0577ae8c 126 myAISContext->Display (AS, Standard_False);
7fd59977 127
128 gp_Trsf TouchTrsf;
129 TouchTrsf.SetTranslation(gp_Vec(20, 20, 0));
130
131 myAISContext->ResetLocation(AS);
132 myAISContext->SetLocation(AS , TouchTrsf) ;
133 myAISContext->Redisplay(AS, Standard_True);
134
135 return 0;
136}
137
138 // Remove as bad version of QAAddOrRemoveSelected from QADraw
139//static Standard_Integer OCC129 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
140//{
141// if( argc != 3) {
142// di<<"Usage : " << argv[0] << " shape islocal\n";
143// return 1;
144// }
145// //get AIS_Shape:
146// Handle(AIS_InteractiveContext) anAISCtx = ViewerTest::GetAISContext();
147//
148// // ViewerTest_DoubleMapOfInteractiveAndName& aMap =
149// // ViewerTest::GetDataMapOfAIS ();
150// ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
151//
152// TCollection_AsciiString aName(argv[1]);
153// Handle(AIS_InteractiveObject) AISObj;
154//
155// if(aMap.IsBound2(aName)) {
156// AISObj = aMap.Find2(aName);
157// if(AISObj.IsNull()){
158// di<<"No interactive object \n";
159// return 1;
160// }
161//
162// Standard_Integer aNum = -1;
163//
91322f44 164// if(Draw::Atoi(argv[2])) {
7fd59977 165// aNum = anAISCtx->OpenLocalContext();
166// }
167//
168// if(anAISCtx->HasOpenedContext()){
169// anAISCtx->InitSelected();
170// anAISCtx->AddOrRemoveSelected(AISObj);
171// }
172// else {
173// anAISCtx->InitCurrent();
174// anAISCtx->AddOrRemoveCurrentObject(AISObj);
175// }
176//
177// if(aNum >= 0) {
178// // anAISCtx->CloseLocalContext(aNum);
179// }
180//
181// return 0;
182// }
183// //select this shape:
184// else {
185// di<<"Use 'vdisplay' before";
186// return 1;
187// }
188//}
189
190static Standard_Integer OCC136 (Draw_Interpretor& di, Standard_Integer argc, const char ** /*argv*/)
191{
192 if(argc > 1){
193 di<<"Usage: OCC136\n";
194 return 1;
195 }
196
197 //create some primitives:
198 // Two basic points:
199 Standard_Real Size=100;
200 gp_Pnt P0(0,0,0), P1(Size,Size,Size);
201 //box
202 TopoDS_Solid aBox = BRepPrimAPI_MakeBox(P0,P1);
203 //sphere
204 TopoDS_Solid aSphere = BRepPrimAPI_MakeSphere (Size*0.5);
205 //cone
206 gp_Ax2 anAx2(P1, gp_Dir(1,1,1));
207 TopoDS_Solid aCone = BRepPrimAPI_MakeCone(anAx2, Size*0.7, Size*0.3, Size);
208 //cylinder
209 anAx2.SetLocation(gp_Pnt(Size,0,0));
210 anAx2.SetDirection(gp_Dir(-1,-1,1));
211 TopoDS_Solid aCyl = BRepPrimAPI_MakeCylinder(anAx2, Size*0.5, Size);
212
213 Handle(AIS_InteractiveContext) anAISCtx = ViewerTest::GetAISContext();
214 if(anAISCtx.IsNull()){
215 di<<"Null interactive context. Use 'vinit' at first.\n";
216 return 1;
217 }
218
0577ae8c 219 anAISCtx->EraseAll (Standard_False);
7fd59977 220
221 //load primitives to context
c3282ec1 222 Handle(AIS_InteractiveObject) aSh1 = new AIS_Shape(aBox);
0577ae8c 223 anAISCtx->Display (aSh1, Standard_False);
7fd59977 224
c3282ec1 225 Handle(AIS_InteractiveObject) aSh2 = new AIS_Shape(aSphere);
0577ae8c 226 anAISCtx->Display (aSh2, Standard_False);
7fd59977 227
c3282ec1 228 Handle(AIS_InteractiveObject) aSh3 = new AIS_Shape(aCone);
0577ae8c 229 anAISCtx->Display (aSh3, Standard_False);
7fd59977 230
c3282ec1 231 Handle(AIS_InteractiveObject) aSh4 = new AIS_Shape(aCyl);
0577ae8c 232 anAISCtx->Display (aSh4, Standard_False);
7fd59977 233
234 //set selected
c3282ec1 235 anAISCtx->InitSelected();
0577ae8c 236 anAISCtx->AddOrRemoveSelected (aSh1, Standard_False);
237 anAISCtx->AddOrRemoveSelected (aSh2, Standard_False);
238 anAISCtx->AddOrRemoveSelected (aSh3, Standard_False);
239 anAISCtx->AddOrRemoveSelected (aSh4, Standard_False);
7fd59977 240
241 //remove all this objects from context
2195ab96 242 anAISCtx->Remove (aSh1, Standard_False);
243 anAISCtx->Remove (aSh2, Standard_False);
244 anAISCtx->Remove (aSh3, Standard_False);
245 anAISCtx->Remove (aSh4, Standard_False);
0577ae8c 246
247 anAISCtx->UpdateCurrentViewer();
7fd59977 248 return 0;
249}
250
251static int BUC60610(Draw_Interpretor& di, Standard_Integer argc, const char ** argv) {
252 if(argc < 2){
253 printf("Usage: %s iges_input [name]\n",argv[0]);
254 return(1);
255 }
1d47d8d0 256 Standard_Character *Ch = NULL;
7fd59977 257
258 if(argc > 2) {
259 Ch = new Standard_Character[strlen(argv[2])+3];
260 }
261 IGESToBRep_Reader IR;
262 IR.LoadFile (argv[1]);
263 IR.Clear();
264 IR.TransferRoots();
265 TopoDS_Shape aTopShape = IR.OneShape();
266 TopExp_Explorer ex(aTopShape, TopAbs_EDGE);
267 Standard_Integer i=0;
268 for( ; ex.More(); ex.Next()){
269 const TopoDS_Edge &E = TopoDS::Edge(ex.Current());
270 BRepAdaptor_Curve aCurve(E);
271 GCPnts_UniformDeflection plin(aCurve, 0.1);
272 di << "Num points = " << plin.NbPoints() << "\n";
273 if(argc > 2) {
274 i++;
91322f44 275 Sprintf(Ch,"%s_%i",argv[2],1);
7fd59977 276 DBRep::Set(Ch,E);
277 }
278 }
279 return (1);
280}
281
7fd59977 282//====================================================
283//
284// Following code is inserted from
285// /dn03/KAS/dev/QAopt/src/QADraw/QADraw_TOPOLOGY.cxx
286// ( 75455 Apr 16 18:59)
287//
288//====================================================
289
290//OCC105
291#include <BRepTools_WireExplorer.hxx>
292#include <BRep_Tool.hxx>
293#include <GCPnts_UniformAbscissa.hxx>
294#include <TopExp.hxx>
295
296//
297// usage : OCC105 shape
298//
299// comments:
300//GCPnts_UniformAbscissa returns bad end point foe first edge. Its value is
301
302//Value Pnt = -338.556216693211 -394.465571897208 0
303//should be
304//Value Pnt = -307.47165394 -340.18073533 0
305
306static int OCC105(Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
307{
308 if (argc != 2){
309 di<<"Usage : OCC105 shape\n";
310 return 1;
311 }
312// TopoDS_Wire myTopoDSWire = TopoDS::Wire(DBRep::Get("aa.brep"));
313 TopoDS_Wire myTopoDSWire = TopoDS::Wire(DBRep::Get(argv[1]));
91322f44 314 Standard_Real l = 0.5; //Draw::Atof(argv[2]);
7fd59977 315 // Find the first vertex of the wire
316 BRepTools_WireExplorer wire_exp(myTopoDSWire);
317 TopoDS_Vertex vlast;
318 {
319 TopoDS_Vertex vw1, vw2;
320 TopExp::Vertices(myTopoDSWire,vw1,vw2);
321 TopoDS_Vertex ve1, ve2;
322 TopoDS_Edge edge = TopoDS::Edge(wire_exp.Current());
323 TopExp::Vertices(edge,ve1,ve2);
324 if (vw1.IsSame(ve1) || vw1.IsSame(ve2))
325 vlast = vw1;
326 else {
327// assert(vw2.IsSame(ve1) || vw2.IsSame(ve2));
328 vlast = vw2;
329 }
330 }
331 for ( ; wire_exp.More(); wire_exp.Next())
332 {
333 di << "\n\n New Edge \n" << "\n";
334 Standard_Real newufirst, newulast;
335 TopoDS_Edge edge = TopoDS::Edge(wire_exp.Current());
336 Standard_Real ufirst, ulast;
337 Handle(Geom_Curve) acurve;
338 TopoDS_Vertex ve1, ve2;
339 TopExp::Vertices(edge,ve1,ve2);
340 if (ve1.IsSame(vlast))
341 {
342 acurve = BRep_Tool::Curve(edge, ufirst, ulast);
343 newufirst = ufirst;
344 newulast = ulast;
345 vlast = ve2;
346 }
347 else
348 {
349// assert(ve2.IsSame(vlast));
350// assert ( wire_exp.Orientation( ) == TopAbs_REVERSED );
351 acurve = BRep_Tool::Curve( edge, ufirst, ulast );
352 newufirst = acurve->ReversedParameter( ufirst );
353 newulast = acurve->ReversedParameter( ulast );
354 acurve = acurve->Reversed( );
355 vlast = ve1;
356 }
357
358 GeomAdaptor_Curve curve;
359 GCPnts_UniformAbscissa algo;
360 curve.Load(acurve);
361 algo.Initialize( curve, l, newufirst, newulast );
362 if (!algo.IsDone())
363 di << "Not Done!!!" << "\n";
364 for (Standard_Integer Index = 1; Index<=algo.NbPoints();Index++) {
365 Standard_Real t = algo.Parameter(Index);
366 gp_Pnt pt3 = curve.Value(t);
367 di << "Parameter t = " << t << "\n";
368 di << "Value Pnt = " << pt3.X()<<" " <<pt3.Y()<<" " << pt3.Z() << "\n";
369 }
370 }
371 return 0;
372
373}
374
375#include <TColStd_SequenceOfTransient.hxx>
376#include <GeomFill_Pipe.hxx>
377static int pipe_OCC9 (Draw_Interpretor& di,
378 Standard_Integer n, const char ** a)
379{
380 if (n < 6) {
586db386 381 di << "Usage: " << a[0] << " result path cur1 cur2 radius [tolerance]\n";
7fd59977 382 return 1;
383 }
384
385 TColStd_SequenceOfTransient aCurveSeq;
386 Standard_Integer i;
387 for (i=2 ; i<=4; i++) {
388 Handle(Geom_Curve) aC = Handle(Geom_Curve)::DownCast( DrawTrSurf::Get(a[i]) );
389 if (aC.IsNull()) {
586db386 390 di << a[i] << " is not a curve\n";
7fd59977 391 return 1;
392 }
393 aCurveSeq.Append(aC);
394 }
395
396 GeomFill_Pipe aPipe(Handle(Geom_Curve)::DownCast( aCurveSeq(1) ),
397 Handle(Geom_Curve)::DownCast( aCurveSeq(2) ),
398 Handle(Geom_Curve)::DownCast( aCurveSeq(3) ),
91322f44 399 Draw::Atof (a[5]) );
7fd59977 400
401 if (n == 7) {
91322f44 402 aPipe.Perform(Draw::Atof (a[6]), Standard_True);
7fd59977 403 } else {
404 aPipe.Perform(Standard_True/*, Standard_True*/);
405 }
406
a8b52677 407 if (!aPipe.IsDone()) {
408 di << "GeomFill_Pipe cannot make a surface\n";
409 return 1;
410 }
411
7fd59977 412 Handle(Geom_Surface) aSurf = aPipe.Surface();
413
414 DrawTrSurf::Set(a[1], aSurf);
415 return 0;
416}
417
418//======================================================================
419// OCC125
420// usage : OCC125 shell
421//======================================================================
422#include <ShapeFix_Shell.hxx>
423
424Standard_Integer OCC125(Draw_Interpretor& di ,
425 Standard_Integer n,
426 const char ** a)
427{
428 if (n!=2) {
429 di<<" Use OCC125 shell";
430 return 1;
431 }
432
433 TopoDS_Shape S = DBRep::Get(a[1]);
434
435 if (S.IsNull()) {
436 di<<" Null shape is not allowed";
437 return 1;
438 }
439
440 TopAbs_ShapeEnum aT;
441 aT=S.ShapeType();
442 if (aT!=TopAbs_SHELL) {
443 di<<" Shape Type must be SHELL";
444 return 1;
445 }
446
447 const TopoDS_Shell& aShell = TopoDS::Shell(S);
448 //
449 Standard_Boolean isAccountMultiConex, bNonManifold, bResult;
450
451 isAccountMultiConex=Standard_True;
452 bNonManifold=Standard_False;
453
454 Handle (ShapeFix_Shell) aFix = new ShapeFix_Shell(aShell);
455 bResult=aFix->FixFaceOrientation(aShell, isAccountMultiConex, bNonManifold);
456
457 di<<"bResult="<<(Standard_Integer)bResult;
458
459 TopoDS_Shape aShape;
460 aShape=aFix->Shape();
461
462 TCollection_AsciiString aName(a[1]), aDef("_sh"), aRName;
463 aRName=aName;
464 aRName=aRName+aDef;
465 DBRep::Set (aRName.ToCString(), aShape);
466 di<<aRName.ToCString();
467 //
468 return 0;
469}
470
471#include <BRepLib_FindSurface.hxx>
472#include <BRepBuilderAPI_MakeFace.hxx>
473Standard_Integer OCC157(Draw_Interpretor& di,
474 Standard_Integer n,
475 const char ** a)
476//static Standard_Integer findplanarsurface(Draw_Interpretor&, Standard_Integer n, const char ** a)
477{
478 if (n<3) {
586db386 479 di << "bad number of arguments\n";
7fd59977 480 return 1;
481 }
482
483 // try to read a shape:
484 TopoDS_Shape inputShape=DBRep::Get(a[2]);
485 if (inputShape.IsNull() || inputShape.ShapeType() != TopAbs_WIRE) {
586db386 486 di << "Invalid input shape\n";
7fd59977 487 return 1;
488 }
91322f44 489 Standard_Real toler = Draw::Atof(a[3]);
7fd59977 490 TopoDS_Wire aWire = TopoDS::Wire(inputShape);
491 BRepLib_FindSurface FS(aWire, toler, Standard_True);
492 if(FS.Found()) {
586db386 493 di<<"OCC157: OK; Planar surface is found\n";
7fd59977 494 Handle(Geom_Surface) aSurf = FS.Surface();
495 BRepBuilderAPI_MakeFace aMakeFace(aSurf,aWire,Standard_True);
496 if(aMakeFace.IsDone()) {
497 TopoDS_Face aFace = aMakeFace.Face();
498 DBRep::Set(a[1],aFace);
499 }
500 }
501 else di<<"OCC157: ERROR; Planar surface is not found with toler = "<<toler <<"\n";
502 return 0;
503
504}
505
506// #include <MyCommandsCMD.h>
507#include <ShapeFix_Shape.hxx>
508#include <BRepOffset_MakeOffset.hxx>
509#include <BRepOffsetAPI_MakeOffset.hxx>
510#include <BRepOffset_Mode.hxx>
511#include <GeomAbs_JoinType.hxx>
512#include <AIS_Shape.hxx>
513
514#include <BRepTools.hxx>
515
516Standard_Integer OCC165(Draw_Interpretor& di ,
517 Standard_Integer n,
518 const char ** a)
519
520
521//=======================================================================
522
523// static int YOffset (Draw_Interpretor& di, Standard_Integer argc, const char ** argv);
524
525// void MyOffsets_Commands(Draw_Interpretor& theCommands)
526// {
527// theCommands.Add("yoffset" , "yoffset" , __FILE__, YOffset, " Offset on Z Direction");
528// }
529
530//=======================================================================
531
532// static int YOffset (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
533 {
534 if (n > 2)
535 {
586db386 536 di <<"Usage : " << a[0] << " [file]\n";
7fd59977 537 return 1;
538 }
539 di.Eval ("axo");
540
541#define _OFFSET_TELCO_
542#ifdef _OFFSET_TELCO_
543
544 Standard_CString file = a[1];
545
546 BRep_Builder aBuilder;
547 TopoDS_Shape theShape;
548 //BRepTools::Read(theShape, Standard_CString("/dn02/users_SUN/inv/3/OCC165/2d_tr_line.brep"), aBuilder);
549 BRepTools::Read(theShape, file, aBuilder);
550 DBRep::Set("shape", theShape);
551
552 TopoDS_Wire theWire = TopoDS::Wire(theShape);
553
554 Standard_Real anOffset = 1.5;
555
556#else
557
558 Standard_Real xA = 0.0, xB = 200.0, xC = 200.0, xD = 0.0,
559 yA = 0.0, yB = 0.0, yC = 200.0, yD = 200.0,
560 zA = 0.0, zB = 0.0, zC = 0.0, zD = 0.0;
561
562 BRepBuilderAPI_MakePolygon theSquare;
563 TopoDS_Vertex theA = BRepBuilderAPI_MakeVertex(gp_Pnt(xA, yA, zA));
564 theSquare.Add(theA);
565 TopoDS_Vertex theB = BRepBuilderAPI_MakeVertex(gp_Pnt(xB, yB, zB));
566 theSquare.Add(theB);
567 TopoDS_Vertex theC = BRepBuilderAPI_MakeVertex(gp_Pnt(xC, yC, zC));
568 theSquare.Add(theC);
569 TopoDS_Vertex theD = BRepBuilderAPI_MakeVertex(gp_Pnt(xD, yD, zD));
570 theSquare.Add(theD);
571
572 theSquare.Close();
573 TopoDS_Wire theWire = theSquare.Wire();
574
575 Standard_Real anOffset = 10;
576
577
578#endif /* _OFFSET_TELCO_ */
579
580
581 TopoDS_Face theFace = BRepBuilderAPI_MakeFace(theWire).Face();
582 DBRep::Set("face", theFace);
583
584
585 Standard_Real anAlt = 0.;
586 GeomAbs_JoinType theJoin = GeomAbs_Intersection;
587//GeomAbs_Intersection; //GeomAbs_Arc;
588 BRepOffsetAPI_MakeOffset aMakeOffset(theFace, theJoin);
589 aMakeOffset.AddWire(theWire);
590
591 aMakeOffset.Perform(anOffset, anAlt);
592
593 TopoDS_Shape theOffsetShapePos = aMakeOffset.Shape();
594 DBRep::Set("offset", theOffsetShapePos);
595 return 0;
596// return TCL_OK;
597}
598
599#include<BRepAlgoAPI_Cut.hxx>
7fd59977 600
601#include<BRepPrimAPI_MakeHalfSpace.hxx>
7fd59977 602#include<Geom_CartesianPoint.hxx>
603#include<AIS_Point.hxx>
604
605#include <BRepBuilderAPI_MakeEdge.hxx>
606#include <BRepBuilderAPI_MakeWire.hxx>
607#include <BRepBuilderAPI_MakeFace.hxx>
608
609static Standard_Integer OCC297 (Draw_Interpretor& di,Standard_Integer /*argc*/, const char ** argv )
610
611{
7fd59977 612 Handle(AIS_InteractiveContext) myAISContext = ViewerTest::GetAISContext();
431d0f18 613 if (myAISContext.IsNull()) {
7fd59977 614 di << "use 'vinit' command before " << argv[0] << "\n";
615 return -1;
616 }
431d0f18 617
618 gp_Pnt pt1_(250., 250., 0.);
619 gp_Pnt pt2_(-250., 250., 0.);
620 gp_Pnt pt3_(-250., -250., 0.);
621 gp_Pnt pt4_(250., -250., 0.);
622 BRepBuilderAPI_MakeEdge edg1_(pt1_, pt2_);
623 BRepBuilderAPI_MakeEdge edg2_(pt2_, pt3_);
624 BRepBuilderAPI_MakeEdge edg3_(pt3_, pt4_);
625 BRepBuilderAPI_MakeEdge edg4_(pt4_, pt1_);
626
627 BRepBuilderAPI_MakeWire wire_(edg1_, edg2_, edg3_, edg4_);
628 BRepBuilderAPI_MakeFace face_(wire_);
629 TopoDS_Face sh_ = face_.Face();
630
631 int up = 1;
632
633 gp_Pnt g_pnt;
634 if (up)
635 g_pnt = gp_Pnt(0, 0, -100);
636 else
637 g_pnt = gp_Pnt(0, 0, 100);
7fd59977 638
431d0f18 639 myAISContext->EraseAll(Standard_False);
640 Handle(Geom_CartesianPoint) GEOMPoint = new Geom_CartesianPoint(g_pnt);
641 Handle(AIS_Point) AISPoint = new AIS_Point(GEOMPoint);
642 myAISContext->Display(AISPoint, Standard_True);
7fd59977 643
431d0f18 644 BRepPrimAPI_MakeHalfSpace half_(sh_, g_pnt);
645 TopoDS_Solid sol1_ = half_.Solid();
7fd59977 646
431d0f18 647 DBRep::Set("Face", sol1_);
7fd59977 648
431d0f18 649 gp_Ax1 ax1_(gp_Pnt(0., 0., -100.), gp_Dir(0., 0., 1.));
7fd59977 650
431d0f18 651 Standard_Real x = 0., y = 0., z = -80.;
7fd59977 652
431d0f18 653 BRepPrimAPI_MakeBox box(gp_Pnt(x, y, z), gp_Pnt(x + 150, y + 200, z + 200));
7fd59977 654
431d0f18 655 DBRep::Set("Box", box.Shape());
7fd59977 656
657 return 0;
658
659}
431d0f18 660
7fd59977 661#include<GProp_GProps.hxx>
662#include<BRepGProp.hxx>
663
664static Standard_Integer OCC305 (Draw_Interpretor& di,Standard_Integer argc, const char ** argv )
665
666{
6d1a5d3a 667 if (argc != 2)
7fd59977 668 {
586db386 669 di <<"Usage : " << argv[0] << " file\n";
7fd59977 670 return 1;
671 }
672 Standard_CString file = argv[1];
673
674 Handle(AIS_InteractiveContext) myAISContext = ViewerTest::GetAISContext();
675 if(myAISContext.IsNull()) {
676 di << "use 'vinit' command before " << argv[0] << "\n";
677 return -1;
678 }
679
680TopoDS_Shape sh;
681BRep_Builder builder;
682//BRepTools::Read(sh, "/dn02/users_SUN/inv/3/OCC305/testc.brep", builder);
683BRepTools::Read(sh, file, builder);
684
685TopoDS_Wire wire;
686builder.MakeWire(wire);
687TopoDS_Edge ed;
688TopoDS_Vertex vt1, vt2;
689TopExp_Explorer wex(sh, TopAbs_EDGE);
690for(;wex.More();wex.Next())
691{
692 ed = TopoDS::Edge(wex.Current());
693 TopExp::Vertices(ed, vt1, vt2);
694 builder.UpdateVertex(vt1, 0.01);
695 builder.UpdateVertex(vt2, 0.01);
696 builder.UpdateEdge(ed, 0.01);
697 builder.Add(wire, ed);
698
699
700 GProp_GProps lprop;
701 BRepGProp::LinearProperties(ed, lprop);
702 printf("\n length = %f", lprop.Mass());
703}
704 DBRep::Set("Wire",wire);
705// Handle(AIS_Shape) res = new AIS_Shape( wire );
706// aContext->SetColor( res, Quantity_NOC_RED );
707// aContext->Display( res );
708
709// BRepOffsetAPI_MakeOffset off(wire, GeomAbs_Arc);
710// off.Perform(0.5, 0);
711
712// printf("\n IsDone = %d", off.IsDone());
713// sh = off.Shape();
714// res = new AIS_Shape( sh );
715// aContext->SetColor( res, Quantity_NOC_GREEN );
716// aContext->Display( res );
717
718 return 0;
719
720}
721
722static Standard_Integer OCC166 (Draw_Interpretor& di, Standard_Integer /*argc*/, const char ** argv)
723{
724
725 Handle(AIS_InteractiveContext) myAISContext = ViewerTest::GetAISContext();
726 if(myAISContext.IsNull()) {
727 di << "use 'vinit' command before " << argv[0];
728 return 1;
729 }
730
731 BRepPrimAPI_MakeBox aBox(gp_Pnt(0, 0, 0), 100, 100, 100);
732 Handle(AIS_Shape) anAISBox = new AIS_Shape(aBox.Shape());
c3282ec1 733 myAISContext->SetAutoActivateSelection (Standard_False);
7fd59977 734 myAISContext->Display(anAISBox, 1);
404c8936 735
c3282ec1 736 TColStd_ListOfInteger anActivatedModes;
737 myAISContext->ActivatedModes (anAISBox, anActivatedModes);
738 if(anActivatedModes.Extent() != 1 || anActivatedModes.First() != -1 )
7fd59977 739 return 1;
740
741 return 0;
742}
743
744#include <TDocStd_Document.hxx>
745#include <DDocStd.hxx>
15e8b082 746#include <PCDM_StoreStatus.hxx>
7fd59977 747#include <TDocStd_Application.hxx>
748
749static Standard_Integer OCC381_Save (Draw_Interpretor& di, Standard_Integer nb, const char ** a)
750{
751 if (nb != 2) {
586db386 752 di << "Usage: " << a[0] << " Doc\n";
7fd59977 753 return 1;
754 }
755
756 Handle(TDocStd_Document) D;
757 if (!DDocStd::GetDocument(a[1],D)) return 1;
758
6fe96f84 759 Handle(TDocStd_Application) A = DDocStd::GetApplication();
7fd59977 760
761 TCollection_ExtendedString theStatusMessage;
762 if (!D->IsSaved()) {
586db386 763 di << "this document has never been saved\n";
7fd59977 764 return 0;
765 }
15e8b082
M
766 PCDM_StoreStatus theStatus = A->Save(D, theStatusMessage);
767 if (theStatus != PCDM_SS_OK ) {
7fd59977 768 switch ( theStatus ) {
566f8441 769 case PCDM_SS_DriverFailure: {
586db386 770 di << "Error saving document: Could not store , no driver found to make it\n";
566f8441 771 break ;
772 }
773 case PCDM_SS_WriteFailure: {
586db386 774 di << "Error saving document: Write access failure\n";
566f8441 775 break;
776 }
777 case PCDM_SS_Failure: {
586db386 778 di << "Error saving document: Write failure\n" ;
566f8441 779 break;
780 }
781 case PCDM_SS_Doc_IsNull: {
586db386 782 di << "Error saving document: No document to save\n";
566f8441 783 break ;
784 }
785 case PCDM_SS_No_Obj: {
586db386 786 di << "Error saving document: No objects written\n";
566f8441 787 break;
788 }
789 case PCDM_SS_Info_Section_Error: {
586db386 790 di << "Error saving document: Write info section failure\n" ;
566f8441 791 break;
792 }
793 default:
794 break;
7fd59977 795 }
796 return 1;
797 }
798 return 0;
799}
800
801static Standard_Integer OCC381_SaveAs (Draw_Interpretor& di, Standard_Integer nb, const char ** a)
802{
803 if (nb != 3) {
586db386 804 di << "Usage: " << a[0] << " Doc Path\n";
7fd59977 805 return 1;
806 }
807
808 Handle(TDocStd_Document) D;
809 if (!DDocStd::GetDocument(a[1],D)) return 1;
810
811 TCollection_ExtendedString path (a[2]);
6fe96f84 812 Handle(TDocStd_Application) A = DDocStd::GetApplication();
7fd59977 813
814 TCollection_ExtendedString theStatusMessage;
15e8b082
M
815 PCDM_StoreStatus theStatus = A->SaveAs(D,path, theStatusMessage);
816 if (theStatus != PCDM_SS_OK ) {
7fd59977 817 switch ( theStatus ) {
566f8441 818 case PCDM_SS_DriverFailure: {
586db386 819 di << "Error saving document: Could not store , no driver found to make it\n";
566f8441 820 break ;
821 }
822 case PCDM_SS_WriteFailure: {
586db386 823 di << "Error saving document: Write access failure\n";
566f8441 824 break;
825 }
826 case PCDM_SS_Failure: {
586db386 827 di << "Error saving document: Write failure\n" ;
566f8441 828 break;
829 }
830 case PCDM_SS_Doc_IsNull: {
586db386 831 di << "Error saving document: No document to save\n";
566f8441 832 break ;
833 }
834 case PCDM_SS_No_Obj: {
586db386 835 di << "Error saving document: No objects written\n";
566f8441 836 break;
837 }
838 case PCDM_SS_Info_Section_Error: {
586db386 839 di << "Error saving document: Write info section failure\n" ;
566f8441 840 break;
841 }
842 default:
843 break;
7fd59977 844 }
845 return 1;
846 }
847
848 return 0;
849}
850
851#include <BRepClass3d_SolidClassifier.hxx>
852
64531d9c 853Standard_Integer OCC299bug (Draw_Interpretor& theDi,
854 Standard_Integer theArgNb,
855 const char** theArgVec)
7fd59977 856{
64531d9c 857 if (theArgNb < 3)
858 {
859 theDi << "Usage : " << theArgVec[0] << " Solid Point [Tolerance=1.e-7]\n";
7fd59977 860 return -1;
861 }
862
64531d9c 863 TopoDS_Shape aS = DBRep::Get (theArgVec[1]);
864 if (aS.IsNull())
865 {
866 theDi << " Null Shape is not allowed here\n";
7fd59977 867 return 1;
868 }
64531d9c 869 else if (aS.ShapeType() != TopAbs_SOLID)
870 {
871 theDi << " Shape type must be SOLID\n";
7fd59977 872 return 1;
873 }
64531d9c 874
875 gp_Pnt aP (8., 9., 10.);
876 if (!DrawTrSurf::GetPoint (theArgVec[2], aP))
877 {
878 theDi << " Null Point is not allowed here\n";
7fd59977 879 return 1;
880 }
64531d9c 881 const Standard_Real aTol = (theArgNb == 4) ? Draw::Atof (theArgVec[3]) : 1.e-7;
7fd59977 882
64531d9c 883 BRepClass3d_SolidClassifier aSC (aS);
884 aSC.Perform (aP, aTol);
7fd59977 885
64531d9c 886 switch (aSC.State())
887 {
888 case TopAbs_IN: theDi << "The point is IN shape\n"; return 0;
889 case TopAbs_OUT: theDi << "The point is OUT of shape\n"; return 0;
890 case TopAbs_ON: theDi << "The point is ON shape\n"; return 0;
891 case TopAbs_UNKNOWN:
892 default: theDi << "The point is UNKNOWN shape\n"; return 0;
893 }
7fd59977 894}
895
896#include <OSD_Process.hxx>
897#include <OSD_Path.hxx>
898
899static Standard_Integer OCC309bug (Draw_Interpretor& di, Standard_Integer nb, const char ** a)
900{
901 if (nb != 1) {
902 di << "Usage: " << a[0] << "\n";
903 return 1;
904 }
905 OSD_Process p;
906 OSD_Path d = p.CurrentDirectory();
907 TCollection_AsciiString s;
908 d.SystemName(s);
586db386 909 di << "*" << s.ToCString() << "*\n";
7fd59977 910 d.UpTrek();
911 d.SystemName(s);
586db386 912 di << "*" << s.ToCString() << "*\n";
7fd59977 913 return 0;
914}
915
916static Standard_Integer OCC310bug (Draw_Interpretor& di, Standard_Integer nb, const char ** a)
917{
918 if (nb != 1) {
919 di << "Usage: " << a[0] << "\n";
920 return 1;
921 }
922 OSD_Path p("/where/you/want/tmp/qwerty/tmp/");
923 di << p.Trek().ToCString() << "\n";
924 p.UpTrek();
925 di << p.Trek().ToCString() << "\n";
926 return 0;
927}
928
929#include <BRepAlgoAPI_Fuse.hxx>
930#include <BRepAlgoAPI_Common.hxx>
7fd59977 931
932static Standard_Integer OCC277bug (Draw_Interpretor& di, Standard_Integer nb, const char ** a)
933{
431d0f18 934 if(nb != 1) {
935 di << "Usage : " << a[0] << "\n";
7fd59977 936 return 1;
937 }
7fd59977 938
939 BRepPrimAPI_MakeBox box1( 100, 100, 100 );
940 BRepPrimAPI_MakeBox box2( gp_Pnt( 50, 50,50 ), 200, 200, 200 );
941
942 TopoDS_Shape shape1 = box1.Shape();
943 TopoDS_Shape shape2 = box2.Shape();
944
7fd59977 945 TopoDS_Shape fuse,comm;
431d0f18 946 di << "fuse = BRepAlgoAPI_Fuse( shape1, shape2 )\n";
947 di << "comm = BRepAlgoAPI_Common( shape1, shape2 )\n";
948 fuse = BRepAlgoAPI_Fuse(shape1, shape2).Shape();
949 comm = BRepAlgoAPI_Common(shape1, shape2).Shape();
7fd59977 950
951 return 0;
952}
953
7fd59977 954#include <DDocStd_DrawDocument.hxx>
955#include <TDataStd_Name.hxx>
956#include <Draw.hxx>
957#include <XCAFDoc_ShapeTool.hxx>
958#include <XCAFDoc_DocumentTool.hxx>
959#include <TDF_LabelSequence.hxx>
960#include <TPrsStd_AISPresentation.hxx>
961#include <TDF_Data.hxx>
962#include <TDF_Label.hxx>
963#include <XCAFPrs_Driver.hxx>
964
965//------------------------------------------------------------------------------------------
966// name : OCC363
967// Purpose :
968//------------------------------------------------------------------------------------------
969static Standard_Integer OCC363 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
970{
971 try
972 {
973 OCC_CATCH_SIGNALS
974 // 1. Verufy amount of arguments
975 if(argc < 3) { di <<"Error OCC363 : Use : OCC363 document filename\n"; return 1; }
976
977 // 2. Retrieve DDocStd application
6fe96f84 978 Handle(TDocStd_Application) App = DDocStd::GetApplication();
7fd59977 979
980 // 3. Open document
981 TCollection_ExtendedString name(argv[2]);
982 Handle(TDocStd_Document) Doc;
15e8b082 983 if(App->Open(name, Doc) != PCDM_RS_OK) { di << "Error OCC363 : document was not opened successfully\n"; return 1;}
7fd59977 984 Handle(DDocStd_DrawDocument) DD = new DDocStd_DrawDocument(Doc);
985 TDataStd_Name::Set(Doc->GetData()->Root(),argv[1]);
986 Draw::Set(argv[1],DD);
987
988 // 4. Create prsentations
989 Handle(XCAFDoc_ShapeTool) shapes = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
990 TDF_LabelSequence seq;
991 shapes->GetFreeShapes ( seq );
992 Handle(TPrsStd_AISPresentation) prs;
993 for ( Standard_Integer i=1; i <= seq.Length(); i++ )
994 if ( ! seq.Value(i).FindAttribute ( TPrsStd_AISPresentation::GetID(), prs ) )
995 prs = TPrsStd_AISPresentation::Set(seq.Value(i),XCAFPrs_Driver::GetID());
996 }
a738b534 997 catch(Standard_Failure const&) { di << "FAULTY OCC363 : Exception during reading document.\n";return 0;}
7fd59977 998
999 di << "OCC363 OK\n";
1000 return 0;
1001}
1002
1003// Must use OCC299
1004////======================================================================================
1005//// Function : OCC372
1006//// Purpose :
1007////======================================================================================
1008//static Standard_Integer OCC372 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
1009//{
1010// try
1011// {
1012// OCC_CATCH_SIGNALS
1013// // 1. Verufy amount of arguments
1014// if(argc < 2) {di << "OCC372 FAULTY. Use : OCC372 brep-file";return 0;}
1015//
1016// // 2. Read solid
1017// BRep_Builder B;
1018// TopoDS_Shape Ref;
1019// BRepTools::Read(Ref, argv[1], B);
1020//
1021// // 3. Calculate location of aP3d in relation to the solid
1022// gp_Pnt aP3d(6311.4862583184, -2841.3092756034, 16.461053497188);
1023// BRepClass3d_SolidClassifier SC(Ref);
1024// SC.Perform(aP3d, 1e-7);
1025//
1026// // 4. Check returned state. The point must be inside the solid.
1027// TopAbs_State aState=SC.State();
1028// switch (aState)
1029// {
1030// case TopAbs_OUT:
1031// di<<"OCC372 FAULTY. aState = TopAbs_OUT";
1032// return 0;
1033// case TopAbs_ON:
1034// di<<"OCC372 FAULTY. aState = TopAbs_ON";
1035// return 0;
1036// case TopAbs_IN:
1037// di<<"OCC372 OK. aState = TopAbs_IN" ;
1038// return 0;
1039// default:
1040// di<<"OCC372 FAULTY. aState = UNKNOWN";
1041// return 0;
1042// }
1043// }
1044// catch (Standard_Failure) { di<<"OCC372 FAULTY. Exception raised"; }
1045//
1046// return 0;
1047//}
1048
1049#include <BRepTopAdaptor_FClass2d.hxx>
1050
1051//======================================================================================
1052// Function : OCC377
1053// Purpose :
1054//======================================================================================
1055static Standard_Integer OCC377 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
1056{
1057 try
1058 {
1059 OCC_CATCH_SIGNALS
1060 // 1. Verify validity of arguments
1061 if ( argc < 1 ) {di << "Error OCC377. Use OCC377 file x y precuv \n";return 0;}
1062
1063 // 2. Initialize parameters
1064 gp_Pnt2d p2d;
91322f44 1065 p2d.SetX ( Draw::Atof(argv[2]) );
1066 p2d.SetY ( Draw::Atof(argv[3]) );
1067 Standard_Real precuv = Draw::Atof (argv[4] );
7fd59977 1068
1069 // 3. Read shape
1070 BRep_Builder B;
1071 TopoDS_Shape Shape;
1072 BRepTools::Read ( Shape, argv[1], B );
1073
1074 // 4. Verify whether enrtry point is on wire and reversed ones (indeed results of veridying must be same)
1075 TopExp_Explorer exp;
1076 Standard_Integer i=1;
1077 for (exp.Init(Shape.Oriented(TopAbs_FORWARD),TopAbs_WIRE); exp.More(); exp.Next(), i++)
1078 {
1079 // 4.1. Verify whether enrtry point is on wire
1080 const TopoDS_Wire& wir = TopoDS::Wire(exp.Current());
1081 TopoDS_Face newFace = TopoDS::Face(Shape.EmptyCopied());
1082
1083 TopAbs_Orientation orWire = wir.Orientation();
1084 newFace.Orientation(TopAbs_FORWARD);
1085 B.Add(newFace,wir);
1086
1087 BRepTopAdaptor_FClass2d FClass2d1(newFace,precuv);
1088 TopAbs_State stat1 = FClass2d1.PerformInfinitePoint();
1089 //di << "Wire " << i << ": Infinite point is " <<
1090 // ( stat1 == TopAbs_IN ? "IN" : stat1 == TopAbs_OUT ? "OUT" : stat1 == TopAbs_ON ? "ON" : "UNKNOWN" ) << "\n";
1091
1092 TCollection_AsciiString TmpString;
1093 stat1 == TopAbs_IN ? TmpString.AssignCat("IN") : stat1 == TopAbs_OUT ? TmpString.AssignCat("OUT") : stat1 == TopAbs_ON ? TmpString.AssignCat("ON") : TmpString.AssignCat("UNKNOWN");
1094 di << "Wire " << i << ": Infinite point is " << TmpString.ToCString() << "\n";
1095
1096 stat1 = FClass2d1.Perform(p2d);
1097 //di << "Wire " << i << ": point ( " << p2d.X() << ", " << p2d.Y() << " ) is " <<
1098 // ( stat1 == TopAbs_IN ? "IN" : stat1 == TopAbs_OUT ? "OUT" : stat1 == TopAbs_ON ? "ON" : "UNKNOWN" ) << "\n";
1099
1100 TmpString.Clear();
1101 stat1 == TopAbs_IN ? TmpString.AssignCat("IN") : stat1 == TopAbs_OUT ? TmpString.AssignCat("OUT") : stat1 == TopAbs_ON ? TmpString.AssignCat("ON") : TmpString.AssignCat("UNKNOWN");
1102 di << "Wire " << i << ": point ( " << p2d.X() << ", " << p2d.Y() << " ) is " << TmpString.ToCString() << "\n";
1103
1104 // 4.2. Verify whether enrtry point is on reversed wire
1105 newFace = TopoDS::Face(Shape.EmptyCopied());
1106 newFace.Orientation(TopAbs_FORWARD);
1107 orWire = TopAbs::Reverse(orWire);
1108 B.Add(newFace,wir.Oriented(orWire));
1109 BRepTopAdaptor_FClass2d FClass2d2(newFace,precuv);
1110 TopAbs_State stat2 = FClass2d2.PerformInfinitePoint();
1111 //di << "Reversed Wire " << i << ": Infinite point is " <<
1112 // ( stat2 == TopAbs_IN ? "IN" : stat2 == TopAbs_OUT ? "OUT" : stat2 == TopAbs_ON ? "ON" : "UNKNOWN" ) << "\n";
1113
1114 TmpString.Clear();
1115 stat2 == TopAbs_IN ? TmpString.AssignCat("IN") : stat2 == TopAbs_OUT ? TmpString.AssignCat("OUT") : stat2 == TopAbs_ON ? TmpString.AssignCat("ON") : TmpString.AssignCat("UNKNOWN");
1116 di << "Reversed Wire " << i << ": Infinite point is " << TmpString.ToCString() << "\n";
1117
1118 stat2 = FClass2d2.Perform(p2d);
1119 //di << "Reversed Wire " << i << ": point ( " << p2d.X() << ", " << p2d.Y() << " ) is " <<
1120 // ( stat2 == TopAbs_IN ? "IN" : stat2 == TopAbs_OUT ? "OUT" : stat2 == TopAbs_ON ? "ON" : "UNKNOWN" ) << "\n";
1121
1122 TmpString.Clear();
1123 stat2 == TopAbs_IN ? TmpString.AssignCat("IN") : stat2 == TopAbs_OUT ? TmpString.AssignCat("OUT") : stat2 == TopAbs_ON ? TmpString.AssignCat("ON") : TmpString.AssignCat("UNKNOWN");
1124 di << "Reversed Wire " << i << ": point ( " << p2d.X() << ", " << p2d.Y() << " ) is " << TmpString.ToCString() << "\n";
1125
1126 // 4.3. Compare results (they must be same)
586db386 1127 if(stat1 ==stat2) di << "OCC377 OK\n";
1128 else {di << "OCC377 FAULTY\n"; return 0;}
7fd59977 1129 }
1130 }
a738b534 1131 catch(Standard_Failure const&)
7fd59977 1132 {
1133 di << "OCC377 Exception";
1134 }
1135
1136 return 0;
1137}
1138
1139#include <ShapeUpgrade_ShapeDivideAngle.hxx>
1140#include <ShapeBuild_ReShape.hxx>
1141
1142//=======================================================================
1143//function : OCC22
1144//purpose :
1145//=======================================================================
1146static Standard_Integer OCC22 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
1147{
1148 try
1149 {
1150 OCC_CATCH_SIGNALS
1151 // 1. Verify arguments of the command
1152 if (argc < 5) { di << "OCC22 FAULTY. Use : OCC22 Result Shape CompoundOfSubshapesToBeDivided ConsiderLocation"; return 0;}
1153
1154 Standard_Boolean aConsiderLocation;
1155 if(strcmp(argv[4], "0")==0) aConsiderLocation = Standard_False;
1156 else aConsiderLocation = Standard_True;
1157
1158 // 2. Iniitialize aShapeUpgrade
c6541a0c 1159 ShapeUpgrade_ShapeDivideAngle aShapeUpgrade(M_PI/2.);
7fd59977 1160 // precision
1161 aShapeUpgrade.SetPrecision (Precision::Confusion());
1162 // tolerance
1163 aShapeUpgrade.SetMaxTolerance(0.1);
1164 // subshapes to be divided
1165 TopoDS_Shape aSubShapesToBeDivided = DBRep::Get(argv[3]);
1166 if(aSubShapesToBeDivided.IsNull()) {di << "OCC22 FAULTY. Compound of subshapes to be divided is not exist. Please, verify input values. \n";return 0;}
1167 aShapeUpgrade.Init(aSubShapesToBeDivided);
1168 // context
1169 Handle(ShapeBuild_ReShape) aReshape = new ShapeBuild_ReShape;
1170 aShapeUpgrade.SetContext(aReshape);
1171 if(aConsiderLocation) aReshape->ModeConsiderLocation() = Standard_True;
1172
1173 // 3. Perform splitting
1174 if (aShapeUpgrade.Perform (Standard_False)) di << "Upgrade_SplitRevolution_Done \n";
1175 else if (aShapeUpgrade.Status (ShapeExtend_OK)) di << "Upgrade_SplitRevolution_OK \n";
1176 else if (aShapeUpgrade.Status (ShapeExtend_FAIL)) { di << "OCC22 FAULTY. Operation failed. Angle was not divided\n";return 0;}
1177
1178 // 4. Perform rebuilding shape
1179 // 4.1. Retrieve Shape
1180 TopoDS_Shape anInitShape = DBRep::Get(argv[2]);
1181 if(anInitShape.IsNull()) { di << "OCC22 FAULTY. Initial shape is not exist. Please verify input values \n"; return 0;}
1182 // 4.2 Rebuid retrieved shape
1183 TopoDS_Shape aResultShape = aReshape->Apply(anInitShape);
1184 // 4.3. Create result Draw shape
1185 DBRep::Set(argv[1], aResultShape);
1186 }
a738b534 1187 catch (Standard_Failure const&) {di << "OCC22 Exception \n" ;return 0;}
7fd59977 1188
1189 return 0;
1190}
1191
1192
1193#include <ShapeProcess_OperLibrary.hxx>
1194#include <ShapeProcess_ShapeContext.hxx>
1195#include <ShapeProcess.hxx>
1196
1197#include <TopTools_DataMapIteratorOfDataMapOfShapeShape.hxx>
1198#include <BRepMesh_IncrementalMesh.hxx>
7bd071ed 1199#include <IMeshTools_Parameters.hxx>
7fd59977 1200
1201//=======================================================================
1202//function : OCC24
1203//purpose :
1204//=======================================================================
1205static Standard_Integer OCC24 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
1206{
1207 try
1208 {
1209 OCC_CATCH_SIGNALS
1210 // 1. Verify amount of arguments of the command
1211 if (argc < 6) { di << "OCC24 FAULTY. Use : OCC22 Result Shape CompoundOfSubshapes ResourceFileName SequenceName"; return 0;}
1212
1213 // 2. Retrieve parameters
1214 // initial shape
1215 TopoDS_Shape anInitShape = DBRep::Get(argv[2]);
1216 if(anInitShape.IsNull()) { di << "OCC24 FAULTY. Initial shape is not exist. Please verify input values \n"; return 0;}
1217 // compound of subshapes
1218 TopoDS_Shape aSubShapes = DBRep::Get(argv[3]);
1219 if(aSubShapes.IsNull()) {di << "OCC24 FAULTY. Compound of subshapes is not exist. Please, verify input values. \n";return 0;}
1220 // name of resource file
1221 const char* aResourceFile = argv[4];
1222 // name of sequence from resource file to be executed
1223 const char* aSequenceName = argv[5];
1224
1225 // 3. Initialize ShapeContext and perform sequence of operation specified with resource file
1226 ShapeProcess_OperLibrary::Init();
1227 Handle(ShapeProcess_ShapeContext) aShapeContext = new ShapeProcess_ShapeContext (aSubShapes, aResourceFile);
1228 aShapeContext->SetDetalisation (TopAbs_EDGE);
1229 ShapeProcess::Perform (aShapeContext, aSequenceName);
1230
1231 // 4. Rebuild initil shape in accordance with performed operation
1232 Handle(ShapeBuild_ReShape) aReshape = new ShapeBuild_ReShape;
1233 TopTools_DataMapIteratorOfDataMapOfShapeShape anIter (aShapeContext->Map());
1234 for (; anIter.More(); anIter.Next())
1235 aReshape->Replace(anIter.Key(), anIter.Value());
1236 TopoDS_Shape aResultShape = aReshape->Apply(anInitShape);
1237
1238 // 5 Create resultant Draw shape
1239 DBRep::Set(argv[1], aResultShape);
1240
1241 }
a738b534 1242 catch (Standard_Failure const&) {di << "OCC24 Exception \n" ;return 0;}
7fd59977 1243
1244 return 0;
1245}
1246
1247//=======================================================================
1248//function : OCC369
1249//purpose : Verify whether exception occurs during building mesh
1250//=======================================================================
1251static Standard_Integer OCC369(Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
1252{
1253 try
1254 {
1255 OCC_CATCH_SIGNALS
1256 // 1. Verify amount of arguments of the command
1257 if (argc < 2) { di << "OCC369 FAULTY. Use : OCC369 Shape \n"; return 0;}
1258
1259 // 2. Retrieve shape
1260 TopoDS_Shape aShape = DBRep::Get(argv[1]);
1261 if(aShape.IsNull()) {di << "OCC369 FAULTY. Entry shape is NULL \n"; return 0;}
1262
1263 // 3. Build mesh
7bd071ed 1264 IMeshTools_Parameters aMeshParams;
1265 aMeshParams.Relative = Standard_True;
e71669c6 1266 aMeshParams.Deflection = 0.2;
7bd071ed 1267 aMeshParams.Angle = M_PI / 6.0;
e71669c6 1268 BRepMesh_IncrementalMesh aMesh(aShape, aMeshParams);
7fd59977 1269
1270 }
a738b534 1271 catch (Standard_Failure const&) {di << "OCC369 Exception \n" ;return 0;}
7fd59977 1272
1273 di << "OCC369 OK \n";
1274 return 0;
1275}
1276
1277#include <math_Vector.hxx>
1278#include <math_Matrix.hxx>
1279static Standard_Integer OCC524 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
1280{
1281 if(argc != 9){
1282 di<<"Usage : " << argv[0] << " LowerVector UpperVector InitialValueVector LowerRowMatrix UpperRowMatrix LowerColMatrix UpperColMatrix InitialValueMatrix\n";
1283 return 1;
1284 }
91322f44 1285 Standard_Integer LowerVector = Draw::Atoi(argv[1]);
1286 Standard_Integer UpperVector = Draw::Atoi(argv[2]);
1287 Standard_Real InitialValueVector = Draw::Atof(argv[3]);
1288 Standard_Integer LowerRowMatrix = Draw::Atoi(argv[4]);
1289 Standard_Integer UpperRowMatrix = Draw::Atoi(argv[5]);
1290 Standard_Integer LowerColMatrix = Draw::Atoi(argv[6]);
1291 Standard_Integer UpperColMatrix = Draw::Atoi(argv[7]);
1292 Standard_Real InitialValueMatrix = Draw::Atof(argv[8]);
7fd59977 1293
1294 math_Vector Vector1(LowerVector, UpperVector);
1295 math_Vector Vector2(LowerVector, UpperVector);
1296
1297 math_Vector Vector(LowerVector, UpperVector, InitialValueVector);
1298 math_Matrix Matrix(LowerRowMatrix, UpperRowMatrix, LowerColMatrix, UpperColMatrix, InitialValueMatrix);
1299
04232180 1300 //Vector.Dump(std::cout);
1301 //std::cout<<std::endl;
7fd59977 1302
04232180 1303 //Matrix.Dump(std::cout);
1304 //std::cout<<std::endl;
7fd59977 1305
1306 Vector1.Multiply(Vector, Matrix);
1307
04232180 1308 //Vector1.Dump(std::cout);
7fd59977 1309 Standard_SStream aSStream1;
1310 Vector1.Dump(aSStream1);
1311 di << aSStream1;
1312 di<<"\n";
1313
d2d893b8
RL
1314 if (Matrix.RowNumber() > 1) {
1315 Matrix(Matrix.LowerRow() + 1, Matrix.LowerCol()) += 1.;
1316 }
7fd59977 1317 Vector2.TMultiply(Vector, Matrix);
1318
04232180 1319 //Vector2.Dump(std::cout);
7fd59977 1320 Standard_SStream aSStream2;
1321 Vector2.Dump(aSStream2);
1322 di << aSStream2;
1323 di<<"\n";
1324
1325 return 0;
1326}
1327
1328#include <GeomPlate_BuildPlateSurface.hxx>
1329//=======================================================================
1330//function : OCC525
1331//purpose :
1332//=======================================================================
1333static Standard_Integer OCC525(Draw_Interpretor& di, Standard_Integer /*argc*/, const char ** /*argv*/)
1334{
e8e26df0 1335 GeomPlate_BuildPlateSurface aBuilder;
1336 aBuilder.Perform();
1337
1338 if (aBuilder.IsDone())
7fd59977 1339 {
e8e26df0 1340 di << "Error in OCC525. Null result is expected.\n";
1341 }
1342 else
1343 {
1344 di << "OCC525 OK \n";
7fd59977 1345 }
7fd59977 1346
7fd59977 1347 return 0;
1348}
1349
7fd59977 1350#include <BRepPrimAPI_MakeWedge.hxx>
1351#include <gce_MakeRotation.hxx>
1352#include <gce_MakeTranslation.hxx>
1353#include <BRepBuilderAPI_Transform.hxx>
1354#include <BRepPrimAPI_MakeWedge.hxx>
7fd59977 1355//=======================================================================
1356//function : OCC578
1357//purpose :
1358//=======================================================================
1359static Standard_Integer OCC578 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
1360{
431d0f18 1361 if(argc != 4) {
1362 di << "Usage : " << argv[0] << " shape1 shape2 shape3\n";
7fd59977 1363 return 1;
1364 }
7fd59977 1365
1366 gp_Pnt P0(0,0,0.0);
1367 double xperiod = 1.0;
1368 double yperiod = 1.0;
1369 double sub_thick = 0.5;
1370
1371 // mask_substrate
1372 //TopoDS_Shape substrate = BRepPrimAPI_MakeBox( P0, xperiod, yperiod, sub_thick );
1373 TopoDS_Shape substrate = BRepPrimAPI_MakeBox( P0, xperiod, yperiod, sub_thick ).Shape();
1374
1375 // --------------------------------------------------------------------
1376
1377 // wedge
1378 //TopoDS_Shape wedge1 = BRepPrimAPI_MakeWedge(0.5, 0.05, 0.5,
1379 // 0.1, 0.1 , 0.4, 0.4 );
1380 TopoDS_Shape wedge1 = BRepPrimAPI_MakeWedge(0.5, 0.05, 0.5,
1381 0.1, 0.1 , 0.4, 0.4 ).Shape();
1382
1383 gp_Trsf rotate = gce_MakeRotation ( gp_Pnt(0.0,0.0,0.0),
1384 gp_Dir(1.0,0.0,0.0),
1385 1.570795 );
1386
1387 gp_Trsf translate = gce_MakeTranslation(gp_Pnt( 0.0, -0.5, 0.0),
1388 gp_Pnt( 0.25, 0.25, 0.5)
1389 );
1390
1391 rotate.PreMultiply( translate );
1392
1393 TopoDS_Shape wedge1a = BRepBuilderAPI_Transform( wedge1, rotate );
1394
1395 if (wedge1a.IsNull()) {
1396 di<<" Null shape1 is not allowed\n";
1397 return 1;
1398 }
1399 DBRep::Set(argv[1], wedge1a);
1400
1401 // --------------------------------------------------------------------
1402
1403 // wedge top
1404 //TopoDS_Shape wedge2 = BRepPrimAPI_MakeWedge(0.5, 0.3, 0.5,
1405 // 0.1, 0.1 , 0.4, 0.4 );
1406 TopoDS_Shape wedge2 = BRepPrimAPI_MakeWedge(0.5, 0.3, 0.5,
1407 0.1, 0.1 , 0.4, 0.4 ).Shape();
1408
1409 gp_Trsf rotate2 = gce_MakeRotation ( gp_Pnt(0.0,0.0,0.0),
1410 gp_Dir(1.0,0.0,0.0),
1411 1.570795 * 3.0 );
1412
1413 gp_Trsf translate2 = gce_MakeTranslation(gp_Pnt( 0.0, 0.0, 0.0),
1414 gp_Pnt( 0.25, 0.25, 0.5)
1415 );
1416
1417 rotate2.PreMultiply( translate2 );
1418
1419 TopoDS_Shape wedge2a = BRepBuilderAPI_Transform( wedge2, rotate2 );
1420
1421 if (wedge2a.IsNull()) {
1422 di<<" Null shape2 is not allowed\n";
1423 return 1;
1424 }
1425 DBRep::Set(argv[2], wedge2a);
1426
1427
1428 // combine wedges
431d0f18 1429 di << "wedge_common = BRepAlgoAPI_Fuse(wedge1a , wedge2a)\n";
1430 TopoDS_Shape wedge_common = BRepAlgoAPI_Fuse(wedge1a , wedge2a).Shape();
7fd59977 1431
431d0f18 1432 di << "sub_etch1 = BRepAlgoAPI_Cut(substrate, wedge_common)\n";
1433 TopoDS_Shape sub_etch1 = BRepAlgoAPI_Cut(substrate, wedge_common).Shape();
1434
7fd59977 1435 if (sub_etch1.IsNull()) {
1436 di<<" Null shape3 is not allowed\n";
1437 return 1;
1438 }
1439 DBRep::Set(argv[3], sub_etch1);
1440
1441 return 0;
1442}
1443
7fd59977 1444#include <Standard_GUID.hxx>
1445//=======================================================================
1446//function : OCC669
1447//purpose :
1448//=======================================================================
1449static Standard_Integer OCC669 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
1450{
1451 if(argc != 2){
1452 di<<"Usage : " << argv[0] << " GUID\n";
1453 return -1;
1454 }
1455 Standard_GUID guid(argv[1]);
04232180 1456 //guid.ShallowDump(std::cout);
7fd59977 1457 Standard_SStream aSStream;
1458 guid.ShallowDump(aSStream);
1459 di << aSStream;
1460 di<<"\n";
1461 return 0;
1462}
1463
1464#include <XCAFDoc.hxx>
1465//=======================================================================
1466//function : OCC738_ShapeRef
1467//purpose :
1468//=======================================================================
1469static Standard_Integer OCC738_ShapeRef (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
1470{
1471 if(argc != 1){
1472 di<<"Usage : " << argv[0] << "\n";
1473 return -1;
1474 }
1475 const Standard_GUID& guid = XCAFDoc::ShapeRefGUID ();
04232180 1476 //guid.ShallowDump(std::cout);
7fd59977 1477 Standard_SStream aSStream;
1478 guid.ShallowDump(aSStream);
1479 di << aSStream;
1480 return 0;
1481}
1482
1483//=======================================================================
1484//function : OCC738_Assembly
1485//purpose :
1486//=======================================================================
1487static Standard_Integer OCC738_Assembly (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
1488{
1489 if(argc != 1){
1490 di<<"Usage : " << argv[0] << "\n";
1491 return -1;
1492 }
1493 const Standard_GUID& guid = XCAFDoc::AssemblyGUID ();
04232180 1494 //guid.ShallowDump(std::cout);
7fd59977 1495 Standard_SStream aSStream;
1496 guid.ShallowDump(aSStream);
1497 di << aSStream;
1498 return 0;
1499}
1500
1501#if defined(DDataStd_def01)
1502#include <DDataStd_DrawPresentation.hxx>
1503//=======================================================================
1504//function : OCC739_DrawPresentation
1505//purpose :
1506//=======================================================================
1507static Standard_Integer OCC739_DrawPresentation (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
1508{
1509 if(argc != 1){
1510 di<<"Usage : " << argv[0] << "\n";
1511 return -1;
1512 }
1513 const Standard_GUID& guid = DDataStd_DrawPresentation::GetID() ;
04232180 1514 //guid.ShallowDump(std::cout);
7fd59977 1515 Standard_SStream aSStream;
1516 guid.ShallowDump(aSStream);
1517 di << aSStream;
1518 return 0;
1519}
1520#endif
1521
1522//=======================================================================
1523//function : OCC708
1524//purpose :
1525//=======================================================================
1526static Standard_Integer OCC708 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
1527{
1528 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
1529 if(aContext.IsNull()) {
586db386 1530 di << argv[0] << "ERROR : use 'vinit' command before \n";
7fd59977 1531 return 1;
1532 }
1533
1534 if ( argc != 2) {
586db386 1535 di << "ERROR : Usage : " << argv[0] << " shape ; Deactivate the current transformation\n";
7fd59977 1536 return 1;
1537 }
1538
eb4320f2 1539 Standard_Boolean updateviewer = Standard_True;
7fd59977 1540
1541 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
1542
1543 TCollection_AsciiString aName(argv[1]);
1544 Handle(AIS_InteractiveObject) AISObj;
1545
8f521168 1546 if (!aMap.Find2 (aName, AISObj)
1547 || AISObj.IsNull())
1548 {
586db386 1549 di << "Use 'vdisplay' before\n";
7fd59977 1550 return 1;
7fd59977 1551 }
8f521168 1552
1553 AISObj->ResetTransformation();
1554
1555 aContext->Erase(AISObj, updateviewer);
1556 aContext->UpdateCurrentViewer();
1557 aContext->Display(AISObj, updateviewer);
1558 aContext->UpdateCurrentViewer();
7fd59977 1559 return 0;
1560}
1561
1562//=======================================================================
1563//function : OCC670
1564//purpose :
1565//=======================================================================
1566#include <TColStd_Array2OfInteger.hxx>
1567static Standard_Integer OCC670 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
1568{
1569 if(argc != 1){
1570 di<<"Usage : " << argv[0] << "\n";
1571 return -1;
1572 }
8fcb8c07 1573
1574 // check that exception initialized without message string can be safely handled and printed
1575 try {
9775fa61 1576 throw Standard_OutOfRange();
8fcb8c07 1577 }
9775fa61 1578 catch (Standard_Failure const& anException) {
8fcb8c07 1579 std::cout << "Caught successfully: ";
04232180 1580 std::cout << anException << std::endl;
8fcb8c07 1581 }
7fd59977 1582 return 0;
1583}
1584
1585#include <GeomAPI_ProjectPointOnSurf.hxx>
1586//=======================================================================
1587//function : OCC867
1588//purpose :
1589//=======================================================================
1590static Standard_Integer OCC867(Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
1591{
1592 if (argc!=7)
1593 {
1594 di<<"Usage : " << argv[0] << " Point Surface Umin Usup Vmin Vsup \n";
1595 return 1;
1596 }
1597
1598 gp_Pnt aPoint3d;
1599 DrawTrSurf::GetPoint(argv[1],aPoint3d);
1600 Handle (Geom_Surface) aSurface=DrawTrSurf::GetSurface(argv[2]);
91322f44 1601 Standard_Real Umin=Draw::Atof(argv[3]);
1602 Standard_Real Usup=Draw::Atof(argv[4]);
1603 Standard_Real Vmin=Draw::Atof(argv[5]);
1604 Standard_Real Vsup=Draw::Atof(argv[6]);
7fd59977 1605
1606 if (aSurface.IsNull()) {
1607 di << argv[2] << " Null surface \n" ;
1608 return 1;
1609 }
1610
1611 GeomAPI_ProjectPointOnSurf PonSurf;
1612 PonSurf.Init(aSurface, Umin, Usup, Vmin, Vsup);
1613 PonSurf.Perform(aPoint3d);
1614
1615 return 0;
1616}
1617
1618//=======================================================================
1619//function : OCC909
1620//purpose :
1621//=======================================================================
1622static Standard_Integer OCC909 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
1623{
1624 if (argc!=3)
1625 {
1626 di<<"Usage : " << argv[0] << " wire face\n";
1627 return 1;
1628 }
1629
1630 TopoDS_Wire awire = TopoDS::Wire(DBRep::Get(argv[1])); //read the wire
1631 TopoDS_Face aface = TopoDS::Face(DBRep::Get(argv[2])); //read the face
1632 if (awire.IsNull() || aface.IsNull()) {
586db386 1633 di << "Null object\n";
7fd59977 1634 return 1;
1635 }
1636
1637 Standard_Integer count = 0;
1638 TopExp_Explorer TE(awire, TopAbs_VERTEX);
1639 if ( TE.More()) {
1640 BRepTools_WireExplorer WE;
1641 for ( WE.Init(awire,aface); WE.More(); WE.Next()) {
1642 TopoDS_Edge E = WE.Current();
1643 count++;
1644 }
1645 }
1646 di << "Count = " << count << "\n";
1647
1648 return 0;
1649}
1650
1651//=======================================================================
1652//function : OCC921
1653//purpose :
1654//=======================================================================
1655static Standard_Integer OCC921 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
1656{
6d1a5d3a 1657 if (argc != 2)
7fd59977 1658 {
586db386 1659 di <<"Usage : " << argv[0] << " face\n";
7fd59977 1660 return 1;
1661 }
1662 Standard_Real u1, u2, v1, v2;
1663 TopoDS_Face F = TopoDS::Face( DBRep::Get(argv[1]) ); //read the shape
1664 if (F.IsNull())
1665 return 1;
1666 BRepTools::UVBounds(F, u1, u2, v1, v2);
1667 di << "Bounds: " << u1 << " " << u2 << " " << v1 << " " << v2 << "\n";
1668 return 0;
1669}
1670
1671#include <Expr_NamedUnknown.hxx>
1672#include <Expr_GeneralExpression.hxx>
1673#include <Expr_Exponential.hxx>
1674//=======================================================================
1675//function : OCC902
1676//purpose :
1677//=======================================================================
1678static Standard_Integer OCC902(Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
1679{
6d1a5d3a 1680 if (argc != 2)
7fd59977 1681 {
586db386 1682 di <<"Usage : " << argv[0] << " expression\n";
7fd59977 1683 return 1;
1684 }
1685
1686 TCollection_AsciiString myStr(argv[1]);
1687
1688 Handle (Expr_NamedUnknown) myNamed = new Expr_NamedUnknown(myStr);
1689 Handle (Expr_Exponential) oldExpr = new Expr_Exponential(myNamed);
1690 Handle (Expr_GeneralExpression) newExpr = oldExpr->Derivative(myNamed);
1691
1692
1693 TCollection_AsciiString res = newExpr->String();
1694 Standard_CString resStr = res.ToCString();
1695 TCollection_AsciiString res_old = oldExpr->String();
1696 Standard_CString res_oldStr = res_old.ToCString();
1697
1698
1699 di << "X = " << argv[1] << "\n";
1700 di << "Y = " << res_oldStr << "\n";
1701 di << "Y' = " << resStr << "\n";
1702
1703 return 0;
1704}
1705
1706#include <DDF.hxx>
1707#include <TPrsStd_AISViewer.hxx>
1708#include <TDF_Label.hxx>
1709#include <TPrsStd_AISPresentation.hxx>
1710//=======================================================================
1711//function : OCC1029_AISTransparency
1712//purpose : OCC1029_AISTransparency (DOC,entry,[real])
1713//=======================================================================
1714
1715static Standard_Integer OCC1029_AISTransparency (Draw_Interpretor& di,
1716 Standard_Integer nb,
1717 const char ** arg)
1718{
1719 if (nb >= 3 ) {
1720 Handle(TDocStd_Document) D;
1721 if (!DDocStd::GetDocument(arg[1],D)) return 1;
1722 TDF_Label L;
1723 if (!DDF::FindLabel(D->GetData(),arg[2],L)) return 1;
1724
1725 Handle(TPrsStd_AISViewer) viewer;
1726 if( !TPrsStd_AISViewer::Find(L, viewer) ) return 1;
1727
1728 Handle(TPrsStd_AISPresentation) prs;
1729 if(L.FindAttribute( TPrsStd_AISPresentation::GetID(), prs) ) {
1730 if( nb == 4 ) {
91322f44 1731 prs->SetTransparency(Draw::Atof(arg[3]));
7fd59977 1732 TPrsStd_AISViewer::Update(L);
1733 }
1734 else {
1735 di << "Transparency = " << prs->Transparency() << "\n";
1736 }
1737 return 0;
1738 }
1739 }
586db386 1740 di << arg[0] << " : Error\n";
7fd59977 1741 return 1;
1742}
1743
7fd59977 1744//=======================================================================
1745//function : OCC1031_AISMaterial
1746//purpose : OCC1031_AISMaterial (DOC,entry,[material])
1747//=======================================================================
1748
1749static Standard_Integer OCC1031_AISMaterial (Draw_Interpretor& di,
1750 Standard_Integer nb,
1751 const char ** arg)
1752{
1753 if (nb >= 3) {
1754 Handle(TDocStd_Document) D;
1755 if (!DDocStd::GetDocument(arg[1],D)) return 1;
1756 TDF_Label L;
1757 if (!DDF::FindLabel(D->GetData(),arg[2],L)) return 1;
1758
1759 Handle(TPrsStd_AISViewer) viewer;
1760 if( !TPrsStd_AISViewer::Find(L, viewer) ) return 1;
1761
1762 Handle(TPrsStd_AISPresentation) prs;
1763 if(L.FindAttribute( TPrsStd_AISPresentation::GetID(), prs) ) {
1764 if( nb == 4 ) {
91322f44 1765 prs->SetMaterial((Graphic3d_NameOfMaterial)Draw::Atoi(arg[3]));
7fd59977 1766 TPrsStd_AISViewer::Update(L);
1767 }
1768 else {
1769 di << "Material = " << prs->Material() << "\n";
1770 }
1771 return 0;
1772 }
1773 }
586db386 1774 di << arg[0] << " : Error\n";
7fd59977 1775 return 1;
1776}
1777
1778//=======================================================================
1779//function : OCC1032_AISWidth
1780//purpose : OCC1032_AISWidth (DOC,entry,[width])
1781//=======================================================================
1782
1783static Standard_Integer OCC1032_AISWidth (Draw_Interpretor& di,
1784 Standard_Integer nb,
1785 const char ** arg)
1786{
1787 if (nb >= 3) {
1788 Handle(TDocStd_Document) D;
1789 if (!DDocStd::GetDocument(arg[1],D)) return 1;
1790 TDF_Label L;
1791 if (!DDF::FindLabel(D->GetData(),arg[2],L)) return 1;
1792
1793 Handle(TPrsStd_AISViewer) viewer;
1794 if( !TPrsStd_AISViewer::Find(L, viewer) ) return 1;
1795
1796 Handle(TPrsStd_AISPresentation) prs;
1797 if(L.FindAttribute( TPrsStd_AISPresentation::GetID(), prs) ) {
1798 if( nb == 4 ) {
91322f44 1799 prs->SetWidth(Draw::Atof(arg[3]));
7fd59977 1800 TPrsStd_AISViewer::Update(L);
1801 }
1802 else {
1803 di << "Width = " << prs->Width() << "\n";
1804 }
1805 return 0;
1806 }
1807 }
586db386 1808 di << arg[0] << " : Error\n";
7fd59977 1809 return 1;
1810}
1811
1812//=======================================================================
1813//function : OCC1033_AISMode
1814//purpose : OCC1033_AISMode (DOC,entry,[mode])
1815//=======================================================================
1816
1817static Standard_Integer OCC1033_AISMode (Draw_Interpretor& di,
1818 Standard_Integer nb,
1819 const char ** arg)
1820{
1821 if (nb >= 3) {
1822 Handle(TDocStd_Document) D;
1823 if (!DDocStd::GetDocument(arg[1],D)) return 1;
1824 TDF_Label L;
1825 if (!DDF::FindLabel(D->GetData(),arg[2],L)) return 1;
1826
1827 Handle(TPrsStd_AISViewer) viewer;
1828 if( !TPrsStd_AISViewer::Find(L, viewer) ) return 1;
1829
1830 Handle(TPrsStd_AISPresentation) prs;
1831 if(L.FindAttribute( TPrsStd_AISPresentation::GetID(), prs) ) {
1832 if( nb == 4 ) {
91322f44 1833 prs->SetMode(Draw::Atoi(arg[3]));
7fd59977 1834 TPrsStd_AISViewer::Update(L);
1835 }
1836 else {
1837 di << "Mode = " << prs->Mode() << "\n";
1838 }
1839 return 0;
1840 }
1841 }
586db386 1842 di << arg[0] << " : Error\n";
7fd59977 1843 return 1;
1844}
1845
1846//=======================================================================
1847//function : OCC1034_AISSelectionMode
1848//purpose : OCC1034_AISSelectionMode (DOC,entry,[selectionmode])
1849//=======================================================================
1850
1851static Standard_Integer OCC1034_AISSelectionMode (Draw_Interpretor& di,
1852 Standard_Integer nb,
1853 const char ** arg)
1854{
1855 if (nb >= 3) {
1856 Handle(TDocStd_Document) D;
1857 if (!DDocStd::GetDocument(arg[1],D)) return 1;
1858 TDF_Label L;
1859 if (!DDF::FindLabel(D->GetData(),arg[2],L)) return 1;
1860
1861 Handle(TPrsStd_AISViewer) viewer;
1862 if( !TPrsStd_AISViewer::Find(L, viewer) ) return 1;
1863
1864 Handle(TPrsStd_AISPresentation) prs;
1865 if(L.FindAttribute( TPrsStd_AISPresentation::GetID(), prs) ) {
1866 if( nb == 4 ) {
91322f44 1867 prs->SetSelectionMode(Draw::Atoi(arg[3]));
7fd59977 1868 TPrsStd_AISViewer::Update(L);
1869 }
1870 else {
1871 di << "SelectionMode = " << prs->SelectionMode() << "\n";
1872 }
1873 return 0;
1874 }
1875 }
586db386 1876 di << arg[0] << " : Error\n";
7fd59977 1877 return 1;
1878}
1879
7fd59977 1880//=======================================================================
1881//function : OCC1487
1882//purpose :
1883//=======================================================================
1884static Standard_Integer OCC1487 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
1885{
431d0f18 1886 if(argc != 5) {
1887 di << "Usage : " << argv[0] << " CylinderVariant(=1/2) cylinder1 cylinder2 cutshape\n";
7fd59977 1888 return 1;
1889 }
7fd59977 1890
91322f44 1891 Standard_Integer CaseNumber = Draw::Atoi(argv[1]);
7fd59977 1892
1893 //BRepPrimAPI_MakeCylinder o_mc1 (gp_Ax2 (gp_Pnt(0,-50,140), gp_Dir(1,0,0)), 50,1000);
1894 gp_Dir myDir(1,0,0);
1895 gp_Pnt myPnt(0,-50,140);
1896 gp_Ax2 myAx2(myPnt, myDir);
1897 BRepPrimAPI_MakeCylinder o_mc1 (myAx2, 50,1000);
1898
1899 TopoDS_Shape cyl1 = o_mc1.Shape();
1900
1901 TopoDS_Shape cyl2;
1902 TopoDS_Shape o_cut_shape;
1903 if (CaseNumber == 1) {
c6541a0c
D
1904 //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);
1905 gp_Dir myDir_mc2(-sin(M_PI/3), 0.0, 0.5);
7fd59977 1906 gp_Pnt myPnt_mc2(21.65064, -50.0, 127.5);
1907 gp_Ax2 myAx2_mc2(myPnt_mc2, myDir_mc2);
1908 BRepPrimAPI_MakeCylinder o_mc2 (myAx2_mc2, 5, 150);
1909
1910 cyl2 = o_mc2.Shape();
431d0f18 1911 di << "o_cut_shape = BRepAlgoAPI_Cut (o_mc1.Solid (), o_mc2.Solid ())\n";
1912 o_cut_shape = BRepAlgoAPI_Cut (o_mc1.Solid (), o_mc2.Solid ()).Shape();
7fd59977 1913 } else {
c6541a0c 1914 //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 1915 gp_Dir myDir_mc2(sin(M_PI/3), 0.0, 0.5);
1916 gp_Pnt myPnt_mc2(978.34936, -50.0, 127.5);
7fd59977 1917 gp_Ax2 myAx2_mc2(myPnt_mc2, myDir_mc2);
1918 BRepPrimAPI_MakeCylinder o_mc2 (myAx2_mc2, 5, 150);
1919
1920 cyl2 = o_mc2.Shape();
431d0f18 1921 di << "o_cut_shape = BRepAlgoAPI_Cut (o_mc1.Solid (), o_mc2.Solid ())\n";
1922 o_cut_shape = BRepAlgoAPI_Cut (o_mc1.Solid (), o_mc2.Solid ()).Shape();
7fd59977 1923 }
1924
1925 DBRep::Set(argv[2],cyl1);
1926 DBRep::Set(argv[3],cyl2);
1927 DBRep::Set(argv[4],o_cut_shape);
1928
1929 return 0;
1930}
1931
1932#include<TopTools_ListIteratorOfListOfShape.hxx>
1933#include<BRepFilletAPI_MakeFillet.hxx>
1934//=======================================================================
1935//function : OCC1077
1936//purpose :
1937//=======================================================================
1938TopoDS_Shape OCC1077_boolbl(BRepAlgoAPI_BooleanOperation& aBoolenaOperation,const Standard_Real aRadius)
1939{
1940 Standard_Real t3d = 1.e-4;
1941 Standard_Real t2d = 1.e-5;
1942 Standard_Real ta = 1.e-2;
1943 Standard_Real fl = 1.e-3;
1944 Standard_Real tapp_angle = 1.e-2;
1945 GeomAbs_Shape blend_cont = GeomAbs_C1;
1946
1947 TopoDS_Shape ShapeCut = aBoolenaOperation.Shape();
1948
7fd59977 1949 TopTools_ListIteratorOfListOfShape its;
1950
1951 TopoDS_Compound result;
1952 BRep_Builder B;
1953 B.MakeCompound(result);
1954
1955 TopExp_Explorer ex;
1956 for (ex.Init(ShapeCut, TopAbs_SOLID); ex.More(); ex.Next())
1957 {
1958 const TopoDS_Shape& cutsol = ex.Current();
1959
1960 BRepFilletAPI_MakeFillet fill(cutsol);
1961 fill.SetParams(ta, t3d, t2d, t3d, t2d, fl);
1962 fill.SetContinuity(blend_cont, tapp_angle);
7fd59977 1963 its = aBoolenaOperation.SectionEdges();
7fd59977 1964 while (its.More())
1965 {
1966 TopoDS_Edge E = TopoDS::Edge(its.Value());
1967 fill.Add(aRadius, E);
1968 its.Next();
1969 }
1970
1971 fill.Build();
1972 if (fill.IsDone())
1973 {
1974 B.Add(result, fill.Shape());
1975 }
1976 else
1977 {
1978 B.Add(result, cutsol);
1979 }
1980 }
1981 return result;
1982}
1983
1984TopoDS_Shape OCC1077_cut_blend(const TopoDS_Shape& aShapeToCut, const TopoDS_Shape& aTool, const Standard_Real aRadius)
1985{
1986 //return OCC1077_boolbl(BRepAlgoAPI_Cut(aShapeToCut, aTool),aRadius);
1987 BRepAlgoAPI_Cut aCut(aShapeToCut, aTool);
1988 return OCC1077_boolbl(aCut,aRadius);
1989}
1990
1991//TopoDS_Shape OCC1077_common_blend(const TopoDS_Shape& aShape1, const TopoDS_Shape& aShape2, const Standard_Real aRadius)
1992//{
1993// return OCC1077_boolbl(BRepAlgoAPI_Common(aShape1, aShape2),aRadius);
1994//}
1995
1996TopoDS_Shape OCC1077_Bug()
1997{
1998 TopoDS_Shape theBox = BRepPrimAPI_MakeBox(gp_Pnt(-5, - 5, - 5), 10, 10, 10).Shape();
1999 TopoDS_Shape theSphere = BRepPrimAPI_MakeSphere(7).Shape();
2000
2001 TopoDS_Shape theCommon = BRepAlgoAPI_Common(theBox,theSphere);
2002 TopoDS_Shape theCylinder1 = BRepPrimAPI_MakeCylinder(gp_Ax2(gp_Pnt(0, 0, - 10),
2003 gp_Dir(0, 0, 1)), 3, 20).Shape();
2004 TopoDS_Shape theCylinder2 = BRepPrimAPI_MakeCylinder(gp_Ax2(gp_Pnt(-10, 0, 0),
2005 gp_Dir(1, 0, 0)), 3, 20).Shape();
2006 TopoDS_Shape theCylinder3 = BRepPrimAPI_MakeCylinder(gp_Ax2(gp_Pnt(0, - 10, 0),
2007 gp_Dir(0, 1, 0)), 3, 20).Shape();
2008 TopoDS_Shape theTmp1 = OCC1077_cut_blend(theCommon,theCylinder1,0.7);
857ffd5e 2009 Handle(ShapeFix_Shape) fixer = new ShapeFix_Shape(theTmp1);
7fd59977 2010 fixer->Perform();
2011 theTmp1 = fixer->Shape();
2012 TopoDS_Shape theTmp2 = OCC1077_cut_blend(theTmp1,theCylinder2,0.7);
2013 fixer->Init(theTmp2);
2014 fixer->Perform();
2015 theTmp2 = fixer->Shape();
2016 TopoDS_Shape theResult = OCC1077_cut_blend(theTmp2,theCylinder3,0.7);
2017 fixer->Init(theResult);
2018 fixer->Perform();
2019 theResult = fixer->Shape();
2020 return theResult;
2021}
2022
2023static Standard_Integer OCC1077 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
2024{
2025 if(argc < 1 || argc > 2) {
586db386 2026 di << "Usage : " << argv[0] << " result\n";
7fd59977 2027 return 1;
2028 }
2029
2030 TopoDS_Shape S = OCC1077_Bug();
2031 DBRep::Set(argv[1],S);
2032
2033 return 0;
2034}
2035
2036//////////////////////////////////////////////////////////////
2037/*!
2038 * Compute uniform distribution of points using GCPnts_UniformAbscissa
2039 */
2040//////////////////////////////////////////////////////////////
2041static Standard_Integer OCC5739_UniAbs (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
2042{
2043 if (argc < 4)
2044 {
586db386 2045 di << "Usage : " << argv[0] << " name shape step\n";
7fd59977 2046 return 1;
2047 }
2048 const char *name = argv[1];
2049 Adaptor3d_Curve *adapCurve=NULL;
2050 Handle(Geom_Curve) curve = DrawTrSurf::GetCurve(argv[2]);
2051 if (!curve.IsNull())
2052 adapCurve = new GeomAdaptor_Curve(curve);
2053 else
2054 {
2055 TopoDS_Shape wire = DBRep::Get(argv[2]);
2056 if (wire.IsNull() || wire.ShapeType() != TopAbs_WIRE)
2057 {
586db386 2058 di << argv[0] <<" Faulty : incorrect 1st parameter, curve or wire expected\n";
7fd59977 2059 return 1;
2060 }
2061 adapCurve = new BRepAdaptor_CompCurve(TopoDS::Wire(wire));
2062 }
91322f44 2063 double step = Draw::Atof(argv[3]);
7fd59977 2064 GCPnts_UniformAbscissa aUni(*adapCurve, step);
2065 int res;
2066 if (!aUni.IsDone())
2067 {
586db386 2068 di << argv[0] <<" : fail\n";
7fd59977 2069 res = 1;
2070 }
2071 else
2072 {
2073 int i, np = aUni.NbPoints();
2074 for (i=0; i < np; i++)
2075 {
2076 double par = aUni.Parameter(i+1);
2077 gp_Pnt p = adapCurve->Value(par);
2078 char n[20], *pname=n;
91322f44 2079 Sprintf(n,"%s_%d",name,i+1);
7fd59977 2080 DrawTrSurf::Set(pname,p);
2081 di<<pname<<" ";
2082 }
2083 res = 0;
2084 }
2085 delete adapCurve;
2086 return res;
2087}
2088
2089static Standard_Integer OCC6046 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
2090{
2091 if (argc != 3)
2092 {
586db386 2093 di << "Usage : " << argv[0] << " nb_of_vectors size\n";
7fd59977 2094 return 1;
2095 }
2096
91322f44 2097 Standard_Integer nb = Draw::Atoi(argv[1]);
2098 Standard_Integer sz = Draw::Atoi(argv[2]);
7fd59977 2099 Standard_Real val = 10;
2100 math_Vector **pv = new math_Vector *[nb];
2101
586db386 2102 di<<"creating "<<nb<<" vectors "<<sz<<" elements each...\n";
7fd59977 2103 Standard_Integer i;
2104 for (i=0; i < nb; i++) {
2105 pv[i] = new math_Vector (1, sz, val);
2106 if ((i % (nb/10)) == 0) {
2107 di<<" "<<i;
04232180 2108 //std::cout.flush();
7fd59977 2109 di<<"\n";
2110 }
2111 }
586db386 2112 di<<" done\n";
2113 di<<"deleting them ...\n";
7fd59977 2114 for (i=0; i < nb; i++) {
2115 delete pv[i];
2116 if ((i % (nb/10)) == 0) {
2117 di<<" "<<i;
04232180 2118 //std::cout.flush();
7fd59977 2119 di<<"\n";
2120 }
2121 }
586db386 2122 di<<" done\n";
7fd59977 2123
2124 delete [] pv;
2125
2126 return 0;
2127}
2128
2129static Standard_Integer OCC5698 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
2130{
2131 if (argc != 2)
2132 {
586db386 2133 di << "Usage : " << argv[0] << " wire\n";
7fd59977 2134 return 1;
2135 }
2136 TopoDS_Shape shape = DBRep::Get(argv[1],TopAbs_WIRE);
2137 if (shape.IsNull())
2138 return 1;
2139 TopoDS_Wire wire = TopoDS::Wire(shape);
2140 // create curve parameterised by curvilinear distance
2141 BRepAdaptor_CompCurve curve(wire,Standard_True);
2142 Standard_Real length = curve.LastParameter();
2143 Standard_Real need_length = length/2;
2144 gp_Pnt pnt;
2145 curve.D0(need_length,pnt);
2146 // create check_curve parameterised in a general way
2147 BRepAdaptor_CompCurve check_curve(wire);
2148 Standard_Real check_par =
2149 GCPnts_AbscissaPoint(check_curve, need_length, 0).Parameter();
2150 gp_Pnt check_pnt;
2151 check_curve.D0(check_par,check_pnt);
2152 // check that points are coinsiding
2153 Standard_Real error_dist = pnt.Distance(check_pnt);
2154 if (error_dist > Precision::Confusion()) {
04232180 2155 //std::cout.precision(3);
7fd59977 2156 di<<"error_dist = "<<error_dist<<
586db386 2157 " ( "<<error_dist/need_length*100<<" %)\n";
7fd59977 2158 return 0;
2159 }
586db386 2160 di<<"OK\n";
7fd59977 2161 return 0;
2162}
2163
d538d7a2 2164// stack overflow can be successfully handled only on 32-bit Windows
2165#if defined(_WIN32) && !defined(_WIN64)
37e640d5 2166static int StackOverflow (int i = -1)
7fd59977 2167{
2168 char arr[2000];
37e640d5 2169 memset (arr, 0, sizeof(arr));
2170 if (i < 0)
2171 StackOverflow(i-1);
7fd59977 2172 return i;
2173}
d538d7a2 2174#endif
7fd59977 2175
7fd59977 2176// this code does not work with optimize mode on Windows
1bd04b5a 2177#if defined(_MSC_VER) && !defined(__clang__)
7fd59977 2178#pragma optimize( "", off )
2179#endif
2180static Standard_Integer OCC6143 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
2181{
2182 if (argc != 1)
2183 {
04232180 2184 std::cout << "Usage : " << argv[0] << "\n";
7fd59977 2185 return 1;
2186 }
2187 Standard_Boolean Succes;
2188
2189 Succes = Standard_True;
2190 //OSD::SetSignal();
2191
2192 {//==== Test Divide ByZero (Integer) ========================================
2193 try{
2194 OCC_CATCH_SIGNALS
04232180 2195 std::cout << "(Integer) Divide By Zero..." << std::endl;
7fd59977 2196 di << "(Integer) Divide By Zero...";
04232180 2197 //std::cout.flush();
7fd59977 2198 di << "\n";
2199 Standard_Integer res, a =4, b = 0 ;
2200 res = a / b;
f4dee9bb 2201 di << "Error: 4 / 0 = " << res << " - no exception is raised!\n";
7fd59977 2202 Succes = Standard_False;
2203 }
d538d7a2 2204#if defined(SOLARIS) || defined(_WIN32)
a738b534 2205 catch(Standard_DivideByZero const&)
7fd59977 2206#else
a738b534 2207 catch(Standard_NumericError const&)
7fd59977 2208#endif
2209 {
f4dee9bb 2210 di << "Caught, OK\n";
7fd59977 2211 }
9775fa61 2212 catch(Standard_Failure const& anException) {
7fd59977 2213 di << " Caught (";
9775fa61 2214 di << anException.GetMessageString();
586db386 2215 di << ")... KO\n";
7fd59977 2216 Succes = Standard_False;
2217 }
7fd59977 2218 // this case tests if (...) supersedes (Standard_*),
2219 // the normal behaviour is not
2220 catch(...) {
586db386 2221 di<<" unknown exception... (But) Ok\n";
7fd59977 2222 }
7fd59977 2223 }
2224
2225 {//==== Test Divide ByZero (Real) ===========================================
2226 try{
2227 OCC_CATCH_SIGNALS
04232180 2228 std::cout << "(Real) Divide By Zero..." << std::endl;
7fd59977 2229 di << "(Real) Divide By Zero...";
04232180 2230 //std::cout.flush();
7fd59977 2231 di << "\n";
2232 Standard_Real res, a= 4.0, b=0.0;
2233 res = a / b;
f4dee9bb 2234 di << "Error: 4.0 / 0.0 = " << res << " - no exception is raised!\n";
2235 Succes = Standard_False;
7fd59977 2236 }
a738b534 2237 catch(Standard_DivideByZero const&) // Solaris, Windows w/o SSE2
7fd59977 2238 {
f4dee9bb 2239 di << "Caught, OK\n";
11fca7c1 2240 }
a738b534 2241 catch(Standard_NumericError const&) // Linux, Windows with SSE2
11fca7c1 2242 {
c381fda2 2243 di << "Caught, OK\n";
7fd59977 2244 }
9775fa61 2245 catch(Standard_Failure const& anException) {
04232180 2246 //std::cout << " Caught (" << Standard_Failure::Caught() << ")... KO" << std::endl;
7fd59977 2247 di << " Caught (";
9775fa61 2248 di << anException.GetMessageString();
586db386 2249 di << ")... KO\n";
7fd59977 2250 Succes = Standard_False;
2251 }
2252 }
2253
2254 {//==== Test Overflow (Integer) =============================================
2255 try{
2256 OCC_CATCH_SIGNALS
04232180 2257 std::cout << "(Integer) Overflow..." << std::endl;
7fd59977 2258 di << "(Integer) Overflow...";
04232180 2259 //std::cout.flush();
7fd59977 2260 di << "\n";
2261 Standard_Integer res, i=IntegerLast();
2262 res = i + 1;
04232180 2263 //++++ std::cout << " -- "<<res<<"="<<i<<"+1 Does not Caught... KO"<< std::endl;
7fd59977 2264 //++++ Succes = Standard_False;
f4dee9bb 2265 di << "Not caught: " << i << " + 1 = " << res << ", still OK\n";
7fd59977 2266 }
a738b534 2267 catch(Standard_Overflow const&) {
f4dee9bb 2268 di << "Caught, OK\n";
7fd59977 2269 }
9775fa61 2270 catch(Standard_Failure const& anException) {
04232180 2271 //std::cout << " Caught (" << Standard_Failure::Caught() << ")... KO" << std::endl;
7fd59977 2272 di << " Caught (";
9775fa61 2273 di << anException.GetMessageString();
586db386 2274 di << ")... KO\n";
7fd59977 2275 Succes = Standard_False;
2276 }
2277 }
2278
2279 {//==== Test Overflow (Real) ================================================
2280 try{
2281 OCC_CATCH_SIGNALS
04232180 2282 std::cout << "(Real) Overflow..." << std::endl;
7fd59977 2283 di << "(Real) Overflow...";
04232180 2284 //std::cout.flush();
7fd59977 2285 di << "\n";
2286 Standard_Real res, r=RealLast();
2287 res = r * r;
2288
31249d19 2289 (void)sin(1.); //this function tests FPU flags and raises signal (tested on LINUX).
7fd59977 2290
f4dee9bb 2291 di << "Error: " << r << "*" << r << " = " << res << " - no exception is raised!\n";
2292 Succes = Standard_False;
7fd59977 2293 }
a738b534 2294 catch(Standard_Overflow const&) // Solaris, Windows w/o SSE2
7fd59977 2295 {
f4dee9bb 2296 di << "Caught, OK\n";
11fca7c1 2297 }
a738b534 2298 catch(Standard_NumericError const&) // Linux, Windows with SSE2
11fca7c1 2299 {
f4dee9bb 2300 di << "Caught, OK\n";
7fd59977 2301 }
9775fa61 2302 catch(Standard_Failure const& anException) {
04232180 2303 //std::cout << " Caught (" << Standard_Failure::Caught() << ")... KO" << std::endl;
7fd59977 2304 di << " Caught (";
9775fa61 2305 di << anException.GetMessageString();
586db386 2306 di << ")... KO\n";
7fd59977 2307 Succes = Standard_False;
2308 }
2309 }
2310
2311 {//==== Test Underflow (Real) ===============================================
2312 try{
2313 OCC_CATCH_SIGNALS
04232180 2314 std::cout << "(Real) Underflow" << std::endl; // to have message in log even if process crashed
7fd59977 2315 di << "(Real) Underflow";
04232180 2316 //std::cout.flush();
7fd59977 2317 di << "\n";
cf0786da 2318 Standard_Real res, r = RealSmall();
7fd59977 2319 res = r * r;
2320 //res = res + 1.;
04232180 2321 //++++ std::cout<<"-- "<<res<<"="<<r<<"*"<<r<<" Does not Caught... KO"<<std::endl;
7fd59977 2322 //++++ Succes = Standard_False;
f4dee9bb 2323 di << "Not caught: " << r << "*" << r << " = " << res << ", still OK\n";
7fd59977 2324 }
a738b534 2325 catch(Standard_Underflow const&) // could be on Solaris, Windows w/o SSE2
7fd59977 2326 {
f4dee9bb 2327 di << "Exception caught, KO\n";
d538d7a2 2328 Succes = Standard_False;
11fca7c1 2329 }
a738b534 2330 catch(Standard_NumericError const&) // could be on Linux, Windows with SSE2
11fca7c1 2331 {
f4dee9bb 2332 di << "Exception caught, KO\n";
d538d7a2 2333 Succes = Standard_False;
7fd59977 2334 }
9775fa61 2335 catch(Standard_Failure const& anException) {
04232180 2336 //std::cout << " Caught (" << Standard_Failure::Caught() << ")... KO" << std::endl;
7fd59977 2337 di << " Caught (";
9775fa61 2338 di << anException.GetMessageString();
586db386 2339 di << ")... KO\n";
7fd59977 2340 Succes = Standard_False;
2341 }
2342 }
2343
2344 {//==== Test Invalid Operation (Real) ===============================================
2345 try{
2346 OCC_CATCH_SIGNALS
04232180 2347 std::cout << "(Real) Invalid Operation..." << std::endl;
7fd59977 2348 di << "(Real) Invalid Operation...";
04232180 2349 //std::cout.flush();
7fd59977 2350 di << "\n";
2351 Standard_Real res, r=-1;
2352 res = sqrt(r);
f4dee9bb 2353 di << "Error: swrt(-1) = " << res << " - no exception is raised!\n";
2354 Succes = Standard_False;
7fd59977 2355 }
a738b534 2356 catch(Standard_NumericError const&) {
f4dee9bb 2357 di << "Caught, OK\n";
7fd59977 2358 }
9775fa61 2359 catch(Standard_Failure const& anException) {
04232180 2360 //std::cout << " Caught (" << Standard_Failure::Caught() << ")... KO" << std::endl;
7fd59977 2361 di << " Caught (";
9775fa61 2362 di << anException.GetMessageString();
586db386 2363 di << ")... KO\n";
7fd59977 2364 Succes = Standard_False;
2365 }
2366 }
2367
2368 {//==== Test Access Violation ===============================================
2369 try {
2370 OCC_CATCH_SIGNALS
04232180 2371 std::cout << "Segmentation Fault..." << std::endl;
7fd59977 2372 di << "Segmentation Fault...";
04232180 2373 //std::cout.flush();
7fd59977 2374 di << "\n";
2375 int* pint=NULL;
2376 *pint = 4;
f4dee9bb 2377 di << "Error: writing by NULL address - no exception is raised!\n";
7fd59977 2378 Succes = Standard_False;
2379 }
d538d7a2 2380#ifdef _WIN32
a738b534 2381 catch(OSD_Exception_ACCESS_VIOLATION const&)
7fd59977 2382#else
a738b534 2383 catch(OSD_SIGSEGV const&)
7fd59977 2384#endif
2385 {
f4dee9bb 2386 di << "Caught, OK\n";
9775fa61 2387 } catch(Standard_Failure const& anException) {
04232180 2388 //std::cout << " Caught (" << Standard_Failure::Caught() << ")... KO" << std::endl;
7fd59977 2389 di << " Caught (";
9775fa61 2390 di << anException.GetMessageString();
586db386 2391 di << ")... KO\n";
7fd59977 2392 Succes = Standard_False;
2393 }
2394 }
2395
d538d7a2 2396#if defined(_WIN32) && !defined(_WIN64)
7fd59977 2397 {//==== Test Stack Overflow ===============================================
2398 try {
2399 OCC_CATCH_SIGNALS
04232180 2400 std::cout << "Stack Overflow..." << std::endl;
7fd59977 2401 di << "Stack Overflow...";
04232180 2402 //std::cout.flush();
7fd59977 2403 di << "\n";
2404 StackOverflow();
f4dee9bb 2405 di << "Error - no exception is raised!\n";
7fd59977 2406 Succes = Standard_False;
2407 }
a738b534 2408 catch(OSD_Exception_STACK_OVERFLOW const&) {
f4dee9bb 2409 di << "Caught, OK\n";
7fd59977 2410 }
d1d3e057 2411 catch(Standard_Failure const& anException) {
04232180 2412 //std::cout << " Caught (" << Standard_Failure::Caught() << ")... KO" << std::endl;
7fd59977 2413 di << " Caught (";
d1d3e057 2414 di << anException.GetMessageString();
586db386 2415 di << ")... KO\n";
7fd59977 2416 Succes = Standard_False;
2417 }
2418 }
2419#endif
2420
2421 if(Succes) {
586db386 2422 di << "TestExcept: Successfull completion\n";
7fd59977 2423 } else {
586db386 2424 di << "TestExcept: failure\n";
7fd59977 2425 }
2426
2427 return 0;
2428}
44b80414 2429
2430//! Auxiliary functor.
2431struct TestParallelFunctor
2432{
2433 TestParallelFunctor() : myNbNotRaised (0), myNbSigSegv (0), myNbUnknown (0) {}
2434
2435 Standard_Integer NbNotRaised() const { return myNbNotRaised; }
2436 Standard_Integer NbSigSegv() const { return myNbSigSegv; }
2437 Standard_Integer NbUnknown() const { return myNbUnknown; }
2438
2439 void operator() (int theThreadId, int theTaskId) const
2440 {
2441 (void )theThreadId;
2442 (void )theTaskId;
2443
2444 // Test Access Violation
2445 {
2446 try {
2447 OCC_CATCH_SIGNALS
2448 int* pint = NULL;
2449 *pint = 4;
2450 Standard_Atomic_Increment (&myNbNotRaised);
2451 }
2452 #ifdef _WIN32
2453 catch (OSD_Exception_ACCESS_VIOLATION const&)
2454 #else
2455 catch (OSD_SIGSEGV const&)
2456 #endif
2457 {
2458 Standard_Atomic_Increment (&myNbSigSegv);
2459 }
2460 catch (Standard_Failure const& )
2461 {
2462 Standard_Atomic_Increment (&myNbUnknown);
2463 }
2464 }
2465 }
2466private:
2467 mutable volatile Standard_Integer myNbNotRaised;
2468 mutable volatile Standard_Integer myNbSigSegv;
2469 mutable volatile Standard_Integer myNbUnknown;
2470};
2471
2472static Standard_Integer OCC30775 (Draw_Interpretor& theDI, Standard_Integer theNbArgs, const char** )
2473{
2474 if (theNbArgs != 1)
2475 {
2476 std::cout << "Syntax error: wrong number of arguments\n";
2477 return 1;
2478 }
2479
2480 Handle(OSD_ThreadPool) aPool = new OSD_ThreadPool (4);
2481 OSD_ThreadPool::Launcher aLauncher (*aPool, 4);
2482 TestParallelFunctor aFunctor;
2483 aLauncher.Perform (0, 100, aFunctor);
2484 theDI << "NbRaised: " << (aFunctor.NbSigSegv() + aFunctor.NbUnknown()) << "\n"
2485 << "NbNotRaised: " << aFunctor.NbNotRaised() << "\n"
2486 << "NbSigSeg: " << aFunctor.NbSigSegv() << "\n"
2487 << "NbUnknown: " << aFunctor.NbUnknown() << "\n";
2488 return 0;
2489}
2490
1bd04b5a 2491#if defined(_MSC_VER) && !defined(__clang__)
7fd59977 2492#pragma optimize( "", on )
2493#endif
2494
2495static TopoDS_Compound AddTestStructure(int nCount_)
2496{
2497 BRep_Builder B;
2498 int nCount=nCount_;
2499 TopoDS_Compound C;
2500 B.MakeCompound(C);
2501 BRepPrimAPI_MakeBox mkBox(1.0, 2.0, 3.0);
2502 for (int i=0; i<nCount; i++) {
2503 for (int j=0; j<nCount; j++) {
2504 gp_Trsf trsf;
2505 trsf.SetTranslationPart(gp_Vec(5.0*i, 05.0*j, 0.0));
2506 TopLoc_Location topLoc(trsf);
2507 TopoDS_Shape tempShape=mkBox.Shape().Located(topLoc);
2508 B.Add(C, tempShape);
2509 }
2510 }
2511 return C;
2512}
2513
2514static Standard_Integer OCC7141 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
2515{
c48e2889 2516 if (argc != 2 && argc != 3)
2517 {
2518 std::cout << "Usage : " << argv[0] << " [nCount] path\n";
2519 return 1;
2520 }
7fd59977 2521
c48e2889 2522 int nCount = (argc > 2 ? Draw::Atoi(argv[1]) : 10);
2523 TCollection_AsciiString aFilePath (argv[argc > 2 ? 2 : 1]);
7fd59977 2524 STEPCAFControl_Writer writer;
857ffd5e 2525 Handle(TDocStd_Document) document;
7fd59977 2526 document = new TDocStd_Document("Pace Test-StepExporter-");
857ffd5e 2527 Handle(XCAFDoc_ShapeTool) shapeTool;
7fd59977 2528 shapeTool = XCAFDoc_DocumentTool::ShapeTool(document->Main());
2529 shapeTool->AddShape(AddTestStructure(nCount), Standard_True);
2530 STEPControl_StepModelType mode = STEPControl_AsIs;
2531 if (!Interface_Static::SetIVal("write.step.assembly",1)) { //assembly mode
586db386 2532 di << "Failed to set assembly mode for step data\n\n";
7fd59977 2533 return 0;
2534 }
2535 try {
2536 OCC_CATCH_SIGNALS
2537 if( writer.Transfer(document, mode)) {
302f96fb 2538 writer.Write(aFilePath.ToCString());
7fd59977 2539 }
2540 }
a738b534 2541 catch(OSD_Exception_STACK_OVERFLOW const&) {
586db386 2542 di << "Failed : STACK OVERFLOW\n\n";
7fd59977 2543 }
9775fa61 2544 catch (Standard_Failure const& anException) {
586db386 2545 di << "Failed :\n\n";
04232180 2546 //std::cout << Standard_Failure::Caught() << std::endl;
9775fa61 2547 di << anException.GetMessageString();
7fd59977 2548 }
586db386 2549 di << argv[0] << " : Finish\n";
7fd59977 2550
2551 return 0;
2552}
2553
2554static Standard_Integer OCC7372 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
2555{
2556 if (argc != 1)
2557 {
2558 di << "Usage : " << argv[0] << "\n";
2559 return 1;
2560 }
2561
2562 // 1. Create an array of points
2563 Handle(TColgp_HArray1OfPnt2d) ap = new TColgp_HArray1OfPnt2d(1,5);
2564 ap->SetValue(1,gp_Pnt2d(100.0,0.0));
2565 ap->SetValue(2,gp_Pnt2d(100.0,100.0));
2566 ap->SetValue(3,gp_Pnt2d(0.0,100.0));
2567 ap->SetValue(4,gp_Pnt2d(0.0,0.0));
2568 ap->SetValue(5,gp_Pnt2d(50.0,-50.0));
2569
2570 // 2. Create a periodic bspline through these 5 points
2571 Geom2dAPI_Interpolate intp(ap,Standard_True,1e-6);
2572 intp.Perform();
2573 Handle(Geom2d_BSplineCurve) bspline1 = intp.Curve();
2574
2575 // 3. Increase degree of curve from 3 to 8
2576 bspline1->IncreaseDegree(8); // Increase degree to demonstrate the error
2577 Standard_CString CString1 = "BSplineCurve";
2578 DrawTrSurf::Set(CString1,bspline1);
2579
2580 // 4. Convers BSpline curve to Bezier segments
2581 Geom2dConvert_BSplineCurveToBezierCurve bc(bspline1);
2582
2583 // 5. Test the result of conversion
2584 TCollection_AsciiString aRName;
2585 for(Standard_Integer i = 1; i <= bc.NbArcs(); i++) {
2586 Handle(Geom2d_BezierCurve) arc = bc.Arc(i);
2587 aRName="segment_";
2588 aRName=aRName+TCollection_AsciiString(i);
2589 Standard_CString aRNameStr = aRName.ToCString();
2590 DrawTrSurf::Set(aRNameStr,arc);
2591 di << aRNameStr << " ";
2592 }
2593
2594 return 0;
2595}
2596
2597static Standard_Integer OCC8169 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
2598{
2599 if (argc != 4)
2600 {
586db386 2601 di << "Usage : " << argv[0] << " edge1 edge2 plane\n";
7fd59977 2602 return 1;
2603 }
2604 TopoDS_Edge theEdge1 = TopoDS::Edge(DBRep::Get(argv[1],TopAbs_EDGE));
2605 if (theEdge1.IsNull()) {
2606 di << "Invalid input shape " << argv[1] << "\n";
2607 return 1;
2608 }
2609 TopoDS_Edge theEdge2 = TopoDS::Edge(DBRep::Get(argv[2],TopAbs_EDGE));
2610 if (theEdge2.IsNull()) {
2611 di << "Invalid input shape " << argv[2] << "\n";
2612 return 1;
2613 }
2614 TopoDS_Face theFace = TopoDS::Face(DBRep::Get(argv[3],TopAbs_FACE));
2615 if (theFace.IsNull()) {
2616 di << "Invalid input shape " << argv[3] << "\n";
2617 return 1;
2618 }
2619
2620 Handle(Geom_Surface) thePlane = BRep_Tool::Surface(theFace);
2621
2622 Standard_Real aConfusion = Precision::Confusion();
2623 Standard_Real aP1first, aP1last, aP2first, aP2last;
2624
2625 Handle(Geom_Curve) aCurve1 = BRep_Tool::Curve(theEdge1, aP1first, aP1last);
2626 Handle(Geom_Curve) aCurve2 = BRep_Tool::Curve(theEdge2, aP2first, aP2last);
2627 Handle(Geom2d_Curve) aCurve2d1 = GeomProjLib::Curve2d(aCurve1, aP1first, aP1last, thePlane);
2628 Handle(Geom2d_Curve) aCurve2d2 = GeomProjLib::Curve2d(aCurve2, aP2first, aP2last, thePlane);
2629
2630 Geom2dAPI_InterCurveCurve anInter(aCurve2d1, aCurve2d2, aConfusion);
2631
2632 Standard_Integer NbPoints = anInter.NbPoints();
2633
2634 di << "NbPoints = " << NbPoints << "\n" ;
2635
2636 if (NbPoints > 0) {
2637 Standard_Integer i;
2638 for (i=1; i<=NbPoints; i++) {
2639 gp_Pnt2d aPi = anInter.Point(i);
586db386 2640 di << "Point.X(" << i << ") = " << aPi.X() << " Point.Y(" << i << ") = " << aPi.Y() << "\n" ;
7fd59977 2641 }
2642 }
2643
2644 Standard_Integer NbSegments = anInter.NbSegments();
2645
2646 di << "\nNbSegments = " << NbSegments << "\n" ;
2647
2648 if (NbSegments > 0) {
2649 IntRes2d_IntersectionSegment aSegment = anInter.Intersector().Segment(1);
2650
2651 gp_Pnt2d aP1 = aCurve2d1->Value(aSegment.FirstPoint().ParamOnFirst());
2652 gp_Pnt2d aP2 = aCurve2d2->Value(aSegment.FirstPoint().ParamOnSecond());
2653
2654 Standard_Real aDist = aP1.Distance(aP2);
2655
586db386 2656 di << "aP1.X() = " << aP1.X() << " aP1.Y() = " << aP1.Y() << "\n" ;
2657 di << "aP2.X() = " << aP2.X() << " aP2.Y() = " << aP2.Y() << "\n" ;
7fd59977 2658
2659 di << "Distance = " << aDist << "\n" ;
2660
2661 di << "Confusion = " << aConfusion << "\n" ;
2662
2663 if (aDist > aConfusion) {
586db386 2664 di << "\n" << argv[0] << " Faulty\n" ;
7fd59977 2665 } else {
586db386 2666 di << "\n" << argv[0] << " OK\n" ;
7fd59977 2667 }
2668 } else {
586db386 2669 di << "\n" << argv[0] << " OK\n" ;
7fd59977 2670 }
2671
2672 return 0;
2673}
2674static Standard_Integer OCC10138 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
2675{
2676 if (argc != 3)
2677 {
586db386 2678 di << "Usage : " << argv[0] << " lower upper\n";
7fd59977 2679 return 1;
2680 }
2681
91322f44 2682 Standard_Integer LOWER = Draw::Atoi(argv[1]);
2683 Standard_Integer UPPER = Draw::Atoi(argv[2]);
7fd59977 2684
2685 //! 0. Create an empty document with several test labels
2686 Handle(TDocStd_Document) doc = new TDocStd_Document("XmlOcaf");
2687 doc->SetUndoLimit(100);
2688 TDF_Label main_label = doc->Main();
2689 TDF_Label label1 = main_label.FindChild(1, Standard_True);
2690 TDF_Label label2 = main_label.FindChild(2, Standard_True);
2691
2692 //! 1. Set/Get OCAF attribute
2693 doc->OpenCommand();
2694 TDataStd_RealArray::Set(label1, LOWER, UPPER);
2695 Handle(TDataStd_RealArray) array;
2696 if (label1.FindAttribute(TDataStd_RealArray::GetID(), array) &&
2697 array->Lower() == LOWER && array->Upper() == UPPER)
04232180 2698 std::cout<<"1: OK"<<std::endl;
7fd59977 2699 else
2700 {
04232180 2701 std::cout<<"1: Failed.."<<std::endl;
7fd59977 2702 return 1;
2703 }
2704 doc->CommitCommand();
2705
2706 //! 2. Set/Get value
2707 doc->OpenCommand();
2708 Standard_Integer i;
2709 for (i = LOWER; i <= UPPER; i++)
2710 array->SetValue(i, i);
2711 for (i = LOWER; i <= UPPER; i++)
2712 {
2713 if (array->Value(i) != i)
2714 {
04232180 2715 std::cout<<"2: Failed.."<<std::endl;
7fd59977 2716 return 2;
2717 }
2718 }
04232180 2719 std::cout<<"2: OK"<<std::endl;
7fd59977 2720 doc->CommitCommand();
2721
2722 //! 3. Re-init the array
2723 doc->OpenCommand();
2724 array->Init(LOWER + 2, UPPER + 4);
2725 if (array->Lower() != LOWER + 2 && array->Upper() != UPPER + 4)
2726 {
04232180 2727 std::cout<<"3: Failed.."<<std::endl;
7fd59977 2728 return 3;
2729 }
2730 for (i = LOWER + 2; i <= UPPER + 4; i++)
2731 array->SetValue(i, i);
2732 for (i = LOWER + 2; i <= UPPER + 4; i++)
2733 {
2734 if (array->Value(i) != i)
2735 {
04232180 2736 std::cout<<"3: Failed.."<<std::endl;
7fd59977 2737 return 3;
2738 }
2739 }
04232180 2740 std::cout<<"3: OK"<<std::endl;
7fd59977 2741 doc->CommitCommand();
2742
2743 //! 4. Change array
2744 doc->OpenCommand();
2745 Handle(TColStd_HArray1OfReal) arr = new TColStd_HArray1OfReal(LOWER + 5, UPPER + 5);
2746 for (i = LOWER + 5; i <= UPPER + 5; i++)
2747 arr->SetValue(i, i);
2748 array->ChangeArray(arr);
2749 for (i = LOWER + 5; i <= UPPER + 5; i++)
2750 {
2751 if (array->Value(i) != i)
2752 {
04232180 2753 std::cout<<"4: Failed.."<<std::endl;
7fd59977 2754 return 4;
2755 }
2756 }
04232180 2757 std::cout<<"4: OK"<<std::endl;
7fd59977 2758 doc->CommitCommand();
2759
2760 //! 5. Copy the array
2761 doc->OpenCommand();
2762 TDF_CopyLabel copier(label1, label2);
2763 copier.Perform();
2764 if (!copier.IsDone())
2765 {
04232180 2766 std::cout<<"5: Failed.."<<std::endl;
7fd59977 2767 return 5;
2768 }
2769 Handle(TDataStd_RealArray) array2;
2770 if (!label2.FindAttribute(TDataStd_RealArray::GetID(), array2))
2771 {
04232180 2772 std::cout<<"5: Failed.."<<std::endl;
7fd59977 2773 return 5;
2774 }
2775 for (i = LOWER + 5; i <= UPPER + 5; i++)
2776 {
2777 if (array->Value(i) != i)
2778 {
04232180 2779 std::cout<<"5: Failed.."<<std::endl;
7fd59977 2780 return 5;
2781 }
2782 }
04232180 2783 std::cout<<"5: OK"<<std::endl;
7fd59977 2784 doc->CommitCommand();
2785
2786 //! 6. Undo/Redo
2787 //! 6.a: undoes the 5th action: the copied array should disappear
2788 doc->Undo();
2789 if (!label1.FindAttribute(TDataStd_RealArray::GetID(), array) ||
2790 label2.FindAttribute(TDataStd_RealArray::GetID(), array2))
2791 {
04232180 2792 std::cout<<"6.a: Failed.."<<std::endl;
7fd59977 2793 return 6;
2794 }
2795 //! 6.b: undoes the 4th action: the array should be changed to (lower+2,upper+4)
2796 doc->Undo();
2797 if (!label1.FindAttribute(TDataStd_RealArray::GetID(), array) ||
2798 array->Lower() != LOWER + 2 ||
2799 array->Upper() != UPPER + 4)
2800 {
04232180 2801 std::cout<<"6.b: Failed.."<<std::endl;
7fd59977 2802 return 6;
2803 }
2804 for (i = LOWER + 2; i <= UPPER + 4; i++)
2805 {
2806 if (array->Value(i) != i)
2807 {
04232180 2808 std::cout<<"6.b: Failed.."<<std::endl;
7fd59977 2809 return 6;
2810 }
2811 }
2812 //! 6.c: undoes the 3d action: the array should be changed to (lower,upper)
2813 doc->Undo();
2814 if (!label1.FindAttribute(TDataStd_RealArray::GetID(), array) ||
2815 array->Lower() != LOWER ||
2816 array->Upper() != UPPER)
2817 {
04232180 2818 std::cout<<"6.c: Failed.."<<std::endl;
7fd59977 2819 return 6;
2820 }
2821 for (i = LOWER; i <= UPPER; i++)
2822 {
2823 if (array->Value(i) != i)
2824 {
04232180 2825 std::cout<<"6.c: Failed.."<<std::endl;
7fd59977 2826 return 6;
2827 }
2828 }
2829 //! 6.d: undoes and redoes the 2nd action: no change is expected.
2830 doc->Undo();
2831 doc->Redo();
2832 if (!label1.FindAttribute(TDataStd_RealArray::GetID(), array) ||
2833 array->Lower() != LOWER ||
2834 array->Upper() != UPPER)
2835 {
04232180 2836 std::cout<<"6.d: Failed.."<<std::endl;
7fd59977 2837 return 6;
2838 }
2839 for (i = LOWER; i <= UPPER; i++)
2840 {
2841 if (array->Value(i) != i)
2842 {
04232180 2843 std::cout<<"6.d: Failed.."<<std::endl;
7fd59977 2844 return 6;
2845 }
2846 }
04232180 2847 std::cout<<"6: OK"<<std::endl;
7fd59977 2848
2849 //! 7. Re-set the array
2850 doc->OpenCommand();
2851 array = TDataStd_RealArray::Set(label1, LOWER + 1, UPPER + 1);
2852 if (array->Lower() != LOWER + 1 && array->Upper() != UPPER + 1)
2853 {
04232180 2854 std::cout<<"7: Failed.."<<std::endl;
7fd59977 2855 return 7;
2856 }
2857 for (i = LOWER + 1; i <= UPPER + 1; i++)
2858 array->SetValue(i, i);
2859 for (i = LOWER + 1; i <= UPPER + 1; i++)
2860 {
2861 if (array->Value(i) != i)
2862 {
04232180 2863 std::cout<<"7: Failed.."<<std::endl;
7fd59977 2864 return 7;
2865 }
2866 }
04232180 2867 std::cout<<"7: OK"<<std::endl;
7fd59977 2868 doc->CommitCommand();
2869
2870 //! 8.Test of speed: set LOWER and UPPER equal to great integer number and
2871 //! measure the time spent by this test.
2872 //! Good luck!
2873
2874 return 0;
2875}
2876
2877static Standard_Integer OCC7639 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
2878{
2879 Standard_Boolean IsEvenArgc = Standard_True;
2880 if (argc % 2 == 0) {
2881 IsEvenArgc = Standard_True;
2882 } else {
2883 IsEvenArgc = Standard_False;
2884 }
2885
2886 if (argc < 3 || IsEvenArgc)
2887 {
586db386 2888 di << "Usage : " << argv[0] << " index1 value1 ... [indexN valueN]\n";
7fd59977 2889 return 1;
2890 }
2891
2892 Standard_Integer i, aValue, aPosition;
2893 NCollection_Vector<int> vec;
2894 for (i = 0; i < argc - 1; i++) {
2895 i++;
91322f44 2896 aValue = Draw::Atoi(argv[i]);
2897 aPosition = Draw::Atoi(argv[i+1]);
7fd59977 2898 vec.SetValue(aValue, aPosition);
2899 }
2900 NCollection_Vector<int>::Iterator it(vec);
2901 Standard_Integer j;
2902 for (j = 0; it.More(); it.Next(), j++) {
2903 //di << it.Value() << "\n";
2904 di << j << " " << it.Value() << "\n";
2905 }
2906
2907 return 0;
2908}
2909
2910static Standard_Integer OCC8797 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
2911{
2912 if (argc != 1) {
2913 di << "Usage : " << argv[0] << "\n";
2914 return 1;
2915 }
2916
2917 gp_Pnt point(0.0,0.0,0.0);
2918
2919 TColgp_Array1OfPnt poles(0,6);
2920 poles(0)=point;
2921
2922 point.SetCoord(1.0,1.0,0.0);
2923 poles(1)=point;
2924
2925 point.SetCoord(2.0,1.0,0.0);
2926 poles(2)=point;
2927
2928 point.SetCoord(3.0,0.0,0.0);
2929 poles(3)=point;
2930
2931 point.SetCoord(4.0,1.0,0.0);
2932 poles(4)=point;
2933
2934 point.SetCoord(5.0,1.0,0.0);
2935 poles(5)=point;
2936
2937 point.SetCoord(6.0,0.0,0.0);
2938 poles(6)=point;
2939
2940 TColStd_Array1OfReal knots(0,2);
2941 knots(0)=0.0;
2942 knots(1)=0.5;
2943 knots(2)=1.0;
2944
2945 TColStd_Array1OfInteger multi(0,2);
2946 multi(0)=4;
2947 multi(1)=3;
2948 multi(2)=4;
2949
2950 Handle(Geom_BSplineCurve) spline = new Geom_BSplineCurve(poles,knots,multi,3);
2951
2952 //length!! 1.
2953 Standard_Real l_abcissa,l_gprop;
2954 GeomAdaptor_Curve adaptor_spline(spline);
2955 GCPnts_AbscissaPoint temp;
2956 l_abcissa=temp.Length(adaptor_spline);
04232180 2957 std::cout<<"Length Spline(abcissa_Pnt): "<<l_abcissa<<std::endl;
7fd59977 2958
2959 //length!! 2.
2960 TopoDS_Edge edge = BRepBuilderAPI_MakeEdge (spline);
2961 GProp_GProps prop;
2962 BRepGProp::LinearProperties(edge,prop);
2963 l_gprop=prop.Mass();
04232180 2964 std::cout<<"Length Spline(GProp_GProps): "<<l_gprop<<std::endl;
7fd59977 2965
04232180 2966 std::cout<<"Difference (abcissa_Pnt<->GProp_GProps): "<<l_gprop-l_abcissa<<std::endl;
7fd59977 2967
2968 return 0;
2969}
2970
2971static Standard_Integer OCC7068 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
2972{
2973 if (argc != 1)
2974 {
2975 di << "Usage : " << argv[0] << "\n";
2976 return 1;
2977 }
2978
2979 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
2980 if(AISContext.IsNull())
2981 {
2982 di << "use 'vinit' command before " << argv[0] << "\n";
2983 return 1;
2984 }
2985
2986 // ObjectsInside
2987 AIS_ListOfInteractive ListOfIO_1;
2988 AISContext->ObjectsInside(ListOfIO_1);
2989 di<< "ObjectsInside = " << ListOfIO_1.Extent() <<"\n";
2990 if (!ListOfIO_1.IsEmpty() ) {
2991 AIS_ListIteratorOfListOfInteractive iter;
2992 for (iter.Initialize(ListOfIO_1); iter.More() ; iter.Next() ) {
2993 Handle(AIS_InteractiveObject) aIO=iter.Value();
2994 di<< GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
2995 }
2996 }
2997
7fd59977 2998 return 0;
2999}
3000
3001static Standard_Integer OCC11457 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
3002{
3003 if ((argc < 9) || (((argc-3) % 3) != 0))
3004 {
3005 di << "Usage : " << argv[0] << "polygon lastedge x1 y1 z1 x2 y2 z2 ...\n";
3006 return 1;
3007 }
3008 Standard_Integer i, j, np = (argc-3) / 3;
3009 BRepBuilderAPI_MakePolygon W;
3010 j = 3;
3011 for (i = 1; i <= np; i ++) {
91322f44 3012 W.Add(gp_Pnt(Draw::Atof(argv[j]),Draw::Atof(argv[j+1]),Draw::Atof(argv[j+2])));
7fd59977 3013 j += 3;
3014 }
3015 W.Close();
3016 DBRep::Set(argv[1],W.Wire());
3017 DBRep::Set(argv[2],W.Edge());
3018 return 0;
3019}
3020
3021static Standard_Integer OCC13963 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
3022{
3023 if (argc < 5) {
3024 di << "Usage : " << argv[0] << " ratio origin_x origin_y origin_z\n";
3025 return 1;
3026 }
3027 gp_Ax2 aPln (gp_Pnt(0.,0.,0.),
3028 gp_Dir(1., -1., 0.));
3029 gp_GTrsf aTrf;
91322f44 3030 aTrf.SetAffinity (aPln, Draw::Atof(argv[4]));
3031 gp_XYZ aOrigin (Draw::Atof(argv[1]),Draw::Atof(argv[2]),Draw::Atof(argv[3]));
7fd59977 3032 gp_XYZ aResult (aOrigin);
3033 aTrf.Transforms(aResult);
3034 char sbf[512];
91322f44 3035 Sprintf(sbf, "( %8.3f %8.3f %8.3f ) => ( %8.3f %8.3f %8.3f )\n",
7fd59977 3036 aOrigin.X(), aOrigin.Y(), aOrigin.Z(),
3037 aResult.X(), aResult.Y(), aResult.Z());
3038 di<<sbf;
3039 return 0;
3040}
3041
3042Standard_Integer OCC14376(Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
3043{
3044 if (argc < 2) {
3045 di << "Usage : " << argv[0] << " shape [deflection]\n";
3046 return 1;
3047 }
3048
3049 TopoDS_Shape aShape = DBRep::Get(argv[1]);
3050
3051 if (aShape.IsNull()) {
3052 di<<" Null shape is not allowed";
3053 return 1;
3054 }
3055
3056 Standard_Real aDeflection = 0.45110277533;
3057 if (argc > 2) {
91322f44 3058 aDeflection = Draw::Atof(argv[2]);
7fd59977 3059 }
3060 di<<"deflection="<< aDeflection << "\n";
3061
14434f3e 3062 BRepMesh_IncrementalMesh aIMesh(aShape, aDeflection, Standard_False, M_PI / 9.);
7fd59977 3063 TopLoc_Location aLocation;
3064 Handle(Poly_Triangulation) aTriang = BRep_Tool::Triangulation(TopoDS::Face(aShape), aLocation);
3065
3066 if(aTriang.IsNull()) {
3067 di << argv[0] << " : Faulty\n" ;
3068 } else {
3069 di << argv[0] << " : OK\n" ;
3070 di<<"NbNodes="<< aTriang->NbNodes()<< "\n";
3071 di<<"NbTriangles="<< aTriang->NbTriangles()<< "\n";
3072 }
3073 return 0;
3074}
3075
3076static Standard_Integer OCC15489 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
3077{
3078 if (argc != 4) {
3079 di << "Usage : " << argv[0] << " A B C\n";
3080 return 1;
3081 }
3082 try
3083 {
91322f44 3084 gp_Lin2d aLin2d (Draw::Atof(argv[1]),Draw::Atof(argv[2]),Draw::Atof(argv[3]));
7fd59977 3085 gp_Pnt2d anOrigin = aLin2d.Location();
3086 di << "X_0 = " << anOrigin.X() << " Y_0 = " << anOrigin.Y() << "\n" ;
3087 }
a738b534 3088 catch(Standard_ConstructionError const&)
7fd59977 3089 {
3090 di << argv[0] << " Exception: Sqrt(A*A + B*B) <= Resolution from gp\n";
3091 }
3092 return 0;
3093}
3094
3095static Standard_Integer OCC15755 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
3096{
3097 if (argc != 3) {
3098 di << "Usage : " << argv[0] << " file shape\n";
3099 return 1;
3100 }
3101
3102 IGESControl_Reader aReader;
3103 aReader.ReadFile(argv[1]);
3104 aReader.SetReadVisible(Standard_True);
3105 aReader.TransferRoots();
3106
3107 Handle(IGESData_IGESModel) model = aReader.IGESModel();
3108 if (model.IsNull()) {
3109 di << "model.IsNull()\n";
3110 return 1;
3111 }
3112 Standard_Integer nb = model->NbEntities();
3113 for (Standard_Integer i = 1; i <= nb; i ++) {
3114 Handle(IGESData_IGESEntity) ent = model->Entity(i);
3115 Handle(TCollection_HAsciiString) name;
3116 name = ent->NameValue();
3117 Standard_CString aStr = name->ToCString();
3118 di << "NameValue = " << aStr << "\n";
3119 }
3120
3121 TopoDS_Shape shape = aReader.OneShape();
3122 DBRep::Set(argv[2],shape);
3123 return 0;
3124}
3125
3126// For OCC16782 testing
3127#include <AppStd_Application.hxx>
3128#include <TDF_Tool.hxx>
3129#include <TColStd_HArray1OfInteger.hxx>
3130// Iterators
3131#include <TColStd_ListIteratorOfListOfInteger.hxx>
3132#include <TColStd_ListIteratorOfListOfReal.hxx>
3133#include <TDataStd_ListIteratorOfListOfExtendedString.hxx>
3134#include <TDataStd_ListIteratorOfListOfByte.hxx>
3135#include <TDF_ListIteratorOfLabelList.hxx>
3136// Attributes
3137#include <TDataStd_Tick.hxx>
3138#include <TDataStd_IntegerList.hxx>
3139#include <TDataStd_RealList.hxx>
3140#include <TDataStd_ExtStringList.hxx>
3141#include <TDataStd_BooleanList.hxx>
3142#include <TDataStd_ReferenceList.hxx>
3143#include <TDataStd_BooleanArray.hxx>
3144#include <TDataStd_ReferenceArray.hxx>
3145#include <TDataStd_ByteArray.hxx>
3146#include <TDataStd_NamedData.hxx>
3147#include <TDF_Reference.hxx>
3148//
3149Handle(AppStd_Application) app;
3150int TestSetGet(const Handle(TDocStd_Document)& doc)
3151{
3152 // TDataStd_Tick:
3153 // Set
3154 TDataStd_Tick::Set(doc->Main());
3155 // Get
3156 Handle(TDataStd_Tick) tick;
3157 if (!doc->Main().FindAttribute(TDataStd_Tick::GetID(), tick))
3158 return 1;
3159 // Forget
3160 doc->Main().ForgetAttribute(TDataStd_Tick::GetID());
3161 if (doc->Main().IsAttribute(TDataStd_Tick::GetID()))
3162 return 2;
3163 doc->Main().ResumeAttribute(tick);
3164 if (!doc->Main().IsAttribute(TDataStd_Tick::GetID()))
3165 return 3;
3166 // Forget
3167 doc->Main().ForgetAttribute(TDataStd_Tick::GetID());
3168 if (doc->Main().IsAttribute(TDataStd_Tick::GetID()))
3169 return 2;
3170
3171 // TDataStd_IntegerList:
3172 // Set
3173 Handle(TDataStd_IntegerList) setintlist = TDataStd_IntegerList::Set(doc->Main());
3174 setintlist->Append(2);
3175 setintlist->Prepend(1);
3176 setintlist->InsertAfter(3, 2);
3177 setintlist->InsertBefore(0, 1);
3178 setintlist->Append(200);
3179 setintlist->Remove(0);
3180 setintlist->Remove(200);
3181 // Get
3182 Handle(TDataStd_IntegerList) getintlist;
3183 if (!doc->Main().FindAttribute(TDataStd_IntegerList::GetID(), getintlist))
3184 return 1;
3185 if (getintlist->First() != 1)
3186 return 2;
3187 if (getintlist->Last() != 3)
3188 return 3;
3189 const TColStd_ListOfInteger& intlist = getintlist->List();
3190 TColStd_ListIteratorOfListOfInteger itr_intlist(intlist);
3191 for (; itr_intlist.More(); itr_intlist.Next())
3192 {
3193 if (itr_intlist.Value() != 1 &&
3194 itr_intlist.Value() != 2 &&
3195 itr_intlist.Value() != 3)
3196 {
3197 return 4;
3198 }
3199 }
3200 getintlist->Clear();
3201
3202 // TDataStd_RealList:
3203 // Set
3204 Handle(TDataStd_RealList) setdbllist = TDataStd_RealList::Set(doc->Main());
3205 setdbllist->Append(2.5);
3206 setdbllist->Prepend(1.5);
3207 setdbllist->InsertAfter(3.5, 2.5);
3208 setdbllist->InsertBefore(0.5, 1.5);
3209 setdbllist->Append(200.5);
3210 setdbllist->Remove(0.5);
3211 setdbllist->Remove(200.5);
3212 // Get
3213 Handle(TDataStd_RealList) getdbllist;
3214 if (!doc->Main().FindAttribute(TDataStd_RealList::GetID(), getdbllist))
3215 return 1;
3216 if (getdbllist->First() != 1.5)
3217 return 2;
3218 if (getdbllist->Last() != 3.5)
3219 return 3;
3220 const TColStd_ListOfReal& dbllist = getdbllist->List();
3221 TColStd_ListIteratorOfListOfReal itr_dbllist(dbllist);
3222 for (; itr_dbllist.More(); itr_dbllist.Next())
3223 {
3224 if (itr_dbllist.Value() != 1.5 &&
3225 itr_dbllist.Value() != 2.5 &&
3226 itr_dbllist.Value() != 3.5)
3227 {
3228 return 4;
3229 }
3230 }
3231 getdbllist->Clear();
3232
3233 // TDataStd_ExtStringList:
3234 // Set
3235 Handle(TDataStd_ExtStringList) setstrlist = TDataStd_ExtStringList::Set(doc->Main());
3236 setstrlist->Append("Hello");
3237 setstrlist->Prepend("Guten Tag");
3238 setstrlist->InsertAfter("Bonjour", "Guten Tag");
3239 setstrlist->InsertBefore("Bonsoir", "Hello");
3240 setstrlist->Append("Good bye");
3241 setstrlist->Remove("Bonsoir");
3242 setstrlist->Remove("Good bye");
3243 // Get
3244 Handle(TDataStd_ExtStringList) getstrlist;
3245 if (!doc->Main().FindAttribute(TDataStd_ExtStringList::GetID(), getstrlist))
3246 return 1;
3247 if (getstrlist->First() != "Guten Tag")
3248 return 2;
3249 if (getstrlist->Last() != "Hello")
3250 return 3;
3251 const TDataStd_ListOfExtendedString& strlist = getstrlist->List();
3252 TDataStd_ListIteratorOfListOfExtendedString itr_strlist(strlist);
3253 for (; itr_strlist.More(); itr_strlist.Next())
3254 {
3255 if (itr_strlist.Value() != "Guten Tag" &&
3256 itr_strlist.Value() != "Bonjour" &&
3257 itr_strlist.Value() != "Hello")
3258 {
3259 return 4;
3260 }
3261 }
3262 getstrlist->Clear();
3263
3264 // TDataStd_BooleanList:
3265 // Set
3266 Handle(TDataStd_BooleanList) setboollist = TDataStd_BooleanList::Set(doc->Main());
3267 setboollist->Append(Standard_True);
3268 setboollist->Prepend(Standard_False);
3269 // Get
3270 Handle(TDataStd_BooleanList) getboollist;
3271 if (!doc->Main().FindAttribute(TDataStd_BooleanList::GetID(), getboollist))
3272 return 1;
3273 if (getboollist->First() != Standard_False)
3274 return 2;
3275 if (getboollist->Last() != Standard_True)
3276 return 3;
3277 const TDataStd_ListOfByte& boollist = getboollist->List();
dde68833 3278 for (TDataStd_ListIteratorOfListOfByte itr_boollist(boollist); itr_boollist.More(); itr_boollist.Next())
7fd59977 3279 {
dde68833 3280 if (itr_boollist.Value() != 1
3281 && itr_boollist.Value() != 0)
7fd59977 3282 {
3283 return 4;
3284 }
3285 }
3286 getboollist->Clear();
3287
3288 // TDataStd_ReferenceList:
3289 TDF_Label L1 = doc->Main().FindChild(100);
3290 TDF_Label L2 = doc->Main().FindChild(101);
3291 TDF_Label L3 = doc->Main().FindChild(102);
3292 TDF_Label L4 = doc->Main().FindChild(103);
3293 TDF_Label L5 = doc->Main().FindChild(104);
3294 // Set
3295 Handle(TDataStd_ReferenceList) setreflist = TDataStd_ReferenceList::Set(doc->Main());
3296 setreflist->Append(L1);
3297 setreflist->Prepend(L2);
3298 setreflist->InsertAfter(L3, L2);
3299 setreflist->InsertBefore(L4, L1);
3300 setreflist->Append(L5);
3301 setreflist->Remove(L4);
3302 setreflist->Remove(L5);
3303 // Get
3304 Handle(TDataStd_ReferenceList) getreflist;
3305 if (!doc->Main().FindAttribute(TDataStd_ReferenceList::GetID(), getreflist))
3306 return 1;
3307 if (getreflist->First() != L2)
3308 return 2;
3309 if (getreflist->Last() != L1)
3310 return 3;
3311 const TDF_LabelList& reflist = getreflist->List();
3312 TDF_ListIteratorOfLabelList itr_reflist(reflist);
3313 for (; itr_reflist.More(); itr_reflist.Next())
3314 {
3315 if (itr_reflist.Value() != L1 &&
3316 itr_reflist.Value() != L2 &&
3317 itr_reflist.Value() != L3)
3318 {
3319 return 4;
3320 }
3321 }
3322 getreflist->Clear();
3323
3324 // TDataStd_BooleanArray:
3325 // Set
3326 Handle(TDataStd_BooleanArray) setboolarr = TDataStd_BooleanArray::Set(doc->Main(), 12, 16);
3327 setboolarr->SetValue(12, Standard_True);
3328 setboolarr->SetValue(13, Standard_False);
3329 setboolarr->SetValue(14, Standard_False);
3330 setboolarr->SetValue(15, Standard_False);
3331 setboolarr->SetValue(16, Standard_True);
3332 setboolarr->SetValue(14, Standard_True);
3333 // Get
3334 Handle(TDataStd_BooleanArray) getboolarr;
3335 if (!doc->Main().FindAttribute(TDataStd_BooleanArray::GetID(), getboolarr))
3336 return 1;
3337 if (getboolarr->Value(12) != Standard_True)
3338 return 2;
3339 if (getboolarr->Value(13) != Standard_False)
3340 return 2;
3341 if (getboolarr->Value(14) != Standard_True)
3342 return 2;
3343 if (getboolarr->Value(15) != Standard_False)
3344 return 2;
3345 if (getboolarr->Value(16) != Standard_True)
3346 return 2;
3347
3348 // TDataStd_ReferenceArray:
3349 // Set
3350 Handle(TDataStd_ReferenceArray) setrefarr = TDataStd_ReferenceArray::Set(doc->Main(), 0, 4);
3351 setrefarr->SetValue(0, L1);
3352 setrefarr->SetValue(1, L2);
3353 setrefarr->SetValue(2, L3);
3354 setrefarr->SetValue(3, L4);
3355 setrefarr->SetValue(4, L5);
3356 // Get
3357 Handle(TDataStd_ReferenceArray) getrefarr;
3358 if (!doc->Main().FindAttribute(TDataStd_ReferenceArray::GetID(), getrefarr))
3359 return 1;
3360 if (getrefarr->Value(0) != L1)
3361 return 2;
3362 if (getrefarr->Value(1) != L2)
3363 return 2;
3364 if (getrefarr->Value(2) != L3)
3365 return 2;
3366 if (getrefarr->Value(3) != L4)
3367 return 2;
3368 if (getrefarr->Value(4) != L5)
3369 return 2;
3370
3371 // TDataStd_ByteArray:
3372 // Set
3373 Handle(TDataStd_ByteArray) setbytearr = TDataStd_ByteArray::Set(doc->Main(), 12, 16);
3374 setbytearr->SetValue(12, 0);
3375 setbytearr->SetValue(13, 1);
3376 setbytearr->SetValue(14, 2);
3377 setbytearr->SetValue(15, 3);
3378 setbytearr->SetValue(16, 255);
3379 // Get
3380 Handle(TDataStd_ByteArray) getbytearr;
3381 if (!doc->Main().FindAttribute(TDataStd_ByteArray::GetID(), getbytearr))
3382 return 1;
3383 if (getbytearr->Value(12) != 0)
3384 return 2;
3385 if (getbytearr->Value(13) != 1)
3386 return 2;
3387 if (getbytearr->Value(14) != 2)
3388 return 2;
3389 if (getbytearr->Value(15) != 3)
3390 return 2;
3391 if (getbytearr->Value(16) != 255)
3392 return 2;
3393
3394 // TDataStd_NamedData:
3395 // Set:
3396 Handle(TDataStd_NamedData) setnd = TDataStd_NamedData::Set(doc->Main());
3397 setnd->SetInteger("Integer1", 1);
3398 setnd->SetInteger("Integer2", 2);
3399 setnd->SetInteger("Integer3", 8);
3400 setnd->SetInteger("Integer3", 3);
3401 // Get:
3402 Handle(TDataStd_NamedData) getnd;
3403 if (!doc->Main().FindAttribute(TDataStd_NamedData::GetID(), getnd))
3404 return 1;
3405 if (!getnd->HasIntegers())
3406 return 2;
3407 if (!getnd->HasInteger("Integer1"))
3408 return 3;
3409 if (getnd->GetInteger("Integer2") != 2)
3410 return 4;
3411 if (getnd->GetInteger("Integer3") != 3)
3412 return 4;
3413
3414 return 0;
3415}
3416
3417int TestUndoRedo(const Handle(TDocStd_Document)& doc)
3418{
3419 // TDataStd_Tick:
3420 doc->OpenCommand();
3421 Handle(TDataStd_Tick) tick = TDataStd_Tick::Set(doc->Main());
3422 doc->CommitCommand();
3423 if (!doc->Main().IsAttribute(TDataStd_Tick::GetID()))
3424 return 1;
3425 doc->Undo();
3426 if (doc->Main().IsAttribute(TDataStd_Tick::GetID()))
3427 return 2;
3428 doc->Redo();
3429 if (!doc->Main().IsAttribute(TDataStd_Tick::GetID()))
3430 return 3;
3431
3432 // TDataStd_IntegerList:
3433 doc->OpenCommand();
3434 Handle(TDataStd_IntegerList) intlist = TDataStd_IntegerList::Set(doc->Main());
3435 intlist->Append(2);
3436 intlist->Prepend(1);
3437 intlist->InsertBefore(0, 1);
3438 intlist->InsertAfter(3, 2);
3439 doc->CommitCommand();
3440 if (!doc->Main().IsAttribute(TDataStd_IntegerList::GetID()))
3441 return 1;
3442 doc->Undo();
3443 if (!intlist->IsEmpty())
3444 return 2;
3445 doc->Redo();
3446 if (!intlist->Extent())
3447 return 3;
3448 if (intlist->First() != 0)
3449 return 4;
3450 if (intlist->Last() != 3)
3451 return 5;
3452 intlist->Clear();
3453
3454 // TDataStd_RealList:
3455 doc->OpenCommand();
3456 Handle(TDataStd_RealList) dbllist = TDataStd_RealList::Set(doc->Main());
3457 dbllist->Append(2.5);
3458 dbllist->Prepend(1.5);
3459 dbllist->InsertBefore(0.5, 1.5);
3460 dbllist->InsertAfter(3.5, 2.5);
3461 doc->CommitCommand();
3462 if (!doc->Main().IsAttribute(TDataStd_RealList::GetID()))
3463 return 1;
3464 doc->Undo();
3465 if (!dbllist->IsEmpty())
3466 return 2;
3467 doc->Redo();
3468 if (!dbllist->Extent())
3469 return 3;
3470 if (dbllist->First() != 0.5)
3471 return 4;
3472 if (dbllist->Last() != 3.5)
3473 return 5;
3474 dbllist->Clear();
3475
3476 // TDataStd_ExtStringList:
3477 doc->OpenCommand();
3478 Handle(TDataStd_ExtStringList) strlist = TDataStd_ExtStringList::Set(doc->Main());
3479 strlist->Append("Hello");
3480 strlist->Prepend("Guten Tag");
3481 strlist->InsertAfter("Bonjour", "Guten Tag");
3482 strlist->InsertBefore("Bonsoir", "Hello");
3483 doc->CommitCommand();
3484 if (!doc->Main().IsAttribute(TDataStd_ExtStringList::GetID()))
3485 return 1;
3486 doc->Undo();
3487 if (!strlist->IsEmpty())
3488 return 2;
3489 doc->Redo();
3490 if (!strlist->Extent())
3491 return 3;
3492 if (strlist->First() != "Guten Tag")
3493 return 4;
3494 if (strlist->Last() != "Hello")
3495 return 5;
3496 strlist->Clear();
3497
3498 // TDataStd_BooleanList:
3499 doc->OpenCommand();
3500 Handle(TDataStd_BooleanList) boollist = TDataStd_BooleanList::Set(doc->Main());
3501 boollist->Append(Standard_True);
3502 boollist->Prepend(Standard_False);
3503 doc->CommitCommand();
3504 if (!doc->Main().IsAttribute(TDataStd_BooleanList::GetID()))
3505 return 1;
3506 doc->Undo();
3507 if (!boollist->IsEmpty())
3508 return 2;
3509 doc->Redo();
3510 if (!boollist->Extent())
3511 return 3;
3512 if (boollist->First() != Standard_False)
3513 return 4;
3514 if (boollist->Last() != Standard_True)
3515 return 5;
3516 boollist->Clear();
3517
3518 // TDataStd_ReferenceList:
3519 TDF_Label L1 = doc->Main().FindChild(100);
3520 TDF_Label L2 = doc->Main().FindChild(101);
3521 TDF_Label L3 = doc->Main().FindChild(102);
3522 TDF_Label L4 = doc->Main().FindChild(103);
3523 doc->OpenCommand();
3524 Handle(TDataStd_ReferenceList) reflist = TDataStd_ReferenceList::Set(doc->Main());
3525 reflist->Append(L1);
3526 reflist->Prepend(L2);
3527 reflist->InsertBefore(L3, L1);
3528 reflist->InsertAfter(L4, L2);
3529 doc->CommitCommand();
3530 if (!doc->Main().IsAttribute(TDataStd_ReferenceList::GetID()))
3531 return 1;
3532 doc->Undo();
3533 if (!reflist->IsEmpty())
3534 return 2;
3535 doc->Redo();
3536 if (!reflist->Extent())
3537 return 3;
3538 if (reflist->First() != L2)
3539 return 4;
3540 if (reflist->Last() != L1)
3541 return 5;
3542 reflist->Clear();
3543
3544 // TDataStd_BooleanArray:
3545 doc->OpenCommand();
3546 Handle(TDataStd_BooleanArray) boolarr = TDataStd_BooleanArray::Set(doc->Main(), 23, 25);
3547 boolarr->SetValue(23, Standard_True);
3548 boolarr->SetValue(25, Standard_True);
3549 doc->CommitCommand();
3550 doc->OpenCommand();
3551 boolarr = TDataStd_BooleanArray::Set(doc->Main(), 230, 250);
3552 boolarr->SetValue(230, Standard_True);
3553 boolarr->SetValue(250, Standard_True);
3554 doc->CommitCommand();
3555 doc->Undo();
3556 if (boolarr->Value(23) != Standard_True)
3557 return 2;
3558 if (boolarr->Value(24) != Standard_False)
3559 return 2;
3560 if (boolarr->Value(25) != Standard_True)
3561 return 2;
3562 doc->Redo();
3563 if (boolarr->Value(230) != Standard_True)
3564 return 3;
3565 if (boolarr->Value(240) != Standard_False)
3566 return 3;
3567 if (boolarr->Value(250) != Standard_True)
3568 return 3;
3569
3570 // TDataStd_ReferenceArray:
3571 doc->OpenCommand();
3572 Handle(TDataStd_ReferenceArray) refarr = TDataStd_ReferenceArray::Set(doc->Main(), 5, 8);
3573 refarr->SetValue(5, L1);
3574 refarr->SetValue(6, L2);
3575 refarr->SetValue(7, L3);
3576 refarr->SetValue(8, L4);
3577 doc->CommitCommand();
3578 if (!doc->Main().IsAttribute(TDataStd_ReferenceArray::GetID()))
3579 return 1;
3580 doc->Undo();
3581 doc->Redo();
3582 if (refarr->Value(5) != L1)
3583 return 4;
3584 if (refarr->Value(6) != L2)
3585 return 4;
3586 if (refarr->Value(7) != L3)
3587 return 4;
3588 if (refarr->Value(8) != L4)
3589 return 4;
3590
3591 // TDataStd_ByteArray:
3592 doc->OpenCommand();
3593 Handle(TDataStd_ByteArray) bytearr = TDataStd_ByteArray::Set(doc->Main(), 23, 25);
3594 bytearr->SetValue(23, 23);
3595 bytearr->SetValue(25, 25);
3596 doc->CommitCommand();
3597 doc->OpenCommand();
3598 bytearr = TDataStd_ByteArray::Set(doc->Main(), 230, 250);
3599 bytearr->SetValue(230, 230);
3600 bytearr->SetValue(250, 250);
3601 doc->CommitCommand();
3602 doc->Undo();
3603 if (bytearr->Value(23) != 23)
3604 return 2;
3605 if (bytearr->Value(25) != 25)
3606 return 2;
3607 doc->Redo();
3608 if (bytearr->Value(230) != 230)
3609 return 3;
3610 if (bytearr->Value(250) != 250)
3611 return 3;
3612
3613 // TDataStd_NamedData:
3614 doc->OpenCommand();
3615 Handle(TDataStd_NamedData) nd = TDataStd_NamedData::Set(doc->Main());
3616 nd->SetByte("b14", 12);
3617 nd->SetByte("b17", 18);
3618 nd->SetByte("b14", 14);
3619 nd->SetByte("b17", 17);
3620 doc->CommitCommand();
3621 doc->OpenCommand();
3622 nd = TDataStd_NamedData::Set(doc->Main());
3623 nd->SetReal("r14", 14);
3624 nd->SetReal("r17", 17);
3625 nd->SetReal("r14", 14.4);
3626 nd->SetReal("r17", 17.7);
3627 doc->CommitCommand();
3628 doc->Undo();
3629 if (nd->HasStrings())
3630 return 1;
3631 if (nd->HasReals())
3632 return 1;
3633 if (nd->HasReal("r17"))
3634 return 2;
3635 if (!nd->HasBytes())
3636 return 3;
3637 if (nd->GetByte("b14") != 14)
3638 return 4;
3639 if (nd->GetByte("b17") != 17)
3640 return 4;
3641 if (nd->HasByte("b18"))
3642 return 5;
3643 doc->Redo();
3644 if (!nd->HasBytes())
3645 return 1;
3646 if (!nd->HasReals())
3647 return 1;
3648 if (nd->GetByte("b14") != 14)
3649 return 2;
3650 if (nd->GetReal("r14") != 14.4)
3651 return 2;
3652 if (nd->GetReal("r17") != 17.7)
3653 return 2;
3654
3655 return 0;
3656}
3657
3658int TestCopyPaste(const Handle(TDocStd_Document)& doc)
3659{
3660 TDF_Label L1 = doc->Main().FindChild(1);
3661 TDF_Label L2 = doc->Main().FindChild(2);
3662 TDF_CopyLabel copier(L1, L2);
3663
3664 // TDataStd_Tick:
3665 TDataStd_Tick::Set(L1);
3666 copier.Perform();
3667 if (!copier.IsDone())
3668 return 1;
3669 if (!L2.IsAttribute(TDataStd_Tick::GetID()))
3670 return 2;
3671
3672 // TDataStd_IntegerList:
3673 Handle(TDataStd_IntegerList) intlist = TDataStd_IntegerList::Set(L1);
3674 intlist->Append(1);
3675 intlist->InsertAfter(2, 1);
3676 copier.Perform();
3677 if (!copier.IsDone())
3678 return 1;
3679 intlist->Clear();
3680 intlist.Nullify();
3681 if (!L2.FindAttribute(TDataStd_IntegerList::GetID(), intlist))
3682 return 2;
3683 if (intlist->First() != 1)
3684 return 3;
3685 if (intlist->Last() != 2)
3686 return 4;
3687 intlist->Clear();
3688
3689 // TDataStd_RealList:
3690 Handle(TDataStd_RealList) dbllist = TDataStd_RealList::Set(L1);
3691 dbllist->Append(1.5);
3692 dbllist->InsertAfter(2.5, 1.5);
3693 copier.Perform();
3694 if (!copier.IsDone())
3695 return 1;
3696 dbllist->Clear();
3697 dbllist.Nullify();
3698 if (!L2.FindAttribute(TDataStd_RealList::GetID(), dbllist))
3699 return 2;
3700 if (dbllist->First() != 1.5)
3701 return 3;
3702 if (dbllist->Last() != 2.5)
3703 return 4;
3704 dbllist->Clear();
3705
3706 // TDataStd_ExtStringList:
3707 Handle(TDataStd_ExtStringList) strlist = TDataStd_ExtStringList::Set(L1);
3708 strlist->Append("Open CASCADE");
3709 strlist->InsertAfter(" - is the best set of libraries!", "Open CASCADE");
3710 copier.Perform();
3711 if (!copier.IsDone())
3712 return 1;
3713 strlist->Clear();
3714 strlist.Nullify();
3715 if (!L2.FindAttribute(TDataStd_ExtStringList::GetID(), strlist))
3716 return 2;
3717 if (strlist->First() != "Open CASCADE")
3718 return 3;
3719 if (strlist->Last() != " - is the best set of libraries!")
3720 return 4;
3721 strlist->Clear();
3722
3723 // TDataStd_BooleanList:
3724 Handle(TDataStd_BooleanList) boollist = TDataStd_BooleanList::Set(L1);
3725 boollist->Append(Standard_True);
3726 boollist->Prepend(Standard_False);
3727 copier.Perform();
3728 if (!copier.IsDone())
3729 return 1;
3730 boollist->Clear();
3731 boollist.Nullify();
3732 if (!L2.FindAttribute(TDataStd_BooleanList::GetID(), boollist))
3733 return 2;
3734 if (boollist->First() != Standard_False)
3735 return 3;
3736 if (boollist->Last() != Standard_True)
3737 return 4;
3738 boollist->Clear();
3739
3740 // TDataStd_ReferenceList:
3741 TDF_Label L100 = doc->Main().FindChild(100);
3742 TDF_Label L101 = doc->Main().FindChild(101);
3743 Handle(TDataStd_ReferenceList) reflist = TDataStd_ReferenceList::Set(L1);
3744 reflist->Append(L100);
3745 reflist->InsertAfter(L101, L100);
3746 copier.Perform();
3747 if (!copier.IsDone())
3748 return 1;
3749 reflist->Clear();
3750 reflist.Nullify();
3751 if (!L2.FindAttribute(TDataStd_ReferenceList::GetID(), reflist))
3752 return 2;
3753 if (reflist->First() != L100)
3754 return 3;
3755 if (reflist->Last() != L101)
3756 return 4;
3757 reflist->Clear();
3758
3759 // TDataStd_BooleanArray:
3760 Handle(TDataStd_BooleanArray) boolarr = TDataStd_BooleanArray::Set(L1, 4, 6);
3761 boolarr->SetValue(4, Standard_True);
3762 boolarr->SetValue(6, Standard_True);
3763 copier.Perform();
3764 if (!copier.IsDone())
3765 return 1;
3766 boolarr.Nullify();
3767 if (!L2.FindAttribute(TDataStd_BooleanArray::GetID(), boolarr))
3768 return 2;
3769 if (boolarr->Value(4) != Standard_True)
3770 return 3;
3771 if (boolarr->Value(5) != Standard_False)
3772 return 3;
3773 if (boolarr->Value(6) != Standard_True)
3774 return 3;
3775
3776 // TDataStd_ReferenceArray:
3777 Handle(TDataStd_ReferenceArray) refarr = TDataStd_ReferenceArray::Set(L1, 3, 4);
3778 refarr->SetValue(3, L100);
3779 refarr->SetValue(4, L101);
3780 copier.Perform();
3781 if (!copier.IsDone())
3782 return 1;
3783 refarr.Nullify();
3784 if (!L2.FindAttribute(TDataStd_ReferenceArray::GetID(), refarr))
3785 return 2;
3786 if (refarr->Value(3) != L100)
3787 return 3;
3788 if (refarr->Value(4) != L101)
3789 return 3;
3790
3791 // TDataStd_ByteArray:
3792 Handle(TDataStd_ByteArray) bytearr = TDataStd_ByteArray::Set(L1, 4, 6);
3793 bytearr->SetValue(4, 40);
3794 bytearr->SetValue(6, 60);
3795 copier.Perform();
3796 if (!copier.IsDone())
3797 return 1;
3798 bytearr.Nullify();
3799 if (!L2.FindAttribute(TDataStd_ByteArray::GetID(), bytearr))
3800 return 2;
3801 if (bytearr->Value(4) != 40)
3802 return 3;
3803 if (bytearr->Value(6) != 60)
3804 return 3;
3805
3806 // TDataStd_NamedData:
3807 Handle(TDataStd_NamedData) nd = TDataStd_NamedData::Set(L1);
3808 nd->SetInteger("Integer1", 11);
3809 nd->SetReal("Real1", 11.1);
3810 nd->SetString("String1", "11.11111111");
3811 nd->SetByte("Byte1", 111);
3812 Handle(TColStd_HArray1OfInteger) ints_arr = new TColStd_HArray1OfInteger(4, 5);
3813 ints_arr->SetValue(4, 4);
3814 ints_arr->SetValue(5, 5);
3815 nd->SetArrayOfIntegers("Integers1", ints_arr);
3816 copier.Perform();
3817 if (!copier.IsDone())
3818 return 1;
3819 nd.Nullify();
3820 if (!L2.FindAttribute(TDataStd_NamedData::GetID(), nd))
3821 return 2;
3822 if (!nd->HasIntegers())
3823 return 3;
3824 if (!nd->HasReals())
3825 return 3;
3826 if (!nd->HasStrings())
3827 return 3;
3828 if (!nd->HasBytes())
3829 return 3;
3830 if (!nd->HasArraysOfIntegers())
3831 return 3;
3832 if (nd->HasArraysOfReals())
3833 return 3;
3834 if (!nd->HasInteger("Integer1"))
3835 return 4;
3836 if (nd->GetInteger("Integer1") != 11)
3837 return 4;
3838 if (!nd->HasReal("Real1"))
3839 return 4;
3840 if (nd->GetReal("Real1") != 11.1)
3841 return 4;
3842 if (!nd->HasString("String1"))
3843 return 4;
3844 if (nd->GetString("String1") != "11.11111111")
3845 return 4;
3846 if (!nd->HasByte("Byte1"))
3847 return 4;
3848 if (nd->GetByte("Byte1") != 111)
3849 return 4;
3850 if (!nd->HasArrayOfIntegers("Integers1"))
3851 return 4;
3852 const Handle(TColStd_HArray1OfInteger)& ints_arr_out = nd->GetArrayOfIntegers("Integers1");
3853 if (ints_arr_out.IsNull())
3854 return 4;
3855 if (ints_arr_out->Value(5) != 5)
3856 return 4;
3857
3858 return 0;
3859}
3860
3861int TestOpenSave(TCollection_ExtendedString aFile1,
3862 TCollection_ExtendedString aFile2,
3863 TCollection_ExtendedString aFile3)
3864{
3865 // Std
3866 Handle(TDocStd_Document) doc_std, doc_std_open;
fff263bd 3867 app->NewDocument("BinOcaf", doc_std);
7fd59977 3868 // TDataStd_Tick:
3869 TDataStd_Tick::Set(doc_std->Main());
3870 // TDataStd_IntegerList:
3871 Handle(TDataStd_IntegerList) intlist = TDataStd_IntegerList::Set(doc_std->Main());
3872 intlist->Append(1);
3873 intlist->Append(5);
3874 // TDataStd_RealList:
3875 Handle(TDataStd_RealList) dbllist = TDataStd_RealList::Set(doc_std->Main());
3876 dbllist->Append(1.5);
3877 dbllist->Append(5.5);
3878 // TDataStd_ExtStringList:
3879 Handle(TDataStd_ExtStringList) strlist = TDataStd_ExtStringList::Set(doc_std->Main());
3880 strlist->Append("Auf");
3881 strlist->Append("Wiedersehen");
3882 // TDataStd_BooleanList:
3883 Handle(TDataStd_BooleanList) boollist = TDataStd_BooleanList::Set(doc_std->Main());
3884 boollist->Append(Standard_False);
3885 boollist->Append(Standard_True);
3886 // TDataStd_ReferenceList:
3887 TCollection_AsciiString entry1, entry2, entry_first, entry_last;
3888 TDF_Label Lstd1 = doc_std->Main().FindChild(100);
3889 TDF_Tool::Entry(Lstd1, entry1);
3890 TDF_Label Lstd2 = doc_std->Main().FindChild(101);
3891 TDF_Tool::Entry(Lstd2, entry2);
3892 Handle(TDataStd_ReferenceList) reflist = TDataStd_ReferenceList::Set(doc_std->Main());
3893 reflist->Append(Lstd1);
3894 reflist->Append(Lstd2);
3895 // TDataStd_BooleanArray:
3896 Handle(TDataStd_BooleanArray) boolarr = TDataStd_BooleanArray::Set(doc_std->Main(), 15, 18);
3897 boolarr->SetValue(15, Standard_False);
3898 boolarr->SetValue(16, Standard_True);
3899 boolarr->SetValue(17, Standard_True);
3900 boolarr->SetValue(18, Standard_True);
3901 // TDataStd_ReferenceArray:
3902 Handle(TDataStd_ReferenceArray) refarr = TDataStd_ReferenceArray::Set(doc_std->Main(), 45, 46);
3903 refarr->SetValue(45, Lstd1);
3904 refarr->SetValue(46, Lstd2);
3905 // TDataStd_ByteArray:
3906 Handle(TDataStd_ByteArray) bytearr = TDataStd_ByteArray::Set(doc_std->Main(), 15, 18);
3907 bytearr->SetValue(15, 150);
3908 bytearr->SetValue(16, 160);
3909 bytearr->SetValue(17, 170);
3910 bytearr->SetValue(18, 180);
3911 // TDataStd_NamedData:
3912 Handle(TDataStd_NamedData) nameddata = TDataStd_NamedData::Set(doc_std->Main());
3913 // TDF_Reference:
3914 TDF_Label Lstd3 = doc_std->Main().FindChild(103);
3915 Handle(TDF_Reference) ref = TDF_Reference::Set(doc_std->Main(), Lstd3);
3916 //
3917 // Save
15e8b082
M
3918 //if (app->SaveAs(doc_std, "W:\\doc.std") != PCDM_SS_OK)
3919 if (app->SaveAs(doc_std, aFile1) != PCDM_SS_OK)
7fd59977 3920 return 1;
3921 intlist.Nullify();
3922 dbllist.Nullify();
3923 strlist.Nullify();
3924 boollist.Nullify();
3925 reflist.Nullify();
3926 boolarr.Nullify();
3927 ref.Nullify();
3928 app->Close(doc_std);
3929 doc_std.Nullify();
15e8b082
M
3930 //if (app->Open("W:\\doc.std", doc_std_open) != PCDM_RS_OK)
3931 if (app->Open(aFile1, doc_std_open) != PCDM_RS_OK)
7fd59977 3932 return 2;
3933 if (!doc_std_open->Main().IsAttribute(TDataStd_Tick::GetID()))
3934 return 3;
3935 if (!doc_std_open->Main().FindAttribute(TDataStd_IntegerList::GetID(), intlist))
3936 return 4;
3937 if (intlist->First() != 1)
3938 return 5;
3939 if (intlist->Last() != 5)
3940 return 6;
3941 if (!doc_std_open->Main().FindAttribute(TDataStd_RealList::GetID(), dbllist))
3942 return 4;
3943 if (dbllist->First() != 1.5)
3944 return 5;
3945 if (dbllist->Last() != 5.5)
3946 return 6;
3947 if (!doc_std_open->Main().FindAttribute(TDataStd_ExtStringList::GetID(), strlist))
3948 return 4;
3949 if (strlist->First() != "Auf")
3950 return 5;
3951 if (strlist->Last() != "Wiedersehen")
3952 return 6;
3953 if (!doc_std_open->Main().FindAttribute(TDataStd_BooleanList::GetID(), boollist))
3954 return 4;
3955 if (boollist->First() != Standard_False)
3956 return 5;
3957 if (boollist->Last() != Standard_True)
3958 return 6;
3959 if (!doc_std_open->Main().FindAttribute(TDataStd_ReferenceList::GetID(), reflist))
3960 return 4;
3961 TDF_Tool::Entry(reflist->First(), entry_first);
3962 if (entry1 != entry_first)
3963 return 5;
3964 TDF_Tool::Entry(reflist->Last(), entry_last);
3965 if (entry2 != entry_last)
3966 return 6;
3967 if (!doc_std_open->Main().FindAttribute(TDataStd_BooleanArray::GetID(), boolarr))
3968 return 4;
3969 if (boolarr->Value(15) != Standard_False)
3970 return 5;
3971 if (boolarr->Value(16) != Standard_True)
3972 return 5;
3973 if (boolarr->Value(17) != Standard_True)
3974 return 5;
3975 if (boolarr->Value(18) != Standard_True)
3976 return 5;
3977 if (!doc_std_open->Main().FindAttribute(TDataStd_ReferenceArray::GetID(), refarr))
3978 return 4;
3979 TDF_Tool::Entry(refarr->Value(45), entry_first);
3980 if (entry1 != entry_first)
3981 return 5;
3982 TDF_Tool::Entry(refarr->Value(46), entry_last);
3983 if (entry2 != entry_last)
3984 return 6;
3985 if (!doc_std_open->Main().FindAttribute(TDataStd_ByteArray::GetID(), bytearr))
3986 return 4;
3987 if (bytearr->Value(15) != 150)
3988 return 5;
3989 if (bytearr->Value(16) != 160)
3990 return 5;
3991 if (bytearr->Value(17) != 170)
3992 return 5;
3993 if (bytearr->Value(18) != 180)
3994 return 5;
3995 if (!doc_std_open->Main().FindAttribute(TDF_Reference::GetID(), ref))
3996 return 4;
3997 if (ref->Get().IsNull())
3998 return 5;
3999 if (ref->Get().Tag() != 103)
4000 return 5;
4001
4002 // Xml
4003 Handle(TDocStd_Document) doc_xml, doc_xml_open;
4004 app->NewDocument("XmlOcaf", doc_xml);
4005 // TDataStd_Tick:
4006 TDataStd_Tick::Set(doc_xml->Main());
4007 // TDataStd_IntegerList:
4008 intlist = TDataStd_IntegerList::Set(doc_xml->Main());
4009 intlist->Append(1);
4010 intlist->Append(5);
4011 // TDataStd_RealList:
4012 dbllist = TDataStd_RealList::Set(doc_xml->Main());
4013 dbllist->Append(1.5);
4014 dbllist->Append(5.5);
4015 // TDataStd_ExtStringList:
4016 strlist = TDataStd_ExtStringList::Set(doc_xml->Main());
4017 strlist->Append("Guten ");
4018 strlist->Append("Tag");
4019 // TDataStd_BooleanList:
4020 boollist = TDataStd_BooleanList::Set(doc_xml->Main());
4021 boollist->Append(Standard_False);
4022 boollist->Append(Standard_True);
4023 // TDataStd_ReferenceList:
4024 TDF_Label Lxml1 = doc_xml->Main().FindChild(100);
4025 TDF_Tool::Entry(Lxml1, entry1);
4026 TDF_Label Lxml2 = doc_xml->Main().FindChild(101);
4027 TDF_Tool::Entry(Lxml2, entry2);
4028 reflist = TDataStd_ReferenceList::Set(doc_xml->Main());
4029 reflist->Append(Lxml1);
4030 reflist->Append(Lxml2);
4031 // TDataStd_BooleanArray:
4032 boolarr = TDataStd_BooleanArray::Set(doc_xml->Main(), 15, 24);
4033 boolarr->SetValue(15, Standard_False);
4034 boolarr->SetValue(16, Standard_True);
4035 boolarr->SetValue(17, Standard_True);
4036 boolarr->SetValue(18, Standard_True);
4037 boolarr->SetValue(19, Standard_True);
4038 boolarr->SetValue(20, Standard_True);
4039 boolarr->SetValue(21, Standard_False);
4040 boolarr->SetValue(22, Standard_True);
4041 boolarr->SetValue(23, Standard_True);
4042 boolarr->SetValue(24, Standard_True);
4043 // TDataStd_ReferenceArray:
4044 refarr = TDataStd_ReferenceArray::Set(doc_xml->Main(), 444, 445);
4045 refarr->SetValue(444, Lxml1);
4046 refarr->SetValue(445, Lxml2);
4047 // TDataStd_ByteArray:
4048 bytearr = TDataStd_ByteArray::Set(doc_xml->Main(), 15, 24);
4049 bytearr->SetValue(15, 0);
4050 bytearr->SetValue(16, 10);
4051 bytearr->SetValue(17, 100);
4052 bytearr->SetValue(18, 200);
4053 bytearr->SetValue(19, 250);
4054 bytearr->SetValue(20, 251);
4055 bytearr->SetValue(21, 252);
4056 bytearr->SetValue(22, 253);
4057 bytearr->SetValue(23, 254);
4058 bytearr->SetValue(24, 255);
4059 // TDF_Reference:
4060 Lstd3 = doc_xml->Main().FindChild(103);
4061 ref = TDF_Reference::Set(doc_xml->Main(), Lstd3);
4062 //
4063 // Save
15e8b082
M
4064 //if (app->SaveAs(doc_xml, "W:\\doc.xml") != PCDM_SS_OK)
4065 if (app->SaveAs(doc_xml, aFile2) != PCDM_SS_OK)
7fd59977 4066 return 1;
4067 intlist.Nullify();
4068 ref.Nullify();
4069 app->Close(doc_xml);
4070 doc_xml.Nullify();
15e8b082
M
4071 //if (app->Open("W:\\doc.xml", doc_xml_open) != PCDM_RS_OK)
4072 if (app->Open(aFile2, doc_xml_open) != PCDM_RS_OK)
7fd59977 4073 return 2;
4074 if (!doc_xml_open->Main().IsAttribute(TDataStd_Tick::GetID()))
4075 return 3;
4076 if (!doc_xml_open->Main().FindAttribute(TDataStd_IntegerList::GetID(), intlist))
4077 return 4;
4078 if (intlist->First() != 1)
4079 return 5;
4080 if (intlist->Last() != 5)
4081 return 6;
4082 if (!doc_xml_open->Main().FindAttribute(TDataStd_RealList::GetID(), dbllist))
4083 return 4;
4084 if (dbllist->First() != 1.5)
4085 return 5;
4086 if (dbllist->Last() != 5.5)
4087 return 6;
4088 if (!doc_xml_open->Main().FindAttribute(TDataStd_ExtStringList::GetID(), strlist))
4089 return 4;
4090 if (strlist->First() != "Guten ")
4091 return 5;
4092 if (strlist->Last() != "Tag")
4093 return 6;
4094 if (!doc_xml_open->Main().FindAttribute(TDataStd_BooleanList::GetID(), boollist))
4095 return 4;
4096 if (boollist->First() != Standard_False)
4097 return 5;
4098 if (boollist->Last() != Standard_True)
4099 return 6;
4100 if (!doc_xml_open->Main().FindAttribute(TDataStd_ReferenceList::GetID(), reflist))
4101 return 4;
4102 TDF_Tool::Entry(reflist->First(), entry_first);
4103 if (entry1 != entry_first)
4104 return 5;
4105 TDF_Tool::Entry(reflist->Last(), entry_last);
4106 if (entry2 != entry_last)
4107 return 6;
4108 if (!doc_xml_open->Main().FindAttribute(TDataStd_BooleanArray::GetID(), boolarr))
4109 return 4;
4110 if (boolarr->Value(15) != Standard_False)
4111 return 5;
4112 if (boolarr->Value(16) != Standard_True)
4113 return 5;
4114 if (boolarr->Value(17) != Standard_True)
4115 return 5;
4116 if (boolarr->Value(18) != Standard_True)
4117 return 5;
4118 if (boolarr->Value(19) != Standard_True)
4119 return 5;
4120 if (boolarr->Value(20) != Standard_True)
4121 return 5;
4122 if (boolarr->Value(21) != Standard_False)
4123 return 5;
4124 if (boolarr->Value(22) != Standard_True)
4125 return 5;
4126 if (boolarr->Value(23) != Standard_True)
4127 return 5;
4128 if (boolarr->Value(24) != Standard_True)
4129 return 5;
4130 if (!doc_xml_open->Main().FindAttribute(TDataStd_ReferenceArray::GetID(), refarr))
4131 return 4;
4132 TDF_Tool::Entry(refarr->Value(444), entry_first);
4133 if (entry1 != entry_first)
4134 return 5;
4135 TDF_Tool::Entry(refarr->Value(445), entry_last);
4136 if (entry2 != entry_last)
4137 return 6;
4138 if (!doc_xml_open->Main().FindAttribute(TDataStd_ByteArray::GetID(), bytearr))
4139 return 4;
4140 if (bytearr->Value(15) != 0)
4141 return 5;
4142 if (bytearr->Value(16) != 10)
4143 return 5;
4144 if (bytearr->Value(17) != 100)
4145 return 5;
4146 if (bytearr->Value(18) != 200)
4147 return 5;
4148 if (bytearr->Value(19) != 250)
4149 return 5;
4150 if (bytearr->Value(20) != 251)
4151 return 5;
4152 if (bytearr->Value(21) != 252)
4153 return 5;
4154 if (bytearr->Value(22) != 253)
4155 return 5;
4156 if (bytearr->Value(23) != 254)
4157 return 5;
4158 if (bytearr->Value(24) != 255)
4159 return 5;
4160 if (!doc_xml_open->Main().FindAttribute(TDF_Reference::GetID(), ref))
4161 return 4;
4162 if (ref->Get().IsNull())
4163 return 5;
4164 if (ref->Get().Tag() != 103)
4165 return 5;
4166
4167 // Bin
4168 Handle(TDocStd_Document) doc_bin, doc_bin_open;
4169 app->NewDocument("BinOcaf", doc_bin);
4170 // TDataStd_Tick:
4171 TDataStd_Tick::Set(doc_bin->Main());
4172 // TDataStd_IntegerList:
4173 intlist = TDataStd_IntegerList::Set(doc_bin->Main());
4174 intlist->Append(1);
4175 intlist->Append(5);
4176 // TDataStd_RealList:
4177 dbllist = TDataStd_RealList::Set(doc_bin->Main());
4178 dbllist->Append(1.5);
4179 dbllist->Append(5.5);
4180 // TDataStd_ExtStringList:
4181 strlist = TDataStd_ExtStringList::Set(doc_bin->Main());
4182 strlist->Append("Bonjour");
4183 strlist->Append("Bonsoir");
4184 // TDataStd_BooleanList:
4185 boollist = TDataStd_BooleanList::Set(doc_bin->Main());
4186 boollist->Append(Standard_False);
4187 boollist->Append(Standard_True);
4188 // TDataStd_ReferenceList:
4189 TDF_Label Lbin1 = doc_bin->Main().FindChild(100);
4190 TDF_Tool::Entry(Lbin1, entry1);
4191 TDF_Label Lbin2 = doc_bin->Main().FindChild(101);
4192 TDF_Tool::Entry(Lbin2, entry2);
4193 reflist = TDataStd_ReferenceList::Set(doc_bin->Main());
4194 reflist->Append(Lbin1);
4195 reflist->Append(Lbin2);
4196 // TDataStd_BooleanArray:
4197 boolarr = TDataStd_BooleanArray::Set(doc_bin->Main(), 15, 24);
4198 boolarr->SetValue(15, Standard_False);
4199 boolarr->SetValue(16, Standard_True);
4200 boolarr->SetValue(17, Standard_True);
4201 boolarr->SetValue(18, Standard_True);
4202 boolarr->SetValue(19, Standard_True);
4203 boolarr->SetValue(20, Standard_True);
4204 boolarr->SetValue(21, Standard_False);
4205 boolarr->SetValue(22, Standard_True);
4206 boolarr->SetValue(23, Standard_True);
4207 boolarr->SetValue(24, Standard_True);
4208 // TDataStd_ReferenceArray:
4209 refarr = TDataStd_ReferenceArray::Set(doc_bin->Main(), 0, 1);
4210 refarr->SetValue(0, Lbin1);
4211 refarr->SetValue(1, Lbin2);
4212 // TDataStd_ByteArray:
4213 bytearr = TDataStd_ByteArray::Set(doc_bin->Main(), 15, 16);
4214 bytearr->SetValue(15, 0);
4215 bytearr->SetValue(16, 255);
4216 // TDataStd_NamedData:
4217 nameddata = TDataStd_NamedData::Set(doc_bin->Main());
4218 nameddata->SetByte("A", 12);
4219 nameddata->SetByte("B", 234);
4220 // TDF_Reference:
4221 Lstd3 = doc_bin->Main().FindChild(103);
4222 ref = TDF_Reference::Set(doc_bin->Main(), Lstd3);
4223 //
4224 // Save
15e8b082
M
4225 //if (app->SaveAs(doc_bin, "W:\\doc.cbf") != PCDM_SS_OK)
4226 if (app->SaveAs(doc_bin, aFile3) != PCDM_SS_OK)
7fd59977 4227 return 1;
4228 intlist.Nullify();
4229 ref.Nullify();
4230 app->Close(doc_bin);
4231 doc_bin.Nullify();
15e8b082
M
4232 //if (app->Open("W:\\doc.cbf", doc_bin_open) != PCDM_RS_OK)
4233 if (app->Open(aFile3, doc_bin_open) != PCDM_RS_OK)
7fd59977 4234 return 2;
4235 if (!doc_bin_open->Main().IsAttribute(TDataStd_Tick::GetID()))
4236 return 3;
4237 if (!doc_bin_open->Main().FindAttribute(TDataStd_IntegerList::GetID(), intlist))
4238 return 4;
4239 if (intlist->First() != 1)
4240 return 5;
4241 if (intlist->Last() != 5)
4242 return 6;
4243 if (!doc_bin_open->Main().FindAttribute(TDataStd_RealList::GetID(), dbllist))
4244 return 4;
4245 if (dbllist->First() != 1.5)
4246 return 5;
4247 if (dbllist->Last() != 5.5)
4248 return 6;
4249 if (!doc_bin_open->Main().FindAttribute(TDataStd_ExtStringList::GetID(), strlist))
4250 return 4;
4251 if (strlist->First() != "Bonjour")
4252 return 5;
4253 if (strlist->Last() != "Bonsoir")
4254 return 6;
4255 if (!doc_bin_open->Main().FindAttribute(TDataStd_BooleanList::GetID(), boollist))
4256 return 4;
4257 if (boollist->First() != Standard_False)
4258 return 5;
4259 if (boollist->Last() != Standard_True)
4260 return 6;
4261 if (!doc_bin_open->Main().FindAttribute(TDataStd_ReferenceList::GetID(), reflist))
4262 return 4;
4263 TDF_Tool::Entry(reflist->First(), entry_first);
4264 if (entry1 != entry_first)
4265 return 5;
4266 TDF_Tool::Entry(reflist->Last(), entry_last);
4267 if (entry2 != entry_last)
4268 return 6;
4269 if (!doc_bin_open->Main().FindAttribute(TDataStd_BooleanArray::GetID(), boolarr))
4270 return 4;
4271 if (boolarr->Value(15) != Standard_False)
4272 return 5;
4273 if (boolarr->Value(16) != Standard_True)
4274 return 5;
4275 if (boolarr->Value(17) != Standard_True)
4276 return 5;
4277 if (boolarr->Value(18) != Standard_True)
4278 return 5;
4279 if (boolarr->Value(19) != Standard_True)
4280 return 5;
4281 if (boolarr->Value(20) != Standard_True)
4282 return 5;
4283 if (boolarr->Value(21) != Standard_False)
4284 return 5;
4285 if (boolarr->Value(22) != Standard_True)
4286 return 5;
4287 if (boolarr->Value(23) != Standard_True)
4288 return 5;
4289 if (boolarr->Value(24) != Standard_True)
4290 return 5;
4291 if (!doc_bin_open->Main().FindAttribute(TDataStd_ReferenceArray::GetID(), refarr))
4292 return 4;
4293 TDF_Tool::Entry(refarr->Value(0), entry_first);
4294 if (entry1 != entry_first)
4295 return 5;
4296 TDF_Tool::Entry(refarr->Value(1), entry_last);
4297 if (entry2 != entry_last)
4298 return 6;
4299 if (!doc_bin_open->Main().FindAttribute(TDataStd_ByteArray::GetID(), bytearr))
4300 return 4;
4301 if (bytearr->Value(15) != 0)
4302 return 5;
4303 if (bytearr->Value(16) != 255)
4304 return 5;
4305 if (!doc_bin_open->Main().FindAttribute(TDataStd_NamedData::GetID(), nameddata))
4306 return 4;
4307 if (nameddata->GetByte("A") != 12)
4308 return 5;
4309 if (nameddata->GetByte("B") != 234)
4310 return 5;
4311 if (!doc_bin_open->Main().FindAttribute(TDF_Reference::GetID(), ref))
4312 return 4;
4313 if (ref->Get().IsNull())
4314 return 5;
4315 if (ref->Get().Tag() != 103)
4316 return 5;
4317
4318 return 0;
4319}
4320// For OCC16782 testing
4321
4322static Standard_Integer OCC16782 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
4323{
4324 if (argc != 4)
4325 {
4326 di << "Usage : " << argv[0] << " file.std file.xml file.cbf\n";
4327 return 1;
4328 }
4329 TCollection_ExtendedString aFile1(argv[1]);
4330 TCollection_ExtendedString aFile2(argv[2]);
4331 TCollection_ExtendedString aFile3(argv[3]);
4332
4333 if (app.IsNull())
4334 app = new AppStd_Application();
4335
4336 int good = 0;
4337
4338 Handle(TDocStd_Document) doc;
fff263bd 4339 app->NewDocument("BinOcaf", doc);
7fd59977 4340 doc->SetUndoLimit(10);
4341
4342 di <<"\nTestSetGet start\n";
4343 good += TestSetGet(doc);
4344 di <<"TestSetGet finish\n";
4345 di <<"Status = " << good << "\n";
4346
4347 di <<"\nTestUndoRedo start\n";
4348 good += TestUndoRedo(doc);
4349 di <<"TestUndoRedo finish\n";
4350 di <<"Status = " << good << "\n";
4351
4352 di <<"\nTestCopyPaste start\n";
4353 good += TestCopyPaste(doc);
4354 di <<"TestCopyPaste finish\n";
4355 di <<"Status = " << good << "\n";
4356
4357 di <<"\nTestOpenSave start\n";
4358 good += TestOpenSave(aFile1, aFile2, aFile3);
4359 di <<"TestOpenSave finish\n";
4360 di <<"Status = " << good << "\n";
4361
4362 if (!good)
4363 di <<"\nThe " << argv[0] << " test is passed well, OK\n";
4364 else
4365 di <<"\nThe " << argv[0] << " test failed, Faulty\n";
4366
4367 return 0;
4368}
4369
4370static Standard_Integer OCC12584 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
4371{
4372 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4373 if(aContext.IsNull()) {
586db386 4374 di << argv[0] << " ERROR : use 'vinit' command before \n";
7fd59977 4375 return -1;
4376 }
4377
4378 if (argc > 2)
4379 {
4380 di << "Usage : " << argv[0] << " [mode = 0/1/2]\n";
4381 return 1;
4382 }
4383 Standard_Integer mode = 0;
4384 if (argc == 2)
4385 {
91322f44 4386 mode = Draw::Atoi(argv[1]);
7fd59977 4387 }
4388 if (mode > 2 || mode < 0)
4389 {
4390 di << "Usage : " << argv[0] << " [mode = 0/1/2]\n";
4391 return 1;
4392 }
4393 Handle(V3d_View) V = ViewerTest::CurrentView();
7a324550 4394 static Handle(AIS_ColorScale) aCS;
4395 if (aCS.IsNull())
4396 {
4397 aCS = new AIS_ColorScale();
4398 }
4399 if (aCS->ZLayer() != Graphic3d_ZLayerId_TopOSD)
4400 {
4401 aCS->SetZLayer (Graphic3d_ZLayerId_TopOSD);
4402 }
778cd667 4403 if (aCS->TransformPersistence().IsNull()
4404 || aCS->TransformPersistence()->Mode() != Graphic3d_TMF_2d)
7a324550 4405 {
778cd667 4406 aContext->SetTransformPersistence (aCS, new Graphic3d_TransformPers (Graphic3d_TMF_2d, Aspect_TOTP_LEFT_LOWER));
7a324550 4407 }
b4b2ecca 4408 Standard_Integer aWinWidth, aWinHeight;
4409 V->Window()->Size (aWinWidth, aWinHeight);
4410 aCS->SetSize (aWinWidth, aWinHeight);
7fd59977 4411 if ( !V.IsNull() ) {
4412 if (mode == 0) {
0577ae8c 4413 aContext->Display (aCS, Standard_True);
7fd59977 4414 }
4415 if (mode == 1) {
0577ae8c 4416 aContext->Erase (aCS, Standard_False);
7fd59977 4417 V->UpdateLights();
4418 V->Update();
4419 }
4420 if (mode == 2) {
7a324550 4421 Standard_Boolean IsDisplayed = aContext->IsDisplayed (aCS);
7fd59977 4422 if (IsDisplayed)
586db386 4423 di <<"ColorScaleIsDisplayed = 1\n";
7fd59977 4424 else
586db386 4425 di <<"ColorScaleIsDisplayed = 0\n";
7fd59977 4426 }
4427 }
4428 return 0;
4429}
4430
4431#include <Interface_Macros.hxx>
4432#include <IGESControl_Controller.hxx>
4433#include <XSDRAW.hxx>
4434#include <Draw_ProgressIndicator.hxx>
4435#include <XSControl_WorkSession.hxx>
4436#include <Transfer_TransientProcess.hxx>
7fd59977 4437#include <TColStd_HSequenceOfTransient.hxx>
4438#include <Message_ProgressSentry.hxx>
4439#include <XSControl_TransferReader.hxx>
4440
7fd59977 4441#include <Geom_Plane.hxx>
4442static Standard_Integer OCC20766 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
4443{
4444 if (argc != 6)
4445 {
4446 di << "Usage : " << argv[0] << " plane a b c d\n";
4447 return 1;
4448 }
4449
91322f44 4450 Standard_Real A = Draw::Atof(argv[2]);
4451 Standard_Real B = Draw::Atof(argv[3]);
4452 Standard_Real C = Draw::Atof(argv[4]);
4453 Standard_Real D = Draw::Atof(argv[5]);
7fd59977 4454
4455 Handle(Geom_Geometry) result;
4456
4457 Handle(Geom_Plane) aPlane = new Geom_Plane(A, B, C, D);
4458 result = aPlane;
4459
4460 DrawTrSurf::Set(argv[1],result);
4461 return 0;
4462}
4463
4464static Standard_Integer OCC20627 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
4465{
4466 if(argc!=2)
4467 {
586db386 4468 di << "Usage : " << argv[0] << " MaxNbr\n";
7fd59977 4469 return -1;
4470 }
91322f44 4471 Standard_Integer aMaxNbr = Draw::Atoi(argv[1]);
7fd59977 4472
4473 for (Standard_Integer i=0;i<aMaxNbr;i++)
4474 {
4475 BRepBuilderAPI_MakePolygon w(gp_Pnt(0,0,0),gp_Pnt(0,100,0),gp_Pnt(20,100,0),gp_Pnt(20,0,0));
4476 w.Close();
4477 TopoDS_Wire wireShape( w.Wire());
4478 BRepBuilderAPI_MakeFace faceBuilder(wireShape);
4479 TopoDS_Face f( faceBuilder.Face());
4480 BRepMesh_IncrementalMesh im(f,1);
4481 BRepTools::Clean(f);
4482 }
4483 return 0;
4484}
4485
4486#include <IntCurvesFace_ShapeIntersector.hxx>
4487#include <gp_Lin.hxx>
4488Standard_Integer OCC17424 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
4489{
4490 if(argc!=9)
4491 {
586db386 4492 di << "Usage : " << argv[0] << " shape X_Pnt Y_Pnt Z_Pnt X_Dir Y_Dir Z_Dir PInf\n";
7fd59977 4493 return -1;
4494 }
4495
4496 TopoDS_Shape shape = DBRep::Get(argv[1]);
4497
4498 if (shape.IsNull()) {
4499 di<<" Null shape is not allowed";
4500 return 1;
4501 }
4502
91322f44 4503 Standard_Real X_Pnt = Draw::Atof(argv[2]);
4504 Standard_Real Y_Pnt = Draw::Atof(argv[3]);
4505 Standard_Real Z_Pnt = Draw::Atof(argv[4]);
7fd59977 4506
91322f44 4507 Standard_Real X_Dir = Draw::Atof(argv[5]);
4508 Standard_Real Y_Dir = Draw::Atof(argv[6]);
4509 Standard_Real Z_Dir = Draw::Atof(argv[7]);
7fd59977 4510
91322f44 4511 Standard_Real PInf = Draw::Atof(argv[8]);
7fd59977 4512
4513 IntCurvesFace_ShapeIntersector intersector;
4514 intersector.Load(shape, Precision::Intersection());
4515
4516 gp_Pnt origin(X_Pnt, Y_Pnt, Z_Pnt);
4517 gp_Dir dir(X_Dir, Y_Dir, Z_Dir);
4518 gp_Lin ray(origin, dir);
4519
4520 Standard_Real PSup = RealLast();
4521 intersector.PerformNearest(ray, PInf, PSup);
4522 if (intersector.NbPnt() != 0)
4523 {
4524 di << argv[0] << " status = 0 \n";
4525 Standard_Real w = intersector.WParameter(1);
4526 di << "w = " << w << "\n";
4527 } else {
4528 di << argv[0] << " status = -1 \n";
4529 }
4530 return 0;
4531}
4532
62110ee7
M
4533Standard_Integer OCC22301 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
4534{
4535 if (argc != 1) {
4536 di << "Usage : " << argv[0] << "\n";
4537 return 1;
4538 }
4539
4540 // Create mask 1111: extent == 4
4541 TColStd_PackedMapOfInteger aFullMask;
4542 for (Standard_Integer i = 0; i < 4; i++)
4543 aFullMask.Add(i);
4544
4545 // Create mask 1100: extent == 2
4546 TColStd_PackedMapOfInteger aPartMask;
4547 for (Standard_Integer i = 0; i < 2; i++)
4548 aPartMask.Add(i);
4549
586db386 4550 di << "aFullMask = 1111\n";
4551 di << "aPartMask = 1100\n";
62110ee7
M
4552
4553 Standard_Boolean isAffected;
4554
4555 isAffected = aFullMask.Intersect(aPartMask); // true; extent == 2 (OK)
4556 di << "First time: aFullMask.Intersect(aPartMask), isAffected = " << (Standard_Integer)isAffected << "\n";
4557 isAffected = aFullMask.Intersect(aPartMask); // true; extent == 0 (?)
4558 di << "Second time: aFullMask.Intersect(aPartMask), isAffected = " << (Standard_Integer)isAffected << "\n";
4559 isAffected = aFullMask.Subtract(aPartMask); // false (?)
4560 di << "After two intersections: aFullMask.Subtract(aPartMask), isAffected = " << (Standard_Integer)isAffected << "\n";
4561
4562 return 0;
4563}
62110ee7 4564
7fa0a598
S
4565#include <NCollection_DataMap.hxx>
4566Standard_Integer OCC22744 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
4567{
4568
4569 if (argc != 1) {
4570 di << "Usage : " << argv[0] << "\n";
4571 return 1;
4572 }
4573
4574 TCollection_ExtendedString anExtString;
4575
2857a8ac 4576 Standard_ExtCharacter aNonAsciiChar = 0x0f00;
7fa0a598
S
4577 anExtString.Insert(1, aNonAsciiChar);
4578
2857a8ac 4579 di << "Is ASCII: " << ( anExtString.IsAscii() ? "true : Error" : "false : OK" ) << "\n";
7fa0a598
S
4580 NCollection_DataMap<TCollection_ExtendedString, Standard_Integer> aMap;
4581 aMap.Bind(anExtString, 0);
4582
4583 return 0;
4584
4585}
4586
c5cb4686 4587Standard_Integer OCC22558 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
4588{
4589 if (argc != 10) {
4590 di << "Wrong number of arguments" << argv[0] << "\n";
4591 return 1;
4592 }
4593
91322f44 4594 Standard_Real X_vec = Draw::Atof(argv[1]);
4595 Standard_Real Y_vec = Draw::Atof(argv[2]);
4596 Standard_Real Z_vec = Draw::Atof(argv[3]);
c5cb4686 4597
91322f44 4598 Standard_Real X_dir = Draw::Atof(argv[4]);
4599 Standard_Real Y_dir = Draw::Atof(argv[5]);
4600 Standard_Real Z_dir = Draw::Atof(argv[6]);
c5cb4686 4601
91322f44 4602 Standard_Real X_pnt = Draw::Atof(argv[7]);
4603 Standard_Real Y_pnt = Draw::Atof(argv[8]);
4604 Standard_Real Z_pnt = Draw::Atof(argv[9]);
c5cb4686 4605
4606 gp_Dir toSym(X_vec, Y_vec, Z_vec);
4607 gp_Dir dir(X_dir, Y_dir, Z_dir);
4608 gp_Pnt loc(X_pnt, Y_pnt, Z_pnt);
4609 gp_Ax2 symObj(loc,dir);
4610 toSym.Mirror(symObj);
4611
4612 di << "The result " << toSym.X() << " " << toSym.Y() << " " << toSym.Z() << "\n";
4613 return 0;
4614}
4615
4616
4714a7a6
SJ
4617Standard_Integer OCC22736 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
4618{
4619
4620 if (argc != 9) {
4621 di << "Usage : " << argv[0] << " X_mirrorFirstPoint Y_mirrorFirstPoint X_mirrorSecondPoint Y_mirrorSecondPoint X_p1 Y_p1 X_p2 Y_p2\n";
4622 return 1;
4623 }
4624
91322f44 4625 Standard_Real X_mirrorFirstPoint = Draw::Atof(argv[1]);
4626 Standard_Real Y_mirrorFirstPoint = Draw::Atof(argv[2]);
4627 Standard_Real X_mirrorSecondPoint = Draw::Atof(argv[3]);
4628 Standard_Real Y_mirrorSecondPoint = Draw::Atof(argv[4]);
4629 Standard_Real X_p1 = Draw::Atof(argv[5]);
4630 Standard_Real Y_p1 = Draw::Atof(argv[6]);
4631 Standard_Real X_p2 = Draw::Atof(argv[7]);
4632 Standard_Real Y_p2 = Draw::Atof(argv[8]);
4714a7a6
SJ
4633
4634 gp_Trsf2d identityTransformation;
4635
4636 gp_Pnt2d mirrorFirstPoint(X_mirrorFirstPoint,Y_mirrorFirstPoint);
4637 gp_Pnt2d mirrorSecondPoint(X_mirrorSecondPoint,Y_mirrorSecondPoint);
4638 gp_Ax2d mirrorAxis(mirrorFirstPoint,gp_Vec2d(mirrorFirstPoint,mirrorSecondPoint));
4639
4640 gp_Pnt2d p1(X_p1,Y_p1);
4641 gp_Pnt2d p2(X_p2,Y_p2);
4642
4643 gp_Trsf2d M1;
4644 M1.SetMirror(mirrorAxis);
4645 gp_Trsf2d M2;
4646 M2.SetMirror(mirrorAxis);
4647 gp_Trsf2d Tcomp;
4648 Tcomp = M2.Multiplied(M1);
4649
4650 Standard_Real aTol = Precision::Confusion();
4651 Standard_Integer aStatus = 0;
4652
4653 //After applying two times the same mirror the point is located on the same location OK
4654 gp_Pnt2d p1MirrorM1 = p1.Transformed(M1);
4655 if ( Abs(p2.X() - p1MirrorM1.X()) > aTol )
4656 aStatus = 2;
4657 if ( Abs(p2.Y() - p1MirrorM1.Y()) > aTol )
4658 aStatus = 3;
4659
4660 gp_Pnt2d p1MirrorM1M2 = p1MirrorM1.Transformed(M2);
4661 if ( Abs(p1.X() - p1MirrorM1M2.X()) > aTol )
4662 aStatus = 4;
4663 if ( Abs(p1.Y() - p1MirrorM1M2.Y()) > aTol )
4664 aStatus = 5;
4665
4666 //If we apply the composed transformation of the same two mirrors to a point the result is //not located on the initial position.-->>ERROR
4667 gp_Pnt2d p1MirrorComp = p1.Transformed(Tcomp);
4668 if ( Abs(p1.X() - p1MirrorComp.X()) > aTol )
4669 aStatus = 6;
4670 if ( Abs(p1.Y() - p1MirrorComp.Y()) > aTol )
4671 aStatus = 7;
4672
4673 di << "Status = " << aStatus << "\n";
4674 return 0;
4714a7a6
SJ
4675}
4676
35e08fe8 4677Standard_Integer OCC23429(Draw_Interpretor& /*di*/,
7c104885 4678 Standard_Integer narg, const char** a)
4679{
4680 if (narg < 4) return 1;
4681
4682 TopoDS_Shape aShape = DBRep::Get(a[2]);
4683 if (aShape.IsNull()) return 1;
4684
4685 BRepFeat_SplitShape Spls(aShape);
4686 Spls.SetCheckInterior(Standard_False);
4687
4688 TopoDS_Shape aTool = DBRep::Get(a[3]);
4689
4690 BRepAlgoAPI_Section Builder(aShape, aTool, Standard_False);
4691 Builder.ComputePCurveOn1(Standard_True);
4692 if (narg == 5)
4693 Builder.Approximation(Standard_True);
4694 Builder.Build();
4695 TopoDS_Shape aSection = Builder.Shape();
4696
4697 TopExp_Explorer ExpSec(aSection, TopAbs_EDGE);
4698 for (; ExpSec.More(); ExpSec.Next())
4699 {
4700 TopoDS_Edge anEdge = TopoDS::Edge(ExpSec.Current());
4701 Handle(Geom2d_Curve) thePCurve;
4702 Handle(Geom_Surface) theSurface;
4703 TopLoc_Location theLoc;
4704 Standard_Real fpar, lpar;
4705 BRep_Tool::CurveOnSurface(anEdge, thePCurve, theSurface, theLoc, fpar, lpar);
4706 TopoDS_Face aFace;
4707 TopExp_Explorer ExpShape(aShape, TopAbs_FACE);
4708 for (; ExpShape.More(); ExpShape.Next())
4709 {
4710 aFace = TopoDS::Face(ExpShape.Current());
4711 TopLoc_Location aLoc;
4712 Handle(Geom_Surface) aSurface = BRep_Tool::Surface(aFace, aLoc);
4713 if (aSurface == theSurface && aLoc == theLoc)
4714 break;
4715 }
4716 Spls.Add(anEdge, aFace);
4717 }
4718
4719 TopoDS_Shape Result = Spls.Shape();
4720 DBRep::Set(a[1], Result);
4721
4722 return 0;
4723}
4724
9fe1ada8 4725#include <ExprIntrp_GenExp.hxx>
4726Standard_Integer CR23403 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
4727{
4728
4729 if (argc != 2) {
4730 di << "Usage : " << argv[0] << " string\n";
4731 return 1;
4732 }
4733
4734 Standard_CString aString = argv[1];
4735 Handle(ExprIntrp_GenExp) myExpr = ExprIntrp_GenExp::Create();
4736 try {
4737 OCC_CATCH_SIGNALS
4738 myExpr->Process( aString );
4739 }
9775fa61 4740 catch(Standard_Failure const& anException) {
4741 di << "Exception : " << anException.GetMessageString() << "\n";
9fe1ada8 4742 }
4743
4744 return 0;
4745}
4746
6b55f8e3 4747Standard_Integer OCC28478 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
4748{
4749 Standard_Integer nbOuter = (argc > 1 ? Draw::Atoi(argv[1]) : 3);
4750 Standard_Integer nbInner = (argc > 2 ? Draw::Atoi(argv[2]) : 2);
53d770b3 4751 Standard_Boolean isInf = (argc > 3 && ! strcmp (argv[3], "-inf"));
6b55f8e3 4752
4753 // test behavior of progress indicator when using nested scopes with names set by Sentry objects
4754 Handle(Draw_ProgressIndicator) aProgress = new Draw_ProgressIndicator (di, 1);
4755 aProgress->SetTextMode (Standard_True);
caee80f3 4756 aProgress->SetTclOutput (Standard_True);
6b55f8e3 4757
4758 // Outer cycle
4759 Message_ProgressSentry anOuter (aProgress, "Outer", 0, nbOuter, 1);
4760 for (int i = 0; i < nbOuter && anOuter.More(); i++, anOuter.Next())
4761 {
4762 // Inner cycle
53d770b3 4763 Message_ProgressSentry anInner (aProgress, "Inner", 0, nbInner, 1, isInf);
6b55f8e3 4764 for (int j = 0; j < nbInner && anInner.More(); j++, anInner.Next())
4765 {
4766 // Cycle body
4767 }
4768 }
4769
4770 return 0;
4771}
4772
1cd84fee 4773void QABugs::Commands_11(Draw_Interpretor& theCommands) {
4774 const char *group = "QABugs";
7fd59977 4775
4776 theCommands.Add("OCC128", "OCC128", __FILE__, OCC128, group);
4777
4778 // Remove as bad version of QAAddOrRemoveSelected from QADraw
4779 //theCommands.Add("OCC129", "OCC129 shape islocal", __FILE__, OCC129, group);
4780
4781 theCommands.Add("OCC136", "OCC136", __FILE__, OCC136, group);
4782 theCommands.Add("BUC60610","BUC60610 iges_input [name]",__FILE__,BUC60610,group);
7fd59977 4783
4784//====================================================
4785//
4786// Following commands are inserted from
4787// /dn03/KAS/dev/QAopt/src/QADraw/QADraw_TOPOLOGY.cxx
4788// ( 75455 Apr 16 18:59)
4789//
4790//====================================================
4791
4792 theCommands.Add("OCC105","OCC105 shape",__FILE__,OCC105,group);
4793 theCommands.Add("OCC9"," result path cur1 cur2 radius [tolerance]:\t test GeomFill_Pipe", __FILE__, pipe_OCC9,group);
4794
4795 theCommands.Add("OCC125","OCC125 shell", __FILE__, OCC125,group);
4796
4797 theCommands.Add("OCC157","findplanarsurface Result wire Tol",__FILE__,OCC157,group);
4798 //theCommands.Add("OCC165","OCC165",__FILE__,OCC165,group);
4799 theCommands.Add("OCC165","OCC165 file",__FILE__,OCC165,group);
4800 theCommands.Add("OCC297","OCC297",__FILE__,OCC297,group);
4801 //theCommands.Add("OCC305","OCC305",__FILE__,OCC305,group);
4802 theCommands.Add("OCC305","OCC305 file",__FILE__,OCC305,group);
4803
4804 // New commands:
4805 theCommands.Add("OCC166", "OCC166", __FILE__, OCC166, group);
4806 theCommands.Add("OCC381_Save", "OCC381_Save Doc", __FILE__, OCC381_Save, group);
4807 theCommands.Add("OCC381_SaveAs", "OCC381_SaveAs Doc Path", __FILE__, OCC381_SaveAs, group);
4808
4809 theCommands.Add("OCC299","OCC299 Solid Point [Tolerance=1.e-7]", __FILE__, OCC299bug, group);
4810 theCommands.Add("OCC309","OCC309", __FILE__, OCC309bug, group);
4811 theCommands.Add("OCC310","OCC310", __FILE__, OCC310bug, group);
4812
4813 //theCommands.Add("OCC277","OCC277", __FILE__, OCC277bug, group);
431d0f18 4814 theCommands.Add("OCC277","OCC277", __FILE__, OCC277bug, group);
7fd59977 4815
7fd59977 4816 theCommands.Add("OCC363", "OCC363 document filename ", __FILE__, OCC363, group);
4817 // Must use OCC299
4818 //theCommands.Add("OCC372", "OCC372", __FILE__, OCC372, group);
4819 theCommands.Add("OCC377", "OCC377", __FILE__, OCC377, group);
4820 theCommands.Add("OCC22", "OCC22 Result Shape CompoundOfSubshapesToBeDivided ConsiderLocation", __FILE__, OCC22, group);
4821 theCommands.Add("OCC24", "OCC24 Result Shape CompoundOfSubshapes ResourceFileName", __FILE__, OCC24, group);
4822 theCommands.Add("OCC369", "OCC369 Shape", __FILE__, OCC369, group);
4823 theCommands.Add("OCC524", "OCC524 LowerVector UpperVector InitialValueVector LowerRowMatrix UpperRowMatrix LowerColMatrix UpperColMatrix InitialValueMatrix", __FILE__, OCC524, group);
4824 theCommands.Add("OCC525", "OCC525", __FILE__, OCC525, group);
7fd59977 4825 //theCommands.Add("OCC578", "OCC578 shape1 shape2 shape3", __FILE__, OCC578, group);
431d0f18 4826 theCommands.Add("OCC578", "OCC578 shape1 shape2 shape3", __FILE__, OCC578, group);
7fd59977 4827 theCommands.Add("OCC669", "OCC669 GUID", __FILE__, OCC669, group);
4828 theCommands.Add("OCC738_ShapeRef", "OCC738_ShapeRef", __FILE__, OCC738_ShapeRef, group);
4829 theCommands.Add("OCC738_Assembly", "OCC738_Assembly", __FILE__, OCC738_Assembly, group);
4830 theCommands.Add("OCC708", "OCC708 shape ; Deactivate the current transformation", __FILE__, OCC708, group);
4831 theCommands.Add("OCC670", "OCC670", __FILE__, OCC670, group);
4832 theCommands.Add("OCC867", "OCC867 Point Surface Umin Usup Vmin Vsup", __FILE__, OCC867, group);
4833 theCommands.Add("OCC909", "OCC909 wire face", __FILE__, OCC909, group);
4834 theCommands.Add("OCC921", "OCC921 face", __FILE__, OCC921, group);
4835 theCommands.Add("OCC902", "OCC902 expression", __FILE__, OCC902, group);
4836
4837 theCommands.Add ("OCC1029_AISTransparency","OCC1029_AISTransparency (DOC, entry, [real])",__FILE__, OCC1029_AISTransparency, group);
7fd59977 4838 theCommands.Add ("OCC1031_AISMaterial", "OCC1031_AISMaterial (DOC, entry, [material])", __FILE__, OCC1031_AISMaterial, group);
4839 theCommands.Add ("OCC1032_AISWidth", "OCC1032_AISWidth (DOC, entry, [width])", __FILE__, OCC1032_AISWidth, group);
4840 theCommands.Add ("OCC1033_AISMode", "OCC1033_AISMode (DOC, entry, [mode])", __FILE__, OCC1033_AISMode, group);
4841 theCommands.Add ("OCC1034_AISSelectionMode", "OCC1034_AISSelectionMode (DOC, entry, [selectionmode])", __FILE__, OCC1034_AISSelectionMode, group);
4842
4843 //theCommands.Add("OCC1487", "OCC1487 CylinderVariant(=1/2) cylinder1 cylinder2 cutshape", __FILE__, OCC1487, group);
431d0f18 4844 theCommands.Add("OCC1487", "OCC1487 CylinderVariant(=1/2) cylinder1 cylinder2 cutshape", __FILE__, OCC1487, group);
7fd59977 4845
4846 theCommands.Add("OCC1077", "OCC1077 result", __FILE__, OCC1077, group);
4847 theCommands.Add("OCC5739", "OCC5739 name shape step", __FILE__, OCC5739_UniAbs, group);
4848 theCommands.Add("OCC6046", "OCC6046 nb_of_vectors size", __FILE__, OCC6046, group);
4849 theCommands.Add("OCC5698", "OCC5698 wire", __FILE__, OCC5698, group);
44b80414 4850 theCommands.Add("OCC6143", "OCC6143 catching signals", __FILE__, OCC6143, group);
4851 theCommands.Add("OCC30775", "OCC30775 catching signals in threads", __FILE__, OCC30775, group);
5879dab4 4852 theCommands.Add("OCC7141", "OCC7141 [nCount] aPath", __FILE__, OCC7141, group);
7fd59977 4853 theCommands.Add("OCC7372", "OCC7372", __FILE__, OCC7372, group);
4854 theCommands.Add("OCC8169", "OCC8169 edge1 edge2 plane", __FILE__, OCC8169, group);
4855 theCommands.Add("OCC10138", "OCC10138 lower upper", __FILE__, OCC10138, group);
4856 theCommands.Add("OCC7639", "OCC7639 index1 value1 ... [indexN valueN]", __FILE__, OCC7639, group);
4857 theCommands.Add("OCC8797", "OCC8797", __FILE__, OCC8797, group);
4858 theCommands.Add("OCC7068", "OCC7068", __FILE__, OCC7068, group);
4859 theCommands.Add("OCC11457", "OCC11457 polygon lastedge x1 y1 z1 x2 y2 z2 ...", __FILE__, OCC11457, group);
4860 theCommands.Add("OCC13963", "OCC13963 ratio origin_x origin_y origin_z", __FILE__, OCC13963, group);
4861 theCommands.Add("OCC14376", "OCC14376 shape [deflection]", __FILE__, OCC14376, group);
4862 theCommands.Add("OCC15489", "OCC15489 A B C", __FILE__, OCC15489, group);
4863 theCommands.Add("OCC15755", "OCC15755 file shape", __FILE__, OCC15755, group);
4864 theCommands.Add("OCC16782", "OCC16782 file.std file.xml file.cbf", __FILE__, OCC16782, group);
4865 theCommands.Add("OCC12584", "OCC12584 [mode = 0/1/2]", __FILE__, OCC12584, group);
7fd59977 4866 theCommands.Add("OCC20766", "OCC20766 plane a b c d", __FILE__, OCC20766, group);
4867 theCommands.Add("OCC20627", "OCC20627", __FILE__, OCC20627, group);
4868 theCommands.Add("OCC17424", "OCC17424 shape X_Pnt Y_Pnt Z_Pnt X_Dir Y_Dir Z_Dir PInf", __FILE__, OCC17424, group);
62110ee7 4869 theCommands.Add("OCC22301", "OCC22301", __FILE__, OCC22301, group);
4714a7a6 4870 theCommands.Add("OCC22736", "OCC22736 X_mirrorFirstPoint Y_mirrorFirstPoint X_mirrorSecondPoint Y_mirrorSecondPoint X_p1 Y_p1 X_p2 Y_p2", __FILE__, OCC22736, group);
7fa0a598 4871 theCommands.Add("OCC22744", "OCC22744", __FILE__, OCC22744, group);
c5cb4686 4872 theCommands.Add("OCC22558", "OCC22558 x_vec y_vec z_vec x_dir y_dir z_dit x_pnt y_pnt z_pnt", __FILE__, OCC22558, group);
9fe1ada8 4873 theCommands.Add("CR23403", "CR23403 string", __FILE__, CR23403, group);
7c104885 4874 theCommands.Add("OCC23429", "OCC23429 res shape tool [appr]", __FILE__, OCC23429, group);
53d770b3 4875 theCommands.Add("OCC28478", "OCC28478 [nb_outer=3 [nb_inner=2] [-inf]: test progress indicator on nested cycles", __FILE__, OCC28478, group);
7fd59977 4876 return;
4877}