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