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 <Precision.hxx>
37 //#define strcasecmp strcmp Already defined
44 //-----------------------------------------------------------------------
45 // suppressarg : suppress a[d],modifie na--
46 //-----------------------------------------------------------------------
47 static void suppressarg(Standard_Integer& na,const char** a,const Standard_Integer d)
49 for(Standard_Integer i=d;i<na;i++) {
57 //=======================================================================
59 //=======================================================================
61 static Standard_Integer mkface(Draw_Interpretor& , Standard_Integer n, const char** a)
65 Handle(Geom_Surface) S = DrawTrSurf::GetSurface(a[2]);
67 cout << a[2] << " is not a surface" << endl;
71 Standard_Boolean mkface = a[0][2] == 'f';
74 Standard_Boolean Segment = Standard_False;
75 if ( !mkface && (n == 4 || n == 8)) {
76 Segment = !strcmp(a[n-1],"1");
82 res = BRepBuilderAPI_MakeFace(S, Precision::Confusion());
84 res = BRepBuilderAPI_MakeShell(S,Segment);
87 if (!mkface) return 1;
88 Standard_Boolean orient = (n == 4);
89 TopoDS_Shape W = DBRep::Get(a[3],TopAbs_WIRE);
90 if (W.IsNull()) return 1;
91 res = BRepBuilderAPI_MakeFace(S,TopoDS::Wire(W),orient);
95 res = BRepBuilderAPI_MakeFace(S,atof(a[3]),atof(a[4]),atof(a[5]),atof(a[6]),Precision::Confusion());
97 res = BRepBuilderAPI_MakeShell(S,atof(a[3]),atof(a[4]),atof(a[5]),atof(a[6]),
101 DBRep::Set(a[1],res);
105 //=======================================================================
107 //=======================================================================
109 static Standard_Integer quilt(Draw_Interpretor& , Standard_Integer n, const char** a)
114 Standard_Integer i = 2;
116 TopoDS_Shape S = DBRep::Get(a[i]);
118 if (S.ShapeType() == TopAbs_EDGE) {
120 TopoDS_Shape E = DBRep::Get(a[i+1]);
122 if (E.ShapeType() == TopAbs_EDGE) {
124 Q.Bind(TopoDS::Edge(S),TopoDS::Edge(E));
129 if (S.ShapeType() == TopAbs_VERTEX) {
131 TopoDS_Shape E = DBRep::Get(a[i+1]);
133 if (E.ShapeType() == TopAbs_VERTEX) {
135 Q.Bind(TopoDS::Vertex(S),TopoDS::Vertex(E));
147 DBRep::Set(a[1],Q.Shells());
152 //=======================================================================
154 //=======================================================================
156 static Standard_Integer mksurface(Draw_Interpretor& , Standard_Integer n, const char** a)
160 TopoDS_Shape S = DBRep::Get(a[2],TopAbs_FACE);
161 if (S.IsNull()) return 1;
163 Handle(Geom_Surface) C = BRep_Tool::Surface(TopoDS::Face(S),L);
166 DrawTrSurf::Set(a[1],C->Transformed(L.Transformation()));
170 //=======================================================================
172 //=======================================================================
174 static Standard_Integer mkplane(Draw_Interpretor& , Standard_Integer n, const char** a)
178 TopoDS_Shape S = DBRep::Get(a[2],TopAbs_WIRE);
179 if (S.IsNull()) return 1;
181 Standard_Boolean OnlyPlane = Standard_False;
183 OnlyPlane = !strcmp(a[3],"1");
186 TopoDS_Face F = BRepBuilderAPI_MakeFace(TopoDS::Wire(S), OnlyPlane);
192 //=======================================================================
194 //=======================================================================
195 Standard_IMPORT Draw_Color DrawTrSurf_CurveColor(const Draw_Color col);
196 Standard_IMPORT void DBRep_WriteColorOrientation ();
197 Standard_IMPORT Draw_Color DBRep_ColorOrientation (const TopAbs_Orientation Or);
199 static Standard_Integer pcurve(Draw_Interpretor& , Standard_Integer n, const char** a)
201 Standard_Boolean mute = Standard_False;
202 for(Standard_Integer ia=1;ia<n;ia++) {
203 if (!strcasecmp(a[ia],"-mute")) {
205 mute = Standard_True;
211 TopoDS_Shape S = DBRep::Get(a[1],TopAbs_FACE);
212 if (S.IsNull()) return 1;
214 if (!mute) DBRep_WriteColorOrientation();
215 Draw_Color col, savecol = DrawTrSurf_CurveColor(Draw_rouge);
217 char* name = new char[100];
219 S.Orientation(TopAbs_FORWARD);
220 TopExp_Explorer ex(S,TopAbs_EDGE);
221 for (Standard_Integer i=1; ex.More(); ex.Next(), i++) {
222 const Handle(Geom2d_Curve) c = BRep_Tool::CurveOnSurface
223 (TopoDS::Edge(ex.Current()),TopoDS::Face(S),f,l);
225 cout << "Error: Edge " << i << " does not have pcurve" << endl;
228 col = DBRep_ColorOrientation(ex.Current().Orientation());
229 DrawTrSurf_CurveColor(col);
231 sprintf(name,"%s_%d",a[1],i);
232 DrawTrSurf::Set(name,new Geom2d_TrimmedCurve(c,f,l));
234 DrawTrSurf_CurveColor(savecol);
238 TopoDS_Shape SE = DBRep::Get(a[2],TopAbs_EDGE);
239 if (SE.IsNull()) return 1;
240 TopoDS_Shape SF = DBRep::Get(a[3],TopAbs_FACE);
241 if (SF.IsNull()) return 1;
243 Draw_Color col, savecol = DrawTrSurf_CurveColor(Draw_rouge);
245 const Handle(Geom2d_Curve) c = BRep_Tool::CurveOnSurface
246 (TopoDS::Edge(SE),TopoDS::Face(SF),f,l);
248 col = DBRep_ColorOrientation(SE.Orientation());
249 DrawTrSurf_CurveColor(col);
250 DrawTrSurf::Set(a[1],new Geom2d_TrimmedCurve(c,f,l));
251 DrawTrSurf_CurveColor(savecol);
260 //=======================================================================
262 //=======================================================================
264 static Standard_Integer sewing (Draw_Interpretor& ,
265 Standard_Integer n, const char** a)
267 if (n < 3) return (1);
269 BRepBuilderAPI_Sewing aSewing;
270 Standard_Integer ntmp = n;
272 TopoDS_Shape sh = DBRep::Get(a[2]);
273 Standard_Integer i=2;
274 Standard_Real tol = 1.0e-06;
276 if (n < 4) return (1);
278 //Standard_Real tol = atof(a[2]);
279 //aSewing.Init(tol, Standard_True,Standard_True,Standard_True,Standard_False);
283 Standard_Boolean NonManifoldMode = Standard_False;
284 sh = DBRep::Get(a[n-1]);
286 // read non manifold mode
287 Standard_Integer nmm = atoi(a[n-1]);
289 NonManifoldMode = Standard_True;
293 aSewing.Init(tol, Standard_True,Standard_True,Standard_True,NonManifoldMode);
296 sh = DBRep::Get(a[i]);
304 const TopoDS_Shape& sh2 = aSewing.SewedShape();
306 DBRep::Set(a[1], sh2);
311 //=======================================================================
313 //=======================================================================
315 static Standard_Integer continuity (Draw_Interpretor& ,
316 Standard_Integer n, const char** a)
318 if (n < 2) return (1);
320 BRepOffsetAPI_FindContigousEdges aFind;
322 TopoDS_Shape sh = DBRep::Get(a[1]);
323 Standard_Integer i=1;
325 if (n < 3) return (1);
326 Standard_Real tol = atof(a[1]);
327 aFind.Init(tol, Standard_False);
332 sh = DBRep::Get(a[i]);
340 for (i=1; i<=aFind.NbContigousEdges(); i++) {
342 const TopoDS_Edge& edge =
344 aFind.ContigousEdge(i);
345 const TopTools_ListOfShape& list = aFind.ContigousEdgeCouple(i);
346 const TopoDS_Edge& sec1 = TopoDS::Edge(list.First());
347 const TopoDS_Edge& sec2 = TopoDS::Edge(list.Last());
349 const TopoDS_Edge& bound1 =
351 aFind.SectionToBoundary(sec1);
353 const TopoDS_Edge& bound2 =
355 aFind.SectionToBoundary(sec2);
361 //=======================================================================
363 //=======================================================================
364 static Standard_Integer encoderegularity (Draw_Interpretor& ,
365 Standard_Integer n, const char** a)
369 TopoDS_Shape sh = DBRep::Get(a[1]);
370 if (sh.IsNull()) return 1;
372 BRepLib::EncodeRegularity(sh);
374 Standard_Real Tol = atof(a[2]);
376 BRepLib::EncodeRegularity(sh, Tol);
382 //=======================================================================
383 //function : SurfaceCommands
385 //=======================================================================
387 void BRepTest::SurfaceCommands(Draw_Interpretor& theCommands)
389 static Standard_Boolean done = Standard_False;
391 done = Standard_True;
393 DBRep::BasicCommands(theCommands);
394 GeometryTest::SurfaceCommands(theCommands);
396 const char* g = "Surface topology commands";
398 theCommands.Add("mkface",
399 "mkface facename surfacename [ufirst ulast vfirst vlast] [wire [norient]]",
402 theCommands.Add("mkshell",
403 "mkshell shellname surfacename [ufirst ulast vfirst vlast] [segment 0/1]",
406 theCommands.Add("quilt",
407 "quilt compoundname shape1 edgeshape2 edgeshape1... shape2 edgeshape3 edgeshape1or2 ... shape3 ...",
410 theCommands.Add("mksurface",
411 "mksurface surfacename facename",
412 __FILE__,mksurface,g);
414 theCommands.Add("mkplane",
415 "mkplane facename wirename [OnlyPlane 0/1]",
418 theCommands.Add("pcurve",
419 "pcurve [name edgename] facename",
422 theCommands.Add("sewing",
423 "sewing result [tolerance] shape1 shape2 ...",
426 theCommands.Add("continuity",
427 "continuity [tolerance] shape1 shape2 ...",
428 __FILE__,continuity, g);
430 theCommands.Add("encoderegularity",
431 "encoderegularity shape [tolerance (in degree)]",
432 __FILE__,encoderegularity, g);