Salome HOME
b1e12489e6064b8f23fa4f021bd687b1e4c71b5e
[modules/geom.git] / src / GEOMAlgo / GEOMAlgo_GetInPlace_3.cxx
1 // Copyright (C) 2007-2023  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, or (at your option) any later version.
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_GetInPlaceIterator.cxx
23 // Created:
24 // Author:      Peter KURNEV
25
26 #include <GEOMAlgo_GetInPlace.hxx>
27
28 #include <GEOMAlgo_CoupleOfShapes.hxx>
29
30 static
31   Standard_Integer TypeToInteger(const TopAbs_ShapeEnum aType1,
32                                  const TopAbs_ShapeEnum aType2);
33
34 //=======================================================================
35 //function :
36 //purpose  :
37 //=======================================================================
38 GEOMAlgo_GetInPlaceIterator::GEOMAlgo_GetInPlaceIterator()
39 {
40   myDim=10;
41 }
42 //=======================================================================
43 //function : ~
44 //purpose  :
45 //=======================================================================
46 GEOMAlgo_GetInPlaceIterator::~GEOMAlgo_GetInPlaceIterator()
47 {
48 }
49 //=======================================================================
50 //function : Clear
51 //purpose  :
52 //=======================================================================
53 void GEOMAlgo_GetInPlaceIterator::Clear()
54 {
55   Standard_Integer i;
56   //
57   for (i=0; i<myDim; ++i) {
58     myLists[i].Clear();
59   }
60 }
61 //=======================================================================
62 //function : AppendPair
63 //purpose  :
64 //=======================================================================
65 void GEOMAlgo_GetInPlaceIterator::AppendPair(const GEOMAlgo_CoupleOfShapes& theCS)
66 {
67   Standard_Integer iX;
68   TopAbs_ShapeEnum aType1, aType2;
69   //
70   const TopoDS_Shape& aS1=theCS.Shape1();
71   const TopoDS_Shape& aS2=theCS.Shape2();
72   aType1=aS1.ShapeType();
73   aType2=aS2.ShapeType();
74   //
75   iX=TypeToInteger(aType1, aType2);
76   if (iX>=0) {
77     myLists[iX].Append(theCS);
78   } else {
79     // Add inverted pair of shapes.
80     iX=TypeToInteger(aType2, aType1);
81
82     if (iX>=0) {
83       GEOMAlgo_CoupleOfShapes aCSInv;
84
85       aCSInv.SetShapes(aS2, aS1);
86       myLists[iX].Append(aCSInv);
87     }
88   }
89 }
90 //=======================================================================
91 //function : ShapeWhere
92 //purpose  :
93 //=======================================================================
94 void GEOMAlgo_GetInPlaceIterator::Initialize(const TopAbs_ShapeEnum aType1,
95                                              const TopAbs_ShapeEnum aType2)
96 {
97   Standard_Integer iX;
98   //
99   iX=TypeToInteger(aType1, aType2);
100   if (iX>=0) {
101     myIterator.Initialize(myLists[iX]);
102   }
103   else {
104     myIterator.Initialize(myEmptyList);
105   }
106 }
107 //=======================================================================
108 // function: More
109 // purpose:
110 //=======================================================================
111 Standard_Boolean GEOMAlgo_GetInPlaceIterator::More()const
112 {
113   return myIterator.More();
114 }
115 //=======================================================================
116 // function: Next
117 // purpose:
118 //=======================================================================
119 void GEOMAlgo_GetInPlaceIterator::Next()
120 {
121   myIterator.Next();
122 }
123 //=======================================================================
124 // function: Value
125 // purpose:
126 //=======================================================================
127 const GEOMAlgo_CoupleOfShapes& GEOMAlgo_GetInPlaceIterator::Value()const
128 {
129   return myIterator.Value();
130 }
131 //=======================================================================
132 //function : TypeToInteger
133 //purpose  :
134 //=======================================================================
135 Standard_Integer TypeToInteger(const TopAbs_ShapeEnum aType1,
136                                const TopAbs_ShapeEnum aType2)
137 {
138   Standard_Integer iRet;
139   //
140   iRet=-1;
141   //
142   if (aType1==TopAbs_VERTEX) {
143     if (aType2==TopAbs_VERTEX) {
144       iRet=0;
145     }
146   }
147   else if (aType1==TopAbs_EDGE) {
148     if (aType2==TopAbs_VERTEX) {
149       iRet=1;
150     }
151     else if (aType2==TopAbs_EDGE) {
152       iRet=2;
153     }
154   }
155   else if (aType1==TopAbs_FACE) {
156     if (aType2==TopAbs_VERTEX) {
157       iRet=3;
158     }
159     else if (aType2==TopAbs_EDGE) {
160       iRet=4;
161     }
162     else if (aType2==TopAbs_FACE) {
163       iRet=5;
164     }
165   }
166   // So_1,*_2
167   else if (aType1==TopAbs_SOLID) {
168     if (aType2==TopAbs_VERTEX) {
169       iRet=6;
170     }
171     else if (aType2==TopAbs_EDGE) {
172       iRet=7;
173     }
174     else if (aType2==TopAbs_FACE) {
175       iRet=8;
176     }
177     else if (aType2==TopAbs_SOLID) {
178       iRet=9;
179     }
180   }
181   return iRet;
182 }