]> SALOME platform Git repositories - modules/hydro.git/commitdiff
Salome HOME
Creation of region face.
authoradv <adv@opencascade.com>
Wed, 15 Jan 2014 10:22:44 +0000 (10:22 +0000)
committeradv <adv@opencascade.com>
Wed, 15 Jan 2014 10:22:44 +0000 (10:22 +0000)
src/HYDROData/HYDROData_Region.cxx
src/HYDROData/HYDROData_ShapesGroup.cxx
src/HYDROData/HYDROData_ShapesGroup.h

index 6b2c19742fa59ae90f6aae0dc07edde96ca26ec5..8c19d65e635fe91b4d1b4298a7871752b3048d53 100644 (file)
@@ -17,6 +17,7 @@
 #include <TopTools_ListOfShape.hxx>
 #include <TopTools_SequenceOfShape.hxx>
 #include <TopTools_ListIteratorOfListOfShape.hxx>
+#include <TopTools_IndexedMapOfShape.hxx>
 
 #include <BRep_Builder.hxx>
 #include <BRepAlgoAPI_Fuse.hxx>
@@ -25,6 +26,8 @@
 
 #include <QStringList>
 
+//#define DEB_GET_REGION_SHAPE
+
 IMPLEMENT_STANDARD_HANDLE(HYDROData_Region, HYDROData_Entity)
 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_Region, HYDROData_Entity)
 
@@ -104,6 +107,9 @@ bool HYDROData_Region::AddZone( const Handle(HYDROData_Zone)& theZone )
     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() );
@@ -157,12 +163,80 @@ Handle(HYDROData_Zone) HYDROData_Region::addNewZone()
   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 );
+      
+      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)
@@ -186,6 +260,8 @@ TopoDS_Shape HYDROData_Region::GetShape( HYDROData_ShapesGroup::SeqOfGroupsDefs*
 
     TopoDS_Face aZoneFace = TopoDS::Face( aZoneShape );
     aRegionFacesList.Append( aZoneFace );
+
+    getUsedGroups( aZoneFace, aSeqOfGroups, aSeqOfUsedGroups );
   } // zones iterator
   
   if ( aRegionFacesList.IsEmpty() )
@@ -200,6 +276,10 @@ TopoDS_Shape HYDROData_Region::GetShape( HYDROData_ShapesGroup::SeqOfGroupsDefs*
   }
   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 );
@@ -219,9 +299,13 @@ TopoDS_Shape HYDROData_Region::GetShape( HYDROData_ShapesGroup::SeqOfGroupsDefs*
       }
 
       aFuseShape = aFuse.Shape();
-      HYDROData_ShapesGroup::GroupDefinition::Update( &aSeqOfGroups, &aFuse );
+      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() )
     {
@@ -235,11 +319,37 @@ TopoDS_Shape HYDROData_Region::GetShape( HYDROData_ShapesGroup::SeqOfGroupsDefs*
       if ( aShapeFaces.Length() == 1 )
       {
         aRegionFace = TopoDS::Face( aShapeFaces.Value( 1 ) );
-        HYDROData_ShapesGroup::GroupDefinition::Update( &aSeqOfGroups, &anUnifier );
 
-        // temporary commented because of needs of testing
-        //if ( theSeqOfGroups )
-          //*theSeqOfGroups = aSeqOfGroups;
+#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;
+            }
+          }
+
+          *theSeqOfGroups = aSeqOfGroups;
+        }
       }
     }
   }
