2 #include "HYDROData_CalculationCase.h"
4 #include "HYDROData_ArtificialObject.h"
5 #include "HYDROData_IAltitudeObject.h"
6 #include "HYDROData_Document.h"
7 #include "HYDROData_ShapesGroup.h"
8 #include "HYDROData_Iterator.h"
9 #include "HYDROData_NaturalObject.h"
10 #include "HYDROData_PolylineXY.h"
11 #include "HYDROData_SplitToZonesTool.h"
12 #include "HYDROData_SplittedShapesGroup.h"
13 #include "HYDROData_Region.h"
14 #include "HYDROData_Tool.h"
15 #include "HYDROData_Zone.h"
22 #include <TopoDS_Shell.hxx>
23 #include <TopoDS_Edge.hxx>
25 #include <BRep_Builder.hxx>
26 #include <BRepBuilderAPI_Sewing.hxx>
27 #include <BRepTopAdaptor_FClass2d.hxx>
29 #include <BRepTools.hxx>
32 #include <TopExp_Explorer.hxx>
34 #include <TopTools_ListOfShape.hxx>
35 #include <TopTools_ListIteratorOfListOfShape.hxx>
37 //#define DEB_CALCULATION 1
38 #ifdef DEB_CALCULATION
39 #include <BRepTools.hxx>
40 #include <TopLoc_Location.hxx>
42 #define CALCULATION_REGIONS_PREF GetName() + "_Reg"
43 #define CALCULATION_ZONES_PREF GetName() + "_Zone"
44 #define CALCULATION_GROUPS_PREF GetName() + "_"
45 //#define DEB_CLASS2D 1
47 #include <BRepBuilderAPI_MakeVertex.hxx>
50 #define EXPORT_NAME "HYDRO_" + GetName()
53 #include "HYDRO_trace.hxx"
55 IMPLEMENT_STANDARD_HANDLE(HYDROData_CalculationCase, HYDROData_Entity)
56 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_CalculationCase, HYDROData_Entity)
58 HYDROData_CalculationCase::HYDROData_CalculationCase()
63 HYDROData_CalculationCase::~HYDROData_CalculationCase()
67 void HYDROData_CalculationCase::SetName( const QString& theName )
69 QString anOldCaseName = GetName();
70 if ( anOldCaseName != theName )
72 HYDROData_SequenceOfObjects aRegions = GetRegions();
74 HYDROData_SequenceOfObjects::Iterator anIter( aRegions );
75 for ( ; anIter.More(); anIter.Next() )
77 Handle(HYDROData_Region) aRegion =
78 Handle(HYDROData_Region)::DownCast( anIter.Value() );
79 if ( aRegion.IsNull() )
82 HYDROData_Tool::UpdateChildObjectName( anOldCaseName, theName, aRegion );
84 HYDROData_SequenceOfObjects aZones = aRegion->GetZones();
85 HYDROData_SequenceOfObjects::Iterator anIter( aZones );
86 for ( ; anIter.More(); anIter.Next() )
88 Handle(HYDROData_Zone) aRegZone =
89 Handle(HYDROData_Zone)::DownCast( anIter.Value() );
90 if ( aRegZone.IsNull() )
93 HYDROData_Tool::UpdateChildObjectName( anOldCaseName, theName, aRegZone );
97 HYDROData_SequenceOfObjects aGroups = GetSplittedGroups();
99 anIter.Init( aGroups );
100 for ( ; anIter.More(); anIter.Next() )
102 Handle(HYDROData_SplittedShapesGroup) aGroup =
103 Handle(HYDROData_SplittedShapesGroup)::DownCast( anIter.Value() );
104 if ( aGroup.IsNull() )
107 HYDROData_Tool::UpdateChildObjectName( anOldCaseName, theName, aGroup );
111 HYDROData_Entity::SetName( theName );
114 QStringList HYDROData_CalculationCase::DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const
116 QStringList aResList = dumpObjectCreation( theTreatedObjects );
118 QString aCalculName = GetObjPyName();
120 HYDROData_SequenceOfObjects aGeomObjects = GetGeometryObjects();
121 HYDROData_SequenceOfObjects::Iterator anIter( aGeomObjects );
122 for ( ; anIter.More(); anIter.Next() )
124 Handle(HYDROData_Object) aRefGeomObj =
125 Handle(HYDROData_Object)::DownCast( anIter.Value() );
126 setPythonReferenceObject( theTreatedObjects, aResList, aRefGeomObj, "AddGeometryObject" );
128 aResList << QString( "" );
130 QString aGroupName = HYDROData_Tool::GenerateNameForPython( theTreatedObjects, "case_geom_group" );
132 HYDROData_SequenceOfObjects aGeomGroups = GetGeometryGroups();
133 anIter.Init( aGeomGroups );
134 for ( ; anIter.More(); anIter.Next() )
136 Handle(HYDROData_ShapesGroup) aGeomGroup =
137 Handle(HYDROData_ShapesGroup)::DownCast( anIter.Value() );
138 if ( aGeomGroup.IsNull() )
141 Handle(HYDROData_Object) aFatherGeom =
142 Handle(HYDROData_Object)::DownCast( aGeomGroup->GetFatherObject() );
143 if ( aFatherGeom.IsNull() )
146 int aGroupId = aFatherGeom->GetGroupId( aGeomGroup );
147 aResList << QString( "%1 = %2.GetGroup( %3 );" )
148 .arg( aGroupName ).arg( aFatherGeom->GetObjPyName() ).arg( aGroupId );
150 aResList << QString( "%1.AddGeometryGroup( %2 );" ).arg( aCalculName ).arg( aGroupName );
152 aResList << QString( "" );
154 Handle(HYDROData_PolylineXY) aBoundaryPolyline = GetBoundaryPolyline();
155 setPythonReferenceObject( theTreatedObjects, aResList, aBoundaryPolyline, "SetBoundaryPolyline" );
156 aResList << QString( "" );
158 aResList << QString( "%1.Update();" ).arg( aCalculName );
159 aResList << QString( "" );
161 // Now we restore the regions and zones order
162 HYDROData_SequenceOfObjects aRegions = GetRegions();
163 anIter.Init( aRegions );
164 for ( ; anIter.More(); anIter.Next() )
166 Handle(HYDROData_Region) aRegion =
167 Handle(HYDROData_Region)::DownCast( anIter.Value() );
168 if ( aRegion.IsNull() )
171 QString aRegionName = aRegion->GetName();
173 HYDROData_SequenceOfObjects aZones = aRegion->GetZones();
174 HYDROData_SequenceOfObjects::Iterator aZonesIter( aZones );
175 for ( ; aZonesIter.More(); aZonesIter.Next() )
177 Handle(HYDROData_Zone) aRegZone =
178 Handle(HYDROData_Zone)::DownCast( aZonesIter.Value() );
179 if ( aRegZone.IsNull() )
185 aResList << QString( "" );
190 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetAllReferenceObjects() const
192 HYDROData_SequenceOfObjects aResSeq = HYDROData_Entity::GetAllReferenceObjects();
194 Handle(HYDROData_PolylineXY) aBoundaryPolyline = GetBoundaryPolyline();
195 if ( !aBoundaryPolyline.IsNull() )
196 aResSeq.Append( aBoundaryPolyline );
198 HYDROData_SequenceOfObjects aSeqOfRegions = GetRegions();
199 aResSeq.Append( aSeqOfRegions );
204 void HYDROData_CalculationCase::Update()
206 HYDROData_Entity::Update();
208 // At first we remove previously created objects
210 RemoveSplittedGroups();
212 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
213 if ( aDocument.IsNull() )
216 Handle(HYDROData_PolylineXY) aBoundaryPolyline = GetBoundaryPolyline();
217 HYDROData_SequenceOfObjects aGeomObjects = GetGeometryObjects();
218 if ( aGeomObjects.IsEmpty() )
221 HYDROData_SequenceOfObjects aGeomGroups = GetGeometryGroups();
223 HYDROData_SplitToZonesTool::SplitDataList aSplitedObjects =
224 HYDROData_SplitToZonesTool::Split( aGeomObjects, aGeomGroups, aBoundaryPolyline );
225 if ( aSplitedObjects.isEmpty() )
228 QString aRegsPref = CALCULATION_REGIONS_PREF;
229 QString aZonesPref = CALCULATION_ZONES_PREF;
231 QMap<QString,Handle(HYDROData_SplittedShapesGroup)> aSplittedEdgesGroupsMap;
233 // Create result regions for case, by default one zone for one region
234 HYDROData_SplitToZonesTool::SplitDataListIterator anIter( aSplitedObjects );
235 while( anIter.hasNext() )
237 const HYDROData_SplitToZonesTool::SplitData& aSplitData = anIter.next();
239 if ( aSplitData.Type == HYDROData_SplitToZonesTool::SplitData::Data_Zone )
242 Handle(HYDROData_Region) aRegion = addNewRegion();
244 QString aRegionName = HYDROData_Tool::GenerateObjectName( aDocument, aRegsPref );
245 aRegion->SetName( aRegionName );
247 // Add the zone for region
248 Handle(HYDROData_Zone) aRegionZone = aRegion->addNewZone();
250 QString aZoneName = HYDROData_Tool::GenerateObjectName( aDocument, aZonesPref );
251 aRegionZone->SetName( aZoneName );
253 aRegionZone->SetShape( aSplitData.Face() );
255 // Add the reference object for zone
256 for ( int i = 0, n = aSplitData.ObjectNames.length(); i < n; ++i )
258 const QString& anObjName = aSplitData.ObjectNames.at( i );
260 Handle(HYDROData_Object) aRefObject =
261 Handle(HYDROData_Object)::DownCast( aDocument->FindObjectByName( anObjName ) );
262 if ( aRefObject.IsNull() )
265 aRegionZone->AddGeometryObject( aRefObject );
268 else if ( aSplitData.Type == HYDROData_SplitToZonesTool::SplitData::Data_Edge )
270 // Create new edges group
271 if ( aSplitData.ObjectNames.isEmpty() || aSplitData.Shape.IsNull() )
274 QString anObjName = aSplitData.ObjectNames.first();
275 if ( anObjName.isEmpty() )
277 #ifdef DEB_CALCULATION
278 QString aStr = aSplitData.ObjectNames.join(" ");
279 cout << " CCase: Names = "<<aStr.toStdString() << " size = " <<aSplitData.ObjectNames.size() <<endl;
281 Handle(HYDROData_SplittedShapesGroup) aSplittedGroup;
282 if ( !aSplittedEdgesGroupsMap.contains( anObjName ) )
284 aSplittedGroup = addNewSplittedGroup();
286 QString aCalcGroupName = CALCULATION_GROUPS_PREF + anObjName;
287 aSplittedGroup->SetName( aCalcGroupName );
289 aSplittedEdgesGroupsMap.insert( anObjName, aSplittedGroup );
293 aSplittedGroup = aSplittedEdgesGroupsMap[ anObjName ];
296 if ( aSplittedGroup.IsNull() )
299 aSplittedGroup->AddShape( aSplitData.Shape );
304 bool HYDROData_CalculationCase::AddGeometryObject( const Handle(HYDROData_Object)& theObject )
306 if ( !HYDROData_Tool::IsGeometryObject( theObject ) )
307 return false; // Wrong type of object
309 if ( HasReference( theObject, DataTag_GeometryObject ) )
310 return false; // Object is already in reference list
312 AddReferenceObject( theObject, DataTag_GeometryObject );
314 // Indicate model of the need to update splitting
320 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetGeometryObjects() const
322 return GetReferenceObjects( DataTag_GeometryObject );
325 void HYDROData_CalculationCase::RemoveGeometryObject( const Handle(HYDROData_Object)& theObject )
327 if ( theObject.IsNull() )
330 RemoveReferenceObject( theObject->Label(), DataTag_GeometryObject );
332 // Indicate model of the need to update splitting
336 void HYDROData_CalculationCase::RemoveGeometryObjects()
338 ClearReferenceObjects( DataTag_GeometryObject );
340 // Indicate model of the need to update splitting
344 bool HYDROData_CalculationCase::AddGeometryGroup( const Handle(HYDROData_ShapesGroup)& theGroup )
346 if ( theGroup.IsNull() )
349 if ( HasReference( theGroup, DataTag_GeometryGroup ) )
350 return false; // Object is already in reference list
352 AddReferenceObject( theGroup, DataTag_GeometryGroup );
354 // Indicate model of the need to update splitting
360 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetGeometryGroups() const
362 return GetReferenceObjects( DataTag_GeometryGroup );
365 void HYDROData_CalculationCase::RemoveGeometryGroup( const Handle(HYDROData_ShapesGroup)& theGroup )
367 if ( theGroup.IsNull() )
370 RemoveReferenceObject( theGroup->Label(), DataTag_GeometryGroup );
372 // Indicate model of the need to update splitting
376 void HYDROData_CalculationCase::RemoveGeometryGroups()
378 ClearReferenceObjects( DataTag_GeometryGroup );
380 // Indicate model of the need to update splitting
384 void HYDROData_CalculationCase::SetBoundaryPolyline( const Handle(HYDROData_PolylineXY)& thePolyline )
386 Handle(HYDROData_PolylineXY) aPrevPolyline = GetBoundaryPolyline();
388 SetReferenceObject( thePolyline, DataTag_Polyline );
390 // Indicate model of the need to update zones splitting
391 SetToUpdate( !IsEqual( aPrevPolyline, thePolyline ) || IsMustBeUpdated() );
394 Handle(HYDROData_PolylineXY) HYDROData_CalculationCase::GetBoundaryPolyline() const
396 return Handle(HYDROData_PolylineXY)::DownCast(
397 GetReferenceObject( DataTag_Polyline ) );
400 void HYDROData_CalculationCase::RemoveBoundaryPolyline()
402 Handle(HYDROData_PolylineXY) aPrevPolyline = GetBoundaryPolyline();
404 ClearReferenceObjects( DataTag_Polyline );
406 // Indicate model of the need to update zones splitting
407 SetToUpdate( !aPrevPolyline.IsNull() || IsMustBeUpdated() );
410 Handle(HYDROData_Region) HYDROData_CalculationCase::AddNewRegion( const Handle(HYDROData_Zone)& theZone )
412 Handle(HYDROData_Region) aNewRegion = addNewRegion();
413 if ( aNewRegion.IsNull() )
416 // Generate new name for new region
417 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
418 if ( !aDocument.IsNull() )
420 QString aRegsPref = CALCULATION_REGIONS_PREF;
422 QString aNewRegionName = HYDROData_Tool::GenerateObjectName( aDocument, aRegsPref );
423 aNewRegion->SetName( aNewRegionName );
426 aNewRegion->AddZone( theZone );
431 bool HYDROData_CalculationCase::AddRegion( const Handle(HYDROData_Region)& theRegion )
433 if ( theRegion.IsNull() )
436 if ( HasReference( theRegion, DataTag_Region ) )
437 return false; // Object is already in reference list
439 // Move the region from other calculation
440 Handle(HYDROData_CalculationCase) aFatherCalc =
441 Handle(HYDROData_CalculationCase)::DownCast( theRegion->GetFatherObject() );
442 if ( !aFatherCalc.IsNull() && aFatherCalc->Label() != myLab )
444 Handle(HYDROData_Region) aNewRegion = addNewRegion();
445 theRegion->CopyTo( aNewRegion );
447 aFatherCalc->RemoveRegion( theRegion );
449 theRegion->SetLabel( aNewRegion->Label() );
453 AddReferenceObject( theRegion, DataTag_Region );
459 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetRegions() const
461 return GetReferenceObjects( DataTag_Region );
464 void HYDROData_CalculationCase::UpdateRegionsOrder()
466 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
467 if ( aDocument.IsNull() )
470 HYDROData_SequenceOfObjects aRegions = GetRegions();
472 HYDROData_SequenceOfObjects::Iterator anIter( aRegions );
473 for ( ; anIter.More(); anIter.Next() )
475 Handle(HYDROData_Region) aRegion =
476 Handle(HYDROData_Region)::DownCast( anIter.Value() );
477 if ( aRegion.IsNull() )
480 aRegion->SetName( "" );
483 QString aRegsPref = CALCULATION_REGIONS_PREF;
485 anIter.Init( aRegions );
486 for ( ; anIter.More(); anIter.Next() )
488 Handle(HYDROData_Region) aRegion =
489 Handle(HYDROData_Region)::DownCast( anIter.Value() );
490 if ( aRegion.IsNull() )
493 QString aRegionName = HYDROData_Tool::GenerateObjectName( aDocument, aRegsPref );
494 aRegion->SetName( aRegionName );
498 void HYDROData_CalculationCase::RemoveRegion( const Handle(HYDROData_Region)& theRegion )
500 if ( theRegion.IsNull() )
503 RemoveReferenceObject( theRegion->Label(), DataTag_Region );
505 // Remove region from data model
506 Handle(HYDROData_CalculationCase) aFatherCalc =
507 Handle(HYDROData_CalculationCase)::DownCast( theRegion->GetFatherObject() );
508 if ( !aFatherCalc.IsNull() && aFatherCalc->Label() == myLab )
512 void HYDROData_CalculationCase::RemoveRegions()
514 myLab.FindChild( DataTag_ChildRegion ).ForgetAllAttributes();
517 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetSplittedGroups() const
519 return GetReferenceObjects( DataTag_SplittedGroups );
522 void HYDROData_CalculationCase::RemoveSplittedGroups()
524 myLab.FindChild( DataTag_SplittedGroups ).ForgetAllAttributes();
527 double HYDROData_CalculationCase::GetAltitudeForPoint( const gp_XY& thePoint ) const
529 Handle(HYDROData_Zone) aZone = GetZoneFromPoint( thePoint );
530 return GetAltitudeForPoint( thePoint, aZone );
533 double HYDROData_CalculationCase::GetAltitudeForPoint( const gp_XY& thePoint,
534 const Handle(HYDROData_Region)& theRegion ) const
536 double aResAltitude = HYDROData_IAltitudeObject::GetInvalidAltitude();
538 Handle(HYDROData_Zone) aZone = GetZoneFromPoint( thePoint );
539 if ( !aZone.IsNull() )
541 //DEBTRACE("GetAltitudeForPoint Region " << theRegion->GetName().toStdString() << " Zone " << aZone->GetName().toStdString());
542 Handle(HYDROData_Region) aRefRegion = Handle(HYDROData_Region)::DownCast( aZone->GetFatherObject() );
543 if ( IsEqual( aRefRegion, theRegion ) )
544 aResAltitude = GetAltitudeForPoint( thePoint, aZone );
547 DEBTRACE("GetAltitudeForPoint Region " << aRefRegion->GetName().toStdString() << " Zone " << aZone->GetName().toStdString() << " ---------------------------");
548 aResAltitude = GetAltitudeForPoint( thePoint, aZone );
553 DEBTRACE(" --- GetAltitudeForPoint No Zone ---");
559 double HYDROData_CalculationCase::GetAltitudeForPoint( const gp_XY& thePoint,
560 const Handle(HYDROData_Zone)& theZone ) const
562 //DEBTRACE("GetAltitudeForPoint Zone " << theZone->GetName().toStdString());
563 double aResAltitude = HYDROData_IAltitudeObject::GetInvalidAltitude();
564 if ( theZone.IsNull() )
567 HYDROData_Zone::MergeAltitudesType aZoneMergeType = theZone->GetMergeType();
568 if ( !theZone->IsMergingNeed() )
570 aZoneMergeType = HYDROData_Zone::Merge_UNKNOWN;
572 else if ( aZoneMergeType == HYDROData_Zone::Merge_UNKNOWN )
577 HYDROData_IInterpolator* aZoneInterpolator = theZone->GetInterpolator();
578 if ( aZoneMergeType == HYDROData_Zone::Merge_Object )
580 Handle(HYDROData_IAltitudeObject) aMergeAltitude = theZone->GetMergeAltitude();
581 if ( !aMergeAltitude.IsNull() )
583 if ( aZoneInterpolator != NULL )
585 aZoneInterpolator->SetAltitudeObject( aMergeAltitude );
586 aResAltitude = aZoneInterpolator->GetAltitudeForPoint( thePoint );
589 aResAltitude = aMergeAltitude->GetAltitudeForPoint( thePoint );
594 HYDROData_SequenceOfObjects aZoneObjects = theZone->GetGeometryObjects();
595 HYDROData_SequenceOfObjects::Iterator anIter( aZoneObjects );
596 for ( ; anIter.More(); anIter.Next() )
598 Handle(HYDROData_Object) aZoneObj =
599 Handle(HYDROData_Object)::DownCast( anIter.Value() );
600 if ( aZoneObj.IsNull() )
603 Handle(HYDROData_IAltitudeObject) anObjAltitude = aZoneObj->GetAltitudeObject();
604 if ( anObjAltitude.IsNull() )
607 double aPointAltitude = 0.0;
608 if ( aZoneInterpolator != NULL )
610 aZoneInterpolator->SetAltitudeObject( anObjAltitude );
611 aPointAltitude = aZoneInterpolator->GetAltitudeForPoint( thePoint );
614 aPointAltitude = anObjAltitude->GetAltitudeForPoint( thePoint );
616 if ( ValuesEquals( aPointAltitude, HYDROData_IAltitudeObject::GetInvalidAltitude() ) )
619 if ( aZoneMergeType == HYDROData_Zone::Merge_UNKNOWN )
621 aResAltitude = aPointAltitude;
624 else if ( aZoneMergeType == HYDROData_Zone::Merge_ZMIN )
626 if ( ValuesEquals( aResAltitude, HYDROData_IAltitudeObject::GetInvalidAltitude() ) ||
627 aResAltitude > aPointAltitude )
629 aResAltitude = aPointAltitude;
632 else if ( aZoneMergeType == HYDROData_Zone::Merge_ZMAX )
634 if ( ValuesEquals( aResAltitude, HYDROData_IAltitudeObject::GetInvalidAltitude() ) ||
635 aResAltitude < aPointAltitude )
637 aResAltitude = aPointAltitude;
646 NCollection_Sequence<double> HYDROData_CalculationCase::GetAltitudesForPoints(
647 const NCollection_Sequence<gp_XY>& thePoints,
648 const Handle(HYDROData_Region)& theRegion ) const
650 //DEBTRACE("HYDROData_CalculationCase::GetAltitudesForPoints " << theRegion->GetName().toStdString());
651 NCollection_Sequence<double> aResSeq;
653 for ( int i = 1, n = thePoints.Length(); i <= n; ++i )
655 const gp_XY& thePnt = thePoints.Value( i );
657 double anAltitude = GetAltitudeForPoint( thePnt, theRegion );
658 aResSeq.Append( anAltitude );
664 NCollection_Sequence<double> HYDROData_CalculationCase::GetAltitudesForPoints(
665 const NCollection_Sequence<gp_XY>& thePoints,
666 const Handle(HYDROData_Zone)& theZone ) const
668 NCollection_Sequence<double> aResSeq;
670 for ( int i = 1, n = thePoints.Length(); i <= n; ++i )
672 const gp_XY& thePnt = thePoints.Value( i );
674 double anAltitude = GetAltitudeForPoint( thePnt, theZone );
675 aResSeq.Append( anAltitude );
681 Handle(HYDROData_Region) HYDROData_CalculationCase::GetRegionFromPoint( const gp_XY& thePoint ) const
683 Handle(HYDROData_Region) aResRegion;
685 Handle(HYDROData_Zone) aZone = GetZoneFromPoint( thePoint );
686 if ( !aZone.IsNull() )
687 aResRegion = Handle(HYDROData_Region)::DownCast( aZone->GetFatherObject() );
692 Handle(HYDROData_Zone) HYDROData_CalculationCase::GetZoneFromPoint( const gp_XY& thePoint ) const
694 Handle(HYDROData_Zone) aResZone;
696 HYDROData_SequenceOfObjects aRegions = GetRegions();
698 HYDROData_SequenceOfObjects::Iterator anIter( aRegions );
699 for ( ; anIter.More() && aResZone.IsNull(); anIter.Next() )
701 Handle(HYDROData_Region) aRegion =
702 Handle(HYDROData_Region)::DownCast( anIter.Value() );
703 if ( aRegion.IsNull() )
706 HYDROData_SequenceOfObjects aZones = aRegion->GetZones();
707 HYDROData_SequenceOfObjects::Iterator aZonesIter( aZones );
708 for ( ; aZonesIter.More() && aResZone.IsNull(); aZonesIter.Next() )
710 Handle(HYDROData_Zone) aRegZone =
711 Handle(HYDROData_Zone)::DownCast( aZonesIter.Value() );
712 if ( aRegZone.IsNull() )
715 PointClassification aPointRelation = GetPointClassification( thePoint, aRegZone );
716 if ( aPointRelation != POINT_OUT )
717 aResZone = aRegZone; // We found the desired zone
724 HYDROData_CalculationCase::PointClassification HYDROData_CalculationCase::GetPointClassification(
725 const gp_XY& thePoint,
726 const Handle(HYDROData_Zone)& theZone ) const
728 PointClassification aRes = POINT_OUT;
729 if ( theZone.IsNull() )
732 TopoDS_Face aZoneFace = TopoDS::Face( theZone->GetShape() );
733 if ( aZoneFace.IsNull() )
736 TopoDS_Compound aCmp;
738 aBB.MakeCompound(aCmp);
739 aBB.Add(aCmp, aZoneFace);
740 gp_Pnt aPnt (thePoint.X(), thePoint.Y(), 0.);
741 BRepBuilderAPI_MakeVertex aMk(aPnt);
742 aBB.Add(aCmp, aMk.Vertex());
743 BRepTools::Write(aCmp, "FCL2d.brep");
745 TopAbs_State State = HYDROData_Tool::ComputePointState(thePoint, aZoneFace);
746 if (State == TopAbs_OUT)
748 else if(State == TopAbs_IN)
750 else if(State == TopAbs_ON)
755 Handle(HYDROData_Region) HYDROData_CalculationCase::addNewRegion()
757 TDF_Label aNewLab = myLab.FindChild( DataTag_ChildRegion ).NewChild();
759 Handle(HYDROData_Region) aNewRegion =
760 Handle(HYDROData_Region)::DownCast( HYDROData_Iterator::CreateObject( aNewLab, KIND_REGION ) );
761 AddRegion( aNewRegion );
766 Handle(HYDROData_SplittedShapesGroup) HYDROData_CalculationCase::addNewSplittedGroup()
768 TDF_Label aNewLab = myLab.FindChild( DataTag_SplittedGroups ).NewChild();
770 Handle(HYDROData_SplittedShapesGroup) aNewGroup =
771 Handle(HYDROData_SplittedShapesGroup)::DownCast(
772 HYDROData_Iterator::CreateObject( aNewLab, KIND_SPLITTED_GROUP ) );
773 AddReferenceObject( aNewGroup, DataTag_SplittedGroups );
778 bool HYDROData_CalculationCase::Export( GEOM::GEOM_Gen_var theGeomEngine,
779 SALOMEDS::Study_ptr theStudy ) const
781 HYDROData_ShapesGroup::SeqOfGroupsDefs aSeqOfGroupsDefs;
783 // Get groups definitions
784 HYDROData_SequenceOfObjects aSplittedGroups = GetSplittedGroups();
786 HYDROData_SequenceOfObjects::Iterator anIter( aSplittedGroups );
787 for ( ; anIter.More(); anIter.Next() )
790 Handle(HYDROData_ShapesGroup) aGroup =
791 Handle(HYDROData_ShapesGroup)::DownCast( anIter.Value() );
792 if ( aGroup.IsNull() )
795 HYDROData_ShapesGroup::GroupDefinition aGroupDef;
797 aGroupDef.Name = aGroup->GetName().toLatin1().constData();
798 aGroup->GetShapes( aGroupDef.Shapes );
800 aSeqOfGroupsDefs.Append( aGroupDef );
804 TopTools_ListOfShape aFaces;
805 HYDROData_SequenceOfObjects aCaseRegions = GetRegions();
806 HYDROData_SequenceOfObjects::Iterator aRegionIter( aCaseRegions );
807 for ( ; aRegionIter.More(); aRegionIter.Next() )
809 Handle(HYDROData_Region) aRegion =
810 Handle(HYDROData_Region)::DownCast( aRegionIter.Value() );
811 if( aRegion.IsNull() )
814 TopoDS_Shape aRegionShape = aRegion->GetShape( &aSeqOfGroupsDefs );
815 aFaces.Append( aRegionShape );
818 return Export( theGeomEngine, theStudy, aFaces, aSeqOfGroupsDefs );
821 bool HYDROData_CalculationCase::Export( GEOM::GEOM_Gen_var theGeomEngine,
822 SALOMEDS::Study_ptr theStudy,
823 const TopTools_ListOfShape& theFaces,
824 const HYDROData_ShapesGroup::SeqOfGroupsDefs& theGroupsDefs ) const
827 BRepBuilderAPI_Sewing aSewing( Precision::Confusion() * 10.0 );
828 aSewing.SetNonManifoldMode( Standard_False );
829 #ifdef DEB_CALCULATION
830 TCollection_AsciiString aNam("Sh_");
833 TopTools_ListIteratorOfListOfShape aFaceIter( theFaces );
834 for ( ; aFaceIter.More(); aFaceIter.Next() )
836 TopoDS_Shape aShape = aFaceIter.Value();
837 if ( aShape.IsNull() )
840 if ( aShape.ShapeType() == TopAbs_FACE )
842 aSewing.Add( aShape );
843 #ifdef DEB_CALCULATION
844 TCollection_AsciiString aName = aNam + ++i + ".brep";
845 BRepTools::Write(aShape ,aName.ToCString());
850 #ifdef DEB_CALCULATION
853 TopExp_Explorer anExp( aShape, TopAbs_FACE );
854 for (; anExp.More(); anExp.Next() ) {
855 aSewing.Add( anExp.Current() );
856 #ifdef DEB_CALCULATION
858 TCollection_AsciiString aName = aNam + i + "_" + ++j + ".brep";
859 BRepTools::Write(anExp.Current() ,aName.ToCString());
866 TopoDS_Shape aSewedShape = aSewing.SewedShape();
868 // If the sewed shape is empty - return false
869 if ( aSewedShape.IsNull() || !TopoDS_Iterator( aSewedShape ).More() )
872 #ifdef DEB_CALCULATION
873 BRepTools::Write(aSewedShape ,"Sew.brep");
875 // Publish the sewed shape
876 QString aName = EXPORT_NAME;
877 GEOM::GEOM_Object_ptr aMainShape =
878 publishShapeInGEOM( theGeomEngine, theStudy, aSewedShape, aName );
880 if ( aMainShape->_is_nil() )
883 if ( theGroupsDefs.IsEmpty() )
887 TopTools_IndexedMapOfShape aMapOfSubShapes;
888 TopExp::MapShapes( aSewedShape, aMapOfSubShapes );
890 NCollection_DataMap< TCollection_AsciiString, NCollection_Sequence<int> > aGroupsData;
892 for ( int aGrId = 1, nbGroups = theGroupsDefs.Length(); aGrId <= nbGroups; ++aGrId )
894 const HYDROData_ShapesGroup::GroupDefinition& aGroupDef = theGroupsDefs.Value( aGrId );
896 NCollection_Sequence<int> aGroupIndexes;
897 for( int i = 1, n = aGroupDef.Shapes.Length(); i <= n; i++ )
899 const TopoDS_Shape& aShape = aGroupDef.Shapes.Value( i );
900 #ifdef DEB_CALCULATION
901 cout << "\nOld shape(" << i << ") = " << aShape.TShape() <<endl;
904 TopoDS_Shape aModifiedShape = aShape;
905 if ( aSewing.IsModified( aShape ) )
906 aModifiedShape = aSewing.Modified( aShape );
907 else if ( aSewing.IsModifiedSubShape( aShape ) )
908 aModifiedShape = aSewing.ModifiedSubShape( aShape );
910 #ifdef DEB_CALCULATION
911 const TopLoc_Location& aL1 = aShape.Location();
912 const TopLoc_Location& aL2 = aModifiedShape.Location();
913 cout << "\nNew shape(" << i << ") = " << aModifiedShape.TShape() << " Location is Equal = " << aL1.IsEqual(aL2)<<endl;
916 int anIndex = aMapOfSubShapes.FindIndex(aModifiedShape);
918 aGroupIndexes.Append( anIndex );
920 #ifdef DEB_CALCULATION
921 TCollection_AsciiString aNam("Lost_");
922 if(!aMapOfSubShapes.Contains(aModifiedShape)) {
923 for ( int anIndex = 1; anIndex <= aMapOfSubShapes.Extent(); anIndex++ )
925 const TopoDS_Shape& aS = aMapOfSubShapes.FindKey( anIndex );
926 if ( aModifiedShape.IsPartner( aS ) )
928 cout <<"\nIndex in Map = " << anIndex << "TShape = " << aS.TShape() <<endl;
929 TCollection_AsciiString aName = aNam + i + "_" + anIndex + ".brep";
930 BRepTools::Write(aS ,aName.ToCString());
938 if ( !aGroupIndexes.IsEmpty() )
939 aGroupsData.Bind( aGroupDef.Name, aGroupIndexes );
942 if ( !aGroupsData.IsEmpty() )
944 GEOM::GEOM_IGroupOperations_var aGroupOp =
945 theGeomEngine->GetIGroupOperations( theStudy->StudyId() );
947 NCollection_DataMap< TCollection_AsciiString, NCollection_Sequence<int> >::Iterator aMapIt( aGroupsData );
948 for ( ; aMapIt.More(); aMapIt.Next() )
950 const TCollection_AsciiString& aGroupName = aMapIt.Key();
951 const NCollection_Sequence<int>& aGroupIndexes = aMapIt.Value();
953 GEOM::GEOM_Object_var aGeomGroup = aGroupOp->CreateGroup( aMainShape, TopAbs_EDGE );
954 if ( CORBA::is_nil( aGeomGroup ) || !aGroupOp->IsDone() )
957 GEOM::ListOfLong_var aGeomIndexes = new GEOM::ListOfLong;
958 aGeomIndexes->length( aGroupIndexes.Length() );
960 for( int i = 1, n = aGroupIndexes.Length(); i <= n; i++ )
961 aGeomIndexes[ i - 1 ] = aGroupIndexes.Value( i );
963 aGroupOp->UnionIDs( aGeomGroup, aGeomIndexes );
964 if ( aGroupOp->IsDone() )
966 SALOMEDS::SObject_var aGroupSO =
967 theGeomEngine->AddInStudy( theStudy, aGeomGroup, aGroupName.ToCString(), aMainShape );
975 GEOM::GEOM_Object_ptr HYDROData_CalculationCase::publishShapeInGEOM(
976 GEOM::GEOM_Gen_var theGeomEngine, SALOMEDS::Study_ptr theStudy,
977 const TopoDS_Shape& theShape, const QString& theName ) const
979 GEOM::GEOM_Object_var aGeomObj;
981 if ( theGeomEngine->_is_nil() || theStudy->_is_nil() ||
982 theShape.IsNull() ) {
983 return aGeomObj._retn();
986 std::ostringstream aStreamShape;
987 // Write TopoDS_Shape in ASCII format to the stream
988 BRepTools::Write( theShape, aStreamShape );
989 // Returns the number of bytes that have been stored in the stream's buffer.
990 int aSize = aStreamShape.str().size();
991 // Allocate octect buffer of required size
992 CORBA::Octet* anOctetBuf = SALOMEDS::TMPFile::allocbuf( aSize );
993 // Copy ostrstream content to the octect buffer
994 memcpy( anOctetBuf, aStreamShape.str().c_str(), aSize );
996 SALOMEDS::TMPFile_var aSeqFile = new SALOMEDS::TMPFile( aSize, aSize, anOctetBuf, 1 );
998 // Restore shape from the stream and get the GEOM object
999 GEOM::GEOM_IInsertOperations_var anInsOp = theGeomEngine->GetIInsertOperations( theStudy->StudyId() );
1000 aGeomObj = anInsOp->RestoreShape( aSeqFile );
1002 // Puplish the GEOM object
1003 if ( !aGeomObj->_is_nil() ) {
1004 QString aName = GEOMBase::GetDefaultName( theName );
1006 SALOMEDS::SObject_var aResultSO =
1007 theGeomEngine->PublishInStudy( theStudy, SALOMEDS::SObject::_nil(),
1008 aGeomObj, qPrintable( aName ) );
1009 if ( aResultSO->_is_nil() ) {
1010 aGeomObj = GEOM::GEOM_Object::_nil();
1014 return aGeomObj._retn();