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