index a540e527f0599b13fa3e22939c9fd5a274556c34..32c82ec35144cf8ab95ee9edfe1c1ad1afe39b65 100644 (file)
@@ -38,32 +38,24 @@ void HYDROData_ShapesGroup::GroupDefinition::Update( SeqOfGroupsDefs*          t
     for ( int i = 1; i <= aGroupDef.Shapes.Length(); ++i )
     {
       TopoDS_Shape aShape = aGroupDef.Shapes.Value( i );
-      /*
-      if ( theAlgo->IsDeleted( aShape ) )
+
+      const TopTools_ListOfShape& aModifiedByAlgo = theAlgo->Modified( aShape );
+      if ( !aModifiedByAlgo.IsEmpty() )
       {
+        HYDROData_ShapesTool::AddShapes( aShapesToAdd, aModifiedByAlgo );
         aGroupDef.Shapes.Remove( i );
         --i;
       }
-      else 
-      {*/
-        const TopTools_ListOfShape& aModifiedByAlgo = theAlgo->Modified( aShape );
-        if ( !aModifiedByAlgo.IsEmpty() )
+      else
+      {
+        const TopTools_ListOfShape& aGeneratedByAlgo = theAlgo->Generated( aShape );
+        if ( !aGeneratedByAlgo.IsEmpty() )
         {
-          HYDROData_ShapesTool::AddShapes( aShapesToAdd, aModifiedByAlgo );
+          HYDROData_ShapesTool::AddShapes( aShapesToAdd, aGeneratedByAlgo );
           aGroupDef.Shapes.Remove( i );
           --i;
         }
-        else
-        {
-          const TopTools_ListOfShape& aGeneratedByAlgo = theAlgo->Generated( aShape );
-          if ( !aGeneratedByAlgo.IsEmpty() )
-          {
-            HYDROData_ShapesTool::AddShapes( aShapesToAdd, aGeneratedByAlgo );
-            aGroupDef.Shapes.Remove( i );
-            --i;
-          }
-        }
-      //}
+      }
     }
 
     HYDROData_ShapesTool::AddShapes( aGroupDef.Shapes, aShapesToAdd );
@@ -89,18 +81,44 @@ void HYDROData_ShapesGroup::GroupDefinition::Update( SeqOfGroupsDefs*
       TopoDS_Shape aShape = aGroupDef.Shapes.Value( i );
 
       TopoDS_Shape aGeneratedByAlgo = theAlgo->Generated( aShape );
-      if ( aGeneratedByAlgo.IsNull() || aShape.IsEqual( aGeneratedByAlgo ) )
-        continue;
-
-      aShapesToAdd.Append( aGeneratedByAlgo );
-      aGroupDef.Shapes.Remove( i );
-      --i;
+      if ( aGeneratedByAlgo.IsNull() )
+      {
+        // Edge has been removed
+        aGroupDef.Shapes.Remove( i );
+        --i;
+      }
+      else if ( !aShape.IsEqual( aGeneratedByAlgo ) )
+      {
+        // Edge has been modified
+        aShapesToAdd.Append( aGeneratedByAlgo );
+        aGroupDef.Shapes.Remove( i );
+        --i;
+      }      
     }
 
     HYDROData_ShapesTool::AddShapes( aGroupDef.Shapes, aShapesToAdd );
   }
 }
 
+void HYDROData_ShapesGroup::GroupDefinition::Dump( std::ostream& theStream ) const
+{
+  theStream << "Name: " << Name.ToCString() << "\n";
+  HYDROData_ShapesTool::DumpSequenceOfShapes( theStream, Shapes );
+}
+
+void HYDROData_ShapesGroup::GroupDefinition::Dump( std::ostream&           theStream,
+                                                   const SeqOfGroupsDefs& theGroups  )
+{
+  SeqOfGroupsDefs::Iterator anIter( theGroups );
+  for ( ; anIter.More(); anIter.Next() )
+  {
+    const GroupDefinition& aGroupDef = anIter.Value();
+    aGroupDef.Dump( theStream );
+  }
+}
+
+
+
 HYDROData_ShapesGroup::HYDROData_ShapesGroup()
 : HYDROData_Entity()
 {
index 56bed37c3cd04fa652007831c6f8705624c17f75..69ac557e2d072af2e8a513979fb708b52f460628 100644 (file)
@@ -32,6 +32,11 @@ public:
     static void Update( NCollection_Sequence<GroupDefinition>* theGroupsDefs,
                         ShapeUpgrade_UnifySameDomain*          theAlgo );
 
+    void        Dump( std::ostream& theStream ) const;
+
+    static void Dump( std::ostream&                                theStream,
+                      const NCollection_Sequence<GroupDefinition>& theGroups );
+
     TCollection_AsciiString            Name;
     TopTools_SequenceOfShape           Shapes;
   };