Salome HOME
Join modifications from BR_Dev_For_4_0 tag V4_1_1.
[modules/geom.git] / src / GEOMAlgo / GEOMAlgo_ClsfSolid.cxx
1 // Copyright (C) 2005  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
3 // 
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either 
7 // version 2.1 of the License.
8 // 
9 // This library is distributed in the hope that it will be useful 
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
12 // Lesser General Public License for more details.
13 //
14 // You should have received a copy of the GNU Lesser General Public  
15 // License along with this library; if not, write to the Free Software 
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
17 //
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 //
20 // File:        GEOMAlgo_ClsfSolid.cxx
21 // Created:     Mon Jan 29 10:35:46 2007
22 // Author:      Peter KURNEV
23 //              <pkv@irinox>
24
25
26 #include <GEOMAlgo_ClsfSolid.ixx>
27
28 #include <TopAbs_ShapeEnum.hxx>
29 #include <TopoDS.hxx>
30 #include <TopoDS_Solid.hxx>
31 #include <BRep_Builder.hxx>
32 #include <BRepClass3d_SolidClassifier.hxx>
33
34 //=======================================================================
35 //function : 
36 //purpose  : 
37 //=======================================================================
38   GEOMAlgo_ClsfSolid::GEOMAlgo_ClsfSolid()
39 :
40   GEOMAlgo_Clsf()
41 {
42   myPClsf=NULL;
43 }
44 //=======================================================================
45 //function : ~
46 //purpose  : 
47 //=======================================================================
48   GEOMAlgo_ClsfSolid::~GEOMAlgo_ClsfSolid()
49 {
50   if (myPClsf) {
51     BRepClass3d_SolidClassifier* pSC;
52     //
53     pSC=(BRepClass3d_SolidClassifier*)myPClsf;
54     delete pSC;
55   }
56 }
57 //=======================================================================
58 //function : SetShape
59 //purpose  : 
60 //=======================================================================
61   void GEOMAlgo_ClsfSolid::SetShape(const TopoDS_Shape& aS)
62 {
63   myShape=aS;
64 }
65 //=======================================================================
66 //function : Shape
67 //purpose  : 
68 //=======================================================================
69   const TopoDS_Shape& GEOMAlgo_ClsfSolid::Shape()const
70 {
71   return myShape;
72 }
73 //=======================================================================
74 //function : CheckData
75 //purpose  : 
76 //=======================================================================
77   void GEOMAlgo_ClsfSolid::CheckData()
78 {
79   myErrorStatus=0;
80   //
81   BRepClass3d_SolidClassifier* pSC;
82   TopAbs_ShapeEnum aType;
83   BRep_Builder aBB;
84   TopoDS_Solid aS;
85   //
86   if (myShape.IsNull()) {
87     myErrorStatus=10; // mySolid=NULL
88     return;
89   }
90   //
91   aType=myShape.ShapeType();
92   if (!(aType==TopAbs_SOLID || aType==TopAbs_SHELL)) {
93     myErrorStatus=12; 
94     return;
95   }
96   //
97   //===
98   if (aType==TopAbs_SOLID) {
99     aS=TopoDS::Solid(myShape);
100   }
101   else {
102     aBB.MakeSolid(aS);
103     aBB.Add(aS, myShape);
104   }
105   //
106   if (myPClsf) {
107     pSC=(BRepClass3d_SolidClassifier*)myPClsf;
108     delete pSC;
109   }
110   //
111   pSC=new BRepClass3d_SolidClassifier(aS);
112   myPClsf=pSC;
113 }
114 //=======================================================================
115 //function : Perform
116 //purpose  : 
117 //=======================================================================
118   void GEOMAlgo_ClsfSolid::Perform()
119 {
120   myErrorStatus=0;
121   //
122   if (!myPClsf) {
123     myErrorStatus=11;
124     return;
125   }
126   //
127   BRepClass3d_SolidClassifier* pSC;
128   //
129   pSC=(BRepClass3d_SolidClassifier*)myPClsf;
130   pSC->Perform(myPnt, myTolerance);
131   myState=pSC->State();
132 }
133 //
134 // myErrorStatus :
135 //
136 // 10 - mySolid=NULL
137 // 11 - myPClsf=NULL
138 // 12 - unallowed type of myShape
139