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() + "_"
46 #define EXPORT_NAME "HYDRO_" + GetName()
48 IMPLEMENT_STANDARD_HANDLE(HYDROData_CalculationCase, HYDROData_Entity)
49 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_CalculationCase, HYDROData_Entity)
51 HYDROData_CalculationCase::HYDROData_CalculationCase()
56 HYDROData_CalculationCase::~HYDROData_CalculationCase()
60 void HYDROData_CalculationCase::SetName( const QString& theName )
62 QString anOldCaseName = GetName();
63 if ( anOldCaseName != theName )
65 HYDROData_SequenceOfObjects aRegions = GetRegions();
67 HYDROData_SequenceOfObjects::Iterator anIter( aRegions );
68 for ( ; anIter.More(); anIter.Next() )
70 Handle(HYDROData_Region) aRegion =
71 Handle(HYDROData_Region)::DownCast( anIter.Value() );
72 if ( aRegion.IsNull() )
75 HYDROData_Tool::UpdateChildObjectName( anOldCaseName, theName, aRegion );
77 HYDROData_SequenceOfObjects aZones = aRegion->GetZones();
78 HYDROData_SequenceOfObjects::Iterator anIter( aZones );
79 for ( ; anIter.More(); anIter.Next() )
81 Handle(HYDROData_Zone) aRegZone =
82 Handle(HYDROData_Zone)::DownCast( anIter.Value() );
83 if ( aRegZone.IsNull() )
86 HYDROData_Tool::UpdateChildObjectName( anOldCaseName, theName, aRegZone );
90 HYDROData_SequenceOfObjects aGroups = GetGeometryGroups();
92 anIter.Init( aGroups );
93 for ( ; anIter.More(); anIter.Next() )
95 Handle(HYDROData_SplittedShapesGroup) aGroup =
96 Handle(HYDROData_SplittedShapesGroup)::DownCast( anIter.Value() );
97 if ( aGroup.IsNull() )
100 HYDROData_Tool::UpdateChildObjectName( anOldCaseName, theName, aGroup );
104 HYDROData_Entity::SetName( theName );
107 QStringList HYDROData_CalculationCase::DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const
109 QStringList aResList = dumpObjectCreation( theTreatedObjects );
111 QString aCalculName = GetObjPyName();
113 HYDROData_SequenceOfObjects aGeomObjects = GetGeometryObjects();
114 HYDROData_SequenceOfObjects::Iterator anIter( aGeomObjects );
115 for ( ; anIter.More(); anIter.Next() )
117 Handle(HYDROData_Object) aRefGeomObj =
118 Handle(HYDROData_Object)::DownCast( anIter.Value() );
119 setPythonReferenceObject( theTreatedObjects, aResList, aRefGeomObj, "AddGeometryObject" );
121 aResList << QString( "" );
123 QString aGroupName = HYDROData_Tool::GenerateNameForPython( theTreatedObjects, "case_geom_group" );
125 HYDROData_SequenceOfObjects aGeomGroups = GetGeometryGroups();
126 anIter.Init( aGeomGroups );
127 for ( ; anIter.More(); anIter.Next() )
129 Handle(HYDROData_ShapesGroup) aGeomGroup =
130 Handle(HYDROData_ShapesGroup)::DownCast( anIter.Value() );
131 if ( aGeomGroup.IsNull() )
134 Handle(HYDROData_Object) aFatherGeom =
135 Handle(HYDROData_Object)::DownCast( aGeomGroup->GetFatherObject() );
136 if ( aFatherGeom.IsNull() )
139 int aGroupId = aFatherGeom->GetGroupId( aGeomGroup );
140 aResList << QString( "%1 = %2.GetGroup( %3 );" )
141 .arg( aGroupName ).arg( aFatherGeom->GetObjPyName() ).arg( aGroupId );
143 aResList << QString( "%1.AddGeometryGroup( %2 );" ).arg( aCalculName ).arg( aGroupName );
145 aResList << QString( "" );
147 Handle(HYDROData_PolylineXY) aBoundaryPolyline = GetBoundaryPolyline();
148 setPythonReferenceObject( theTreatedObjects, aResList, aBoundaryPolyline, "SetBoundaryPolyline" );
149 aResList << QString( "" );
151 aResList << QString( "%1.Update();" ).arg( aCalculName );
152 aResList << QString( "" );
154 // Now we restore the regions and zones order
155 HYDROData_SequenceOfObjects aRegions = GetRegions();
156 anIter.Init( aRegions );
157 for ( ; anIter.More(); anIter.Next() )
159 Handle(HYDROData_Region) aRegion =
160 Handle(HYDROData_Region)::DownCast( anIter.Value() );
161 if ( aRegion.IsNull() )
164 QString aRegionName = aRegion->GetName();
166 HYDROData_SequenceOfObjects aZones = aRegion->GetZones();
167 HYDROData_SequenceOfObjects::Iterator aZonesIter( aZones );
168 for ( ; aZonesIter.More(); aZonesIter.Next() )
170 Handle(HYDROData_Zone) aRegZone =
171 Handle(HYDROData_Zone)::DownCast( aZonesIter.Value() );
172 if ( aRegZone.IsNull() )
178 aResList << QString( "" );
183 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetAllReferenceObjects() const
185 HYDROData_SequenceOfObjects aResSeq = HYDROData_Entity::GetAllReferenceObjects();
187 Handle(HYDROData_PolylineXY) aBoundaryPolyline = GetBoundaryPolyline();
188 if ( !aBoundaryPolyline.IsNull() )
189 aResSeq.Append( aBoundaryPolyline );
191 HYDROData_SequenceOfObjects aSeqOfRegions = GetRegions();
192 aResSeq.Append( aSeqOfRegions );
197 void HYDROData_CalculationCase::Update()
199 HYDROData_Entity::Update();
201 // At first we remove previously created objects
203 RemoveSplittedGroups();
205 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
206 if ( aDocument.IsNull() )
209 Handle(HYDROData_PolylineXY) aBoundaryPolyline = GetBoundaryPolyline();
210 HYDROData_SequenceOfObjects aGeomObjects = GetGeometryObjects();
211 if ( aGeomObjects.IsEmpty() )
214 HYDROData_SequenceOfObjects aGeomGroups = GetGeometryGroups();
216 HYDROData_SplitToZonesTool::SplitDataList aSplitedObjects =
217 HYDROData_SplitToZonesTool::Split( aGeomObjects, aGeomGroups, aBoundaryPolyline );
218 if ( aSplitedObjects.isEmpty() )
221 QString aRegsPref = CALCULATION_REGIONS_PREF;
222 QString aZonesPref = CALCULATION_ZONES_PREF;
224 QMap<QString,Handle(HYDROData_SplittedShapesGroup)> aSplittedEdgesGroupsMap;
226 // Create result regions for case, by default one zone for one region
227 HYDROData_SplitToZonesTool::SplitDataListIterator anIter( aSplitedObjects );
228 while( anIter.hasNext() )
230 const HYDROData_SplitToZonesTool::SplitData& aSplitData = anIter.next();
232 if ( aSplitData.Type == HYDROData_SplitToZonesTool::SplitData::Data_Zone )
235 Handle(HYDROData_Region) aRegion = addNewRegion();
237 QString aRegionName = HYDROData_Tool::GenerateObjectName( aDocument, aRegsPref );
238 aRegion->SetName( aRegionName );
240 // Add the zone for region
241 Handle(HYDROData_Zone) aRegionZone = aRegion->addNewZone();
243 QString aZoneName = HYDROData_Tool::GenerateObjectName( aDocument, aZonesPref );
244 aRegionZone->SetName( aZoneName );
246 aRegionZone->SetShape( aSplitData.Face() );
248 // Add the reference object for zone
249 for ( int i = 0, n = aSplitData.ObjectNames.length(); i < n; ++i )
251 const QString& anObjName = aSplitData.ObjectNames.at( i );
253 Handle(HYDROData_Object) aRefObject =
254 Handle(HYDROData_Object)::DownCast( aDocument->FindObjectByName( anObjName ) );
255 if ( aRefObject.IsNull() )
258 aRegionZone->AddGeometryObject( aRefObject );
261 else if ( aSplitData.Type == HYDROData_SplitToZonesTool::SplitData::Data_Edge )
263 // Create new edges group
264 if ( aSplitData.ObjectNames.isEmpty() || aSplitData.Shape.IsNull() )
267 QString anObjName = aSplitData.ObjectNames.first();
268 if ( anObjName.isEmpty() )
270 #ifdef DEB_CALCULATION
271 QString aStr = aSplitData.ObjectNames.join(" ");
272 cout << " CCase: Names = "<<aStr.toStdString() << " size = " <<aSplitData.ObjectNames.size() <<endl;
274 Handle(HYDROData_SplittedShapesGroup) aSplittedGroup;
275 if ( !aSplittedEdgesGroupsMap.contains( anObjName ) )
277 aSplittedGroup = addNewSplittedGroup();
279 QString aCalcGroupName = CALCULATION_GROUPS_PREF + anObjName;
280 aSplittedGroup->SetName( aCalcGroupName );
282 aSplittedEdgesGroupsMap.insert( anObjName, aSplittedGroup );
286 aSplittedGroup = aSplittedEdgesGroupsMap[ anObjName ];
289 if ( aSplittedGroup.IsNull() )
292 aSplittedGroup->AddShape( aSplitData.Shape );
297 bool HYDROData_CalculationCase::AddGeometryObject( const Handle(HYDROData_Object)& theObject )
299 if ( !HYDROData_Tool::IsGeometryObject( theObject ) )
300 return false; // Wrong type of object
302 if ( HasReference( theObject, DataTag_GeometryObject ) )
303 return false; // Object is already in reference list
305 AddReferenceObject( theObject, DataTag_GeometryObject );
307 // Indicate model of the need to update splitting
313 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetGeometryObjects() const
315 return GetReferenceObjects( DataTag_GeometryObject );
318 void HYDROData_CalculationCase::RemoveGeometryObject( const Handle(HYDROData_Object)& theObject )
320 if ( theObject.IsNull() )
323 RemoveReferenceObject( theObject->Label(), DataTag_GeometryObject );
325 // Indicate model of the need to update splitting
329 void HYDROData_CalculationCase::RemoveGeometryObjects()
331 ClearReferenceObjects( DataTag_GeometryObject );
333 // Indicate model of the need to update splitting
337 bool HYDROData_CalculationCase::AddGeometryGroup( const Handle(HYDROData_ShapesGroup)& theGroup )
339 if ( theGroup.IsNull() )
342 if ( HasReference( theGroup, DataTag_GeometryGroup ) )
343 return false; // Object is already in reference list
345 AddReferenceObject( theGroup, DataTag_GeometryGroup );
347 // Indicate model of the need to update splitting
353 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetGeometryGroups() const
355 return GetReferenceObjects( DataTag_GeometryGroup );
358 void HYDROData_CalculationCase::RemoveGeometryGroup( const Handle(HYDROData_ShapesGroup)& theGroup )
360 if ( theGroup.IsNull() )
363 RemoveReferenceObject( theGroup->Label(), DataTag_GeometryGroup );
365 // Indicate model of the need to update splitting
369 void HYDROData_CalculationCase::RemoveGeometryGroups()
371 ClearReferenceObjects( DataTag_GeometryGroup );
373 // Indicate model of the need to update splitting
377 void HYDROData_CalculationCase::SetBoundaryPolyline( const Handle(HYDROData_PolylineXY)& thePolyline )
379 Handle(HYDROData_PolylineXY) aPrevPolyline = GetBoundaryPolyline();
381 SetReferenceObject( thePolyline, DataTag_Polyline );
383 // Indicate model of the need to update zones splitting
384 SetToUpdate( !IsEqual( aPrevPolyline, thePolyline ) || IsMustBeUpdated() );
387 Handle(HYDROData_PolylineXY) HYDROData_CalculationCase::GetBoundaryPolyline() const
389 return Handle(HYDROData_PolylineXY)::DownCast(
390 GetReferenceObject( DataTag_Polyline ) );
393 void HYDROData_CalculationCase::RemoveBoundaryPolyline()
395 Handle(HYDROData_PolylineXY) aPrevPolyline = GetBoundaryPolyline();
397 ClearReferenceObjects( DataTag_Polyline );
399 // Indicate model of the need to update zones splitting
400 SetToUpdate( !aPrevPolyline.IsNull() || IsMustBeUpdated() );
403 Handle(HYDROData_Region) HYDROData_CalculationCase::AddNewRegion( const Handle(HYDROData_Zone)& theZone )
405 Handle(HYDROData_Region) aNewRegion = addNewRegion();
406 if ( aNewRegion.IsNull() )
409 // Generate new name for new region
410 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
411 if ( !aDocument.IsNull() )
413 QString aRegsPref = CALCULATION_REGIONS_PREF;
415 QString aNewRegionName = HYDROData_Tool::GenerateObjectName( aDocument, aRegsPref );
416 aNewRegion->SetName( aNewRegionName );
419 aNewRegion->AddZone( theZone );
424 bool HYDROData_CalculationCase::AddRegion( const Handle(HYDROData_Region)& theRegion )
426 if ( theRegion.IsNull() )
429 if ( HasReference( theRegion, DataTag_Region ) )
430 return false; // Object is already in reference list
432 // Move the region from other calculation
433 Handle(HYDROData_CalculationCase) aFatherCalc =
434 Handle(HYDROData_CalculationCase)::DownCast( theRegion->GetFatherObject() );
435 if ( !aFatherCalc.IsNull() && aFatherCalc->Label() != myLab )
437 Handle(HYDROData_Region) aNewRegion = addNewRegion();
438 theRegion->CopyTo( aNewRegion );
440 aFatherCalc->RemoveRegion( theRegion );
442 theRegion->SetLabel( aNewRegion->Label() );
446 AddReferenceObject( theRegion, DataTag_Region );
452 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetRegions() const
454 return GetReferenceObjects( DataTag_Region );
457 void HYDROData_CalculationCase::UpdateRegionsOrder()
459 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
460 if ( aDocument.IsNull() )
463 HYDROData_SequenceOfObjects aRegions = GetRegions();
465 HYDROData_SequenceOfObjects::Iterator anIter( aRegions );
466 for ( ; anIter.More(); anIter.Next() )
468 Handle(HYDROData_Region) aRegion =
469 Handle(HYDROData_Region)::DownCast( anIter.Value() );
470 if ( aRegion.IsNull() )
473 aRegion->SetName( "" );
476 QString aRegsPref = CALCULATION_REGIONS_PREF;
478 anIter.Init( aRegions );
479 for ( ; anIter.More(); anIter.Next() )
481 Handle(HYDROData_Region) aRegion =
482 Handle(HYDROData_Region)::DownCast( anIter.Value() );
483 if ( aRegion.IsNull() )
486 QString aRegionName = HYDROData_Tool::GenerateObjectName( aDocument, aRegsPref );
487 aRegion->SetName( aRegionName );
491 void HYDROData_CalculationCase::RemoveRegion( const Handle(HYDROData_Region)& theRegion )
493 if ( theRegion.IsNull() )
496 RemoveReferenceObject( theRegion->Label(), DataTag_Region );
498 // Remove region from data model
499 Handle(HYDROData_CalculationCase) aFatherCalc =
500 Handle(HYDROData_CalculationCase)::DownCast( theRegion->GetFatherObject() );
501 if ( !aFatherCalc.IsNull() && aFatherCalc->Label() == myLab )
505 void HYDROData_CalculationCase::RemoveRegions()
507 myLab.FindChild( DataTag_ChildRegion ).ForgetAllAttributes();
510 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetSplittedGroups() const
512 return GetReferenceObjects( DataTag_SplittedGroups );
515 void HYDROData_CalculationCase::RemoveSplittedGroups()
517 myLab.FindChild( DataTag_SplittedGroups ).ForgetAllAttributes();
520 double HYDROData_CalculationCase::GetAltitudeForPoint( const gp_XY& thePoint ) const
522 Handle(HYDROData_Zone) aZone = GetZoneFromPoint( thePoint );
523 return GetAltitudeForPoint( thePoint, aZone );
526 double HYDROData_CalculationCase::GetAltitudeForPoint( const gp_XY& thePoint,
527 const Handle(HYDROData_Zone)& theZone ) const
529 double aResAltitude = HYDROData_IAltitudeObject::GetInvalidAltitude();
530 if ( theZone.IsNull() )
533 HYDROData_Zone::MergeAltitudesType aZoneMergeType = theZone->GetMergeType();
534 if ( !theZone->IsMergingNeed() )
536 aZoneMergeType = HYDROData_Zone::Merge_UNKNOWN;
538 else if ( aZoneMergeType == HYDROData_Zone::Merge_UNKNOWN )
543 HYDROData_IInterpolator* aZoneInterpolator = theZone->GetInterpolator();
544 if ( aZoneMergeType == HYDROData_Zone::Merge_Object )
546 Handle(HYDROData_IAltitudeObject) aMergeAltitude = theZone->GetMergeAltitude();
547 if ( !aMergeAltitude.IsNull() )
549 if ( aZoneInterpolator != NULL )
551 aZoneInterpolator->SetAltitudeObject( aMergeAltitude );
552 aResAltitude = aZoneInterpolator->GetAltitudeForPoint( thePoint );
555 aResAltitude = aMergeAltitude->GetAltitudeForPoint( thePoint );
560 HYDROData_SequenceOfObjects aZoneObjects = theZone->GetGeometryObjects();
561 HYDROData_SequenceOfObjects::Iterator anIter( aZoneObjects );
562 for ( ; anIter.More(); anIter.Next() )
564 Handle(HYDROData_Object) aZoneObj =
565 Handle(HYDROData_Object)::DownCast( anIter.Value() );
566 if ( aZoneObj.IsNull() )
569 Handle(HYDROData_IAltitudeObject) anObjAltitude = aZoneObj->GetAltitudeObject();
570 if ( anObjAltitude.IsNull() )
573 double aPointAltitude = 0.0;
574 if ( aZoneInterpolator != NULL )
576 aZoneInterpolator->SetAltitudeObject( anObjAltitude );
577 aPointAltitude = aZoneInterpolator->GetAltitudeForPoint( thePoint );
580 aPointAltitude = anObjAltitude->GetAltitudeForPoint( thePoint );
582 if ( ValuesEquals( aPointAltitude, HYDROData_IAltitudeObject::GetInvalidAltitude() ) )
585 if ( aZoneMergeType == HYDROData_Zone::Merge_UNKNOWN )
587 aResAltitude = aPointAltitude;
590 else if ( aZoneMergeType == HYDROData_Zone::Merge_ZMIN )
592 if ( ValuesEquals( aResAltitude, HYDROData_IAltitudeObject::GetInvalidAltitude() ) ||
593 aResAltitude > aPointAltitude )
595 aResAltitude = aPointAltitude;
598 else if ( aZoneMergeType == HYDROData_Zone::Merge_ZMAX )
600 if ( ValuesEquals( aResAltitude, HYDROData_IAltitudeObject::GetInvalidAltitude() ) ||
601 aResAltitude < aPointAltitude )
603 aResAltitude = aPointAltitude;
612 NCollection_Sequence<double> HYDROData_CalculationCase::GetAltitudesForPoints(
613 const NCollection_Sequence<gp_XY>& thePoints,
614 const Handle(HYDROData_Zone)& theZone ) const
616 NCollection_Sequence<double> aResSeq;
618 for ( int i = 1, n = thePoints.Length(); i <= n; ++i )
620 const gp_XY& thePnt = thePoints.Value( i );
622 double anAltitude = GetAltitudeForPoint( thePnt, theZone );
623 aResSeq.Append( anAltitude );
629 Handle(HYDROData_Zone) HYDROData_CalculationCase::GetZoneFromPoint( const gp_XY& thePoint ) const
631 Handle(HYDROData_Zone) aResZone;
633 HYDROData_SequenceOfObjects aRegions = GetRegions();
635 HYDROData_SequenceOfObjects::Iterator anIter( aRegions );
636 for ( ; anIter.More() && aResZone.IsNull(); anIter.Next() )
638 Handle(HYDROData_Region) aRegion =
639 Handle(HYDROData_Region)::DownCast( anIter.Value() );
640 if ( aRegion.IsNull() )
643 HYDROData_SequenceOfObjects aZones = aRegion->GetZones();
644 HYDROData_SequenceOfObjects::Iterator aZonesIter( aZones );
645 for ( ; aZonesIter.More() && aResZone.IsNull(); aZonesIter.Next() )
647 Handle(HYDROData_Zone) aRegZone =
648 Handle(HYDROData_Zone)::DownCast( aZonesIter.Value() );
649 if ( aRegZone.IsNull() )
652 PointClassification aPointRelation = GetPointClassification( thePoint, aRegZone );
653 if ( aPointRelation != POINT_OUT )
654 aResZone = aRegZone; // We found the desired zone
661 HYDROData_CalculationCase::PointClassification HYDROData_CalculationCase::GetPointClassification(
662 const gp_XY& thePoint,
663 const Handle(HYDROData_Zone)& theZone ) const
665 PointClassification aRes = POINT_OUT;
666 if ( theZone.IsNull() )
669 TopoDS_Face aZoneFace = TopoDS::Face( theZone->GetShape() );
670 if ( aZoneFace.IsNull() )
673 TopAbs_State State = HYDROData_Tool::ComputePointState(thePoint, aZoneFace);
674 if (State == TopAbs_OUT)
676 else if(State == TopAbs_IN)
678 else if(State == TopAbs_ON)
683 Handle(HYDROData_Region) HYDROData_CalculationCase::addNewRegion()
685 TDF_Label aNewLab = myLab.FindChild( DataTag_ChildRegion ).NewChild();
687 Handle(HYDROData_Region) aNewRegion =
688 Handle(HYDROData_Region)::DownCast( HYDROData_Iterator::CreateObject( aNewLab, KIND_REGION ) );
689 AddRegion( aNewRegion );
694 Handle(HYDROData_SplittedShapesGroup) HYDROData_CalculationCase::addNewSplittedGroup()
696 TDF_Label aNewLab = myLab.FindChild( DataTag_SplittedGroups ).NewChild();
698 Handle(HYDROData_SplittedShapesGroup) aNewGroup =
699 Handle(HYDROData_SplittedShapesGroup)::DownCast(
700 HYDROData_Iterator::CreateObject( aNewLab, KIND_SPLITTED_GROUP ) );
701 AddReferenceObject( aNewGroup, DataTag_SplittedGroups );
706 bool HYDROData_CalculationCase::Export( GEOM::GEOM_Gen_var theGeomEngine,
707 SALOMEDS::Study_ptr theStudy ) const
709 HYDROData_ShapesGroup::SeqOfGroupsDefs aSeqOfGroupsDefs;
711 // Get groups definitions
712 HYDROData_SequenceOfObjects aSplittedGroups = GetSplittedGroups();
714 HYDROData_SequenceOfObjects::Iterator anIter( aSplittedGroups );
715 for ( ; anIter.More(); anIter.Next() )
718 Handle(HYDROData_ShapesGroup) aGroup =
719 Handle(HYDROData_ShapesGroup)::DownCast( anIter.Value() );
720 if ( aGroup.IsNull() )
723 HYDROData_ShapesGroup::GroupDefinition aGroupDef;
725 aGroupDef.Name = aGroup->GetName().toLatin1().constData();
726 aGroup->GetShapes( aGroupDef.Shapes );
728 aSeqOfGroupsDefs.Append( aGroupDef );
732 TopTools_ListOfShape aFaces;
733 HYDROData_SequenceOfObjects aCaseRegions = GetRegions();
734 HYDROData_SequenceOfObjects::Iterator aRegionIter( aCaseRegions );
735 for ( ; aRegionIter.More(); aRegionIter.Next() )
737 Handle(HYDROData_Region) aRegion =
738 Handle(HYDROData_Region)::DownCast( aRegionIter.Value() );
739 if( aRegion.IsNull() )
742 TopoDS_Shape aRegionShape = aRegion->GetShape( &aSeqOfGroupsDefs );
743 aFaces.Append( aRegionShape );
746 return Export( theGeomEngine, theStudy, aFaces, aSeqOfGroupsDefs );
749 bool HYDROData_CalculationCase::Export( GEOM::GEOM_Gen_var theGeomEngine,
750 SALOMEDS::Study_ptr theStudy,
751 const TopTools_ListOfShape& theFaces,
752 const HYDROData_ShapesGroup::SeqOfGroupsDefs& theGroupsDefs ) const
755 BRepBuilderAPI_Sewing aSewing( Precision::Confusion() * 10.0 );
756 aSewing.SetNonManifoldMode( Standard_False );
757 #ifdef DEB_CALCULATION
758 TCollection_AsciiString aNam("Sh_");
761 TopTools_ListIteratorOfListOfShape aFaceIter( theFaces );
762 for ( ; aFaceIter.More(); aFaceIter.Next() )
764 TopoDS_Shape aShape = aFaceIter.Value();
765 if ( aShape.IsNull() )
768 if ( aShape.ShapeType() == TopAbs_FACE )
770 aSewing.Add( aShape );
771 #ifdef DEB_CALCULATION
772 TCollection_AsciiString aName = aNam + ++i + ".brep";
773 BRepTools::Write(aShape ,aName.ToCString());
778 #ifdef DEB_CALCULATION
781 TopExp_Explorer anExp( aShape, TopAbs_FACE );
782 for (; anExp.More(); anExp.Next() ) {
783 aSewing.Add( anExp.Current() );
784 #ifdef DEB_CALCULATION
786 TCollection_AsciiString aName = aNam + i + "_" + ++j + ".brep";
787 BRepTools::Write(anExp.Current() ,aName.ToCString());
794 TopoDS_Shape aSewedShape = aSewing.SewedShape();
796 // If the sewed shape is empty - return false
797 if ( aSewedShape.IsNull() || !TopoDS_Iterator( aSewedShape ).More() )
800 #ifdef DEB_CALCULATION
801 BRepTools::Write(aSewedShape ,"Sew.brep");
803 // Publish the sewed shape
804 QString aName = EXPORT_NAME;
805 GEOM::GEOM_Object_ptr aMainShape =
806 publishShapeInGEOM( theGeomEngine, theStudy, aSewedShape, aName );
808 if ( aMainShape->_is_nil() )
811 if ( theGroupsDefs.IsEmpty() )
815 TopTools_IndexedMapOfShape aMapOfSubShapes;
816 TopExp::MapShapes( aSewedShape, aMapOfSubShapes );
818 NCollection_DataMap< TCollection_AsciiString, NCollection_Sequence<int> > aGroupsData;
820 for ( int aGrId = 1, nbGroups = theGroupsDefs.Length(); aGrId <= nbGroups; ++aGrId )
822 const HYDROData_ShapesGroup::GroupDefinition& aGroupDef = theGroupsDefs.Value( aGrId );
824 NCollection_Sequence<int> aGroupIndexes;
825 for( int i = 1, n = aGroupDef.Shapes.Length(); i <= n; i++ )
827 const TopoDS_Shape& aShape = aGroupDef.Shapes.Value( i );
828 #ifdef DEB_CALCULATION
829 cout << "\nOld shape(" << i << ") = " << aShape.TShape() <<endl;
831 const TopoDS_Shape& aModifiedShape = aSewing.Modified( aShape );
832 if ( aModifiedShape.IsNull() )
835 #ifdef DEB_CALCULATION
836 const TopLoc_Location& aL1 = aShape.Location();
837 const TopLoc_Location& aL2 = aModifiedShape.Location();
838 cout << "\nNew shape(" << i << ") = " << aModifiedShape.TShape() << " Location is Equal = " << aL1.IsEqual(aL2)<<endl;
841 int anIndex = aMapOfSubShapes.FindIndex(aModifiedShape);
843 aGroupIndexes.Append( anIndex );
845 #ifdef DEB_CALCULATION
846 TCollection_AsciiString aNam("Lost_");
847 if(!aMapOfSubShapes.Contains(aModifiedShape)) {
848 for ( int anIndex = 1; anIndex <= aMapOfSubShapes.Extent(); anIndex++ )
850 const TopoDS_Shape& aS = aMapOfSubShapes.FindKey( anIndex );
851 if ( aModifiedShape.IsPartner( aS ) )
853 cout <<"\nIndex in Map = " << anIndex << "TShape = " << aS.TShape() <<endl;
854 TCollection_AsciiString aName = aNam + i + "_" + anIndex + ".brep";
855 BRepTools::Write(aS ,aName.ToCString());
863 if ( !aGroupIndexes.IsEmpty() )
864 aGroupsData.Bind( aGroupDef.Name, aGroupIndexes );
867 if ( !aGroupsData.IsEmpty() )
869 GEOM::GEOM_IGroupOperations_var aGroupOp =
870 theGeomEngine->GetIGroupOperations( theStudy->StudyId() );
872 NCollection_DataMap< TCollection_AsciiString, NCollection_Sequence<int> >::Iterator aMapIt( aGroupsData );
873 for ( ; aMapIt.More(); aMapIt.Next() )
875 const TCollection_AsciiString& aGroupName = aMapIt.Key();
876 const NCollection_Sequence<int>& aGroupIndexes = aMapIt.Value();
878 GEOM::GEOM_Object_var aGeomGroup = aGroupOp->CreateGroup( aMainShape, TopAbs_EDGE );
879 if ( CORBA::is_nil( aGeomGroup ) || !aGroupOp->IsDone() )
882 GEOM::ListOfLong_var aGeomIndexes = new GEOM::ListOfLong;
883 aGeomIndexes->length( aGroupIndexes.Length() );
885 for( int i = 1, n = aGroupIndexes.Length(); i <= n; i++ )
886 aGeomIndexes[ i - 1 ] = aGroupIndexes.Value( i );
888 aGroupOp->UnionIDs( aGeomGroup, aGeomIndexes );
889 if ( aGroupOp->IsDone() )
891 SALOMEDS::SObject_var aGroupSO =
892 theGeomEngine->AddInStudy( theStudy, aGeomGroup, aGroupName.ToCString(), aMainShape );
900 GEOM::GEOM_Object_ptr HYDROData_CalculationCase::publishShapeInGEOM(
901 GEOM::GEOM_Gen_var theGeomEngine, SALOMEDS::Study_ptr theStudy,
902 const TopoDS_Shape& theShape, const QString& theName ) const
904 GEOM::GEOM_Object_var aGeomObj;
906 if ( theGeomEngine->_is_nil() || theStudy->_is_nil() ||
907 theShape.IsNull() ) {
908 return aGeomObj._retn();
911 std::ostringstream aStreamShape;
912 // Write TopoDS_Shape in ASCII format to the stream
913 BRepTools::Write( theShape, aStreamShape );
914 // Returns the number of bytes that have been stored in the stream's buffer.
915 int aSize = aStreamShape.str().size();
916 // Allocate octect buffer of required size
917 CORBA::Octet* anOctetBuf = SALOMEDS::TMPFile::allocbuf( aSize );
918 // Copy ostrstream content to the octect buffer
919 memcpy( anOctetBuf, aStreamShape.str().c_str(), aSize );
921 SALOMEDS::TMPFile_var aSeqFile = new SALOMEDS::TMPFile( aSize, aSize, anOctetBuf, 1 );
923 // Restore shape from the stream and get the GEOM object
924 GEOM::GEOM_IInsertOperations_var anInsOp = theGeomEngine->GetIInsertOperations( theStudy->StudyId() );
925 aGeomObj = anInsOp->RestoreShape( aSeqFile );
927 // Puplish the GEOM object
928 if ( !aGeomObj->_is_nil() ) {
929 QString aName = GEOMBase::GetDefaultName( theName );
931 SALOMEDS::SObject_var aResultSO =
932 theGeomEngine->PublishInStudy( theStudy, SALOMEDS::SObject::_nil(),
933 aGeomObj, qPrintable( aName ) );
934 if ( aResultSO->_is_nil() ) {
935 aGeomObj = GEOM::GEOM_Object::_nil();
939 return aGeomObj._retn();