Salome HOME
land cover object is removed from the data model
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_SplitPolylinesDlg.cxx
index 5a702d1608ef20750b7c7c6dde91ed697bf301c3..eec48af774ffc9e2e1105be0bdfdc1075ae7f454 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 );
@@ -37,18 +48,50 @@ 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 );
+  aPointPageLayout->addWidget( new QLabel( tr( "POINT" ) ), 1, 0 );
+  aPointPageLayout->addWidget( myX, 1, 1 );
+  aPointPageLayout->addWidget( myY, 1, 2 );
+  aPointPageLayout->setColumnStretch( 1, 1 );
+  aPointPageLayout->setColumnStretch( 2, 1 );
+  aPointPageLayout->setRowStretch( 2, 1 );
   myTab->addTab( aPointPage, tr( "BY_POINT" ) );
 
   QFrame* aToolPage = new QFrame();
+  myMainPolyline2 = new HYDROGUI_ObjComboBox( theModule, tr( "POLYLINE" ), KIND_POLYLINEXY, aToolPage );
+  myToolPolyline = new HYDROGUI_ObjComboBox( theModule, tr( "TOOL_POLYLINE" ), KIND_POLYLINEXY, aToolPage );
+
+  QGridLayout* aToolPageLayout = new QGridLayout( aToolPage );
+  aToolPageLayout->addWidget( myMainPolyline2, 0, 0 );
+  aToolPageLayout->addWidget( myToolPolyline, 1, 0 );
+  aToolPageLayout->setRowStretch( 2, 1 );
   myTab->addTab( aToolPage, tr( "BY_TOOL" ) );
 
   QFrame* aSplitPage = new QFrame();
+  myPolylines = new HYDROGUI_ObjListBox( theModule, tr( "POLYLINES" ), KIND_POLYLINEXY, aSplitPage );
+  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()
@@ -65,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
@@ -96,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;
@@ -105,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;
+}