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