1 // Created on: 1998-12-21
2 // Created by: Michael KAZAKOV
3 // Copyright (c) 1998-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.
23 #include <BRepTest.hxx>
24 #include <Draw_Interpretor.hxx>
25 #include <Draw_Appli.hxx>
27 #include <BRepTools.hxx>
28 #include <BRepOffset.hxx>
29 #include <BRepOffsetAPI_MakeThickSolid.hxx>
30 #include <TopTools_ListOfShape.hxx>
31 #include <TopoDS_Shape.hxx>
32 #include <TopExp_Explorer.hxx>
34 #include <BRep_Tool.hxx>
36 #include <TopExp_Explorer.hxx>
38 #include <TopoDS_Face.hxx>
40 #include <TopoDS_Shell.hxx>
41 #include <TopoDS_Solid.hxx>
42 #include <BRepClass3d.hxx>
46 Standard_Boolean issame(TopoDS_Face& face,
47 TopoDS_Face& newface);
49 TopoDS_Face findface(TopoDS_Shape& shape,
52 static Standard_Integer shell(Draw_Interpretor&, Standard_Integer, const char** );
53 static Standard_Integer outershell(Draw_Interpretor&, Standard_Integer, const char** );
55 //=======================================================================
56 //function : ShellCommands
58 //=======================================================================
59 void BRepTest::ShellCommands(Draw_Interpretor& theCommands)
61 static Standard_Boolean loaded = Standard_False;
63 loaded = Standard_True;
65 const char* g = "Projection of wire commands";
67 theCommands.Add("shell","Make shell on bugged object", __FILE__, shell,g);
68 theCommands.Add("outershell","use outershell r s", __FILE__, outershell,g);
71 //modified by NIZNHY-PKV Thu Sep 20 10:44:11 2012f
72 //=======================================================================
73 //function : outershell
75 //=======================================================================
76 Standard_Integer outershell(Draw_Interpretor& di, Standard_Integer n, const char** a)
83 di << " use outershell r s\n";
89 di << " Null shape is not allowed\n";
92 if (aS.ShapeType()!=TopAbs_SOLID) {
93 di << " The shape must be a solid\n";
97 aSd=*((TopoDS_Solid*)&aS);
99 aSh=BRepClass3d::OuterShell(aSd);
101 di << " not found\n";
104 DBRep::Set(a[1],aSh);
109 //modified by NIZNHY-PKV Thu Sep 20 10:44:17 2012t
110 //=======================================================================
113 //=======================================================================
114 Standard_Integer shell(Draw_Interpretor& di, Standard_Integer n, const char** a)
116 TopoDS_Shape Shape = DBRep::Get(a[1]);
117 TopTools_ListOfShape ListOfCorks;
118 //cout <<"You have "<<n-2<<" of the reference faces" << endl;
119 di <<"You have "<<n-2<<" of the reference faces" << "\n";
120 Standard_Integer i=2;
123 //cout <<i-1<<"th element"<< endl;
124 di <<i-1<<"th element"<< "\n";
125 // ListOfCorks.Append(findface(Shape,TopoDS::Face(DBRep::Get(a[i]))));
126 TopoDS_Shape aLocalFace(DBRep::Get(a[i]));
127 ListOfCorks.Append(findface(Shape,(TopoDS_Face &) TopoDS::Face(aLocalFace)));
128 // ListOfCorks.Append(findface(Shape,(TopoDS_Face &) TopoDS::Face(DBRep::Get(a[i]))));
130 Standard_Real Tol = 1e-5;
131 Standard_Real OffsetValue = 1;
132 OffsetValue = -OffsetValue; // Offset > 0 = Interior.
133 BRepOffsetAPI_MakeThickSolid MKTS (Shape,
140 DBRep::Set("Result.brep",MKTS.Shape());
141 TopTools_ListOfShape Larg;
143 //Check if the shape has at least one face
144 TopExp_Explorer FExp (MKTS.Shape (), TopAbs_FACE);
146 //cout << "Standard_True"<<endl;
147 di << "Standard_True"<<"\n";
149 DBRep::Set("S",MKTS.Shape());
154 //=======================================================================
157 //=======================================================================
158 Standard_Boolean issame(TopoDS_Face& face, TopoDS_Face& newface)
160 TopExp_Explorer exp(face,TopAbs_VERTEX),newexp(newface,TopAbs_VERTEX);
161 Standard_Integer newcounter=0,counter=0;
162 for (;exp.More();exp.Next())
165 gp_Pnt p(BRep_Tool::Pnt(TopoDS::Vertex(exp.Current())));
166 for (;newexp.More();newexp.Next())
168 gp_Pnt newp(BRep_Tool::Pnt(TopoDS::Vertex(newexp.Current())));
169 if (p.IsEqual(newp,1e-7))
176 if (counter==newcounter)
177 return Standard_True;
178 return Standard_False;
181 //=======================================================================
182 //function : findface
184 //=======================================================================
185 TopoDS_Face findface(TopoDS_Shape& shape, TopoDS_Face& face)
188 TopExp_Explorer exp(shape,TopAbs_FACE);
189 for (;exp.More();exp.Next())
191 newface = TopoDS::Face(exp.Current());
192 if (issame(face,newface))