Salome HOME
Merge branch 'BR_H2018_3' into BR_2018_V8_5
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_SplitPolylinesDlg.cxx
index ddc0a44dcb29074d486dbe4f440e9af7b7c04241..a6ce1887022474cd89291d391c76544a1d69f075 100644 (file)
 #include <HYDROGUI_SplitPolylinesDlg.h>
 #include <HYDROGUI_ObjComboBox.h>
 #include <HYDROGUI_ObjListBox.h>
-#include <HYDROGUI_Tool.h>
+#include <HYDROGUI_Tool2.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 );
@@ -38,12 +48,16 @@ HYDROGUI_SplitPolylinesDlg::HYDROGUI_SplitPolylinesDlg( HYDROGUI_Module* theModu
   aLayout->setSpacing( 5 );
 
   myTab = new QTabWidget( aFrame );
-  aLayout->addWidget( myTab, 0, 0 );
+  aLayout->addWidget( myTab, 1, 0, 1, 2 );
 
   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()
@@ -86,12 +108,15 @@ Handle( HYDROData_PolylineXY ) HYDROGUI_SplitPolylinesDlg::GetMainPolyline() con
   switch( GetMode() )
   {
   case ByPoint:
-    return Handle( HYDROData_PolylineXY )::DownCast( myMainPolyline1->GetObject() );
+    if( !myMainPolyline1->GetObject().IsNull() )
+      return Handle( HYDROData_PolylineXY )::DownCast( myMainPolyline1->GetObject() );
   case ByTool:
-    return Handle( HYDROData_PolylineXY )::DownCast( myMainPolyline2->GetObject() );
+    if( !myMainPolyline2->GetObject().IsNull() )
+      return Handle( HYDROData_PolylineXY )::DownCast( myMainPolyline2->GetObject() );
   default:
     return Handle( HYDROData_PolylineXY )();
   }
+  return Handle( HYDROData_PolylineXY )();
 }
 
 Handle( HYDROData_PolylineXY ) HYDROGUI_SplitPolylinesDlg::GetToolPolyline() const
@@ -117,6 +142,11 @@ HYDROData_SequenceOfObjects HYDROGUI_SplitPolylinesDlg::GetPolylines() const
 
 void HYDROGUI_SplitPolylinesDlg::setPolylinesFromSelection()
 {
+  myMainPolyline1->reset();
+  myMainPolyline2->reset();
+  myToolPolyline->reset();
+  myPolylines->reset();
+
   Handle( HYDROData_Entity ) anObject = HYDROGUI_Tool::GetSelectedObject( module() );
   if( anObject.IsNull() || anObject->GetKind() != KIND_POLYLINEXY )
     return;
@@ -126,3 +156,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;
+}