Salome HOME
Source IHM nettoye
[modules/hexablock.git] / src / HEXABLOCKGUI / MyGEOMBase_Skeleton.cxx
1 // Copyright (C) 2009-2013  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20
21 #include "MyGEOMBase_Skeleton.hxx"
22 #include "HEXABLOCKGUI_VtkDocumentGraphicView.hxx"
23
24 #include "MyDlgRef.hxx"
25
26 #include <SalomeApp_Application.h>
27 #include <SalomeApp_DoubleSpinBox.h>
28 #include <SalomeApp_Study.h>
29 #include <LightApp_Application.h>
30 #include <LightApp_SelectionMgr.h>
31 #include <SUIT_Desktop.h>
32 #include <SUIT_ResourceMgr.h>
33 #include <SUIT_Session.h>
34 #include <SUIT_MessageBox.h>
35
36 #include <QKeyEvent>
37 #include <QSpinBox>
38 #include <QDoubleSpinBox>
39
40 using namespace HEXABLOCK::GUI;
41
42 //=================================================================================
43 // class    : MyGEOMBase_Skeleton()
44 // purpose  : Constructs a MyGEOMBase_Skeleton which is a child of 'parent', with the
45 //            name 'name' and widget flags set to 'f'.
46 //            The dialog will by default be modeless, unless you set 'modal' to
47 //            true to construct a modal dialog.
48 //=================================================================================
49 MyGEOMBase_Skeleton::MyGEOMBase_Skeleton( QWidget* parent, Qt::WindowFlags fl )
50   : HexaBaseDialog(parent, NEW_MODE, fl),
51     myRBGroup( 0 )
52 {
53
54   myMainFrame = new MyDlgRef_Skeleton( this );
55   QVBoxLayout* topLayout = new QVBoxLayout( this );
56   topLayout->setMargin( 0 ); topLayout->setSpacing( 0 );
57   topLayout->addWidget( myMainFrame );
58
59   myMainFrame->GroupBoxPublish->setTitle( tr( "GEOM_PUBLISH_RESULT_GRP" ) );
60   myMainFrame->CheckBoxRestoreSS->setText( tr( "GEOM_RESTORE_SUB_SHAPES" ) );
61   myMainFrame->CheckBoxAddPrefix->setText( tr( "GEOM_RSS_ADD_FREFIX" ) );
62   myMainFrame->CheckBoxPreview->setText( tr("GEOM_PREVIEW") );
63
64   myRBGroup = new QButtonGroup( this );
65   myRBGroup->addButton( myMainFrame->RadioButton1, 0 );
66   myRBGroup->addButton( myMainFrame->RadioButton2, 1 );
67   myRBGroup->addButton( myMainFrame->RadioButton3, 2 );
68   myRBGroup->addButton( myMainFrame->RadioButton4, 3 );
69   myRBGroup->addButton( myMainFrame->RadioButton5, 4 );
70
71   connect( myRBGroup, SIGNAL( buttonClicked( int ) ), this, SIGNAL( constructorsClicked( int ) ) );
72   Init();
73 }
74
75 //=================================================================================
76 // function : ~MyGEOMBase_Skeleton()
77 // purpose  : Destroys the object and frees any allocated resources
78 //=================================================================================
79 MyGEOMBase_Skeleton::~MyGEOMBase_Skeleton()
80 {
81 }
82
83 //=================================================================================
84 // function : Init()
85 // purpose  :
86 //=================================================================================
87 void MyGEOMBase_Skeleton::Init()
88 {
89   /* displays Dialog */
90   myMainFrame->RadioButton1->setChecked( true );
91   myMainFrame->RadioButton4->hide();
92   myMainFrame->RadioButton5->hide();
93   myMainFrame->GroupBoxPublish->hide();
94 }
95
96 //=================================================================================
97 // function : initSpinBox()
98 // purpose  :
99 //=================================================================================
100 void MyGEOMBase_Skeleton::initSpinBox( QSpinBox* spinBox,
101                                      int min,  int max, int step )
102 {
103   spinBox->setRange( min, max );
104   spinBox->setSingleStep( step );
105 }
106
107 //=================================================================================
108 // function : initSpinBox()
109 // purpose  :
110 //=================================================================================
111 void MyGEOMBase_Skeleton::initSpinBox( SalomeApp_DoubleSpinBox* spinBox,
112                                      double min,  double max,
113                                      double step, const char* quantity, unsigned int decimals)
114 {
115   spinBox->setPrecision( decimals );
116   spinBox->setDecimals( decimals );
117   spinBox->setRange( min, max );
118   spinBox->setSingleStep( step );
119 }
120
121 //=================================================================================
122 // function : closeEvent()
123 // purpose  : same than click on cancel button
124 //=================================================================================
125 void MyGEOMBase_Skeleton::closeEvent( QCloseEvent* e )
126 {
127     TopoDS_Shape shape;
128     HEXABLOCKGUI::currentOccGView->displayPreview(shape);
129
130     QDialog::closeEvent( e );
131 }
132
133 //=================================================================================
134 // function : getConstructorId()
135 // purpose  :
136 //=================================================================================
137 int MyGEOMBase_Skeleton::getConstructorId() const
138 {
139   if ( myRBGroup )
140     return myRBGroup->checkedId();
141   return -1;
142 }
143
144 //=================================================================================
145 // function : setConstructorId( id )
146 // purpose  :
147 //=================================================================================
148 void MyGEOMBase_Skeleton::setConstructorId( const int id )
149 {
150   if ( myRBGroup && myRBGroup->button( id ) )
151     myRBGroup->button( id )->setChecked( true );
152 }
153
154 //=================================================================================
155 // function : unsetConstructorId
156 // purpose  :
157 //=================================================================================
158 void MyGEOMBase_Skeleton::unsetConstructorId()
159 {
160   // 0020428: EDF 906 GEOM : Performance for Group creation in GEOM
161   // uncheck all buttons
162   // workaround, because setChecked( false ) does not result in Qt4
163   bool isExclusive = myRBGroup->exclusive();
164   myRBGroup->setExclusive( false );
165   QList<QAbstractButton*> btnList = myRBGroup->buttons();
166   for ( int j = 0; j < 2; j++ )
167   {
168     QList<QAbstractButton*>::const_iterator it = btnList.constBegin(), itEnd = btnList.constEnd();
169     for ( ; it != itEnd; ++it )
170       (*it)->setCheckable( j == 1 );
171   }
172   myRBGroup->setExclusive( isExclusive );
173 }
174
175 MyDlgRef_Skeleton* MyGEOMBase_Skeleton::mainFrame()
176 {
177   return myMainFrame;
178 }
179
180 QWidget* MyGEOMBase_Skeleton::centralWidget()
181 {
182   return myMainFrame->GroupMedium;
183 }
184
185 //=================================================================================
186 // function : showOnlyPreviewControl()
187 // purpose  : display only CheckBoxPreview check box,
188 //            hide CheckBoxRestoreSS and CheckBoxAddPrefix
189 //=================================================================================
190 void MyGEOMBase_Skeleton::showOnlyPreviewControl(){
191   mainFrame()->GroupBoxPublish->show();
192   mainFrame()->CheckBoxRestoreSS->hide();
193   mainFrame()->CheckBoxAddPrefix->hide();
194 }
195