Salome HOME
This commit was generated by cvs2git to create tag 'TRIPOLI_323'.
[modules/geom.git] / src / GEOMAlgo / GEOMAlgo_WESScaler.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 // File:        GEOMAlgo_WESScaler.cxx
20 // Created:
21 // Author:
22 //              <pkv@VORTEX>
23
24
25 #include <GEOMAlgo_WESScaler.hxx>
26
27 #include <gp_Pnt.hxx>
28 #include <gp_Trsf.hxx>
29
30 #include <TopoDS_Face.hxx>
31 #include <TopoDS_Iterator.hxx>
32 #include <TopoDS_Wire.hxx>
33 #include <BRep_Builder.hxx>
34
35 #include <TopTools_ListOfShape.hxx>
36 #include <TopTools_ListIteratorOfListOfShape.hxx>
37
38 #include <BRepBuilderAPI_Transform.hxx>
39
40
41 //=======================================================================
42 //function :
43 //purpose  :
44 //=======================================================================
45   GEOMAlgo_WESScaler::GEOMAlgo_WESScaler()
46 :
47   GEOMAlgo_Algo()
48 {
49   myScale=1.;
50 }
51 //=======================================================================
52 //function : ~
53 //purpose  :
54 //=======================================================================
55   GEOMAlgo_WESScaler::~GEOMAlgo_WESScaler()
56 {
57 }
58 //=======================================================================
59 // function: SetScale
60 // purpose:
61 //=======================================================================
62   void GEOMAlgo_WESScaler::SetScale (const Standard_Real aScale)
63 {
64   myScale=aScale;
65 }
66 //=======================================================================
67 // function: Scale
68 // purpose:
69 //=======================================================================
70   Standard_Real GEOMAlgo_WESScaler::Scale()const
71 {
72   return myScale;
73 }
74 //=======================================================================
75 // function: SetFace
76 // purpose:
77 //=======================================================================
78   void GEOMAlgo_WESScaler::SetFace(const TopoDS_Face& aF)
79 {
80   myFace=aF;
81 }
82 //=======================================================================
83 // function: Face
84 // purpose:
85 //=======================================================================
86   const TopoDS_Face& GEOMAlgo_WESScaler::Face()const
87 {
88   return myFace;
89 }
90 //=======================================================================
91 // function: SetEdges
92 // purpose:
93 //=======================================================================
94   void GEOMAlgo_WESScaler::SetEdges(const TopTools_ListOfShape& aLE)
95 {
96   myEdges=aLE;
97 }
98 //=======================================================================
99 // function: Edges
100 // purpose:
101 //=======================================================================
102   const TopTools_ListOfShape& GEOMAlgo_WESScaler::Edges()const
103 {
104   return myEdges;
105 }
106 //=======================================================================
107 // function: FaceScaled
108 // purpose:
109 //=======================================================================
110   const TopoDS_Face& GEOMAlgo_WESScaler::FaceScaled()const
111 {
112   return myFaceScaled;
113 }
114 //=======================================================================
115 // function: EdgesScaled
116 // purpose:
117 //=======================================================================
118   const TopTools_ListOfShape& GEOMAlgo_WESScaler::EdgesScaled()const
119 {
120   return myEdgesScaled;
121 }
122 //=======================================================================
123 // function: Image
124 // purpose:
125 //=======================================================================
126   const TopoDS_Shape& GEOMAlgo_WESScaler::Image (const TopoDS_Shape& aS) const
127 {
128   if (myImages.IsBound(aS)) {
129     return myImages.Find(aS);
130   }
131   return myShapeTmp;
132 }
133 //=======================================================================
134 // function: Origin
135 // purpose:
136 //=======================================================================
137   const TopoDS_Shape& GEOMAlgo_WESScaler::Origin (const TopoDS_Shape& aS) const
138 {
139   if (myOrigins.IsBound(aS)) {
140     return myOrigins.Find(aS);
141   }
142   return myShapeTmp;
143 }
144 //=======================================================================
145 // function: Images
146 // purpose:
147 //=======================================================================
148   const GEOMAlgo_DataMapOfOrientedShapeShape& GEOMAlgo_WESScaler::Images () const
149 {
150   return myImages;
151 }
152 //=======================================================================
153 // function: Origins
154 // purpose:
155 //=======================================================================
156   const GEOMAlgo_DataMapOfOrientedShapeShape& GEOMAlgo_WESScaler::Origins () const
157 {
158   return myOrigins;
159 }
160 //=======================================================================
161 // function: CheckData
162 // purpose:
163 //=======================================================================
164   void GEOMAlgo_WESScaler::CheckData()
165 {
166   myErrorStatus=0;
167   //
168   if(myFace.IsNull()) {
169     myErrorStatus=2;
170     return;
171   }
172   if(!myEdges.Extent()) {
173     myErrorStatus=3;
174     return;
175   }
176   if (myScale<=0.){
177     myErrorStatus=4;
178   }
179 }
180 //=======================================================================
181 // function: Perform
182 // purpose:
183 //=======================================================================
184   void GEOMAlgo_WESScaler::Perform()
185 {
186   Standard_Boolean bIsDone;
187   Standard_Integer i;
188   gp_Pnt aP;
189   gp_Trsf aTrsf;
190   TopAbs_Orientation aOr;
191   TopoDS_Shape aFC, aFR, aER;
192   TopoDS_Wire aWE;
193   TopoDS_Iterator aItS;
194   BRep_Builder aBB;
195   TopTools_ListIteratorOfListOfShape aIt;
196   //
197   // 0. CheckData
198   CheckData();
199   if(myErrorStatus) {
200     return;
201   }
202   //
203   myImages.Clear();
204   myOrigins.Clear();
205   myEdgesScaled.Clear();
206   //
207   // 1. aFC
208   aFC=myFace.EmptyCopied();
209   //
210   aBB.MakeWire(aWE);
211   aIt.Initialize(myEdges);
212   for (; aIt.More(); aIt.Next()) {
213     const TopoDS_Shape& aE=aIt.Value();
214     aBB.Add(aWE, aE);
215   }
216   aBB.Add(aFC, aWE);
217   //
218   aItS.Initialize(myFace);
219   for (; aItS.More(); aItS.Next()) {
220     const TopoDS_Shape& aW=aItS.Value();
221     aBB.Add(aFC, aW);
222   }
223   //
224   // 2. Scale aFC
225   aP.SetCoord(0.,0.,0.);
226   aTrsf.SetScale(aP, myScale);
227   //
228   BRepBuilderAPI_Transform aBT(aTrsf);
229   aBT.Perform(aFC);
230   bIsDone=aBT.IsDone();
231   if (!bIsDone) {
232     myErrorStatus=10;
233     return;
234   }
235   //
236   const TopoDS_Shape& aSR=aBT.Shape();
237   //
238   // Refined image face FR
239   aFR=aSR.EmptyCopied();
240   aItS.Initialize(aSR);
241   for (i=0; aItS.More(); aItS.Next(),++i) {
242     const TopoDS_Shape& aWR=aItS.Value();
243     if (i) {
244       aBB.Add(aFR, aWR);
245     }
246   }
247   myFaceScaled=*((TopoDS_Face*)&aFR);
248   //
249   // 3. Fill Images, Origins, EdgesScaled
250   aIt.Initialize(myEdges);
251   for (; aIt.More(); aIt.Next()) {
252     const TopoDS_Shape& aE=aIt.Value();
253     aOr=aE.Orientation();
254     //
255     aER=aBT.ModifiedShape(aE);
256     if(aER.IsNull()) {
257       myErrorStatus=11;
258       return;
259     }
260     //
261     aER.Orientation(aOr);
262     myImages.Bind(aE, aER);
263     myOrigins.Bind(aER, aE);
264     //
265     myEdgesScaled.Append(aER);
266   }
267 }