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