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