]> SALOME platform Git repositories - modules/geom.git/blob - src/TransformationGUI/TransformationGUI_OffsetDlg.cxx
Salome HOME
Update copyright information
[modules/geom.git] / src / TransformationGUI / TransformationGUI_OffsetDlg.cxx
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  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 //  GEOM GEOMGUI : GUI for Geometry component
23 //  File   : TransformationGUI_OffsetDlg.cxx
24 //  Author : Lucien PIGNOLONI
25 //  Module : GEOM
26 //  $Header$
27 //
28 #include "TransformationGUI_OffsetDlg.h"
29
30 #include "SUIT_Desktop.h"
31 #include "SUIT_Session.h"
32 #include "SalomeApp_Application.h"
33 #include "LightApp_SelectionMgr.h"
34
35 #include <qlabel.h>
36 #include <qcheckbox.h>
37
38 #include "utilities.h"
39
40 using namespace std;
41
42 //=================================================================================
43 // class    : TransformationGUI_OffsetDlg()
44 // purpose  : Constructs a TransformationGUI_OffsetDlg 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 TransformationGUI_OffsetDlg::TransformationGUI_OffsetDlg(GeometryGUI* theGeometryGUI, QWidget* parent,
50                                                          const char* name, bool modal, WFlags fl)
51     :GEOMBase_Skeleton(theGeometryGUI, parent, name, modal, WStyle_Customize |
52                        WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
53 {
54   QPixmap image0(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_OFFSET")));
55   QPixmap image1(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_SELECT")));
56
57   setCaption(tr("GEOM_OFFSET_TITLE"));
58
59   /***************************************************************/
60   GroupConstructors->setTitle(tr("GEOM_OFFSET"));
61   RadioButton1->setPixmap(image0);
62   RadioButton2->close(TRUE);
63   RadioButton3->close(TRUE);
64
65   GroupPoints = new DlgRef_1Sel1Spin1Check(this, "GroupPoints");
66   GroupPoints->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
67   GroupPoints->TextLabel1->setText(tr("GEOM_OBJECTS"));
68   GroupPoints->TextLabel2->setText(tr("GEOM_OFFSET"));
69   GroupPoints->CheckButton1->setText(tr("GEOM_CREATE_COPY"));
70
71   // san -- modification of an exisitng object by offset is not allowed
72   GroupPoints->CheckButton1->hide();
73
74   GroupPoints->PushButton1->setPixmap(image1);
75
76   Layout1->addWidget(GroupPoints, 2, 0);
77
78   /***************************************************************/
79
80   setHelpFileName("offset_operation_page.html");
81
82   Init();
83 }
84
85
86 //=================================================================================
87 // function : ~TransformationGUI_OffsetDlg()
88 // purpose  : Destroys the object and frees any allocated resources
89 //=================================================================================
90 TransformationGUI_OffsetDlg::~TransformationGUI_OffsetDlg()
91 {
92   /* no need to delete child widgets, Qt does it all for us */
93 }
94
95
96 //=================================================================================
97 // function : Init()
98 // purpose  :
99 //=================================================================================
100 void TransformationGUI_OffsetDlg::Init()
101 {
102   /* init variables */
103   myEditCurrentArgument = GroupPoints->LineEdit1;
104   GroupPoints->LineEdit1->setReadOnly( true );
105
106   /* Get setting of step value from file configuration */
107   double step = 1;
108
109   /* min, max, step and decimals for spin boxes & initial values */
110   GroupPoints->SpinBox_DX->RangeStepAndValidator(COORD_MIN, COORD_MAX, step, DBL_DIGITS_DISPLAY);
111   GroupPoints->SpinBox_DX->SetValue(1e-05);
112
113   // Activate Create a Copy mode
114   GroupPoints->CheckButton1->setChecked(true);
115   CreateCopyModeChanged(true);
116
117   GroupBoxPublish->show();
118
119   /* signals and slots connections */
120   connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
121   connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
122
123   connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
124   connect(myGeomGUI->getApp()->selectionMgr(),
125           SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
126
127   connect(GroupPoints->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
128   connect(GroupPoints->CheckButton1, SIGNAL(toggled(bool)), this, SLOT(CreateCopyModeChanged(bool)));
129
130   initName( tr( "GEOM_OFFSET" ) );
131
132   globalSelection( GEOM_ALLSHAPES );
133 }
134
135
136 //=================================================================================
137 // function : ClickOnOk()
138 // purpose  :
139 //=================================================================================
140 void TransformationGUI_OffsetDlg::ClickOnOk()
141 {
142   if ( ClickOnApply() )
143     ClickOnCancel();
144 }
145
146
147 //=================================================================================
148 // function : ClickOnApply()
149 // purpose  :
150 //=================================================================================
151 bool TransformationGUI_OffsetDlg::ClickOnApply()
152 {
153   if ( !onAccept( GroupPoints->CheckButton1->isChecked() ) )
154     return false;
155
156   initName();
157   return true;
158 }
159
160
161 //=================================================================================
162 // function : SelectionIntoArgument()
163 // purpose  : Called when selection has changed
164 //=================================================================================
165 void TransformationGUI_OffsetDlg::SelectionIntoArgument()
166 {
167   myEditCurrentArgument->setText("");
168   QString aName;
169
170   int aNbSel = GEOMBase::GetNameOfSelectedIObjects(selectedIO(), aName);
171   if(aNbSel < 1)
172     {
173       myObjects.length(0);
174       return;
175     }
176
177   // nbSel > 0
178   GEOMBase::ConvertListOfIOInListOfGO(selectedIO(), myObjects);
179   if (!myObjects.length())
180     return;
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(myGeomGUI->getApp()->selectionMgr(),
239           SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
240   globalSelection( GEOM_ALLSHAPES );
241   myEditCurrentArgument = GroupPoints->LineEdit1;
242   myEditCurrentArgument->setFocus();
243 }
244
245
246 //=================================================================================
247 // function : ValueChangedInSpinBox()
248 // purpose  :
249 //=================================================================================
250 void TransformationGUI_OffsetDlg::ValueChangedInSpinBox()
251 {
252   displayPreview();
253 }
254
255
256 //=================================================================================
257 // function : createOperation
258 // purpose  :
259 //=================================================================================
260 GEOM::GEOM_IOperations_ptr TransformationGUI_OffsetDlg::createOperation()
261 {
262   return getGeomEngine()->GetITransformOperations( getStudyId() );
263 }
264
265 //=================================================================================
266 // function : isValid
267 // purpose  :
268 //=================================================================================
269 bool TransformationGUI_OffsetDlg::isValid( QString& msg )
270 {
271   //return !(myObjects.length() == 0);
272   if (myObjects.length() == 0) return false;
273
274   for (int i = 0; i < myObjects.length(); i++)
275   {
276     GEOM::shape_type aType = myObjects[i]->GetShapeType();
277     if( aType != GEOM::FACE && aType != GEOM::SHELL && aType != GEOM::SOLID ){
278        msg = tr("ERROR_SHAPE_TYPE");
279        return false;
280     }
281   }
282   return true;
283 }
284
285 //=================================================================================
286 // function : execute
287 // purpose  :
288 //=================================================================================
289 bool TransformationGUI_OffsetDlg::execute( ObjectList& objects )
290 {
291   bool res = false;
292
293   GEOM::GEOM_Object_var anObj;
294
295   if (GroupPoints->CheckButton1->isChecked() || IsPreview())
296     for (int i = 0; i < myObjects.length(); i++)
297     {
298       anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->
299         OffsetShapeCopy( myObjects[i], GetOffset() );
300       if ( !anObj->_is_nil() )
301         objects.push_back( anObj._retn() );
302     }
303   else
304     for (int i = 0; i < myObjects.length(); i++)
305     {
306       anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->
307         OffsetShape( myObjects[i], GetOffset() );
308       if ( !anObj->_is_nil() )
309         objects.push_back( anObj._retn() );
310     }
311
312   res = true;
313
314   return res;
315 }
316
317 //=================================================================================
318 // function : restoreSubShapes
319 // purpose  :
320 //=================================================================================
321 void TransformationGUI_OffsetDlg::restoreSubShapes (SALOMEDS::Study_ptr   theStudy,
322                                                     SALOMEDS::SObject_ptr theSObject)
323 {
324   if (CheckBoxRestoreSS->isChecked()) {
325     // empty list of arguments means that all arguments should be restored
326     getGeomEngine()->RestoreSubShapesSO(theStudy, theSObject, GEOM::ListOfGO(),
327                                         /*theFindMethod=*/GEOM::FSM_Transformed,
328                                         /*theInheritFirstArg=*/true);
329   }
330 }
331
332 //=================================================================================
333 // function : GetOffset()
334 // purpose  :
335 //=================================================================================
336 double TransformationGUI_OffsetDlg::GetOffset() const
337 {
338   return GroupPoints->SpinBox_DX->GetValue();
339 }
340
341 //=================================================================================
342 // function :  CreateCopyModeChanged()
343 // purpose  :
344 //=================================================================================
345 void TransformationGUI_OffsetDlg::CreateCopyModeChanged(bool isCreateCopy)
346 {
347   this->GroupBoxName->setEnabled(isCreateCopy);
348 }