1 #include <HYDROData_Transform.h>
8 #include <TopoDS_Shape.hxx>
9 #include <TopoDS_Iterator.hxx>
11 #include <BRepBndLib.hxx>
13 #include <TopTools_ListIteratorOfListOfShape.hxx>
15 #include <BOPCol_ListOfShape.hxx>
16 #include <BOPCol_MapOfShape.hxx>
18 #include <BOPCol_ListOfShape.hxx>
20 #include <BOPAlgo_BuilderShape.hxx>
21 #include <BOPAlgo_PaveFiller.hxx>
23 //#define DEB_SPLIT_TO_ZONES_CHECK_PARTITION 1
24 #ifdef DEB_SPLIT_TO_ZONES_CHECK_PARTITION
25 #include <BRepTools.hxx>
26 #include <TCollection_AsciiString.hxx>
27 static TCollection_AsciiString fileNameAfter("AfterTranslation");
30 void HYDROData_Transform::SetFileName(const TCollection_AsciiString& theNameAfter)
32 #ifdef DEB_SPLIT_TO_ZONES_CHECK_PARTITION
33 fileNameAfter = theNameAfter;
36 //=======================================================================
37 //function : HYDROData_Transform
39 //=======================================================================
40 HYDROData_Transform::HYDROData_Transform()
42 BOPAlgo_BuilderShape()
44 myToTransform=Standard_False;
50 //=======================================================================
53 //=======================================================================
54 HYDROData_Transform::~HYDROData_Transform()
58 //=======================================================================
61 //=======================================================================
62 void HYDROData_Transform::Clear()
79 BOPAlgo_BuilderShape::PrepareHistory();
81 //=======================================================================
82 //function : SetArgument
84 //=======================================================================
85 void HYDROData_Transform::SetArgument(const TopoDS_Shape& theShape)
89 //=======================================================================
90 //function : AddArgument
92 //=======================================================================
93 const TopoDS_Shape& HYDROData_Transform::Argument()const
97 //=======================================================================
98 //function : SetTreshold
100 //=======================================================================
101 void HYDROData_Transform::SetTreshold(const Standard_Real theTreshold)
103 myTreshold=theTreshold;
105 //=======================================================================
106 //function : Treshold
108 //=======================================================================
109 Standard_Real HYDROData_Transform::Treshold()const
113 //=======================================================================
114 //function : SetToTransform
116 //=======================================================================
117 void HYDROData_Transform::SetToTransform(const Standard_Boolean theFlag)
119 myToTransform=theFlag;
121 //=======================================================================
122 //function : ToTransform
124 //=======================================================================
125 Standard_Boolean HYDROData_Transform::ToTransform()const
127 return myToTransform;
129 //=======================================================================
130 //function : CheckData
132 //=======================================================================
133 void HYDROData_Transform::CheckData()
135 if(myArgument.IsNull()) {
139 //=======================================================================
142 //=======================================================================
143 void HYDROData_Transform::Prepare()
151 //=======================================================================
154 //=======================================================================
155 void HYDROData_Transform::Perform()
186 //=======================================================================
189 //=======================================================================
190 void HYDROData_Transform::Detect()
192 Standard_Real aXmin, aYmin, aZmin, aXmax, aYmax, aZmax;
193 Standard_Real aXc, aYc, aZc;
199 BRepBndLib::Add(myArgument, aBox);
201 aBox.Get(aXmin, aYmin, aZmin, aXmax, aYmax, aZmax);
203 aXc=0.5*(aXmin+aXmax);
204 aYc=0.5*(aYmin+aYmax);
205 aZc=0.5*(aZmin+aZmax);
206 //printf(" aVc : { %lf %lf %lf }\n", aXc, aYc, aZc);
208 myToTransform=Standard_False;
209 if (fabs(aXc)>myTreshold ||
210 fabs(aYc)>myTreshold ||
211 fabs(aZc)>myTreshold) {
212 myToTransform=!myToTransform;
215 aVec.SetCoord(-aXc, -aYc, -aZc);
216 myTrsf1.SetTranslation(aVec);
218 aVec.SetCoord(aXc, aYc, aZc);
219 myTrsf2.SetTranslation(aVec);
221 //=======================================================================
222 //function : ComputeTrsf
224 //=======================================================================
225 void HYDROData_Transform::ComputeTrsf()
227 if (!myToTransform) {
234 //=======================================================================
235 //function : Transform1
237 //=======================================================================
238 void HYDROData_Transform::Transform1()
242 if (myToTransform) {//pkv ft
243 Standard_Boolean bIsDone;
247 myTransform1=new BRepBuilderAPI_Transform(myTrsf1);
249 myTransform1->Perform(myArgument);
250 bIsDone=myTransform1->IsDone();
256 //=======================================================================
257 //function : BuildFuse
259 //=======================================================================
260 void HYDROData_Transform::BuildFuse()
262 Standard_Integer iErr;
264 BOPCol_ListOfShape aLC;
265 BOPAlgo_PaveFiller aPF;
269 //modified by NIZNHY-PKV Wed Jan 15 13:24:48 2014f
270 const TopoDS_Shape& aS1=
271 (myToTransform)? myTransform1->Shape() : myArgument;
272 //const TopoDS_Shape& aS1=()Transform1->Shape();
273 //modified by NIZNHY-PKV Wed Jan 15 13:24:52 2014t
275 #ifdef DEB_SPLIT_TO_ZONES_CHECK_PARTITION
276 TCollection_AsciiString aNameBefore = fileNameAfter + ".brep";
277 BRepTools::Write(aS1, aNameBefore.ToCString());
281 for (; aIt.More(); aIt.Next()) {
282 const TopoDS_Shape& aS1x=aIt.Value();
286 aPF.SetArguments(aLC);
289 iErr=aPF.ErrorStatus();
295 myBuilder=new BOPAlgo_Builder;
298 for (; aIt.More(); aIt.Next()) {
299 const TopoDS_Shape& aS1x=aIt.Value();
300 myBuilder->AddArgument(aS1x);
303 myBuilder->PerformWithFiller(aPF);
304 iErr=myBuilder->ErrorStatus();
310 //=======================================================================
311 //function : Transform2
313 //=======================================================================
314 void HYDROData_Transform::Transform2()
318 const TopoDS_Shape& aR1=myBuilder->Shape();
320 myShape=aR1; //pkv ft
321 if (myToTransform) { //pkv ft
322 Standard_Boolean bIsDone;
324 myTransform2=new BRepBuilderAPI_Transform(myTrsf2);
326 myTransform2->Perform(aR1);
327 bIsDone=myTransform2->IsDone();
333 const TopoDS_Shape& aR2=myTransform2->Shape();
339 //=======================================================================
340 //function : Modified
342 //=======================================================================
343 const TopTools_ListOfShape& HYDROData_Transform::Modified
344 (const TopoDS_Shape& aS)
346 TopTools_ListOfShape* pHistShapes;
347 TopTools_ListIteratorOfListOfShape aItLS;
349 pHistShapes=(TopTools_ListOfShape*)&myHistShapes;
350 pHistShapes->Clear();
352 if (myToTransform) { //pkv ft
353 const TopTools_ListOfShape& aLS1=myTransform1->Modified(aS);
354 const TopoDS_Shape& aS1=aLS1.First();
356 const TopTools_ListOfShape& aLS1B=myBuilder->Modified(aS1);
358 if (aLS1B.IsEmpty()) { //pkv ft
359 const TopTools_ListOfShape& aLS2B=myTransform2->Modified(aS1);
360 const TopoDS_Shape& aS2B=aLS2B.First();
361 pHistShapes->Append(aS2B);
364 aItLS.Initialize(aLS1B);
365 for (; aItLS.More(); aItLS.Next()) {
366 const TopoDS_Shape& aS1B=aItLS.Value();
367 const TopTools_ListOfShape& aLS2B=myTransform2->Modified(aS1B);
368 const TopoDS_Shape& aS2B=aLS2B.First();
369 pHistShapes->Append(aS2B);
374 const TopTools_ListOfShape& aLS1B=myBuilder->Modified(aS);
375 aItLS.Initialize(aLS1B);
376 for (; aItLS.More(); aItLS.Next()) {
377 const TopoDS_Shape& aS1B=aItLS.Value();
378 pHistShapes->Append(aS1B);
384 //=======================================================================
385 //function : Generated
387 //=======================================================================
388 const TopTools_ListOfShape& HYDROData_Transform::Generated
389 (const TopoDS_Shape& aS)
391 TopTools_ListOfShape* pHistShapes;
392 TopTools_ListIteratorOfListOfShape aItLS;
394 pHistShapes=(TopTools_ListOfShape*)&myHistShapes;
395 pHistShapes->Clear();
397 if (myToTransform) { //pkv ft
398 const TopTools_ListOfShape& aLS1=myTransform1->Modified(aS);
399 const TopoDS_Shape& aS1=aLS1.First();
401 const TopTools_ListOfShape& aLS1B=myBuilder->Generated(aS1);
402 if (aLS1B.IsEmpty()) { //pkv ft
403 const TopTools_ListOfShape& aLS2B=myTransform2->Modified(aS1);
404 const TopoDS_Shape& aS2B=aLS2B.First();
405 pHistShapes->Append(aS2B);
408 aItLS.Initialize(aLS1B);
409 for (; aItLS.More(); aItLS.Next()) {
410 const TopoDS_Shape& aS1B=aItLS.Value();
411 const TopTools_ListOfShape& aLS2B=myTransform2->Modified(aS1B);
412 const TopoDS_Shape& aS2B=aLS2B.First();
413 pHistShapes->Append(aS2B);
418 const TopTools_ListOfShape& aLS1B=myBuilder->Generated(aS);
419 aItLS.Initialize(aLS1B);
420 for (; aItLS.More(); aItLS.Next()) {
421 const TopoDS_Shape& aS1B=aItLS.Value();
422 pHistShapes->Append(aS1B);
428 //=======================================================================
429 //function : IsDeleted
431 //=======================================================================
432 Standard_Boolean HYDROData_Transform::IsDeleted(const TopoDS_Shape& aS)
434 Standard_Boolean bIsDeleted;
436 if (myToTransform) { //pkv ft
437 const TopTools_ListOfShape& aLS1=myTransform1->Modified(aS);
438 const TopoDS_Shape& aS1=aLS1.First();
440 bIsDeleted=myBuilder->IsDeleted(aS1);
443 bIsDeleted=myBuilder->IsDeleted(aS);
448 //=======================================================================
449 //function : HasDeleted
451 //=======================================================================
452 Standard_Boolean HYDROData_Transform::HasDeleted()
454 return myBuilder->HasDeleted();
456 //=======================================================================
457 //function : HasGenerated
459 //=======================================================================
460 Standard_Boolean HYDROData_Transform::HasGenerated()
462 return myBuilder->HasGenerated();
464 //=======================================================================
465 //function : HasModified
467 //=======================================================================
468 Standard_Boolean HYDROData_Transform::HasModified()
470 return myBuilder->HasModified();