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 PYTHON_CALCULATION_ID "KIND_CALCULATION"
16 IMPLEMENT_STANDARD_HANDLE(HYDROData_CalculationCase, HYDROData_Entity)
17 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_CalculationCase, HYDROData_Entity)
19 HYDROData_CalculationCase::HYDROData_CalculationCase()
24 HYDROData_CalculationCase::~HYDROData_CalculationCase()
28 QStringList HYDROData_CalculationCase::DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const
32 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
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_CalculationCase::SplitGeometryObjects()
78 // At first we remove previously created regions
81 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
82 if ( aDocument.IsNull() )
85 Handle(HYDROData_Polyline) aBoundaryPolyline = GetBoundaryPolyline();
86 HYDROData_SequenceOfObjects aGeomObjects = GetGeometryObjects();
87 if ( aGeomObjects.IsEmpty() )
90 HYDROData_SplitToZonesTool::SplitDataList aSplitedZones =
91 HYDROData_SplitToZonesTool::SplitToZones( aGeomObjects, aBoundaryPolyline );
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();
104 QString aRegionName = HYDROData_Tool::GenerateObjectName( aDocument, "Region" );
105 aRegion->SetName( aRegionName );
107 // Add the zone for region
108 Handle(HYDROData_Zone) aRegionZone = aRegion->addNewZone();
110 QString aZoneName = HYDROData_Tool::GenerateObjectName( aDocument, "Zone" );
111 aRegionZone->SetName( aZoneName );
113 aRegionZone->SetShape( aSplitData.Face() );
115 // Add the reference object for zone
116 for ( int i = 0, n = aSplitData.ObjectNames.length(); i < n; ++i )
118 const QString& anObjName = aSplitData.ObjectNames.at( i );
120 Handle(HYDROData_Object) aRefObject = Handle(HYDROData_Object)::DownCast(
121 HYDROData_Tool::FindObjectByName( aDocument, anObjName ) );
122 if ( aRefObject.IsNull() )
125 aRegionZone->AddGeometryObject( aRefObject );
129 // The splitted data is up to date
130 SetToUpdate( false );
133 bool HYDROData_CalculationCase::AddGeometryObject( const Handle(HYDROData_Object)& theObject )
135 if ( !HYDROData_Tool::IsGeometryObject( theObject ) )
136 return false; // Wrong type of object
138 if ( HasReference( theObject, DataTag_GeometryObject ) )
139 return false; // Object is already in reference list
141 AddReferenceObject( theObject, DataTag_GeometryObject );
143 // Indicate model of the need to update zones splitting
149 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetGeometryObjects() const
151 return GetReferenceObjects( DataTag_GeometryObject );
154 void HYDROData_CalculationCase::RemoveGeometryObject( const Handle(HYDROData_Object)& theObject )
156 if ( theObject.IsNull() )
159 RemoveReferenceObject( theObject->Label(), DataTag_GeometryObject );
161 // Indicate model of the need to update zones splitting
165 void HYDROData_CalculationCase::RemoveGeometryObjects()
167 ClearReferenceObjects( DataTag_GeometryObject );
169 // Indicate model of the need to update zones splitting
173 void HYDROData_CalculationCase::SetBoundaryPolyline( const Handle(HYDROData_Polyline)& thePolyline )
175 SetReferenceObject( thePolyline, DataTag_Polyline );
178 Handle(HYDROData_Polyline) HYDROData_CalculationCase::GetBoundaryPolyline() const
180 return Handle(HYDROData_Polyline)::DownCast(
181 GetReferenceObject( DataTag_Polyline ) );
184 void HYDROData_CalculationCase::RemoveBoundaryPolyline()
186 ClearReferenceObjects( DataTag_Polyline );
189 Handle(HYDROData_Region) HYDROData_CalculationCase::AddNewRegion( const Handle(HYDROData_Zone)& theZone )
191 Handle(HYDROData_Region) aNewRegion = addNewRegion();
192 if ( aNewRegion.IsNull() )
195 // Generate new name for new region
196 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
197 if ( !aDocument.IsNull() )
199 QString aNewRegionName = HYDROData_Tool::GenerateObjectName( aDocument, "Region" );
200 aNewRegion->SetName( aNewRegionName );
203 aNewRegion->AddZone( theZone );
208 bool HYDROData_CalculationCase::AddRegion( const Handle(HYDROData_Region)& theRegion )
210 if ( theRegion.IsNull() )
213 if ( HasReference( theRegion, DataTag_Region ) )
214 return false; // Object is already in reference list
216 // Move the region from other calculation
217 Handle(HYDROData_CalculationCase) aFatherCalc =
218 Handle(HYDROData_CalculationCase)::DownCast( theRegion->GetFatherObject() );
219 if ( !aFatherCalc.IsNull() && aFatherCalc->Label() != myLab )
221 Handle(HYDROData_Region) aNewRegion = addNewRegion();
222 theRegion->CopyTo( aNewRegion );
224 aFatherCalc->RemoveRegion( theRegion );
226 theRegion->SetLabel( aNewRegion->Label() );
230 AddReferenceObject( theRegion, DataTag_Region );
236 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetRegions() const
238 return GetReferenceObjects( DataTag_Region );
241 void HYDROData_CalculationCase::RemoveRegion( const Handle(HYDROData_Region)& theRegion )
243 if ( theRegion.IsNull() )
246 RemoveReferenceObject( theRegion->Label(), DataTag_Region );
248 // Remove region from data model
249 Handle(HYDROData_CalculationCase) aFatherCalc =
250 Handle(HYDROData_CalculationCase)::DownCast( theRegion->GetFatherObject() );
251 if ( !aFatherCalc.IsNull() && aFatherCalc->Label() == myLab )
255 void HYDROData_CalculationCase::RemoveRegions()
257 ClearReferenceObjects( DataTag_Region );
258 myLab.FindChild( DataTag_ChildRegion ).ForgetAllAttributes( true );
261 Handle(HYDROData_Region) HYDROData_CalculationCase::addNewRegion()
263 TDF_Label aNewLab = myLab.FindChild( DataTag_ChildRegion ).NewChild();
265 Handle(HYDROData_Region) aNewRegion =
266 Handle(HYDROData_Region)::DownCast( HYDROData_Iterator::CreateObject( aNewLab, KIND_REGION ) );
267 AddRegion( aNewRegion );