Salome HOME
Merge branch 'master' into BR_RIVER
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_ProfileInterpolateOp.cxx
index c713bfab1121756df44aaa42976cb7c046f38335..6578a86de6d1468a74934aba827c7b1dedf75508 100644 (file)
 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
 
-#include <HYDROGUI_Module.h>
 #include <HYDROGUI_ProfileInterpolateOp.h>
-#include <HYDROGUI_ProfileDlg.h>
-#include <HYDROGUI_Tool.h>
-#include <HYDROGUI_UpdateFlags.h>
-#include <HYDROGUI_DataObject.h>
-#include <HYDROData_Document.h>
+
+#include "HYDROGUI_Tool.h"
+#include "HYDROGUI_Module.h"
+#include "HYDROGUI_DataObject.h"
+#include "HYDROGUI_UpdateFlags.h"
+#include "HYDROGUI_ProfileInterpolateDlg.h"
+
+#include <HYDROData_Stream.h>
 #include <HYDROData_Profile.h>
-#include <HYDROGUI_CurveCreatorProfile.h>
-#include <CurveCreator_Displayer.hxx>
 
 #include <LightApp_Application.h>
 #include <LightApp_SelectionMgr.h>
 #include <LightApp_UpdateFlags.h>
 
-#include <OCCViewer_ViewManager.h>
 #include <OCCViewer_ViewModel.h>
+#include <OCCViewer_ViewManager.h>
 #include <OCCViewer_ViewWindow.h>
-
 #include <OCCViewer_AISSelector.h>
 
-#include <Precision.hxx>
-
-//static int ZValueIncrement = 0;
+#include <AIS_ListOfInteractive.hxx>
+#include <AIS_ListIteratorOfListOfInteractive.hxx>
 
-HYDROGUI_ProfileInterpolateOp::HYDROGUI_ProfileInterpolateOp( HYDROGUI_Module* theModule, bool theIsEdit )
-: HYDROGUI_Operation( theModule ), myIsEdit(theIsEdit), myProfile(NULL)
+HYDROGUI_ProfileInterpolateOp::HYDROGUI_ProfileInterpolateOp( HYDROGUI_Module* theModule )
+    : HYDROGUI_Operation( theModule )
 {
-  setName( theIsEdit ? tr( "EDIT_PROFILE" ) : tr( "CREATE_PROFILE" ) );
+    setName( tr( "PROFILE_INTERPOLATION" ) );
 }
 
 HYDROGUI_ProfileInterpolateOp::~HYDROGUI_ProfileInterpolateOp()
 {
-  erasePreview();
 }
 
-/**
- * Redirect the delete action to input panel
- */
-void HYDROGUI_ProfileInterpolateOp::deleteSelected()
+void HYDROGUI_ProfileInterpolateOp::startOperation()
 {
-  HYDROGUI_ProfileDlg* aPanel = (HYDROGUI_ProfileDlg*)inputPanel();
-  aPanel->deleteSelected();
+    HYDROGUI_Operation::startOperation();
+
+    HYDROGUI_ProfileInterpolateDlg* aPanel = ::qobject_cast<HYDROGUI_ProfileInterpolateDlg*>( inputPanel() );
+    if ( aPanel )
+    {
+        aPanel->reset();
+        aPanel->setInterpolators( interpolators() );
+    }
+
+/*
+    if( myIsEdit )
+        myEditedObject = Handle(HYDROData_Profile)::DownCast( HYDROGUI_Tool::GetSelectedObject( module() ) );
+
+    QString aProfileName;
+    if( !myEditedObject.IsNull() )
+    {
+        Handle(HYDROData_ProfileUZ) aProfileUZ = myEditedObject->GetProfileUZ( false );
+        if ( !aProfileUZ.IsNull() )
+        {
+            CurveCreator::Coordinates aCurveCoords;
+            CurveCreator::SectionsMap aSectionsMap;
+
+            HYDROData_ProfileUZ::PointsList aSectPointsList = aProfileUZ->GetPoints();
+            CurveCreator::PosPointsList aPoints;
+            for ( int k = 1, aNbPoints = aSectPointsList.Size(); k <= aNbPoints; ++k )
+            {
+                const HYDROData_ProfileUZ::Point& aSectPoint = aSectPointsList.Value( k );
+                aCurveCoords.clear();
+                aCurveCoords.push_back( aSectPoint.X() );
+                aCurveCoords.push_back( aSectPoint.Y() );
+
+                CurveCreator_PosPoint* aPosPoint = new CurveCreator_PosPoint( k, aCurveCoords );
+                aPoints.push_back( aPosPoint );
+            }
+
+            aSectionsMap[0] = aPoints;
+            myProfile->addPointsInternal( aSectionsMap );
+
+            HYDROData_ProfileUZ::SectionType aSectType = aProfileUZ->GetSectionType( 0 );
+
+            CurveCreator::SectionType aCurveType = CurveCreator::Polyline;
+            if( aSectType == HYDROData_ProfileUZ::SECTION_SPLINE )
+                aCurveType = CurveCreator::Spline;
+
+            myProfile->setSectionType( 0, aCurveType );
+        }
+
+        aProfileName = myEditedObject->GetName();
+    }
+    else
+    {
+        aProfileName = HYDROGUI_Tool::GenerateObjectName( module(), tr( "DEFAULT_PROFILE_NAME" ) );
+    }
+
+    aPanel->setProfileName( aProfileName );
+    aPanel->setProfile( myProfile );
+*/
+//    displayPreview();
 }
 
