Salome HOME
Avoid linking to the native omniORB
[modules/geom.git] / src / GEOMAlgo / GEOMAlgo_ClsfBox.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_ClsfSurf.cxx
21 // Created:     Wed Nov 22 10:41:47 2006
22 // Author:      Peter KURNEV
23 //              <pkv@irinox>
24
25
26 #include <GEOMAlgo_ClsfBox.ixx>
27 #include <GeomAbs_SurfaceType.hxx>
28 #include <GEOMAlgo_SurfaceTools.hxx>
29 #include <TopAbs_ShapeEnum.hxx>
30 #include <TopTools_IndexedMapOfShape.hxx>
31 #include <TopExp.hxx>
32 #include <TopoDS_Face.hxx>
33 #include <TopoDS.hxx>
34 #include <Geom_Surface.hxx>
35 #include <BRep_Tool.hxx>
36 #include <Geom_Plane.hxx>
37 #include <gp_Pnt.hxx>
38 #include <gp_Dir.hxx>
39 #include <gp_Pln.hxx>
40 #include <gp_Ax1.hxx>
41 #include <Geom_Plane.hxx>
42
43 //=======================================================================
44 //function : 
45 //purpose  : 
46 //=======================================================================
47   GEOMAlgo_ClsfBox::GEOMAlgo_ClsfBox()
48 :
49   GEOMAlgo_Clsf()
50 {
51 }
52 //=======================================================================
53 //function : ~
54 //purpose  : 
55 //=======================================================================
56   GEOMAlgo_ClsfBox::~GEOMAlgo_ClsfBox()
57 {
58 }
59 //=======================================================================
60 //function : SetBox
61 //purpose  : 
62 //=======================================================================
63   void GEOMAlgo_ClsfBox::SetBox(const TopoDS_Shape& aBox)
64 {
65   myBox=aBox;
66 }
67 //=======================================================================
68 //function : Box
69 //purpose  : 
70 //=======================================================================
71   const TopoDS_Shape& GEOMAlgo_ClsfBox::Box() const
72 {
73   return myBox;
74 }
75 //=======================================================================
76 //function : CheckData
77 //purpose  : 
78 //=======================================================================
79   void GEOMAlgo_ClsfBox::CheckData()
80
81   Standard_Integer i, aNbF;
82   TopAbs_ShapeEnum aTypeShape;
83   TopAbs_Orientation aOr;
84   GeomAbs_SurfaceType aType;
85   Handle(Geom_Surface) aS;
86   TopTools_IndexedMapOfShape aMF;
87   //
88   myErrorStatus=0;
89   //
90   if(myBox.IsNull()) {
91     myErrorStatus=10; // myBox=NULL
92     return;
93   }
94   //
95   aTypeShape=myBox.ShapeType();
96   if (aTypeShape!=TopAbs_SOLID) {
97     myErrorStatus=11; // unallowed shape type
98     return;
99   }
100   //
101   TopExp::MapShapes(myBox, TopAbs_FACE, aMF);
102   aNbF=aMF.Extent();
103   if (aNbF!=6) {
104     myErrorStatus=12; // wrong number of faces
105     return;
106   }
107   //
108   for (i=1; i<=aNbF; ++i) {
109     const TopoDS_Face& aF=TopoDS::Face(aMF(i));
110     aOr=aF.Orientation();
111     if (!(aOr==TopAbs_FORWARD || aOr==TopAbs_REVERSED)) {
112       myErrorStatus=12; // unallowed orientation of face
113       return;
114     }
115     //
116     aS=BRep_Tool::Surface(aF);
117     myGAS[i-1].Load(aS);
118     aType=myGAS[i-1].GetType();
119     if (!aType==GeomAbs_Plane) { 
120       myErrorStatus=13; // unallowed surface type
121       return;
122     }
123     //
124     if(aOr==TopAbs_REVERSED) {
125       gp_Ax1 aAx1;
126       gp_Pln aPln;
127       gp_Pnt aP;
128       gp_Dir aD;
129       Handle(Geom_Plane) aSR;
130       //
131       aPln=myGAS[i-1].Plane();
132       aAx1=aPln.Axis();
133       aP=aAx1.Location();
134       aD=aAx1.Direction();
135       aD.Reverse();
136       aSR=new Geom_Plane(aP, aD);
137       myGAS[i-1].Load(aSR);
138     }
139   }
140 }
141 //=======================================================================
142 //function : Perform
143 //purpose  : 
144 //=======================================================================
145   void GEOMAlgo_ClsfBox::Perform()
146 {
147   myErrorStatus=0;
148   //
149   const Standard_Integer aNbS=6;
150   Standard_Integer i, aNbON, aNbIN, iNext;
151   TopAbs_State aSt;
152   /*
153   CheckData();
154   if(myErrorStatus) {
155     return;
156   }
157   */
158   iNext=1;
159   aNbON=0; 
160   aNbIN=0;
161   for(i=0; i<aNbS && iNext; i++) {
162     GEOMAlgo_SurfaceTools::GetState(myPnt, myGAS[i], myTolerance, aSt);
163     //
164     switch (aSt) {
165       case TopAbs_OUT:
166         myState=aSt;
167         iNext=0;
168         break;
169       case TopAbs_ON:
170         ++aNbON;
171         break;
172       case TopAbs_IN:
173         ++aNbIN;
174         break;
175       default:
176         myState=TopAbs_UNKNOWN;
177         iNext=0;
178         break; 
179     }
180   }
181   //
182   if (iNext) {
183     myState=TopAbs_UNKNOWN;
184     //
185     if (aNbON && aNbIN) {
186       myState=TopAbs_ON;
187     }
188     else if (aNbIN==aNbS){
189       myState=TopAbs_IN;
190     }
191   }
192 }
193 //=======================================================================
194 //function : CanBeON
195 //purpose  : 
196 //=======================================================================
197   Standard_Boolean GEOMAlgo_ClsfBox::CanBeON(const Handle(Geom_Curve)& aC) const
198 {
199   return GEOMAlgo_Clsf::CanBeON(aC);
200 }
201 //=======================================================================
202 //function : CanBeON
203 //purpose  : 
204 //=======================================================================
205   Standard_Boolean GEOMAlgo_ClsfBox::CanBeON(const Handle(Geom_Surface)& aS1) const
206 {
207   Standard_Boolean bRet;
208   GeomAbs_SurfaceType  aST1;
209   GeomAdaptor_Surface aGAS1;
210   //
211   aGAS1.Load(aS1);
212   aST1=aGAS1.GetType();
213   bRet=(aST1==GeomAbs_Plane);
214   //
215   return bRet;
216 }