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