-/**
- * Checks whether there are some to delete
- */
-bool HYDROGUI_ProfileInterpolateOp::deleteEnabled()
+void HYDROGUI_ProfileInterpolateOp::abortOperation()
 {
-  HYDROGUI_ProfileDlg* aPanel = (HYDROGUI_ProfileDlg*)inputPanel();
-  return aPanel->deleteEnabled();
+    HYDROGUI_Operation::abortOperation();
 }
 
-void HYDROGUI_ProfileInterpolateOp::startOperation()
+void HYDROGUI_ProfileInterpolateOp::commitOperation()
 {
-  if( myProfile )
-    delete myProfile;
+    HYDROGUI_Operation::commitOperation();
+}
 
-  myProfile = new HYDROGUI_CurveCreatorProfile();
+HYDROGUI_InputPanel* HYDROGUI_ProfileInterpolateOp::createInputPanel() const
+{
+    HYDROGUI_ProfileInterpolateDlg* aDlg = new HYDROGUI_ProfileInterpolateDlg( module(), getName() );
 
-  HYDROGUI_Operation::startOperation();
+    connect( aDlg, SIGNAL( riverChanged( const QString& ) ), this, SLOT( onRiverChanged( const QString& ) ) );
+    connect( aDlg, SIGNAL( interpolatorChanged( const QString& ) ), this, SLOT( onInterpolatorChanged( const QString& ) ) );
+    connect( aDlg, SIGNAL( interpolatorParametersChanged( const QString& ) ), this, SLOT( updatePreview() ) );
+    connect( aDlg, SIGNAL( profileNumberChanged( int ) ), this, SLOT( updatePreview() ) );
+    connect( aDlg, SIGNAL( profileStartChanged( const QString& ) ), this, SLOT( updatePreview() ) );
+    connect( aDlg, SIGNAL( profileFinishChanged( const QString& ) ), this, SLOT( updatePreview() ) );
 
-  HYDROGUI_ProfileDlg* aPanel = (HYDROGUI_ProfileDlg*)inputPanel();
-  aPanel->reset();
+    return aDlg;
+}
 
