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