Integration of OCCT 6.5.0 from SVN
[occt.git] / src / BRepTest / BRepTest_ShellCommands.cxx
1 // File:        BRepTest_ShellCommands.cxx
2 // Created:     Mon Dec 21 10:19:27 1998
3 // Author:      Michael KAZAKOV
4 //              <mko@vladox.nnov.matra-dtv.fr>
5
6
7 #include <BRepTest.hxx>
8 #include <Draw_Interpretor.hxx>
9 #include <Draw_Appli.hxx>
10 #include <DBRep.hxx>
11 #include <BRepTools.hxx>
12 #include <BRepOffset.hxx>
13 #include <BRepOffsetAPI_MakeThickSolid.hxx>
14 #include <TopTools_ListOfShape.hxx>
15 #include <TopoDS_Shape.hxx>
16 #include <TopExp_Explorer.hxx>
17 #include <TopAbs.hxx>
18 #include <BRep_Tool.hxx>
19 #include <gp_Pnt.hxx>
20 #include <TopExp_Explorer.hxx>
21 #include <TopAbs.hxx>
22 #include <TopoDS_Face.hxx>
23 #include <TopoDS.hxx>
24
25
26
27
28 static Standard_Boolean issame(TopoDS_Face& face, TopoDS_Face& newface)
29 {
30   TopExp_Explorer exp(face,TopAbs_VERTEX),newexp(newface,TopAbs_VERTEX);
31   Standard_Integer newcounter=0,counter=0;
32   for (;exp.More();exp.Next())
33     {
34       counter++;
35       gp_Pnt p(BRep_Tool::Pnt(TopoDS::Vertex(exp.Current())));
36       for (;newexp.More();newexp.Next())
37         {
38           gp_Pnt newp(BRep_Tool::Pnt(TopoDS::Vertex(newexp.Current())));
39           if (p.IsEqual(newp,1e-7))
40             {
41               newcounter++;
42               break;
43             };
44         };
45     };
46   if (counter==newcounter)
47     return Standard_True;
48   return Standard_False;
49 }
50
51 static TopoDS_Face findface(TopoDS_Shape& shape, TopoDS_Face& face)
52 {
53   TopoDS_Face newface;
54   TopExp_Explorer exp(shape,TopAbs_FACE);
55   for (;exp.More();exp.Next())
56     {
57       newface = TopoDS::Face(exp.Current());
58       if (issame(face,newface))
59         {
60           break;
61         };
62     };
63   return newface;
64 }
65
66 static Standard_Integer shell(Draw_Interpretor& di, Standard_Integer n, const char** a)
67
68   TopoDS_Shape Shape =  DBRep::Get(a[1]);
69   TopTools_ListOfShape ListOfCorks;
70   //cout <<"You have "<<n-2<<" of the reference faces" << endl;
71   di <<"You have "<<n-2<<" of the reference faces" << "\n";
72   Standard_Integer i=2;
73   for (;i<n;i++)
74     {
75       //cout <<i-1<<"th element"<< endl;
76       di <<i-1<<"th element"<< "\n";
77 //      ListOfCorks.Append(findface(Shape,TopoDS::Face(DBRep::Get(a[i]))));
78       TopoDS_Shape aLocalFace(DBRep::Get(a[i]));
79       ListOfCorks.Append(findface(Shape,(TopoDS_Face &) TopoDS::Face(aLocalFace)));
80 //      ListOfCorks.Append(findface(Shape,(TopoDS_Face &) TopoDS::Face(DBRep::Get(a[i]))));
81     }
82   Standard_Real Tol = 1e-5;
83   Standard_Real OffsetValue = 1;
84   OffsetValue = -OffsetValue; // Offset > 0 = Interior.
85   BRepOffsetAPI_MakeThickSolid MKTS (Shape, 
86                                ListOfCorks, 
87                                OffsetValue, 
88                                Tol, 
89                                BRepOffset_Skin, 
90                                1, Standard_False);
91
92   DBRep::Set("Result.brep",MKTS.Shape());
93   TopTools_ListOfShape Larg;
94   Larg.Append(Shape);
95   //Check if the shape has at least one face
96   TopExp_Explorer FExp (MKTS.Shape (), TopAbs_FACE);
97   if (FExp.More ()) {
98     //cout << "Standard_True"<<endl;
99     di << "Standard_True"<<"\n";
100   }
101   DBRep::Set("S",MKTS.Shape());
102   return 0;
103 }
104 /*********************************************************************************/
105
106 void  BRepTest::ShellCommands(Draw_Interpretor& theCommands)
107 {
108   static Standard_Boolean loaded = Standard_False;
109   if (loaded) return;
110   loaded = Standard_True;
111
112   const char* g = "Projection of wire commands";
113
114   theCommands.Add("shell","Make shell on bugged object",
115                   __FILE__,
116                   shell,g);
117
118 }