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.salome-platform.org/ or email : webmaster.salome@opencascade.com
24 // File : TransformationGUI_ScaleDlg.cxx
25 // Author : Lucien PIGNOLONI
29 #include "TransformationGUI_ScaleDlg.h"
30 #include "DlgRef_2Sel1Spin2Check.h"
31 #include "DlgRef_SpinBox.h"
33 #include "GeometryGUI.h"
36 #include "SUIT_ResourceMgr.h"
37 #include "SUIT_Session.h"
38 #include "SalomeApp_Application.h"
39 #include "LightApp_SelectionMgr.h"
41 #include "GEOMImpl_Types.hxx"
45 //=================================================================================
46 // class : TransformationGUI_ScaleDlg()
47 // purpose : Constructs a TransformationGUI_ScaleDlg which is a child of 'parent', with the
48 // name 'name' and widget flags set to 'f'.
49 // The dialog will by default be modeless, unless you set 'modal' to
50 // TRUE to construct a modal dialog.
51 //=================================================================================
52 TransformationGUI_ScaleDlg::TransformationGUI_ScaleDlg(GeometryGUI* theGeometryGUI, QWidget* parent,
53 const char* name, bool modal, Qt::WindowFlags fl)
54 :GEOMBase_Skeleton(theGeometryGUI, parent, name, modal, Qt::WindowTitleHint | Qt::WindowSystemMenuHint)
56 QPixmap image0(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_SCALE")));
57 QPixmap image1(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_SELECT")));
59 setWindowTitle(tr("GEOM_SCALE_TITLE"));
61 /***************************************************************/
62 GroupConstructors->setTitle(tr("GEOM_SCALE"));
63 RadioButton1->setIcon(image0);
64 RadioButton2->setAttribute( Qt::WA_DeleteOnClose );
65 RadioButton2->close();
66 RadioButton3->setAttribute( Qt::WA_DeleteOnClose );
67 RadioButton3->close();
69 GroupPoints = new DlgRef_2Sel1Spin2Check(this, "GroupPoints");
70 GroupPoints->CheckButton2->hide();
71 GroupPoints->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
72 GroupPoints->TextLabel1->setText(tr("GEOM_OBJECTS"));
73 GroupPoints->TextLabel2->setText(tr("GEOM_CENTRAL_POINT"));
74 GroupPoints->TextLabel3->setText(tr("GEOM_SCALE_FACTOR"));
75 GroupPoints->LineEdit1->setReadOnly( true );
76 GroupPoints->LineEdit2->setReadOnly( true );
77 GroupPoints->PushButton1->setIcon(image1);
78 GroupPoints->PushButton2->setIcon(image1);
79 GroupPoints->CheckButton1->setText(tr("GEOM_CREATE_COPY"));
81 // san -- modification of an exisitng object by offset is not allowed
82 GroupPoints->CheckButton1->hide();
84 gridLayout1->addWidget(GroupPoints, 2, 0);
85 /***************************************************************/
87 double SpecificStep = 0.5;
88 /* min, max, step and decimals for spin boxes & initial values */
89 GroupPoints->SpinBox_DX->RangeStepAndValidator(COORD_MIN, COORD_MAX, SpecificStep, 3);
90 GroupPoints->SpinBox_DX->SetValue(aFactor);
92 // Activate Create a Copy mode
93 GroupPoints->CheckButton1->setChecked(true);
94 CreateCopyModeChanged(true);
96 /* signals and slots connections */
97 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
98 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
100 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
101 connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
103 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
104 connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
106 connect(GroupPoints->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
107 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_DX, SLOT(SetStep(double)));
108 connect(GroupPoints->CheckButton1, SIGNAL(toggled(bool)), this, SLOT(CreateCopyModeChanged(bool)));
110 connect(myGeomGUI->getApp()->selectionMgr(),
111 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
113 setHelpFileName("scale_transform.htm");
119 //=================================================================================
120 // function : ~TransformationGUI_ScaleDlg()
121 // purpose : Destroys the object and frees any allocated resources
122 //=================================================================================
123 TransformationGUI_ScaleDlg::~TransformationGUI_ScaleDlg()
125 /* no need to delete child widgets, Qt does it all for us */
129 //=================================================================================
132 //=================================================================================
133 void TransformationGUI_ScaleDlg::Init()
135 myEditCurrentArgument = GroupPoints->LineEdit1;
136 GroupPoints->LineEdit2->clear();
138 myPoint = GEOM::GEOM_Object::_nil();
140 initName( tr( "GEOM_SCALE" ).toLatin1().constData() );
144 //=================================================================================
145 // function : ClickOnOk()
147 //=================================================================================
148 void TransformationGUI_ScaleDlg::ClickOnOk()
150 if ( ClickOnApply() )
155 //=================================================================================
156 // function : ClickOnApply()
158 //=================================================================================
159 bool TransformationGUI_ScaleDlg::ClickOnApply()
161 if ( !onAccept(GroupPoints->CheckButton1->isChecked()) )
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(selectedIO(), aName);
186 GEOMBase::ConvertListOfIOInListOfGO(selectedIO(), myObjects);
187 if (!myObjects.length())
190 else if(myEditCurrentArgument == GroupPoints->LineEdit2)
192 if(IObjectCount() != 1)
194 myPoint = GEOM::GEOM_Object::_nil();
197 Standard_Boolean testResult = Standard_False;
198 myPoint = GEOMBase::ConvertIOinGEOMObject(firstIObject(), testResult );
199 if(!testResult || CORBA::is_nil( myPoint ))
201 aName = GEOMBase::GetName( myPoint );
203 myEditCurrentArgument->setText( aName );
209 //=================================================================================
210 // function : LineEditReturnPressed()
212 //=================================================================================
213 void TransformationGUI_ScaleDlg::LineEditReturnPressed()
215 QLineEdit* send = (QLineEdit*)sender();
216 if(send == GroupPoints->LineEdit1 ||
217 send == GroupPoints->LineEdit2)
219 myEditCurrentArgument = send;
220 GEOMBase_Skeleton::LineEditReturnPressed();
225 //=================================================================================
226 // function : SetEditCurrentArgument()
228 //=================================================================================
229 void TransformationGUI_ScaleDlg::SetEditCurrentArgument()
231 QPushButton* send = (QPushButton*)sender();
233 if(send == GroupPoints->PushButton1) {
234 myEditCurrentArgument = GroupPoints->LineEdit1;
237 else if(send == GroupPoints->PushButton2) {
238 myEditCurrentArgument = GroupPoints->LineEdit2;
239 globalSelection( GEOM_POINT );
242 myEditCurrentArgument->setFocus();
243 SelectionIntoArgument();
247 //=================================================================================
248 // function : ActivateThisDialog()
250 //=================================================================================
251 void TransformationGUI_ScaleDlg::ActivateThisDialog()
253 GEOMBase_Skeleton::ActivateThisDialog();
254 connect(myGeomGUI->getApp()->selectionMgr(),
255 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
257 GroupPoints->LineEdit1->setFocus();
258 myEditCurrentArgument = GroupPoints->LineEdit1;
262 //=================================================================================
263 // function : enterEvent()
265 //=================================================================================
266 void TransformationGUI_ScaleDlg::enterEvent(QEvent* e)
268 if( !GroupConstructors->isEnabled() )
269 ActivateThisDialog();
273 //=================================================================================
274 // function : ValueChangedInSpinBox()
276 //=================================================================================
277 void TransformationGUI_ScaleDlg::ValueChangedInSpinBox()
283 //=================================================================================
284 // function : createOperation
286 //=================================================================================
287 GEOM::GEOM_IOperations_ptr TransformationGUI_ScaleDlg::createOperation()
289 return myGeomGUI->GetGeomGen()->GetITransformOperations( getStudyId() );
292 //=================================================================================
293 // function : isValid
295 //=================================================================================
296 bool TransformationGUI_ScaleDlg::isValid( QString& msg )
298 return !(myObjects.length() == 0 || myPoint->_is_nil() || fabs(GetFactor()) <= 0.00001);
302 //=================================================================================
303 // function : execute
305 //=================================================================================
306 bool TransformationGUI_ScaleDlg::execute( ObjectList& objects )
310 GEOM::GEOM_Object_var anObj;
312 if (GroupPoints->CheckButton1->isChecked() || IsPreview())
313 for (int i = 0; i < myObjects.length(); i++)
315 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->ScaleShapeCopy( myObjects[i], myPoint, GetFactor() );
316 if ( !anObj->_is_nil() )
317 objects.push_back( anObj._retn() );
320 for (int i = 0; i < myObjects.length(); i++)
322 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->ScaleShape( myObjects[i], myPoint, GetFactor() );
323 if ( !anObj->_is_nil() )
324 objects.push_back( anObj._retn() );
332 //=================================================================================
333 // function : closeEvent
335 //=================================================================================
336 void TransformationGUI_ScaleDlg::closeEvent( QCloseEvent* e )
338 GEOMBase_Skeleton::closeEvent( e );
342 //=================================================================================
343 // function : GetFactor()
345 //=================================================================================
346 double TransformationGUI_ScaleDlg::GetFactor() const
348 return GroupPoints->SpinBox_DX->GetValue();
352 //=================================================================================
353 // function : CreateCopyModeChanged()
355 //=================================================================================
356 void TransformationGUI_ScaleDlg::CreateCopyModeChanged(bool isCreateCopy)
358 this->GroupBoxName->setEnabled(isCreateCopy);