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" ) );
122 globalSelection( GEOM_ALLSHAPES );
127 //=================================================================================
128 // function : ClickOnOk()
130 //=================================================================================
131 void TransformationGUI_OffsetDlg::ClickOnOk()
133 if ( ClickOnApply() )
138 //=================================================================================
139 // function : ClickOnApply()
141 //=================================================================================
142 bool TransformationGUI_OffsetDlg::ClickOnApply()
144 if ( !onAccept( GroupPoints->CheckButton1->isChecked() ) )
152 //=======================================================================
153 // function : ClickOnCancel()
155 //=======================================================================
156 void TransformationGUI_OffsetDlg::ClickOnCancel()
158 GEOMBase_Skeleton::ClickOnCancel();
162 //=================================================================================
163 // function : SelectionIntoArgument()
164 // purpose : Called when selection has changed
165 //=================================================================================
166 void TransformationGUI_OffsetDlg::SelectionIntoArgument()
168 myEditCurrentArgument->setText("");
171 int aNbSel = GEOMBase::GetNameOfSelectedIObjects(mySelection, aName);
179 GEOMBase::ConvertListOfIOInListOfGO(mySelection->StoredIObjects(), myObjects);
180 if (!myObjects.length())
183 aName = tr("%1_objects").arg(aNbSel);
185 myEditCurrentArgument->setText( aName );
191 //=================================================================================
192 // function : LineEditReturnPressed()
194 //=================================================================================
195 void TransformationGUI_OffsetDlg::LineEditReturnPressed()
197 QLineEdit* send = (QLineEdit*)sender();
198 if ( send == GroupPoints->LineEdit1 )
200 myEditCurrentArgument = GroupPoints->LineEdit1;
201 GEOMBase_Skeleton::LineEditReturnPressed();
206 //=================================================================================
207 // function : SetEditCurrentArgument()
209 //=================================================================================
210 void TransformationGUI_OffsetDlg::SetEditCurrentArgument()
212 QPushButton* send = (QPushButton*)sender();
214 if(send == GroupPoints->PushButton1)
216 myEditCurrentArgument = GroupPoints->LineEdit1;
217 myEditCurrentArgument->setFocus();
218 SelectionIntoArgument();
223 //=================================================================================
224 // function : enterEvent()
225 // purpose : when mouse enter onto the QWidget
226 //=================================================================================
227 void TransformationGUI_OffsetDlg::enterEvent(QEvent * e)
229 if ( !GroupConstructors->isEnabled() )
230 ActivateThisDialog();
234 //=================================================================================
235 // function : ActivateThisDialog()
237 //=================================================================================
238 void TransformationGUI_OffsetDlg::ActivateThisDialog()
240 GEOMBase_Skeleton::ActivateThisDialog();
241 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
242 globalSelection( GEOM_ALLSHAPES );
243 myEditCurrentArgument = GroupPoints->LineEdit1;
244 myEditCurrentArgument->setFocus();
248 //=================================================================================
249 // function : DeactivateActiveDialog()
250 // purpose : public slot to deactivate if active
251 //=================================================================================
252 void TransformationGUI_OffsetDlg::DeactivateActiveDialog()
254 GEOMBase_Skeleton::DeactivateActiveDialog();
258 //=================================================================================
259 // function : ValueChangedInSpinBox()
261 //=================================================================================
262 void TransformationGUI_OffsetDlg::ValueChangedInSpinBox()
268 //=================================================================================
269 // function : createOperation
271 //=================================================================================
272 GEOM::GEOM_IOperations_ptr TransformationGUI_OffsetDlg::createOperation()
274 return getGeomEngine()->GetITransformOperations( getStudyId() );
277 //=================================================================================
278 // function : isValid
280 //=================================================================================
281 bool TransformationGUI_OffsetDlg::isValid( QString& msg )
283 return !(myObjects.length() == 0);
287 //=================================================================================
288 // function : execute
290 //=================================================================================
291 bool TransformationGUI_OffsetDlg::execute( ObjectList& objects )
295 GEOM::GEOM_Object_var anObj;
298 if (GroupPoints->CheckButton1->isChecked() || IsPreview())
299 for (int i = 0; i < myObjects.length(); i++)
301 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->OffsetShapeCopy( myObjects[i], GetOffset() );
302 if ( !anObj->_is_nil() )
303 objects.push_back( anObj._retn() );
306 for (int i = 0; i < myObjects.length(); i++)
308 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->OffsetShape( myObjects[i], GetOffset() );
309 if ( !anObj->_is_nil() )
310 objects.push_back( anObj._retn() );
318 //=================================================================================
319 // function : closeEvent
321 //=================================================================================
322 void TransformationGUI_OffsetDlg::closeEvent( QCloseEvent* e )
324 myGeomGUI->SetState( -1 );
325 GEOMBase_Skeleton::closeEvent( e );
329 //=================================================================================
330 // function : GetOffset()
332 //=================================================================================
333 double TransformationGUI_OffsetDlg::GetOffset() const
335 return GroupPoints->SpinBox_DX->GetValue();
339 //=================================================================================
340 // function : CreateCopyModeChanged()
342 //=================================================================================
343 void TransformationGUI_OffsetDlg::CreateCopyModeChanged(bool isCreateCopy)
345 this->GroupBoxName->setEnabled(isCreateCopy);