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