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