2 #include "HYDROData_CalculationCase.h"
4 #include "HYDROData_ArtificialObject.h"
5 #include "HYDROData_Document.h"
6 #include "HYDROData_Iterator.h"
7 #include "HYDROData_NaturalObject.h"
8 #include "HYDROData_SplitToZonesTool.h"
9 #include "HYDROData_Region.h"
10 #include "HYDROData_Tool.h"
11 #include "HYDROData_Zone.h"
13 #define PYTHON_CALCULATION_ID "KIND_CALCULATION"
15 IMPLEMENT_STANDARD_HANDLE(HYDROData_CalculationCase, HYDROData_Entity)
16 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_CalculationCase, HYDROData_Entity)
18 HYDROData_CalculationCase::HYDROData_CalculationCase()
23 HYDROData_CalculationCase::~HYDROData_CalculationCase()
27 QStringList HYDROData_CalculationCase::DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const
31 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
32 if ( aDocument.IsNull() )
35 QString aDocName = aDocument->GetDocPyName();
36 QString aCalculName = GetName();
38 aResList << QString( "%1 = %2.CreateObject( %3 );" )
39 .arg( aCalculName ).arg( aDocName ).arg( PYTHON_CALCULATION_ID );
40 aResList << QString( "%1.SetName( \"%2\" );" )
41 .arg( aCalculName ).arg( aCalculName );
42 aResList << QString( "" );
44 HYDROData_SequenceOfObjects aGeomObjects = GetGeometryObjects();
45 HYDROData_SequenceOfObjects::Iterator anIter( aGeomObjects );
46 for ( ; anIter.More(); anIter.Next() )
48 Handle(HYDROData_Object) aRefGeomObj =
49 Handle(HYDROData_Object)::DownCast( anIter.Value() );
50 if ( !aRefGeomObj.IsNull() )
51 setPythonReferenceObject( theTreatedObjects, aResList, aRefGeomObj, "AddGeometryObject" );
53 aResList << QString( "" );
55 aResList << QString( "%1.SplitGeometryObjects();" ).arg( aCalculName );
56 aResList << QString( "" );
58 // Now we restore the regions and zones order
59 HYDROData_SequenceOfObjects aRegions = GetRegions();
60 anIter.Init( aRegions );
61 for ( ; anIter.More(); anIter.Next() )
63 Handle(HYDROData_Region) aRegion =
64 Handle(HYDROData_Region)::DownCast( anIter.Value() );
65 if ( aRegion.IsNull() )
68 QString aRegionName = aRegion->GetName();
75 void HYDROData_CalculationCase::SplitGeometryObjects()
77 // At first we remove previously created regions
80 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
81 if ( aDocument.IsNull() )
84 HYDROData_SequenceOfObjects aGeomObjects = GetGeometryObjects();
85 if ( aGeomObjects.IsEmpty() )
88 HYDROData_SplitToZonesTool::SplitDataList aSplitedZones =
89 HYDROData_SplitToZonesTool::SplitToZones( aGeomObjects );
90 if ( aSplitedZones.isEmpty() )
93 // Create result regions for case, by default one zone for one region
94 HYDROData_SplitToZonesTool::SplitDataListIterator anIter( aSplitedZones );
95 while( anIter.hasNext() )
97 const HYDROData_SplitToZonesTool::SplitData& aSplitData = anIter.next();
100 Handle(HYDROData_Region) aRegion = addNewRegion();
102 QString aRegionName = HYDROData_Tool::GenerateObjectName( aDocument, "Region" );
103 aRegion->SetName( aRegionName );
105 // Add the zone for region
106 Handle(HYDROData_Zone) aRegionZone = aRegion->addNewZone();
108 QString aZoneName = HYDROData_Tool::GenerateObjectName( aDocument, "Zone" );
109 aRegionZone->SetName( aZoneName );
111 aRegionZone->SetShape( aSplitData.Face() );
113 // Add the reference object for zone
114 for ( int i = 0, n = aSplitData.ObjectNames.length(); i < n; ++i )
116 const QString& anObjName = aSplitData.ObjectNames.at( i );
118 Handle(HYDROData_Object) aRefObject = Handle(HYDROData_Object)::DownCast(
119 HYDROData_Tool::FindObjectByName( aDocument, anObjName ) );
120 if ( aRefObject.IsNull() )
123 aRegionZone->AddGeometryObject( aRefObject );
128 bool HYDROData_CalculationCase::AddGeometryObject( const Handle(HYDROData_Object)& theObject )
130 if ( theObject.IsNull() )
133 if ( !theObject->IsKind( STANDARD_TYPE(HYDROData_ArtificialObject) ) &&
134 !theObject->IsKind( STANDARD_TYPE(HYDROData_NaturalObject) ) )
135 return false; // Wrong type of object
137 if ( HasReference( theObject, DataTag_GeometryObject ) )
138 return false; // Object is already in reference list
140 AddReferenceObject( theObject, DataTag_GeometryObject );
144 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetGeometryObjects() const
146 return GetReferenceObjects( DataTag_GeometryObject );
149 void HYDROData_CalculationCase::RemoveGeometryObject( const Handle(HYDROData_Object)& theObject )
151 if ( theObject.IsNull() )
154 RemoveReferenceObject( theObject->Label(), DataTag_GeometryObject );
157 void HYDROData_CalculationCase::RemoveGeometryObjects()
159 ClearReferenceObjects( DataTag_GeometryObject );
162 Handle(HYDROData_Region) HYDROData_CalculationCase::AddNewRegion( const Handle(HYDROData_Zone)& theZone )
164 Handle(HYDROData_Region) aNewRegion = addNewRegion();
165 if ( aNewRegion.IsNull() )
168 // Generate new name for new region
169 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
170 if ( !aDocument.IsNull() )
172 QString aNewRegionName = HYDROData_Tool::GenerateObjectName( aDocument, "Region" );
173 aNewRegion->SetName( aNewRegionName );
176 aNewRegion->AddZone( theZone );
181 bool HYDROData_CalculationCase::AddRegion( const Handle(HYDROData_Region)& theRegion )
183 if ( theRegion.IsNull() )
186 if ( HasReference( theRegion, DataTag_Region ) )
187 return false; // Object is already in reference list
189 // Move the region from other calculation
190 Handle(HYDROData_CalculationCase) aFatherCalc =
191 Handle(HYDROData_CalculationCase)::DownCast( theRegion->GetFatherObject() );
192 if ( !aFatherCalc.IsNull() && aFatherCalc->Label() != myLab )
194 Handle(HYDROData_Region) aNewRegion = addNewRegion();
195 theRegion->CopyTo( aNewRegion );
197 aFatherCalc->RemoveRegion( theRegion );
199 theRegion->SetLabel( aNewRegion->Label() );
203 AddReferenceObject( theRegion, DataTag_Region );
209 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetRegions() const
211 return GetReferenceObjects( DataTag_Region );
214 void HYDROData_CalculationCase::RemoveRegion( const Handle(HYDROData_Region)& theRegion )
216 if ( theRegion.IsNull() )
219 RemoveReferenceObject( theRegion->Label(), DataTag_Region );
221 // Remove region from data model
222 Handle(HYDROData_CalculationCase) aFatherCalc =
223 Handle(HYDROData_CalculationCase)::DownCast( theRegion->GetFatherObject() );
224 if ( !aFatherCalc.IsNull() && aFatherCalc->Label() == myLab )
228 void HYDROData_CalculationCase::RemoveRegions()
230 ClearReferenceObjects( DataTag_Region );
231 myLab.FindChild( DataTag_ChildRegion ).ForgetAllAttributes( true );
234 Handle(HYDROData_Region) HYDROData_CalculationCase::addNewRegion()
236 TDF_Label aNewLab = myLab.FindChild( DataTag_ChildRegion ).NewChild();
238 Handle(HYDROData_Region) aNewRegion =
239 Handle(HYDROData_Region)::DownCast( HYDROData_Iterator::CreateObject( aNewLab, KIND_REGION ) );
240 AddRegion( aNewRegion );