1 // GEOM GEOMGUI : GUI for Geometry component
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : TransformationGUI_OffsetDlg.cxx
25 // Author : Lucien PIGNOLONI
29 #include "TransformationGUI_OffsetDlg.h"
31 #include "SUIT_Desktop.h"
32 #include "SUIT_Session.h"
33 #include "SalomeApp_Application.h"
34 #include "SalomeApp_SelectionMgr.h"
37 #include <qcheckbox.h>
39 #include "utilities.h"
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(QWidget* parent, const char* name, bool modal, WFlags fl)
51 :GEOMBase_Skeleton(parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
53 QPixmap image0(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_OFFSET")));
54 QPixmap image1(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_SELECT")));
56 setCaption(tr("GEOM_OFFSET_TITLE"));
58 /***************************************************************/
59 GroupConstructors->setTitle(tr("GEOM_OFFSET"));
60 RadioButton1->setPixmap(image0);
61 RadioButton2->close(TRUE);
62 RadioButton3->close(TRUE);
64 GroupPoints = new DlgRef_1Sel1Spin1Check(this, "GroupPoints");
65 GroupPoints->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
66 GroupPoints->TextLabel1->setText(tr("GEOM_OBJECTS"));
67 GroupPoints->TextLabel2->setText(tr("GEOM_OFFSET"));
68 GroupPoints->CheckButton1->setText(tr("GEOM_CREATE_COPY"));
70 // san -- modification of an exisitng object by offset is not allowed
71 GroupPoints->CheckButton1->hide();
73 GroupPoints->PushButton1->setPixmap(image1);
75 Layout1->addWidget(GroupPoints, 2, 0);
77 /***************************************************************/
83 //=================================================================================
84 // function : ~TransformationGUI_OffsetDlg()
85 // purpose : Destroys the object and frees any allocated resources
86 //=================================================================================
87 TransformationGUI_OffsetDlg::~TransformationGUI_OffsetDlg()
89 /* no need to delete child widgets, Qt does it all for us */
93 //=================================================================================
96 //=================================================================================
97 void TransformationGUI_OffsetDlg::Init()
100 myEditCurrentArgument = GroupPoints->LineEdit1;
101 GroupPoints->LineEdit1->setReadOnly( true );
103 /* Get setting of step value from file configuration */
106 /* min, max, step and decimals for spin boxes & initial values */
107 GroupPoints->SpinBox_DX->RangeStepAndValidator(-999.999, 999.999, step, 3);
108 GroupPoints->SpinBox_DX->setPrecision(5);
109 //@ GroupPoints->SpinBox_DX->setDblPrecision(1e-05);
110 GroupPoints->SpinBox_DX->SetValue(1e-05);
112 // Activate Create a Copy mode
113 GroupPoints->CheckButton1->setChecked(true);
114 CreateCopyModeChanged(true);
116 /* signals and slots connections */
117 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
118 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
120 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
121 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
122 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
124 connect(GroupPoints->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
125 connect(GroupPoints->CheckButton1, SIGNAL(toggled(bool)), this, SLOT(CreateCopyModeChanged(bool)));
127 initName( tr( "GEOM_OFFSET" ) );
129 globalSelection( GEOM_ALLSHAPES );
134 //=================================================================================
135 // function : ClickOnOk()
137 //=================================================================================
138 void TransformationGUI_OffsetDlg::ClickOnOk()
140 if ( ClickOnApply() )
145 //=================================================================================
146 // function : ClickOnApply()
148 //=================================================================================
149 bool TransformationGUI_OffsetDlg::ClickOnApply()
151 if ( !onAccept( GroupPoints->CheckButton1->isChecked() ) )
159 //=======================================================================
160 // function : ClickOnCancel()
162 //=======================================================================
163 void TransformationGUI_OffsetDlg::ClickOnCancel()
165 GEOMBase_Skeleton::ClickOnCancel();
169 //=================================================================================
170 // function : SelectionIntoArgument()
171 // purpose : Called when selection has changed
172 //=================================================================================
173 void TransformationGUI_OffsetDlg::SelectionIntoArgument()
175 myEditCurrentArgument->setText("");
178 int aNbSel = GEOMBase::GetNameOfSelectedIObjects(selectedIO(), aName);
186 GEOMBase::ConvertListOfIOInListOfGO(selectedIO(), myObjects);
187 if (!myObjects.length())
190 myEditCurrentArgument->setText( aName );
196 //=================================================================================
197 // function : LineEditReturnPressed()
199 //=================================================================================
200 void TransformationGUI_OffsetDlg::LineEditReturnPressed()
202 QLineEdit* send = (QLineEdit*)sender();
203 if ( send == GroupPoints->LineEdit1 )
205 myEditCurrentArgument = GroupPoints->LineEdit1;
206 GEOMBase_Skeleton::LineEditReturnPressed();
211 //=================================================================================
212 // function : SetEditCurrentArgument()
214 //=================================================================================
215 void TransformationGUI_OffsetDlg::SetEditCurrentArgument()
217 QPushButton* send = (QPushButton*)sender();
219 if(send == GroupPoints->PushButton1)
221 myEditCurrentArgument = GroupPoints->LineEdit1;
222 myEditCurrentArgument->setFocus();
223 SelectionIntoArgument();
228 //=================================================================================
229 // function : enterEvent()
230 // purpose : when mouse enter onto the QWidget
231 //=================================================================================
232 void TransformationGUI_OffsetDlg::enterEvent(QEvent * e)
234 if ( !GroupConstructors->isEnabled() )
235 ActivateThisDialog();
239 //=================================================================================
240 // function : ActivateThisDialog()
242 //=================================================================================
243 void TransformationGUI_OffsetDlg::ActivateThisDialog()
245 GEOMBase_Skeleton::ActivateThisDialog();
246 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
247 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
248 globalSelection( GEOM_ALLSHAPES );
249 myEditCurrentArgument = GroupPoints->LineEdit1;
250 myEditCurrentArgument->setFocus();
254 //=================================================================================
255 // function : DeactivateActiveDialog()
256 // purpose : public slot to deactivate if active
257 //=================================================================================
258 void TransformationGUI_OffsetDlg::DeactivateActiveDialog()
260 GEOMBase_Skeleton::DeactivateActiveDialog();
264 //=================================================================================
265 // function : ValueChangedInSpinBox()
267 //=================================================================================
268 void TransformationGUI_OffsetDlg::ValueChangedInSpinBox()
274 //=================================================================================
275 // function : createOperation
277 //=================================================================================
278 GEOM::GEOM_IOperations_ptr TransformationGUI_OffsetDlg::createOperation()
280 return getGeomEngine()->GetITransformOperations( getStudyId() );
283 //=================================================================================
284 // function : isValid
286 //=================================================================================
287 bool TransformationGUI_OffsetDlg::isValid( QString& msg )
289 return !(myObjects.length() == 0);
293 //=================================================================================
294 // function : execute
296 //=================================================================================
297 bool TransformationGUI_OffsetDlg::execute( ObjectList& objects )
301 GEOM::GEOM_Object_var anObj;
304 if (GroupPoints->CheckButton1->isChecked() || IsPreview())
305 for (int i = 0; i < myObjects.length(); i++)
307 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->OffsetShapeCopy( myObjects[i], GetOffset() );
308 if ( !anObj->_is_nil() )
309 objects.push_back( anObj._retn() );
312 for (int i = 0; i < myObjects.length(); i++)
314 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->OffsetShape( myObjects[i], GetOffset() );
315 if ( !anObj->_is_nil() )
316 objects.push_back( anObj._retn() );
324 //=================================================================================
325 // function : closeEvent
327 //=================================================================================
328 void TransformationGUI_OffsetDlg::closeEvent( QCloseEvent* e )
330 // myGeomGUI->SetState( -1 );
331 GEOMBase_Skeleton::closeEvent( e );
335 //=================================================================================
336 // function : GetOffset()
338 //=================================================================================
339 double TransformationGUI_OffsetDlg::GetOffset() const
341 return GroupPoints->SpinBox_DX->GetValue();
345 //=================================================================================
346 // function : CreateCopyModeChanged()
348 //=================================================================================
349 void TransformationGUI_OffsetDlg::CreateCopyModeChanged(bool isCreateCopy)
351 this->GroupBoxName->setEnabled(isCreateCopy);