]> SALOME platform Git repositories - modules/hydro.git/blob - src/HYDROGUI/HYDROGUI_SplitPolylinesDlg.cxx
Salome HOME
refs #585: gui for polyline operations
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_SplitPolylinesDlg.cxx
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.
6 //
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.
11 //
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
15 //
16 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
17 //
18
19 #include <HYDROGUI_SplitPolylinesDlg.h>
20 #include <HYDROGUI_ObjComboBox.h>
21 #include <HYDROGUI_ObjListBox.h>
22 #include <HYDROGUI_Tool.h>
23 #include <QtxDoubleSpinBox.h>
24 #include <QFrame>
25 #include <QLabel>
26 #include <QGridLayout>
27 #include <QTabWidget>
28 #include <gp_Pnt2d.hxx>
29
30 HYDROGUI_SplitPolylinesDlg::HYDROGUI_SplitPolylinesDlg( HYDROGUI_Module* theModule, const QString& theTitle )
31 : HYDROGUI_InputPanel( theModule, theTitle )
32 {
33   QFrame* aFrame = new QFrame( mainFrame() );
34   addWidget( aFrame, 1 );
35
36   QGridLayout* aLayout = new QGridLayout( aFrame );
37   aLayout->setMargin( 5 );
38   aLayout->setSpacing( 5 );
39
40   myTab = new QTabWidget( aFrame );
41   aLayout->addWidget( myTab, 0, 0 );
42
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 );
47   
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" ) );
57
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 );
61
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" ) );
67
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" ) );
73 }
74
75 HYDROGUI_SplitPolylinesDlg::~HYDROGUI_SplitPolylinesDlg()
76 {
77 }
78
79 HYDROGUI_SplitPolylinesDlg::Mode HYDROGUI_SplitPolylinesDlg::GetMode() const
80 {
81   return ( Mode )myTab->currentIndex();
82 }
83
84 Handle( HYDROData_PolylineXY ) HYDROGUI_SplitPolylinesDlg::GetMainPolyline() const
85 {
86   switch( GetMode() )
87   {
88   case ByPoint:
89     return Handle( HYDROData_PolylineXY )::DownCast( myMainPolyline1->GetObject() );
90   case ByTool:
91     return Handle( HYDROData_PolylineXY )::DownCast( myMainPolyline2->GetObject() );
92   default:
93     return Handle( HYDROData_PolylineXY )();
94   }
95 }
96
97 Handle( HYDROData_PolylineXY ) HYDROGUI_SplitPolylinesDlg::GetToolPolyline() const
98 {
99   if( GetMode()==ByTool )
100     return Handle( HYDROData_PolylineXY )::DownCast( myToolPolyline->GetObject() );
101   else
102     return Handle( HYDROData_PolylineXY )();
103 }
104
105 gp_Pnt2d HYDROGUI_SplitPolylinesDlg::GetPoint() const
106 {
107   return gp_Pnt2d( myX->value(), myY->value() );
108 }
109
110 HYDROData_SequenceOfObjects HYDROGUI_SplitPolylinesDlg::GetPolylines() const
111 {
112   if( GetMode()==Split )
113     return myPolylines->selectedObjects();
114   else
115     return HYDROData_SequenceOfObjects();
116 }
117
118 void HYDROGUI_SplitPolylinesDlg::setPolylinesFromSelection()
119 {
120   Handle( HYDROData_Entity ) anObject = HYDROGUI_Tool::GetSelectedObject( module() );
121   if( anObject.IsNull() || anObject->GetKind() != KIND_POLYLINEXY )
122     return;
123
124   QString aName = anObject->GetName();
125   myMainPolyline1->setObjectName( aName );
126   myMainPolyline2->setObjectName( aName );
127   myPolylines->setObjectsFromSelection();
128 }