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"
31 #include "SUIT_Desktop.h"
32 #include "SUIT_Session.h"
33 #include "SalomeApp_Application.h"
34 #include "LightApp_SelectionMgr.h"
37 #include <qcheckbox.h>
39 #include "GEOMImpl_Types.hxx"
41 #include "utilities.h"
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, WFlags fl)
54 :GEOMBase_Skeleton(theGeometryGUI, parent, name, modal, WStyle_Customize |
55 WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
57 QPixmap image0(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_SCALE")));
58 QPixmap image1(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_SELECT")));
60 setCaption(tr("GEOM_SCALE_TITLE"));
62 /***************************************************************/
63 GroupConstructors->setTitle(tr("GEOM_SCALE"));
64 RadioButton1->setPixmap(image0);
65 RadioButton2->close(TRUE);
66 RadioButton3->close(TRUE);
68 GroupPoints = new DlgRef_2Sel1Spin2Check(this, "GroupPoints");
69 GroupPoints->CheckButton2->hide();
70 GroupPoints->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
71 GroupPoints->TextLabel1->setText(tr("GEOM_OBJECTS"));
72 GroupPoints->TextLabel2->setText(tr("GEOM_CENTRAL_POINT"));
73 GroupPoints->TextLabel3->setText(tr("GEOM_SCALE_FACTOR"));
74 GroupPoints->LineEdit1->setReadOnly( true );
75 GroupPoints->LineEdit2->setReadOnly( true );
76 GroupPoints->PushButton1->setPixmap(image1);
77 GroupPoints->PushButton2->setPixmap(image1);
78 GroupPoints->CheckButton1->setText(tr("GEOM_CREATE_COPY"));
80 // san -- modification of an exisitng object by offset is not allowed
81 GroupPoints->CheckButton1->hide();
83 Layout1->addWidget(GroupPoints, 2, 0);
84 /***************************************************************/
86 double SpecificStep = 0.5;
87 /* min, max, step and decimals for spin boxes & initial values */
88 GroupPoints->SpinBox_DX->RangeStepAndValidator(-999.999, 999.999, SpecificStep, 3);
89 GroupPoints->SpinBox_DX->SetValue(aFactor);
91 // Activate Create a Copy mode
92 GroupPoints->CheckButton1->setChecked(true);
93 CreateCopyModeChanged(true);
95 /* signals and slots connections */
96 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
97 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
99 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
100 connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
102 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
103 connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
105 connect(GroupPoints->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
106 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_DX, SLOT(SetStep(double)));
107 connect(GroupPoints->CheckButton1, SIGNAL(toggled(bool)), this, SLOT(CreateCopyModeChanged(bool)));
109 connect(myGeomGUI->getApp()->selectionMgr(),
110 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
112 setHelpFileName("scale_transform.htm");
118 //=================================================================================
119 // function : ~TransformationGUI_ScaleDlg()
120 // purpose : Destroys the object and frees any allocated resources
121 //=================================================================================
122 TransformationGUI_ScaleDlg::~TransformationGUI_ScaleDlg()
124 /* no need to delete child widgets, Qt does it all for us */
128 //=================================================================================
131 //=================================================================================
132 void TransformationGUI_ScaleDlg::Init()
134 myEditCurrentArgument = GroupPoints->LineEdit1;
135 GroupPoints->LineEdit2->clear();
137 myPoint = GEOM::GEOM_Object::_nil();
139 initName( tr( "GEOM_SCALE" ) );
143 //=================================================================================
144 // function : ClickOnOk()
146 //=================================================================================
147 void TransformationGUI_ScaleDlg::ClickOnOk()
149 if ( ClickOnApply() )
154 //=================================================================================
155 // function : ClickOnApply()
157 //=================================================================================
158 bool TransformationGUI_ScaleDlg::ClickOnApply()
160 if ( !onAccept(GroupPoints->CheckButton1->isChecked()) )
168 //=================================================================================
169 // function : SelectionIntoArgument()
170 // purpose : Called when selection as changed or other case
171 //=================================================================================
172 void TransformationGUI_ScaleDlg::SelectionIntoArgument()
174 myEditCurrentArgument->setText("");
177 if(myEditCurrentArgument == GroupPoints->LineEdit1)
179 int aNbSel = GEOMBase::GetNameOfSelectedIObjects(selectedIO(), aName);
185 GEOMBase::ConvertListOfIOInListOfGO(selectedIO(), myObjects);
186 if (!myObjects.length())
189 else if(myEditCurrentArgument == GroupPoints->LineEdit2)
191 if(IObjectCount() != 1)
193 myPoint = GEOM::GEOM_Object::_nil();
196 Standard_Boolean testResult = Standard_False;
197 myPoint = GEOMBase::ConvertIOinGEOMObject(firstIObject(), testResult );
198 if(!testResult || CORBA::is_nil( myPoint ))
200 aName = GEOMBase::GetName( myPoint );
202 myEditCurrentArgument->setText( aName );
208 //=================================================================================
209 // function : LineEditReturnPressed()
211 //=================================================================================
212 void TransformationGUI_ScaleDlg::LineEditReturnPressed()
214 QLineEdit* send = (QLineEdit*)sender();
215 if(send == GroupPoints->LineEdit1 ||
216 send == GroupPoints->LineEdit2)
218 myEditCurrentArgument = send;
219 GEOMBase_Skeleton::LineEditReturnPressed();
224 //=================================================================================
225 // function : SetEditCurrentArgument()
227 //=================================================================================
228 void TransformationGUI_ScaleDlg::SetEditCurrentArgument()
230 QPushButton* send = (QPushButton*)sender();
232 if(send == GroupPoints->PushButton1) {
233 myEditCurrentArgument = GroupPoints->LineEdit1;
236 else if(send == GroupPoints->PushButton2) {
237 myEditCurrentArgument = GroupPoints->LineEdit2;
238 globalSelection( GEOM_POINT );
241 myEditCurrentArgument->setFocus();
242 SelectionIntoArgument();
246 //=================================================================================
247 // function : ActivateThisDialog()
249 //=================================================================================
250 void TransformationGUI_ScaleDlg::ActivateThisDialog()
252 GEOMBase_Skeleton::ActivateThisDialog();
253 connect(myGeomGUI->getApp()->selectionMgr(),
254 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
256 GroupPoints->LineEdit1->setFocus();
257 myEditCurrentArgument = GroupPoints->LineEdit1;
261 //=================================================================================
262 // function : enterEvent()
264 //=================================================================================
265 void TransformationGUI_ScaleDlg::enterEvent(QEvent* e)
267 if( !GroupConstructors->isEnabled() )
268 ActivateThisDialog();
272 //=================================================================================
273 // function : ValueChangedInSpinBox()
275 //=================================================================================
276 void TransformationGUI_ScaleDlg::ValueChangedInSpinBox()
282 //=================================================================================
283 // function : createOperation
285 //=================================================================================
286 GEOM::GEOM_IOperations_ptr TransformationGUI_ScaleDlg::createOperation()
288 return myGeomGUI->GetGeomGen()->GetITransformOperations( getStudyId() );
291 //=================================================================================
292 // function : isValid
294 //=================================================================================
295 bool TransformationGUI_ScaleDlg::isValid( QString& msg )
297 return !(myObjects.length() == 0 || myPoint->_is_nil() || fabs(GetFactor()) <= 0.00001);
301 //=================================================================================
302 // function : execute
304 //=================================================================================
305 bool TransformationGUI_ScaleDlg::execute( ObjectList& objects )
309 GEOM::GEOM_Object_var anObj;
311 if (GroupPoints->CheckButton1->isChecked() || IsPreview())
312 for (int i = 0; i < myObjects.length(); i++)
314 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->ScaleShapeCopy( myObjects[i], myPoint, GetFactor() );
315 if ( !anObj->_is_nil() )
316 objects.push_back( anObj._retn() );
319 for (int i = 0; i < myObjects.length(); i++)
321 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->ScaleShape( myObjects[i], myPoint, GetFactor() );
322 if ( !anObj->_is_nil() )
323 objects.push_back( anObj._retn() );
331 //=================================================================================
332 // function : closeEvent
334 //=================================================================================
335 void TransformationGUI_ScaleDlg::closeEvent( QCloseEvent* e )
337 GEOMBase_Skeleton::closeEvent( e );
341 //=================================================================================
342 // function : GetFactor()
344 //=================================================================================
345 double TransformationGUI_ScaleDlg::GetFactor() const
347 return GroupPoints->SpinBox_DX->GetValue();
351 //=================================================================================
352 // function : CreateCopyModeChanged()
354 //=================================================================================
355 void TransformationGUI_ScaleDlg::CreateCopyModeChanged(bool isCreateCopy)
357 this->GroupBoxName->setEnabled(isCreateCopy);