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
22 // File : TransformationGUI_ScaleDlg.cxx
23 // Author : Lucien PIGNOLONI, Open CASCADE S.A.S.
25 #include "TransformationGUI_ScaleDlg.h"
27 #include <GEOM_DlgRef.h>
28 #include <GeometryGUI.h>
31 #include <SUIT_ResourceMgr.h>
32 #include <SUIT_Session.h>
33 #include <SalomeApp_Application.h>
34 #include <LightApp_SelectionMgr.h>
36 #include <GEOMImpl_Types.hxx>
38 //=================================================================================
39 // class : TransformationGUI_ScaleDlg()
40 // purpose : Constructs a TransformationGUI_ScaleDlg which is a child of 'parent', with the
41 // name 'name' and widget flags set to 'f'.
42 // The dialog will by default be modeless, unless you set 'modal' to
43 // TRUE to construct a modal dialog.
44 //=================================================================================
45 TransformationGUI_ScaleDlg::TransformationGUI_ScaleDlg( GeometryGUI* theGeometryGUI, QWidget* parent,
46 bool modal, Qt::WindowFlags fl )
47 : GEOMBase_Skeleton( theGeometryGUI, parent, modal, fl )
49 QPixmap image0( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_SCALE" ) ) );
50 QPixmap image1( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
52 setWindowTitle( tr( "GEOM_SCALE_TITLE" ) );
54 /***************************************************************/
55 mainFrame()->GroupConstructors->setTitle( tr( "GEOM_SCALE" ) );
56 mainFrame()->RadioButton1->setIcon( image0 );
57 mainFrame()->RadioButton2->setAttribute( Qt::WA_DeleteOnClose );
58 mainFrame()->RadioButton2->close();
59 mainFrame()->RadioButton3->setAttribute( Qt::WA_DeleteOnClose );
60 mainFrame()->RadioButton3->close();
62 GroupPoints = new DlgRef_2Sel1Spin2Check( centralWidget() );
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->setIcon( image1 );
71 GroupPoints->PushButton2->setIcon( 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 QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
78 layout->setMargin( 0 ); layout->setSpacing( 6 );
79 layout->addWidget( GroupPoints );
81 /***************************************************************/
83 double SpecificStep = 0.5;
84 /* min, max, step and decimals for spin boxes & initial values */
85 initSpinBox( GroupPoints->SpinBox_DX, COORD_MIN, COORD_MAX, SpecificStep, 3 );
86 GroupPoints->SpinBox_DX->setValue( aFactor );
88 // Activate Create a Copy mode
89 GroupPoints->CheckButton1->setChecked( true );
90 CreateCopyModeChanged( true );
92 /* signals and slots connections */
93 connect( buttonOk(), SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
94 connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
96 connect( GroupPoints->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
97 connect( GroupPoints->PushButton2, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
99 connect( GroupPoints->LineEdit1, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
100 connect( GroupPoints->LineEdit2, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
102 connect( GroupPoints->SpinBox_DX, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox() ) );
104 connect( myGeomGUI, SIGNAL( SignalDefaultStepValueChanged( double ) ), GroupPoints->SpinBox_DX, SLOT( SetStep( double ) ) );
106 connect( GroupPoints->CheckButton1, SIGNAL( toggled( bool ) ), this, SLOT( CreateCopyModeChanged( bool ) ) );
108 connect( myGeomGUI->getApp()->selectionMgr(),
109 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
111 setHelpFileName( "scale_transform.htm" );
117 //=================================================================================
118 // function : ~TransformationGUI_ScaleDlg()
119 // purpose : Destroys the object and frees any allocated resources
120 //=================================================================================
121 TransformationGUI_ScaleDlg::~TransformationGUI_ScaleDlg()
123 /* no need to delete child widgets, Qt does it all for us */
127 //=================================================================================
130 //=================================================================================
131 void TransformationGUI_ScaleDlg::Init()
133 myEditCurrentArgument = GroupPoints->LineEdit1;
134 GroupPoints->LineEdit2->clear();
136 myPoint = GEOM::GEOM_Object::_nil();
138 initName( tr( "GEOM_SCALE" ) );
142 //=================================================================================
143 // function : ClickOnOk()
145 //=================================================================================
146 void TransformationGUI_ScaleDlg::ClickOnOk()
148 if ( ClickOnApply() )
153 //=================================================================================
154 // function : ClickOnApply()
156 //=================================================================================
157 bool TransformationGUI_ScaleDlg::ClickOnApply()
159 if ( !onAccept( GroupPoints->CheckButton1->isChecked() ) )
167 //=================================================================================
168 // function : SelectionIntoArgument()
169 // purpose : Called when selection as changed or other case
170 //=================================================================================
171 void TransformationGUI_ScaleDlg::SelectionIntoArgument()
173 myEditCurrentArgument->setText( "" );
176 if ( myEditCurrentArgument == GroupPoints->LineEdit1 ) {
177 int aNbSel = GEOMBase::GetNameOfSelectedIObjects( selectedIO(), aName );
179 myObjects.length( 0 );
182 GEOMBase::ConvertListOfIOInListOfGO( selectedIO(), myObjects );
183 if ( !myObjects.length() )
186 else if ( myEditCurrentArgument == GroupPoints->LineEdit2 ) {
187 if ( IObjectCount() != 1 ) {
188 myPoint = GEOM::GEOM_Object::_nil();
191 Standard_Boolean testResult = Standard_False;
192 myPoint = GEOMBase::ConvertIOinGEOMObject( firstIObject(), testResult );
193 if ( !testResult || CORBA::is_nil( myPoint ) )
195 aName = GEOMBase::GetName( myPoint );
197 myEditCurrentArgument->setText( aName );
203 //=================================================================================
204 // function : LineEditReturnPressed()
206 //=================================================================================
207 void TransformationGUI_ScaleDlg::LineEditReturnPressed()
209 QLineEdit* send = (QLineEdit*)sender();
210 if ( send == GroupPoints->LineEdit1 ||
211 send == GroupPoints->LineEdit2 ) {
212 myEditCurrentArgument = send;
213 GEOMBase_Skeleton::LineEditReturnPressed();
218 //=================================================================================
219 // function : SetEditCurrentArgument()
221 //=================================================================================
222 void TransformationGUI_ScaleDlg::SetEditCurrentArgument()
224 QPushButton* send = (QPushButton*)sender();
226 if ( send == GroupPoints->PushButton1 ) {
227 myEditCurrentArgument = GroupPoints->LineEdit1;
230 else if ( send == GroupPoints->PushButton2 ) {
231 myEditCurrentArgument = GroupPoints->LineEdit2;
232 globalSelection( GEOM_POINT );
235 myEditCurrentArgument->setFocus();
236 SelectionIntoArgument();
240 //=================================================================================
241 // function : ActivateThisDialog()
243 //=================================================================================
244 void TransformationGUI_ScaleDlg::ActivateThisDialog()
246 GEOMBase_Skeleton::ActivateThisDialog();
247 connect( myGeomGUI->getApp()->selectionMgr(),
248 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
250 GroupPoints->LineEdit1->setFocus();
251 myEditCurrentArgument = GroupPoints->LineEdit1;
255 //=================================================================================
256 // function : enterEvent()
258 //=================================================================================
259 void TransformationGUI_ScaleDlg::enterEvent( QEvent* )
261 if( !mainFrame()->GroupConstructors->isEnabled() )
262 ActivateThisDialog();
266 //=================================================================================
267 // function : ValueChangedInSpinBox()
269 //=================================================================================
270 void TransformationGUI_ScaleDlg::ValueChangedInSpinBox()
276 //=================================================================================
277 // function : createOperation
279 //=================================================================================
280 GEOM::GEOM_IOperations_ptr TransformationGUI_ScaleDlg::createOperation()
282 return myGeomGUI->GetGeomGen()->GetITransformOperations( getStudyId() );
285 //=================================================================================
286 // function : isValid
288 //=================================================================================
289 bool TransformationGUI_ScaleDlg::isValid( QString& /*msg*/)
291 return !( myObjects.length() == 0 || myPoint->_is_nil() || fabs( GetFactor()) <= 0.00001 );
295 //=================================================================================
296 // function : execute
298 //=================================================================================
299 bool TransformationGUI_ScaleDlg::execute( ObjectList& objects )
301 GEOM::GEOM_Object_var anObj;
303 if ( GroupPoints->CheckButton1->isChecked() || IsPreview() ) {
304 for ( int i = 0; i < myObjects.length(); i++ ) {
305 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->ScaleShapeCopy( myObjects[i], myPoint, GetFactor() );
306 if ( !anObj->_is_nil() )
307 objects.push_back( anObj._retn() );
311 for ( int i = 0; i < myObjects.length(); i++ ) {
312 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->ScaleShape( myObjects[i], myPoint, GetFactor() );
313 if ( !anObj->_is_nil() )
314 objects.push_back( anObj._retn() );
321 //=================================================================================
322 // function : closeEvent
324 //=================================================================================
325 void TransformationGUI_ScaleDlg::closeEvent( QCloseEvent* e )
327 GEOMBase_Skeleton::closeEvent( e );
331 //=================================================================================
332 // function : GetFactor()
334 //=================================================================================
335 double TransformationGUI_ScaleDlg::GetFactor() const
337 return GroupPoints->SpinBox_DX->value();
341 //=================================================================================
342 // function : CreateCopyModeChanged()
344 //=================================================================================
345 void TransformationGUI_ScaleDlg::CreateCopyModeChanged( bool isCreateCopy )
347 mainFrame()->GroupBoxName->setEnabled(isCreateCopy);