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_ScaleDlg.cxx
25 // Author : Lucien PIGNOLONI
29 #include "TransformationGUI_ScaleDlg.h"
31 #include "QAD_Desktop.h"
33 #include "GEOMImpl_Types.hxx"
35 #include <qcheckbox.h>
37 #include "utilities.h"
41 //=================================================================================
42 // class : TransformationGUI_ScaleDlg()
43 // purpose : Constructs a TransformationGUI_ScaleDlg which is a child of 'parent', with the
44 // name 'name' and widget flags set to 'f'.
45 // The dialog will by default be modeless, unless you set 'modal' to
46 // TRUE to construct a modal dialog.
47 //=================================================================================
48 TransformationGUI_ScaleDlg::TransformationGUI_ScaleDlg(QWidget* parent, const char* name, SALOME_Selection* Sel, bool modal, WFlags fl)
49 :GEOMBase_Skeleton(parent, name, Sel, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
51 QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_DLG_SCALE")));
52 QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_SELECT")));
54 setCaption(tr("GEOM_SCALE_TITLE"));
56 /***************************************************************/
57 GroupConstructors->setTitle(tr("GEOM_SCALE"));
58 RadioButton1->setPixmap(image0);
59 RadioButton2->close(TRUE);
60 RadioButton3->close(TRUE);
62 GroupPoints = new DlgRef_2Sel1Spin2Check(this, "GroupPoints");
63 GroupPoints->CheckButton2->hide();
64 GroupPoints->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
65 GroupPoints->TextLabel1->setText(tr("GEOM_OBJECTS"));
66 GroupPoints->TextLabel2->setText(tr("GEOM_CENTRAL_POINT"));
67 GroupPoints->TextLabel3->setText(tr("GEOM_SCALE_FACTOR"));
68 GroupPoints->LineEdit1->setReadOnly( true );
69 GroupPoints->LineEdit2->setReadOnly( true );
70 GroupPoints->PushButton1->setPixmap(image1);
71 GroupPoints->PushButton2->setPixmap(image1);
72 GroupPoints->CheckButton1->setText(tr("GEOM_CREATE_COPY"));
74 // san -- modification of an exisitng object by offset is not allowed
75 GroupPoints->CheckButton1->hide();
77 Layout1->addWidget(GroupPoints, 2, 0);
78 /***************************************************************/
80 double SpecificStep = 0.5;
81 /* min, max, step and decimals for spin boxes & initial values */
82 GroupPoints->SpinBox_DX->RangeStepAndValidator(-999.999, 999.999, SpecificStep, 3);
83 GroupPoints->SpinBox_DX->SetValue(aFactor);
85 // Activate Create a Copy mode
86 GroupPoints->CheckButton1->setChecked(true);
87 CreateCopyModeChanged(true);
89 /* signals and slots connections */
90 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
91 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
93 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
94 connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
96 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
97 connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
99 connect(GroupPoints->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
100 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_DX, SLOT(SetStep(double)));
101 connect(GroupPoints->CheckButton1, SIGNAL(toggled(bool)), this, SLOT(CreateCopyModeChanged(bool)));
103 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
109 //=================================================================================
110 // function : ~TransformationGUI_ScaleDlg()
111 // purpose : Destroys the object and frees any allocated resources
112 //=================================================================================
113 TransformationGUI_ScaleDlg::~TransformationGUI_ScaleDlg()
115 /* no need to delete child widgets, Qt does it all for us */
119 //=================================================================================
122 //=================================================================================
123 void TransformationGUI_ScaleDlg::Init()
125 myEditCurrentArgument = GroupPoints->LineEdit1;
126 GroupPoints->LineEdit2->clear();
128 myPoint = GEOM::GEOM_Object::_nil();
130 initName( tr( "GEOM_SCALE" ) );
134 //=================================================================================
135 // function : ClickOnOk()
137 //=================================================================================
138 void TransformationGUI_ScaleDlg::ClickOnOk()
140 if ( ClickOnApply() )
145 //=================================================================================
146 // function : ClickOnApply()
148 //=================================================================================
149 bool TransformationGUI_ScaleDlg::ClickOnApply()
151 if ( !onAccept(GroupPoints->CheckButton1->isChecked()) )
159 //=======================================================================
160 // function : ClickOnCancel()
162 //=======================================================================
163 void TransformationGUI_ScaleDlg::ClickOnCancel()
165 GEOMBase_Skeleton::ClickOnCancel();
169 //=================================================================================
170 // function : SelectionIntoArgument()
171 // purpose : Called when selection as changed or other case
172 //=================================================================================
173 void TransformationGUI_ScaleDlg::SelectionIntoArgument()
175 myEditCurrentArgument->setText("");
178 if(myEditCurrentArgument == GroupPoints->LineEdit1)
180 int aNbSel = GEOMBase::GetNameOfSelectedIObjects(mySelection, aName);
186 GEOMBase::ConvertListOfIOInListOfGO(mySelection->StoredIObjects(), myObjects);
187 if (!myObjects.length())
190 aName = tr("%1_objects").arg(aNbSel);
192 else if(myEditCurrentArgument == GroupPoints->LineEdit2)
194 if(mySelection->IObjectCount() != 1)
196 myPoint = GEOM::GEOM_Object::_nil();
199 Standard_Boolean testResult = Standard_False;
200 myPoint = GEOMBase::ConvertIOinGEOMObject(mySelection->firstIObject(), testResult );
201 if(!testResult || CORBA::is_nil( myPoint ))
203 aName = GEOMBase::GetName( myPoint );
205 myEditCurrentArgument->setText( aName );
211 //=================================================================================
212 // function : LineEditReturnPressed()
214 //=================================================================================
215 void TransformationGUI_ScaleDlg::LineEditReturnPressed()
217 QLineEdit* send = (QLineEdit*)sender();
218 if(send == GroupPoints->LineEdit1 ||
219 send == GroupPoints->LineEdit2)
221 myEditCurrentArgument = send;
222 GEOMBase_Skeleton::LineEditReturnPressed();
227 //=================================================================================
228 // function : SetEditCurrentArgument()
230 //=================================================================================
231 void TransformationGUI_ScaleDlg::SetEditCurrentArgument()
233 QPushButton* send = (QPushButton*)sender();
235 if(send == GroupPoints->PushButton1) {
236 myEditCurrentArgument = GroupPoints->LineEdit1;
239 else if(send == GroupPoints->PushButton2) {
240 myEditCurrentArgument = GroupPoints->LineEdit2;
241 globalSelection( GEOM_POINT );
244 myEditCurrentArgument->setFocus();
245 SelectionIntoArgument();
249 //=================================================================================
250 // function : ActivateThisDialog()
252 //=================================================================================
253 void TransformationGUI_ScaleDlg::ActivateThisDialog()
255 GEOMBase_Skeleton::ActivateThisDialog();
256 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
258 GroupPoints->LineEdit1->setFocus();
259 myEditCurrentArgument = GroupPoints->LineEdit1;
263 //=================================================================================
264 // function : DeactivateActiveDialog()
265 // purpose : public slot to deactivate if active
266 //=================================================================================
267 void TransformationGUI_ScaleDlg::DeactivateActiveDialog()
269 GEOMBase_Skeleton::DeactivateActiveDialog();
273 //=================================================================================
274 // function : enterEvent()
276 //=================================================================================
277 void TransformationGUI_ScaleDlg::enterEvent(QEvent* e)
279 if( !GroupConstructors->isEnabled() )
280 ActivateThisDialog();
284 //=================================================================================
285 // function : ValueChangedInSpinBox()
287 //=================================================================================
288 void TransformationGUI_ScaleDlg::ValueChangedInSpinBox()
294 //=================================================================================
295 // function : createOperation
297 //=================================================================================
298 GEOM::GEOM_IOperations_ptr TransformationGUI_ScaleDlg::createOperation()
300 return getGeomEngine()->GetITransformOperations( getStudyId() );
303 //=================================================================================
304 // function : isValid
306 //=================================================================================
307 bool TransformationGUI_ScaleDlg::isValid( QString& msg )
309 return !(myObjects.length() == 0 || myPoint->_is_nil() || fabs(GetFactor()) <= 0.00001);
313 //=================================================================================
314 // function : execute
316 //=================================================================================
317 bool TransformationGUI_ScaleDlg::execute( ObjectList& objects )
321 GEOM::GEOM_Object_var anObj;
323 if (GroupPoints->CheckButton1->isChecked() || IsPreview())
324 for (int i = 0; i < myObjects.length(); i++)
326 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->ScaleShapeCopy( myObjects[i], myPoint, GetFactor() );
327 if ( !anObj->_is_nil() )
328 objects.push_back( anObj._retn() );
331 for (int i = 0; i < myObjects.length(); i++)
333 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->ScaleShape( myObjects[i], myPoint, GetFactor() );
334 if ( !anObj->_is_nil() )
335 objects.push_back( anObj._retn() );
343 //=================================================================================
344 // function : closeEvent
346 //=================================================================================
347 void TransformationGUI_ScaleDlg::closeEvent( QCloseEvent* e )
349 GEOMBase_Skeleton::closeEvent( e );
353 //=================================================================================
354 // function : GetFactor()
356 //=================================================================================
357 double TransformationGUI_ScaleDlg::GetFactor() const
359 return GroupPoints->SpinBox_DX->GetValue();
363 //=================================================================================
364 // function : CreateCopyModeChanged()
366 //=================================================================================
367 void TransformationGUI_ScaleDlg::CreateCopyModeChanged(bool isCreateCopy)
369 this->GroupBoxName->setEnabled(isCreateCopy);