]> SALOME platform Git repositories - modules/geom.git/blob - src/TransformationGUI/TransformationGUI_OffsetDlg.cxx
Salome HOME
Merge with version on tag OCC-V2_1_0d
[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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
21 //
22 //
23 //
24 //  File   : TransformationGUI_OffsetDlg.cxx
25 //  Author : Lucien PIGNOLONI
26 //  Module : GEOM
27 //  $Header$
28
29 #include "TransformationGUI_OffsetDlg.h"
30 #include <QAD_Desktop.h>
31 #include "utilities.h"
32
33 #include <qcheckbox.h>
34
35 using namespace std;
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(QWidget* parent,  const char* name, SALOME_Selection* Sel, bool modal, WFlags fl)
45     :GEOMBase_Skeleton(parent, name, Sel, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
46 {
47   QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_DLG_OFFSET")));
48   QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_SELECT")));
49
50   setCaption(tr("GEOM_OFFSET_TITLE"));
51
52   /***************************************************************/
53   GroupConstructors->setTitle(tr("GEOM_OFFSET"));
54   RadioButton1->setPixmap(image0);
55   RadioButton2->close(TRUE);
56   RadioButton3->close(TRUE);
57  
58   GroupPoints = new DlgRef_1Sel1Spin1Check(this, "GroupPoints");
59   GroupPoints->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
60   GroupPoints->TextLabel1->setText(tr("GEOM_OBJECTS"));
61   GroupPoints->TextLabel2->setText(tr("GEOM_OFFSET"));
62   GroupPoints->CheckButton1->setText(tr("GEOM_CREATE_COPY"));
63
64   // san -- modification of an exisitng object by offset is not allowed
65   GroupPoints->CheckButton1->hide();
66
67   GroupPoints->PushButton1->setPixmap(image1);
68   
69   Layout1->addWidget(GroupPoints, 2, 0);
70   
71   /***************************************************************/
72   
73   Init();
74 }
75
76
77 //=================================================================================
78 // function : ~TransformationGUI_OffsetDlg()
79 // purpose  : Destroys the object and frees any allocated resources
80 //=================================================================================
81 TransformationGUI_OffsetDlg::~TransformationGUI_OffsetDlg()
82 {  
83   /* no need to delete child widgets, Qt does it all for us */
84 }
85
86
87 //=================================================================================
88 // function : Init()
89 // purpose  :
90 //=================================================================================
91 void TransformationGUI_OffsetDlg::Init()
92 {  
93   /* init variables */
94   myEditCurrentArgument = GroupPoints->LineEdit1;
95   GroupPoints->LineEdit1->setReadOnly( true );
96   
97   /* Get setting of step value from file configuration */
98   double step = 1;
99    
100   /* min, max, step and decimals for spin boxes & initial values */
101   GroupPoints->SpinBox_DX->RangeStepAndValidator(-999.999, 999.999, step, 3);
102   GroupPoints->SpinBox_DX->setPrecision(5);
103   GroupPoints->SpinBox_DX->setDblPrecision(1e-05);    
104   GroupPoints->SpinBox_DX->SetValue(1e-05);
105   
106   // Activate Create a Copy mode
107   GroupPoints->CheckButton1->setChecked(true);
108   CreateCopyModeChanged(true);
109
110   /* signals and slots connections */
111   connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
112   connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
113   
114   connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
115   connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
116
117   connect(GroupPoints->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
118   connect(GroupPoints->CheckButton1, SIGNAL(toggled(bool)), this, SLOT(CreateCopyModeChanged(bool)));
119   
120   initName( tr( "GEOM_OFFSET" ) );
121
122   globalSelection( GEOM_ALLSHAPES );
123   
124 }
125
126
127 //=================================================================================
128 // function : ClickOnOk()
129 // purpose  :
130 //=================================================================================
131 void TransformationGUI_OffsetDlg::ClickOnOk()
132 {
133   if ( ClickOnApply() )
134     ClickOnCancel();
135 }
136
137
138 //=================================================================================
139 // function : ClickOnApply()
140 // purpose  :
141 //=================================================================================
142 bool TransformationGUI_OffsetDlg::ClickOnApply()
143 {
144   if ( !onAccept( GroupPoints->CheckButton1->isChecked() ) )
145     return false;
146   
147   initName();
148   return true;
149 }
150
151
152 //=======================================================================
153 // function : ClickOnCancel()
154 // purpose  :
155 //=======================================================================
156 void TransformationGUI_OffsetDlg::ClickOnCancel()
157 {
158   GEOMBase_Skeleton::ClickOnCancel();
159 }
160
161
162 //=================================================================================
163 // function : SelectionIntoArgument()
164 // purpose  : Called when selection has changed
165 //=================================================================================
166 void TransformationGUI_OffsetDlg::SelectionIntoArgument()
167 {
168   myEditCurrentArgument->setText("");
169   QString aName;
170
171   int aNbSel = GEOMBase::GetNameOfSelectedIObjects(mySelection, aName);
172   if(aNbSel < 1)
173     {
174       myObjects.length(0);
175       return;
176     }
177
178   // nbSel > 0
179   GEOMBase::ConvertListOfIOInListOfGO(mySelection->StoredIObjects(), myObjects);
180   if (!myObjects.length())
181     return;
182   if(aNbSel != 1)
183     aName = tr("%1_objects").arg(aNbSel);
184
185   myEditCurrentArgument->setText( aName );
186   
187   displayPreview();
188 }
189
190
191 //=================================================================================
192 // function : LineEditReturnPressed()
193 // purpose  :
194 //=================================================================================
195 void TransformationGUI_OffsetDlg::LineEditReturnPressed()
196 {
197   QLineEdit* send = (QLineEdit*)sender();
198   if ( send == GroupPoints->LineEdit1 )
199   {
200     myEditCurrentArgument = GroupPoints->LineEdit1;
201     GEOMBase_Skeleton::LineEditReturnPressed();
202   }
203 }
204
205
206 //=================================================================================
207 // function : SetEditCurrentArgument()
208 // purpose  :
209 //=================================================================================
210 void TransformationGUI_OffsetDlg::SetEditCurrentArgument()
211 {
212   QPushButton* send = (QPushButton*)sender();
213   
214   if(send == GroupPoints->PushButton1)
215     {
216       myEditCurrentArgument = GroupPoints->LineEdit1;
217       myEditCurrentArgument->setFocus();
218       SelectionIntoArgument();
219     }
220 }
221
222
223 //=================================================================================
224 // function : enterEvent()
225 // purpose  : when mouse enter onto the QWidget
226 //=================================================================================
227 void TransformationGUI_OffsetDlg::enterEvent(QEvent * e)
228 {
229   if ( !GroupConstructors->isEnabled() )
230     ActivateThisDialog();
231 }
232
233
234 //=================================================================================
235 // function : ActivateThisDialog()
236 // purpose  :
237 //=================================================================================
238 void TransformationGUI_OffsetDlg::ActivateThisDialog()
239 {
240   GEOMBase_Skeleton::ActivateThisDialog();
241   connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
242   globalSelection( GEOM_ALLSHAPES );
243   myEditCurrentArgument = GroupPoints->LineEdit1;
244   myEditCurrentArgument->setFocus();
245 }
246
247
248 //=================================================================================
249 // function : DeactivateActiveDialog()
250 // purpose  : public slot to deactivate if active
251 //=================================================================================
252 void TransformationGUI_OffsetDlg::DeactivateActiveDialog()
253 {
254  GEOMBase_Skeleton::DeactivateActiveDialog();
255 }
256
257
258 //=================================================================================
259 // function : ValueChangedInSpinBox()
260 // purpose  :
261 //=================================================================================
262 void TransformationGUI_OffsetDlg::ValueChangedInSpinBox()
263 {
264   displayPreview();
265 }
266
267
268 //=================================================================================
269 // function : createOperation
270 // purpose  :
271 //=================================================================================
272 GEOM::GEOM_IOperations_ptr TransformationGUI_OffsetDlg::createOperation()
273 {
274   return getGeomEngine()->GetITransformOperations( getStudyId() );
275 }
276
277 //=================================================================================
278 // function : isValid
279 // purpose  :
280 //=================================================================================
281 bool TransformationGUI_OffsetDlg::isValid( QString& msg )
282 {
283   return !(myObjects.length() == 0);
284 }
285
286
287 //=================================================================================
288 // function : execute
289 // purpose  :
290 //=================================================================================
291 bool TransformationGUI_OffsetDlg::execute( ObjectList& objects )
292 {
293   bool res = false;
294   
295   GEOM::GEOM_Object_var anObj;
296   
297   
298   if (GroupPoints->CheckButton1->isChecked() || IsPreview())
299     for (int i = 0; i < myObjects.length(); i++)
300       {
301         anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->OffsetShapeCopy( myObjects[i], GetOffset() );
302         if ( !anObj->_is_nil() )
303           objects.push_back( anObj._retn() );
304       }
305   else
306     for (int i = 0; i < myObjects.length(); i++)
307       {
308         anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->OffsetShape( myObjects[i], GetOffset() );
309         if ( !anObj->_is_nil() )
310           objects.push_back( anObj._retn() );
311       }
312      
313   res = true;
314     
315   return res;
316 }
317
318 //=================================================================================
319 // function : closeEvent
320 // purpose  :
321 //=================================================================================
322 void TransformationGUI_OffsetDlg::closeEvent( QCloseEvent* e )
323 {
324   myGeomGUI->SetState( -1 );
325   GEOMBase_Skeleton::closeEvent( e );
326 }
327
328
329 //=================================================================================
330 // function : GetOffset()
331 // purpose  :
332 //=================================================================================
333 double TransformationGUI_OffsetDlg::GetOffset() const
334 {
335   return GroupPoints->SpinBox_DX->GetValue();
336 }
337
338
339 //=================================================================================
340 // function :  CreateCopyModeChanged()
341 // purpose  :
342 //=================================================================================
343 void TransformationGUI_OffsetDlg::CreateCopyModeChanged(bool isCreateCopy)
344 {
345   this->GroupBoxName->setEnabled(isCreateCopy);
346 }