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_Tool.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>
35 #include <gp_Pnt2d.hxx>
37 const double MIN_COORD = -1000000;
38 const double MAX_COORD = 1000000;
39 const double STEP = 10;
41 HYDROGUI_SplitPolylinesDlg::HYDROGUI_SplitPolylinesDlg( HYDROGUI_Module* theModule, const QString& theTitle )
42 : HYDROGUI_InputPanel( theModule, theTitle ), myOCCViewer( 0 )
44 QFrame* aFrame = new QFrame( mainFrame() );
45 addWidget( aFrame, 1 );
47 QGridLayout* aLayout = new QGridLayout( aFrame );
48 aLayout->setMargin( 5 );
49 aLayout->setSpacing( 5 );
51 myName = new QLineEdit( mainFrame() );
52 aLayout->addWidget( new QLabel( tr( "RESULT_NAME" ) ), 0, 0 );
53 aLayout->addWidget( myName, 0, 1 );
55 myTab = new QTabWidget( aFrame );
56 aLayout->addWidget( myTab, 1, 0, 1, 2 );
58 QFrame* aPointPage = new QFrame();
59 myMainPolyline1 = new HYDROGUI_ObjComboBox( theModule, tr( "POLYLINE" ), KIND_POLYLINEXY, aPointPage );
60 myX = new QtxDoubleSpinBox( aPointPage );
61 myX->setRange( MIN_COORD, MAX_COORD );
62 myX->setSingleStep( STEP );
63 myY = new QtxDoubleSpinBox( aPointPage );
64 myY->setRange( MIN_COORD, MAX_COORD );
65 myY->setSingleStep( STEP );
67 QGridLayout* aPointPageLayout = new QGridLayout( aPointPage );
68 aPointPageLayout->addWidget( myMainPolyline1, 0, 0, 1, 3 );
69 aPointPageLayout->addWidget( new QLabel( tr( "POINT" ) ), 1, 0 );
70 aPointPageLayout->addWidget( myX, 1, 1 );
71 aPointPageLayout->addWidget( myY, 1, 2 );
72 aPointPageLayout->setColumnStretch( 1, 1 );
73 aPointPageLayout->setColumnStretch( 2, 1 );
74 aPointPageLayout->setRowStretch( 2, 1 );
75 myTab->addTab( aPointPage, tr( "BY_POINT" ) );
77 QFrame* aToolPage = new QFrame();
78 myMainPolyline2 = new HYDROGUI_ObjComboBox( theModule, tr( "POLYLINE" ), KIND_POLYLINEXY, aToolPage );
79 myToolPolyline = new HYDROGUI_ObjComboBox( theModule, tr( "TOOL_POLYLINE" ), KIND_POLYLINEXY, aToolPage );
81 QGridLayout* aToolPageLayout = new QGridLayout( aToolPage );
82 aToolPageLayout->addWidget( myMainPolyline2, 0, 0 );
83 aToolPageLayout->addWidget( myToolPolyline, 1, 0 );
84 aToolPageLayout->setRowStretch( 2, 1 );
85 myTab->addTab( aToolPage, tr( "BY_TOOL" ) );
87 QFrame* aSplitPage = new QFrame();
88 myPolylines = new HYDROGUI_ObjListBox( theModule, tr( "POLYLINES" ), KIND_POLYLINEXY, aSplitPage );
89 QGridLayout* aSplitPageLayout = new QGridLayout( aSplitPage );
90 aSplitPageLayout->addWidget( myPolylines, 0, 0 );
91 myTab->addTab( aSplitPage, tr( "COMPLETE_SPLIT" ) );
93 connect( myX, SIGNAL( valueChanged( double ) ), this, SIGNAL( pointMoved() ) );
94 connect( myY, SIGNAL( valueChanged( double ) ), this, SIGNAL( pointMoved() ) );
95 connect( myTab, SIGNAL( currentChanged( int ) ), this, SIGNAL( modeChanged() ) );
96 connect( myMainPolyline1, SIGNAL( objectSelected( const QString& ) ), this, SIGNAL( selectionChanged() ) );
97 connect( myMainPolyline2, SIGNAL( objectSelected( const QString& ) ), this, SIGNAL( selectionChanged() ) );
98 connect( myToolPolyline, SIGNAL( objectSelected( const QString& ) ), this, SIGNAL( selectionChanged() ) );
99 connect( myPolylines, SIGNAL( selectionChanged() ), this, SIGNAL( selectionChanged() ) );
102 HYDROGUI_SplitPolylinesDlg::~HYDROGUI_SplitPolylinesDlg()
106 HYDROGUI_SplitPolylinesDlg::Mode HYDROGUI_SplitPolylinesDlg::GetMode() const
108 return ( Mode )myTab->currentIndex();
111 Handle( HYDROData_PolylineXY ) HYDROGUI_SplitPolylinesDlg::GetMainPolyline() const
116 if( !myMainPolyline1->GetObject().IsNull() )
117 return Handle( HYDROData_PolylineXY )::DownCast( myMainPolyline1->GetObject() );
119 if( !myMainPolyline2->GetObject().IsNull() )
120 return Handle( HYDROData_PolylineXY )::DownCast( myMainPolyline2->GetObject() );
122 return Handle( HYDROData_PolylineXY )();
124 return Handle( HYDROData_PolylineXY )();
127 Handle( HYDROData_PolylineXY ) HYDROGUI_SplitPolylinesDlg::GetToolPolyline() const
129 if( GetMode()==ByTool )
130 return Handle( HYDROData_PolylineXY )::DownCast( myToolPolyline->GetObject() );
132 return Handle( HYDROData_PolylineXY )();
135 gp_Pnt2d HYDROGUI_SplitPolylinesDlg::GetPoint() const
137 return gp_Pnt2d( myX->value(), myY->value() );
140 HYDROData_SequenceOfObjects HYDROGUI_SplitPolylinesDlg::GetPolylines() const
142 if( GetMode()==Split )
143 return myPolylines->selectedObjects();
145 return HYDROData_SequenceOfObjects();
148 void HYDROGUI_SplitPolylinesDlg::setPolylinesFromSelection()
150 myMainPolyline1->reset();
151 myMainPolyline2->reset();
152 myToolPolyline->reset();
153 myPolylines->reset();
155 Handle( HYDROData_Entity ) anObject = HYDROGUI_Tool::GetSelectedObject( module() );
156 if( anObject.IsNull() || anObject->GetKind() != KIND_POLYLINEXY )
159 QString aName = anObject->GetName();
160 myMainPolyline1->setObjectName( aName );
161 myMainPolyline2->setObjectName( aName );
162 myPolylines->setObjectsFromSelection();
165 void HYDROGUI_SplitPolylinesDlg::setOCCViewer( OCCViewer_Viewer* theViewer )
170 myOCCViewer = theViewer;
171 OCCViewer_ViewManager* aViewManager = dynamic_cast<OCCViewer_ViewManager*>( myOCCViewer->getViewManager() );
172 disconnect( aViewManager, SIGNAL( mousePress( SUIT_ViewWindow*, QMouseEvent* ) ),
173 this, SLOT( onMousePress( SUIT_ViewWindow*, QMouseEvent* ) ) );
174 connect( aViewManager, SIGNAL( mousePress( SUIT_ViewWindow*, QMouseEvent* ) ),
175 this, SLOT( onMousePress( SUIT_ViewWindow*, QMouseEvent* ) ) );
178 void HYDROGUI_SplitPolylinesDlg::onMousePress( SUIT_ViewWindow* theWindow, QMouseEvent* theEvent )
180 gp_Pnt aPnt = CurveCreator_Utils::ConvertClickToPoint( theEvent->x(), theEvent->y(), getViewPort()->getView() );
181 myX->setValue( aPnt.X() );
182 myY->setValue( aPnt.Y() );
185 OCCViewer_ViewPort3d* HYDROGUI_SplitPolylinesDlg::getViewPort() const
187 OCCViewer_ViewPort3d* aViewPort = 0;
189 aViewPort = dynamic_cast<OCCViewer_ViewWindow*>( myOCCViewer->getViewManager()->getActiveView() )->getViewPort();
194 QString HYDROGUI_SplitPolylinesDlg::GetResultName() const
196 return myName->text();