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"
30 #include <QAD_Desktop.h>
31 #include "utilities.h"
33 #include <qcheckbox.h>
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)
47 QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_DLG_OFFSET")));
48 QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_SELECT")));
50 setCaption(tr("GEOM_OFFSET_TITLE"));
52 /***************************************************************/
53 GroupConstructors->setTitle(tr("GEOM_OFFSET"));
54 RadioButton1->setPixmap(image0);
55 RadioButton2->close(TRUE);
56 RadioButton3->close(TRUE);
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"));
64 // san -- modification of an exisitng object by offset is not allowed
65 GroupPoints->CheckButton1->hide();
67 GroupPoints->PushButton1->setPixmap(image1);
69 Layout1->addWidget(GroupPoints, 2, 0);
71 /***************************************************************/
77 //=================================================================================
78 // function : ~TransformationGUI_OffsetDlg()
79 // purpose : Destroys the object and frees any allocated resources
80 //=================================================================================
81 TransformationGUI_OffsetDlg::~TransformationGUI_OffsetDlg()
83 /* no need to delete child widgets, Qt does it all for us */
87 //=================================================================================
90 //=================================================================================
91 void TransformationGUI_OffsetDlg::Init()
94 myEditCurrentArgument = GroupPoints->LineEdit1;
95 GroupPoints->LineEdit1->setReadOnly( true );
97 /* Get setting of step value from file configuration */
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);
106 // Activate Create a Copy mode
107 GroupPoints->CheckButton1->setChecked(true);
108 CreateCopyModeChanged(true);
110 /* signals and slots connections */
111 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
112 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
114 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
115 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
117 connect(GroupPoints->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
118 connect(GroupPoints->CheckButton1, SIGNAL(toggled(bool)), this, SLOT(CreateCopyModeChanged(bool)));
120 initName( tr( "GEOM_OFFSET" ) );
124 //=================================================================================
125 // function : ClickOnOk()
127 //=================================================================================
128 void TransformationGUI_OffsetDlg::ClickOnOk()
130 if ( ClickOnApply() )
135 //=================================================================================
136 // function : ClickOnApply()
138 //=================================================================================
139 bool TransformationGUI_OffsetDlg::ClickOnApply()
141 if ( !onAccept( GroupPoints->CheckButton1->isChecked() ) )
149 //=======================================================================
150 // function : ClickOnCancel()
152 //=======================================================================
153 void TransformationGUI_OffsetDlg::ClickOnCancel()
155 GEOMBase_Skeleton::ClickOnCancel();
159 //=================================================================================
160 // function : SelectionIntoArgument()
161 // purpose : Called when selection has changed
162 //=================================================================================
163 void TransformationGUI_OffsetDlg::SelectionIntoArgument()
165 myEditCurrentArgument->setText("");
168 int aNbSel = GEOMBase::GetNameOfSelectedIObjects(mySelection, aName);
176 GEOMBase::ConvertListOfIOInListOfGO(mySelection->StoredIObjects(), myObjects);
177 if (!myObjects.length())
180 aName = tr("%1_objects").arg(aNbSel);
182 myEditCurrentArgument->setText( aName );
188 //=================================================================================
189 // function : LineEditReturnPressed()
191 //=================================================================================
192 void TransformationGUI_OffsetDlg::LineEditReturnPressed()
194 QLineEdit* send = (QLineEdit*)sender();
195 if ( send == GroupPoints->LineEdit1 )
197 myEditCurrentArgument = GroupPoints->LineEdit1;
198 GEOMBase_Skeleton::LineEditReturnPressed();
203 //=================================================================================
204 // function : SetEditCurrentArgument()
206 //=================================================================================
207 void TransformationGUI_OffsetDlg::SetEditCurrentArgument()
209 QPushButton* send = (QPushButton*)sender();
211 if(send == GroupPoints->PushButton1)
213 myEditCurrentArgument = GroupPoints->LineEdit1;
214 myEditCurrentArgument->setFocus();
215 SelectionIntoArgument();
220 //=================================================================================
221 // function : enterEvent()
222 // purpose : when mouse enter onto the QWidget
223 //=================================================================================
224 void TransformationGUI_OffsetDlg::enterEvent(QEvent * e)
226 if ( !GroupConstructors->isEnabled() )
227 ActivateThisDialog();
231 //=================================================================================
232 // function : ActivateThisDialog()
234 //=================================================================================
235 void TransformationGUI_OffsetDlg::ActivateThisDialog()
237 GEOMBase_Skeleton::ActivateThisDialog();
238 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
240 myEditCurrentArgument = GroupPoints->LineEdit1;
241 myEditCurrentArgument->setFocus();
245 //=================================================================================
246 // function : DeactivateActiveDialog()
247 // purpose : public slot to deactivate if active
248 //=================================================================================
249 void TransformationGUI_OffsetDlg::DeactivateActiveDialog()
251 GEOMBase_Skeleton::DeactivateActiveDialog();
255 //=================================================================================
256 // function : ValueChangedInSpinBox()
258 //=================================================================================
259 void TransformationGUI_OffsetDlg::ValueChangedInSpinBox()
265 //=================================================================================
266 // function : createOperation
268 //=================================================================================
269 GEOM::GEOM_IOperations_ptr TransformationGUI_OffsetDlg::createOperation()
271 return getGeomEngine()->GetITransformOperations( getStudyId() );
274 //=================================================================================
275 // function : isValid
277 //=================================================================================
278 bool TransformationGUI_OffsetDlg::isValid( QString& msg )
280 return !(myObjects.length() == 0);
284 //=================================================================================
285 // function : execute
287 //=================================================================================
288 bool TransformationGUI_OffsetDlg::execute( ObjectList& objects )
292 GEOM::GEOM_Object_var anObj;
295 if (GroupPoints->CheckButton1->isChecked() || IsPreview())
296 for (int i = 0; i < myObjects.length(); i++)
298 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->OffsetShapeCopy( myObjects[i], GetOffset() );
299 if ( !anObj->_is_nil() )
300 objects.push_back( anObj._retn() );
303 for (int i = 0; i < myObjects.length(); i++)
305 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->OffsetShape( myObjects[i], GetOffset() );
306 if ( !anObj->_is_nil() )
307 objects.push_back( anObj._retn() );
315 //=================================================================================
316 // function : closeEvent
318 //=================================================================================
319 void TransformationGUI_OffsetDlg::closeEvent( QCloseEvent* e )
321 myGeomGUI->SetState( -1 );
322 GEOMBase_Skeleton::closeEvent( e );
326 //=================================================================================
327 // function : GetOffset()
329 //=================================================================================
330 double TransformationGUI_OffsetDlg::GetOffset() const
332 return GroupPoints->SpinBox_DX->GetValue();
336 //=================================================================================
337 // function : CreateCopyModeChanged()
339 //=================================================================================
340 void TransformationGUI_OffsetDlg::CreateCopyModeChanged(bool isCreateCopy)
342 this->GroupBoxName->setEnabled(isCreateCopy);