Salome HOME
IMP 0019918: Re-open popup for imported shapes. Enable for multiple selection.
[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 //
23 //
24 //  File   : TransformationGUI_OffsetDlg.cxx
25 //  Author : Lucien PIGNOLONI
26 //  Module : GEOM
27 //  $Header$
28
29 #include "TransformationGUI_OffsetDlg.h"
30
31 #include "SUIT_Desktop.h"
32 #include "SUIT_Session.h"
33 #include "SalomeApp_Application.h"
34 #include "LightApp_SelectionMgr.h"
35
36 #include <qlabel.h>
37 #include <qcheckbox.h>
38
39 #include "utilities.h"
40
41 using namespace std;
42
43 //=================================================================================
44 // class    : TransformationGUI_OffsetDlg()
45 // purpose  : Constructs a TransformationGUI_OffsetDlg 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 TransformationGUI_OffsetDlg::TransformationGUI_OffsetDlg(GeometryGUI* theGeometryGUI, QWidget* parent,
51                                                          const char* name, bool modal, WFlags fl)
52     :GEOMBase_Skeleton(theGeometryGUI, parent, name, modal, WStyle_Customize |
53                        WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
54 {
55   QPixmap image0(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_OFFSET")));
56   QPixmap image1(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_SELECT")));
57
58   setCaption(tr("GEOM_OFFSET_TITLE"));
59
60   /***************************************************************/
61   GroupConstructors->setTitle(tr("GEOM_OFFSET"));
62   RadioButton1->setPixmap(image0);
63   RadioButton2->close(TRUE);
64   RadioButton3->close(TRUE);
65
66   GroupPoints = new DlgRef_1Sel1Spin1Check(this, "GroupPoints");
67   GroupPoints->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
68   GroupPoints->TextLabel1->setText(tr("GEOM_OBJECTS"));
69   GroupPoints->TextLabel2->setText(tr("GEOM_OFFSET"));
70   GroupPoints->CheckButton1->setText(tr("GEOM_CREATE_COPY"));
71
72   // san -- modification of an exisitng object by offset is not allowed
73   GroupPoints->CheckButton1->hide();
74
75   GroupPoints->PushButton1->setPixmap(image1);
76
77   Layout1->addWidget(GroupPoints, 2, 0);
78
79   /***************************************************************/
80
81   setHelpFileName("offset_operation_page.html");
82
83   Init();
84 }
85
86
87 //=================================================================================
88 // function : ~TransformationGUI_OffsetDlg()
89 // purpose  : Destroys the object and frees any allocated resources
90 //=================================================================================
91 TransformationGUI_OffsetDlg::~TransformationGUI_OffsetDlg()
92 {
93   /* no need to delete child widgets, Qt does it all for us */
94 }
95
96
97 //=================================================================================
98 // function : Init()
99 // purpose  :
100 //=================================================================================
101 void TransformationGUI_OffsetDlg::Init()
102 {
103   /* init variables */
104   myEditCurrentArgument = GroupPoints->LineEdit1;
105   GroupPoints->LineEdit1->setReadOnly( true );
106
107   /* Get setting of step value from file configuration */
108   double step = 1;
109
110   /* min, max, step and decimals for spin boxes & initial values */
111   GroupPoints->SpinBox_DX->RangeStepAndValidator(COORD_MIN, COORD_MAX, step, DBL_DIGITS_DISPLAY);
112   GroupPoints->SpinBox_DX->SetValue(1e-05);
113
114   // Activate Create a Copy mode
115   GroupPoints->CheckButton1->setChecked(true);
116   CreateCopyModeChanged(true);
117
118   GroupBoxPublish->show();
119
120   /* signals and slots connections */
121   connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
122   connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
123
124   connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
125   connect(myGeomGUI->getApp()->selectionMgr(),
126           SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
127
128   connect(GroupPoints->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
129   connect(GroupPoints->CheckButton1, SIGNAL(toggled(bool)), this, SLOT(CreateCopyModeChanged(bool)));
130
131   initName( tr( "GEOM_OFFSET" ) );
132
133   globalSelection( GEOM_ALLSHAPES );
134 }
135
136
137 //=================================================================================
138 // function : ClickOnOk()
139 // purpose  :
140 //=================================================================================
141 void TransformationGUI_OffsetDlg::ClickOnOk()
142 {
143   if ( ClickOnApply() )
144     ClickOnCancel();
145 }
146
147
148 //=================================================================================
149 // function : ClickOnApply()
150 // purpose  :
151 //=================================================================================
152 bool TransformationGUI_OffsetDlg::ClickOnApply()
153 {
154   if ( !onAccept( GroupPoints->CheckButton1->isChecked() ) )
155     return false;
156
157   initName();
158   return true;
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(selectedIO(), aName);
172   if(aNbSel < 1)
173     {
174       myObjects.length(0);
175       return;
176     }
177
178   // nbSel > 0
179   GEOMBase::ConvertListOfIOInListOfGO(selectedIO(), myObjects);
180   if (!myObjects.length())
181     return;
182
183   myEditCurrentArgument->setText( aName );
184
185   displayPreview();
186 }
187
188
189 //=================================================================================
190 // function : LineEditReturnPressed()
191 // purpose  :
192 //=================================================================================
193 void TransformationGUI_OffsetDlg::LineEditReturnPressed()
194 {
195   QLineEdit* send = (QLineEdit*)sender();
196   if ( send == GroupPoints->LineEdit1 )
197   {
198     myEditCurrentArgument = GroupPoints->LineEdit1;
199     GEOMBase_Skeleton::LineEditReturnPressed();
200   }
201 }
202
203
204 //=================================================================================
205 // function : SetEditCurrentArgument()
206 // purpose  :
207 //=================================================================================
208 void TransformationGUI_OffsetDlg::SetEditCurrentArgument()
209 {
210   QPushButton* send = (QPushButton*)sender();
211
212   if(send == GroupPoints->PushButton1)
213     {
214       myEditCurrentArgument = GroupPoints->LineEdit1;
215       myEditCurrentArgument->setFocus();
216       SelectionIntoArgument();
217     }
218 }
219
220
221 //=================================================================================
222 // function : enterEvent()
223 // purpose  : when mouse enter onto the QWidget
224 //=================================================================================
225 void TransformationGUI_OffsetDlg::enterEvent(QEvent * e)
226 {
227   if ( !GroupConstructors->isEnabled() )
228     ActivateThisDialog();
229 }
230
231
232 //=================================================================================
233 // function : ActivateThisDialog()
234 // purpose  :
235 //=================================================================================
236 void TransformationGUI_OffsetDlg::ActivateThisDialog()
237 {
238   GEOMBase_Skeleton::ActivateThisDialog();
239   connect(myGeomGUI->getApp()->selectionMgr(),
240           SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
241   globalSelection( GEOM_ALLSHAPES );
242   myEditCurrentArgument = GroupPoints->LineEdit1;
243   myEditCurrentArgument->setFocus();
244 }
245
246
247 //=================================================================================
248 // function : ValueChangedInSpinBox()
249 // purpose  :
250 //=================================================================================
251 void TransformationGUI_OffsetDlg::ValueChangedInSpinBox()
252 {
253   displayPreview();
254 }
255
256
257 //=================================================================================
258 // function : createOperation
259 // purpose  :
260 //=================================================================================
261 GEOM::GEOM_IOperations_ptr TransformationGUI_OffsetDlg::createOperation()
262 {
263   return getGeomEngine()->GetITransformOperations( getStudyId() );
264 }
265
266 //=================================================================================
267 // function : isValid
268 // purpose  :
269 //=================================================================================
270 bool TransformationGUI_OffsetDlg::isValid( QString& msg )
271 {
272   //return !(myObjects.length() == 0);
273   if (myObjects.length() == 0) return false;
274
275   for (int i = 0; i < myObjects.length(); i++)
276   {
277     GEOM::shape_type aType = myObjects[i]->GetShapeType();
278     if( aType != GEOM::FACE && aType != GEOM::SHELL && aType != GEOM::SOLID ){
279        msg = tr("ERROR_SHAPE_TYPE");
280        return false;
281     }
282   }
283   return true;
284 }
285
286 //=================================================================================
287 // function : execute
288 // purpose  :
289 //=================================================================================
290 bool TransformationGUI_OffsetDlg::execute( ObjectList& objects )
291 {
292   bool res = false;
293
294   GEOM::GEOM_Object_var anObj;
295
296   if (GroupPoints->CheckButton1->isChecked() || IsPreview())
297     for (int i = 0; i < myObjects.length(); i++)
298     {
299       anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->
300         OffsetShapeCopy( myObjects[i], GetOffset() );
301       if ( !anObj->_is_nil() )
302         objects.push_back( anObj._retn() );
303     }
304   else
305     for (int i = 0; i < myObjects.length(); i++)
306     {
307       anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->
308         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 : restoreSubShapes
320 // purpose  :
321 //=================================================================================
322 void TransformationGUI_OffsetDlg::restoreSubShapes (SALOMEDS::Study_ptr   theStudy,
323                                                     SALOMEDS::SObject_ptr theSObject)
324 {
325   if (CheckBoxRestoreSS->isChecked()) {
326     // empty list of arguments means that all arguments should be restored
327     getGeomEngine()->RestoreSubShapesSO(theStudy, theSObject, GEOM::ListOfGO(),
328                                         /*theFindMethod=*/GEOM::FSM_Transformed,
329                                         /*theInheritFirstArg=*/true);
330   }
331 }
332
333 //=================================================================================
334 // function : GetOffset()
335 // purpose  :
336 //=================================================================================
337 double TransformationGUI_OffsetDlg::GetOffset() const
338 {
339   return GroupPoints->SpinBox_DX->GetValue();
340 }
341
342 //=================================================================================
343 // function :  CreateCopyModeChanged()
344 // purpose  :
345 //=================================================================================
346 void TransformationGUI_OffsetDlg::CreateCopyModeChanged(bool isCreateCopy)
347 {
348   this->GroupBoxName->setEnabled(isCreateCopy);
349 }