Salome HOME
mask traces
[modules/hydro.git] / src / HYDROData / HYDROData_Region.cxx
index daf99893d885d9e31823c5e87dd40863646deb3a..a381e208358302290c6d044ebfe52abe73e59ee6 100644 (file)
@@ -51,6 +51,9 @@
 #include "gp_Pln.hxx"
 #include "BRepTools_ReShape.hxx"
 
+//#define _DEVDEBUG_
+#include "HYDRO_trace.hxx"
+
 //#define DEB_GET_REGION_SHAPE
 
 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_Region, HYDROData_Entity)
@@ -98,7 +101,7 @@ HYDROData_SequenceOfObjects HYDROData_Region::GetAllReferenceObjects() const
 
 bool HYDROData_Region::AddZone( const Handle(HYDROData_Zone)& theZone )
 {
-  Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
+  Handle(HYDROData_Document) aDocument = HYDROData_Document::Document();
 
   if ( theZone.IsNull() )
     return false;
@@ -134,7 +137,7 @@ HYDROData_SequenceOfObjects HYDROData_Region::GetZones() const
   return GetReferenceObjects( DataTag_Zone );
 }
 
-void HYDROData_Region::RemoveZone( const Handle(HYDROData_Zone)& theZone )
+void HYDROData_Region::RemoveZone( const Handle(HYDROData_Zone)& theZone,  bool removeRegion )
 {
   if ( theZone.IsNull() )
     return;
@@ -147,10 +150,13 @@ void HYDROData_Region::RemoveZone( const Handle(HYDROData_Zone)& theZone )
   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();
+  if (removeRegion)
+  {
+    // 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()
@@ -182,7 +188,7 @@ Handle(HYDROData_Zone) HYDROData_Region::addNewZone( const Handle(HYDROData_Docu
     Handle(HYDROData_Entity) aRefObject = theDoc->FindObjectByName( anObjName );
     if ( aRefObject.IsNull() )
       continue;
-
+    DEBTRACE("aRefObject name: " << aRefObject->GetName());
     aNewZone->AddObject( aRefObject );
   }
 
@@ -244,9 +250,9 @@ void getUsedGroups( const TopoDS_Shape&                     theShape,
 }
 
 
-
 TopoDS_Shape HYDROData_Region::GetShape( HYDROData_ShapesGroup::SeqOfGroupsDefs* theSeqOfGroups, const TopTools_SequenceOfShape* IntSh ) const
 {
+  DEBTRACE("GetShape");
   HYDROData_ShapesGroup::SeqOfGroupsDefs aSeqOfGroups;
   HYDROData_ShapesGroup::SeqOfGroupsDefs aSeqOfUsedGroups;
   if ( theSeqOfGroups )
@@ -286,11 +292,15 @@ TopoDS_Shape HYDROData_Region::GetShape( HYDROData_ShapesGroup::SeqOfGroupsDefs*
     getUsedGroups( aZoneFace, aSeqOfGroups, aSeqOfUsedGroups );
   } // zones iterator
 
-  for (int i = 1; i <= IntSh->Length(); i++)
+  DEBTRACE("--- IntSh->Length():" << IntSh->Length());
+  if (IntSh)
   {
-    const TopoDS_Shape& CS = (*IntSh)(i);
-    if (AllE.Contains(CS))
-      IE.Add(CS);
+    for (int i = 1; i <= IntSh->Length(); i++)
+    {
+      const TopoDS_Shape& CS = (*IntSh)(i);
+      if (AllE.Contains(CS))
+        IE.Add(CS);
+    }
   }
   
   if ( aRegionFacesList.IsEmpty() )
@@ -300,6 +310,7 @@ TopoDS_Shape HYDROData_Region::GetShape( HYDROData_ShapesGroup::SeqOfGroupsDefs*
 
   if ( aRegionFacesList.Extent() == 1 )
   {
+    DEBTRACE("--- aRegionFacesList.Extent() == 1 ");
     aResShape = TopoDS::Face( aRegionFacesList.First() );
   }
   else
@@ -331,6 +342,7 @@ TopoDS_Shape HYDROData_Region::GetShape( HYDROData_ShapesGroup::SeqOfGroupsDefs*
       //update history of internal edges
       TopTools_IndexedMapOfShape DIE;
       TopTools_ListOfShape newSh1, newSh2;
+      DEBTRACE("IE.Extent():" << IE.Extent());
       for (int i = 1; i <= IE.Extent(); i++)
       {
         const TopoDS_Shape& CSH = IE(i);
@@ -363,42 +375,27 @@ TopoDS_Shape HYDROData_Region::GetShape( HYDROData_ShapesGroup::SeqOfGroupsDefs*
     HYDROData_ShapesTool::DumpShapeSubShapes( std::cout, "Fused face edges:", aFuseShape, TopAbs_EDGE );
 #endif
 
-    BRep_Builder BB;
-    TopoDS_Face DF;
+    aFuseShape = HYDROData_Tool::RebuildCmp(aFuseShape);
+
+    ShapeUpgrade_UnifySameDomain unif( aFuseShape, Standard_False, Standard_True, Standard_False );
     if (!IE.IsEmpty())
     {
-      //add dummy face to existing shell
-      //this face contains all internal edges
-      //USD algo will skip such edges and will not perform unifying through them 
-      //(more than 2 faces are connected to one edge + non same domain surfaces)
-      TopoDS_Wire DW;
-      Handle(Geom_Plane) DPl = new Geom_Plane(gp_Pln (gp_Pnt(0,0,0), gp_Dir(0,1,0))); //non same domain with the main surf
-      BB.MakeFace(DF, DPl, Precision::Confusion());
-      BB.MakeWire(DW);
+      TopTools_MapOfShape IEM;
       for (int i = 1; i <= IE.Extent(); i++)
-        BB.Add(DW, IE(i));
-      BB.Add(DF, DW);
-      BB.Add(aFuseShape, DF);
+        IEM.Add(IE(i));
+      unif.KeepShapes(IEM);
     }
 
-    ShapeUpgrade_UnifySameDomain unif( aFuseShape );
     unif.Build();
     TopoDS_Shape anUnitedShape;
-    const TopoDS_Shape& out = unif.Shape();
+    anUnitedShape = unif.Shape();
 
     HYDROData_ShapesGroup::GroupDefinition::Update( &aSeqOfUsedGroups, &unif );
 
-    if (!IE.IsEmpty())
-    {
-      //remove dummy face from shell; shell becomes valid
-      const TopoDS_Shape& NDF = unif.Generated(DF);
-      BRepTools_ReShape ReShaper;
-      ReShaper.Remove(NDF);
-      anUnitedShape = ReShaper.Apply(out);
-      HYDROData_ShapesGroup::GroupDefinition::Update( &aSeqOfUsedGroups, &ReShaper );
-    }
-    else
-      anUnitedShape = out;
+    //cout << "inif:   fuseshape: " << aFuseShape.TShape().get() << "unifS " << anUnitedShape.TShape().get() << endl;
+#ifdef DEB_GET_REGION_SHAPE
+    HYDROData_ShapesGroup::GroupDefinition::Dump( std::cout, aSeqOfUsedGroups );
+#endif
 
     TopTools_SequenceOfShape aShapeFaces;
     HYDROData_ShapesTool::ExploreShapeToShapes( anUnitedShape, TopAbs_FACE, aShapeFaces );
@@ -442,7 +439,7 @@ TopoDS_Shape HYDROData_Region::GetShape( HYDROData_ShapesGroup::SeqOfGroupsDefs*
       *theSeqOfGroups = aSeqOfGroups;
     }
   }
-
+                                                     
   return aResShape;
 }