]> SALOME platform Git repositories - modules/hydro.git/commitdiff
Salome HOME
refs #611: redesign of the polylines extraction
authorasl <asl@opencascade.com>
Wed, 21 Oct 2015 13:19:45 +0000 (16:19 +0300)
committerasl <asl@opencascade.com>
Wed, 21 Oct 2015 13:19:45 +0000 (16:19 +0300)
src/HYDROData/HYDROData_Object.cxx
src/HYDROData/HYDROData_Object.h
src/HYDROData/HYDROData_PolylineOperator.cxx
src/HYDROData/HYDROData_PolylineOperator.h
src/HYDROGUI/HYDROGUI_PolylineExtractionOp.cxx
src/HYDROGUI/HYDROGUI_PolylineExtractionOp.h

index 78f734ea0a9b387d71b020c1fbae3f0c5e3ed986..20eead85ab2a6ab08dbbced470a32b015fe94632 100644 (file)
@@ -374,3 +374,26 @@ void HYDROData_Object::SetIsSubmersible( bool isSubmersible ) const
 {
   TDataStd_Integer::Set( myLab, isSubmersible ? 1 : 0 );
 }
+
+void HYDROData_Object::GetBoundaries( QList<TopoDS_Shape>& theBoundShapes,
+                                      QStringList& theBoundNames ) const
+{
+  HYDROData_SequenceOfObjects aGroups = GetGroups();
+    HYDROData_SequenceOfObjects::Iterator anIter( aGroups );
+    for ( ; anIter.More(); anIter.Next() )
+    {
+      Handle(HYDROData_ShapesGroup) aGroup =
+        Handle(HYDROData_ShapesGroup)::DownCast( anIter.Value() );
+      if( aGroup.IsNull() )
+        continue;
+
+      QString aName = aGroup->GetName();
+      TopTools_SequenceOfShape aShapes;
+      aGroup->GetShapes( aShapes );
+      for( int i=1, n=aShapes.Length(); i<=n; i++ )
+      {
+        theBoundShapes.append( aShapes( i ) );
+        theBoundNames.append( aName );
+      }
+    }
+}
index aa85d5aca966356f30e06cc5243c9ea1ad7320f1..0c217f274a6464e8e44d93c5271e4c7de578453b 100644 (file)
@@ -160,6 +160,9 @@ public:
   HYDRODATA_EXPORT bool IsSubmersible() const;
   HYDRODATA_EXPORT void SetIsSubmersible( bool ) const;
 
