1 // Copyright (C) 2014-2015 EDF-R&D
2 // This library is free software; you can redistribute it and/or
3 // modify it under the terms of the GNU Lesser General Public
4 // License as published by the Free Software Foundation; either
5 // version 2.1 of the License, or (at your option) any later version.
7 // This library is distributed in the hope that it will be useful,
8 // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10 // Lesser General Public License for more details.
12 // You should have received a copy of the GNU Lesser General Public
13 // License along with this library; if not, write to the Free Software
14 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #include <HYDROGUI_SplitPolylinesDlg.h>
20 #include <HYDROGUI_ObjComboBox.h>
21 #include <HYDROGUI_ObjListBox.h>
22 #include <HYDROGUI_Tool2.h>
23 #include <OCCViewer_ViewManager.h>
24 #include <OCCViewer_ViewWindow.h>
25 #include <OCCViewer_ViewPort3d.h>
26 #include <CurveCreator_Utils.hxx>
27 #include <SUIT_ViewWindow.h>
28 #include <QtxDoubleSpinBox.h>
31 #include <QGridLayout>
33 #include <QMouseEvent>
34 #include <gp_Pnt2d.hxx>
36 const double MIN_COORD = -1000000;
37 const double MAX_COORD = 1000000;
38 const double STEP = 10;
40 HYDROGUI_SplitPolylinesDlg::HYDROGUI_SplitPolylinesDlg( HYDROGUI_Module* theModule, const QString& theTitle )
41 : HYDROGUI_InputPanel( theModule, theTitle ), myOCCViewer( 0 )
43 QFrame* aFrame = new QFrame( mainFrame() );
44 addWidget( aFrame, 1 );
46 QGridLayout* aLayout = new QGridLayout( aFrame );
47 aLayout->setMargin( 5 );
48 aLayout->setSpacing( 5 );
50 myTab = new QTabWidget( aFrame );
51 aLayout->addWidget( myTab, 1, 0, 1, 2 );
53 QFrame* aPointPage = new QFrame();
54 myMainPolyline1 = new HYDROGUI_ObjComboBox( theModule, tr( "POLYLINE" ), KIND_POLYLINEXY, aPointPage );
55 myX = new QtxDoubleSpinBox( aPointPage );
56 myX->setRange( MIN_COORD, MAX_COORD );
57 myX->setSingleStep( STEP );
58 myY = new QtxDoubleSpinBox( aPointPage );
59 myY->setRange( MIN_COORD, MAX_COORD );
60 myY->setSingleStep( STEP );
62 QGridLayout* aPointPageLayout = new QGridLayout( aPointPage );
63 aPointPageLayout->addWidget( myMainPolyline1, 0, 0, 1, 3 );
64 aPointPageLayout->addWidget( new QLabel( tr( "POINT" ) ), 1, 0 );
65 aPointPageLayout->addWidget( myX, 1, 1 );
66 aPointPageLayout->addWidget( myY, 1, 2 );
67 aPointPageLayout->setColumnStretch( 1, 1 );
68 aPointPageLayout->setColumnStretch( 2, 1 );
69 aPointPageLayout->setRowStretch( 2, 1 );
70 myTab->addTab( aPointPage, tr( "BY_POINT" ) );
72 QFrame* aToolPage = new QFrame();
73 myMainPolyline2 = new HYDROGUI_ObjComboBox( theModule, tr( "POLYLINE" ), KIND_POLYLINEXY, aToolPage );
74 myToolPolyline = new HYDROGUI_ObjComboBox( theModule, tr( "TOOL_POLYLINE" ), KIND_POLYLINEXY, aToolPage );
76 QGridLayout* aToolPageLayout = new QGridLayout( aToolPage );
77 aToolPageLayout->addWidget( myMainPolyline2, 0, 0 );
78 aToolPageLayout->addWidget( myToolPolyline, 1, 0 );
79 aToolPageLayout->setRowStretch( 2, 1 );
80 myTab->addTab( aToolPage, tr( "BY_TOOL" ) );
82 QFrame* aSplitPage = new QFrame();
83 myPolylines = new HYDROGUI_ObjListBox( theModule, tr( "POLYLINES" ), KIND_POLYLINEXY, aSplitPage );
84 QGridLayout* aSplitPageLayout = new QGridLayout( aSplitPage );
85 aSplitPageLayout->addWidget( myPolylines, 0, 0 );
86 myTab->addTab( aSplitPage, tr( "COMPLETE_SPLIT" ) );
88 connect( myX, SIGNAL( valueChanged( double ) ), this, SIGNAL( pointMoved() ) );
89 connect( myY, SIGNAL( valueChanged( double ) ), this, SIGNAL( pointMoved() ) );
90 connect( myTab, SIGNAL( currentChanged( int ) ), this, SIGNAL( modeChanged() ) );
91 connect( myMainPolyline1, SIGNAL( objectSelected( const QString& ) ), this, SIGNAL( selectionChanged() ) );
92 connect( myMainPolyline2, SIGNAL( objectSelected( const QString& ) ), this, SIGNAL( selectionChanged() ) );
93 connect( myToolPolyline, SIGNAL( objectSelected( const QString& ) ), this, SIGNAL( selectionChanged() ) );
94 connect( myPolylines, SIGNAL( selectionChanged() ), this, SIGNAL( selectionChanged() ) );
97 HYDROGUI_SplitPolylinesDlg::~HYDROGUI_SplitPolylinesDlg()
101 HYDROGUI_SplitPolylinesDlg::Mode HYDROGUI_SplitPolylinesDlg::GetMode() const
103 return ( Mode )myTab->currentIndex();
106 Handle( HYDROData_PolylineXY ) HYDROGUI_SplitPolylinesDlg::GetMainPolyline() const
111 if( !myMainPolyline1->GetObject().IsNull() )
112 return Handle( HYDROData_PolylineXY )::DownCast( myMainPolyline1->GetObject() );
114 if( !myMainPolyline2->GetObject().IsNull() )
115 return Handle( HYDROData_PolylineXY )::DownCast( myMainPolyline2->GetObject() );
117 return Handle( HYDROData_PolylineXY )();
119 return Handle( HYDROData_PolylineXY )();
122 Handle( HYDROData_PolylineXY ) HYDROGUI_SplitPolylinesDlg::GetToolPolyline() const
124 if( GetMode()==ByTool )
125 return Handle( HYDROData_PolylineXY )::DownCast( myToolPolyline->GetObject() );
127 return Handle( HYDROData_PolylineXY )();
130 gp_Pnt2d HYDROGUI_SplitPolylinesDlg::GetPoint() const
132 return gp_Pnt2d( myX->value(), myY->value() );
135 HYDROData_SequenceOfObjects HYDROGUI_SplitPolylinesDlg::GetPolylines() const
137 if( GetMode()==Split )
138 return myPolylines->selectedObjects();
140 return HYDROData_SequenceOfObjects();
143 void HYDROGUI_SplitPolylinesDlg::setPolylinesFromSelection()
145 myMainPolyline1->reset();
146 myMainPolyline2->reset();
147 myToolPolyline->reset();
148 myPolylines->reset();
150 Handle( HYDROData_Entity ) anObject = HYDROGUI_Tool::GetSelectedObject( module() );
151 if( anObject.IsNull() || anObject->GetKind() != KIND_POLYLINEXY )
154 QString aName = anObject->GetName();
155 myMainPolyline1->setObjectName( aName );
156 myMainPolyline2->setObjectName( aName );
157 myPolylines->setObjectsFromSelection();
160 void HYDROGUI_SplitPolylinesDlg::setOCCViewer( OCCViewer_Viewer* theViewer )
165 myOCCViewer = theViewer;
166 OCCViewer_ViewManager* aViewManager = dynamic_cast<OCCViewer_ViewManager*>( myOCCViewer->getViewManager() );
167 disconnect( aViewManager, SIGNAL( mousePress( SUIT_ViewWindow*, QMouseEvent* ) ),
168 this, SLOT( onMousePress( SUIT_ViewWindow*, QMouseEvent* ) ) );
169 connect( aViewManager, SIGNAL( mousePress( SUIT_ViewWindow*, QMouseEvent* ) ),
170 this, SLOT( onMousePress( SUIT_ViewWindow*, QMouseEvent* ) ) );
173 void HYDROGUI_SplitPolylinesDlg::onMousePress( SUIT_ViewWindow* theWindow, QMouseEvent* theEvent )
175 gp_Pnt aPnt = CurveCreator_Utils::ConvertClickToPoint( theEvent->x(), theEvent->y(), getViewPort()->getView() );
176 myX->setValue( aPnt.X() );
177 myY->setValue( aPnt.Y() );
180 OCCViewer_ViewPort3d* HYDROGUI_SplitPolylinesDlg::getViewPort() const
182 OCCViewer_ViewPort3d* aViewPort = 0;
184 aViewPort = dynamic_cast<OCCViewer_ViewWindow*>( myOCCViewer->getViewManager()->getActiveView() )->getViewPort();