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() ) );
109 connect( myGeomGUI, SIGNAL( SignalDefaultStepValueChanged( double ) ), this, SLOT( SetDoubleSpinBoxStep( double ) ) );
110 connect( GroupPoints->CheckButton1, SIGNAL( toggled( bool ) ), this, SLOT( CreateCopyModeChanged( bool ) ) );
112 connect( myGeomGUI->getApp()->selectionMgr(),
113 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
115 setHelpFileName( "scale_operation_page.html" );
121 //=================================================================================
122 // function : ~TransformationGUI_ScaleDlg()
123 // purpose : Destroys the object and frees any allocated resources
124 //=================================================================================
125 TransformationGUI_ScaleDlg::~TransformationGUI_ScaleDlg()
127 /* no need to delete child widgets, Qt does it all for us */
131 //=================================================================================
134 //=================================================================================
135 void TransformationGUI_ScaleDlg::Init()
137 myEditCurrentArgument = GroupPoints->LineEdit1;
138 GroupPoints->LineEdit2->clear();
140 myPoint = GEOM::GEOM_Object::_nil();
142 initName( tr( "GEOM_SCALE" ) );
146 //=================================================================================
147 // function : ClickOnOk()
149 //=================================================================================
150 void TransformationGUI_ScaleDlg::ClickOnOk()
152 if ( ClickOnApply() )
157 //=================================================================================
158 // function : ClickOnApply()
160 //=================================================================================
161 bool TransformationGUI_ScaleDlg::ClickOnApply()
163 if ( !onAccept( GroupPoints->CheckButton1->isChecked() ) )
171 //=================================================================================
172 // function : SelectionIntoArgument()
173 // purpose : Called when selection as changed or other case
174 //=================================================================================
175 void TransformationGUI_ScaleDlg::SelectionIntoArgument()
177 myEditCurrentArgument->setText( "" );
180 if ( myEditCurrentArgument == GroupPoints->LineEdit1 ) {
181 int aNbSel = GEOMBase::GetNameOfSelectedIObjects( selectedIO(), aName );
183 myObjects.length( 0 );
186 GEOMBase::ConvertListOfIOInListOfGO( selectedIO(), myObjects );
187 if ( !myObjects.length() )
190 else if ( myEditCurrentArgument == GroupPoints->LineEdit2 ) {
191 if ( IObjectCount() != 1 ) {
192 myPoint = GEOM::GEOM_Object::_nil();
195 Standard_Boolean testResult = Standard_False;
196 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject( firstIObject(), testResult );
197 aName = GEOMBase::GetName( aSelectedObject );
200 if ( GEOMBase::GetShape( aSelectedObject, aShape, TopAbs_SHAPE ) && !aShape.IsNull() ) {
201 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
202 TColStd_IndexedMapOfInteger aMap;
203 aSelMgr->GetIndexes( firstIObject(), aMap );
204 if ( aMap.Extent() == 1 ) {
205 int anIndex = aMap( 1 );
206 aName += QString( ":vertex_%1" ).arg( anIndex );
208 //Find SubShape Object in Father
209 GEOM::GEOM_Object_var aFindedObject = findObjectInFather( aSelectedObject, aName );
211 if ( aFindedObject == GEOM::GEOM_Object::_nil() ) { // Object not found in study
212 GEOM::GEOM_IShapesOperations_var aShapesOp =
213 getGeomEngine()->GetIShapesOperations( getStudyId() );
214 aSelectedObject = aShapesOp->GetSubShape( aSelectedObject, anIndex );
215 aSelMgr->clearSelected();
218 aSelectedObject = aFindedObject; // get Object from study
222 if ( aShape.ShapeType() != TopAbs_VERTEX ) {
223 aSelectedObject = GEOM::GEOM_Object::_nil();
229 myPoint = aSelectedObject;
231 if ( !testResult || CORBA::is_nil( myPoint ) )
234 myEditCurrentArgument->setText( aName );
240 //=================================================================================
241 // function : LineEditReturnPressed()
243 //=================================================================================
244 void TransformationGUI_ScaleDlg::LineEditReturnPressed()
246 QLineEdit* send = (QLineEdit*)sender();
247 if ( send == GroupPoints->LineEdit1 ||
248 send == GroupPoints->LineEdit2 ) {
249 myEditCurrentArgument = send;
250 GEOMBase_Skeleton::LineEditReturnPressed();
255 //=================================================================================
256 // function : SetEditCurrentArgument()
258 //=================================================================================
259 void TransformationGUI_ScaleDlg::SetEditCurrentArgument()
261 QPushButton* send = (QPushButton*)sender();
264 if ( send == GroupPoints->PushButton1 ) {
265 myEditCurrentArgument = GroupPoints->LineEdit1;
267 else if ( send == GroupPoints->PushButton2 ) {
268 myEditCurrentArgument = GroupPoints->LineEdit2;
269 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
272 myEditCurrentArgument->setFocus();
273 SelectionIntoArgument();
277 //=================================================================================
278 // function : ActivateThisDialog()
280 //=================================================================================
281 void TransformationGUI_ScaleDlg::ActivateThisDialog()
283 GEOMBase_Skeleton::ActivateThisDialog();
284 connect( myGeomGUI->getApp()->selectionMgr(),
285 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
287 GroupPoints->LineEdit1->setFocus();
288 myEditCurrentArgument = GroupPoints->LineEdit1;
292 //=================================================================================
293 // function : enterEvent()
295 //=================================================================================
296 void TransformationGUI_ScaleDlg::enterEvent( QEvent* )
298 if ( !mainFrame()->GroupConstructors->isEnabled() )
299 ActivateThisDialog();
303 //=================================================================================
304 // function : ValueChangedInSpinBox()
306 //=================================================================================
307 void TransformationGUI_ScaleDlg::ValueChangedInSpinBox()
312 //=================================================================================
313 // function : SetDoubleSpinBoxStep()
314 // purpose : Double spin box management
315 //=================================================================================
316 void TransformationGUI_ScaleDlg::SetDoubleSpinBoxStep( double step )
318 GroupPoints->SpinBox_DX->setSingleStep(step);
322 //=================================================================================
323 // function : createOperation
325 //=================================================================================
326 GEOM::GEOM_IOperations_ptr TransformationGUI_ScaleDlg::createOperation()
328 return myGeomGUI->GetGeomGen()->GetITransformOperations( getStudyId() );
331 //=================================================================================
332 // function : isValid
334 //=================================================================================
335 bool TransformationGUI_ScaleDlg::isValid( QString& /*msg*/)
337 return !( myObjects.length() == 0 || myPoint->_is_nil() || fabs( GetFactor()) <= 0.00001 );
341 //=================================================================================
342 // function : execute
344 //=================================================================================
345 bool TransformationGUI_ScaleDlg::execute( ObjectList& objects )
347 GEOM::GEOM_Object_var anObj;
349 if ( GroupPoints->CheckButton1->isChecked() || IsPreview() ) {
350 for ( int i = 0; i < myObjects.length(); i++ ) {
351 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->ScaleShapeCopy( myObjects[i], myPoint, GetFactor() );
352 if ( !anObj->_is_nil() )
353 objects.push_back( anObj._retn() );
357 for ( int i = 0; i < myObjects.length(); i++ ) {
358 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->ScaleShape( myObjects[i], myPoint, GetFactor() );
359 if ( !anObj->_is_nil() )
360 objects.push_back( anObj._retn() );
367 //=================================================================================
368 // function : GetFactor()
370 //=================================================================================
371 double TransformationGUI_ScaleDlg::GetFactor() const
373 return GroupPoints->SpinBox_DX->value();
377 //=================================================================================
378 // function : CreateCopyModeChanged()
380 //=================================================================================
381 void TransformationGUI_ScaleDlg::CreateCopyModeChanged( bool isCreateCopy )
383 mainFrame()->GroupBoxName->setEnabled(isCreateCopy);
386 //=================================================================================
387 // function : addSubshapeToStudy
388 // purpose : virtual method to add new SubObjects if local selection
389 //=================================================================================
390 void TransformationGUI_ScaleDlg::addSubshapesToStudy()
392 bool toCreateCopy = IsPreview() || GroupPoints->CheckButton1->isChecked();
393 if ( toCreateCopy ) {
394 QMap<QString, GEOM::GEOM_Object_var> objMap;
396 objMap[GroupPoints->LineEdit2->text()] = myPoint;
398 addSubshapesToFather( objMap );