-  if( myIsEdit )
-    myEditedObject = Handle(HYDROData_Profile)::DownCast( HYDROGUI_Tool::GetSelectedObject( module() ) );
+bool HYDROGUI_ProfileInterpolateOp::processApply( int& theUpdateFlags, QString& theErrorMsg,
+                                                  QStringList& theBrowseObjectsEntries )
+{
+    HYDROGUI_ProfileInterpolateDlg* aPanel = ::qobject_cast<HYDROGUI_ProfileInterpolateDlg*>( inputPanel() );
+    if ( !aPanel )
+        return false;
+/*
+    QString aProfileName = aPanel->getProfileName().simplified();
+    if ( aProfileName.isEmpty() )
+    {
+        theErrorMsg = tr( "INCORRECT_OBJECT_NAME" );
+        return false;
+    }
 
-  QString aProfileName;
-  if( !myEditedObject.IsNull() )
-  {
-    Handle(HYDROData_ProfileUZ) aProfileUZ = myEditedObject->GetProfileUZ( false );
-    if ( !aProfileUZ.IsNull() )
+    if( !myIsEdit || ( !myEditedObject.IsNull() && myEditedObject->GetName() != aProfileName ) )
     {
-      CurveCreator::Coordinates aCurveCoords;
-      CurveCreator::SectionsMap aSectionsMap;
+        // check that there are no other objects with the same name in the document
+        Handle(HYDROData_Entity) anObject = HYDROGUI_Tool::FindObjectByName( module(), aProfileName );
+        if( !anObject.IsNull() )
+        {
+            theErrorMsg = tr( "OBJECT_EXISTS_IN_DOCUMENT" ).arg( aProfileName );
+            return false;
+        }
+    }
 
-      HYDROData_ProfileUZ::PointsList aSectPointsList = aProfileUZ->GetPoints();
-      CurveCreator::PosPointsList aPoints;
-      for ( int k = 1, aNbPoints = aSectPointsList.Size(); k <= aNbPoints; ++k )
-      {
-        const HYDROData_ProfileUZ::Point& aSectPoint = aSectPointsList.Value( k );
-        aCurveCoords.clear();
-        aCurveCoords.push_back( aSectPoint.X() );
-        aCurveCoords.push_back( aSectPoint.Y() );
+    Handle(HYDROData_Profile) aProfileObj;
+    if( myIsEdit ){
+        aProfileObj = myEditedObject;
+    }
+    else{
+        aProfileObj = Handle(HYDROData_Profile)::DownCast( doc()->CreateObject( KIND_PROFILE ) );
+    }
 
-        CurveCreator_PosPoint* aPosPoint = new CurveCreator_PosPoint( k, aCurveCoords );
-        aPoints.push_back( aPosPoint );
-      }
+    if( aProfileObj.IsNull() )
+        return false;
 
-      aSectionsMap[0] = aPoints;
-      myProfile->addPointsInternal( aSectionsMap );
+    Handle(HYDROData_ProfileUZ) aProfileUZ = aProfileObj->GetProfileUZ();
+    if ( aProfileUZ.IsNull() )
+        return false;
 
-      HYDROData_ProfileUZ::SectionType aSectType = aProfileUZ->GetSectionType( 0 );
+    aProfileObj->SetName(aProfileName);
 
-      CurveCreator::SectionType aCurveType = CurveCreator::Polyline;
-      if( aSectType == HYDROData_ProfileUZ::SECTION_SPLINE )
-        aCurveType = CurveCreator::Spline;
+    HYDROData_ProfileUZ::PointsList aProfileParamPoints;
 
-      myProfile->setSectionType( 0, aCurveType );
+    CurveCreator::Coordinates aCurveCoords = myProfile->getPoints( 0 );
+    if ( aCurveCoords.size() <= 2 )
+    {
+        theErrorMsg = tr( "NUMBER_OF_PROFILE_POINTS_INCORRECT" );
+        return false;
     }
 
-    aProfileName = myEditedObject->GetName();
-  }
-  else
-  {
-    aProfileName = HYDROGUI_Tool::GenerateObjectName( module(), tr( "DEFAULT_PROFILE_NAME" ) );
-  }
+    for ( int k = 0 ; k + 1 < aCurveCoords.size() ; k++ )
+    {
+        HYDROData_ProfileUZ::Point aProfileParamPoint;
 
-  aPanel->setProfileName( aProfileName );
-  aPanel->setProfile( myProfile );
-  displayPreview();
-}
+        aProfileParamPoint.SetX( aCurveCoords.at( k ) );
+        k++;
+        aProfileParamPoint.SetY( aCurveCoords.at( k ) );
 
-void HYDROGUI_ProfileInterpolateOp::abortOperation()
-{
-  erasePreview();
+        aProfileParamPoints.Append( aProfileParamPoint );
+    }
+    aProfileObj->SetParametricPoints( aProfileParamPoints );
 
-  HYDROGUI_Operation::abortOperation();
-}
+    HYDROData_ProfileUZ::SectionType aSectType = HYDROData_ProfileUZ::SECTION_POLYLINE;
+    if ( myProfile->getSectionType( 0 ) == CurveCreator::Spline )
+        aSectType = HYDROData_ProfileUZ::SECTION_SPLINE;
 
-void HYDROGUI_ProfileInterpolateOp::commitOperation()
-{
-  erasePreview();
+    aProfileUZ->SetSectionType( 0, aSectType );
+
+    if ( !myIsEdit )
+    {
+        aProfileObj->SetBorderColor( HYDROData_Profile::DefaultBorderColor() );
+    }
+
+    // At first we update the child u,z profile object
+    aProfileUZ->SetToUpdate( true );
+    aProfileUZ->Update();
 
-  HYDROGUI_Operation::commitOperation();
+    // And now we update our edited object
+    aProfileObj->Update();
+    module()->setIsToUpdate( aProfileObj );
+
+    theUpdateFlags = UF_Model;
+    if ( myIsEdit )
+        theUpdateFlags |= UF_OCCViewer | UF_OCC_Forced | UF_VTKViewer;
+    else
+    {
+        QString anEntry = HYDROGUI_DataObject::dataObjectEntry( aProfileObj );
+        theBrowseObjectsEntries.append( anEntry );
+    }
+
+    */
+    return true;
 }
 
