2 #include "HYDROData_Calculation.h"
4 #include "HYDROData_Document.h"
5 #include "HYDROData_Iterator.h"
6 #include "HYDROData_Object.h"
7 #include "HYDROData_SplitToZonesTool.h"
8 #include "HYDROData_Region.h"
9 #include "HYDROData_Tool.h"
10 #include "HYDROData_Zone.h"
12 #include <QStringList>
14 #define PYTHON_CALCULATION_ID "KIND_CALCULATION"
16 IMPLEMENT_STANDARD_HANDLE(HYDROData_Calculation, HYDROData_Entity)
17 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_Calculation, HYDROData_Entity)
19 HYDROData_Calculation::HYDROData_Calculation()
24 HYDROData_Calculation::~HYDROData_Calculation()
28 QStringList HYDROData_Calculation::DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const
32 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( this );
33 if ( aDocument.IsNull() )
36 QString aDocName = aDocument->GetDocPyName();
37 QString aCalculName = GetName();
39 aResList << QString( "%1 = %2.CreateObject( %3 );" )
40 .arg( aCalculName ).arg( aDocName ).arg( PYTHON_CALCULATION_ID );
41 aResList << QString( "%1.SetName( \"%2\" );" )
42 .arg( aCalculName ).arg( aCalculName );
43 aResList << QString( "" );
45 HYDROData_SequenceOfObjects aGeomObjects = GetGeometryObjects();
46 HYDROData_SequenceOfObjects::Iterator anIter( aGeomObjects );
47 for ( ; anIter.More(); anIter.Next() )
49 Handle(HYDROData_Object) aRefGeomObj =
50 Handle(HYDROData_Object)::DownCast( anIter.Value() );
51 if ( !aRefGeomObj.IsNull() )
52 setPythonReferenceObject( theTreatedObjects, aResList, aRefGeomObj, "AddGeometryObject" );
54 aResList << QString( "" );
56 aResList << QString( "%1.SplitGeometryObjects();" ).arg( aCalculName );
57 aResList << QString( "" );
59 // Now we restore the regions and zones order
60 HYDROData_SequenceOfObjects aRegions = GetRegions();
61 anIter.Init( aRegions );
62 for ( ; anIter.More(); anIter.Next() )
64 Handle(HYDROData_Region) aRegion =
65 Handle(HYDROData_Region)::DownCast( anIter.Value() );
66 if ( aRegion.IsNull() )
69 QString aRegionName = aRegion->GetName();
76 void HYDROData_Calculation::SplitGeometryObjects()
78 // At first we remove previously created regions
82 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( this );
83 if ( aDocument.IsNull() )
86 HYDROData_SequenceOfObjects aGeomObjects = GetGeometryObjects();
87 if ( aGeomObjects.IsEmpty() )
90 HYDROData_SplitToZonesTool::SplitDataList aSplitedZones =
91 HYDROData_SplitToZonesTool::SplitToZones( aGeomObjects );
92 if ( aSplitedZones.isEmpty() )
95 // Create result regions for case, by default one zone for one region
96 HYDROData_SplitToZonesTool::SplitDataListIterator anIter( aSplitedZones );
97 while( anIter.hasNext() )
99 const HYDROData_SplitToZonesTool::SplitData& aSplitData = anIter.next();
102 Handle(HYDROData_Region) aRegion = AddNewRegion();
103 AddRegion( aRegion );
105 QString aRegionName = HYDROData_Tool::GenerateObjectName( aDocument, "Region" );
106 aRegion->SetName( aRegionName );
108 // Add the zone for region
109 Handle(HYDROData_Zone) aRegionZone = aRegion->AddNewZone();
110 aRegion->AddZone( aRegionZone );
112 QString aZoneName = HYDROData_Tool::GenerateObjectName( aDocument, "Zone" );
113 aRegionZone->SetName( aZoneName );
115 aRegionZone->SetShape( aSplitData.Face() );
117 // Add the reference object for zone
118 for ( int i = 0, n = aSplitData.ObjectNames.length(); i < n; ++i )
120 const QString& anObjName = aSplitData.ObjectNames.at( i );
122 Handle(HYDROData_Object) aRefObject = Handle(HYDROData_Object)::DownCast(
123 HYDROData_Tool::FindObjectByName( aDocument, anObjName ) );
124 if ( aRefObject.IsNull() )
127 aRegionZone->AddGeometryObject( aRefObject );
132 int HYDROData_Calculation::NbGeometryObjects() const
134 return NbReferenceObjects( DataTag_GeometryObject );
137 void HYDROData_Calculation::AddGeometryObject( const Handle(HYDROData_Object)& theObject )
139 AddReferenceObject( theObject, DataTag_GeometryObject );
142 void HYDROData_Calculation::SetGeometryObject( const int theIndex,
143 const Handle(HYDROData_Object)& theObject )
145 SetReferenceObject( theObject, DataTag_GeometryObject, theIndex );
148 void HYDROData_Calculation::SetGeometryObjects( const HYDROData_SequenceOfObjects& theObjects )
150 SetReferenceObjects( theObjects, DataTag_GeometryObject );
153 Handle(HYDROData_Object) HYDROData_Calculation::GetGeometryObject( const int theIndex ) const
155 return Handle(HYDROData_Object)::DownCast(
156 GetReferenceObject( DataTag_GeometryObject, theIndex ) );
159 HYDROData_SequenceOfObjects HYDROData_Calculation::GetGeometryObjects() const
161 return GetReferenceObjects( DataTag_GeometryObject );
164 void HYDROData_Calculation::RemoveGeometryObjects()
166 ClearReferenceObjects( DataTag_GeometryObject );
169 Handle(HYDROData_Region) HYDROData_Calculation::AddNewRegion()
171 TDF_Label aNewLab = myLab.FindChild( ChildTag_Region ).NewChild();
173 return Handle(HYDROData_Region)::DownCast(
174 HYDROData_Iterator::CreateObject( aNewLab, KIND_REGION ) );
177 void HYDROData_Calculation::RemoveChildRegions()
179 myLab.FindChild( ChildTag_Region ).ForgetAllAttributes( true );
182 int HYDROData_Calculation::NbRegions() const
184 return NbReferenceObjects( DataTag_Region );
187 void HYDROData_Calculation::AddRegion( const Handle(HYDROData_Region)& theRegion )
189 AddReferenceObject( theRegion, DataTag_Region );
192 void HYDROData_Calculation::SetRegion( const int theIndex,
193 const Handle(HYDROData_Region)& theRegion )
195 SetReferenceObject( theRegion, DataTag_Region, theIndex );
198 void HYDROData_Calculation::InsertRegion( const int theBeforeIndex,
199 const Handle(HYDROData_Region)& theRegion )
201 InsertReferenceObject( theRegion, DataTag_Region, theBeforeIndex );
204 void HYDROData_Calculation::SetRegions( const HYDROData_SequenceOfObjects& theRegions )
206 SetReferenceObjects( theRegions, DataTag_Region );
209 Handle(HYDROData_Region) HYDROData_Calculation::GetRegion( const int theIndex ) const
211 return Handle(HYDROData_Region)::DownCast(
212 GetReferenceObject( DataTag_Region, theIndex ) );
215 HYDROData_SequenceOfObjects HYDROData_Calculation::GetRegions() const
217 return GetReferenceObjects( DataTag_Region );
220 void HYDROData_Calculation::RemoveRegion( const Handle(HYDROData_Region)& theRegion )
222 if ( theRegion.IsNull() )
225 RemoveReferenceObject( theRegion->Label(), DataTag_Region );
228 void HYDROData_Calculation::RemoveRegion( const int theIndex )
230 RemoveReferenceObject( DataTag_Region, theIndex );
233 void HYDROData_Calculation::RemoveRegions()
235 ClearReferenceObjects( DataTag_Region );