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;
68 //=======================================================================
71 //=======================================================================
72 HYDROData_Transform::~HYDROData_Transform()
76 //=======================================================================
79 //=======================================================================
80 void HYDROData_Transform::Clear()
97 BOPAlgo_BuilderShape::PrepareHistory();
99 //=======================================================================
100 //function : SetArgument
102 //=======================================================================
103 void HYDROData_Transform::SetArgument(const TopoDS_Shape& theShape)
107 //=======================================================================
108 //function : AddArgument
110 //=======================================================================
111 const TopoDS_Shape& HYDROData_Transform::Argument()const
115 //=======================================================================
116 //function : SetTreshold
118 //=======================================================================
119 void HYDROData_Transform::SetTreshold(const Standard_Real theTreshold)
121 myTreshold=theTreshold;
123 //=======================================================================
124 //function : Treshold
126 //=======================================================================
127 Standard_Real HYDROData_Transform::Treshold()const
131 //=======================================================================
132 //function : SetToTransform
134 //=======================================================================
135 void HYDROData_Transform::SetToTransform(const Standard_Boolean theFlag)
137 myToTransform=theFlag;
139 //=======================================================================
140 //function : ToTransform
142 //=======================================================================
143 Standard_Boolean HYDROData_Transform::ToTransform()const
145 return myToTransform;
147 //=======================================================================
148 //function : CheckData
150 //=======================================================================
151 void HYDROData_Transform::CheckData()
153 if(myArgument.IsNull()) {
157 //=======================================================================
160 //=======================================================================
161 void HYDROData_Transform::Prepare()
169 //=======================================================================
172 //=======================================================================
173 void HYDROData_Transform::Perform()
204 //=======================================================================
207 //=======================================================================
208 void HYDROData_Transform::Detect()
210 Standard_Real aXmin, aYmin, aZmin, aXmax, aYmax, aZmax;
211 Standard_Real aXc, aYc, aZc;
217 BRepBndLib::Add(myArgument, aBox);
219 aBox.Get(aXmin, aYmin, aZmin, aXmax, aYmax, aZmax);
221 aXc=0.5*(aXmin+aXmax);
222 aYc=0.5*(aYmin+aYmax);
223 aZc=0.5*(aZmin+aZmax);
224 //printf(" aVc : { %lf %lf %lf }\n", aXc, aYc, aZc);
226 myToTransform=Standard_False;
227 if (fabs(aXc)>myTreshold ||
228 fabs(aYc)>myTreshold ||
229 fabs(aZc)>myTreshold) {
230 myToTransform=!myToTransform;
233 aVec.SetCoord(-aXc, -aYc, -aZc);
234 myTrsf1.SetTranslation(aVec);
236 aVec.SetCoord(aXc, aYc, aZc);
237 myTrsf2.SetTranslation(aVec);
239 //=======================================================================
240 //function : ComputeTrsf
242 //=======================================================================
243 void HYDROData_Transform::ComputeTrsf()
245 if (!myToTransform) {
252 //=======================================================================
253 //function : Transform1
255 //=======================================================================
256 void HYDROData_Transform::Transform1()
260 if (myToTransform) {//pkv ft
261 Standard_Boolean bIsDone;
265 myTransform1=new BRepBuilderAPI_Transform(myTrsf1);
267 myTransform1->Perform(myArgument);
268 bIsDone=myTransform1->IsDone();
274 //=======================================================================
275 //function : BuildFuse
277 //=======================================================================
278 void HYDROData_Transform::BuildFuse()
280 Standard_Integer iErr;
282 BOPCol_ListOfShape aLC;
283 BOPAlgo_PaveFiller aPF;
287 //modified by NIZNHY-PKV Wed Jan 15 13:24:48 2014f
288 const TopoDS_Shape& aS1=
289 (myToTransform)? myTransform1->Shape() : myArgument;
290 //const TopoDS_Shape& aS1=()Transform1->Shape();
291 //modified by NIZNHY-PKV Wed Jan 15 13:24:52 2014t
293 #ifdef DEB_SPLIT_TO_ZONES_CHECK_PARTITION
294 TCollection_AsciiString aNameBefore = fileNameAfter + ".brep";
295 BRepTools::Write(aS1, aNameBefore.ToCString());
299 for (; aIt.More(); aIt.Next()) {
300 const TopoDS_Shape& aS1x=aIt.Value();
304 aPF.SetArguments(aLC);
307 iErr=aPF.ErrorStatus();
313 myBuilder=new BOPAlgo_Builder;
316 for (; aIt.More(); aIt.Next()) {
317 const TopoDS_Shape& aS1x=aIt.Value();
318 myBuilder->AddArgument(aS1x);
321 myBuilder->PerformWithFiller(aPF);
322 iErr=myBuilder->ErrorStatus();
328 //=======================================================================
329 //function : Transform2
331 //=======================================================================
332 void HYDROData_Transform::Transform2()
336 const TopoDS_Shape& aR1=myBuilder->Shape();
338 myShape=aR1; //pkv ft
339 if (myToTransform) { //pkv ft
340 Standard_Boolean bIsDone;
342 myTransform2=new BRepBuilderAPI_Transform(myTrsf2);
344 myTransform2->Perform(aR1);
345 bIsDone=myTransform2->IsDone();
351 const TopoDS_Shape& aR2=myTransform2->Shape();
357 //=======================================================================
358 //function : Modified
360 //=======================================================================
361 const TopTools_ListOfShape& HYDROData_Transform::Modified
362 (const TopoDS_Shape& aS)
364 TopTools_ListOfShape* pHistShapes;
365 TopTools_ListIteratorOfListOfShape aItLS;
367 pHistShapes=(TopTools_ListOfShape*)&myHistShapes;
368 pHistShapes->Clear();
370 if (myToTransform) { //pkv ft
371 const TopTools_ListOfShape& aLS1=myTransform1->Modified(aS);
372 const TopoDS_Shape& aS1=aLS1.First();
374 const TopTools_ListOfShape& aLS1B=myBuilder->Modified(aS1);
376 if (aLS1B.IsEmpty()) { //pkv ft
377 const TopTools_ListOfShape& aLS2B=myTransform2->Modified(aS1);
378 const TopoDS_Shape& aS2B=aLS2B.First();
379 pHistShapes->Append(aS2B);
382 aItLS.Initialize(aLS1B);
383 for (; aItLS.More(); aItLS.Next()) {
384 const TopoDS_Shape& aS1B=aItLS.Value();
385 const TopTools_ListOfShape& aLS2B=myTransform2->Modified(aS1B);
386 const TopoDS_Shape& aS2B=aLS2B.First();
387 pHistShapes->Append(aS2B);
392 const TopTools_ListOfShape& aLS1B=myBuilder->Modified(aS);
393 aItLS.Initialize(aLS1B);
394 for (; aItLS.More(); aItLS.Next()) {
395 const TopoDS_Shape& aS1B=aItLS.Value();
396 pHistShapes->Append(aS1B);
402 //=======================================================================
403 //function : Generated
405 //=======================================================================
406 const TopTools_ListOfShape& HYDROData_Transform::Generated
407 (const TopoDS_Shape& aS)
409 TopTools_ListOfShape* pHistShapes;
410 TopTools_ListIteratorOfListOfShape aItLS;
412 pHistShapes=(TopTools_ListOfShape*)&myHistShapes;
413 pHistShapes->Clear();
415 if (myToTransform) { //pkv ft
416 const TopTools_ListOfShape& aLS1=myTransform1->Modified(aS);
417 const TopoDS_Shape& aS1=aLS1.First();
419 const TopTools_ListOfShape& aLS1B=myBuilder->Generated(aS1);
420 if (aLS1B.IsEmpty()) { //pkv ft
421 const TopTools_ListOfShape& aLS2B=myTransform2->Modified(aS1);
422 const TopoDS_Shape& aS2B=aLS2B.First();
423 pHistShapes->Append(aS2B);
426 aItLS.Initialize(aLS1B);
427 for (; aItLS.More(); aItLS.Next()) {
428 const TopoDS_Shape& aS1B=aItLS.Value();
429 const TopTools_ListOfShape& aLS2B=myTransform2->Modified(aS1B);
430 const TopoDS_Shape& aS2B=aLS2B.First();
431 pHistShapes->Append(aS2B);
436 const TopTools_ListOfShape& aLS1B=myBuilder->Generated(aS);
437 aItLS.Initialize(aLS1B);
438 for (; aItLS.More(); aItLS.Next()) {
439 const TopoDS_Shape& aS1B=aItLS.Value();
440 pHistShapes->Append(aS1B);
446 //=======================================================================
447 //function : IsDeleted
449 //=======================================================================
450 Standard_Boolean HYDROData_Transform::IsDeleted(const TopoDS_Shape& aS)
452 Standard_Boolean bIsDeleted;
454 if (myToTransform) { //pkv ft
455 const TopTools_ListOfShape& aLS1=myTransform1->Modified(aS);
456 const TopoDS_Shape& aS1=aLS1.First();
458 bIsDeleted=myBuilder->IsDeleted(aS1);
461 bIsDeleted=myBuilder->IsDeleted(aS);
466 //=======================================================================
467 //function : HasDeleted
469 //=======================================================================
470 Standard_Boolean HYDROData_Transform::HasDeleted()
472 return myBuilder->HasDeleted();
474 //=======================================================================
475 //function : HasGenerated
477 //=======================================================================
478 Standard_Boolean HYDROData_Transform::HasGenerated()
480 return myBuilder->HasGenerated();
482 //=======================================================================
483 //function : HasModified
485 //=======================================================================
486 Standard_Boolean HYDROData_Transform::HasModified()
488 return myBuilder->HasModified();