1 // Created on: 1993-07-22
2 // Created by: Remi LEQUETTE
3 // Copyright (c) 1993-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
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
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.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
18 #include <BRepTest.hxx>
19 #include <GeometryTest.hxx>
21 #include <DrawTrSurf.hxx>
23 #include <Draw_Interpretor.hxx>
24 #include <Draw_Appli.hxx>
26 #include <BRep_Builder.hxx>
27 #include <BRep_Tool.hxx>
28 #include <BRepLib.hxx>
29 #include <BRepTools_Quilt.hxx>
30 #include <BRepAdaptor_Curve.hxx>
31 #include <BRepBuilderAPI_MakeFace.hxx>
32 #include <BRepBuilderAPI_MakeShell.hxx>
33 #include <BRepBuilderAPI.hxx>
34 #include <BRepBuilderAPI_Sewing.hxx>
35 #include <BRepOffsetAPI_FindContigousEdges.hxx>
36 #include <TopExp_Explorer.hxx>
38 #include <TopoDS_Face.hxx>
39 #include <Geom_Surface.hxx>
40 #include <Geom2d_TrimmedCurve.hxx>
41 #include <TopTools_ListOfShape.hxx>
42 #include <TopTools_SequenceOfShape.hxx>
43 #include <Precision.hxx>
44 #include <Draw_ProgressIndicator.hxx>
45 #include <NCollection_Vector.hxx>
46 #include <BRepBuilderAPI_FastSewing.hxx>
49 //#define strcasecmp strcmp Already defined
53 //-----------------------------------------------------------------------
54 // suppressarg : suppress a[d],modifie na--
55 //-----------------------------------------------------------------------
56 static void suppressarg(Standard_Integer& na,const char** a,const Standard_Integer d)
58 for(Standard_Integer i=d;i<na;i++) {
66 //=======================================================================
68 //=======================================================================
70 static Standard_Integer mkface(Draw_Interpretor& , Standard_Integer n, const char** a)
74 Handle(Geom_Surface) S = DrawTrSurf::GetSurface(a[2]);
76 cout << a[2] << " is not a surface" << endl;
80 Standard_Boolean mkface = a[0][2] == 'f';
83 Standard_Boolean Segment = Standard_False;
84 if ( !mkface && (n == 4 || n == 8)) {
85 Segment = !strcmp(a[n-1],"1");
91 res = BRepBuilderAPI_MakeFace(S, Precision::Confusion());
93 res = BRepBuilderAPI_MakeShell(S,Segment);
96 if (!mkface) return 1;
97 Standard_Boolean orient = (n == 4);
98 TopoDS_Shape W = DBRep::Get(a[3],TopAbs_WIRE);
99 if (W.IsNull()) return 1;
100 res = BRepBuilderAPI_MakeFace(S,TopoDS::Wire(W),orient);
104 res = BRepBuilderAPI_MakeFace(S,Draw::Atof(a[3]),Draw::Atof(a[4]),Draw::Atof(a[5]),Draw::Atof(a[6]),Precision::Confusion());
106 res = BRepBuilderAPI_MakeShell(S,Draw::Atof(a[3]),Draw::Atof(a[4]),Draw::Atof(a[5]),Draw::Atof(a[6]),
110 DBRep::Set(a[1],res);
114 //=======================================================================
116 //=======================================================================
118 static Standard_Integer quilt(Draw_Interpretor& , Standard_Integer n, const char** a)
123 Standard_Integer i = 2;
125 TopoDS_Shape S = DBRep::Get(a[i]);
127 if (S.ShapeType() == TopAbs_EDGE) {
129 TopoDS_Shape E = DBRep::Get(a[i+1]);
131 if (E.ShapeType() == TopAbs_EDGE) {
133 Q.Bind(TopoDS::Edge(S),TopoDS::Edge(E));
138 if (S.ShapeType() == TopAbs_VERTEX) {
140 TopoDS_Shape E = DBRep::Get(a[i+1]);
142 if (E.ShapeType() == TopAbs_VERTEX) {
144 Q.Bind(TopoDS::Vertex(S),TopoDS::Vertex(E));
156 DBRep::Set(a[1],Q.Shells());
161 //=======================================================================
163 //=======================================================================
165 static Standard_Integer mksurface(Draw_Interpretor& , Standard_Integer n, const char** a)
169 TopoDS_Shape S = DBRep::Get(a[2],TopAbs_FACE);
170 if (S.IsNull()) return 1;
172 Handle(Geom_Surface) C = BRep_Tool::Surface(TopoDS::Face(S),L);
175 DrawTrSurf::Set(a[1],C->Transformed(L.Transformation()));
179 //=======================================================================
181 //=======================================================================
183 static Standard_Integer mkplane(Draw_Interpretor& theDI, Standard_Integer n, const char** a)
187 TopoDS_Shape S = DBRep::Get(a[2],TopAbs_WIRE);
188 if (S.IsNull()) return 1;
190 Standard_Boolean OnlyPlane = Standard_False;
192 OnlyPlane = !strcmp(a[3],"1");
195 BRepBuilderAPI_MakeFace aMF(TopoDS::Wire(S), OnlyPlane);
199 case BRepBuilderAPI_FaceDone:
200 DBRep::Set(a[1],aMF.Face());
203 theDI << "Error. mkplane has been finished with \"No Face\" status.\n";
205 case BRepLib_NotPlanar:
206 theDI << "Error. mkplane has been finished with \"Not Planar\" status.\n";
208 case BRepLib_CurveProjectionFailed:
209 theDI << "Error. mkplane has been finished with \"Fail in projection curve\" status.\n";
211 case BRepLib_ParametersOutOfRange:
212 theDI << "Error. mkplane has been finished with \"Parameters are out of range\" status.\n";
215 theDI << "Error. Undefined status. Please check the code.\n";
222 //=======================================================================
224 //=======================================================================
225 Standard_IMPORT Draw_Color DrawTrSurf_CurveColor(const Draw_Color col);
226 Standard_IMPORT void DBRep_WriteColorOrientation ();
227 Standard_IMPORT Draw_Color DBRep_ColorOrientation (const TopAbs_Orientation Or);
229 static Standard_Integer pcurve(Draw_Interpretor& , Standard_Integer n, const char** a)
231 Standard_Boolean mute = Standard_False;
232 for(Standard_Integer ia=1;ia<n;ia++) {
233 if (!strcasecmp(a[ia],"-mute")) {
235 mute = Standard_True;
241 TopoDS_Shape S = DBRep::Get(a[1],TopAbs_FACE);
242 if (S.IsNull()) return 1;
244 if (!mute) DBRep_WriteColorOrientation();
245 Draw_Color col, savecol = DrawTrSurf_CurveColor(Draw_rouge);
247 char* name = new char[100];
249 S.Orientation(TopAbs_FORWARD);
250 TopExp_Explorer ex(S,TopAbs_EDGE);
251 for (Standard_Integer i=1; ex.More(); ex.Next(), i++) {
252 const Handle(Geom2d_Curve) c = BRep_Tool::CurveOnSurface
253 (TopoDS::Edge(ex.Current()),TopoDS::Face(S),f,l);
255 cout << "Error: Edge " << i << " does not have pcurve" << endl;
258 col = DBRep_ColorOrientation(ex.Current().Orientation());
259 DrawTrSurf_CurveColor(col);
261 Sprintf(name,"%s_%d",a[1],i);
262 DrawTrSurf::Set(name,new Geom2d_TrimmedCurve(c,f,l));
264 DrawTrSurf_CurveColor(savecol);
268 TopoDS_Shape SE = DBRep::Get(a[2],TopAbs_EDGE);
269 if (SE.IsNull()) return 1;
270 TopoDS_Shape SF = DBRep::Get(a[3],TopAbs_FACE);
271 if (SF.IsNull()) return 1;
273 Draw_Color col, savecol = DrawTrSurf_CurveColor(Draw_rouge);
275 const Handle(Geom2d_Curve) c = BRep_Tool::CurveOnSurface
276 (TopoDS::Edge(SE),TopoDS::Face(SF),f,l);
278 col = DBRep_ColorOrientation(SE.Orientation());
279 DrawTrSurf_CurveColor(col);
280 DrawTrSurf::Set(a[1],new Geom2d_TrimmedCurve(c,f,l));
281 DrawTrSurf_CurveColor(savecol);
290 //=======================================================================
292 //=======================================================================
294 static Standard_Integer sewing (Draw_Interpretor& theDi,
295 Standard_Integer theArgc, const char** theArgv)
297 BRepBuilderAPI_Sewing aSewing;
298 Standard_Integer aPar = 1;
299 TopTools_SequenceOfShape aSeq;
301 Standard_Real aTol = 1.0e-06;
302 Standard_Boolean aSewingMode = Standard_True;
303 Standard_Boolean anAnalysisMode = Standard_True;
304 Standard_Boolean aCuttingMode = Standard_True;
305 Standard_Boolean aNonManifoldMode = Standard_False;
306 Standard_Boolean aSameParameterMode = Standard_True;
307 Standard_Boolean aFloatingEdgesMode = Standard_False;
308 Standard_Boolean aFaceMode = Standard_True;
309 Standard_Boolean aSetMinTol = Standard_False;
310 Standard_Real aMinTol = 0.;
311 Standard_Real aMaxTol = Precision::Infinite();
313 for (Standard_Integer i = 2; i < theArgc; i++)
315 if (theArgv[i][0] == '-' || theArgv[i][0] == '+')
317 Standard_Boolean aVal = (theArgv[i][0] == '+' ? Standard_True : Standard_False);
318 switch (tolower(theArgv[i][1]))
322 if (tolower(theArgv[i][2]) == 'i' && i+1 < theArgc)
324 if (Draw::Atof (theArgv[i+1]))
326 aMinTol = Draw::Atof (theArgv[++i]);
327 aSetMinTol = Standard_True;
331 theDi << "Error! min tolerance can't possess the null value\n";
335 if (tolower(theArgv[i][2]) == 'a' && i+1 < theArgc)
337 if (Draw::Atof (theArgv[i+1]))
338 aMaxTol = Draw::Atof (theArgv[++i]);
341 theDi << "Error! max tolerance can't possess the null value\n";
347 case 's': aSewingMode = aVal; break;
348 case 'a': anAnalysisMode = aVal; break;
349 case 'c': aCuttingMode = aVal; break;
350 case 'n': aNonManifoldMode = aVal; break;
351 case 'p': aSameParameterMode = aVal; break;
352 case 'e': aFloatingEdgesMode = aVal; break;
353 case 'f': aFaceMode = aVal; break;
358 TopoDS_Shape aShape = DBRep::Get (theArgv[i]);
359 if (!aShape.IsNull())
361 aSeq.Append (aShape);
366 if (Draw::Atof (theArgv[i]))
367 aTol = Draw::Atof (theArgv[i]);
374 theDi << "Use: " << theArgv[0] << " result [tolerance] shape1 shape2 ... [min tolerance] [max tolerance] [switches]\n";
375 theDi << "To set user's value of min/max tolerances the following syntax is used: +<parameter> <value>\n";
376 theDi << "- parameters are identified by letters:\n";
377 theDi << " mint - min tolerance\n";
378 theDi << " maxt - max tolerance\n";
379 theDi << "Switches allow to tune other parameters of Sewing\n";
380 theDi << "The following syntax is used: <symbol><parameter>\n";
381 theDi << "- symbol may be - to set parameter off, + to set on\n";
382 theDi << "- parameters are identified by letters:\n";
383 theDi << " s - mode for creating sewed shape\n";
384 theDi << " a - mode for analysis of input shapes\n";
385 theDi << " c - mode for cutting of free edges\n";
386 theDi << " n - mode for non manifold processing\n";
387 theDi << " p - mode for same parameter processing for edges\n";
388 theDi << " e - mode for sewing floating edges\n";
389 theDi << " f - mode for sewing faces\n";
395 if (aTol < Precision::Confusion())
396 aTol = Precision::Confusion();
397 if (aMinTol < Precision::Confusion())
398 aMinTol = Precision::Confusion();
401 theDi << "Error! min tolerance can't exceed working tolerance\n";
406 theDi << "Error! max tolerance can't be less than working tolerance\n";
410 aSewing.Init (aTol, aSewingMode, anAnalysisMode, aCuttingMode, aNonManifoldMode);
411 aSewing.SetSameParameterMode (aSameParameterMode);
412 aSewing.SetFloatingEdgesMode (aFloatingEdgesMode);
413 aSewing.SetFaceMode (aFaceMode);
414 aSewing.SetMinTolerance (aMinTol);
415 aSewing.SetMaxTolerance (aMaxTol);
417 for (Standard_Integer i = 1; i <= aSeq.Length(); i++)
418 aSewing.Add(aSeq.Value(i));
420 Handle(Draw_ProgressIndicator) aProgress = new Draw_ProgressIndicator (theDi, 1);
421 aSewing.Perform (aProgress);
424 const TopoDS_Shape& aRes = aSewing.SewedShape();
426 DBRep::Set(theArgv[1], aRes);
430 //=======================================================================
431 //function : fastsewing
433 //=======================================================================
434 Standard_Integer fastsewing (Draw_Interpretor& theDI,
435 Standard_Integer theNArg,
436 const char** theArgVal)
441 theDI << "Use: fastsewing result [-tol <value>] <list_of_faces>\n";
445 BRepBuilderAPI_FastSewing aFS;
447 Standard_Integer aStartIndex = 2;
449 if(!strcmp(theArgVal[aStartIndex], "-tol"))
451 aFS.SetTolerance(Draw::Atof (theArgVal[aStartIndex+1]));
455 for(Standard_Integer i = aStartIndex; i < theNArg; i++)
457 TopoDS_Shape aS = DBRep::Get(theArgVal[i]);
461 theDI << "Face is not added. See statuses.\n";
465 BRepBuilderAPI_FastSewing::FS_VARStatuses aStatus = aFS.GetStatuses();
469 theDI << "Error: There are some problems while adding (" <<
470 (static_cast<Standard_Integer>(aStatus)) << ")\n";
471 aFS.GetStatuses(&cout);
476 aStatus = aFS.GetStatuses();
480 theDI << "Error: There are some problems while performing (" <<
481 (static_cast<Standard_Integer>(aStatus)) << ")\n";
482 aFS.GetStatuses(&cout);
485 DBRep::Set(theArgVal[1], aFS.GetResult());
490 //=======================================================================
492 //=======================================================================
494 static Standard_Integer continuity (Draw_Interpretor& ,
495 Standard_Integer n, const char** a)
497 if (n < 2) return (1);
499 BRepOffsetAPI_FindContigousEdges aFind;
501 TopoDS_Shape sh = DBRep::Get(a[1]);
502 Standard_Integer i=1;
504 if (n < 3) return (1);
505 Standard_Real tol = Draw::Atof(a[1]);
506 aFind.Init(tol, Standard_False);
511 sh = DBRep::Get(a[i]);
522 //=======================================================================
524 //=======================================================================
525 static Standard_Integer encoderegularity (Draw_Interpretor& ,
526 Standard_Integer n, const char** a)
530 TopoDS_Shape sh = DBRep::Get(a[1]);
531 if (sh.IsNull()) return 1;
533 BRepLib::EncodeRegularity(sh);
535 Standard_Real Tol = Draw::Atof(a[2]);
537 BRepLib::EncodeRegularity(sh, Tol);
542 static Standard_Integer getedgeregul
543 (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
547 cout<<"Invalid number of arguments. Should be: checkedgeregularity edge face1 [face2]"<<endl;
551 TopoDS_Shape anEdge = DBRep::Get(argv[1],TopAbs_EDGE);
552 TopoDS_Shape aFace1 = DBRep::Get(argv[2],TopAbs_FACE);
553 TopoDS_Shape aFace2 = (argc > 3 ? DBRep::Get(argv[3],TopAbs_FACE) : aFace1);
554 if( anEdge.IsNull() || aFace1.IsNull() || aFace2.IsNull())
556 cout<<"Invalid number of arguments. Should be: getedgeregularity edge face1 [face2]"<<endl;
560 GeomAbs_Shape aRegularity = BRep_Tool::Continuity(TopoDS::Edge(anEdge), TopoDS::Face(aFace1), TopoDS::Face(aFace2));
561 TCollection_AsciiString aStrReg("Regularity of edge : ");
565 case GeomAbs_C0 : aStrReg += "C0"; break;
566 case GeomAbs_G1 : aStrReg += "G1"; break;
567 case GeomAbs_C1 : aStrReg += "C1"; break;
568 case GeomAbs_G2 : aStrReg += "G2"; break;
569 case GeomAbs_C2 : aStrReg += "C2"; break;
570 case GeomAbs_C3 : aStrReg += "C3"; break;
571 case GeomAbs_CN : aStrReg += "CN"; break;
574 di<<aStrReg.ToCString()<<"\n";
578 //=======================================================================
579 //function : SurfaceCommands
581 //=======================================================================
583 void BRepTest::SurfaceCommands(Draw_Interpretor& theCommands)
585 static Standard_Boolean done = Standard_False;
587 done = Standard_True;
589 DBRep::BasicCommands(theCommands);
590 GeometryTest::SurfaceCommands(theCommands);
592 const char* g = "Surface topology commands";
594 theCommands.Add("mkface",
595 "mkface facename surfacename [ufirst ulast vfirst vlast] [wire [norient]]",
598 theCommands.Add("mkshell",
599 "mkshell shellname surfacename [ufirst ulast vfirst vlast] [segment 0/1]",
602 theCommands.Add("quilt",
603 "quilt compoundname shape1 edgeshape2 edgeshape1... shape2 edgeshape3 edgeshape1or2 ... shape3 ...",
606 theCommands.Add("mksurface",
607 "mksurface surfacename facename",
608 __FILE__,mksurface,g);
610 theCommands.Add("mkplane",
611 "mkplane facename wirename [OnlyPlane 0/1]",
614 theCommands.Add("pcurve",
615 "pcurve [name edgename] facename",
618 theCommands.Add("sewing",
619 "sewing result [tolerance] shape1 shape2 ... [min tolerance] [max tolerance] [switches]",
622 theCommands.Add("continuity",
623 "continuity [tolerance] shape1 shape2 ...",
624 __FILE__,continuity, g);
626 theCommands.Add("encoderegularity",
627 "encoderegularity shape [tolerance (in degree)]",
628 __FILE__,encoderegularity, g);
630 theCommands.Add ("fastsewing", "fastsewing result [-tol <value>] <list_of_faces>",
631 __FILE__, fastsewing, g);
632 theCommands.Add ("getedgeregularity", "getedgeregularity edge face1 [face2]", __FILE__,getedgeregul,g);