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 <QtxDoubleSpinBox.h>
26 #include <QGridLayout>
28 #include <gp_Pnt2d.hxx>
30 HYDROGUI_SplitPolylinesDlg::HYDROGUI_SplitPolylinesDlg( HYDROGUI_Module* theModule, const QString& theTitle )
31 : HYDROGUI_InputPanel( theModule, theTitle )
33 QFrame* aFrame = new QFrame( mainFrame() );
34 addWidget( aFrame, 1 );
36 QGridLayout* aLayout = new QGridLayout( aFrame );
37 aLayout->setMargin( 5 );
38 aLayout->setSpacing( 5 );
40 myTab = new QTabWidget( aFrame );
41 aLayout->addWidget( myTab, 0, 0 );
43 QFrame* aPointPage = new QFrame();
44 myMainPolyline1 = new HYDROGUI_ObjComboBox( theModule, tr( "POLYLINE" ), KIND_POLYLINEXY, aPointPage );
45 myX = new QtxDoubleSpinBox( aPointPage );
46 myY = new QtxDoubleSpinBox( aPointPage );
48 QGridLayout* aPointPageLayout = new QGridLayout( aPointPage );
49 aPointPageLayout->addWidget( myMainPolyline1, 0, 0, 1, 3 );
50 aPointPageLayout->addWidget( new QLabel( tr( "POINT" ) ), 1, 0 );
51 aPointPageLayout->addWidget( myX, 1, 1 );
52 aPointPageLayout->addWidget( myY, 1, 2 );
53 aPointPageLayout->setColumnStretch( 1, 1 );
54 aPointPageLayout->setColumnStretch( 2, 1 );
55 aPointPageLayout->setRowStretch( 2, 1 );
56 myTab->addTab( aPointPage, tr( "BY_POINT" ) );
58 QFrame* aToolPage = new QFrame();
59 myMainPolyline2 = new HYDROGUI_ObjComboBox( theModule, tr( "POLYLINE" ), KIND_POLYLINEXY, aToolPage );
60 myToolPolyline = new HYDROGUI_ObjComboBox( theModule, tr( "TOOL_POLYLINE" ), KIND_POLYLINEXY, aToolPage );
62 QGridLayout* aToolPageLayout = new QGridLayout( aToolPage );
63 aToolPageLayout->addWidget( myMainPolyline2, 0, 0 );
64 aToolPageLayout->addWidget( myToolPolyline, 1, 0 );
65 aToolPageLayout->setRowStretch( 2, 1 );
66 myTab->addTab( aToolPage, tr( "BY_TOOL" ) );
68 QFrame* aSplitPage = new QFrame();
69 myPolylines = new HYDROGUI_ObjListBox( theModule, tr( "POLYLINES" ), KIND_POLYLINEXY, aSplitPage );
70 QGridLayout* aSplitPageLayout = new QGridLayout( aSplitPage );
71 aSplitPageLayout->addWidget( myPolylines, 0, 0 );
72 myTab->addTab( aSplitPage, tr( "COMPLETE_SPLIT" ) );
75 HYDROGUI_SplitPolylinesDlg::~HYDROGUI_SplitPolylinesDlg()
79 HYDROGUI_SplitPolylinesDlg::Mode HYDROGUI_SplitPolylinesDlg::GetMode() const
81 return ( Mode )myTab->currentIndex();
84 Handle( HYDROData_PolylineXY ) HYDROGUI_SplitPolylinesDlg::GetMainPolyline() const
89 return Handle( HYDROData_PolylineXY )::DownCast( myMainPolyline1->GetObject() );
91 return Handle( HYDROData_PolylineXY )::DownCast( myMainPolyline2->GetObject() );
93 return Handle( HYDROData_PolylineXY )();
97 Handle( HYDROData_PolylineXY ) HYDROGUI_SplitPolylinesDlg::GetToolPolyline() const
99 if( GetMode()==ByTool )
100 return Handle( HYDROData_PolylineXY )::DownCast( myToolPolyline->GetObject() );
102 return Handle( HYDROData_PolylineXY )();
105 gp_Pnt2d HYDROGUI_SplitPolylinesDlg::GetPoint() const
107 return gp_Pnt2d( myX->value(), myY->value() );
110 HYDROData_SequenceOfObjects HYDROGUI_SplitPolylinesDlg::GetPolylines() const
112 if( GetMode()==Split )
113 return myPolylines->selectedObjects();
115 return HYDROData_SequenceOfObjects();
118 void HYDROGUI_SplitPolylinesDlg::setPolylinesFromSelection()
120 Handle( HYDROData_Entity ) anObject = HYDROGUI_Tool::GetSelectedObject( module() );
121 if( anObject.IsNull() || anObject->GetKind() != KIND_POLYLINEXY )
124 QString aName = anObject->GetName();
125 myMainPolyline1->setObjectName( aName );
126 myMainPolyline2->setObjectName( aName );
127 myPolylines->setObjectsFromSelection();