+bool HYDROData_Region::CanBeUpdated() const
+{
+ return false;
+}
+
+void HYDROData_Region::Remove()
+{
+ Handle(HYDROData_CalculationCase) aFatherCalc =
+ Handle(HYDROData_CalculationCase)::DownCast( GetFatherObject() );
+
+ HYDROData_Entity::Remove();
+
+ if ( !aFatherCalc.IsNull() )
+ aFatherCalc->UpdateRegionsOrder();
+}
+
+bool HYDROData_Region::CanRemove()
+{
+ return false;
+}
+
+HYDROData_SequenceOfObjects HYDROData_Region::GetAllReferenceObjects() const
+{
+ HYDROData_SequenceOfObjects aResSeq = HYDROData_Entity::GetAllReferenceObjects();
+
+ HYDROData_SequenceOfObjects aSeqOfZones = GetZones();
+ aResSeq.Append( aSeqOfZones );
+
+ return aResSeq;
+}
+
+bool HYDROData_Region::AddZone( const Handle(HYDROData_Zone)& theZone )
+{
+ Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
+
+ if ( theZone.IsNull() )
+ return false;
+
+ if ( HasReference( theZone, DataTag_Zone ) )
+ return false; // Object is already in reference list
+
+ // Move the zone from other region
+ Handle(HYDROData_Region) aFatherRegion =
+ Handle(HYDROData_Region)::DownCast( theZone->GetFatherObject() );
+ if ( !aFatherRegion.IsNull() && aFatherRegion->Label() != myLab )
+ {
+ Handle(HYDROData_Zone) aNewZone = addNewZone( aDocument, "", TopoDS_Face(), QStringList() );
+ theZone->CopyTo( aNewZone, false );
+
+ // To prevent changing of stored shape
+ aNewZone->SetShape( theZone->GetShape() );
+
+ aFatherRegion->RemoveZone( theZone );
+
+ theZone->SetLabel( aNewZone->Label() );
+ }
+ else
+ {
+ AddReferenceObject( theZone, DataTag_Zone );
+ }
+
+ return true;
+}
+
+HYDROData_SequenceOfObjects HYDROData_Region::GetZones() const
+{
+ return GetReferenceObjects( DataTag_Zone );
+}
+
+void HYDROData_Region::RemoveZone( const Handle(HYDROData_Zone)& theZone )
+{
+ if ( theZone.IsNull() )
+ return;
+
+ RemoveReferenceObject( theZone->Label(), DataTag_Zone );
+
+ // Remove zone from data model
+ Handle(HYDROData_Region) aFatherRegion =
+ Handle(HYDROData_Region)::DownCast( theZone->GetFatherObject() );
+ if ( !aFatherRegion.IsNull() && aFatherRegion->Label() == myLab )
+ theZone->Remove();
+
+ // If the last zone has been removed from region we remove this region
+ HYDROData_SequenceOfObjects aRefZones = GetZones();
+ if ( aRefZones.IsEmpty() )
+ Remove();
+}
+
+void HYDROData_Region::RemoveZones()
+{
+ ClearReferenceObjects( DataTag_Zone );
+ myLab.FindChild( DataTag_ChildZone ).ForgetAllAttributes( true );
+}
+
+Handle(HYDROData_Zone) HYDROData_Region::addNewZone( const Handle(HYDROData_Document)& theDoc,
+ const QString& thePrefix,
+ const TopoDS_Face& theFace,
+ const QStringList& theRefObjects )
+{
+ TDF_Label aNewLab = myLab.FindChild( DataTag_ChildZone ).NewChild();
+
+ Handle(HYDROData_Zone) aNewZone =
+ Handle(HYDROData_Zone)::DownCast( HYDROData_Iterator::CreateObject( aNewLab, KIND_ZONE ) );
+ AddZone( aNewZone );
+
+ QString aZoneName = HYDROData_Tool::GenerateObjectName( theDoc, thePrefix );
+ aNewZone->SetName( aZoneName );
+
+ aNewZone->SetShape( theFace );
+
+ // Add the reference object for zone
+ for ( int i = 0, n = theRefObjects.length(); i < n; ++i )
+ {
+ const QString& anObjName = theRefObjects.at( i );
+ Handle(HYDROData_Entity) aRefObject = theDoc->FindObjectByName( anObjName );
+ if ( aRefObject.IsNull() )
+ continue;
+
+ aNewZone->AddObject( aRefObject );
+ }
+
+ return aNewZone;
+}
+
+void getUsedGroups( const TopoDS_Shape& theShape,
+ HYDROData_ShapesGroup::SeqOfGroupsDefs& theOriGroups,
+ HYDROData_ShapesGroup::SeqOfGroupsDefs& theUsedGroups )
+{
+#ifdef DEB_GET_REGION_SHAPE
+ HYDROData_ShapesTool::DumpShapeSubShapes( std::cout, "Zone face edges:", theShape, TopAbs_EDGE );
+#endif
+
+ TopTools_IndexedMapOfShape aMapOfSubShapes;
+ TopExp::MapShapes( theShape, TopAbs_EDGE, aMapOfSubShapes );
+
+ HYDROData_ShapesGroup::SeqOfGroupsDefs::Iterator anIter( theOriGroups );
+ for ( ; anIter.More(); anIter.Next() )
+ {
+ HYDROData_ShapesGroup::GroupDefinition& anOriGroupDef = anIter.ChangeValue();
+ if ( anOriGroupDef.Shapes.IsEmpty() )
+ continue;
+
+ for ( int i = 1; i <= anOriGroupDef.Shapes.Length(); ++i )
+ {
+ TopoDS_Shape aGroupEdge = anOriGroupDef.Shapes.Value( i );
+
+ int aShapeIndex = aMapOfSubShapes.FindIndex( aGroupEdge );
+ if ( aShapeIndex <= 0 )
+ continue;
+
+ anOriGroupDef.Shapes.Remove( i );
+ --i;
+
+ bool anIsAdded = false;
+
+ HYDROData_ShapesGroup::SeqOfGroupsDefs::Iterator aUsedIter( theUsedGroups );
+ for ( ; aUsedIter.More(); aUsedIter.Next() )
+ {
+ HYDROData_ShapesGroup::GroupDefinition& aUsedGroupDef = aUsedIter.ChangeValue();
+ if ( aUsedGroupDef.Name != anOriGroupDef.Name )
+ continue;
+
+ aUsedGroupDef.Shapes.Append( aGroupEdge );
+ anIsAdded = true;
+ break;
+ }
+
+ if ( !anIsAdded )
+ {
+ HYDROData_ShapesGroup::GroupDefinition aUsedGroupDef;
+ aUsedGroupDef.Name = anOriGroupDef.Name;
+ aUsedGroupDef.Shapes.Append( aGroupEdge );
+ theUsedGroups.Append( aUsedGroupDef );
+ }
+ }
+ }
+}
+
+TopoDS_Shape HYDROData_Region::GetShape( HYDROData_ShapesGroup::SeqOfGroupsDefs* theSeqOfGroups ) const