Salome HOME
*** empty log message ***
[modules/geom.git] / src / TransformationGUI / TransformationGUI_OffsetDlg.cxx
1 // GEOM GEOMGUI : GUI for Geometry component
2 //
3 // Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
5 // 
6 // This library is free software; you can redistribute it and/or 
7 // modify it under the terms of the GNU Lesser General Public 
8 // License as published by the Free Software Foundation; either 
9 // version 2.1 of the License. 
10 // 
11 // This library is distributed in the hope that it will be useful, 
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of 
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
14 // Lesser General Public License for more details. 
15 // 
16 // You should have received a copy of the GNU Lesser General Public 
17 // License along with this library; if not, write to the Free Software 
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
19 // 
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 // File   : TransformationGUI_OffsetDlg.cxx
23 // Author : Lucien PIGNOLONI, Open CASCADE S.A.S.
24 //
25
26 #include "TransformationGUI_OffsetDlg.h"
27
28 #include <DlgRef.h>
29 #include <GeometryGUI.h>
30 #include <GEOMBase.h>
31
32 #include <SUIT_ResourceMgr.h>
33 #include <SUIT_Session.h>
34 #include <SalomeApp_Application.h>
35 #include <LightApp_SelectionMgr.h>
36
37 //=================================================================================
38 // class    : TransformationGUI_OffsetDlg()
39 // purpose  : Constructs a TransformationGUI_OffsetDlg which is a child of 'parent', with the 
40 //            name 'name' and widget flags set to 'f'.
41 //            The dialog will by default be modeless, unless you set 'modal' to
42 //            TRUE to construct a modal dialog.
43 //=================================================================================
44 TransformationGUI_OffsetDlg::TransformationGUI_OffsetDlg( GeometryGUI* theGeometryGUI, QWidget* parent,
45                                                           bool modal, Qt::WindowFlags fl )
46   : GEOMBase_Skeleton( theGeometryGUI, parent, modal, fl )
47 {
48   QPixmap image0( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_OFFSET" ) ) );
49   QPixmap image1( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
50
51   setWindowTitle( tr( "GEOM_OFFSET_TITLE" ) );
52
53   /***************************************************************/
54   mainFrame()->GroupConstructors->setTitle( tr( "GEOM_OFFSET" ) );
55   mainFrame()->RadioButton1->setIcon( image0 );
56   mainFrame()->RadioButton2->setAttribute( Qt::WA_DeleteOnClose );
57   mainFrame()->RadioButton2->close();
58   mainFrame()->RadioButton3->setAttribute( Qt::WA_DeleteOnClose );
59   mainFrame()->RadioButton3->close();
60  
61   GroupPoints = new DlgRef_1Sel1Spin1Check( centralWidget() );
62   GroupPoints->GroupBox1->setTitle( tr( "GEOM_ARGUMENTS" ) );
63   GroupPoints->TextLabel1->setText( tr( "GEOM_OBJECTS" ) );
64   GroupPoints->TextLabel2->setText( tr( "GEOM_OFFSET" ) );
65   GroupPoints->CheckButton1->setText( tr( "GEOM_CREATE_COPY" ) );
66
67   // san -- modification of an exisitng object by offset is not allowed
68   GroupPoints->CheckButton1->hide();
69
70   GroupPoints->PushButton1->setIcon( image1 );
71   
72   QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
73   layout->setMargin( 0 ); layout->setSpacing( 6 );
74   layout->addWidget( GroupPoints );
75   
76   /***************************************************************/
77
78   setHelpFileName( "offset_surface.htm" );  
79   
80   Init();
81 }
82
83
84 //=================================================================================
85 // function : ~TransformationGUI_OffsetDlg()
86 // purpose  : Destroys the object and frees any allocated resources
87 //=================================================================================
88 TransformationGUI_OffsetDlg::~TransformationGUI_OffsetDlg()
89 {  
90   /* no need to delete child widgets, Qt does it all for us */
91 }
92
93
94 //=================================================================================
95 // function : Init()
96 // purpose  :
97 //=================================================================================
98 void TransformationGUI_OffsetDlg::Init()
99 {  
100   /* init variables */
101   myEditCurrentArgument = GroupPoints->LineEdit1;
102   GroupPoints->LineEdit1->setReadOnly( true );
103   
104   /* Get setting of step value from file configuration */
105   double step = 1;
106    
107   /* min, max, step and decimals for spin boxes & initial values */
108   initSpinBox( GroupPoints->SpinBox_DX, COORD_MIN, COORD_MAX, step, 3 );
109   GroupPoints->SpinBox_DX->setDecimals( 5 );
110   //@ GroupPoints->SpinBox_DX->setDblPrecision(1e-05);    
111   GroupPoints->SpinBox_DX->setValue( 1e-05 );
112   
113   // Activate Create a Copy mode
114   GroupPoints->CheckButton1->setChecked( true );
115   CreateCopyModeChanged( true );
116
117   /* signals and slots connections */
118   connect( buttonOk(),    SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
119   connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
120   
121   connect( GroupPoints->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
122   connect( myGeomGUI->getApp()->selectionMgr(), 
123            SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
124
125   connect( GroupPoints->SpinBox_DX,   SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox() ) );
126   connect( GroupPoints->CheckButton1, SIGNAL( toggled( bool ) ),        this, SLOT( CreateCopyModeChanged( bool ) ) );
127   
128   initName( tr( "GEOM_OFFSET" ) );
129
130   globalSelection( GEOM_ALLSHAPES );
131   
132 }
133
134
135 //=================================================================================
136 // function : ClickOnOk()
137 // purpose  :
138 //=================================================================================
139 void TransformationGUI_OffsetDlg::ClickOnOk()
140 {
141   if ( ClickOnApply() )
142     ClickOnCancel();
143 }
144
145
146 //=================================================================================
147 // function : ClickOnApply()
148 // purpose  :
149 //=================================================================================
150 bool TransformationGUI_OffsetDlg::ClickOnApply()
151 {
152   if ( !onAccept( GroupPoints->CheckButton1->isChecked() ) )
153     return false;
154   
155   initName();
156   return true;
157 }
158
159
160 //=================================================================================
161 // function : SelectionIntoArgument()
162 // purpose  : Called when selection has changed
163 //=================================================================================
164 void TransformationGUI_OffsetDlg::SelectionIntoArgument()
165 {
166   myEditCurrentArgument->setText( "" );
167   QString aName;
168
169   int aNbSel = GEOMBase::GetNameOfSelectedIObjects( selectedIO(), aName );
170   if ( aNbSel < 1 ) {
171     myObjects.length( 0 );
172     return;
173   }
174
175   // nbSel > 0
176   GEOMBase::ConvertListOfIOInListOfGO( selectedIO(), myObjects );
177   if ( !myObjects.length() )
178     return;
179   
180   myEditCurrentArgument->setText( aName );
181   
182   displayPreview();
183 }
184
185
186 //=================================================================================
187 // function : LineEditReturnPressed()
188 // purpose  :
189 //=================================================================================
190 void TransformationGUI_OffsetDlg::LineEditReturnPressed()
191 {
192   QLineEdit* send = (QLineEdit*)sender();
193   if ( send == GroupPoints->LineEdit1 ) {
194     myEditCurrentArgument = GroupPoints->LineEdit1;
195     GEOMBase_Skeleton::LineEditReturnPressed();
196   }
197 }
198
199
200 //=================================================================================
201 // function : SetEditCurrentArgument()
202 // purpose  :
203 //=================================================================================
204 void TransformationGUI_OffsetDlg::SetEditCurrentArgument()
205 {
206   QPushButton* send = (QPushButton*)sender();
207   
208   if ( send == GroupPoints->PushButton1 ) {
209     myEditCurrentArgument = GroupPoints->LineEdit1;
210     myEditCurrentArgument->setFocus();
211     SelectionIntoArgument();
212   }
213 }
214
215
216 //=================================================================================
217 // function : enterEvent()
218 // purpose  : when mouse enter onto the QWidget
219 //=================================================================================
220 void TransformationGUI_OffsetDlg::enterEvent( QEvent* )
221 {
222   if ( !mainFrame()->GroupConstructors->isEnabled() )
223     ActivateThisDialog();
224 }
225
226
227 //=================================================================================
228 // function : ActivateThisDialog()
229 // purpose  :
230 //=================================================================================
231 void TransformationGUI_OffsetDlg::ActivateThisDialog()
232 {
233   GEOMBase_Skeleton::ActivateThisDialog();
234   connect( myGeomGUI->getApp()->selectionMgr(), 
235            SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
236   globalSelection( GEOM_ALLSHAPES );
237   myEditCurrentArgument = GroupPoints->LineEdit1;
238   myEditCurrentArgument->setFocus();
239 }
240
241
242 //=================================================================================
243 // function : ValueChangedInSpinBox()
244 // purpose  :
245 //=================================================================================
246 void TransformationGUI_OffsetDlg::ValueChangedInSpinBox()
247 {
248   displayPreview();
249 }
250
251
252 //=================================================================================
253 // function : createOperation
254 // purpose  :
255 //=================================================================================
256 GEOM::GEOM_IOperations_ptr TransformationGUI_OffsetDlg::createOperation()
257 {
258   return getGeomEngine()->GetITransformOperations( getStudyId() );
259 }
260
261 //=================================================================================
262 // function : isValid
263 // purpose  :
264 //=================================================================================
265 bool TransformationGUI_OffsetDlg::isValid( QString& msg )
266 {
267   //return !(myObjects.length() == 0);
268   if ( myObjects.length() == 0 ) return false;
269
270   for ( int i = 0; i < myObjects.length(); i++ ) {
271     GEOM::shape_type aType = myObjects[i]->GetShapeType();
272     if ( aType != GEOM::FACE && aType != GEOM::SHELL && aType != GEOM::SOLID ) {
273       msg = tr( "ERROR_SHAPE_TYPE" );
274       return false;
275     }
276   }
277   return true;
278 }
279
280
281 //=================================================================================
282 // function : execute
283 // purpose  :
284 //=================================================================================
285 bool TransformationGUI_OffsetDlg::execute( ObjectList& objects )
286 {
287   bool res = false;
288   
289   GEOM::GEOM_Object_var anObj;
290   
291   if ( GroupPoints->CheckButton1->isChecked() || IsPreview() ) {
292     for ( int i = 0; i < myObjects.length(); i++ ) {
293       
294       anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->OffsetShapeCopy( myObjects[i], GetOffset() );
295       if ( !anObj->_is_nil() )
296         objects.push_back( anObj._retn() );
297     }
298   }
299   else {
300     for ( int i = 0; i < myObjects.length(); i++ ) {
301       anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->OffsetShape( myObjects[i], GetOffset() );
302       if ( !anObj->_is_nil() )
303         objects.push_back( anObj._retn() );
304     }
305   }
306   res = true;
307     
308   return res;
309 }
310
311 //=================================================================================
312 // function : closeEvent
313 // purpose  :
314 //=================================================================================
315 void TransformationGUI_OffsetDlg::closeEvent( QCloseEvent* e )
316 {
317   // myGeomGUI->SetState( -1 );
318   GEOMBase_Skeleton::closeEvent( e );
319 }
320
321
322 //=================================================================================
323 // function : GetOffset()
324 // purpose  :
325 //=================================================================================
326 double TransformationGUI_OffsetDlg::GetOffset() const
327 {
328   return GroupPoints->SpinBox_DX->value();
329 }
330
331
332 //=================================================================================
333 // function :  CreateCopyModeChanged()
334 // purpose  :
335 //=================================================================================
336 void TransformationGUI_OffsetDlg::CreateCopyModeChanged( bool isCreateCopy )
337 {
338   mainFrame()->GroupBoxName->setEnabled( isCreateCopy );
339 }