0033661: Data Exchange, Step Import - Tessellated GDTs are not imported
[occt.git] / src / BRepTest / BRepTest_SurfaceCommands.cxx
CommitLineData
b311480e 1// Created on: 1993-07-22
2// Created by: Remi LEQUETTE
3// Copyright (c) 1993-1999 Matra Datavision
973c2be1 4// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 5//
973c2be1 6// This file is part of Open CASCADE Technology software library.
b311480e 7//
d5f74e42 8// This library is free software; you can redistribute it and/or modify it under
9// the terms of the GNU Lesser General Public License version 2.1 as published
973c2be1 10// by the Free Software Foundation, with special exception defined in the file
11// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12// distribution for complete text of the license and disclaimer of any warranty.
b311480e 13//
973c2be1 14// Alternatively, this file may be used under the terms of Open CASCADE
15// commercial license or contractual agreement.
7fd59977 16
7fd59977 17#include <stdio.h>
18#include <BRepTest.hxx>
19#include <GeometryTest.hxx>
20
21#include <DrawTrSurf.hxx>
22#include <DBRep.hxx>
23#include <Draw_Interpretor.hxx>
24#include <Draw_Appli.hxx>
25
7fd59977 26#include <BRepLib.hxx>
27#include <BRepTools_Quilt.hxx>
28#include <BRepAdaptor_Curve.hxx>
29#include <BRepBuilderAPI_MakeFace.hxx>
30#include <BRepBuilderAPI_MakeShell.hxx>
7fd59977 31#include <BRepBuilderAPI_Sewing.hxx>
32#include <BRepOffsetAPI_FindContigousEdges.hxx>
33#include <TopExp_Explorer.hxx>
34#include <TopoDS.hxx>
7e785937 35#include <TCollection_AsciiString.hxx>
7fd59977 36#include <Geom_Surface.hxx>
37#include <Geom2d_TrimmedCurve.hxx>
d63f9881 38#include <TopTools_SequenceOfShape.hxx>
1c72dff6 39#include <Precision.hxx>
92434a36 40#include <Draw_ProgressIndicator.hxx>
7693827d 41#include <BRepBuilderAPI_FastSewing.hxx>
7fd59977 42
7868210d 43#include <GeomAPI_ProjectPointOnSurf.hxx>
d99f0355 44#include <Message.hxx>
7868210d 45
7fd59977 46//-----------------------------------------------------------------------
47// suppressarg : suppress a[d],modifie na--
48//-----------------------------------------------------------------------
49static void suppressarg(Standard_Integer& na,const char** a,const Standard_Integer d)
50{
51 for(Standard_Integer i=d;i<na;i++) {
52 a[i]=a[i+1];
53 a[i+1]=NULL;
54 }
55 na--;
56}
57
58
59//=======================================================================
60// mkface
61//=======================================================================
62
63static Standard_Integer mkface(Draw_Interpretor& , Standard_Integer n, const char** a)
64{
65 if (n < 3) return 1;
66
67 Handle(Geom_Surface) S = DrawTrSurf::GetSurface(a[2]);
68 if (S.IsNull()) {
d99f0355 69 Message::SendFail() << a[2] << " is not a surface";
7fd59977 70 return 1;
71 }
72
73 Standard_Boolean mkface = a[0][2] == 'f';
74 TopoDS_Shape res;
75
76 Standard_Boolean Segment = Standard_False;
77 if ( !mkface && (n == 4 || n == 8)) {
78 Segment = !strcmp(a[n-1],"1");
79 n--;
80 }
81
82 if (n == 3) {
83 if (mkface)
1c72dff6 84 res = BRepBuilderAPI_MakeFace(S, Precision::Confusion());
7fd59977 85 else
86 res = BRepBuilderAPI_MakeShell(S,Segment);
87 }
88 else if (n <= 5) {
89 if (!mkface) return 1;
90 Standard_Boolean orient = (n == 4);
91 TopoDS_Shape W = DBRep::Get(a[3],TopAbs_WIRE);
92 if (W.IsNull()) return 1;
93 res = BRepBuilderAPI_MakeFace(S,TopoDS::Wire(W),orient);
94 }
95 else {
96 if (mkface)
91322f44 97 res = BRepBuilderAPI_MakeFace(S,Draw::Atof(a[3]),Draw::Atof(a[4]),Draw::Atof(a[5]),Draw::Atof(a[6]),Precision::Confusion());
7fd59977 98 else
91322f44 99 res = BRepBuilderAPI_MakeShell(S,Draw::Atof(a[3]),Draw::Atof(a[4]),Draw::Atof(a[5]),Draw::Atof(a[6]),
7fd59977 100 Segment);
101 }
102
103 DBRep::Set(a[1],res);
104 return 0;
105}
106
107//=======================================================================
108// quilt
109//=======================================================================
110
111static Standard_Integer quilt(Draw_Interpretor& , Standard_Integer n, const char** a)
112{
113 if (n < 4) return 1;
114 BRepTools_Quilt Q;
115
116 Standard_Integer i = 2;
117 while (i < n) {
118 TopoDS_Shape S = DBRep::Get(a[i]);
119 if (!S.IsNull()) {
120 if (S.ShapeType() == TopAbs_EDGE) {
121 if (i+1 < n) {
122 TopoDS_Shape E = DBRep::Get(a[i+1]);
123 if (!E.IsNull()) {
124 if (E.ShapeType() == TopAbs_EDGE) {
125 i++;
126 Q.Bind(TopoDS::Edge(S),TopoDS::Edge(E));
127 }
128 }
129 }
130 }
131 if (S.ShapeType() == TopAbs_VERTEX) {
132 if (i+1 < n) {
133 TopoDS_Shape E = DBRep::Get(a[i+1]);
134 if (!E.IsNull()) {
135 if (E.ShapeType() == TopAbs_VERTEX) {
136 i++;
137 Q.Bind(TopoDS::Vertex(S),TopoDS::Vertex(E));
138 }
139 }
140 }
141 }
142 else {
143 Q.Add(S);
144 }
145 }
146 i++;
147 }
148
149 DBRep::Set(a[1],Q.Shells());
150 return 0;
151}
152
153
154//=======================================================================
155// mksurface
156//=======================================================================
157
158static Standard_Integer mksurface(Draw_Interpretor& , Standard_Integer n, const char** a)
159{
160 if (n < 3) return 1;
161
162 TopoDS_Shape S = DBRep::Get(a[2],TopAbs_FACE);
163 if (S.IsNull()) return 1;
164 TopLoc_Location L;
165 Handle(Geom_Surface) C = BRep_Tool::Surface(TopoDS::Face(S),L);
166
167
168 DrawTrSurf::Set(a[1],C->Transformed(L.Transformation()));
169 return 0;
170}
171
172//=======================================================================
173// mkplane
174//=======================================================================
175
1f0adf31 176static Standard_Integer mkplane(Draw_Interpretor& theDI, Standard_Integer n, const char** a)
7fd59977 177{
178 if (n < 3) return 1;
179
180 TopoDS_Shape S = DBRep::Get(a[2],TopAbs_WIRE);
181 if (S.IsNull()) return 1;
182
183 Standard_Boolean OnlyPlane = Standard_False;
184 if ( n == 4) {
185 OnlyPlane = !strcmp(a[3],"1");
186 }
187
1f0adf31 188 BRepBuilderAPI_MakeFace aMF(TopoDS::Wire(S), OnlyPlane);
189
190 switch(aMF.Error())
191 {
192 case BRepBuilderAPI_FaceDone:
193 DBRep::Set(a[1],aMF.Face());
194 break;
321659b0 195 case BRepBuilderAPI_NoFace:
1f0adf31 196 theDI << "Error. mkplane has been finished with \"No Face\" status.\n";
197 break;
321659b0 198 case BRepBuilderAPI_NotPlanar:
1f0adf31 199 theDI << "Error. mkplane has been finished with \"Not Planar\" status.\n";
200 break;
321659b0 201 case BRepBuilderAPI_CurveProjectionFailed:
1f0adf31 202 theDI << "Error. mkplane has been finished with \"Fail in projection curve\" status.\n";
203 break;
321659b0 204 case BRepBuilderAPI_ParametersOutOfRange:
1f0adf31 205 theDI << "Error. mkplane has been finished with \"Parameters are out of range\" status.\n";
206 break;
207 default:
208 theDI << "Error. Undefined status. Please check the code.\n";
209 break;
210 }
7fd59977 211
7fd59977 212 return 0;
213}
214
215//=======================================================================
216// pcurve
217//=======================================================================
218Standard_IMPORT Draw_Color DrawTrSurf_CurveColor(const Draw_Color col);
219Standard_IMPORT void DBRep_WriteColorOrientation ();
220Standard_IMPORT Draw_Color DBRep_ColorOrientation (const TopAbs_Orientation Or);
221
222static Standard_Integer pcurve(Draw_Interpretor& , Standard_Integer n, const char** a)
223{
224 Standard_Boolean mute = Standard_False;
225 for(Standard_Integer ia=1;ia<n;ia++) {
226 if (!strcasecmp(a[ia],"-mute")) {
227 suppressarg(n,a,ia);
228 mute = Standard_True;
229 }
230 }
231
232 if (n == 2) {
233 // pcurves of a face
234 TopoDS_Shape S = DBRep::Get(a[1],TopAbs_FACE);
235 if (S.IsNull()) return 1;
236
237 if (!mute) DBRep_WriteColorOrientation();
238 Draw_Color col, savecol = DrawTrSurf_CurveColor(Draw_rouge);
239
240 char* name = new char[100];
241 Standard_Real f,l;
242 S.Orientation(TopAbs_FORWARD);
243 TopExp_Explorer ex(S,TopAbs_EDGE);
244 for (Standard_Integer i=1; ex.More(); ex.Next(), i++) {
245 const Handle(Geom2d_Curve) c = BRep_Tool::CurveOnSurface
246 (TopoDS::Edge(ex.Current()),TopoDS::Face(S),f,l);
247 if ( c.IsNull() ) {
04232180 248 std::cout << "Error: Edge " << i << " does not have pcurve" << std::endl;
7fd59977 249 continue;
250 }
251 col = DBRep_ColorOrientation(ex.Current().Orientation());
252 DrawTrSurf_CurveColor(col);
253
91322f44 254 Sprintf(name,"%s_%d",a[1],i);
4e882c71 255 Standard_Real fr = c->FirstParameter(), lr = c->LastParameter();
256 Standard_Boolean IsPeriodic = c->IsPeriodic();
257 if (c->DynamicType() == STANDARD_TYPE(Geom2d_TrimmedCurve))
258 {
259 const Handle(Geom2d_Curve)& aC = Handle(Geom2d_TrimmedCurve)::DownCast (c)->BasisCurve();
260 IsPeriodic = aC->IsPeriodic();
261 fr = aC->FirstParameter();
262 lr = aC->LastParameter();
263 }
264 if(!IsPeriodic &&
265 ((fr - f > Precision::PConfusion()) || (l - lr > Precision::PConfusion())))
266 {
267 DrawTrSurf::Set(name, c);
268 }
269 else
270 {
271 DrawTrSurf::Set(name,new Geom2d_TrimmedCurve(c,f,l));
272 }
7fd59977 273 }
274 DrawTrSurf_CurveColor(savecol);
275
276 }
277 else if (n >= 4) {
278 TopoDS_Shape SE = DBRep::Get(a[2],TopAbs_EDGE);
279 if (SE.IsNull()) return 1;
280 TopoDS_Shape SF = DBRep::Get(a[3],TopAbs_FACE);
281 if (SF.IsNull()) return 1;
282
283 Draw_Color col, savecol = DrawTrSurf_CurveColor(Draw_rouge);
284 Standard_Real f,l;
285 const Handle(Geom2d_Curve) c = BRep_Tool::CurveOnSurface
286 (TopoDS::Edge(SE),TopoDS::Face(SF),f,l);
4e882c71 287 Standard_Real fr = c->FirstParameter(), lr = c->LastParameter();
288 Standard_Boolean IsPeriodic = c->IsPeriodic();
289 if (c->DynamicType() == STANDARD_TYPE(Geom2d_TrimmedCurve))
290 {
291 const Handle(Geom2d_Curve)& aC = Handle(Geom2d_TrimmedCurve)::DownCast (c)->BasisCurve();
292 IsPeriodic = aC->IsPeriodic();
293 fr = aC->FirstParameter();
294 lr = aC->LastParameter();
295 }
7fd59977 296
297 col = DBRep_ColorOrientation(SE.Orientation());
298 DrawTrSurf_CurveColor(col);
4e882c71 299 if(!IsPeriodic &&
300 ((fr - f > Precision::PConfusion()) || (l - lr > Precision::PConfusion())))
301 {
302 DrawTrSurf::Set(a[1], c);
303 }
304 else
305 {
306 DrawTrSurf::Set(a[1],new Geom2d_TrimmedCurve(c,f,l));
307 }
7fd59977 308 DrawTrSurf_CurveColor(savecol);
309 }
310 else {
311 return 1;
312 }
313
314 return 0;
315}
316
317//=======================================================================
318// sewing
319//=======================================================================
320
92434a36 321static Standard_Integer sewing (Draw_Interpretor& theDi,
d63f9881 322 Standard_Integer theArgc, const char** theArgv)
7fd59977 323{
7fd59977 324 BRepBuilderAPI_Sewing aSewing;
d63f9881 325 Standard_Integer aPar = 1;
326 TopTools_SequenceOfShape aSeq;
327
328 Standard_Real aTol = 1.0e-06;
329 Standard_Boolean aSewingMode = Standard_True;
330 Standard_Boolean anAnalysisMode = Standard_True;
331 Standard_Boolean aCuttingMode = Standard_True;
332 Standard_Boolean aNonManifoldMode = Standard_False;
333 Standard_Boolean aSameParameterMode = Standard_True;
334 Standard_Boolean aFloatingEdgesMode = Standard_False;
335 Standard_Boolean aFaceMode = Standard_True;
dc161d81
A
336 Standard_Boolean aSetMinTol = Standard_False;
337 Standard_Real aMinTol = 0.;
d63f9881 338 Standard_Real aMaxTol = Precision::Infinite();
339
340 for (Standard_Integer i = 2; i < theArgc; i++)
341 {
342 if (theArgv[i][0] == '-' || theArgv[i][0] == '+')
343 {
344 Standard_Boolean aVal = (theArgv[i][0] == '+' ? Standard_True : Standard_False);
345 switch (tolower(theArgv[i][1]))
346 {
347 case 'm':
348 {
349 if (tolower(theArgv[i][2]) == 'i' && i+1 < theArgc)
350 {
91322f44 351 if (Draw::Atof (theArgv[i+1]))
dc161d81 352 {
91322f44 353 aMinTol = Draw::Atof (theArgv[++i]);
dc161d81
A
354 aSetMinTol = Standard_True;
355 }
d63f9881 356 else
357 {
586db386 358 theDi << "Error! min tolerance can't possess the null value\n";
d63f9881 359 return (1);
360 }
361 }
362 if (tolower(theArgv[i][2]) == 'a' && i+1 < theArgc)
363 {
91322f44 364 if (Draw::Atof (theArgv[i+1]))
365 aMaxTol = Draw::Atof (theArgv[++i]);
d63f9881 366 else
367 {
586db386 368 theDi << "Error! max tolerance can't possess the null value\n";
d63f9881 369 return (1);
370 }
371 }
372 }
373 break;
374 case 's': aSewingMode = aVal; break;
375 case 'a': anAnalysisMode = aVal; break;
376 case 'c': aCuttingMode = aVal; break;
377 case 'n': aNonManifoldMode = aVal; break;
378 case 'p': aSameParameterMode = aVal; break;
379 case 'e': aFloatingEdgesMode = aVal; break;
380 case 'f': aFaceMode = aVal; break;
381 }
382 }
383 else
384 {
dc161d81
A
385 TopoDS_Shape aShape = DBRep::Get (theArgv[i]);
386 if (!aShape.IsNull())
d63f9881 387 {
d63f9881 388 aSeq.Append (aShape);
389 aPar++;
390 }
dc161d81
A
391 else
392 {
91322f44 393 if (Draw::Atof (theArgv[i]))
394 aTol = Draw::Atof (theArgv[i]);
dc161d81 395 }
d63f9881 396 }
7fd59977 397 }
d63f9881 398
399 if (aPar < 2)
400 {
586db386 401 theDi << "Use: " << theArgv[0] << " result [tolerance] shape1 shape2 ... [min tolerance] [max tolerance] [switches]\n";
402 theDi << "To set user's value of min/max tolerances the following syntax is used: +<parameter> <value>\n";
403 theDi << "- parameters are identified by letters:\n";
404 theDi << " mint - min tolerance\n";
405 theDi << " maxt - max tolerance\n";
406 theDi << "Switches allow to tune other parameters of Sewing\n";
407 theDi << "The following syntax is used: <symbol><parameter>\n";
408 theDi << "- symbol may be - to set parameter off, + to set on\n";
409 theDi << "- parameters are identified by letters:\n";
410 theDi << " s - mode for creating sewed shape\n";
411 theDi << " a - mode for analysis of input shapes\n";
412 theDi << " c - mode for cutting of free edges\n";
413 theDi << " n - mode for non manifold processing\n";
414 theDi << " p - mode for same parameter processing for edges\n";
415 theDi << " e - mode for sewing floating edges\n";
416 theDi << " f - mode for sewing faces\n";
d63f9881 417 return (1);
7fd59977 418 }
d63f9881 419
dc161d81
A
420 if (!aSetMinTol)
421 aMinTol = aTol*1e-4;
d63f9881 422 if (aTol < Precision::Confusion())
423 aTol = Precision::Confusion();
424 if (aMinTol < Precision::Confusion())
425 aMinTol = Precision::Confusion();
426 if (aMinTol > aTol)
427 {
586db386 428 theDi << "Error! min tolerance can't exceed working tolerance\n";
d63f9881 429 return (1);
430 }
431 if (aMaxTol < aTol)
432 {
586db386 433 theDi << "Error! max tolerance can't be less than working tolerance\n";
d63f9881 434 return (1);
7fd59977 435 }
d63f9881 436
437 aSewing.Init (aTol, aSewingMode, anAnalysisMode, aCuttingMode, aNonManifoldMode);
438 aSewing.SetSameParameterMode (aSameParameterMode);
439 aSewing.SetFloatingEdgesMode (aFloatingEdgesMode);
440 aSewing.SetFaceMode (aFaceMode);
441 aSewing.SetMinTolerance (aMinTol);
442 aSewing.SetMaxTolerance (aMaxTol);
443
444 for (Standard_Integer i = 1; i <= aSeq.Length(); i++)
445 aSewing.Add(aSeq.Value(i));
446
92434a36 447 Handle(Draw_ProgressIndicator) aProgress = new Draw_ProgressIndicator (theDi, 1);
7e785937 448 aSewing.Perform (aProgress->Start());
7fd59977 449 aSewing.Dump();
d63f9881 450
451 const TopoDS_Shape& aRes = aSewing.SewedShape();
452 if (!aRes.IsNull())
453 DBRep::Set(theArgv[1], aRes);
7fd59977 454 return 0;
455}
456
7693827d 457//=======================================================================
458//function : fastsewing
459//purpose :
460//=======================================================================
461Standard_Integer fastsewing (Draw_Interpretor& theDI,
462 Standard_Integer theNArg,
463 const char** theArgVal)
464{
465 if(theNArg < 3)
466 {
467 // 0 1 2 3 4
468 theDI << "Use: fastsewing result [-tol <value>] <list_of_faces>\n";
469 return 1;
470 }
471
472 BRepBuilderAPI_FastSewing aFS;
473
474 Standard_Integer aStartIndex = 2;
475
476 if(!strcmp(theArgVal[aStartIndex], "-tol"))
477 {
478 aFS.SetTolerance(Draw::Atof (theArgVal[aStartIndex+1]));
479 aStartIndex = 4;
480 }
481
482 for(Standard_Integer i = aStartIndex; i < theNArg; i++)
483 {
484 TopoDS_Shape aS = DBRep::Get(theArgVal[i]);
485
486 if(!aFS.Add(aS))
487 {
488 theDI << "Face is not added. See statuses.\n";
489 }
490 }
491
492 BRepBuilderAPI_FastSewing::FS_VARStatuses aStatus = aFS.GetStatuses();
493
494 if(aStatus)
495 {
496 theDI << "Error: There are some problems while adding (" <<
497 (static_cast<Standard_Integer>(aStatus)) << ")\n";
04232180 498 aFS.GetStatuses(&std::cout);
7693827d 499 }
500
501 aFS.Perform();
502
503 aStatus = aFS.GetStatuses();
504
505 if(aStatus)
506 {
507 theDI << "Error: There are some problems while performing (" <<
508 (static_cast<Standard_Integer>(aStatus)) << ")\n";
04232180 509 aFS.GetStatuses(&std::cout);
7693827d 510 }
511
512 DBRep::Set(theArgVal[1], aFS.GetResult());
513
514 return 0;
515}
516
7fd59977 517//=======================================================================
518// continuity
519//=======================================================================
520
521static Standard_Integer continuity (Draw_Interpretor& ,
522 Standard_Integer n, const char** a)
523{
524 if (n < 2) return (1);
525
526 BRepOffsetAPI_FindContigousEdges aFind;
527
528 TopoDS_Shape sh = DBRep::Get(a[1]);
529 Standard_Integer i=1;
530 if (sh.IsNull()) {
531 if (n < 3) return (1);
91322f44 532 Standard_Real tol = Draw::Atof(a[1]);
7fd59977 533 aFind.Init(tol, Standard_False);
534 i = 2;
535 }
536
537 while (i < n) {
538 sh = DBRep::Get(a[i]);
539 aFind.Add(sh);
540 i++;
541 }
542
543 aFind.Perform();
544 aFind.Dump();
545
7fd59977 546 return 0;
547}
548
549//=======================================================================
550// encoderegularity
551//=======================================================================
552static Standard_Integer encoderegularity (Draw_Interpretor& ,
553 Standard_Integer n, const char** a)
554
555{
556 if (n < 2) return 1;
557 TopoDS_Shape sh = DBRep::Get(a[1]);
558 if (sh.IsNull()) return 1;
559 if (n==2)
560 BRepLib::EncodeRegularity(sh);
561 else {
91322f44 562 Standard_Real Tol = Draw::Atof(a[2]);
c6541a0c 563 Tol *= M_PI/180.;
7fd59977 564 BRepLib::EncodeRegularity(sh, Tol);
565 }
566 return 0;
567}
568
a0bb29e7 569static Standard_Integer getedgeregul
570 (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
571{
572 if( argc < 3)
573 {
d99f0355 574 Message::SendFail() << "Invalid number of arguments. Should be: checkedgeregularity edge face1 [face2]";
a0bb29e7 575 return 1;
576 }
577
578 TopoDS_Shape anEdge = DBRep::Get(argv[1],TopAbs_EDGE);
579 TopoDS_Shape aFace1 = DBRep::Get(argv[2],TopAbs_FACE);
580 TopoDS_Shape aFace2 = (argc > 3 ? DBRep::Get(argv[3],TopAbs_FACE) : aFace1);
581 if( anEdge.IsNull() || aFace1.IsNull() || aFace2.IsNull())
582 {
d99f0355 583 Message::SendFail() << "Invalid number of arguments. Should be: getedgeregularity edge face1 [face2]";
a0bb29e7 584 return 1;
585 }
586
587 GeomAbs_Shape aRegularity = BRep_Tool::Continuity(TopoDS::Edge(anEdge), TopoDS::Face(aFace1), TopoDS::Face(aFace2));
588 TCollection_AsciiString aStrReg("Regularity of edge : ");
589 switch( aRegularity)
590 {
591 default:
592 case GeomAbs_C0 : aStrReg += "C0"; break;
593 case GeomAbs_G1 : aStrReg += "G1"; break;
594 case GeomAbs_C1 : aStrReg += "C1"; break;
595 case GeomAbs_G2 : aStrReg += "G2"; break;
596 case GeomAbs_C2 : aStrReg += "C2"; break;
597 case GeomAbs_C3 : aStrReg += "C3"; break;
598 case GeomAbs_CN : aStrReg += "CN"; break;
599 };
600
601 di<<aStrReg.ToCString()<<"\n";
602 return 0; // Done
603}
7fd59977 604
7868210d 605//=======================================================================
606//function : projponf
607//purpose :
608//=======================================================================
609static Standard_Integer projponf(Draw_Interpretor& di, Standard_Integer n, const char** a)
610{
611 if (n < 3 || n > 5) {
612 di << "Project point on the face.\n";
613 di << "Usage: projponf face pnt [extrema flag: -min/-max/-minmax] [extrema algo: -g(grad)/-t(tree)]\n";
614 return 1;
615 }
616 // get face
617 TopoDS_Shape aS = DBRep::Get(a[1]);
618 if (aS.IsNull()) {
619 di << "the face is a null shape\n";
620 return 0;
621 }
622 //
623 if (aS.ShapeType() != TopAbs_FACE) {
624 di << "not a face\n";
625 return 0;
626 }
627 //
628 const TopoDS_Face& aFace = *(TopoDS_Face*)&aS;
629 //
630 // get point
631 gp_Pnt aP;
632 DrawTrSurf::GetPoint(a[2], aP);
633 //
634 // get projection options
635 // default values;
636 Extrema_ExtAlgo anExtAlgo = Extrema_ExtAlgo_Grad;
637 Extrema_ExtFlag anExtFlag = Extrema_ExtFlag_MINMAX;
638 //
639 for (Standard_Integer i = 3; i < n; ++i) {
640 if (!strcasecmp(a[i], "-min")) {
641 anExtFlag = Extrema_ExtFlag_MIN;
642 }
643 else if (!strcasecmp(a[i], "-max")) {
644 anExtFlag = Extrema_ExtFlag_MAX;
645 }
646 else if (!strcasecmp(a[i], "-minmax")) {
647 anExtFlag = Extrema_ExtFlag_MINMAX;
648 }
649 else if (!strcasecmp(a[i], "-t")) {
650 anExtAlgo = Extrema_ExtAlgo_Tree;
651 }
652 else if (!strcasecmp(a[i], "-g")) {
653 anExtAlgo = Extrema_ExtAlgo_Grad;
654 }
655 }
656 //
657 // get surface
658 TopLoc_Location aLoc;
659 const Handle(Geom_Surface)& aSurf = BRep_Tool::Surface(aFace, aLoc);
660 // move point to surface location
661 aP.Transform(aLoc.Transformation().Inverted());
662 //
663 // get bounds of the surface
664 Standard_Real aUMin, aUMax, aVMin, aVMax;
665 aSurf->Bounds(aUMin, aUMax, aVMin, aVMax);
666 //
667 // initialize projector
668 GeomAPI_ProjectPointOnSurf aProjPS;
669 aProjPS.Init(aSurf, aUMin, aUMax, aVMin, aVMax);
670 // set the options
671 aProjPS.SetExtremaAlgo(anExtAlgo);
672 aProjPS.SetExtremaFlag(anExtFlag);
673 // perform projection
674 aProjPS.Perform(aP);
675 //
676 if (aProjPS.NbPoints()) {
677 // lower distance
678 Standard_Real aDist = aProjPS.LowerDistance();
679 // lower distance parameters
680 Standard_Real U, V;
681 aProjPS.LowerDistanceParameters(U, V);
682 // nearest point
683 gp_Pnt aPProj = aProjPS.NearestPoint();
684 // translate projection point to face location
685 aPProj.Transform(aLoc.Transformation());
686 //
687 // print the projection values
688 di << "proj dist = " << aDist << "\n";
689 di << "uvproj = " << U << " " << V << "\n";
690 di << "pproj = " << aPProj.X() << " " << aPProj.Y() << " " << aPProj.Z() << "\n";
691 }
692 else {
693 if (!aProjPS.IsDone()) {
694 di << "projection failed\n";
695 }
696 else {
697 di << "no projection found\n";
698 }
699 }
700 return 0;
701}
702
7fd59977 703//=======================================================================
704//function : SurfaceCommands
705//purpose :
706//=======================================================================
707
708void BRepTest::SurfaceCommands(Draw_Interpretor& theCommands)
709{
710 static Standard_Boolean done = Standard_False;
711 if (done) return;
712 done = Standard_True;
713
714 DBRep::BasicCommands(theCommands);
715 GeometryTest::SurfaceCommands(theCommands);
716
717 const char* g = "Surface topology commands";
718
719 theCommands.Add("mkface",
720 "mkface facename surfacename [ufirst ulast vfirst vlast] [wire [norient]]",
721 __FILE__,mkface,g);
722
723 theCommands.Add("mkshell",
724 "mkshell shellname surfacename [ufirst ulast vfirst vlast] [segment 0/1]",
725 __FILE__,mkface,g);
726
727 theCommands.Add("quilt",
728 "quilt compoundname shape1 edgeshape2 edgeshape1... shape2 edgeshape3 edgeshape1or2 ... shape3 ...",
729 __FILE__,quilt,g);
730
731 theCommands.Add("mksurface",
732 "mksurface surfacename facename",
733 __FILE__,mksurface,g);
734
735 theCommands.Add("mkplane",
736 "mkplane facename wirename [OnlyPlane 0/1]",
737 __FILE__,mkplane,g);
738
739 theCommands.Add("pcurve",
740 "pcurve [name edgename] facename",
741 __FILE__,pcurve,g);
742
743 theCommands.Add("sewing",
d63f9881 744 "sewing result [tolerance] shape1 shape2 ... [min tolerance] [max tolerance] [switches]",
7fd59977 745 __FILE__,sewing, g);
746
747 theCommands.Add("continuity",
748 "continuity [tolerance] shape1 shape2 ...",
749 __FILE__,continuity, g);
750
751 theCommands.Add("encoderegularity",
752 "encoderegularity shape [tolerance (in degree)]",
753 __FILE__,encoderegularity, g);
7693827d 754
755 theCommands.Add ("fastsewing", "fastsewing result [-tol <value>] <list_of_faces>",
756 __FILE__, fastsewing, g);
a0bb29e7 757 theCommands.Add ("getedgeregularity", "getedgeregularity edge face1 [face2]", __FILE__,getedgeregul,g);
7868210d 758
759 theCommands.Add ("projponf",
760 "projponf face pnt [extrema flag: -min/-max/-minmax] [extrema algo: -g(grad)/-t(tree)]\n"
761 "\t\tProject point on the face.",
762 __FILE__, projponf, g);
7fd59977 763}
764