#include "HYDROData_CalculationCase.h"
#include "HYDROData_Document.h"
#include "HYDROData_Iterator.h"
+#include "HYDROData_ShapesTool.h"
#include "HYDROData_Zone.h"
#include <TopoDS.hxx>
#include <TopoDS_Shape.hxx>
#include <TopoDS_Shell.hxx>
#include <TopoDS_Face.hxx>
+
+#include <TopExp.hxx>
+
#include <TopTools_ListOfShape.hxx>
+#include <TopTools_SequenceOfShape.hxx>
#include <TopTools_ListIteratorOfListOfShape.hxx>
#include <TopTools_IndexedMapOfShape.hxx>
-#include <TopExp.hxx>
+
#include <BRep_Builder.hxx>
#include <BRepAlgoAPI_Fuse.hxx>
+
#include <ShapeUpgrade_UnifySameDomain.hxx>
#include <QStringList>
-#define PYTHON_REGION_ID "KIND_REGION"
+//#define DEB_GET_REGION_SHAPE
IMPLEMENT_STANDARD_HANDLE(HYDROData_Region, HYDROData_Entity)
IMPLEMENT_STANDARD_RTTIEXT(HYDROData_Region, HYDROData_Entity)
QStringList HYDROData_Region::DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const
{
- QStringList aResList;
-
- Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
- if ( aDocument.IsNull() )
- return aResList;
-
- QString aDocName = aDocument->GetDocPyName();
+ QStringList aResList = dumpObjectCreation( theTreatedObjects );
QString aRegionName = GetName();
- aResList << QString( "%1 = %2.CreateObject( %3 );" )
- .arg( aRegionName ).arg( aDocName ).arg( PYTHON_REGION_ID );
- aResList << QString( "%1.SetName( \"%2\" );" )
- .arg( aRegionName ).arg( aRegionName );
- aResList << QString( "" );
-
HYDROData_SequenceOfObjects aZones = GetZones();
HYDROData_SequenceOfObjects::Iterator anIter( aZones );
for ( ; anIter.More(); anIter.Next() )
return aResList;
}
+bool HYDROData_Region::CanBeUpdated() const
+{
+ return false;
+}
+
void HYDROData_Region::Remove()
{
Handle(HYDROData_CalculationCase) aFatherCalc =
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 )
{
if ( theZone.IsNull() )
Handle(HYDROData_Zone) aNewZone = addNewZone();
theZone->CopyTo( aNewZone );
+ // To prevent changing of stored shape
+ aNewZone->SetShape( theZone->GetShape() );
+
aFatherRegion->RemoveZone( theZone );
theZone->SetLabel( aNewZone->Label() );
return aNewZone;
}
-TopoDS_Shape HYDROData_Region::GetShape() const
+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 );
+
+ bool anIsFound = false;
+ for ( int anIndex = 1; anIndex <= aMapOfSubShapes.Extent(); anIndex++ )
+ {
+ if ( aGroupEdge.IsPartner( aMapOfSubShapes.FindKey( anIndex ) ) )
+ {
+ anIsFound = true;
+ break;
+ }
+ }
+
+ if ( !anIsFound )
+ 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
{
+ HYDROData_ShapesGroup::SeqOfGroupsDefs aSeqOfGroups;
+ HYDROData_ShapesGroup::SeqOfGroupsDefs aSeqOfUsedGroups;
+ if ( theSeqOfGroups )
+ aSeqOfGroups = *theSeqOfGroups;
+
+#ifdef DEB_GET_REGION_SHAPE
+ HYDROData_ShapesGroup::GroupDefinition::Dump( std::cout, aSeqOfGroups );
+#endif
+
TopoDS_Shape aResShape;
// Unite the region zones (each zone is a face) into one face (united face)
HYDROData_SequenceOfObjects aZones = GetZones();
HYDROData_SequenceOfObjects::Iterator aZoneIter( aZones );
- for ( ; aZoneIter.More(); aZoneIter.Next() ) {
+ for ( ; aZoneIter.More(); aZoneIter.Next() )
+ {
Handle(HYDROData_Zone) aZone =
Handle(HYDROData_Zone)::DownCast( aZoneIter.Value() );
-
- if ( aZone.IsNull() ) {
+ if ( aZone.IsNull() )
continue;
- }
- TopoDS_Face aFace = TopoDS::Face( aZone->GetShape() );
- if ( !aFace.IsNull() ) {
- aRegionFacesList.Append( aFace );
- }
+ TopoDS_Shape aZoneShape = aZone->GetShape();
+ if ( aZoneShape.IsNull() || aZoneShape.ShapeType() != TopAbs_FACE )
+ continue;
+
+ TopoDS_Face aZoneFace = TopoDS::Face( aZoneShape );
+ aRegionFacesList.Append( aZoneFace );
+
+ getUsedGroups( aZoneFace, aSeqOfGroups, aSeqOfUsedGroups );
} // zones iterator
- // Check number of faces
- int aNbFaces = aRegionFacesList.Extent();
- if ( aNbFaces > 0 ) {
- // The unite region face
- TopoDS_Face aRegionFace;
-
- if ( aNbFaces == 1 ) {
- aRegionFace = TopoDS::Face( aRegionFacesList.First() );
- } else {
- // Fuse faces into one
- TopoDS_Shape aFuseShape;
- TopTools_ListIteratorOfListOfShape aFaceIter( aRegionFacesList );
- for ( ; aFaceIter.More(); aFaceIter.Next() ) {
- if ( aFuseShape.IsNull() ) {
- aFuseShape = aFaceIter.Value();
- } else {
- BRepAlgoAPI_Fuse aFuse(aFuseShape, aFaceIter.Value());
- if ( !aFuse.IsDone() ) {
- aFuseShape.Nullify();
- break;
+ if ( aRegionFacesList.IsEmpty() )
+ return aResShape;
+
+ // The unite region face
+ TopoDS_Face aRegionFace;
+
+ if ( aRegionFacesList.Extent() == 1 )
+ {
+ aRegionFace = TopoDS::Face( aRegionFacesList.First() );
+ }
+ else
+ {
+#ifdef DEB_GET_REGION_SHAPE
+ HYDROData_ShapesGroup::GroupDefinition::Dump( std::cout, aSeqOfUsedGroups );
+#endif
+
+ // Try to fuse all region faces into one common face
+ TopoDS_Shape aFuseShape;
+ TopTools_ListIteratorOfListOfShape aFaceIter( aRegionFacesList );
+ for ( ; aFaceIter.More(); aFaceIter.Next() )
+ {
+ if ( aFuseShape.IsNull() )
+ {
+ aFuseShape = aFaceIter.Value();
+ continue;
+ }
+
+ BRepAlgoAPI_Fuse aFuse( aFuseShape, aFaceIter.Value() );
+ if ( !aFuse.IsDone() )
+ {
+ aFuseShape.Nullify();
+ break;
+ }
+
+ aFuseShape = aFuse.Shape();
+ HYDROData_ShapesGroup::GroupDefinition::Update( &aSeqOfUsedGroups, &aFuse );
+ } // faces iterator
+
+#ifdef DEB_GET_REGION_SHAPE
+ HYDROData_ShapesTool::DumpShapeSubShapes( std::cout, "Fused face edges:", aFuseShape, TopAbs_EDGE );
+#endif
+
+ // Check the result of fuse operation
+ if ( !aFuseShape.IsNull() )
+ {
+ ShapeUpgrade_UnifySameDomain anUnifier( aFuseShape );
+ anUnifier.Build();
+
+ const TopoDS_Shape& anUnitedShape = anUnifier.Shape();
+
+ TopTools_SequenceOfShape aShapeFaces;
+ HYDROData_ShapesTool::ExploreShapeToShapes( anUnitedShape, TopAbs_FACE, aShapeFaces );
+ if ( aShapeFaces.Length() == 1 )
+ {
+ aRegionFace = TopoDS::Face( aShapeFaces.Value( 1 ) );
+
+#ifdef DEB_GET_REGION_SHAPE
+ HYDROData_ShapesTool::DumpShapeSubShapes( std::cout, "Result face edges:", aRegionFace, TopAbs_EDGE );
+#endif
+
+ HYDROData_ShapesGroup::GroupDefinition::Update( &aSeqOfUsedGroups, &anUnifier );
+
+ // Update the sequence of groups
+ if ( theSeqOfGroups )
+ {
+ HYDROData_ShapesGroup::SeqOfGroupsDefs::Iterator aUsedIter( aSeqOfUsedGroups );
+ for ( ; aUsedIter.More(); aUsedIter.Next() )
+ {
+ const HYDROData_ShapesGroup::GroupDefinition& aUsedGroupDef = aUsedIter.Value();
+ if ( aUsedGroupDef.Shapes.IsEmpty() )
+ continue;
+
+ HYDROData_ShapesGroup::SeqOfGroupsDefs::Iterator anOriIter( aSeqOfGroups );
+ for ( ; anOriIter.More(); anOriIter.Next() )
+ {
+ HYDROData_ShapesGroup::GroupDefinition& anOriGroupDef = anOriIter.ChangeValue();
+ if ( anOriGroupDef.Name != aUsedGroupDef.Name )
+ continue;
+
+ HYDROData_ShapesTool::AddShapes( anOriGroupDef.Shapes, aUsedGroupDef.Shapes );
+ break;
+ }
}
- aFuseShape = aFuse.Shape();
- }
- } // faces iterator
-
- // Check the result of fuse operation
- if ( !aFuseShape.IsNull() ) {
- ShapeUpgrade_UnifySameDomain anUnifier( aFuseShape );
- anUnifier.Build();
- TopoDS_Shape anUnitedShape = anUnifier.Shape();
-
- TopTools_IndexedMapOfShape aMapOfFaces;
- TopExp::MapShapes( anUnitedShape, TopAbs_FACE, aMapOfFaces );
- if ( aMapOfFaces.Extent() == 1 ) {
- aRegionFace = TopoDS::Face( aMapOfFaces(1) );
+
+ *theSeqOfGroups = aSeqOfGroups;
}
}
}
+ }
- if ( !aRegionFace.IsNull() ) { // result shape is a face
- aResShape = aRegionFace;
- } else { // result shape is a shell
- TopoDS_Shell aShell;
- BRep_Builder aBuilder;
- aBuilder.MakeShell( aShell );
+ if ( !aRegionFace.IsNull() )
+ {
+ // result shape is a face
+ aResShape = aRegionFace;
+ }
+ else
+ {
+ // result shape is a shell
+ TopoDS_Shell aShell;
+ BRep_Builder aBuilder;
+ aBuilder.MakeShell( aShell );
- TopTools_ListIteratorOfListOfShape aFaceIter( aRegionFacesList );
- for ( ; aFaceIter.More(); aFaceIter.Next() ) {
- aBuilder.Add( aShell, aFaceIter.Value() );
- }
+ TopTools_ListIteratorOfListOfShape aFaceIter( aRegionFacesList );
+ for ( ; aFaceIter.More(); aFaceIter.Next() )
+ aBuilder.Add( aShell, aFaceIter.Value() );
- aResShape = aShell;
- }
+ aResShape = aShell;
}
return aResShape;