Salome HOME
refs #585: preview in split operation
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_SplitPolylinesDlg.cxx
index ddc0a44dcb29074d486dbe4f440e9af7b7c04241..6fe879871c1bc44a0548f47977d5d4f5f6ebbd59 100644 (file)
 #include <HYDROGUI_ObjComboBox.h>
 #include <HYDROGUI_ObjListBox.h>
 #include <HYDROGUI_Tool.h>
+#include <OCCViewer_ViewManager.h>
+#include <OCCViewer_ViewWindow.h>
+#include <OCCViewer_ViewPort3d.h>
+#include <CurveCreator_Utils.hxx>
+#include <SUIT_ViewWindow.h>
 #include <QtxDoubleSpinBox.h>
 #include <QFrame>
 #include <QLabel>
 #include <QGridLayout>
 #include <QTabWidget>
+#include <QMouseEvent>
 #include <gp_Pnt2d.hxx>
 
+const double MIN_COORD = -1000000;
+const double MAX_COORD =  1000000;
+const double STEP      =  10;
+
 HYDROGUI_SplitPolylinesDlg::HYDROGUI_SplitPolylinesDlg( HYDROGUI_Module* theModule, const QString& theTitle )
-: HYDROGUI_InputPanel( theModule, theTitle )
+: HYDROGUI_InputPanel( theModule, theTitle ), myOCCViewer( 0 )
 {
   QFrame* aFrame = new QFrame( mainFrame() );
   addWidget( aFrame, 1 );
@@ -43,7 +53,11 @@ HYDROGUI_SplitPolylinesDlg::HYDROGUI_SplitPolylinesDlg( HYDROGUI_Module* theModu
   QFrame* aPointPage = new QFrame();
   myMainPolyline1 = new HYDROGUI_ObjComboBox( theModule, tr( "POLYLINE" ), KIND_POLYLINEXY, aPointPage );
   myX = new QtxDoubleSpinBox( aPointPage );
+  myX->setRange( MIN_COORD, MAX_COORD );
+  myX->setSingleStep( STEP );
   myY = new QtxDoubleSpinBox( aPointPage );
+  myY->setRange( MIN_COORD, MAX_COORD );
+  myY->setSingleStep( STEP );
   
   QGridLayout* aPointPageLayout = new QGridLayout( aPointPage );
   aPointPageLayout->addWidget( myMainPolyline1, 0, 0, 1, 3 );
@@ -70,6 +84,14 @@ HYDROGUI_SplitPolylinesDlg::HYDROGUI_SplitPolylinesDlg( HYDROGUI_Module* theModu
   QGridLayout* aSplitPageLayout = new QGridLayout( aSplitPage );
   aSplitPageLayout->addWidget( myPolylines, 0, 0 );
   myTab->addTab( aSplitPage, tr( "COMPLETE_SPLIT" ) );
+
+  connect( myX, SIGNAL( valueChanged( double ) ), this, SIGNAL( pointMoved() ) );
+  connect( myY, SIGNAL( valueChanged( double ) ), this, SIGNAL( pointMoved() ) );
+  connect( myTab, SIGNAL( currentChanged( int ) ), this, SIGNAL( modeChanged() ) );
+  connect( myMainPolyline1, SIGNAL( objectSelected( const QString& ) ), this, SIGNAL( selectionChanged() ) );
+  connect( myMainPolyline2, SIGNAL( objectSelected( const QString& ) ), this, SIGNAL( selectionChanged() ) );
+  connect( myToolPolyline, SIGNAL( objectSelected( const QString& ) ), this, SIGNAL( selectionChanged() ) );
+  connect( myPolylines, SIGNAL( selectionChanged() ), this, SIGNAL( selectionChanged() ) );
 }
 
 HYDROGUI_SplitPolylinesDlg::~HYDROGUI_SplitPolylinesDlg()
@@ -117,6 +139,10 @@ HYDROData_SequenceOfObjects HYDROGUI_SplitPolylinesDlg::GetPolylines() const
 
 void HYDROGUI_SplitPolylinesDlg::setPolylinesFromSelection()
 {
+  myMainPolyline1->reset();
+  myMainPolyline2->reset();
+  myPolylines->reset();
+
   Handle( HYDROData_Entity ) anObject = HYDROGUI_Tool::GetSelectedObject( module() );
   if( anObject.IsNull() || anObject->GetKind() != KIND_POLYLINEXY )
     return;
@@ -126,3 +152,32 @@ void HYDROGUI_SplitPolylinesDlg::setPolylinesFromSelection()
   myMainPolyline2->setObjectName( aName );
   myPolylines->setObjectsFromSelection();
 }
+
+void HYDROGUI_SplitPolylinesDlg::setOCCViewer( OCCViewer_Viewer* theViewer )
+{
+  if( !theViewer )
+    return;
+  
+  myOCCViewer = theViewer;
+  OCCViewer_ViewManager* aViewManager = dynamic_cast<OCCViewer_ViewManager*>( myOCCViewer->getViewManager() );
+  disconnect( aViewManager, SIGNAL( mousePress( SUIT_ViewWindow*, QMouseEvent* ) ),
+              this, SLOT( onMousePress( SUIT_ViewWindow*, QMouseEvent* ) ) );
+  connect( aViewManager, SIGNAL( mousePress( SUIT_ViewWindow*, QMouseEvent* ) ),
+           this, SLOT( onMousePress( SUIT_ViewWindow*, QMouseEvent* ) ) );
+}
+
+void HYDROGUI_SplitPolylinesDlg::onMousePress( SUIT_ViewWindow* theWindow, QMouseEvent* theEvent )
+{
+  gp_Pnt aPnt = CurveCreator_Utils::ConvertClickToPoint( theEvent->x(), theEvent->y(), getViewPort()->getView() );
+  myX->setValue( aPnt.X() );
+  myY->setValue( aPnt.Y() );
+}
+
+OCCViewer_ViewPort3d* HYDROGUI_SplitPolylinesDlg::getViewPort() const
+{
+  OCCViewer_ViewPort3d* aViewPort = 0;
+  if ( myOCCViewer )
+    aViewPort = dynamic_cast<OCCViewer_ViewWindow*>( myOCCViewer->getViewManager()->getActiveView() )->getViewPort();
+    
+  return aViewPort;
+}