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_Polyline.h"
9 #include "HYDROData_SplitToZonesTool.h"
10 #include "HYDROData_Region.h"
11 #include "HYDROData_Tool.h"
12 #include "HYDROData_Zone.h"
14 #define CALCULATION_REGIONS_PREF GetName() + "_Reg"
15 #define CALCULATION_ZONES_PREF GetName() + "_Zone"
17 #define PYTHON_CALCULATION_ID "KIND_CALCULATION"
19 IMPLEMENT_STANDARD_HANDLE(HYDROData_CalculationCase, HYDROData_Entity)
20 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_CalculationCase, HYDROData_Entity)
22 HYDROData_CalculationCase::HYDROData_CalculationCase()
27 HYDROData_CalculationCase::~HYDROData_CalculationCase()
31 QStringList HYDROData_CalculationCase::DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const
35 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
36 if ( aDocument.IsNull() )
39 QString aDocName = aDocument->GetDocPyName();
40 QString aCalculName = GetName();
42 aResList << QString( "%1 = %2.CreateObject( %3 );" )
43 .arg( aCalculName ).arg( aDocName ).arg( PYTHON_CALCULATION_ID );
44 aResList << QString( "%1.SetName( \"%2\" );" )
45 .arg( aCalculName ).arg( aCalculName );
46 aResList << QString( "" );
48 HYDROData_SequenceOfObjects aGeomObjects = GetGeometryObjects();
49 HYDROData_SequenceOfObjects::Iterator anIter( aGeomObjects );
50 for ( ; anIter.More(); anIter.Next() )
52 Handle(HYDROData_Object) aRefGeomObj =
53 Handle(HYDROData_Object)::DownCast( anIter.Value() );
54 if ( !aRefGeomObj.IsNull() )
55 setPythonReferenceObject( theTreatedObjects, aResList, aRefGeomObj, "AddGeometryObject" );
57 aResList << QString( "" );
59 aResList << QString( "%1.SplitGeometryObjects();" ).arg( aCalculName );
60 aResList << QString( "" );
62 // Now we restore the regions and zones order
63 HYDROData_SequenceOfObjects aRegions = GetRegions();
64 anIter.Init( aRegions );
65 for ( ; anIter.More(); anIter.Next() )
67 Handle(HYDROData_Region) aRegion =
68 Handle(HYDROData_Region)::DownCast( anIter.Value() );
69 if ( aRegion.IsNull() )
72 QString aRegionName = aRegion->GetName();
79 void HYDROData_CalculationCase::SplitGeometryObjects()
81 // At first we remove previously created regions
84 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
85 if ( aDocument.IsNull() )
88 Handle(HYDROData_Polyline) aBoundaryPolyline = GetBoundaryPolyline();
89 HYDROData_SequenceOfObjects aGeomObjects = GetGeometryObjects();
90 if ( aGeomObjects.IsEmpty() )
93 HYDROData_SplitToZonesTool::SplitDataList aSplitedZones =
94 HYDROData_SplitToZonesTool::SplitToZones( aGeomObjects, aBoundaryPolyline );
95 if ( aSplitedZones.isEmpty() )
98 QString aRegsPref = CALCULATION_REGIONS_PREF;
99 QString aZonesPref = CALCULATION_ZONES_PREF;
101 // Create result regions for case, by default one zone for one region
102 HYDROData_SplitToZonesTool::SplitDataListIterator anIter( aSplitedZones );
103 while( anIter.hasNext() )
105 const HYDROData_SplitToZonesTool::SplitData& aSplitData = anIter.next();
108 Handle(HYDROData_Region) aRegion = addNewRegion();
110 QString aRegionName = HYDROData_Tool::GenerateObjectName( aDocument, aRegsPref );
111 aRegion->SetName( aRegionName );
113 // Add the zone for region
114 Handle(HYDROData_Zone) aRegionZone = aRegion->addNewZone();
116 QString aZoneName = HYDROData_Tool::GenerateObjectName( aDocument, aZonesPref );
117 aRegionZone->SetName( aZoneName );
119 aRegionZone->SetShape( aSplitData.Face() );
121 // Add the reference object for zone
122 for ( int i = 0, n = aSplitData.ObjectNames.length(); i < n; ++i )
124 const QString& anObjName = aSplitData.ObjectNames.at( i );
126 Handle(HYDROData_Object) aRefObject = Handle(HYDROData_Object)::DownCast(
127 HYDROData_Tool::FindObjectByName( aDocument, anObjName ) );
128 if ( aRefObject.IsNull() )
131 aRegionZone->AddGeometryObject( aRefObject );
135 // The splitted data is up to date
136 SetToUpdate( false );
139 bool HYDROData_CalculationCase::AddGeometryObject( const Handle(HYDROData_Object)& theObject )
141 if ( !HYDROData_Tool::IsGeometryObject( theObject ) )
142 return false; // Wrong type of object
144 if ( HasReference( theObject, DataTag_GeometryObject ) )
145 return false; // Object is already in reference list
147 AddReferenceObject( theObject, DataTag_GeometryObject );
149 // Indicate model of the need to update zones splitting
155 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetGeometryObjects() const
157 return GetReferenceObjects( DataTag_GeometryObject );
160 void HYDROData_CalculationCase::RemoveGeometryObject( const Handle(HYDROData_Object)& theObject )
162 if ( theObject.IsNull() )
165 RemoveReferenceObject( theObject->Label(), DataTag_GeometryObject );
167 // Indicate model of the need to update zones splitting
171 void HYDROData_CalculationCase::RemoveGeometryObjects()
173 ClearReferenceObjects( DataTag_GeometryObject );
175 // Indicate model of the need to update zones splitting
179 void HYDROData_CalculationCase::SetBoundaryPolyline( const Handle(HYDROData_Polyline)& thePolyline )
181 Handle(HYDROData_Polyline) aPrevPolyline = GetBoundaryPolyline();
183 SetReferenceObject( thePolyline, DataTag_Polyline );
185 // Indicate model of the need to update zones splitting
186 SetToUpdate( !IsEqual( aPrevPolyline, thePolyline ) || IsMustBeUpdated() );
189 Handle(HYDROData_Polyline) HYDROData_CalculationCase::GetBoundaryPolyline() const
191 return Handle(HYDROData_Polyline)::DownCast(
192 GetReferenceObject( DataTag_Polyline ) );
195 void HYDROData_CalculationCase::RemoveBoundaryPolyline()
197 Handle(HYDROData_Polyline) aPrevPolyline = GetBoundaryPolyline();
199 ClearReferenceObjects( DataTag_Polyline );
201 // Indicate model of the need to update zones splitting
202 SetToUpdate( !aPrevPolyline.IsNull() || IsMustBeUpdated() );
205 Handle(HYDROData_Region) HYDROData_CalculationCase::AddNewRegion( const Handle(HYDROData_Zone)& theZone )
207 Handle(HYDROData_Region) aNewRegion = addNewRegion();
208 if ( aNewRegion.IsNull() )
211 // Generate new name for new region
212 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
213 if ( !aDocument.IsNull() )
215 QString aRegsPref = CALCULATION_REGIONS_PREF;
217 QString aNewRegionName = HYDROData_Tool::GenerateObjectName( aDocument, aRegsPref );
218 aNewRegion->SetName( aNewRegionName );
221 aNewRegion->AddZone( theZone );
226 bool HYDROData_CalculationCase::AddRegion( const Handle(HYDROData_Region)& theRegion )
228 if ( theRegion.IsNull() )
231 if ( HasReference( theRegion, DataTag_Region ) )
232 return false; // Object is already in reference list
234 // Move the region from other calculation
235 Handle(HYDROData_CalculationCase) aFatherCalc =
236 Handle(HYDROData_CalculationCase)::DownCast( theRegion->GetFatherObject() );
237 if ( !aFatherCalc.IsNull() && aFatherCalc->Label() != myLab )
239 Handle(HYDROData_Region) aNewRegion = addNewRegion();
240 theRegion->CopyTo( aNewRegion );
242 aFatherCalc->RemoveRegion( theRegion );
244 theRegion->SetLabel( aNewRegion->Label() );
248 AddReferenceObject( theRegion, DataTag_Region );
254 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetRegions() const
256 return GetReferenceObjects( DataTag_Region );
259 void HYDROData_CalculationCase::UpdateRegionsOrder()
261 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
262 if ( aDocument.IsNull() )
265 HYDROData_SequenceOfObjects aRegions = GetRegions();
267 HYDROData_SequenceOfObjects::Iterator anIter( aRegions );
268 for ( ; anIter.More(); anIter.Next() )
270 Handle(HYDROData_Region) aRegion =
271 Handle(HYDROData_Region)::DownCast( anIter.Value() );
272 if ( aRegion.IsNull() )
275 aRegion->SetName( "" );
278 QString aRegsPref = CALCULATION_REGIONS_PREF;
280 anIter.Init( aRegions );
281 for ( ; anIter.More(); anIter.Next() )
283 Handle(HYDROData_Region) aRegion =
284 Handle(HYDROData_Region)::DownCast( anIter.Value() );
285 if ( aRegion.IsNull() )
288 QString aRegionName = HYDROData_Tool::GenerateObjectName( aDocument, aRegsPref );
289 aRegion->SetName( aRegionName );
293 void HYDROData_CalculationCase::RemoveRegion( const Handle(HYDROData_Region)& theRegion )
295 if ( theRegion.IsNull() )
298 RemoveReferenceObject( theRegion->Label(), DataTag_Region );
300 // Remove region from data model
301 Handle(HYDROData_CalculationCase) aFatherCalc =
302 Handle(HYDROData_CalculationCase)::DownCast( theRegion->GetFatherObject() );
303 if ( !aFatherCalc.IsNull() && aFatherCalc->Label() == myLab )
307 void HYDROData_CalculationCase::RemoveRegions()
309 ClearReferenceObjects( DataTag_Region );
310 myLab.FindChild( DataTag_ChildRegion ).ForgetAllAttributes( true );
313 Handle(HYDROData_Region) HYDROData_CalculationCase::addNewRegion()
315 TDF_Label aNewLab = myLab.FindChild( DataTag_ChildRegion ).NewChild();
317 Handle(HYDROData_Region) aNewRegion =
318 Handle(HYDROData_Region)::DownCast( HYDROData_Iterator::CreateObject( aNewLab, KIND_REGION ) );
319 AddRegion( aNewRegion );