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