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_MirrorDlg.cxx
23 // Author : Lucien PIGNOLONI, Open CASCADE S.A.S.
26 #include "TransformationGUI_MirrorDlg.h"
28 #include <GEOM_DlgRef.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 <GEOMImpl_Types.hxx>
39 //=================================================================================
40 // class : TransformationGUI_MirrorDlg()
41 // purpose : Constructs a TransformationGUI_MirrorDlg which is a child of 'parent', with the
42 // name 'name' and widget flags set to 'f'.
43 // The dialog will by default be modeless, unless you set 'modal' to
44 // TRUE to construct a modal dialog.
45 //=================================================================================
46 TransformationGUI_MirrorDlg::TransformationGUI_MirrorDlg( GeometryGUI* theGeometryGUI, QWidget* parent,
47 bool modal, Qt::WindowFlags fl )
48 : GEOMBase_Skeleton( theGeometryGUI, parent, modal, fl )
50 QPixmap image0( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_MIRROR_POINT" ) ) );
51 QPixmap image1( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_MIRROR_AXE" ) ) );
52 QPixmap image2( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_MIRROR_PLANE" ) ) );
53 QPixmap image3( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
55 setWindowTitle( tr( "GEOM_MIRROR_TITLE" ) );
57 /***************************************************************/
58 mainFrame()->GroupConstructors->setTitle( tr( "GEOM_MIRROR" ) );
59 mainFrame()->RadioButton1->setIcon( image0 );
60 mainFrame()->RadioButton2->setIcon( image1 );
61 mainFrame()->RadioButton3->setIcon( image2 );
63 GroupPoints = new DlgRef_2Sel1Spin2Check( centralWidget() );
64 GroupPoints->SpinBox_DX->hide();
65 GroupPoints->TextLabel3->hide();
66 GroupPoints->CheckButton2->hide();
67 GroupPoints->GroupBox1->setTitle( tr( "GEOM_ARGUMENTS" ) );
68 GroupPoints->TextLabel1->setText( tr( "GEOM_OBJECTS" ) );
69 GroupPoints->TextLabel2->setText( tr( "GEOM_POINT_MIRROR" ) );
70 GroupPoints->TextLabel2->setFixedWidth( 74 );
71 GroupPoints->PushButton1->setIcon( image3 );
72 GroupPoints->PushButton2->setIcon( image3 );
73 GroupPoints->CheckButton1->setText( tr( "GEOM_CREATE_COPY" ) );
75 QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
76 layout->setMargin( 0 ); layout->setSpacing( 6 );
77 layout->addWidget( GroupPoints );
78 /***************************************************************/
80 setHelpFileName( "mirror_image.htm" );
86 //=================================================================================
87 // function : ~TransformationGUI_MirrorDlg()
88 // purpose : Destroys the object and frees any allocated resources
89 //=================================================================================
90 TransformationGUI_MirrorDlg::~TransformationGUI_MirrorDlg()
92 /* no need to delete child widgets, Qt does it all for us */
96 //=================================================================================
99 //=================================================================================
100 void TransformationGUI_MirrorDlg::Init()
103 myEditCurrentArgument = GroupPoints->LineEdit1;
104 GroupPoints->LineEdit1->setReadOnly( true );
105 GroupPoints->LineEdit2->setReadOnly( true );
107 myArgument = GEOM::GEOM_Object::_nil();
109 // Activate Create a Copy mode
110 GroupPoints->CheckButton1->setChecked( true );
111 CreateCopyModeChanged( true );
113 /* signals and slots connections */
114 connect( buttonOk(), SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
115 connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
117 connect( this, SIGNAL( constructorsClicked( int ) ), this, SLOT( ConstructorsClicked( int ) ) );
119 connect( GroupPoints->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
120 connect( GroupPoints->PushButton2, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
122 connect( GroupPoints->LineEdit1, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
123 connect( GroupPoints->LineEdit2, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
125 connect( GroupPoints->CheckButton1, SIGNAL( toggled( bool ) ), this, SLOT( CreateCopyModeChanged( bool ) ) );
127 connect( myGeomGUI->getApp()->selectionMgr(),
128 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
130 initName( tr( "GEOM_MIRROR" ) );
132 ConstructorsClicked( 0 );
136 //=================================================================================
137 // function : ConstructorsClicked()
138 // purpose : Radio button management
139 //=================================================================================
140 void TransformationGUI_MirrorDlg::ConstructorsClicked( int constructorId )
142 disconnect( myGeomGUI->getApp()->selectionMgr(), 0, this, 0 );
145 myEditCurrentArgument = GroupPoints->LineEdit1;
146 GroupPoints->LineEdit2->clear();
147 myArgument = GEOM::GEOM_Object::_nil();
149 switch ( constructorId ) {
150 case 0: /* mirror an object by point */
151 GroupPoints->TextLabel2->setText( tr( "GEOM_POINT_MIRROR" ) );
153 case 1: /* mirror an object by axe */
154 GroupPoints->TextLabel2->setText( tr( "GEOM_AXE_MIRROR" ) );
156 case 2: /* mirror an object by plane */
157 GroupPoints->TextLabel2->setText( tr( "GEOM_PLANE_MIRROR" ) );
161 connect( myGeomGUI->getApp()->selectionMgr(),
162 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
167 //=================================================================================
168 // function : ClickOnOk()
170 //=================================================================================
171 void TransformationGUI_MirrorDlg::ClickOnOk()
173 if ( ClickOnApply() )
178 //=================================================================================
179 // function : ClickOnApply()
181 //=================================================================================
182 bool TransformationGUI_MirrorDlg::ClickOnApply()
184 if ( !onAccept( GroupPoints->CheckButton1->isChecked() ) )
188 ConstructorsClicked( getConstructorId() );
193 //=================================================================================
194 // function : SelectionIntoArgument()
195 // purpose : Called when selection has changed
196 //=================================================================================
197 void TransformationGUI_MirrorDlg::SelectionIntoArgument()
199 myEditCurrentArgument->setText( "" );
202 if ( myEditCurrentArgument == GroupPoints->LineEdit1 ) {
203 int aNbSel = GEOMBase::GetNameOfSelectedIObjects( selectedIO(), aName );
205 myObjects.length( 0 );
208 GEOMBase::ConvertListOfIOInListOfGO( selectedIO(), myObjects );
209 if ( !myObjects.length() )
212 aName = tr( "%1_objects" ).arg( aNbSel );
214 else if ( myEditCurrentArgument == GroupPoints->LineEdit2 ) {
215 if ( IObjectCount() != 1 ) {
216 myArgument = GEOM::GEOM_Object::_nil();
219 Standard_Boolean testResult = Standard_False;
220 myArgument = GEOMBase::ConvertIOinGEOMObject( firstIObject(), testResult );
221 if ( !testResult || CORBA::is_nil( myArgument ) )
223 aName = GEOMBase::GetName( myArgument );
225 myEditCurrentArgument->setText( aName );
231 //=================================================================================
232 // function : LineEditReturnPressed()
234 //=================================================================================
235 void TransformationGUI_MirrorDlg::LineEditReturnPressed()
237 QLineEdit* send = (QLineEdit*)sender();
238 if ( send == GroupPoints->LineEdit1 ||
239 send == GroupPoints->LineEdit2 ) {
240 myEditCurrentArgument = send;
241 GEOMBase_Skeleton::LineEditReturnPressed();
246 //=================================================================================
247 // function : SetEditCurrentArgument()
249 //=================================================================================
250 void TransformationGUI_MirrorDlg::SetEditCurrentArgument()
252 QPushButton* send = (QPushButton*)sender();
254 if ( send == GroupPoints->PushButton1 ) {
255 myEditCurrentArgument = GroupPoints->LineEdit1;
258 else if ( send == GroupPoints->PushButton2 ) {
259 myEditCurrentArgument = GroupPoints->LineEdit2;
260 switch ( getConstructorId() ) {
262 globalSelection( GEOM_POINT );
265 globalSelection( GEOM_LINE );
268 globalSelection( GEOM_PLANE );
273 myEditCurrentArgument->setFocus();
274 SelectionIntoArgument();
278 //=================================================================================
279 // function : ActivateThisDialog()
281 //=================================================================================
282 void TransformationGUI_MirrorDlg::ActivateThisDialog()
284 GEOMBase_Skeleton::ActivateThisDialog();
285 connect( myGeomGUI->getApp()->selectionMgr(),
286 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
287 ConstructorsClicked( getConstructorId() );
291 //=================================================================================
292 // function : enterEvent()
293 // purpose : when mouse enter onto the QWidget
294 //=================================================================================
295 void TransformationGUI_MirrorDlg::enterEvent( QEvent* )
297 if ( !mainFrame()->GroupConstructors->isEnabled() )
298 ActivateThisDialog();
302 //=================================================================================
303 // function : createOperation
305 //=================================================================================
306 GEOM::GEOM_IOperations_ptr TransformationGUI_MirrorDlg::createOperation()
308 return getGeomEngine()->GetITransformOperations( getStudyId() );
312 //=================================================================================
313 // function : isValid
315 //=================================================================================
316 bool TransformationGUI_MirrorDlg::isValid( QString& /*msg*/ )
318 return !( myObjects.length() == 0 || myArgument->_is_nil() );
322 //=================================================================================
323 // function : execute
325 //=================================================================================
326 bool TransformationGUI_MirrorDlg::execute( ObjectList& objects )
329 bool toCreateCopy = IsPreview() || GroupPoints->CheckButton1->isChecked();
331 GEOM::GEOM_Object_var anObj;
333 switch ( getConstructorId() ) {
336 if ( toCreateCopy ) {
337 for ( int i = 0; i < myObjects.length(); i++ ) {
338 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->MirrorPointCopy( myObjects[i], myArgument );
339 if ( !anObj->_is_nil() )
340 objects.push_back( anObj._retn() );
344 for ( int i = 0; i < myObjects.length(); i++ ) {
345 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->MirrorPoint( myObjects[i], myArgument );
346 if ( !anObj->_is_nil() )
347 objects.push_back( anObj._retn() );
355 if ( toCreateCopy ) {
356 for ( int i = 0; i < myObjects.length(); i++ ) {
357 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->MirrorAxisCopy( myObjects[i], myArgument );
358 if ( !anObj->_is_nil() )
359 objects.push_back( anObj._retn() );
363 for ( int i = 0; i < myObjects.length(); i++ ) {
364 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->MirrorAxis( myObjects[i], myArgument );
365 if ( !anObj->_is_nil() )
366 objects.push_back( anObj._retn() );
374 if ( toCreateCopy ) {
375 for ( int i = 0; i < myObjects.length(); i++ ) {
376 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->MirrorPlaneCopy( myObjects[i], myArgument );
377 if ( !anObj->_is_nil() )
378 objects.push_back( anObj._retn() );
382 for ( int i = 0; i < myObjects.length(); i++ ) {
383 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->MirrorPlane( myObjects[i], myArgument );
384 if ( !anObj->_is_nil() )
385 objects.push_back( anObj._retn() );
396 //=================================================================================
397 // function : closeEvent
399 //=================================================================================
400 void TransformationGUI_MirrorDlg::closeEvent( QCloseEvent* e )
402 GEOMBase_Skeleton::closeEvent( e );
406 //=================================================================================
407 // function : CreateCopyModeChanged()
409 //=================================================================================
410 void TransformationGUI_MirrorDlg::CreateCopyModeChanged( bool isCreateCopy )
412 mainFrame()->GroupBoxName->setEnabled( isCreateCopy );