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