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