Salome HOME
refs #430: incorrect coordinates in dump polyline
[modules/hydro.git] / src / HYDROData / HYDROData_ShapesGroup.cxx
index 1ef3ad95827d648bc1bf1ca556e9d0ffacf15923..32c82ec35144cf8ab95ee9edfe1c1ad1afe39b65 100644 (file)
 
 #include "HYDROData_ShapesGroup.h"
 
+#include "HYDROData_ShapesTool.h"
+
 #include <TDF_ChildIDIterator.hxx>
 
 #include <TopoDS.hxx>
 #include <TopoDS_Edge.hxx>
 
+#include <TopTools_ListOfShape.hxx>
+#include <TopTools_ListIteratorOfListOfShape.hxx>
+
 #include <TNaming_Builder.hxx>
 #include <TNaming_NamedShape.hxx>
 
+#include <BRepBuilderAPI_MakeShape.hxx>
+
+#include <ShapeUpgrade_UnifySameDomain.hxx>
+
 IMPLEMENT_STANDARD_HANDLE(HYDROData_ShapesGroup,HYDROData_Entity)
 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_ShapesGroup,HYDROData_Entity)
 
+void HYDROData_ShapesGroup::GroupDefinition::Update( SeqOfGroupsDefs*          theGroupsDefs,
+                                                     BRepBuilderAPI_MakeShape* theAlgo )
+{
+  if ( !theGroupsDefs || !theAlgo )
+    return;
+
+  SeqOfGroupsDefs::Iterator anIter( *theGroupsDefs );
+  for ( ; anIter.More(); anIter.Next() )
+  {
+    GroupDefinition& aGroupDef = anIter.ChangeValue();
+    if ( aGroupDef.Shapes.IsEmpty() )
+      continue;
+
+    TopTools_ListOfShape aShapesToAdd;
+    for ( int i = 1; i <= aGroupDef.Shapes.Length(); ++i )
+    {
+      TopoDS_Shape aShape = aGroupDef.Shapes.Value( i );
+
+      const TopTools_ListOfShape& aModifiedByAlgo = theAlgo->Modified( aShape );
+      if ( !aModifiedByAlgo.IsEmpty() )
+      {
+        HYDROData_ShapesTool::AddShapes( aShapesToAdd, aModifiedByAlgo );
+        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 );
+  }
+}
+
+void HYDROData_ShapesGroup::GroupDefinition::Update( SeqOfGroupsDefs*              theGroupsDefs,
+                                                     ShapeUpgrade_UnifySameDomain* theAlgo )
+{
+  if ( !theGroupsDefs || !theAlgo )
+    return;
+
+  SeqOfGroupsDefs::Iterator anIter( *theGroupsDefs );
+  for ( ; anIter.More(); anIter.Next() )
+  {
+    GroupDefinition& aGroupDef = anIter.ChangeValue();
+    if ( aGroupDef.Shapes.IsEmpty() )
+      continue;
+
+    TopTools_ListOfShape aShapesToAdd;
+    for ( int i = 1; i <= aGroupDef.Shapes.Length(); ++i )
+    {
+      TopoDS_Shape aShape = aGroupDef.Shapes.Value( i );
+
+      TopoDS_Shape aGeneratedByAlgo = theAlgo->Generated( aShape );
+      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()
 {
@@ -53,7 +160,19 @@ void HYDROData_ShapesGroup::SetShapes( const TopTools_SequenceOfShape& theShapes
   }
 }
 
-void HYDROData_ShapesGroup::GeShapes( TopTools_SequenceOfShape& theShapes ) const
+void HYDROData_ShapesGroup::SetShapes( const TopTools_ListOfShape& theShapes )
+{
+  RemoveShapes();
+
+  TopTools_ListIteratorOfListOfShape anIter( theShapes );
+  for ( ; anIter.More(); anIter.Next() )
+  {
+    const TopoDS_Shape& aShape = anIter.Value();
+    AddShape( aShape );
+  }
+}
+
+void HYDROData_ShapesGroup::GetShapes( TopTools_SequenceOfShape& theShapes ) const
 {
   theShapes.Clear();