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