0024277: DRAW command that shows coordinates of a vertex
[occt.git] / src / BRepTest / BRepTest_BasicCommands.cxx
CommitLineData
b311480e 1// Created on: 1994-12-13
2// Created by: Jacques GOUSSARD
3// Copyright (c) 1994-1999 Matra Datavision
4// Copyright (c) 1999-2012 OPEN CASCADE SAS
5//
6// The content of this file is subject to the Open CASCADE Technology Public
7// License Version 6.5 (the "License"). You may not use the content of this file
8// except in compliance with the License. Please obtain a copy of the License
9// at http://www.opencascade.org and read it completely before using this file.
10//
11// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
13//
14// The Original Code and all software distributed under the License is
15// distributed on an "AS IS" basis, without warranty of any kind, and the
16// Initial Developer hereby disclaims all such warranties, including without
17// limitation, any warranties of merchantability, fitness for a particular
18// purpose or non-infringement. Please see the License for the specific terms
19// and conditions governing the rights and limitations under the License.
20
7fd59977 21
22#include <Standard_Stream.hxx>
23#include <Standard_Macro.hxx>
24
25#include <BRepTest.hxx>
26
27#include <DBRep.hxx>
28#include <Draw_Appli.hxx>
29#include <Draw_Interpretor.hxx>
30#include <Draw_Box.hxx>
31
32#include <BRepBuilderAPI.hxx>
33#include <BRepBuilderAPI_FindPlane.hxx>
34#include <BRepBuilderAPI_Copy.hxx>
35#include <BRepBuilderAPI_Transform.hxx>
36#include <BRepBuilderAPI_GTransform.hxx>
37#include <BRepBuilderAPI_NurbsConvert.hxx>
38#include <gp_Ax2.hxx>
39#include <gp_Mat.hxx>
40#include <gp_GTrsf.hxx>
41#include <BRepOffsetAPI_NormalProjection.hxx>
42#include <BRepLib.hxx>
43#include <BRep_Builder.hxx>
44#include <BRepBndLib.hxx>
45#include <Bnd_Box.hxx>
46#include <TopExp_Explorer.hxx>
47#include <TopoDS.hxx>
48#include <BRepTools_WireExplorer.hxx>
49
50#include <GCPnts_QuasiUniformAbscissa.hxx>
51#include <Geom2dAdaptor_Curve.hxx>
52#include <GeomAdaptor_Curve.hxx>
53#include <ProjLib_ComputeApproxOnPolarSurface.hxx>
54#include <DrawTrSurf.hxx>
55
56
57#include <Draw_Segment3D.hxx>
58#include <Draw_Marker3D.hxx>
59#include <Draw_MarkerShape.hxx>
60
7fd59977 61#include <stdio.h>
62
63Standard_IMPORT Draw_Viewer dout;
64
65
66
67//=======================================================================
68// addpcurve
69//=======================================================================
70
71static Standard_Integer addpcurve(Draw_Interpretor& , Standard_Integer n, const char** a)
72{
73 if(n < 4) return 1;
74 TopoDS_Shape E = DBRep::Get(a[1]);
75 if (E.IsNull()) return 1;
76 Handle(Geom2d_Curve) PC = DrawTrSurf::GetCurve2d(a[2]);
77 TopoDS_Shape F = DBRep::Get(a[3]);
78 Standard_Real tol = 1.e-7;
79 if (n > 4) {
91322f44 80 tol = Draw::Atof(a[4]);
7fd59977 81 }
82 BRep_Builder BB;
83 BB.UpdateEdge(TopoDS::Edge(E), PC, TopoDS::Face(F),tol);
84 DBRep::Set(a[1], E);
85 return 0;
86}
87
88
89//=======================================================================
90// transform
91//=======================================================================
92
93static Standard_Integer transform(Draw_Interpretor& di,Standard_Integer n,const char** a)
94{
95 if (n <= 1) return 1;
96
97 gp_Trsf T;
98 Standard_Integer last = n;
99
100 if (!strcmp(a[0],"reset")) {
101 }
102 else if (!strcmp(a[0],"tmove")) {
103 if (n < 3) return 1;
104 TopoDS_Shape SL = DBRep::Get(a[n-1]);
105 if (SL.IsNull()) return 0;
106 T = SL.Location().Transformation();
107 last = n-1;
108 }
109 else if (!strcmp(a[0],"ttranslate")) {
110 if (n < 5) return 1;
91322f44 111 T.SetTranslation(gp_Vec(Draw::Atof(a[n-3]),Draw::Atof(a[n-2]),Draw::Atof(a[n-1])));
7fd59977 112 last = n-3;
113 }
114 else if (!strcmp(a[0],"trotate")) {
115 if (n < 9) return 1;
91322f44 116 T.SetRotation(gp_Ax1(gp_Pnt(Draw::Atof(a[n-7]),Draw::Atof(a[n-6]),Draw::Atof(a[n-5])),
117 gp_Vec(Draw::Atof(a[n-4]),Draw::Atof(a[n-3]),Draw::Atof(a[n-2]))),
118 Draw::Atof(a[n-1])* (M_PI / 180.0));
7fd59977 119 last = n-7;
120 }
121 else if (!strcmp(a[0],"tmirror")) {
122 if (n < 8) return 1;
91322f44 123 T.SetMirror(gp_Ax2(gp_Pnt(Draw::Atof(a[n-6]),Draw::Atof(a[n-5]),Draw::Atof(a[n-4])),
124 gp_Vec(Draw::Atof(a[n-3]),Draw::Atof(a[n-2]),Draw::Atof(a[n-1]))));
7fd59977 125 last = n-6;
126 }
127 else if (!strcmp(a[0],"tscale")) {
128 if (n < 6) return 1;
91322f44 129 T.SetScale(gp_Pnt(Draw::Atof(a[n-4]),Draw::Atof(a[n-3]),Draw::Atof(a[n-2])),Draw::Atof(a[n-1]));
7fd59977 130 last = n-4;
131
132 }
133
134 if (T.Form() == gp_Identity) {
135 TopLoc_Location L;
136 for (Standard_Integer i = 1; i < last; i++) {
137 TopoDS_Shape S = DBRep::Get(a[i]);
138 if (S.IsNull()) {
139 //cout << a[i] << " is not a valid shape" << endl;
140 di << a[i] << " is not a valid shape" << "\n";
141 }
142 else {
143 DBRep::Set(a[i],S.Located(L));
144 }
145 }
146 }
147 else {
148 BRepBuilderAPI_Transform trf(T);
149 for (Standard_Integer i = 1; i < last; i++) {
150 TopoDS_Shape S = DBRep::Get(a[i]);
151 if (S.IsNull()) {
152 //cout << a[i] << " is not a valid shape" << endl;
153 di << a[i] << " is not a valid shape" << "\n";
154 }
155 else {
156 trf.Perform(S);
157 if (trf.IsDone()){
158 DBRep::Set(a[i],trf.Shape());
159 }
160 else {
161 return 1;
162 }
163 }
164 }
165 }
166 return 0;
167}
168
169
170///=======================================================================
171// gtransform
172//=======================================================================
173
174static Standard_Integer deform(Draw_Interpretor& di,Standard_Integer n,const char** a)
175{
176 if (n <= 1) return 1;
177
178 Standard_Integer last = n;
179
180 gp_Trsf T;
181 gp_GTrsf GT(T);
182
91322f44 183// gp_Mat rot(Draw::Atof(a[last-3]),0,0,0,Draw::Atof(a[last-2]),0,0,0,Draw::Atof(a[last-1]));
184 gp_Mat rot(Draw::Atof(a[3]),0,0,0,Draw::Atof(a[4]),0,0,0,Draw::Atof(a[5]));
7fd59977 185 GT.SetVectorialPart(rot);
186 last -= 3;
187 BRepBuilderAPI_GTransform gtrf(GT);
188 BRepBuilderAPI_NurbsConvert nbscv;
189 // for (Standard_Integer i = 1; i < last; i++) {
190 // TopoDS_Shape S = DBRep::Get(a[i]);
191 TopoDS_Shape S = DBRep::Get(a[2]);
192 if (S.IsNull()) {
193 //cout << a[2] << " is not a valid shape" << endl;
194 di << a[2] << " is not a valid shape" << "\n";
195 }
196 else {
197 gtrf.Perform(S);
198 if (gtrf.IsDone()){
199 DBRep::Set(a[1],gtrf.Shape());
200 }
201 else {
202 return 1;
203 }
204 }
205
206 return 0;
207}
208
209//=======================================================================
210// tcopy
211//=======================================================================
212
213static Standard_Integer tcopy(Draw_Interpretor& di,Standard_Integer n,const char** a)
214{
215 Standard_Boolean copyGeom = Standard_True;
216 Standard_Integer iFirst = 1; // index of first shape argument
217
218 if (n > 1 && a[1][0] == '-' && a[1][1] == 'n' )
219 {
220 copyGeom = Standard_False;
221 iFirst = 2;
222 }
223
224 if (n < 3 || (n - iFirst) % 2) {
225 cout << "Use: " << a[0] << " [-n(ogeom)] shape1 copy1 [shape2 copy2 [...]]" << endl;
226 cout << "Option -n forbids copying of geometry (it will be shared)" << endl;
227 return 1;
228 }
229
230 BRepBuilderAPI_Copy cop;
231 Standard_Integer nbPairs = (n - iFirst) / 2;
232 for (Standard_Integer i=0; i < nbPairs; i++) {
233 cop.Perform(DBRep::Get(a[i+iFirst]), copyGeom);
234 DBRep::Set(a[i+iFirst+1],cop.Shape());
235 di << a[i+iFirst+1] << " ";
236 }
237 return 0;
238}
239
240
241//=======================================================================
242// NurbsConvert
243//=======================================================================
244
245static Standard_Integer nurbsconvert(Draw_Interpretor& di,Standard_Integer n,const char** a)
246{
247 if (n < 3) return 1;
248 if ((n-1)%2 != 0) return 1;
249 BRepBuilderAPI_NurbsConvert nbscv;
250 for (Standard_Integer i=0; i<(n-1)/2; i++) {
251 TopoDS_Shape S = DBRep::Get(a[2*i+2]);
252 if (S.IsNull()) {
253 //cout << a[2*i+2] << " is not a valid shape" << endl;
254 di << a[2*i+2] << " is not a valid shape" << "\n";
255 }
256 else {
257 nbscv.Perform(S);
258 if (nbscv.IsDone()){
259 DBRep::Set(a[2*i+1],nbscv.Shape());
260 }
261 else {
262 return 1;
263 }
264 }
265 }
266
267 return 0;
268
269}
270
271//=======================================================================
272// make a 3D edge curve
273//=======================================================================
274
275static Standard_Integer mkedgecurve (Draw_Interpretor& ,Standard_Integer n,const char** a)
276{
277
278 Standard_Boolean CurveDone ;
279
280 if (n < 3) return 1;
91322f44 281 Standard_Real Tolerance = Draw::Atof(a[2]) ;
7fd59977 282
283 TopoDS_Shape S = DBRep::Get(a[1]);
284
285 if (S.IsNull()) return 1;
286
287 CurveDone =
288 BRepLib::BuildCurves3d(S,
289 Tolerance) ;
290 return 0 ;
291}
292
293//=======================================================================
294// sameparameter
295//=======================================================================
296
297static Standard_Integer sameparameter(Draw_Interpretor& ,Standard_Integer n,const char** a)
298{
299 if (n < 2) return 1;
300 Standard_Real tol = 1.e-7;
301 TopoDS_Shape S = DBRep::Get(a[1]);
302 if (S.IsNull()) return 1;
303 Standard_Boolean force = !strcmp(a[0],"fsameparameter");
91322f44 304 if (n == 3) tol = Draw::Atof(a[2]);
7fd59977 305
306 BRepLib::SameParameter(S,tol,force);
307
308 DBRep::Set(a[1],S);
309 return 0;
310}
311//=======================================================================
312//function : updatetol
313//purpose :
314//=======================================================================
315static Standard_Integer updatetol(Draw_Interpretor& ,Standard_Integer n,const char** a)
316{
317 if (n < 2) return 1;
318
319 TopoDS_Shape S = DBRep::Get(a[1]);
320 if (S.IsNull()) return 1;
321
322 if (n==2) BRepLib::UpdateTolerances(S);
323 else BRepLib::UpdateTolerances(S,Standard_True);
324 DBRep::Set(a[1],S);
325 return 0;
326
327}
328
329//=======================================================================
330//function : OrienSolid
331//purpose :
332//=======================================================================
333static Standard_Integer orientsolid(Draw_Interpretor& ,Standard_Integer n,const char** a)
334{
335 if (n < 2) return 1;
336
337 TopoDS_Shape S = DBRep::Get(a[1]);
338 if (S.IsNull()) return 1;
339 if (S.ShapeType()!=TopAbs_SOLID) return 1;
340
341 BRepLib::OrientClosedSolid(TopoDS::Solid(S));
342
343 DBRep::Set(a[1],S);
344 return 0;
345
346}
347
348//=======================================================================
349//function : boundingstr
350//purpose :
351//=======================================================================
352static Standard_Integer boundingstr(Draw_Interpretor& di,Standard_Integer n,const char** a)
353{
354 if (n < 2) return 1;
355 TopoDS_Shape S = DBRep::Get(a[1]);
356 if (S.IsNull()) return 1;
357 Bnd_Box B;
358 BRepBndLib::Add(S,B);
359 Standard_Real axmin,aymin,azmin,axmax,aymax,azmax;
360 B.Get(axmin,aymin,azmin,axmax,aymax,azmax);
361 di << axmin<<" "<< aymin<<" "<< azmin<<" "<< axmax<<" "<< aymax<<" "<< azmax;
362 if (n >= 8) {
363 Draw::Set(a[2],axmin) ;
364 Draw::Set(a[3],aymin) ;
365 Draw::Set(a[4],azmin) ;
366 Draw::Set(a[5],axmax) ;
367 Draw::Set(a[6],aymax) ;
368 Draw::Set(a[7],azmax) ;
369 }
370 return 0;
371}
372
9f6931fb 373//=======================================================================
374//function : getcoords
375//purpose :
376//=======================================================================
377static Standard_Integer getcoords(Draw_Interpretor& di,Standard_Integer n,const char** a)
378{
379 if(n < 2)
380 return 1;
381
382 for (Standard_Integer i = 1; i < n; i++)
383 {
384 const TopoDS_Shape aShape = DBRep::Get (a[i]);
385
386 if (aShape.IsNull())
387 continue;
388
389 if (aShape.ShapeType() == TopAbs_VERTEX)
390 {
391 const TopoDS_Vertex& aVertex = TopoDS::Vertex(aShape);
392 gp_Pnt aPnt = BRep_Tool::Pnt(aVertex);
393
394 di << a[i] << " (x,y,z) : " << aPnt.X() << " " << aPnt.Y() << " " << aPnt.Z() << "\n";
395 }
396 }
397
398 return 0;
399}
400
7fd59977 401//=======================================================================
402//function : bounding
403//purpose :
404//=======================================================================
405static Standard_Integer bounding(Draw_Interpretor& di,Standard_Integer n,const char** a)
406{
407 if (n < 2) return 1;
408 Standard_Real axmin,aymin,azmin,axmax,aymax,azmax;
409 Bnd_Box B; Handle(Draw_Box) DB;
410
411 if (n == 2) {
412 TopoDS_Shape S = DBRep::Get(a[1]);
413 if (S.IsNull()) return 1;
414 BRepBndLib::Add(S,B);
415 B.Get(axmin,aymin,azmin,axmax,aymax,azmax);
416 DB = new Draw_Box(gp_Pnt(axmin,aymin,azmin),gp_Pnt(axmax,aymax,azmax),Draw_orange);
417 dout<<DB;
418 di << axmin<<" "<< aymin<<" "<< azmin<<" "<< axmax<<" "<< aymax<<" "<< azmax;
419 }
420 else if (n == 7) {
91322f44 421 axmin=Draw::Atof(a[1]);
422 aymin=Draw::Atof(a[2]);
423 azmin=Draw::Atof(a[3]);
424 axmax=Draw::Atof(a[4]);
425 aymax=Draw::Atof(a[5]);
426 azmax=Draw::Atof(a[6]);
7fd59977 427 DB = new Draw_Box(gp_Pnt(axmin,aymin,azmin),gp_Pnt(axmax,aymax,azmax),Draw_orange);
428 dout<<DB;
429 }
430 return 0;
431}
432//=======================================================================
433//function : findplane
434//purpose :
435//=======================================================================
436static Standard_Integer findplane(Draw_Interpretor& di,Standard_Integer n,const char** a)
437{
438 if (n < 3) return 1;
439 TopoDS_Shape S = DBRep::Get(a[1]);
440 if (S.IsNull()) return 1;
441 Standard_Real tolerance = 1.0e-5 ;
442 BRepBuilderAPI_FindPlane a_plane_finder(S,
443 tolerance) ;
444 if (a_plane_finder.Found()) {
445 //cout << " a plane is found " ;
446 di << " a plane is found \n";
447 DrawTrSurf::Set(a[2],a_plane_finder.Plane()) ;
448 }
449 return 0 ;
450}
451//=======================================================================
452//function : precision
453//purpose :
454//=======================================================================
455
456static Standard_Integer precision(Draw_Interpretor& di,Standard_Integer n,const char** a)
457{
458 n--;
459
460 if ( n == 0) {
461 //cout << " Current Precision = " << BRepBuilderAPI::Precision() << endl;
462 di << " Current Precision = " << BRepBuilderAPI::Precision() << "\n";
463 }
464 else {
91322f44 465 BRepBuilderAPI::Precision(Draw::Atof(a[1]));
7fd59977 466 }
467 return 0;
468}
469
470
471//=======================================================================
472//function : reperage shape (Int lin Shape) + pointe double click + maxtol
473//purpose :
474//=======================================================================
475#include <IntCurvesFace_ShapeIntersector.hxx>
476#include <gp_Lin.hxx>
477
478static Standard_Integer reperageshape(Draw_Interpretor& di, Standard_Integer narg , const char** a)
479{
480 Standard_Integer details=0;
481 if(narg<2) return 1;
482 if(narg==3) details=1;
483 const char *id1 = a[1];
484 TopoDS_Shape TheShape1 = DBRep::Get(id1);
485
486 //cout << "Pick positions with button "<<endl;
487 di << "Pick positions with button "<< "\n";
488 Standard_Integer id,X,Y,b;
489 gp_Trsf T;
490 gp_Pnt P1,P2;
491 dout.Select(id,X,Y,b);
492
493 dout.GetTrsf(id,T);
494 T.Invert();
495 Standard_Real z = dout.Zoom(id);
496 P2.SetCoord((Standard_Real)X /z,(Standard_Real)Y /z, 0.0);
497 P2.Transform(T);
498 P1.SetCoord((Standard_Real)X /z,(Standard_Real)Y /z,-1.0);
499 P1.Transform(T);
500
501
502 gp_Ax1 Axe(P1,gp_Vec(P1,P2));
503 IntCurvesFace_ShapeIntersector Inter;
504 Inter.Load(TheShape1,1e-7);
505
506 Inter.Perform(Axe,-RealLast(),RealLast());
507
508 //cout<<"\n --> ";
509 di <<"\n --> ";
510 if(Inter.NbPnt()) {
511 for(Standard_Integer i=1; i<=Inter.NbPnt(); i++) {
512 Standard_Integer numface=1;
513 TopExp_Explorer ExF;
514 for(ExF.Init(TheShape1,TopAbs_FACE);
515 ExF.More();
516 ExF.Next(),numface++) {
517 TopoDS_Face Face=TopoDS::Face(ExF.Current());
518 if(Face.IsEqual(Inter.Face(i))) {
519 //cout<<" "<<a[1]<<"_"<<numface;
520 di<<" "<<a[1]<<"_"<<numface;
521 continue;
522 }
523 }
524 const gp_Pnt& P = Inter.Pnt(i);
525 Standard_Real PMin = Inter.WParameter(i);
526 if(details) {
527 //cout<<" w:"<<PMin<<endl;
528 di<<" w:"<<PMin<< "\n";
529 }
530 if(Inter.Transition(i) == IntCurveSurface_In) {
531 if(Inter.State(i) == TopAbs_IN) {
532 Handle(Draw_Marker3D) p = new Draw_Marker3D(P, Draw_Square, Draw_rouge,2);
533 dout << p; dout.Flush();
534 }
535 else if(Inter.State(i) == TopAbs_ON) {
536 Handle(Draw_Marker3D) p = new Draw_Marker3D(P, Draw_Square, Draw_vert,2);
537 dout << p; dout.Flush();
538 }
539 }
540 else {
541 if(Inter.Transition(i) == IntCurveSurface_Out) {
542 if(Inter.State(i) == TopAbs_IN) {
543 Handle(Draw_Marker3D) p = new Draw_Marker3D(P, Draw_X, Draw_rouge,2);
544 dout << p; dout.Flush();
545 }
546 else if(Inter.State(i) == TopAbs_ON) {
547 Handle(Draw_Marker3D) p = new Draw_Marker3D(P, Draw_X, Draw_vert,2);
548 dout << p; dout.Flush();
549 }
550 }
551 }
552 }
553 }
554 //cout<<endl;
555 di << "\n";
556 return(0);
557}
558
559
560static Standard_Integer maxtolerance(Draw_Interpretor& theCommands,
561 Standard_Integer n, const char** a) {
562 if(n<2) return(1);
563 TopoDS_Shape TheShape = DBRep::Get(a[1]);
564 if(TheShape.IsNull()) return(1);
565
566 Standard_Real T,TMF,TME,TMV,TmF,TmE,TmV;
567 Standard_Integer nbF,nbE,nbV;
568 TMF=TME=TMV=-RealLast();
569 TmF=TmE=TmV=RealLast();
581971fe 570
571 TopTools_MapOfShape mapS;
572 mapS.Clear();
7fd59977 573
581971fe 574 for(TopExp_Explorer ex(TheShape,TopAbs_FACE);
575 ex.More();
576 ex.Next()) {
577 TopoDS_Face Face=TopoDS::Face(ex.Current());
7fd59977 578 T=BRep_Tool::Tolerance(Face);
579 if(T>TMF) TMF=T;
580 if(T<TmF) TmF=T;
581971fe 581 mapS.Add(Face);
7fd59977 582 }
581971fe 583
584 nbF = mapS.Extent();
585 mapS.Clear();
586
587 for(TopExp_Explorer ex(TheShape,TopAbs_EDGE);
588 ex.More();
589 ex.Next()) {
590 TopoDS_Edge Edge=TopoDS::Edge(ex.Current());
7fd59977 591 T=BRep_Tool::Tolerance(Edge);
592 if(T>TME) TME=T;
593 if(T<TmE) TmE=T;
581971fe 594 mapS.Add(Edge);
7fd59977 595 }
581971fe 596
597 nbE = mapS.Extent();
598 mapS.Clear();
599
600 for(TopExp_Explorer ex(TheShape,TopAbs_VERTEX);
601 ex.More();
602 ex.Next()) {
603 TopoDS_Vertex Vertex=TopoDS::Vertex(ex.Current());
7fd59977 604 T=BRep_Tool::Tolerance(Vertex);
605 if(T>TMV) TMV=T;
606 if(T<TmV) TmV=T;
581971fe 607 mapS.Add(Vertex);
7fd59977 608 }
7fd59977 609
581971fe 610 nbV = mapS.Extent();
611
612//#ifndef WNT
7fd59977 613 Standard_SStream sss;
614 sss << "\n## Tolerances on the shape " << a[1] << " (nbFaces:" << nbF
615 << " nbEdges:" << nbE << " nbVtx:" << nbV << ")\n" ;
616 sss.precision(5);
617 sss.setf(ios::scientific);
618 if(TmF<=TMF) sss << "\n Face : Min " << setw(8) << TmF <<" Max " << setw(8) << TMF << " \n ";
619 if(TmE<=TME) sss << "\n Edge : Min " << setw(8) << TmE <<" Max " << setw(8) << TME << " \n ";
620 if(TmV<=TMV) sss << "\n Vertex : Min " << setw(8) << TmV <<" Max " << setw(8) << TMV << " \n ";
621 theCommands << sss;
581971fe 622 //#endif*/
623 return 0;
7fd59977 624}
625
626
627static Standard_Integer vecdc(Draw_Interpretor& di,Standard_Integer ,const char** ) {
628 //cout << "Pick positions with button "<<endl;
629 di << "Pick positions with button "<< "\n";
630
631 Standard_Integer id,X,Y,b;
632 gp_Trsf T;
633 gp_Pnt P1,P2,PP1,PP2;
634
635 //-----------------------------------------------------------
636 dout.Select(id,X,Y,b); dout.GetTrsf(id,T);
637 T.Invert();
638 Standard_Real z = dout.Zoom(id);
639 P1.SetCoord((Standard_Real)X /z,(Standard_Real)Y /z,0.0);
640 P1.Transform(T);
641
642 dout.Select(id,X,Y,b); dout.GetTrsf(id,T);
643 T.Invert(); z = dout.Zoom(id);
644
645 P2.SetCoord((Standard_Real)X /z,(Standard_Real)Y /z,0.0);
646 P2.Transform(T);
647 Standard_Real xa,ya,za;
648 if(Abs(P1.X())>Abs(P2.X())) xa = P1.X(); else xa = P2.X();
649 if(Abs(P1.Y())>Abs(P2.Y())) ya = P1.Y(); else ya = P2.Y();
650 if(Abs(P1.Z())>Abs(P2.Z())) za = P1.Z(); else za = P2.Z();
651 P1.SetCoord(xa,ya,za);
652 Handle(Draw_Marker3D) D0 = new Draw_Marker3D(gp_Pnt(P1.X(),
653 P1.Y(),
654 P1.Z()),
655 Draw_Square,Draw_blanc,1);
656
657 dout << D0;
658 dout.Flush();
659 //-----------------------------------------------------------
660 dout.Select(id,X,Y,b);
661 dout.GetTrsf(id,T);
662 T.Invert();
663 z = dout.Zoom(id);
664 PP1.SetCoord((Standard_Real)X /z,(Standard_Real)Y /z,0.0);
665 PP1.Transform(T);
666 dout.Select(id,X,Y,b);
667 dout.GetTrsf(id,T);
668 T.Invert();
669 z = dout.Zoom(id);
670 PP2.SetCoord((Standard_Real)X /z,(Standard_Real)Y /z,0.0);
671 PP2.Transform(T);
672 if(Abs(PP1.X())>Abs(PP2.X())) xa = PP1.X(); else xa = PP2.X();
673 if(Abs(PP1.Y())>Abs(PP2.Y())) ya = PP1.Y(); else ya = PP2.Y();
674 if(Abs(PP1.Z())>Abs(PP2.Z())) za = PP1.Z(); else za = PP2.Z();
675 PP1.SetCoord(xa,ya,za);
676 Handle(Draw_Segment3D) d = new Draw_Segment3D(P1,PP1,Draw_blanc);
677 dout << d;
678 dout.Flush();
679 //cout<<"\nttran "<<PP1.X()-P1.X()<<" "<<PP1.Y()-P1.Y()<<" "<<PP1.Z()-P1.Z()<<endl;
680 di <<"\nttran "<<PP1.X()-P1.X()<<" "<<PP1.Y()-P1.Y()<<" "<<PP1.Z()-P1.Z()<< "\n";
681
682 static Standard_Integer nboxvecdp=0;
683 //cout<<"\nbox b"<<++nboxvecdp<<" "<<Min(P1.X(),PP1.X())<<" "<<Min(P1.Y(),PP1.Y())<<" "<<Min(PP1.Z(),P1.Z());
684 //cout<<" "<<Abs(PP1.X()-P1.X())<<" "<<Abs(PP1.Y()-P1.Y())<<" "<<Abs(PP1.Z()-P1.Z())<<endl;
685
686 //cout<<"\nDistance :"<<sqrt( (PP1.X()-P1.X())*(PP1.X()-P1.X())
687 // +(PP1.Y()-P1.Y())*(PP1.Y()-P1.Y())
688 // +(PP1.Z()-P1.Z())*(PP1.Z()-P1.Z()))<<endl;
689
690 di <<"\nbox b"<<++nboxvecdp<<" "<<Min(P1.X(),PP1.X())<<" "<<Min(P1.Y(),PP1.Y())<<" "<<Min(PP1.Z(),P1.Z());
691 di <<" "<<Abs(PP1.X()-P1.X())<<" "<<Abs(PP1.Y()-P1.Y())<<" "<<Abs(PP1.Z()-P1.Z())<< "\n";
692
693 di <<"\nDistance :"<<sqrt( (PP1.X()-P1.X())*(PP1.X()-P1.X())
694 +(PP1.Y()-P1.Y())*(PP1.Y()-P1.Y())
695 +(PP1.Z()-P1.Z())*(PP1.Z()-P1.Z()))<< "\n";
696 return(0);
697}
698//=======================================================================
699// nproject
700//=======================================================================
701
702#include <TopTools_SequenceOfShape.hxx>
703 static Standard_Integer nproject(Draw_Interpretor& di, Standard_Integer n, const char** a)
704{
705 if ( n < 4) return 1;
706 TopoDS_Shape InpShape;
707 Standard_Integer arg = 2, i;
708 TopTools_SequenceOfShape Args;
709
710 Standard_Real Tol = 1.e-4;
711 Standard_Real Tol2d;
712 Standard_Real MaxDistance = 1.e-3;
713 GeomAbs_Shape Continuity = GeomAbs_C2;
714 Standard_Integer MaxDeg = 14;
715 Standard_Integer MaxSeg = 16;
716
717 while((n > arg) && !(InpShape = DBRep::Get(a[arg])).IsNull()){
718 Args.Append(InpShape);
719 arg++;
720 }
721 if(Args.Length() < 2) return 1;
722
723 BRepOffsetAPI_NormalProjection OrtProj(Args.Last());
724
725 for(i = 1; i < Args.Length(); i++)
726 OrtProj.Add(Args(i));
727
728 if(n > arg)
729 if (!strcmp(a[arg],"-g")) {
730 OrtProj.SetLimit(Standard_False);
731 arg++;
732 }
733
734 if(n > arg)
735 if (!strcmp(a[arg],"-d")) {
736 arg++;
737 if(n > arg)
91322f44 738 MaxDistance = Draw::Atof(a[arg++]);
7fd59977 739 OrtProj.SetMaxDistance(MaxDistance);
740 }
741 if(n > arg) {
91322f44 742 Tol = Max(Draw::Atof(a[arg++]),1.e-10);
7fd59977 743 }
744
745 if(n > arg) {
91322f44 746 if (Draw::Atoi(a[arg]) == 0) Continuity = GeomAbs_C0;
747 else if (Draw::Atoi(a[arg]) == 1) Continuity = GeomAbs_C1;
7fd59977 748 arg++;
749 }
750
751
752 if(n > arg) {
91322f44 753 MaxDeg = Draw::Atoi(a[arg++]);
7fd59977 754 if (MaxDeg<1 || MaxDeg>14) MaxDeg = 14;
755 }
756
91322f44 757 if(n > arg) MaxSeg = Draw::Atoi(a[arg]);
7fd59977 758
759 Tol2d = Pow(Tol, 2./3);
760
761 OrtProj.SetParams(Tol, Tol2d, Continuity, MaxDeg, MaxSeg);
762 OrtProj.Build();
763 TopTools_ListOfShape Wire;
764 Standard_Boolean IsWire=OrtProj.BuildWire(Wire);
765 if (IsWire) {
766 //cout << " BuildWire OK " << endl;
767 di << " BuildWire OK " << "\n";
768 }
769 DBRep::Set(a[1], OrtProj.Shape());
770 return 0;
771}
772
773//==========================================================================
774//function : wexplo
0d969553 775// exploration of a wire
7fd59977 776//==========================================================================
777static Standard_Integer wexplo (Draw_Interpretor&,
778 Standard_Integer argc, const char** argv)
779{
780 char name[100];
781 if (argc < 2) return 1;
782
783 TopoDS_Shape C1 = DBRep::Get (argv[1],TopAbs_WIRE);
784 TopoDS_Shape C2 ;
785
786 if (argc > 2) C2 = DBRep::Get (argv[2],TopAbs_FACE);
787
788 if (C1.IsNull()) return 1;
789
790 BRepTools_WireExplorer we;
791 if (C2.IsNull()) we.Init(TopoDS::Wire(C1));
792 else we.Init(TopoDS::Wire(C1),TopoDS::Face(C2));
793
794 Standard_Integer k = 1;
795 while (we.More()) {
796 TopoDS_Edge E = we.Current();
91322f44 797 Sprintf(name,"WEDGE_%d",k);
7fd59977 798 DBRep::Set(name,E);
799 we.Next();
800 k++;
801 }
802
803 return 0;
804}
805
35e08fe8 806static Standard_Integer scalexyz(Draw_Interpretor& /*di*/, Standard_Integer n, const char** a)
86eff19e
J
807{
808 if (n < 6) return 1;
7fd59977 809
86eff19e
J
810 TopoDS_Shape aShapeBase = DBRep::Get(a[2]);
811 if (aShapeBase.IsNull()) return 1;
812
91322f44 813 Standard_Real aFactorX = Draw::Atof(a[3]);
814 Standard_Real aFactorY = Draw::Atof(a[4]);
815 Standard_Real aFactorZ = Draw::Atof(a[5]);
86eff19e
J
816
817 gp_GTrsf aGTrsf;
818 gp_Mat rot (aFactorX, 0, 0,
819 0, aFactorY, 0,
820 0, 0, aFactorZ);
821 aGTrsf.SetVectorialPart(rot);
822 BRepBuilderAPI_GTransform aBRepGTrsf (aShapeBase, aGTrsf, Standard_False);
823 if (!aBRepGTrsf.IsDone())
824 Standard_ConstructionError::Raise("Scaling not done");
825 TopoDS_Shape Result = aBRepGTrsf.Shape();
826
827 DBRep::Set(a[1], Result);
828 return 0;
829}
7fd59977 830
831void BRepTest::BasicCommands(Draw_Interpretor& theCommands)
832{
833 static Standard_Boolean done = Standard_False;
834 if (done) return;
835 done = Standard_True;
836
837 DBRep::BasicCommands(theCommands);
838
839 const char* g = "TOPOLOGY Basic shape commands";
840
841 theCommands.Add("addpcurve",
842 "addpcurve edge 2dcurve face [tol (default 1.e-7)]",
843 __FILE__,
844 addpcurve,g);
845
846 theCommands.Add("reset",
847 "reset name1 name2..., remove location",
848 __FILE__,
849 transform,g);
850
851 theCommands.Add("tmove",
852 "tmove name1 name2 ... name(location)",
853 __FILE__,
854 transform,g);
855
856 theCommands.Add("ttranslate",
857 "tmove name1 name2 ... dx dy dz",
858 __FILE__,
859 transform,g);
860
861 theCommands.Add("trotate","trotate name1 name2 ... x y z dx dy dz angle",
862 __FILE__,
863 transform,g);
864
865 theCommands.Add("tmirror",
866 "tmirror name x y z dx dy dz",
867 __FILE__,
868 transform,g);
869
870 theCommands.Add("tscale",
871 "tscale name x y z scale",
872 __FILE__,
873 transform,g);
874
875 theCommands.Add("tcopy",
876 "tcopy [-n(ogeom)] name1 result1 [name2 result2 ...]",
877 __FILE__,
878 tcopy,g);
879
880 theCommands.Add("precision",
881 "precision [preci]",
882 __FILE__,
883 precision,g);
884
885 theCommands.Add("mkedgecurve",
886 "mkedgecurve name tolerance",
887 __FILE__,
888 mkedgecurve,g);
889
890 theCommands.Add("fsameparameter",
0d969553 891 "fsameparameter shapename [tol (default 1.e-7)], \nforce sameparameter on all edges of the shape",
7fd59977 892 __FILE__,
893 sameparameter,g);
894
895 theCommands.Add("sameparameter",
896 "sameparameter shapename [tol (default 1.e-7)]",
897 __FILE__,
898 sameparameter,g);
899
900 theCommands.Add("updatetolerance",
901 "updatetolerance myShape [param] \n if [param] is absent - not verify of face tolerance, else - perform it",
902 __FILE__,
903 updatetol,g);
904
905 theCommands.Add("solidorientation",
906 "orientsolid myClosedSolid",
907 __FILE__,
908 orientsolid,g);
909
9f6931fb 910 theCommands.Add("getcoords",
911 "getcoords vertex1 vertex 2... ; shows coords of input vertices",
912 __FILE__,
913 getcoords,g);
914
7fd59977 915 theCommands.Add("bounding",
916 "bounding shape [ xmin ymin zmin xmax ymax zmax] ; draw bounds",
917 __FILE__,
918 bounding,g);
919
920 theCommands.Add("boundingstr",
921 "boundingstr shape [ xmin ymin zmin xmax ymax zmax] ; print bounding box",
922 __FILE__,
923 boundingstr,g);
924
925 theCommands.Add("nurbsconvert",
926 "nurbsconvert result name [result name]",
927 __FILE__,
928 nurbsconvert,g);
929
930 theCommands.Add("deform",
931 "deform newname name CoeffX CoeffY CoeffZ",
932 __FILE__,
933 deform,g);
934
935 theCommands.Add("findplane",
936 "findplane name planename ",
937 __FILE__,
938 findplane,g) ;
939
940 theCommands.Add("maxtolerance",
941 "maxtolerance shape ",
942 __FILE__,
943 maxtolerance,g) ;
944
945 theCommands.Add("reperageshape",
946 "reperage shape -> list of shape (result of interstion shape , line)",
947 __FILE__,
948 reperageshape,g) ;
949
950 theCommands.Add("vecdc",
951 "vecdc + Pointe double click ",
952 __FILE__,
953 vecdc,g) ;
954
955 theCommands.Add("nproject","nproject pj e1 e2 e3 ... surf -g -d [dmax] [Tol [continuity [maxdeg [maxseg]]]",
956 __FILE__,
957 nproject,g);
958
959 theCommands.Add("wexplo","wexplo wire [face] create WEDGE_i",
960 __FILE__,
961 wexplo,g);
86eff19e
J
962
963 theCommands.Add("scalexyz",
964 "scalexyz res shape factor_x factor_y factor_z",
965 __FILE__,
966 scalexyz, g);
7fd59977 967}