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.
21 #include <BRepTest.hxx>
22 #include <GeometryTest.hxx>
24 #include <DrawTrSurf.hxx>
26 #include <Draw_Interpretor.hxx>
27 #include <Draw_Appli.hxx>
29 #include <BRep_Builder.hxx>
30 #include <BRep_Tool.hxx>
31 #include <BRepLib.hxx>
32 #include <BRepTools_Quilt.hxx>
33 #include <BRepAdaptor_Curve.hxx>
34 #include <BRepBuilderAPI_MakeFace.hxx>
35 #include <BRepBuilderAPI_MakeShell.hxx>
36 #include <BRepBuilderAPI.hxx>
37 #include <BRepBuilderAPI_Sewing.hxx>
38 #include <BRepOffsetAPI_FindContigousEdges.hxx>
39 #include <TopExp_Explorer.hxx>
41 #include <TopoDS_Face.hxx>
42 #include <Geom_Surface.hxx>
43 #include <Geom2d_TrimmedCurve.hxx>
44 #include <TopTools_ListOfShape.hxx>
45 #include <TopTools_SequenceOfShape.hxx>
46 #include <Precision.hxx>
47 #include <Draw_ProgressIndicator.hxx>
50 //#define strcasecmp strcmp Already defined
57 //-----------------------------------------------------------------------
58 // suppressarg : suppress a[d],modifie na--
59 //-----------------------------------------------------------------------
60 static void suppressarg(Standard_Integer& na,const char** a,const Standard_Integer d)
62 for(Standard_Integer i=d;i<na;i++) {
70 //=======================================================================
72 //=======================================================================
74 static Standard_Integer mkface(Draw_Interpretor& , Standard_Integer n, const char** a)
78 Handle(Geom_Surface) S = DrawTrSurf::GetSurface(a[2]);
80 cout << a[2] << " is not a surface" << endl;
84 Standard_Boolean mkface = a[0][2] == 'f';
87 Standard_Boolean Segment = Standard_False;
88 if ( !mkface && (n == 4 || n == 8)) {
89 Segment = !strcmp(a[n-1],"1");
95 res = BRepBuilderAPI_MakeFace(S, Precision::Confusion());
97 res = BRepBuilderAPI_MakeShell(S,Segment);
100 if (!mkface) return 1;
101 Standard_Boolean orient = (n == 4);
102 TopoDS_Shape W = DBRep::Get(a[3],TopAbs_WIRE);
103 if (W.IsNull()) return 1;
104 res = BRepBuilderAPI_MakeFace(S,TopoDS::Wire(W),orient);
108 res = BRepBuilderAPI_MakeFace(S,Draw::Atof(a[3]),Draw::Atof(a[4]),Draw::Atof(a[5]),Draw::Atof(a[6]),Precision::Confusion());
110 res = BRepBuilderAPI_MakeShell(S,Draw::Atof(a[3]),Draw::Atof(a[4]),Draw::Atof(a[5]),Draw::Atof(a[6]),
114 DBRep::Set(a[1],res);
118 //=======================================================================
120 //=======================================================================
122 static Standard_Integer quilt(Draw_Interpretor& , Standard_Integer n, const char** a)
127 Standard_Integer i = 2;
129 TopoDS_Shape S = DBRep::Get(a[i]);
131 if (S.ShapeType() == TopAbs_EDGE) {
133 TopoDS_Shape E = DBRep::Get(a[i+1]);
135 if (E.ShapeType() == TopAbs_EDGE) {
137 Q.Bind(TopoDS::Edge(S),TopoDS::Edge(E));
142 if (S.ShapeType() == TopAbs_VERTEX) {
144 TopoDS_Shape E = DBRep::Get(a[i+1]);
146 if (E.ShapeType() == TopAbs_VERTEX) {
148 Q.Bind(TopoDS::Vertex(S),TopoDS::Vertex(E));
160 DBRep::Set(a[1],Q.Shells());
165 //=======================================================================
167 //=======================================================================
169 static Standard_Integer mksurface(Draw_Interpretor& , Standard_Integer n, const char** a)
173 TopoDS_Shape S = DBRep::Get(a[2],TopAbs_FACE);
174 if (S.IsNull()) return 1;
176 Handle(Geom_Surface) C = BRep_Tool::Surface(TopoDS::Face(S),L);
179 DrawTrSurf::Set(a[1],C->Transformed(L.Transformation()));
183 //=======================================================================
185 //=======================================================================
187 static Standard_Integer mkplane(Draw_Interpretor& , Standard_Integer n, const char** a)
191 TopoDS_Shape S = DBRep::Get(a[2],TopAbs_WIRE);
192 if (S.IsNull()) return 1;
194 Standard_Boolean OnlyPlane = Standard_False;
196 OnlyPlane = !strcmp(a[3],"1");
199 TopoDS_Face F = BRepBuilderAPI_MakeFace(TopoDS::Wire(S), OnlyPlane);
205 //=======================================================================
207 //=======================================================================
208 Standard_IMPORT Draw_Color DrawTrSurf_CurveColor(const Draw_Color col);
209 Standard_IMPORT void DBRep_WriteColorOrientation ();
210 Standard_IMPORT Draw_Color DBRep_ColorOrientation (const TopAbs_Orientation Or);
212 static Standard_Integer pcurve(Draw_Interpretor& , Standard_Integer n, const char** a)
214 Standard_Boolean mute = Standard_False;
215 for(Standard_Integer ia=1;ia<n;ia++) {
216 if (!strcasecmp(a[ia],"-mute")) {
218 mute = Standard_True;
224 TopoDS_Shape S = DBRep::Get(a[1],TopAbs_FACE);
225 if (S.IsNull()) return 1;
227 if (!mute) DBRep_WriteColorOrientation();
228 Draw_Color col, savecol = DrawTrSurf_CurveColor(Draw_rouge);
230 char* name = new char[100];
232 S.Orientation(TopAbs_FORWARD);
233 TopExp_Explorer ex(S,TopAbs_EDGE);
234 for (Standard_Integer i=1; ex.More(); ex.Next(), i++) {
235 const Handle(Geom2d_Curve) c = BRep_Tool::CurveOnSurface
236 (TopoDS::Edge(ex.Current()),TopoDS::Face(S),f,l);
238 cout << "Error: Edge " << i << " does not have pcurve" << endl;
241 col = DBRep_ColorOrientation(ex.Current().Orientation());
242 DrawTrSurf_CurveColor(col);
244 Sprintf(name,"%s_%d",a[1],i);
245 DrawTrSurf::Set(name,new Geom2d_TrimmedCurve(c,f,l));
247 DrawTrSurf_CurveColor(savecol);
251 TopoDS_Shape SE = DBRep::Get(a[2],TopAbs_EDGE);
252 if (SE.IsNull()) return 1;
253 TopoDS_Shape SF = DBRep::Get(a[3],TopAbs_FACE);
254 if (SF.IsNull()) return 1;
256 Draw_Color col, savecol = DrawTrSurf_CurveColor(Draw_rouge);
258 const Handle(Geom2d_Curve) c = BRep_Tool::CurveOnSurface
259 (TopoDS::Edge(SE),TopoDS::Face(SF),f,l);
261 col = DBRep_ColorOrientation(SE.Orientation());
262 DrawTrSurf_CurveColor(col);
263 DrawTrSurf::Set(a[1],new Geom2d_TrimmedCurve(c,f,l));
264 DrawTrSurf_CurveColor(savecol);
273 //=======================================================================
275 //=======================================================================
277 static Standard_Integer sewing (Draw_Interpretor& theDi,
278 Standard_Integer theArgc, const char** theArgv)
280 BRepBuilderAPI_Sewing aSewing;
281 Standard_Integer aPar = 1;
282 TopTools_SequenceOfShape aSeq;
284 Standard_Real aTol = 1.0e-06;
285 Standard_Boolean aSewingMode = Standard_True;
286 Standard_Boolean anAnalysisMode = Standard_True;
287 Standard_Boolean aCuttingMode = Standard_True;
288 Standard_Boolean aNonManifoldMode = Standard_False;
289 Standard_Boolean aSameParameterMode = Standard_True;
290 Standard_Boolean aFloatingEdgesMode = Standard_False;
291 Standard_Boolean aFaceMode = Standard_True;
292 Standard_Boolean aSetMinTol = Standard_False;
293 Standard_Real aMinTol = 0.;
294 Standard_Real aMaxTol = Precision::Infinite();
296 for (Standard_Integer i = 2; i < theArgc; i++)
298 if (theArgv[i][0] == '-' || theArgv[i][0] == '+')
300 Standard_Boolean aVal = (theArgv[i][0] == '+' ? Standard_True : Standard_False);
301 switch (tolower(theArgv[i][1]))
305 if (tolower(theArgv[i][2]) == 'i' && i+1 < theArgc)
307 if (Draw::Atof (theArgv[i+1]))
309 aMinTol = Draw::Atof (theArgv[++i]);
310 aSetMinTol = Standard_True;
314 theDi << "Error! min tolerance can't possess the null value" << "\n";
318 if (tolower(theArgv[i][2]) == 'a' && i+1 < theArgc)
320 if (Draw::Atof (theArgv[i+1]))
321 aMaxTol = Draw::Atof (theArgv[++i]);
324 theDi << "Error! max tolerance can't possess the null value" << "\n";
330 case 's': aSewingMode = aVal; break;
331 case 'a': anAnalysisMode = aVal; break;
332 case 'c': aCuttingMode = aVal; break;
333 case 'n': aNonManifoldMode = aVal; break;
334 case 'p': aSameParameterMode = aVal; break;
335 case 'e': aFloatingEdgesMode = aVal; break;
336 case 'f': aFaceMode = aVal; break;
341 TopoDS_Shape aShape = DBRep::Get (theArgv[i]);
342 if (!aShape.IsNull())
344 aSeq.Append (aShape);
349 if (Draw::Atof (theArgv[i]))
350 aTol = Draw::Atof (theArgv[i]);
357 theDi << "Use: " << theArgv[0] << " result [tolerance] shape1 shape2 ... [min tolerance] [max tolerance] [switches]" << "\n";
358 theDi << "To set user's value of min/max tolerances the following syntax is used: +<parameter> <value>" << "\n";
359 theDi << "- parameters are identified by letters:" << "\n";
360 theDi << " mint - min tolerance" << "\n";
361 theDi << " maxt - max tolerance" << "\n";
362 theDi << "Switches allow to tune other parameters of Sewing" << "\n";
363 theDi << "The following syntax is used: <symbol><parameter>" << "\n";
364 theDi << "- symbol may be - to set parameter off, + to set on" << "\n";
365 theDi << "- parameters are identified by letters:" << "\n";
366 theDi << " s - mode for creating sewed shape" << "\n";
367 theDi << " a - mode for analysis of input shapes" << "\n";
368 theDi << " c - mode for cutting of free edges" << "\n";
369 theDi << " n - mode for non manifold processing" << "\n";
370 theDi << " p - mode for same parameter processing for edges" << "\n";
371 theDi << " e - mode for sewing floating edges" << "\n";
372 theDi << " f - mode for sewing faces" << "\n";
378 if (aTol < Precision::Confusion())
379 aTol = Precision::Confusion();
380 if (aMinTol < Precision::Confusion())
381 aMinTol = Precision::Confusion();
384 theDi << "Error! min tolerance can't exceed working tolerance" << "\n";
389 theDi << "Error! max tolerance can't be less than working tolerance" << "\n";
393 aSewing.Init (aTol, aSewingMode, anAnalysisMode, aCuttingMode, aNonManifoldMode);
394 aSewing.SetSameParameterMode (aSameParameterMode);
395 aSewing.SetFloatingEdgesMode (aFloatingEdgesMode);
396 aSewing.SetFaceMode (aFaceMode);
397 aSewing.SetMinTolerance (aMinTol);
398 aSewing.SetMaxTolerance (aMaxTol);
400 for (Standard_Integer i = 1; i <= aSeq.Length(); i++)
401 aSewing.Add(aSeq.Value(i));
403 Handle(Draw_ProgressIndicator) aProgress = new Draw_ProgressIndicator (theDi, 1);
404 aSewing.Perform (aProgress);
407 const TopoDS_Shape& aRes = aSewing.SewedShape();
409 DBRep::Set(theArgv[1], aRes);
413 //=======================================================================
415 //=======================================================================
417 static Standard_Integer continuity (Draw_Interpretor& ,
418 Standard_Integer n, const char** a)
420 if (n < 2) return (1);
422 BRepOffsetAPI_FindContigousEdges aFind;
424 TopoDS_Shape sh = DBRep::Get(a[1]);
425 Standard_Integer i=1;
427 if (n < 3) return (1);
428 Standard_Real tol = Draw::Atof(a[1]);
429 aFind.Init(tol, Standard_False);
434 sh = DBRep::Get(a[i]);
445 //=======================================================================
447 //=======================================================================
448 static Standard_Integer encoderegularity (Draw_Interpretor& ,
449 Standard_Integer n, const char** a)
453 TopoDS_Shape sh = DBRep::Get(a[1]);
454 if (sh.IsNull()) return 1;
456 BRepLib::EncodeRegularity(sh);
458 Standard_Real Tol = Draw::Atof(a[2]);
460 BRepLib::EncodeRegularity(sh, Tol);
466 //=======================================================================
467 //function : SurfaceCommands
469 //=======================================================================
471 void BRepTest::SurfaceCommands(Draw_Interpretor& theCommands)
473 static Standard_Boolean done = Standard_False;
475 done = Standard_True;
477 DBRep::BasicCommands(theCommands);
478 GeometryTest::SurfaceCommands(theCommands);
480 const char* g = "Surface topology commands";
482 theCommands.Add("mkface",
483 "mkface facename surfacename [ufirst ulast vfirst vlast] [wire [norient]]",
486 theCommands.Add("mkshell",
487 "mkshell shellname surfacename [ufirst ulast vfirst vlast] [segment 0/1]",
490 theCommands.Add("quilt",
491 "quilt compoundname shape1 edgeshape2 edgeshape1... shape2 edgeshape3 edgeshape1or2 ... shape3 ...",
494 theCommands.Add("mksurface",
495 "mksurface surfacename facename",
496 __FILE__,mksurface,g);
498 theCommands.Add("mkplane",
499 "mkplane facename wirename [OnlyPlane 0/1]",
502 theCommands.Add("pcurve",
503 "pcurve [name edgename] facename",
506 theCommands.Add("sewing",
507 "sewing result [tolerance] shape1 shape2 ... [min tolerance] [max tolerance] [switches]",
510 theCommands.Add("continuity",
511 "continuity [tolerance] shape1 shape2 ...",
512 __FILE__,continuity, g);
514 theCommands.Add("encoderegularity",
515 "encoderegularity shape [tolerance (in degree)]",
516 __FILE__,encoderegularity, g);