2 // Created: Thu Jul 22 16:39:43 1993
3 // Author: Remi LEQUETTE
10 #include <BRepTest.hxx>
11 #include <GeometryTest.hxx>
13 #include <DrawTrSurf.hxx>
15 #include <Draw_Interpretor.hxx>
16 #include <Draw_Appli.hxx>
18 #include <BRep_Builder.hxx>
19 #include <BRep_Tool.hxx>
20 #include <BRepLib.hxx>
21 #include <BRepTools_Quilt.hxx>
22 #include <BRepAdaptor_Curve.hxx>
23 #include <BRepBuilderAPI_MakeFace.hxx>
24 #include <BRepBuilderAPI_MakeShell.hxx>
25 #include <BRepBuilderAPI.hxx>
26 #include <BRepBuilderAPI_Sewing.hxx>
27 #include <BRepOffsetAPI_FindContigousEdges.hxx>
28 #include <TopExp_Explorer.hxx>
30 #include <TopoDS_Face.hxx>
31 #include <Geom_Surface.hxx>
32 #include <Geom2d_TrimmedCurve.hxx>
33 #include <TopTools_ListOfShape.hxx>
34 #include <TopTools_SequenceOfShape.hxx>
35 #include <Precision.hxx>
36 #include <Draw_ProgressIndicator.hxx>
39 //#define strcasecmp strcmp Already defined
46 //-----------------------------------------------------------------------
47 // suppressarg : suppress a[d],modifie na--
48 //-----------------------------------------------------------------------
49 static void suppressarg(Standard_Integer& na,const char** a,const Standard_Integer d)
51 for(Standard_Integer i=d;i<na;i++) {
59 //=======================================================================
61 //=======================================================================
63 static Standard_Integer mkface(Draw_Interpretor& , Standard_Integer n, const char** a)
67 Handle(Geom_Surface) S = DrawTrSurf::GetSurface(a[2]);
69 cout << a[2] << " is not a surface" << endl;
73 Standard_Boolean mkface = a[0][2] == 'f';
76 Standard_Boolean Segment = Standard_False;
77 if ( !mkface && (n == 4 || n == 8)) {
78 Segment = !strcmp(a[n-1],"1");
84 res = BRepBuilderAPI_MakeFace(S, Precision::Confusion());
86 res = BRepBuilderAPI_MakeShell(S,Segment);
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);
97 res = BRepBuilderAPI_MakeFace(S,atof(a[3]),atof(a[4]),atof(a[5]),atof(a[6]),Precision::Confusion());
99 res = BRepBuilderAPI_MakeShell(S,atof(a[3]),atof(a[4]),atof(a[5]),atof(a[6]),
103 DBRep::Set(a[1],res);
107 //=======================================================================
109 //=======================================================================
111 static Standard_Integer quilt(Draw_Interpretor& , Standard_Integer n, const char** a)
116 Standard_Integer i = 2;
118 TopoDS_Shape S = DBRep::Get(a[i]);
120 if (S.ShapeType() == TopAbs_EDGE) {
122 TopoDS_Shape E = DBRep::Get(a[i+1]);
124 if (E.ShapeType() == TopAbs_EDGE) {
126 Q.Bind(TopoDS::Edge(S),TopoDS::Edge(E));
131 if (S.ShapeType() == TopAbs_VERTEX) {
133 TopoDS_Shape E = DBRep::Get(a[i+1]);
135 if (E.ShapeType() == TopAbs_VERTEX) {
137 Q.Bind(TopoDS::Vertex(S),TopoDS::Vertex(E));
149 DBRep::Set(a[1],Q.Shells());
154 //=======================================================================
156 //=======================================================================
158 static Standard_Integer mksurface(Draw_Interpretor& , Standard_Integer n, const char** a)
162 TopoDS_Shape S = DBRep::Get(a[2],TopAbs_FACE);
163 if (S.IsNull()) return 1;
165 Handle(Geom_Surface) C = BRep_Tool::Surface(TopoDS::Face(S),L);
168 DrawTrSurf::Set(a[1],C->Transformed(L.Transformation()));
172 //=======================================================================
174 //=======================================================================
176 static Standard_Integer mkplane(Draw_Interpretor& , Standard_Integer n, const char** a)
180 TopoDS_Shape S = DBRep::Get(a[2],TopAbs_WIRE);
181 if (S.IsNull()) return 1;
183 Standard_Boolean OnlyPlane = Standard_False;
185 OnlyPlane = !strcmp(a[3],"1");
188 TopoDS_Face F = BRepBuilderAPI_MakeFace(TopoDS::Wire(S), OnlyPlane);
194 //=======================================================================
196 //=======================================================================
197 Standard_IMPORT Draw_Color DrawTrSurf_CurveColor(const Draw_Color col);
198 Standard_IMPORT void DBRep_WriteColorOrientation ();
199 Standard_IMPORT Draw_Color DBRep_ColorOrientation (const TopAbs_Orientation Or);
201 static Standard_Integer pcurve(Draw_Interpretor& , Standard_Integer n, const char** a)
203 Standard_Boolean mute = Standard_False;
204 for(Standard_Integer ia=1;ia<n;ia++) {
205 if (!strcasecmp(a[ia],"-mute")) {
207 mute = Standard_True;
213 TopoDS_Shape S = DBRep::Get(a[1],TopAbs_FACE);
214 if (S.IsNull()) return 1;
216 if (!mute) DBRep_WriteColorOrientation();
217 Draw_Color col, savecol = DrawTrSurf_CurveColor(Draw_rouge);
219 char* name = new char[100];
221 S.Orientation(TopAbs_FORWARD);
222 TopExp_Explorer ex(S,TopAbs_EDGE);
223 for (Standard_Integer i=1; ex.More(); ex.Next(), i++) {
224 const Handle(Geom2d_Curve) c = BRep_Tool::CurveOnSurface
225 (TopoDS::Edge(ex.Current()),TopoDS::Face(S),f,l);
227 cout << "Error: Edge " << i << " does not have pcurve" << endl;
230 col = DBRep_ColorOrientation(ex.Current().Orientation());
231 DrawTrSurf_CurveColor(col);
233 sprintf(name,"%s_%d",a[1],i);
234 DrawTrSurf::Set(name,new Geom2d_TrimmedCurve(c,f,l));
236 DrawTrSurf_CurveColor(savecol);
240 TopoDS_Shape SE = DBRep::Get(a[2],TopAbs_EDGE);
241 if (SE.IsNull()) return 1;
242 TopoDS_Shape SF = DBRep::Get(a[3],TopAbs_FACE);
243 if (SF.IsNull()) return 1;
245 Draw_Color col, savecol = DrawTrSurf_CurveColor(Draw_rouge);
247 const Handle(Geom2d_Curve) c = BRep_Tool::CurveOnSurface
248 (TopoDS::Edge(SE),TopoDS::Face(SF),f,l);
250 col = DBRep_ColorOrientation(SE.Orientation());
251 DrawTrSurf_CurveColor(col);
252 DrawTrSurf::Set(a[1],new Geom2d_TrimmedCurve(c,f,l));
253 DrawTrSurf_CurveColor(savecol);
262 //=======================================================================
264 //=======================================================================
266 static Standard_Integer sewing (Draw_Interpretor& theDi,
267 Standard_Integer theArgc, const char** theArgv)
269 BRepBuilderAPI_Sewing aSewing;
270 Standard_Integer aPar = 1;
271 TopTools_SequenceOfShape aSeq;
273 Standard_Real aTol = 1.0e-06;
274 Standard_Boolean aSewingMode = Standard_True;
275 Standard_Boolean anAnalysisMode = Standard_True;
276 Standard_Boolean aCuttingMode = Standard_True;
277 Standard_Boolean aNonManifoldMode = Standard_False;
278 Standard_Boolean aSameParameterMode = Standard_True;
279 Standard_Boolean aFloatingEdgesMode = Standard_False;
280 Standard_Boolean aFaceMode = Standard_True;
281 Standard_Real aMinTol = aTol*1e-4;
282 Standard_Real aMaxTol = Precision::Infinite();
284 for (Standard_Integer i = 2; i < theArgc; i++)
286 if (theArgv[i][0] == '-' || theArgv[i][0] == '+')
288 Standard_Boolean aVal = (theArgv[i][0] == '+' ? Standard_True : Standard_False);
289 switch (tolower(theArgv[i][1]))
293 if (tolower(theArgv[i][2]) == 'i' && i+1 < theArgc)
295 if (atof (theArgv[i+1]))
296 aMinTol = atof (theArgv[i+1]);
299 theDi << "Error! min tolerance can't possess the null value" << "\n";
303 if (tolower(theArgv[i][2]) == 'a' && i+1 < theArgc)
305 if (atof (theArgv[i+1]))
306 aMaxTol = atof (theArgv[i+1]);
309 theDi << "Error! max tolerance can't possess the null value" << "\n";
315 case 's': aSewingMode = aVal; break;
316 case 'a': anAnalysisMode = aVal; break;
317 case 'c': aCuttingMode = aVal; break;
318 case 'n': aNonManifoldMode = aVal; break;
319 case 'p': aSameParameterMode = aVal; break;
320 case 'e': aFloatingEdgesMode = aVal; break;
321 case 'f': aFaceMode = aVal; break;
326 if (atof (theArgv[i]))
327 aTol = atof (theArgv[i]);
330 TopoDS_Shape aShape = DBRep::Get (theArgv[i]);
333 aSeq.Append (aShape);
341 theDi << "Use: " << theArgv[0] << " result [tolerance] shape1 shape2 ... [min tolerance] [max tolerance] [switches]" << "\n";
342 theDi << "To set user's value of min/max tolerances the following syntax is used: +<parameter> <value>" << "\n";
343 theDi << "- parameters are identified by letters:" << "\n";
344 theDi << " mint - min tolerance" << "\n";
345 theDi << " maxt - max tolerance" << "\n";
346 theDi << "Switches allow to tune other parameters of Sewing" << "\n";
347 theDi << "The following syntax is used: <symbol><parameter>" << "\n";
348 theDi << "- symbol may be - to set parameter off, + to set on" << "\n";
349 theDi << "- parameters are identified by letters:" << "\n";
350 theDi << " s - mode for creating sewed shape" << "\n";
351 theDi << " a - mode for analysis of input shapes" << "\n";
352 theDi << " c - mode for cutting of free edges" << "\n";
353 theDi << " n - mode for non manifold processing" << "\n";
354 theDi << " p - mode for same parameter processing for edges" << "\n";
355 theDi << " e - mode for sewing floating edges" << "\n";
356 theDi << " f - mode for sewing faces" << "\n";
360 if (aTol < Precision::Confusion())
361 aTol = Precision::Confusion();
362 if (aMinTol < Precision::Confusion())
363 aMinTol = Precision::Confusion();
366 theDi << "Error! min tolerance can't exceed working tolerance" << "\n";
371 theDi << "Error! max tolerance can't be less than working tolerance" << "\n";
375 aSewing.Init (aTol, aSewingMode, anAnalysisMode, aCuttingMode, aNonManifoldMode);
376 aSewing.SetSameParameterMode (aSameParameterMode);
377 aSewing.SetFloatingEdgesMode (aFloatingEdgesMode);
378 aSewing.SetFaceMode (aFaceMode);
379 aSewing.SetMinTolerance (aMinTol);
380 aSewing.SetMaxTolerance (aMaxTol);
382 for (Standard_Integer i = 1; i <= aSeq.Length(); i++)
383 aSewing.Add(aSeq.Value(i));
385 Handle(Draw_ProgressIndicator) aProgress = new Draw_ProgressIndicator (theDi, 1);
386 aSewing.Perform (aProgress);
389 const TopoDS_Shape& aRes = aSewing.SewedShape();
391 DBRep::Set(theArgv[1], aRes);
395 //=======================================================================
397 //=======================================================================
399 static Standard_Integer continuity (Draw_Interpretor& ,
400 Standard_Integer n, const char** a)
402 if (n < 2) return (1);
404 BRepOffsetAPI_FindContigousEdges aFind;
406 TopoDS_Shape sh = DBRep::Get(a[1]);
407 Standard_Integer i=1;
409 if (n < 3) return (1);
410 Standard_Real tol = atof(a[1]);
411 aFind.Init(tol, Standard_False);
416 sh = DBRep::Get(a[i]);
424 for (i=1; i<=aFind.NbContigousEdges(); i++) {
426 const TopoDS_Edge& edge =
428 aFind.ContigousEdge(i);
429 const TopTools_ListOfShape& list = aFind.ContigousEdgeCouple(i);
430 const TopoDS_Edge& sec1 = TopoDS::Edge(list.First());
431 const TopoDS_Edge& sec2 = TopoDS::Edge(list.Last());
433 const TopoDS_Edge& bound1 =
435 aFind.SectionToBoundary(sec1);
437 const TopoDS_Edge& bound2 =
439 aFind.SectionToBoundary(sec2);
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 = 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);