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_PositionDlg.cxx
23 // Author : Damien COQUERET, Open CASCADE S.A.S.
26 #include "TransformationGUI_PositionDlg.h"
29 #include <GeometryGUI.h>
32 #include <SUIT_ResourceMgr.h>
33 #include <SUIT_Session.h>
34 #include <SalomeApp_Application.h>
35 #include <LightApp_SelectionMgr.h>
37 #include <TColStd_MapOfInteger.hxx>
39 #include <GEOMImpl_Types.hxx>
41 //=================================================================================
42 // class : TransformationGUI_PositionDlg()
43 // purpose : Constructs a TransformationGUI_PositionDlg which is a child of 'parent', with the
44 // name 'name' and widget flags set to 'f'.
45 // The dialog will by default be modeless, unless you set 'modal' to
46 // TRUE to construct a modal dialog.
47 //=================================================================================
48 TransformationGUI_PositionDlg::TransformationGUI_PositionDlg
49 ( GeometryGUI* theGeometryGUI, QWidget* parent, bool modal, Qt::WindowFlags fl )
50 : GEOMBase_Skeleton( theGeometryGUI, parent, modal, fl )
52 SUIT_ResourceMgr* aResMgr = myGeomGUI->getApp()->resourceMgr();
53 QPixmap image0( aResMgr->loadPixmap( "GEOM", tr( "ICON_DLG_POSITION" ) ) );
54 QPixmap image1( aResMgr->loadPixmap( "GEOM", tr( "ICON_DLG_POSITION2" ) ) );
55 QPixmap imageselect( aResMgr->loadPixmap( "GEOM", tr( "ICON_SELECT") ) );
57 setWindowTitle( tr( "GEOM_POSITION_TITLE" ) );
59 /***************************************************************/
60 mainFrame()->GroupConstructors->setTitle( tr( "GEOM_POSITION" ) );
61 mainFrame()->RadioButton1->setIcon( image0 );
62 mainFrame()->RadioButton2->setIcon( image1 );
63 mainFrame()->RadioButton3->setAttribute( Qt::WA_DeleteOnClose );
64 mainFrame()->RadioButton3->close();
66 Group1 = new DlgRef_3Sel3Spin1Check( centralWidget() );
67 Group1->SpinBox1->hide();
68 Group1->SpinBox2->hide();
69 Group1->SpinBox3->hide();
70 Group1->TextLabel4->hide();
71 Group1->TextLabel5->hide();
72 Group1->TextLabel6->hide();
73 Group1->GroupBox1->setTitle( tr( "GEOM_ARGUMENTS" ) );
74 Group1->TextLabel1->setText( tr( "GEOM_OBJECTS" ) );
75 Group1->TextLabel2->setText( tr( "GEOM_START_LCS" ) );
76 Group1->TextLabel3->setText( tr( "GEOM_END_LCS" ) );
77 Group1->PushButton1->setIcon( imageselect );
78 Group1->PushButton2->setIcon( imageselect );
79 Group1->PushButton3->setIcon( imageselect );
80 Group1->CheckBox1->setText( tr( "GEOM_CREATE_COPY" ) );
82 QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
83 layout->setMargin( 0 ); layout->setSpacing( 6 );
84 layout->addWidget( Group1 );
86 /***************************************************************/
88 setHelpFileName( "modify_location_operation_page.html" );
94 //=================================================================================
95 // function : ~TransformationGUI_PositionDlg()
96 // purpose : Destroys the object and frees any allocated resources
97 //=================================================================================
98 TransformationGUI_PositionDlg::~TransformationGUI_PositionDlg()
100 /* no need to delete child widgets, Qt does it all for us */
104 //=================================================================================
107 //=================================================================================
108 void TransformationGUI_PositionDlg::Init()
111 Group1->LineEdit1->setReadOnly( true );
112 Group1->LineEdit2->setReadOnly( true );
113 Group1->LineEdit3->setReadOnly( true );
115 myStartLCS = GEOM::GEOM_Object::_nil();
116 myEndLCS = GEOM::GEOM_Object::_nil();
118 // Activate Create a Copy mode
119 Group1->CheckBox1->setChecked( true );
120 CreateCopyModeChanged( true );
122 mainFrame()->GroupBoxPublish->show();
124 /* signals and slots connections */
125 connect( buttonOk(), SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
126 connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
128 connect( this, SIGNAL( constructorsClicked( int ) ), this, SLOT( ConstructorsClicked( int ) ) );
130 connect( Group1->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
131 connect( Group1->PushButton2, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
132 connect( Group1->PushButton3, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
134 connect( Group1->LineEdit1, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
135 connect( Group1->LineEdit2, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
136 connect( Group1->LineEdit3, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
138 connect( Group1->CheckBox1, SIGNAL( toggled( bool ) ), this, SLOT( CreateCopyModeChanged( bool ) ) );
140 connect( myGeomGUI->getApp()->selectionMgr(),
141 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
143 initName( tr( "GEOM_POSITION" ) );
145 ConstructorsClicked( 0 );
150 //=================================================================================
151 // function : ConstructorsClicked()
152 // purpose : Radio button management
153 //=================================================================================
154 void TransformationGUI_PositionDlg::ConstructorsClicked( int constructorId )
156 disconnect( myGeomGUI->getApp()->selectionMgr(), 0, this, 0 );
159 myEditCurrentArgument = Group1->LineEdit1;
160 Group1->LineEdit2->clear();
161 Group1->LineEdit3->clear();
162 myStartLCS = GEOM::GEOM_Object::_nil();
163 myEndLCS = GEOM::GEOM_Object::_nil();
165 switch ( constructorId ) {
167 Group1->LineEdit2->hide();
168 Group1->TextLabel2->hide();
169 Group1->PushButton2->hide();
172 Group1->LineEdit2->show();
173 Group1->TextLabel2->show();
174 Group1->PushButton2->show();
178 qApp->processEvents();
180 resize( minimumSize() );
182 connect( myGeomGUI->getApp()->selectionMgr(),
183 SIGNAL( currentSelectionChanged() ), this, SLOT(SelectionIntoArgument() ) );
184 SelectionIntoArgument();
188 //=================================================================================
189 // function : ClickOnOk()
191 //=================================================================================
192 void TransformationGUI_PositionDlg::ClickOnOk()
194 if ( ClickOnApply() )
199 //=================================================================================
200 // function : ClickOnApply()
202 //=================================================================================
203 bool TransformationGUI_PositionDlg::ClickOnApply()
205 if ( !onAccept( Group1->CheckBox1->isChecked() ) )
209 ConstructorsClicked( getConstructorId() );
214 //=================================================================================
215 // function : SelectionIntoArgument()
216 // purpose : Called when selection has changed
217 //=================================================================================
218 void TransformationGUI_PositionDlg::SelectionIntoArgument()
220 myEditCurrentArgument->setText( "" );
223 if ( myEditCurrentArgument == Group1->LineEdit1 ) {
224 int aNbSel = GEOMBase::GetNameOfSelectedIObjects( selectedIO(), aName );
226 myObjects.length( 0 );
230 GEOMBase::ConvertListOfIOInListOfGO( selectedIO(), myObjects );
231 if ( !myObjects.length() ) {
236 else if ( myEditCurrentArgument == Group1->LineEdit2 ) {
237 myStartLCS = GEOM::GEOM_Object::_nil();
238 if ( IObjectCount() != 1 ) {
243 Standard_Boolean testResult = Standard_False;
244 myStartLCS = GEOMBase::ConvertIOinGEOMObject( firstIObject(), testResult );
245 if ( !testResult || CORBA::is_nil( myStartLCS ) ) {
249 aName = GEOMBase::GetName( myStartLCS );
251 else if ( myEditCurrentArgument == Group1->LineEdit3 ) {
252 myEndLCS = GEOM::GEOM_Object::_nil();
253 if ( IObjectCount() != 1 ) {
258 Standard_Boolean testResult = Standard_False;
259 myEndLCS = GEOMBase::ConvertIOinGEOMObject( firstIObject(), testResult );
260 if ( !testResult || CORBA::is_nil( myEndLCS ) ) {
264 aName = GEOMBase::GetName( myEndLCS );
267 myEditCurrentArgument->setText( aName );
272 //=================================================================================
273 // function : LineEditReturnPressed()
275 //=================================================================================
276 void TransformationGUI_PositionDlg::LineEditReturnPressed()
278 QLineEdit* send = (QLineEdit*)sender();
279 if ( send == Group1->LineEdit1 || send == Group1->LineEdit2 ||
280 send == Group1->LineEdit3 ) {
281 myEditCurrentArgument = send;
282 GEOMBase_Skeleton::LineEditReturnPressed();
287 //=================================================================================
288 // function : SetEditCurrentArgument()
290 //=================================================================================
291 void TransformationGUI_PositionDlg::SetEditCurrentArgument()
293 QPushButton* send = (QPushButton*)sender();
295 if ( send == Group1->PushButton1 ) {
296 myEditCurrentArgument = Group1->LineEdit1;
299 else if ( send == Group1->PushButton2 ) {
300 myEditCurrentArgument = Group1->LineEdit2;
301 TColStd_MapOfInteger aMap;
302 aMap.Add( GEOM_PLANE );
303 aMap.Add( GEOM_MARKER );
304 globalSelection( aMap );
306 else if ( send == Group1->PushButton3 ) {
307 myEditCurrentArgument = Group1->LineEdit3;
308 TColStd_MapOfInteger aMap;
309 aMap.Add( GEOM_PLANE );
310 aMap.Add( GEOM_MARKER );
311 globalSelection( aMap );
314 myEditCurrentArgument->setFocus();
315 SelectionIntoArgument();
319 //=================================================================================
320 // function : ActivateThisDialog()
322 //=================================================================================
323 void TransformationGUI_PositionDlg::ActivateThisDialog()
325 GEOMBase_Skeleton::ActivateThisDialog();
326 connect( myGeomGUI->getApp()->selectionMgr(),
327 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
328 ConstructorsClicked( getConstructorId() );
332 //=================================================================================
333 // function : enterEvent()
334 // purpose : when mouse enter onto the QWidget
335 //=================================================================================
336 void TransformationGUI_PositionDlg::enterEvent( QEvent* )
338 if ( !mainFrame()->GroupConstructors->isEnabled() )
339 ActivateThisDialog();
343 //=================================================================================
344 // function : createOperation
346 //=================================================================================
347 GEOM::GEOM_IOperations_ptr TransformationGUI_PositionDlg::createOperation()
349 return getGeomEngine()->GetITransformOperations( getStudyId() );
353 //=================================================================================
354 // function : isValid
356 //=================================================================================
357 bool TransformationGUI_PositionDlg::isValid( QString& /*msg*/ )
360 if ( getConstructorId() == 0 )
361 res = !( myObjects.length() == 0 || myEndLCS->_is_nil() );
363 res = !( myObjects.length() == 0 || myStartLCS->_is_nil() || myEndLCS->_is_nil() );
369 //=================================================================================
370 // function : execute
372 //=================================================================================
373 bool TransformationGUI_PositionDlg::execute( ObjectList& objects )
376 bool toCreateCopy = IsPreview() || Group1->CheckBox1->isChecked();
377 GEOM::GEOM_Object_var anObj;
379 switch ( getConstructorId() ) {
382 for ( int i = 0; i < myObjects.length(); i++ ) {
384 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->
385 PositionShapeCopy( myObjects[i], myObjects[i], myEndLCS );
387 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->
388 PositionShape( myObjects[i], myObjects[i], myEndLCS );
390 if ( !anObj->_is_nil() )
391 objects.push_back( anObj._retn() );
398 for ( int i = 0; i < myObjects.length(); i++ ) {
400 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->
401 PositionShapeCopy( myObjects[i], myStartLCS, myEndLCS );
403 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->
404 PositionShape( myObjects[i], myStartLCS, myEndLCS );
405 if ( !anObj->_is_nil() )
406 objects.push_back( anObj._retn() );
416 //=================================================================================
417 // function : restoreSubShapes
419 //=================================================================================
420 void TransformationGUI_PositionDlg::restoreSubShapes( SALOMEDS::Study_ptr theStudy,
421 SALOMEDS::SObject_ptr theSObject )
423 if ( mainFrame()->CheckBoxRestoreSS->isChecked() ) {
424 // empty list of arguments means that all arguments should be restored
425 getGeomEngine()->RestoreSubShapesSO( theStudy, theSObject, GEOM::ListOfGO(),
426 /*theFindMethod=*/GEOM::FSM_Transformed,
427 /*theInheritFirstArg=*/true );
431 //=================================================================================
432 // function : CreateCopyModeChanged()
434 //=================================================================================
435 void TransformationGUI_PositionDlg::CreateCopyModeChanged( bool isCreateCopy )
437 mainFrame()->GroupBoxName->setEnabled( isCreateCopy );