-HYDROGUI_InputPanel* HYDROGUI_ProfileInterpolateOp::createInputPanel() const
+void HYDROGUI_ProfileInterpolateOp::updatePreview()
 {
-  HYDROGUI_ProfileDlg* aDlg = new HYDROGUI_ProfileDlg( module(), getName() );
-  return aDlg;
+    HYDROGUI_ProfileInterpolateDlg* aDlg = ::qobject_cast<HYDROGUI_ProfileInterpolateDlg*>( inputPanel() );
+    if ( !aDlg )
+        return;
+
+    Handle(AIS_InteractiveContext) aCtx = aDlg->getAISContext();
+    if ( aCtx.IsNull() )
+        return;
+
+    aCtx->UpdateCurrentViewer();
 }
 
-bool HYDROGUI_ProfileInterpolateOp::processApply( int& theUpdateFlags,
-                                       QString& theErrorMsg,
-                                       QStringList& theBrowseObjectsEntries )
+QStringList HYDROGUI_ProfileInterpolateOp::interpolators() const
 {
-  HYDROGUI_ProfileDlg* aPanel = ::qobject_cast<HYDROGUI_ProfileDlg*>( inputPanel() );
-  if ( !aPanel )
-    return false;
-
-  QString aProfileName = aPanel->getProfileName().simplified();
-  if ( aProfileName.isEmpty() )
-  {
-    theErrorMsg = tr( "INCORRECT_OBJECT_NAME" );
-    return false;
-  }
-
-  if( !myIsEdit || ( !myEditedObject.IsNull() && myEditedObject->GetName() != aProfileName ) )
-  {
-    // check that there are no other objects with the same name in the document
-    Handle(HYDROData_Entity) anObject = HYDROGUI_Tool::FindObjectByName( module(), aProfileName );
-    if( !anObject.IsNull() )
-    {
-      theErrorMsg = tr( "OBJECT_EXISTS_IN_DOCUMENT" ).arg( aProfileName );
-      return false;
-    }
-  }
-
-  Handle(HYDROData_Profile) aProfileObj;
-  if( myIsEdit ){
-    aProfileObj = myEditedObject;
-  }
-  else{
-    aProfileObj = Handle(HYDROData_Profile)::DownCast( doc()->CreateObject( KIND_PROFILE ) );
-  }
-
-  if( aProfileObj.IsNull() )
-    return false;
-
-  Handle(HYDROData_ProfileUZ) aProfileUZ = aProfileObj->GetProfileUZ();
-  if ( aProfileUZ.IsNull() )
-    return false;
-
-  aProfileObj->SetName(aProfileName);
-
-  HYDROData_ProfileUZ::PointsList aProfileParamPoints;
-
-  CurveCreator::Coordinates aCurveCoords = myProfile->getPoints( 0 );
-  if ( aCurveCoords.size() <= 2 )
-  {
-    theErrorMsg = tr( "NUMBER_OF_PROFILE_POINTS_INCORRECT" );
-    return false;
-  }
-
-  for ( int k = 0 ; k + 1 < aCurveCoords.size() ; k++ )
-  {
-    HYDROData_ProfileUZ::Point aProfileParamPoint;
-
-    aProfileParamPoint.SetX( aCurveCoords.at( k ) );
-    k++;
-    aProfileParamPoint.SetY( aCurveCoords.at( k ) );
-
-    aProfileParamPoints.Append( aProfileParamPoint );
-  }
-  aProfileObj->SetParametricPoints( aProfileParamPoints );
-
-  HYDROData_ProfileUZ::SectionType aSectType = HYDROData_ProfileUZ::SECTION_POLYLINE;
-  if ( myProfile->getSectionType( 0 ) == CurveCreator::Spline )
-    aSectType = HYDROData_ProfileUZ::SECTION_SPLINE;
-
-  aProfileUZ->SetSectionType( 0, aSectType );
-
-  if ( !myIsEdit )
-  {
-    aProfileObj->SetBorderColor( HYDROData_Profile::DefaultBorderColor() );
-  }
-
-  // At first we update the child u,z profile object
-  aProfileUZ->SetToUpdate( true );
-  aProfileUZ->Update();
-
-  // And now we update our edited object
-  aProfileObj->Update();
-  module()->setIsToUpdate( aProfileObj );
-
-  theUpdateFlags = UF_Model;
-  if ( myIsEdit )
-    theUpdateFlags |= UF_OCCViewer | UF_OCC_Forced | UF_VTKViewer;
-  else
-  {
-    QString anEntry = HYDROGUI_DataObject::dataObjectEntry( aProfileObj );
-    theBrowseObjectsEntries.append( anEntry );
-  }
-
-  return true;
+    return QStringList() << "Linear interpolator" << "Spline interpolator";
 }
 
