0023367: New functionality restoring the middle path of pipe-like shape
[occt.git] / src / BRepTest / BRepTest_ShellCommands.cxx
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
5 //
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.
10 //
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.
13 //
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.
20
21
22
23 #include <BRepTest.hxx>
24 #include <Draw_Interpretor.hxx>
25 #include <Draw_Appli.hxx>
26 #include <DBRep.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>
33 #include <TopAbs.hxx>
34 #include <BRep_Tool.hxx>
35 #include <gp_Pnt.hxx>
36 #include <TopExp_Explorer.hxx>
37 #include <TopAbs.hxx>
38 #include <TopoDS_Face.hxx>
39 #include <TopoDS.hxx>
40 #include <TopoDS_Shell.hxx>
41 #include <TopoDS_Solid.hxx>
42 #include <BRepClass3d.hxx>
43
44 //
45 static 
46   Standard_Boolean issame(TopoDS_Face& face, 
47                           TopoDS_Face& newface);
48 static 
49   TopoDS_Face findface(TopoDS_Shape& shape, 
50                        TopoDS_Face& face);
51 //
52 static Standard_Integer shell(Draw_Interpretor&, Standard_Integer, const char** );
53 static Standard_Integer outershell(Draw_Interpretor&, Standard_Integer, const char** );
54
55 //=======================================================================
56 //function : ShellCommands
57 //purpose  : 
58 //=======================================================================
59 void BRepTest::ShellCommands(Draw_Interpretor& theCommands)
60 {
61   static Standard_Boolean loaded = Standard_False;
62   if (loaded) return;
63   loaded = Standard_True;
64
65   const char* g = "Projection of wire commands";
66
67   theCommands.Add("shell","Make shell on bugged object",  __FILE__, shell,g);
68   theCommands.Add("outershell","use outershell r s",  __FILE__, outershell,g);
69
70 }
71 //modified by NIZNHY-PKV Thu Sep 20 10:44:11 2012f
72 //=======================================================================
73 //function : outershell
74 //purpose  : 
75 //=======================================================================
76 Standard_Integer outershell(Draw_Interpretor& di, Standard_Integer n, const char** a)
77 {  
78   TopoDS_Shape aS;
79   TopoDS_Solid aSd;
80   TopoDS_Shell aSh;
81   //
82   if (n!=3) {
83     di << " use outershell r s\n";
84     return 1;
85   }
86   //
87   aS=DBRep::Get(a[2]);
88   if (aS.IsNull()) {
89     di << " Null shape is not allowed\n";
90     return 1;
91   }
92   if (aS.ShapeType()!=TopAbs_SOLID) {
93     di << " The shape must be a solid\n";
94     return 1;
95   }
96   //
97   aSd=*((TopoDS_Solid*)&aS);
98   //
99   aSh=BRepClass3d::OuterShell(aSd);
100   if (aSh.IsNull()) {
101     di << " not found\n";
102   }
103   else {
104     DBRep::Set(a[1],aSh);
105   }
106   return 0;
107 }
108
109 //modified by NIZNHY-PKV Thu Sep 20 10:44:17 2012t
110 //=======================================================================
111 //function : shell
112 //purpose  : 
113 //=======================================================================
114 Standard_Integer shell(Draw_Interpretor& di, Standard_Integer n, const char** a)
115
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;
121   for (;i<n;i++)
122     {
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]))));
129     }
130   Standard_Real Tol = 1e-5;
131   Standard_Real OffsetValue = 1;
132   OffsetValue = -OffsetValue; // Offset > 0 = Interior.
133   BRepOffsetAPI_MakeThickSolid MKTS (Shape, 
134                                ListOfCorks, 
135                                OffsetValue, 
136                                Tol, 
137                                BRepOffset_Skin, 
138                                1, Standard_False);
139
140   DBRep::Set("Result.brep",MKTS.Shape());
141   TopTools_ListOfShape Larg;
142   Larg.Append(Shape);
143   //Check if the shape has at least one face
144   TopExp_Explorer FExp (MKTS.Shape (), TopAbs_FACE);
145   if (FExp.More ()) {
146     //cout << "Standard_True"<<endl;
147     di << "Standard_True"<<"\n";
148   }
149   DBRep::Set("S",MKTS.Shape());
150   return 0;
151 }
152
153
154 //=======================================================================
155 //function : issame
156 //purpose  : 
157 //=======================================================================
158 Standard_Boolean issame(TopoDS_Face& face, TopoDS_Face& newface)
159 {
160   TopExp_Explorer exp(face,TopAbs_VERTEX),newexp(newface,TopAbs_VERTEX);
161   Standard_Integer newcounter=0,counter=0;
162   for (;exp.More();exp.Next())
163     {
164       counter++;
165       gp_Pnt p(BRep_Tool::Pnt(TopoDS::Vertex(exp.Current())));
166       for (;newexp.More();newexp.Next())
167         {
168           gp_Pnt newp(BRep_Tool::Pnt(TopoDS::Vertex(newexp.Current())));
169           if (p.IsEqual(newp,1e-7))
170             {
171               newcounter++;
172               break;
173             };
174         };
175     };
176   if (counter==newcounter)
177     return Standard_True;
178   return Standard_False;
179 }
180
181 //=======================================================================
182 //function : findface
183 //purpose  : 
184 //=======================================================================
185 TopoDS_Face findface(TopoDS_Shape& shape, TopoDS_Face& face)
186 {
187   TopoDS_Face newface;
188   TopExp_Explorer exp(shape,TopAbs_FACE);
189   for (;exp.More();exp.Next())
190     {
191       newface = TopoDS::Face(exp.Current());
192       if (issame(face,newface))
193         {
194           break;
195         };
196     };
197   return newface;
198 }
199
200