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