Salome HOME
b9acbd6777e200dfc84d1233e21dd69bc1efb9fd
[modules/geom.git] / src / GEOMAlgo / GEOMAlgo_ClsfSolid.cxx
1 // Copyright (C) 2007-2023  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_RTTIEXT(GEOMAlgo_ClsfSolid, GEOMAlgo_Clsf)
36
37 //=======================================================================
38 //function :
39 //purpose  :
40 //=======================================================================
41   GEOMAlgo_ClsfSolid::GEOMAlgo_ClsfSolid()
42 :
43   GEOMAlgo_Clsf()
44 {
45   myPClsf=NULL;
46 }
47 //=======================================================================
48 //function : ~
49 //purpose  :
50 //=======================================================================
51   GEOMAlgo_ClsfSolid::~GEOMAlgo_ClsfSolid()
52 {
53   if (myPClsf) {
54     BRepClass3d_SolidClassifier* pSC;
55     //
56     pSC=(BRepClass3d_SolidClassifier*)myPClsf;
57     delete pSC;
58   }
59 }
60 //=======================================================================
61 //function : SetShape
62 //purpose  :
63 //=======================================================================
64   void GEOMAlgo_ClsfSolid::SetShape(const TopoDS_Shape& aS)
65 {
66   myShape=aS;
67 }
68 //=======================================================================
69 //function : Shape
70 //purpose  :
71 //=======================================================================
72   const TopoDS_Shape& GEOMAlgo_ClsfSolid::Shape()const
73 {
74   return myShape;
75 }
76 //=======================================================================
77 //function : CheckData
78 //purpose  :
79 //=======================================================================
80   void GEOMAlgo_ClsfSolid::CheckData()
81 {
82   myErrorStatus=0;
83   //
84   BRepClass3d_SolidClassifier* pSC;
85   TopAbs_ShapeEnum aType;
86   BRep_Builder aBB;
87   TopoDS_Solid aS;
88   //
89   if (myShape.IsNull()) {
90     myErrorStatus=10; // mySolid=NULL
91     return;
92   }
93   //
94   aType=myShape.ShapeType();
95   if (!(aType==TopAbs_SOLID || aType==TopAbs_SHELL)) {
96     myErrorStatus=12;
97     return;
98   }
99   //
100   //===
101   if (aType==TopAbs_SOLID) {
102     aS=TopoDS::Solid(myShape);
103   }
104   else {
105     aBB.MakeSolid(aS);
106     aBB.Add(aS, myShape);
107   }
108   //
109   if (myPClsf) {
110     pSC=(BRepClass3d_SolidClassifier*)myPClsf;
111     delete pSC;
112   }
113   //
114   pSC=new BRepClass3d_SolidClassifier(aS);
115   myPClsf=pSC;
116 }
117 //=======================================================================
118 //function : Perform
119 //purpose  :
120 //=======================================================================
121   void GEOMAlgo_ClsfSolid::Perform()
122 {
123   myErrorStatus=0;
124   //
125   if (!myPClsf) {
126     myErrorStatus=11;
127     return;
128   }
129   //
130   BRepClass3d_SolidClassifier* pSC;
131   //
132   pSC=(BRepClass3d_SolidClassifier*)myPClsf;
133   pSC->Perform(myPnt, myTolerance);
134   myState=pSC->State();
135 }
136 //
137 // myErrorStatus :
138 //
139 // 10 - mySolid=NULL
140 // 11 - myPClsf=NULL
141 // 12 - unallowed type of myShape
142