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 Handle(HYDROData_Polyline) aPrevPolyline = GetBoundaryPolyline();
177 SetReferenceObject( thePolyline, DataTag_Polyline );
179 // Indicate model of the need to update zones splitting
180 SetToUpdate( !IsEqual( aPrevPolyline, thePolyline ) || IsMustBeUpdated() );
183 Handle(HYDROData_Polyline) HYDROData_CalculationCase::GetBoundaryPolyline() const
185 return Handle(HYDROData_Polyline)::DownCast(
186 GetReferenceObject( DataTag_Polyline ) );
189 void HYDROData_CalculationCase::RemoveBoundaryPolyline()
191 Handle(HYDROData_Polyline) aPrevPolyline = GetBoundaryPolyline();
193 ClearReferenceObjects( DataTag_Polyline );
195 // Indicate model of the need to update zones splitting
196 SetToUpdate( !aPrevPolyline.IsNull() || IsMustBeUpdated() );
199 Handle(HYDROData_Region) HYDROData_CalculationCase::AddNewRegion( const Handle(HYDROData_Zone)& theZone )
201 Handle(HYDROData_Region) aNewRegion = addNewRegion();
202 if ( aNewRegion.IsNull() )
205 // Generate new name for new region
206 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
207 if ( !aDocument.IsNull() )
209 QString aNewRegionName = HYDROData_Tool::GenerateObjectName( aDocument, "Region" );
210 aNewRegion->SetName( aNewRegionName );
213 aNewRegion->AddZone( theZone );
218 bool HYDROData_CalculationCase::AddRegion( const Handle(HYDROData_Region)& theRegion )
220 if ( theRegion.IsNull() )
223 if ( HasReference( theRegion, DataTag_Region ) )
224 return false; // Object is already in reference list
226 // Move the region from other calculation
227 Handle(HYDROData_CalculationCase) aFatherCalc =
228 Handle(HYDROData_CalculationCase)::DownCast( theRegion->GetFatherObject() );
229 if ( !aFatherCalc.IsNull() && aFatherCalc->Label() != myLab )
231 Handle(HYDROData_Region) aNewRegion = addNewRegion();
232 theRegion->CopyTo( aNewRegion );
234 aFatherCalc->RemoveRegion( theRegion );
236 theRegion->SetLabel( aNewRegion->Label() );
240 AddReferenceObject( theRegion, DataTag_Region );
246 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetRegions() const
248 return GetReferenceObjects( DataTag_Region );
251 void HYDROData_CalculationCase::RemoveRegion( const Handle(HYDROData_Region)& theRegion )
253 if ( theRegion.IsNull() )
256 RemoveReferenceObject( theRegion->Label(), DataTag_Region );
258 // Remove region from data model
259 Handle(HYDROData_CalculationCase) aFatherCalc =
260 Handle(HYDROData_CalculationCase)::DownCast( theRegion->GetFatherObject() );
261 if ( !aFatherCalc.IsNull() && aFatherCalc->Label() == myLab )
265 void HYDROData_CalculationCase::RemoveRegions()
267 ClearReferenceObjects( DataTag_Region );
268 myLab.FindChild( DataTag_ChildRegion ).ForgetAllAttributes( true );
271 Handle(HYDROData_Region) HYDROData_CalculationCase::addNewRegion()
273 TDF_Label aNewLab = myLab.FindChild( DataTag_ChildRegion ).NewChild();
275 Handle(HYDROData_Region) aNewRegion =
276 Handle(HYDROData_Region)::DownCast( HYDROData_Iterator::CreateObject( aNewLab, KIND_REGION ) );
277 AddRegion( aNewRegion );