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"
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 <TopoDS_Shape.hxx>
39 #include <TColStd_IndexedMapOfInteger.hxx>
40 #include <TopTools_IndexedMapOfShape.hxx>
42 #include <GEOMImpl_Types.hxx>
44 //=================================================================================
45 // class : TransformationGUI_ScaleDlg()
46 // purpose : Constructs a TransformationGUI_ScaleDlg which is a child of 'parent', with the
47 // name 'name' and widget flags set to 'f'.
48 // The dialog will by default be modeless, unless you set 'modal' to
49 // TRUE to construct a modal dialog.
50 //=================================================================================
51 TransformationGUI_ScaleDlg::TransformationGUI_ScaleDlg( GeometryGUI* theGeometryGUI, QWidget* parent,
52 bool modal, Qt::WindowFlags fl )
53 : GEOMBase_Skeleton( theGeometryGUI, parent, modal, fl )
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 setWindowTitle( tr( "GEOM_SCALE_TITLE" ) );
60 /***************************************************************/
61 mainFrame()->GroupConstructors->setTitle( tr( "GEOM_SCALE" ) );
62 mainFrame()->RadioButton1->setIcon( image0 );
63 mainFrame()->RadioButton2->setAttribute( Qt::WA_DeleteOnClose );
64 mainFrame()->RadioButton2->close();
65 mainFrame()->RadioButton3->setAttribute( Qt::WA_DeleteOnClose );
66 mainFrame()->RadioButton3->close();
68 GroupPoints = new DlgRef_2Sel1Spin2Check( centralWidget() );
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->setIcon( image1 );
77 GroupPoints->PushButton2->setIcon( 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 QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
84 layout->setMargin( 0 ); layout->setSpacing( 6 );
85 layout->addWidget( GroupPoints );
87 /***************************************************************/
89 double SpecificStep = 0.5;
90 /* min, max, step and decimals for spin boxes & initial values */
91 initSpinBox( GroupPoints->SpinBox_DX, COORD_MIN, COORD_MAX, SpecificStep, 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
92 GroupPoints->SpinBox_DX->setValue( aFactor );
94 // Activate Create a Copy mode
95 GroupPoints->CheckButton1->setChecked( true );
96 CreateCopyModeChanged( true );
98 /* signals and slots connections */
99 connect( buttonOk(), SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
100 connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
102 connect( GroupPoints->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
103 connect( GroupPoints->PushButton2, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
105 connect( GroupPoints->LineEdit1, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
106 connect( GroupPoints->LineEdit2, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
108 connect( GroupPoints->SpinBox_DX, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox() ) );
110 connect( myGeomGUI, SIGNAL( SignalDefaultStepValueChanged( double ) ), GroupPoints->SpinBox_DX, SLOT( SetStep( double ) ) );
112 connect( GroupPoints->CheckButton1, SIGNAL( toggled( bool ) ), this, SLOT( CreateCopyModeChanged( bool ) ) );
114 connect( myGeomGUI->getApp()->selectionMgr(),
115 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
117 setHelpFileName( "scale_operation_page.html" );
123 //=================================================================================
124 // function : ~TransformationGUI_ScaleDlg()
125 // purpose : Destroys the object and frees any allocated resources
126 //=================================================================================
127 TransformationGUI_ScaleDlg::~TransformationGUI_ScaleDlg()
129 /* no need to delete child widgets, Qt does it all for us */
133 //=================================================================================
136 //=================================================================================
137 void TransformationGUI_ScaleDlg::Init()
139 myEditCurrentArgument = GroupPoints->LineEdit1;
140 GroupPoints->LineEdit2->clear();
142 myPoint = GEOM::GEOM_Object::_nil();
144 initName( tr( "GEOM_SCALE" ) );
148 //=================================================================================
149 // function : ClickOnOk()
151 //=================================================================================
152 void TransformationGUI_ScaleDlg::ClickOnOk()
154 if ( ClickOnApply() )
159 //=================================================================================
160 // function : ClickOnApply()
162 //=================================================================================
163 bool TransformationGUI_ScaleDlg::ClickOnApply()
165 if ( !onAccept( GroupPoints->CheckButton1->isChecked() ) )
173 //=================================================================================
174 // function : SelectionIntoArgument()
175 // purpose : Called when selection as changed or other case
176 //=================================================================================
177 void TransformationGUI_ScaleDlg::SelectionIntoArgument()
179 myEditCurrentArgument->setText( "" );
182 if ( myEditCurrentArgument == GroupPoints->LineEdit1 ) {
183 int aNbSel = GEOMBase::GetNameOfSelectedIObjects( selectedIO(), aName );
185 myObjects.length( 0 );
188 GEOMBase::ConvertListOfIOInListOfGO( selectedIO(), myObjects );
189 if ( !myObjects.length() )
192 else if ( myEditCurrentArgument == GroupPoints->LineEdit2 ) {
193 if ( IObjectCount() != 1 ) {
194 myPoint = GEOM::GEOM_Object::_nil();
197 Standard_Boolean testResult = Standard_False;
198 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject( firstIObject(), testResult );
199 aName = GEOMBase::GetName( aSelectedObject );
202 if ( GEOMBase::GetShape( aSelectedObject, aShape, TopAbs_SHAPE ) && !aShape.IsNull() ) {
203 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
204 TColStd_IndexedMapOfInteger aMap;
205 aSelMgr->GetIndexes( firstIObject(), aMap );
206 if ( aMap.Extent() == 1 ) {
207 int anIndex = aMap( 1 );
208 aName += QString( ":vertex_%1" ).arg( anIndex );
210 //Find SubShape Object in Father
211 GEOM::GEOM_Object_var aFindedObject = findObjectInFather( aSelectedObject, aName );
213 if ( aFindedObject == GEOM::GEOM_Object::_nil() ) { // Object not found in study
214 GEOM::GEOM_IShapesOperations_var aShapesOp =
215 getGeomEngine()->GetIShapesOperations( getStudyId() );
216 aSelectedObject = aShapesOp->GetSubShape( aSelectedObject, anIndex );
217 aSelMgr->clearSelected();
220 aSelectedObject = aFindedObject; // get Object from study
224 if ( aShape.ShapeType() != TopAbs_VERTEX ) {
225 aSelectedObject = GEOM::GEOM_Object::_nil();
231 myPoint = aSelectedObject;
233 if ( !testResult || CORBA::is_nil( myPoint ) )
236 myEditCurrentArgument->setText( aName );
242 //=================================================================================
243 // function : LineEditReturnPressed()
245 //=================================================================================
246 void TransformationGUI_ScaleDlg::LineEditReturnPressed()
248 QLineEdit* send = (QLineEdit*)sender();
249 if ( send == GroupPoints->LineEdit1 ||
250 send == GroupPoints->LineEdit2 ) {
251 myEditCurrentArgument = send;
252 GEOMBase_Skeleton::LineEditReturnPressed();
257 //=================================================================================
258 // function : SetEditCurrentArgument()
260 //=================================================================================
261 void TransformationGUI_ScaleDlg::SetEditCurrentArgument()
263 QPushButton* send = (QPushButton*)sender();
266 if ( send == GroupPoints->PushButton1 ) {
267 myEditCurrentArgument = GroupPoints->LineEdit1;
269 else if ( send == GroupPoints->PushButton2 ) {
270 myEditCurrentArgument = GroupPoints->LineEdit2;
271 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
274 myEditCurrentArgument->setFocus();
275 SelectionIntoArgument();
279 //=================================================================================
280 // function : ActivateThisDialog()
282 //=================================================================================
283 void TransformationGUI_ScaleDlg::ActivateThisDialog()
285 GEOMBase_Skeleton::ActivateThisDialog();
286 connect( myGeomGUI->getApp()->selectionMgr(),
287 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
289 GroupPoints->LineEdit1->setFocus();
290 myEditCurrentArgument = GroupPoints->LineEdit1;
294 //=================================================================================
295 // function : enterEvent()
297 //=================================================================================
298 void TransformationGUI_ScaleDlg::enterEvent( QEvent* )
300 if ( !mainFrame()->GroupConstructors->isEnabled() )
301 ActivateThisDialog();
305 //=================================================================================
306 // function : ValueChangedInSpinBox()
308 //=================================================================================
309 void TransformationGUI_ScaleDlg::ValueChangedInSpinBox()
315 //=================================================================================
316 // function : createOperation
318 //=================================================================================
319 GEOM::GEOM_IOperations_ptr TransformationGUI_ScaleDlg::createOperation()
321 return myGeomGUI->GetGeomGen()->GetITransformOperations( getStudyId() );
324 //=================================================================================
325 // function : isValid
327 //=================================================================================
328 bool TransformationGUI_ScaleDlg::isValid( QString& /*msg*/)
330 return !( myObjects.length() == 0 || myPoint->_is_nil() || fabs( GetFactor()) <= 0.00001 );
334 //=================================================================================
335 // function : execute
337 //=================================================================================
338 bool TransformationGUI_ScaleDlg::execute( ObjectList& objects )
340 GEOM::GEOM_Object_var anObj;
342 if ( GroupPoints->CheckButton1->isChecked() || IsPreview() ) {
343 for ( int i = 0; i < myObjects.length(); i++ ) {
344 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->ScaleShapeCopy( myObjects[i], myPoint, GetFactor() );
345 if ( !anObj->_is_nil() )
346 objects.push_back( anObj._retn() );
350 for ( int i = 0; i < myObjects.length(); i++ ) {
351 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->ScaleShape( myObjects[i], myPoint, GetFactor() );
352 if ( !anObj->_is_nil() )
353 objects.push_back( anObj._retn() );
360 //=================================================================================
361 // function : GetFactor()
363 //=================================================================================
364 double TransformationGUI_ScaleDlg::GetFactor() const
366 return GroupPoints->SpinBox_DX->value();
370 //=================================================================================
371 // function : CreateCopyModeChanged()
373 //=================================================================================
374 void TransformationGUI_ScaleDlg::CreateCopyModeChanged( bool isCreateCopy )
376 mainFrame()->GroupBoxName->setEnabled(isCreateCopy);
379 //=================================================================================
380 // function : addSubshapeToStudy
381 // purpose : virtual method to add new SubObjects if local selection
382 //=================================================================================
383 void TransformationGUI_ScaleDlg::addSubshapesToStudy()
385 bool toCreateCopy = IsPreview() || GroupPoints->CheckButton1->isChecked();
386 if ( toCreateCopy ) {
387 QMap<QString, GEOM::GEOM_Object_var> objMap;
389 objMap[GroupPoints->LineEdit2->text()] = myPoint;
391 addSubshapesToFather( objMap );