Salome HOME
683e310b034e6f4cee7a01362ae97d1bcb21d9de
[modules/hexablock.git] / src / HEXABLOCKGUI / MyGEOMBase_Skeleton.cxx
1 // Copyright (C) 2009-2023  CEA, EDF
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, or (at your option) any later version.
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 #include <QButtonGroup>
40
41 using namespace HEXABLOCK::GUI;
42
43 //=================================================================================
44 // class    : MyGEOMBase_Skeleton()
45 // purpose  : Constructs a MyGEOMBase_Skeleton which is a child of 'parent', with the
46 //            name 'name' and widget flags set to 'f'.
47 //            The dialog will by default be modeless, unless you set 'modal' to
48 //            true to construct a modal dialog.
49 //=================================================================================
50 MyGEOMBase_Skeleton::MyGEOMBase_Skeleton( QWidget* parent, Qt::WindowFlags fl )
51   : HexaBaseDialog(parent, NEW_MODE, fl),
52     myRBGroup( 0 )
53 {
54
55   myMainFrame = new MyDlgRef_Skeleton( this );
56   QVBoxLayout* topLayout = new QVBoxLayout( this );
57   topLayout->setMargin( 0 ); topLayout->setSpacing( 0 );
58   topLayout->addWidget( myMainFrame );
59
60   myMainFrame->GroupBoxPublish->setTitle( tr( "GEOM_PUBLISH_RESULT_GRP" ) );
61   myMainFrame->CheckBoxRestoreSS->setText( tr( "GEOM_RESTORE_SUB_SHAPES" ) );
62   myMainFrame->CheckBoxAddPrefix->setText( tr( "GEOM_RSS_ADD_FREFIX" ) );
63   myMainFrame->CheckBoxPreview->setText( tr("GEOM_PREVIEW") );
64
65   myRBGroup = new QButtonGroup( this );
66   myRBGroup->addButton( myMainFrame->RadioButton1, 0 );
67   myRBGroup->addButton( myMainFrame->RadioButton2, 1 );
68   myRBGroup->addButton( myMainFrame->RadioButton3, 2 );
69   myRBGroup->addButton( myMainFrame->RadioButton4, 3 );
70   myRBGroup->addButton( myMainFrame->RadioButton5, 4 );
71
72   connect( myRBGroup, SIGNAL( buttonClicked( int ) ), this, SIGNAL( constructorsClicked( int ) ) );
73   Init();
74 }
75
76 //=================================================================================
77 // function : ~MyGEOMBase_Skeleton()
78 // purpose  : Destroys the object and frees any allocated resources
79 //=================================================================================
80 MyGEOMBase_Skeleton::~MyGEOMBase_Skeleton()
81 {
82 }
83
84 //=================================================================================
85 // function : Init()
86 // purpose  :
87 //=================================================================================
88 void MyGEOMBase_Skeleton::Init()
89 {
90   /* displays Dialog */
91   myMainFrame->RadioButton1->setChecked( true );
92   myMainFrame->RadioButton4->hide();
93   myMainFrame->RadioButton5->hide();
94   myMainFrame->GroupBoxPublish->hide();
95 }
96
97 //=================================================================================
98 // function : initSpinBox()
99 // purpose  :
100 //=================================================================================
101 void MyGEOMBase_Skeleton::initSpinBox( QSpinBox* spinBox,
102                                      int min,  int max, int step )
103 {
104   spinBox->setRange( min, max );
105   spinBox->setSingleStep( step );
106 }
107
108 //=================================================================================
109 // function : initSpinBox()
110 // purpose  :
111 //=================================================================================
112 void MyGEOMBase_Skeleton::initSpinBox( SalomeApp_DoubleSpinBox* spinBox,
113                                      double min,  double max,
114                                      double step, const char* quantity, unsigned int decimals)
115 {
116   spinBox->setPrecision( decimals );
117   spinBox->setDecimals( decimals );
118   spinBox->setRange( min, max );
119   spinBox->setSingleStep( step );
120 }
121
122 //=================================================================================
123 // function : closeEvent()
124 // purpose  : same than click on cancel button
125 //=================================================================================
126 void MyGEOMBase_Skeleton::closeEvent( QCloseEvent* e )
127 {
128     TopoDS_Shape shape;
129     HEXABLOCKGUI::currentOccGView->displayPreview(shape);
130
131     QDialog::closeEvent( e );
132 }
133
134 //=================================================================================
135 // function : getConstructorId()
136 // purpose  :
137 //=================================================================================
138 int MyGEOMBase_Skeleton::getConstructorId() const
139 {
140   if ( myRBGroup )
141     return myRBGroup->checkedId();
142   return -1;
143 }
144
145 //=================================================================================
146 // function : setConstructorId( id )
147 // purpose  :
148 //=================================================================================
149 void MyGEOMBase_Skeleton::setConstructorId( const int id )
150 {
151   if ( myRBGroup && myRBGroup->button( id ) )
152     myRBGroup->button( id )->setChecked( true );
153 }
154
155 //=================================================================================
156 // function : unsetConstructorId
157 // purpose  :
158 //=================================================================================
159 void MyGEOMBase_Skeleton::unsetConstructorId()
160 {
161   // 0020428: EDF 906 GEOM : Performance for Group creation in GEOM
162   // uncheck all buttons
163   // workaround, because setChecked( false ) does not result in Qt4
164   bool isExclusive = myRBGroup->exclusive();
165   myRBGroup->setExclusive( false );
166   QList<QAbstractButton*> btnList = myRBGroup->buttons();
167   for ( int j = 0; j < 2; j++ )
168   {
169     QList<QAbstractButton*>::const_iterator it = btnList.constBegin(), itEnd = btnList.constEnd();
170     for ( ; it != itEnd; ++it )
171       (*it)->setCheckable( j == 1 );
172   }
173   myRBGroup->setExclusive( isExclusive );
174 }
175
176 MyDlgRef_Skeleton* MyGEOMBase_Skeleton::mainFrame()
177 {
178   return myMainFrame;
179 }
180
181 QWidget* MyGEOMBase_Skeleton::centralWidget()
182 {
183   return myMainFrame->GroupMedium;
184 }
185
186 //=================================================================================
187 // function : showOnlyPreviewControl()
188 // purpose  : display only CheckBoxPreview check box,
189 //            hide CheckBoxRestoreSS and CheckBoxAddPrefix
190 //=================================================================================
191 void MyGEOMBase_Skeleton::showOnlyPreviewControl(){
192   mainFrame()->GroupBoxPublish->show();
193   mainFrame()->CheckBoxRestoreSS->hide();
194   mainFrame()->CheckBoxAddPrefix->hide();
195 }
196