+  HYDRODATA_EXPORT virtual void GetBoundaries( QList<TopoDS_Shape>& theBoundShapes,
+                                               QStringList& theBoundNames ) const;
+
 protected:
 
   /**
index 7e44abefa551166741ff52efc984e12951d4047a..a5768945013f69a6b08bf9cbfd60248161d63cbc 100644 (file)
@@ -19,6 +19,7 @@
 #include <HYDROData_PolylineOperator.h>
 #include <HYDROData_Document.h>
 #include <HYDROData_TopoCurve.h>
+#include <HYDROData_Object.h>
 
 #ifndef LIGHT_MODE
 #include <CurveCreator_Utils.hxx>
@@ -46,7 +47,7 @@
 #include <TopExp.hxx>
 #include <TopExp_Explorer.hxx>
 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
-#include <QString>
+#include <QStringList>
 #include <Geom_BSplineCurve.hxx>
 
 template<class T> void append( std::vector<T>& theList, const std::vector<T>& theList2 )
@@ -412,3 +413,43 @@ double HYDROData_PolylineOperator::ReduceDeflection(
   }
   return aMaxDefl;
 }
+
+bool HYDROData_PolylineOperator::Extract( const Handle(HYDROData_Document)& theDocument,
+                                          const Handle(HYDROData_Object)& theObject )
+{
+  if( theObject.IsNull() || theDocument.IsNull() )
+    return false;
+
+  QList<TopoDS_Shape> aBoundShapes;
+  QStringList aBoundNames;
+
+  theObject->GetBoundaries( aBoundShapes, aBoundNames );
+
+  for( int i=0, n=aBoundShapes.size(); i<n; i++ )
+  {
+    TopoDS_Shape aShape = aBoundShapes[i];
+    if( aShape.IsNull() )
+      continue;
+
+    QString aBoundName = i<aBoundNames.size() ? aBoundNames[i] : "";
+
+    Handle( HYDROData_PolylineXY ) aPolyline = 
+      Handle( HYDROData_PolylineXY )::DownCast( theDocument->CreateObject( KIND_POLYLINEXY ) );
+    
+    if( aPolyline.IsNull() )
+      return false;
+
+    aPolyline->SetShape( aShape );
+
+    int anIndex = 0;
+    QString aName = aBoundName;
+    while( !theDocument->FindObjectByName( aName ).IsNull() )
+    {
+      anIndex++;
+      aName = aBoundName + "_" + QString::number( anIndex );
+    }
+    aPolyline->SetName( aName );
+  }
+
+  return true;
+}
index 8e27796cea78a6f98165bbf531534985fc482ca3..4263370dec1c4b110091d80304bddee87c9ff25a 100644 (file)
@@ -26,6 +26,7 @@
 
 class Handle( HYDROData_Document );
 class HYDROData_TopoCurve;
+class Handle(HYDROData_Object);
 
 class HYDRODATA_EXPORT HYDROData_PolylineOperator
 {
@@ -64,6 +65,9 @@ public:
     HYDROData_TopoCurve& theCurve,
     int& thePieceCount);
 
+  bool Extract( const Handle(HYDROData_Document)& theDocument,
+                const Handle(HYDROData_Object)& theObject );
+
 protected:
   bool split( const Handle( HYDROData_Document )& theDoc,
               const Handle( HYDROData_PolylineXY )& thePolyline,
index ac0a39ade019ca88f4cd19139050e4739c110fe1..591ae2de9d67c8c0b89a05fe0c8155641ea111be 100644 (file)
 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
 
-#include "HYDROGUI_PolylineExtractionOp.h"
-
-#include <GraphicsView_Viewer.h>
-
-#include "HYDROGUI_Module.h"
-#include "HYDROGUI_Operations.h"
-#include "HYDROGUI_Tool.h"
-#include "HYDROGUI_UpdateFlags.h"
-
-#include <HYDROData_Profile.h>
+#include <HYDROGUI_PolylineExtractionOp.h>
+#include <HYDROGUI_Module.h>
+#include <HYDROGUI_Tool.h>
+#include <HYDROGUI_UpdateFlags.h>
 #include <HYDROData_Document.h>
-#include <HYDROData_PolylineXY.h>
-#include <HYDROData_ShapesGroup.h>
-
-#include <LightApp_Application.h>
-#include <LightApp_Displayer.h>
-
-#include <OCCViewer_ViewModel.h>
-#include <OCCViewer_ViewManager.h>
-
-#include <BRep_Builder.hxx>
+#include <HYDROData_PolylineOperator.h>
 
 HYDROGUI_PolylineExtractionOp::HYDROGUI_PolylineExtractionOp( HYDROGUI_Module* theModule )
 : HYDROGUI_Operation( theModule )
@@ -59,124 +44,16 @@ void HYDROGUI_PolylineExtractionOp::startOperation()
     if ( aSeq.IsEmpty() )
         return;
 
+    startDocOperation();
+    HYDROData_PolylineOperator anOp;
     for ( Standard_Integer anIndex = 1, aLength = aSeq.Length(); anIndex <= aLength; anIndex++ )
     {
-        Handle(HYDROData_Entity) anObject = aSeq.Value( anIndex );
-        if ( anObject.IsNull() )
-            continue;
-
-        ShapeInfoList aList;
-
-        switch ( anObject->GetKind() )
-        {
-        case KIND_STREAM:
-            aList = extract( Handle(HYDROData_Stream)::DownCast( anObject ) );
-            break;
-        case KIND_DIGUE:
-        case KIND_CHANNEL:
-            aList = extract( Handle(HYDROData_Channel)::DownCast( anObject ) );
-            break;
-        case KIND_OBSTACLE:
-            aList = extract( Handle(HYDROData_Obstacle)::DownCast( anObject ) );
-            break;
-        }
-
-        startDocOperation();
-
-        for ( ShapeInfoList::const_iterator it = aList.begin(); it != aList.end(); ++it )
-        {
-            const ShapeInfo& inf = *it;
-            TopoDS_Shape aLine = inf.shape();
-            QString aName = QString( "%1_%2" ).arg( anObject->GetName() ).arg( inf.name() );
-            if ( !HYDROGUI_Tool::FindObjectByName( aModule, aName ).IsNull() )
-            {
-                int num = 1;
-                while ( !HYDROGUI_Tool::FindObjectByName( aModule, aName + QString( "_%1" ).arg( num ) ).IsNull() )
-                    num++;
-
-                aName += QString( "_%1" ).arg( num );
-            }
-
-            Handle(HYDROData_PolylineXY) aPolylineObj = Handle(HYDROData_PolylineXY)::DownCast( doc()->CreateObject( KIND_POLYLINEXY ) );
-            if ( !aPolylineObj.IsNull() )
-            {
-                aPolylineObj->SetName( aName );
-                aPolylineObj->ImportShape( aLine );
-                aPolylineObj->Update();
-            }
-        }
-
-        commitDocOperation();
+      Handle(HYDROData_Object) anObject = Handle(HYDROData_Object)::DownCast( aSeq.Value( anIndex ) );
+      if( !anObject.IsNull() )
+        anOp.Extract( doc(), anObject );      
     }
 
+    commitDocOperation();
     aModule->update( anUpdateFlags );
-
     commit();
 }
-
-HYDROGUI_PolylineExtractionOp::ShapeInfoList HYDROGUI_PolylineExtractionOp::extract( const Handle(HYDROData_Stream)& theStream ) const
-{
-    ShapeInfoList aList;
-    if ( !theStream.IsNull() )
-    {
-        aList.append( ShapeInfo( theStream->GetLeftShape(), QString( "Left bank" ) ) );
-        aList.append( ShapeInfo( theStream->GetRightShape(), QString( "Right bank" ) ) );
-
-        HYDROData_SequenceOfObjects aProfiles = theStream->GetProfiles();
-        for ( int i = 1; i <= aProfiles.Length(); i++ )
-        {
-            Handle(HYDROData_Profile) aProfile = Handle(HYDROData_Profile)::DownCast( aProfiles.Value( i ) );
-            aList.append( ShapeInfo( aProfile->GetTopShape(), QString( "Profile_%1" ).arg( i ) ) );
-        }
-    }
-    return aList;
-}
-
-HYDROGUI_PolylineExtractionOp::ShapeInfoList HYDROGUI_PolylineExtractionOp::extract( const Handle(HYDROData_Channel)& aChannel ) const
-{
-    ShapeInfoList aList;
-    if ( !aChannel.IsNull() )
-    {
-        HYDROData_SequenceOfObjects aGroups = aChannel->GetGroups();
-        int aNum = qMin( aGroups.Length(), 2 );
-        for ( int i = 1; i <= aNum; i++ )
-        {
-            Handle(HYDROData_ShapesGroup) aGroup = Handle(HYDROData_ShapesGroup)::DownCast( aGroups.Value( i ) );
-            TopTools_SequenceOfShape aShapes;
-            aGroup->GetShapes( aShapes );
-            if ( !aShapes.IsEmpty() )
-            {
-                TopoDS_Wire aWire;
-                BRep_Builder aBuilder;
-                aBuilder.MakeWire( aWire );
-
-                for ( int s = 1; s <= aShapes.Length(); s++ )
-                    aBuilder.Add( aWire, aShapes.Value( s ) );
-                aList.append( ShapeInfo( aWire, i > 1 ? "Right bank" : "Left bank" ) );
-            }
-        }
-    }
-    return aList;
-}
-
-HYDROGUI_PolylineExtractionOp::ShapeInfoList HYDROGUI_PolylineExtractionOp::extract( const Handle(HYDROData_Obstacle)& theObstacle ) const
-{
-    ShapeInfoList aList;
-    if ( !theObstacle.IsNull() )
-    {
-        TopoDS_Wire aWire;
-        BRep_Builder aBuilder;
-        aBuilder.MakeWire( aWire );
-        HYDROData_SequenceOfObjects aGroups = theObstacle->GetGroups();
-        for ( int i = 1; i <= aGroups.Length(); i++ )
-        {
-            Handle(HYDROData_ShapesGroup) aGroup = Handle(HYDROData_ShapesGroup)::DownCast( aGroups.Value( i ) );
-            TopTools_SequenceOfShape aShapes;
-            aGroup->GetShapes( aShapes );
-            for ( int s = 1; s <= aShapes.Length(); s++ )
-                aBuilder.Add( aWire, aShapes.Value( s ) );
-        }
-        aList.append( ShapeInfo( aWire, QString( "Contour" ) ) );
-    }
-    return aList;
-}
index 414799e5bcdfeda6d7c91399d5913d8692dbf00a..1258e1f1aa9609b3cf143b6ca947ff51fc0d121b 100644 (file)
@@ -37,27 +37,7 @@ public:
   virtual ~HYDROGUI_PolylineExtractionOp();
 
 protected:
-  virtual void               startOperation();
-
-private:
-  class ShapeInfo
-  {
-  public:
-      ShapeInfo( const TopoDS_Shape s, const QString& n ) : myShape( s ), myName( n ) {}
-      TopoDS_Shape shape() const { return myShape; }
-      QString      name() const { return myName; }
-
-  private:
-      TopoDS_Shape myShape;
-      QString      myName;
-  };
-
-  typedef QList<ShapeInfo> ShapeInfoList;
-
-private:
-  ShapeInfoList              extract( const Handle(HYDROData_Stream)& ) const;
-  ShapeInfoList              extract( const Handle(HYDROData_Channel)& ) const;
-  ShapeInfoList              extract( const Handle(HYDROData_Obstacle)& ) const;
+  virtual void startOperation();
 };
 
 #endif