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 "SUIT_Desktop.h"
32 #include "SUIT_Session.h"
33 #include "SalomeApp_Application.h"
34 #include "SalomeApp_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, const char* name, bool modal, WFlags fl)
53 :GEOMBase_Skeleton(parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu), myGeometryGUI(theGeometryGUI)
55 QPixmap image0(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_SCALE")));
56 QPixmap image1(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_SELECT")));
58 setCaption(tr("GEOM_SCALE_TITLE"));
60 /***************************************************************/
61 GroupConstructors->setTitle(tr("GEOM_SCALE"));
62 RadioButton1->setPixmap(image0);
63 RadioButton2->close(TRUE);
64 RadioButton3->close(TRUE);
66 GroupPoints = new DlgRef_2Sel1Spin2Check(this, "GroupPoints");
67 GroupPoints->CheckButton2->hide();
68 GroupPoints->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
69 GroupPoints->TextLabel1->setText(tr("GEOM_OBJECTS"));
70 GroupPoints->TextLabel2->setText(tr("GEOM_CENTRAL_POINT"));
71 GroupPoints->TextLabel3->setText(tr("GEOM_SCALE_FACTOR"));
72 GroupPoints->LineEdit1->setReadOnly( true );
73 GroupPoints->LineEdit2->setReadOnly( true );
74 GroupPoints->PushButton1->setPixmap(image1);
75 GroupPoints->PushButton2->setPixmap(image1);
76 GroupPoints->CheckButton1->setText(tr("GEOM_CREATE_COPY"));
78 // san -- modification of an exisitng object by offset is not allowed
79 GroupPoints->CheckButton1->hide();
81 Layout1->addWidget(GroupPoints, 2, 0);
82 /***************************************************************/
84 double SpecificStep = 0.5;
85 /* min, max, step and decimals for spin boxes & initial values */
86 GroupPoints->SpinBox_DX->RangeStepAndValidator(-999.999, 999.999, SpecificStep, 3);
87 GroupPoints->SpinBox_DX->SetValue(aFactor);
89 // Activate Create a Copy mode
90 GroupPoints->CheckButton1->setChecked(true);
91 CreateCopyModeChanged(true);
93 /* signals and slots connections */
94 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
95 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
97 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
98 connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
100 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
101 connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
103 connect(GroupPoints->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
104 connect(myGeometryGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_DX, SLOT(SetStep(double)));
105 connect(GroupPoints->CheckButton1, SIGNAL(toggled(bool)), this, SLOT(CreateCopyModeChanged(bool)));
107 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
108 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
114 //=================================================================================
115 // function : ~TransformationGUI_ScaleDlg()
116 // purpose : Destroys the object and frees any allocated resources
117 //=================================================================================
118 TransformationGUI_ScaleDlg::~TransformationGUI_ScaleDlg()
120 /* no need to delete child widgets, Qt does it all for us */
124 //=================================================================================
127 //=================================================================================
128 void TransformationGUI_ScaleDlg::Init()
130 myEditCurrentArgument = GroupPoints->LineEdit1;
131 GroupPoints->LineEdit2->clear();
133 myPoint = GEOM::GEOM_Object::_nil();
135 initName( tr( "GEOM_SCALE" ) );
139 //=================================================================================
140 // function : ClickOnOk()
142 //=================================================================================
143 void TransformationGUI_ScaleDlg::ClickOnOk()
145 if ( ClickOnApply() )
150 //=================================================================================
151 // function : ClickOnApply()
153 //=================================================================================
154 bool TransformationGUI_ScaleDlg::ClickOnApply()
156 if ( !onAccept(GroupPoints->CheckButton1->isChecked()) )
164 //=======================================================================
165 // function : ClickOnCancel()
167 //=======================================================================
168 void TransformationGUI_ScaleDlg::ClickOnCancel()
170 GEOMBase_Skeleton::ClickOnCancel();
174 //=================================================================================
175 // function : SelectionIntoArgument()
176 // purpose : Called when selection as changed or other case
177 //=================================================================================
178 void TransformationGUI_ScaleDlg::SelectionIntoArgument()
180 myEditCurrentArgument->setText("");
183 if(myEditCurrentArgument == GroupPoints->LineEdit1)
185 int aNbSel = GEOMBase::GetNameOfSelectedIObjects(selectedIO(), aName);
191 GEOMBase::ConvertListOfIOInListOfGO(selectedIO(), myObjects);
192 if (!myObjects.length())
195 else if(myEditCurrentArgument == GroupPoints->LineEdit2)
197 if(IObjectCount() != 1)
199 myPoint = GEOM::GEOM_Object::_nil();
202 Standard_Boolean testResult = Standard_False;
203 myPoint = GEOMBase::ConvertIOinGEOMObject(firstIObject(), testResult );
204 if(!testResult || CORBA::is_nil( myPoint ))
206 aName = GEOMBase::GetName( myPoint );
208 myEditCurrentArgument->setText( aName );
214 //=================================================================================
215 // function : LineEditReturnPressed()
217 //=================================================================================
218 void TransformationGUI_ScaleDlg::LineEditReturnPressed()
220 QLineEdit* send = (QLineEdit*)sender();
221 if(send == GroupPoints->LineEdit1 ||
222 send == GroupPoints->LineEdit2)
224 myEditCurrentArgument = send;
225 GEOMBase_Skeleton::LineEditReturnPressed();
230 //=================================================================================
231 // function : SetEditCurrentArgument()
233 //=================================================================================
234 void TransformationGUI_ScaleDlg::SetEditCurrentArgument()
236 QPushButton* send = (QPushButton*)sender();
238 if(send == GroupPoints->PushButton1) {
239 myEditCurrentArgument = GroupPoints->LineEdit1;
242 else if(send == GroupPoints->PushButton2) {
243 myEditCurrentArgument = GroupPoints->LineEdit2;
244 globalSelection( GEOM_POINT );
247 myEditCurrentArgument->setFocus();
248 SelectionIntoArgument();
252 //=================================================================================
253 // function : ActivateThisDialog()
255 //=================================================================================
256 void TransformationGUI_ScaleDlg::ActivateThisDialog()
258 GEOMBase_Skeleton::ActivateThisDialog();
259 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
260 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
262 GroupPoints->LineEdit1->setFocus();
263 myEditCurrentArgument = GroupPoints->LineEdit1;
267 //=================================================================================
268 // function : DeactivateActiveDialog()
269 // purpose : public slot to deactivate if active
270 //=================================================================================
271 void TransformationGUI_ScaleDlg::DeactivateActiveDialog()
273 GEOMBase_Skeleton::DeactivateActiveDialog();
277 //=================================================================================
278 // function : enterEvent()
280 //=================================================================================
281 void TransformationGUI_ScaleDlg::enterEvent(QEvent* e)
283 if( !GroupConstructors->isEnabled() )
284 ActivateThisDialog();
288 //=================================================================================
289 // function : ValueChangedInSpinBox()
291 //=================================================================================
292 void TransformationGUI_ScaleDlg::ValueChangedInSpinBox()
298 //=================================================================================
299 // function : createOperation
301 //=================================================================================
302 GEOM::GEOM_IOperations_ptr TransformationGUI_ScaleDlg::createOperation()
304 return myGeometryGUI->GetGeomGen()->GetITransformOperations( getStudyId() );
307 //=================================================================================
308 // function : isValid
310 //=================================================================================
311 bool TransformationGUI_ScaleDlg::isValid( QString& msg )
313 return !(myObjects.length() == 0 || myPoint->_is_nil() || fabs(GetFactor()) <= 0.00001);
317 //=================================================================================
318 // function : execute
320 //=================================================================================
321 bool TransformationGUI_ScaleDlg::execute( ObjectList& objects )
325 GEOM::GEOM_Object_var anObj;
327 if (GroupPoints->CheckButton1->isChecked() || IsPreview())
328 for (int i = 0; i < myObjects.length(); i++)
330 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->ScaleShapeCopy( myObjects[i], myPoint, GetFactor() );
331 if ( !anObj->_is_nil() )
332 objects.push_back( anObj._retn() );
335 for (int i = 0; i < myObjects.length(); i++)
337 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->ScaleShape( myObjects[i], myPoint, GetFactor() );
338 if ( !anObj->_is_nil() )
339 objects.push_back( anObj._retn() );
347 //=================================================================================
348 // function : closeEvent
350 //=================================================================================
351 void TransformationGUI_ScaleDlg::closeEvent( QCloseEvent* e )
353 GEOMBase_Skeleton::closeEvent( e );
357 //=================================================================================
358 // function : GetFactor()
360 //=================================================================================
361 double TransformationGUI_ScaleDlg::GetFactor() const
363 return GroupPoints->SpinBox_DX->GetValue();
367 //=================================================================================
368 // function : CreateCopyModeChanged()
370 //=================================================================================
371 void TransformationGUI_ScaleDlg::CreateCopyModeChanged(bool isCreateCopy)
373 this->GroupBoxName->setEnabled(isCreateCopy);