1 // Copyright (C) 2014-2015 EDF-R&D
2 // This library is free software; you can redistribute it and/or
3 // modify it under the terms of the GNU Lesser General Public
4 // License as published by the Free Software Foundation; either
5 // version 2.1 of the License, or (at your option) any later version.
7 // This library is distributed in the hope that it will be useful,
8 // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10 // Lesser General Public License for more details.
12 // You should have received a copy of the GNU Lesser General Public
13 // License along with this library; if not, write to the Free Software
14 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #include <HYDROData_Transform.h>
23 #include <Bnd_Box.hxx>
26 #include <TopoDS_Shape.hxx>
27 #include <TopoDS_Iterator.hxx>
29 #include <BRepBndLib.hxx>
31 #include <TopTools_ListIteratorOfListOfShape.hxx>
33 #include <BOPCol_ListOfShape.hxx>
34 #include <BOPCol_MapOfShape.hxx>
36 #include <BOPCol_ListOfShape.hxx>
38 #include <BOPAlgo_BuilderShape.hxx>
39 #include <BOPAlgo_PaveFiller.hxx>
41 //#define DEB_SPLIT_TO_ZONES_CHECK_PARTITION 1
42 #ifdef DEB_SPLIT_TO_ZONES_CHECK_PARTITION
43 #include <BRepTools.hxx>
44 #include <TCollection_AsciiString.hxx>
45 static TCollection_AsciiString fileNameAfter("AfterTranslation");
48 void HYDROData_Transform::SetFileName(const TCollection_AsciiString& theNameAfter)
50 #ifdef DEB_SPLIT_TO_ZONES_CHECK_PARTITION
51 fileNameAfter = theNameAfter;
54 //=======================================================================
55 //function : HYDROData_Transform
57 //=======================================================================
58 HYDROData_Transform::HYDROData_Transform()
60 BOPAlgo_BuilderShape()
62 myToTransform=Standard_False;
70 //=======================================================================
73 //=======================================================================
74 HYDROData_Transform::~HYDROData_Transform()
78 //=======================================================================
81 //=======================================================================
82 void HYDROData_Transform::Clear()
99 BOPAlgo_BuilderShape::PrepareHistory();
101 //=======================================================================
102 //function : SetArgument
104 //=======================================================================
105 void HYDROData_Transform::SetArgument(const TopoDS_Shape& theShape)
109 //=======================================================================
110 //function : AddArgument
112 //=======================================================================
113 const TopoDS_Shape& HYDROData_Transform::Argument()const
117 //=======================================================================
118 //function : SetTreshold
120 //=======================================================================
121 void HYDROData_Transform::SetTreshold(const Standard_Real theTreshold)
123 myTreshold=theTreshold;
125 //=======================================================================
126 //function : Treshold
128 //=======================================================================
129 Standard_Real HYDROData_Transform::Treshold()const
133 //=======================================================================
134 //function : SetToTransform
136 //=======================================================================
137 void HYDROData_Transform::SetToTransform(const Standard_Boolean theFlag)
139 myToTransform=theFlag;
141 //=======================================================================
142 //function : ToTransform
144 //=======================================================================
145 Standard_Boolean HYDROData_Transform::ToTransform()const
147 return myToTransform;
149 //=======================================================================
150 //function : CheckData
152 //=======================================================================
153 void HYDROData_Transform::CheckData()
155 if(myArgument.IsNull()) {
159 //=======================================================================
162 //=======================================================================
163 void HYDROData_Transform::Prepare()
171 //=======================================================================
174 //=======================================================================
175 void HYDROData_Transform::Perform()
206 //=======================================================================
209 //=======================================================================
210 void HYDROData_Transform::Detect()
212 Standard_Real aXmin, aYmin, aZmin, aXmax, aYmax, aZmax;
213 Standard_Real aXc, aYc, aZc;
219 BRepBndLib::Add(myArgument, aBox);
221 aBox.Get(aXmin, aYmin, aZmin, aXmax, aYmax, aZmax);
223 aXc=0.5*(aXmin+aXmax);
224 aYc=0.5*(aYmin+aYmax);
225 aZc=0.5*(aZmin+aZmax);
226 //printf(" aVc : { %lf %lf %lf }\n", aXc, aYc, aZc);
228 myToTransform=Standard_False;
229 if (fabs(aXc)>myTreshold ||
230 fabs(aYc)>myTreshold ||
231 fabs(aZc)>myTreshold) {
232 myToTransform=!myToTransform;
235 aVec.SetCoord(-aXc, -aYc, -aZc);
236 myTrsf1.SetTranslation(aVec);
238 aVec.SetCoord(aXc, aYc, aZc);
239 myTrsf2.SetTranslation(aVec);
241 //=======================================================================
242 //function : ComputeTrsf
244 //=======================================================================
245 void HYDROData_Transform::ComputeTrsf()
247 if (!myToTransform) {
254 //=======================================================================
255 //function : Transform1
257 //=======================================================================
258 void HYDROData_Transform::Transform1()
262 if (myToTransform) {//pkv ft
263 Standard_Boolean bIsDone;
267 myTransform1=new BRepBuilderAPI_Transform(myTrsf1);
269 myTransform1->Perform(myArgument);
270 bIsDone=myTransform1->IsDone();
276 //=======================================================================
277 //function : BuildFuse
279 //=======================================================================
280 void HYDROData_Transform::BuildFuse()
282 Standard_Integer iErr;
284 BOPCol_ListOfShape aLC;
285 BOPAlgo_PaveFiller aPF;
289 //modified by NIZNHY-PKV Wed Jan 15 13:24:48 2014f
290 const TopoDS_Shape& aS1=
291 (myToTransform)? myTransform1->Shape() : myArgument;
292 //const TopoDS_Shape& aS1=()Transform1->Shape();
293 //modified by NIZNHY-PKV Wed Jan 15 13:24:52 2014t
295 #ifdef DEB_SPLIT_TO_ZONES_CHECK_PARTITION
296 TCollection_AsciiString aNameBefore = fileNameAfter + ".brep";
297 BRepTools::Write(aS1, aNameBefore.ToCString());
301 for (; aIt.More(); aIt.Next()) {
302 const TopoDS_Shape& aS1x=aIt.Value();
306 aPF.SetArguments(aLC);
315 myBuilder=new BOPAlgo_Builder;
318 for (; aIt.More(); aIt.Next()) {
319 const TopoDS_Shape& aS1x=aIt.Value();
320 myBuilder->AddArgument(aS1x);
323 myBuilder->PerformWithFiller(aPF);
324 if (myBuilder->HasErrors())
330 //=======================================================================
331 //function : Transform2
333 //=======================================================================
334 void HYDROData_Transform::Transform2()
338 const TopoDS_Shape& aR1=myBuilder->Shape();
340 myShape=aR1; //pkv ft
341 if (myToTransform) { //pkv ft
342 Standard_Boolean bIsDone;
344 myTransform2=new BRepBuilderAPI_Transform(myTrsf2);
346 myTransform2->Perform(aR1);
347 bIsDone=myTransform2->IsDone();
353 const TopoDS_Shape& aR2=myTransform2->Shape();
359 //=======================================================================
360 //function : Modified
362 //=======================================================================
363 const TopTools_ListOfShape& HYDROData_Transform::Modified
364 (const TopoDS_Shape& aS)
366 TopTools_ListOfShape* pHistShapes;
367 TopTools_ListIteratorOfListOfShape aItLS;
369 pHistShapes=(TopTools_ListOfShape*)&myHistShapes;
370 pHistShapes->Clear();
372 if (myToTransform) { //pkv ft
373 const TopTools_ListOfShape& aLS1=myTransform1->Modified(aS);
374 const TopoDS_Shape& aS1=aLS1.First();
376 const TopTools_ListOfShape& aLS1B=myBuilder->Modified(aS1);
378 if (aLS1B.IsEmpty()) { //pkv ft
379 const TopTools_ListOfShape& aLS2B=myTransform2->Modified(aS1);
380 const TopoDS_Shape& aS2B=aLS2B.First();
381 pHistShapes->Append(aS2B);
384 aItLS.Initialize(aLS1B);
385 for (; aItLS.More(); aItLS.Next()) {
386 const TopoDS_Shape& aS1B=aItLS.Value();
387 const TopTools_ListOfShape& aLS2B=myTransform2->Modified(aS1B);
388 const TopoDS_Shape& aS2B=aLS2B.First();
389 pHistShapes->Append(aS2B);
394 const TopTools_ListOfShape& aLS1B=myBuilder->Modified(aS);
395 aItLS.Initialize(aLS1B);
396 for (; aItLS.More(); aItLS.Next()) {
397 const TopoDS_Shape& aS1B=aItLS.Value();
398 pHistShapes->Append(aS1B);
404 //=======================================================================
405 //function : Generated
407 //=======================================================================
408 const TopTools_ListOfShape& HYDROData_Transform::Generated
409 (const TopoDS_Shape& aS)
411 TopTools_ListOfShape* pHistShapes;
412 TopTools_ListIteratorOfListOfShape aItLS;
414 pHistShapes=(TopTools_ListOfShape*)&myHistShapes;
415 pHistShapes->Clear();
417 if (myToTransform) { //pkv ft
418 const TopTools_ListOfShape& aLS1=myTransform1->Modified(aS);
419 const TopoDS_Shape& aS1=aLS1.First();
421 const TopTools_ListOfShape& aLS1B=myBuilder->Generated(aS1);
422 if (aLS1B.IsEmpty()) { //pkv ft
423 const TopTools_ListOfShape& aLS2B=myTransform2->Modified(aS1);
424 const TopoDS_Shape& aS2B=aLS2B.First();
425 pHistShapes->Append(aS2B);
428 aItLS.Initialize(aLS1B);
429 for (; aItLS.More(); aItLS.Next()) {
430 const TopoDS_Shape& aS1B=aItLS.Value();
431 const TopTools_ListOfShape& aLS2B=myTransform2->Modified(aS1B);
432 const TopoDS_Shape& aS2B=aLS2B.First();
433 pHistShapes->Append(aS2B);
438 const TopTools_ListOfShape& aLS1B=myBuilder->Generated(aS);
439 aItLS.Initialize(aLS1B);
440 for (; aItLS.More(); aItLS.Next()) {
441 const TopoDS_Shape& aS1B=aItLS.Value();
442 pHistShapes->Append(aS1B);
448 //=======================================================================
449 //function : IsDeleted
451 //=======================================================================
452 Standard_Boolean HYDROData_Transform::IsDeleted(const TopoDS_Shape& aS)
454 Standard_Boolean bIsDeleted;
456 if (myToTransform) { //pkv ft
457 const TopTools_ListOfShape& aLS1=myTransform1->Modified(aS);
458 const TopoDS_Shape& aS1=aLS1.First();
460 bIsDeleted=myBuilder->IsDeleted(aS1);
463 bIsDeleted=myBuilder->IsDeleted(aS);
468 //=======================================================================
469 //function : HasDeleted
471 //=======================================================================
472 Standard_Boolean HYDROData_Transform::HasDeleted()
474 return myBuilder->HasDeleted();
476 //=======================================================================
477 //function : HasGenerated
479 //=======================================================================
480 Standard_Boolean HYDROData_Transform::HasGenerated()
482 return myBuilder->HasGenerated();
484 //=======================================================================
485 //function : HasModified
487 //=======================================================================
488 Standard_Boolean HYDROData_Transform::HasModified()
490 return myBuilder->HasModified();