Salome HOME
lot 15:: protection against corrupted polylines/objects
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_PolylineExtractionOp.cxx
index ac0a39ade019ca88f4cd19139050e4739c110fe1..76519f492c44734265b4c9c4e028af3c5ca30e42 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_Tool2.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;
-}