1 // Created on: 1995-04-13
2 // Created by: Jean Yves LEBEY
3 // Copyright (c) 1995-1999 Matra Datavision
4 // Copyright (c) 1999-2012 OPEN CASCADE SAS
6 // The content of this file is subject to the Open CASCADE Technology Public
7 // License Version 6.5 (the "License"). You may not use the content of this file
8 // except in compliance with the License. Please obtain a copy of the License
9 // at http://www.opencascade.org and read it completely before using this file.
11 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
14 // The Original Code and all software distributed under the License is
15 // distributed on an "AS IS" basis, without warranty of any kind, and the
16 // Initial Developer hereby disclaims all such warranties, including without
17 // limitation, any warranties of merchantability, fitness for a particular
18 // purpose or non-infringement. Please see the License for the specific terms
19 // and conditions governing the rights and limitations under the License.
22 #include <BRepTest.hxx>
25 #include <Draw_Interpretor.hxx>
27 #include <DrawTrSurf.hxx>
32 #include <Standard_ErrorHandler.hxx>
33 #include <Precision.hxx>
34 #include <TCollection_AsciiString.hxx>
42 #include <TColgp_SequenceOfPnt.hxx>
44 #include <GeomAbs_JoinType.hxx>
45 #include <Geom_Line.hxx>
47 #include <IntCurvesFace_Intersector.hxx>
50 #include <TopAbs_Orientation.hxx>
53 #include <TopoDS_Shape.hxx>
54 #include <TopoDS_Compound.hxx>
55 #include <TopoDS_CompSolid.hxx>
56 #include <TopoDS_Solid.hxx>
57 #include <TopoDS_Shell.hxx>
58 #include <TopoDS_Face.hxx>
59 #include <TopoDS_Wire.hxx>
60 #include <TopoDS_Edge.hxx>
61 #include <TopoDS_Vertex.hxx>
62 #include <TopoDS_Iterator.hxx>
64 #include <BRep_Builder.hxx>
65 #include <BRep_Tool.hxx>
67 #include <TopExp_Explorer.hxx>
69 #include <TopTools_ListOfShape.hxx>
70 #include <TopTools_ListIteratorOfListOfShape.hxx>
71 #include <TopTools_MapOfShape.hxx>
73 #include <LocOpe_CSIntersector.hxx>
74 #include <LocOpe_SequenceOfLin.hxx>
75 #include <LocOpe_PntFace.hxx>
76 #include <BRepFeat_MakeDPrism.hxx>
78 #include <BRepTools.hxx>
79 #include <BRepIntCurveSurface_Inter.hxx>
80 #include <BRepOffset.hxx>
81 #include <BRepOffset_MakeOffset.hxx>
82 #include <BRepClass3d_SolidClassifier.hxx>
85 void SampleEdges (const TopoDS_Shape& theShape,
86 TColgp_SequenceOfPnt& theSeq);
88 TopoDS_Face NextFaceForPrism (const TopoDS_Shape& shape,
89 const TopoDS_Shape& basis,
92 void PrintState (Draw_Interpretor& aDI,
93 const TopAbs_State& aState);
95 static Standard_Integer emptyshape(Draw_Interpretor&, Standard_Integer, const char** );
96 static Standard_Integer subshape (Draw_Interpretor&, Standard_Integer, const char** );
97 static Standard_Integer brepintcs (Draw_Interpretor&, Standard_Integer, const char** );
98 static Standard_Integer MakeBoss (Draw_Interpretor&, Standard_Integer, const char** );
99 static Standard_Integer MakeShell (Draw_Interpretor&, Standard_Integer, const char** );
100 static Standard_Integer xbounds (Draw_Interpretor&, Standard_Integer, const char** );
101 static Standard_Integer xclassify (Draw_Interpretor&, Standard_Integer, const char** );
103 //=======================================================================
104 //function : OtherCommands
106 //=======================================================================
107 void BRepTest::OtherCommands(Draw_Interpretor& theCommands)
109 static Standard_Boolean done = Standard_False;
111 done = Standard_True;
113 const char* g = "TOPOLOGY other commands";
115 theCommands.Add("shape",
116 "shape name V/E/W/F/Sh/So/CS/C; make a empty shape",__FILE__,emptyshape,g);
118 theCommands.Add("subshape",
119 "subshape name V/E/W/F/Sh/So/CS/C index; get subsshape <index> of given type"
120 ,__FILE__,subshape,g);
122 theCommands.Add("BRepIntCS",
123 "Calcul d'intersection entre face et curve : BRepIntCS curve shape"
124 ,__FILE__,brepintcs,g);
126 theCommands.Add("makeboss", "create a boss on the shape myS", __FILE__, MakeBoss, g);
127 theCommands.Add("mksh", "create a shell on Shape", __FILE__, MakeShell, g);
128 theCommands.Add("xbounds", "xbounds face", __FILE__, xbounds, g);
129 theCommands.Add("xclassify", "use xclassify Solid [Tolerance=1.e-7]", __FILE__, xclassify, g);
133 //=======================================================================
134 //function : emptyshape
135 //purpose : shape : shape name V/E/W/F/SH/SO/CS/C
136 //=======================================================================
137 Standard_Integer emptyshape(Draw_Interpretor& , Standard_Integer n, const char** a)
139 if (n <= 1) return 1;
145 TCollection_AsciiString as(a[2]); as.LowerCase();
146 const char* a2 = as.ToCString();
148 if ( ! strcmp(a2,"c") ) {
149 TopoDS_Compound SS; B.MakeCompound(SS); S = SS;
151 else if ( ! strcmp(a2,"cs") ) {
152 TopoDS_CompSolid SS; B.MakeCompSolid(SS); S = SS;
154 else if ( ! strcmp(a2,"so") ) {
155 TopoDS_Solid SS; B.MakeSolid(SS); S = SS;
157 else if ( ! strcmp(a2,"sh") ) {
158 TopoDS_Shell SS; B.MakeShell(SS); S = SS;
160 else if ( ! strcmp(a2,"f") ) {
161 TopoDS_Face SS; B.MakeFace(SS); S = SS;
163 else if ( ! strcmp(a2,"w") ) {
164 TopoDS_Wire SS; B.MakeWire(SS); S = SS;
166 else if ( ! strcmp(a2,"e") ) {
167 TopoDS_Edge SS; B.MakeEdge(SS); S = SS;
169 else if ( ! strcmp(a2,"v") ) {
170 TopoDS_Vertex SS; B.MakeVertex(SS); S = SS;
177 const char *shapename = a[1];
178 DBRep::Set(shapename,S);
182 //=======================================================================
183 //function : subshape
185 //=======================================================================
186 Standard_Integer subshape(Draw_Interpretor& di, Standard_Integer n, const char** a)
188 if (n <= 2) return 1;
191 TopoDS_Shape S = DBRep::Get(a[1]);
192 if (S.IsNull()) return 0;
194 strcpy(newname,a[1]);
196 while (*p != '\0') p++;
199 Standard_Integer i = 0;
201 Standard_Integer isub = Draw::Atoi(a[2]);
202 TopoDS_Iterator itr(S);
207 DBRep::Set(newname,itr.Value());
208 di.AppendElement(newname);
216 TopAbs_ShapeEnum typ;
221 typ = TopAbs_COMPSOLID;
226 if ((a[2][1] == 'O')||(a[2][1] == 'o'))
228 else if ((a[2][1] == 'H')||(a[2][1] == 'h'))
258 Standard_Integer isub = Draw::Atoi(a[3]);
259 TopTools_MapOfShape M;
261 TopExp_Explorer ex(S,typ);
263 if (M.Add(ex.Current())) {
267 DBRep::Set(newname,ex.Current());
268 di.AppendElement(newname);
277 //=======================================================================
278 //function : brepintcs
280 //=======================================================================
281 Standard_Integer brepintcs(Draw_Interpretor& , Standard_Integer n, const char** a)
283 if (n <= 2) return 1;
284 TopoDS_Shape S = DBRep::Get(a[n-1]);
285 if (S.IsNull()) return 3;
287 static BRepIntCurveSurface_Inter theAlg;
288 static double tol=1e-6;
293 Handle(Geom_Curve) C= DrawTrSurf::GetCurve(a[1]);
294 if (C.IsNull()) return 2;
295 GeomAdaptor_Curve acur(C);
296 theAlg.Init(S, acur, tol);
297 for (; theAlg.More(); theAlg.Next()) {
301 char* temp = name; // pour portage WNT
302 Sprintf(temp, "%s_%d", "brics", nbpi);
303 DrawTrSurf::Set(temp, curp);
307 Handle(Geom_Line) hl;
309 for (Standard_Integer il = 1; il<n ; il++) {
310 hl= Handle(Geom_Line)::DownCast(DrawTrSurf::GetCurve(a[il]));
313 theAlg.Init(S, thel, tol);
314 for (; theAlg.More(); theAlg.Next()) {
318 char* temp = name; // pour portage WNT
319 Sprintf(temp, "%s_%d", "brics", nbpi);
320 DrawTrSurf::Set(temp, curp);
328 //=======================================================================
329 //function : MakeBoss
331 //=======================================================================
332 Standard_Integer MakeBoss(Draw_Interpretor& , Standard_Integer , const char** a)
334 TopoDS_Shape myS = DBRep::Get( a[2] );
336 TopoDS_Shape myBasis = DBRep::Get( a[3] ) ;
338 Standard_Real ang = -0.05235987901687622;
341 TopoDS_Face basis = TopoDS::Face(myBasis);
343 BRepFeat_MakeDPrism DPRISM(myS, basis, basis, ang, 1, Standard_True);
345 TopoDS_Shape myFaceOnShape;
346 gp_Pnt Pnt(0.0, 0.0, 50.0);
347 gp_Dir Dir(-0.0, -0.0, -1.0);
350 myFaceOnShape = NextFaceForPrism(myS, myBasis, ax);
352 DPRISM.Perform (myFaceOnShape);
355 if( DPRISM.IsDone() ) DBRep::Set( a[1], DPRISM.Shape() );
359 //=======================================================================
360 //function : MakeShell
362 //=======================================================================
363 Standard_Integer MakeShell(Draw_Interpretor& , Standard_Integer , const char** a)
366 TopoDS_Shape aShape = DBRep::Get( a[1] );
367 TopTools_ListOfShape Lst;
368 TopExp_Explorer Exp(aShape, TopAbs_FACE);
369 TopoDS_Shape InputShape(DBRep::Get( a[2] ));
370 TopoDS_Face F = TopoDS::Face(InputShape);
371 // TopoDS_Face F = TopoDS::Face(DBRep::Get( a[2] ));
373 Standard_Real Off = -Draw::Atof( a[3] );
375 BRepOffset_MakeOffset Offset;
377 Offset.Initialize( aShape, Off, 1.0e-3, BRepOffset_Skin,
378 Standard_True , Standard_False , GeomAbs_Arc );
380 Offset.MakeThickSolid();
382 if( Offset.IsDone() ) {
383 // SaveShape::Save(Offset.Shape(), "ss");
384 DBRep::Set( a[1], Offset.Shape() );
388 //=======================================================================
391 //=======================================================================
392 Standard_Integer xbounds(Draw_Interpretor& di, Standard_Integer n, const char** a)
395 di << "Usage : " << a[0] << " face" << "\n";
400 Standard_Real aUMin, aUMax, aVMin, aVMax;
406 di << " null shapes is not allowed here\n";
409 if (aS.ShapeType()!=TopAbs_FACE) {
410 di << " shape" << a[1] <<" must be a face\n";
414 aF=*((TopoDS_Face*)&aS);
416 BRepTools::UVBounds(aF, aUMin, aUMax, aVMin, aVMax);
418 TCollection_AsciiString aStr;
419 TCollection_AsciiString sUMin(aUMin);
420 TCollection_AsciiString sUMax(aUMax);
421 TCollection_AsciiString sVMin(aVMin);
422 TCollection_AsciiString sVMax(aVMax);
424 aStr=aStr+sUMin + "\n";
425 aStr=aStr+sUMax + "\n";
426 aStr=aStr+sVMin + "\n";
427 aStr=aStr+sVMax + "\n";
428 di <<aStr.ToCString();
432 //=======================================================================
433 //function : xclassify
435 //=======================================================================
436 Standard_Integer xclassify (Draw_Interpretor& aDI, Standard_Integer n, const char** a)
439 aDI<<" use xclassify Solid [Tolerance=1.e-7]\n";
443 TopoDS_Shape aS = DBRep::Get(a[1]);
445 aDI<<" Null Shape is not allowed here\n";
449 if (aS.ShapeType()!=TopAbs_SOLID) {
450 aDI<< " Shape type must be SOLID\n";
454 Standard_Real aTol=1.e-7;
455 TopAbs_State aState = TopAbs_UNKNOWN;
459 aTol=Draw::Atof(a[2]);
462 BRepClass3d_SolidClassifier aSC(aS);
463 aSC.PerformInfinitePoint(aTol);
465 aState = aSC.State();
466 PrintState(aDI, aState);
470 //=======================================================================
471 //function : PrintState
473 //=======================================================================
474 void PrintState (Draw_Interpretor& aDI,
475 const TopAbs_State& aState)
494 //=======================================================================
495 //function : NextFaceForPrism
496 //purpose : Search a face from <shape> which intersects with a line of
497 // direction <ax1> and location a point of <basis>.
498 //=======================================================================
499 TopoDS_Face NextFaceForPrism (const TopoDS_Shape& shape,
500 const TopoDS_Shape& basis,
503 TopoDS_Face nextFace;
505 TColgp_SequenceOfPnt seqPnts;
506 SampleEdges(basis, seqPnts);
508 for (Standard_Integer i=1; i<=seqPnts.Length(); i++) {
509 const gp_Pnt& pt = seqPnts(i);
510 // find a axis through a face
511 gp_Dir dir = ax1.Direction();
512 gp_Ax1 ax1b(pt, dir);
514 LocOpe_CSIntersector ASI(shape);
515 LocOpe_SequenceOfLin slin;
520 Standard_Integer no=1, IndFrom, IndTo;
521 TopAbs_Orientation theOr;
522 Standard_Real min = 1.e-04, Tol = -Precision::Confusion();
523 if (ASI.LocalizeAfter (no, min, Tol, theOr, IndFrom, IndTo)) {
524 nextFace = ASI.Point(no, IndFrom).Face();
534 //=======================================================================
535 //function : SampleEdges
536 //purpose : Sampling of <theShape>.
537 //design : Collect the vertices and points on the edges
538 //=======================================================================
539 void SampleEdges (const TopoDS_Shape& theShape, TColgp_SequenceOfPnt& theSeq)
545 TopTools_MapOfShape theMap;
548 // Adds all vertices/pnt
549 for (exp.Init(theShape,TopAbs_VERTEX); exp.More(); exp.Next()) {
550 if (theMap.Add(exp.Current())) {
551 theSeq.Append (BRep_Tool::Pnt(TopoDS::Vertex(exp.Current())));
555 // Computes points on edge, but does not take the extremities into account
556 Standard_Integer NECHANT = 5;
557 Handle(Geom_Curve) C;
558 Standard_Real f,l,prm;
559 for (exp.Init (theShape,TopAbs_EDGE); exp.More(); exp.Next()) {
560 const TopoDS_Edge& edg = TopoDS::Edge(exp.Current());
561 if (theMap.Add(edg)) {
562 if (!BRep_Tool::Degenerated(edg)) {
563 C = BRep_Tool::Curve(edg,f,l);
564 for (Standard_Integer i=1; i < NECHANT; i++) {
565 prm = ((NECHANT-i)*f+i*l)/NECHANT;
566 theSeq.Append (C->Value(prm));