-void HYDROGUI_ProfileInterpolateOp::displayPreview()
+void HYDROGUI_ProfileInterpolateOp::onInterpolatorChanged( const QString& theInterpName )
 {
-  HYDROGUI_ProfileDlg* aPanel = dynamic_cast<HYDROGUI_ProfileDlg*>( inputPanel() );
-  if( aPanel )
-  {
-    Handle(AIS_InteractiveContext) aCtx = aPanel->getAISContext();
-    if( !aCtx.IsNull() )
-    {
-      CurveCreator_Displayer* aDisplayer = new CurveCreator_Displayer( aCtx );
-      myProfile->setDisplayer( aDisplayer );
-      aDisplayer->display( myProfile->getAISObject( true ), true );
-    }
-  }
+    HYDROGUI_ProfileInterpolateDlg* aPanel = dynamic_cast<HYDROGUI_ProfileInterpolateDlg*>( inputPanel() );
+    if ( !aPanel )
+        return;
+
+    aPanel->setInterpolatorDescription( QString( "Profile will be calculated used %1" ).arg( theInterpName ) );
+
+    updatePreview();
 }
 
-void HYDROGUI_ProfileInterpolateOp::erasePreview()
+void HYDROGUI_ProfileInterpolateOp::onRiverChanged( const QString& theRiver )
 {
-  HYDROGUI_ProfileDlg* aPanel = dynamic_cast<HYDROGUI_ProfileDlg*>( inputPanel() );
-  CurveCreator_Displayer* aDisplayer = myProfile ? myProfile->getDisplayer() : 0;
-  if( aPanel && aDisplayer )
-  {
-    Handle(AIS_InteractiveContext) aCtx = aPanel->getAISContext();
-    if( !aCtx.IsNull() )
+    HYDROGUI_ProfileInterpolateDlg* aDlg = ::qobject_cast<HYDROGUI_ProfileInterpolateDlg*>( inputPanel() );
+    if ( !aDlg )
+        return;
+
+    Handle(AIS_InteractiveContext) aCtx = aDlg->getAISContext();
+    if ( !aCtx.IsNull() )
     {
-      aDisplayer->eraseAll( true );
+        AIS_ListOfInteractive aList;
+        aCtx->DisplayedObjects( aList );
+        for ( AIS_ListIteratorOfListOfInteractive it( aList ); it.More(); it.Next() )
+        {
+            Handle(AIS_Shape) anObj = Handle(AIS_Shape)::DownCast( it.Value() );
+            if ( !anObj.IsNull() )
+                aCtx->Remove( anObj, false );
+        }
+
+        Handle(HYDROData_Stream) aStream = Handle(HYDROData_Stream)::DownCast( HYDROGUI_Tool::FindObjectByName( module(), theRiver, KIND_STREAM ) );
+        if ( !aStream.IsNull() )
+        {
+            HYDROData_SequenceOfObjects aSeq = aStream->GetProfiles();
+            for ( int i = aSeq.Lower(); i <= aSeq.Upper(); i++ )
+            {
+                Handle(HYDROData_Profile) aProfile = Handle(HYDROData_Profile)::DownCast( aSeq.Value( i ) );
+                if ( !aProfile.IsNull() )
+                {
+                    Handle(AIS_Shape) aPrs = new AIS_Shape( aProfile->GetShape3D() );
+                    aPrs->SetOwner( aProfile );
+                    aPrs->SetColor( Quantity_NOC_BLACK );
+                    aCtx->Display( aPrs, 0, 0, false );
+                }
+            }
+        }
     }
-  }
+    updatePreview();
 }