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 /* signals and slots connections */
123 connect( buttonOk(), SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
124 connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
126 connect( this, SIGNAL( constructorsClicked( int ) ), this, SLOT( ConstructorsClicked( int ) ) );
128 connect( Group1->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
129 connect( Group1->PushButton2, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
130 connect( Group1->PushButton3, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
132 connect( Group1->LineEdit1, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
133 connect( Group1->LineEdit2, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
134 connect( Group1->LineEdit3, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
136 connect( Group1->CheckBox1, SIGNAL( toggled( bool ) ), this, SLOT( CreateCopyModeChanged( bool ) ) );
138 connect( myGeomGUI->getApp()->selectionMgr(),
139 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
141 initName( tr( "GEOM_POSITION" ) );
143 ConstructorsClicked( 0 );
148 //=================================================================================
149 // function : ConstructorsClicked()
150 // purpose : Radio button management
151 //=================================================================================
152 void TransformationGUI_PositionDlg::ConstructorsClicked( int constructorId )
154 disconnect( myGeomGUI->getApp()->selectionMgr(), 0, this, 0 );
157 myEditCurrentArgument = Group1->LineEdit1;
158 Group1->LineEdit2->clear();
159 Group1->LineEdit3->clear();
160 myStartLCS = GEOM::GEOM_Object::_nil();
161 myEndLCS = GEOM::GEOM_Object::_nil();
163 switch ( constructorId ) {
165 Group1->LineEdit2->hide();
166 Group1->TextLabel2->hide();
167 Group1->PushButton2->hide();
170 Group1->LineEdit2->show();
171 Group1->TextLabel2->show();
172 Group1->PushButton2->show();
176 qApp->processEvents();
178 resize( minimumSize() );
180 connect( myGeomGUI->getApp()->selectionMgr(),
181 SIGNAL( currentSelectionChanged() ), this, SLOT(SelectionIntoArgument() ) );
182 SelectionIntoArgument();
186 //=================================================================================
187 // function : ClickOnOk()
189 //=================================================================================
190 void TransformationGUI_PositionDlg::ClickOnOk()
192 if ( ClickOnApply() )
197 //=================================================================================
198 // function : ClickOnApply()
200 //=================================================================================
201 bool TransformationGUI_PositionDlg::ClickOnApply()
203 if ( !onAccept( Group1->CheckBox1->isChecked() ) )
207 ConstructorsClicked( getConstructorId() );
212 //=================================================================================
213 // function : SelectionIntoArgument()
214 // purpose : Called when selection has changed
215 //=================================================================================
216 void TransformationGUI_PositionDlg::SelectionIntoArgument()
218 myEditCurrentArgument->setText( "" );
221 if ( myEditCurrentArgument == Group1->LineEdit1 ) {
222 int aNbSel = GEOMBase::GetNameOfSelectedIObjects( selectedIO(), aName );
224 myObjects.length( 0 );
228 GEOMBase::ConvertListOfIOInListOfGO( selectedIO(), myObjects );
229 if ( !myObjects.length() ) {
234 else if ( myEditCurrentArgument == Group1->LineEdit2 ) {
235 myStartLCS = GEOM::GEOM_Object::_nil();
236 if ( IObjectCount() != 1 ) {
241 Standard_Boolean testResult = Standard_False;
242 myStartLCS = GEOMBase::ConvertIOinGEOMObject( firstIObject(), testResult );
243 if ( !testResult || CORBA::is_nil( myStartLCS ) ) {
247 aName = GEOMBase::GetName( myStartLCS );
249 else if ( myEditCurrentArgument == Group1->LineEdit3 ) {
250 myEndLCS = GEOM::GEOM_Object::_nil();
251 if ( IObjectCount() != 1 ) {
256 Standard_Boolean testResult = Standard_False;
257 myEndLCS = GEOMBase::ConvertIOinGEOMObject( firstIObject(), testResult );
258 if ( !testResult || CORBA::is_nil( myEndLCS ) ) {
262 aName = GEOMBase::GetName( myEndLCS );
265 myEditCurrentArgument->setText( aName );
270 //=================================================================================
271 // function : LineEditReturnPressed()
273 //=================================================================================
274 void TransformationGUI_PositionDlg::LineEditReturnPressed()
276 QLineEdit* send = (QLineEdit*)sender();
277 if ( send == Group1->LineEdit1 || send == Group1->LineEdit2 ||
278 send == Group1->LineEdit3 ) {
279 myEditCurrentArgument = send;
280 GEOMBase_Skeleton::LineEditReturnPressed();
285 //=================================================================================
286 // function : SetEditCurrentArgument()
288 //=================================================================================
289 void TransformationGUI_PositionDlg::SetEditCurrentArgument()
291 QPushButton* send = (QPushButton*)sender();
293 if ( send == Group1->PushButton1 ) {
294 myEditCurrentArgument = Group1->LineEdit1;
297 else if ( send == Group1->PushButton2 ) {
298 myEditCurrentArgument = Group1->LineEdit2;
299 TColStd_MapOfInteger aMap;
300 aMap.Add( GEOM_PLANE );
301 aMap.Add( GEOM_MARKER );
302 globalSelection( aMap );
304 else if ( send == Group1->PushButton3 ) {
305 myEditCurrentArgument = Group1->LineEdit3;
306 TColStd_MapOfInteger aMap;
307 aMap.Add( GEOM_PLANE );
308 aMap.Add( GEOM_MARKER );
309 globalSelection( aMap );
312 myEditCurrentArgument->setFocus();
313 SelectionIntoArgument();
317 //=================================================================================
318 // function : ActivateThisDialog()
320 //=================================================================================
321 void TransformationGUI_PositionDlg::ActivateThisDialog()
323 GEOMBase_Skeleton::ActivateThisDialog();
324 connect( myGeomGUI->getApp()->selectionMgr(),
325 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
326 ConstructorsClicked( getConstructorId() );
330 //=================================================================================
331 // function : enterEvent()
332 // purpose : when mouse enter onto the QWidget
333 //=================================================================================
334 void TransformationGUI_PositionDlg::enterEvent( QEvent* )
336 if ( !mainFrame()->GroupConstructors->isEnabled() )
337 ActivateThisDialog();
341 //=================================================================================
342 // function : createOperation
344 //=================================================================================
345 GEOM::GEOM_IOperations_ptr TransformationGUI_PositionDlg::createOperation()
347 return getGeomEngine()->GetITransformOperations( getStudyId() );
351 //=================================================================================
352 // function : isValid
354 //=================================================================================
355 bool TransformationGUI_PositionDlg::isValid( QString& /*msg*/ )
358 if ( getConstructorId() == 0 )
359 res = !( myObjects.length() == 0 || myEndLCS->_is_nil() );
361 res = !( myObjects.length() == 0 || myStartLCS->_is_nil() || myEndLCS->_is_nil() );
367 //=================================================================================
368 // function : execute
370 //=================================================================================
371 bool TransformationGUI_PositionDlg::execute( ObjectList& objects )
374 bool toCreateCopy = IsPreview() || Group1->CheckBox1->isChecked();
375 GEOM::GEOM_Object_var anObj;
377 switch ( getConstructorId() ) {
380 for ( int i = 0; i < myObjects.length(); i++ ) {
382 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->PositionShapeCopy( myObjects[i], myObjects[i], myEndLCS );
384 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->PositionShape( myObjects[i], myObjects[i], myEndLCS );
386 if ( !anObj->_is_nil() )
387 objects.push_back( anObj._retn() );
394 for ( int i = 0; i < myObjects.length(); i++ ) {
396 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->PositionShapeCopy( myObjects[i], myStartLCS, myEndLCS );
398 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->PositionShape( myObjects[i], myStartLCS, myEndLCS );
399 if ( !anObj->_is_nil() )
400 objects.push_back( anObj._retn() );
411 //=================================================================================
412 // function : CreateCopyModeChanged()
414 //=================================================================================
415 void TransformationGUI_PositionDlg::CreateCopyModeChanged( bool isCreateCopy )
417 mainFrame()->GroupBoxName->setEnabled( isCreateCopy );