]> SALOME platform Git repositories - modules/geom.git/blob - src/NMTDS/NMTDS_Tools.cxx
Salome HOME
NPAL 16768 Select Vertex from Vertex on Shape
[modules/geom.git] / src / NMTDS / NMTDS_Tools.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:        NMTDS_Tools.cxx
21 // Created:     Tue Feb 20 14:57:28 2007
22 // Author:      Peter KURNEV
23 //              <pkv@irinox>
24
25
26 #include <NMTDS_Tools.ixx>
27 #include <TopoDS_Vertex.hxx>
28 #include <gp_Pnt.hxx>
29 #include <BRep_Tool.hxx>
30 #include <TopoDS_Shape.hxx>
31 #include <TopTools_IndexedDataMapOfShapeShape.hxx>
32 #include <TopAbs_ShapeEnum.hxx>
33 #include <TopoDS_Iterator.hxx>
34 #include <BRep_Builder.hxx>
35
36 void CopySource(const TopoDS_Shape& aS, 
37                 TopTools_IndexedDataMapOfShapeShape& aMapSS, 
38                 TopoDS_Shape& aSC);
39
40 //=======================================================================
41 //function : CopyShape
42 //purpose  : 
43 //=======================================================================
44   void NMTDS_Tools::CopyShape(const TopoDS_Shape& aS, 
45                               TopoDS_Shape& aSC)
46 {
47   TopTools_IndexedDataMapOfShapeShape aMapSS;
48   //
49   CopySource(aS, aMapSS, aSC);
50 }
51 //=======================================================================
52 //function : CopyShape
53 //purpose  : 
54 //=======================================================================
55   void NMTDS_Tools::CopyShape(const TopoDS_Shape& aS, 
56                               TopoDS_Shape& aSC,
57                               TopTools_IndexedDataMapOfShapeShape& aMapSS)
58 {
59   CopySource(aS, aMapSS, aSC);
60 }
61 //=======================================================================
62 //function : CopySource
63 //purpose  : 
64 //=======================================================================
65 void CopySource(const TopoDS_Shape& aS, 
66                 TopTools_IndexedDataMapOfShapeShape& aMapSS, 
67                 TopoDS_Shape& aSC)
68 {
69   Standard_Boolean bFree;
70   TopAbs_ShapeEnum aT;
71   TopoDS_Iterator aIt;
72   BRep_Builder BB;
73   //
74   aT=aS.ShapeType();
75   //
76   if (aMapSS.Contains(aS)) {
77     aSC=aMapSS.ChangeFromKey(aS);
78     aSC.Orientation(aS.Orientation());
79     return;
80   }
81   else {
82     aSC=aS.EmptyCopied();
83     aMapSS.Add(aS, aSC);
84   }
85   //
86   bFree=aSC.Free();
87   aSC.Free(Standard_True);
88   aIt.Initialize(aS);
89   for (; aIt.More();  aIt.Next()) {
90     TopoDS_Shape aSCx;
91     //
92     const TopoDS_Shape& aSx=aIt.Value();
93     //
94     CopySource (aSx, aMapSS, aSCx);  
95     //
96     aSCx.Orientation(aSx.Orientation());
97     BB.Add(aSC, aSCx);
98   }
99   aSC.Free(bFree);
100 }
101 //=======================================================================
102 // function: ComputeVV
103 // purpose: 
104 //=======================================================================
105   Standard_Integer NMTDS_Tools::ComputeVV(const TopoDS_Vertex& aV1, 
106                                           const TopoDS_Vertex& aV2)
107 {
108   Standard_Real aTolV1, aTolV2, aTolSum, aTolSum2, aD2;
109   gp_Pnt aP1, aP2;
110   //
111   aTolV1=BRep_Tool::Tolerance(aV1);
112   aTolV2=BRep_Tool::Tolerance(aV2);
113   aTolSum=aTolV1+aTolV2;
114   aTolSum2=aTolSum*aTolSum;
115   //
116   aP1=BRep_Tool::Pnt(aV1);
117   aP2=BRep_Tool::Pnt(aV2);
118   //
119   aD2=aP1.SquareDistance(aP2);
120   if (aD2>aTolSum2) {
121     return -1;
122   }
123   return 0;
124 }
125 //=======================================================================
126 // function: HasBRep
127 // purpose: 
128 //=======================================================================
129   Standard_Boolean NMTDS_Tools::HasBRep(const TopAbs_ShapeEnum aTi)
130 {
131   return (aTi==TopAbs_VERTEX || aTi==TopAbs_EDGE || aTi==TopAbs_FACE);
132 }
133 //=======================================================================
134 //function : TypeToInteger
135 //purpose  : 
136 //=======================================================================
137   Standard_Integer NMTDS_Tools::TypeToInteger(const TopAbs_ShapeEnum aType1,
138                                             const TopAbs_ShapeEnum aType2)
139 {
140   Standard_Integer iRet, iT1, iT2, iX;
141   //
142   iRet=-1;
143   iT1=(Standard_Integer)aType1;
144   iT2=(Standard_Integer)aType2;
145   //
146   iX=iT2*10+iT1;
147   switch (iX) {
148     case 77:
149       iRet=5; // VV
150       break;
151     case 76:
152     case 67:
153       iRet=4; // VE
154       break;
155     case 74:
156     case 47:
157       iRet=2; // VF
158       break;
159     case 66:
160       iRet=3; // EE
161       break;
162     case 64:
163     case 46:
164       iRet=1; // EF
165       break;
166     case 44:
167       iRet=0; // FF
168       break;
169     default:
170       break;
171   }
172   return iRet; 
173 }