]> SALOME platform Git repositories - modules/geom.git/blob - src/TransformationGUI/TransformationGUI_OffsetDlg.cxx
Salome HOME
Integration of PAL/SALOME V2.1.0c from OCC
[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
123
124 //=================================================================================
125 // function : ClickOnOk()
126 // purpose  :
127 //=================================================================================
128 void TransformationGUI_OffsetDlg::ClickOnOk()
129 {
130   if ( ClickOnApply() )
131     ClickOnCancel();
132 }
133
134
135 //=================================================================================
136 // function : ClickOnApply()
137 // purpose  :
138 //=================================================================================
139 bool TransformationGUI_OffsetDlg::ClickOnApply()
140 {
141   if ( !onAccept( GroupPoints->CheckButton1->isChecked() ) )
142     return false;
143   
144   initName();
145   return true;
146 }
147
148
149 //=======================================================================
150 // function : ClickOnCancel()
151 // purpose  :
152 //=======================================================================
153 void TransformationGUI_OffsetDlg::ClickOnCancel()
154 {
155   GEOMBase_Skeleton::ClickOnCancel();
156 }
157
158
159 //=================================================================================
160 // function : SelectionIntoArgument()
161 // purpose  : Called when selection has changed
162 //=================================================================================
163 void TransformationGUI_OffsetDlg::SelectionIntoArgument()
164 {
165   myEditCurrentArgument->setText("");
166   QString aName;
167
168   int aNbSel = GEOMBase::GetNameOfSelectedIObjects(mySelection, aName);
169   if(aNbSel < 1)
170     {
171       myObjects.length(0);
172       return;
173     }
174
175   // nbSel > 0
176   GEOMBase::ConvertListOfIOInListOfGO(mySelection->StoredIObjects(), myObjects);
177   if (!myObjects.length())
178     return;
179   if(aNbSel != 1)
180     aName = tr("%1_objects").arg(aNbSel);
181
182   myEditCurrentArgument->setText( aName );
183   
184   displayPreview();
185 }
186
187
188 //=================================================================================
189 // function : LineEditReturnPressed()
190 // purpose  :
191 //=================================================================================
192 void TransformationGUI_OffsetDlg::LineEditReturnPressed()
193 {
194   QLineEdit* send = (QLineEdit*)sender();
195   if ( send == GroupPoints->LineEdit1 )
196   {
197     myEditCurrentArgument = GroupPoints->LineEdit1;
198     GEOMBase_Skeleton::LineEditReturnPressed();
199   }
200 }
201
202
203 //=================================================================================
204 // function : SetEditCurrentArgument()
205 // purpose  :
206 //=================================================================================
207 void TransformationGUI_OffsetDlg::SetEditCurrentArgument()
208 {
209   QPushButton* send = (QPushButton*)sender();
210   
211   if(send == GroupPoints->PushButton1)
212     {
213       myEditCurrentArgument = GroupPoints->LineEdit1;
214       myEditCurrentArgument->setFocus();
215       SelectionIntoArgument();
216     }
217 }
218
219
220 //=================================================================================
221 // function : enterEvent()
222 // purpose  : when mouse enter onto the QWidget
223 //=================================================================================
224 void TransformationGUI_OffsetDlg::enterEvent(QEvent * e)
225 {
226   if ( !GroupConstructors->isEnabled() )
227     ActivateThisDialog();
228 }
229
230
231 //=================================================================================
232 // function : ActivateThisDialog()
233 // purpose  :
234 //=================================================================================
235 void TransformationGUI_OffsetDlg::ActivateThisDialog()
236 {
237   GEOMBase_Skeleton::ActivateThisDialog();
238   connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
239   globalSelection();
240   myEditCurrentArgument = GroupPoints->LineEdit1;
241   myEditCurrentArgument->setFocus();
242 }
243
244
245 //=================================================================================
246 // function : DeactivateActiveDialog()
247 // purpose  : public slot to deactivate if active
248 //=================================================================================
249 void TransformationGUI_OffsetDlg::DeactivateActiveDialog()
250 {
251  GEOMBase_Skeleton::DeactivateActiveDialog();
252 }
253
254
255 //=================================================================================
256 // function : ValueChangedInSpinBox()
257 // purpose  :
258 //=================================================================================
259 void TransformationGUI_OffsetDlg::ValueChangedInSpinBox()
260 {
261   displayPreview();
262 }
263
264
265 //=================================================================================
266 // function : createOperation
267 // purpose  :
268 //=================================================================================
269 GEOM::GEOM_IOperations_ptr TransformationGUI_OffsetDlg::createOperation()
270 {
271   return getGeomEngine()->GetITransformOperations( getStudyId() );
272 }
273
274 //=================================================================================
275 // function : isValid
276 // purpose  :
277 //=================================================================================
278 bool TransformationGUI_OffsetDlg::isValid( QString& msg )
279 {
280   return !(myObjects.length() == 0);
281 }
282
283
284 //=================================================================================
285 // function : execute
286 // purpose  :
287 //=================================================================================
288 bool TransformationGUI_OffsetDlg::execute( ObjectList& objects )
289 {
290   bool res = false;
291   
292   GEOM::GEOM_Object_var anObj;
293   
294   
295   if (GroupPoints->CheckButton1->isChecked() || IsPreview())
296     for (int i = 0; i < myObjects.length(); i++)
297       {
298         anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->OffsetShapeCopy( myObjects[i], GetOffset() );
299         if ( !anObj->_is_nil() )
300           objects.push_back( anObj._retn() );
301       }
302   else
303     for (int i = 0; i < myObjects.length(); i++)
304       {
305         anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->OffsetShape( myObjects[i], GetOffset() );
306         if ( !anObj->_is_nil() )
307           objects.push_back( anObj._retn() );
308       }
309      
310   res = true;
311     
312   return res;
313 }
314
315 //=================================================================================
316 // function : closeEvent
317 // purpose  :
318 //=================================================================================
319 void TransformationGUI_OffsetDlg::closeEvent( QCloseEvent* e )
320 {
321   myGeomGUI->SetState( -1 );
322   GEOMBase_Skeleton::closeEvent( e );
323 }
324
325
326 //=================================================================================
327 // function : GetOffset()
328 // purpose  :
329 //=================================================================================
330 double TransformationGUI_OffsetDlg::GetOffset() const
331 {
332   return GroupPoints->SpinBox_DX->GetValue();
333 }
334
335
336 //=================================================================================
337 // function :  CreateCopyModeChanged()
338 // purpose  :
339 //=================================================================================
340 void TransformationGUI_OffsetDlg::CreateCopyModeChanged(bool isCreateCopy)
341 {
342   this->GroupBoxName->setEnabled(isCreateCopy);
343 }