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"
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 <TopoDS_Shape.hxx>
38 #include <TopoDS_Edge.hxx>
41 #include <TColStd_IndexedMapOfInteger.hxx>
42 #include <TopTools_IndexedMapOfShape.hxx>
44 #include <GEOMImpl_Types.hxx>
46 //=================================================================================
47 // class : TransformationGUI_MirrorDlg()
48 // purpose : Constructs a TransformationGUI_MirrorDlg which is a child of 'parent', with the
49 // name 'name' and widget flags set to 'f'.
50 // The dialog will by default be modeless, unless you set 'modal' to
51 // TRUE to construct a modal dialog.
52 //=================================================================================
53 TransformationGUI_MirrorDlg::TransformationGUI_MirrorDlg( GeometryGUI* theGeometryGUI, QWidget* parent,
54 bool modal, Qt::WindowFlags fl )
55 : GEOMBase_Skeleton( theGeometryGUI, parent, modal, fl )
57 QPixmap image0( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_MIRROR_POINT" ) ) );
58 QPixmap image1( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_MIRROR_AXE" ) ) );
59 QPixmap image2( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_MIRROR_PLANE" ) ) );
60 QPixmap image3( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
62 setWindowTitle( tr( "GEOM_MIRROR_TITLE" ) );
64 /***************************************************************/
65 mainFrame()->GroupConstructors->setTitle( tr( "GEOM_MIRROR" ) );
66 mainFrame()->RadioButton1->setIcon( image0 );
67 mainFrame()->RadioButton2->setIcon( image1 );
68 mainFrame()->RadioButton3->setIcon( image2 );
70 GroupPoints = new DlgRef_2Sel1Spin2Check( centralWidget() );
71 GroupPoints->SpinBox_DX->hide();
72 GroupPoints->TextLabel3->hide();
73 GroupPoints->CheckButton2->hide();
74 GroupPoints->GroupBox1->setTitle( tr( "GEOM_ARGUMENTS" ) );
75 GroupPoints->TextLabel1->setText( tr( "GEOM_OBJECTS" ) );
76 GroupPoints->TextLabel2->setText( tr( "GEOM_POINT_MIRROR" ) );
77 GroupPoints->TextLabel2->setFixedWidth( 74 );
78 GroupPoints->PushButton1->setIcon( image3 );
79 GroupPoints->PushButton2->setIcon( image3 );
80 GroupPoints->CheckButton1->setText( tr( "GEOM_CREATE_COPY" ) );
82 QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
83 layout->setMargin( 0 ); layout->setSpacing( 6 );
84 layout->addWidget( GroupPoints );
85 /***************************************************************/
87 setHelpFileName( "mirror_operation_page.html" );
93 //=================================================================================
94 // function : ~TransformationGUI_MirrorDlg()
95 // purpose : Destroys the object and frees any allocated resources
96 //=================================================================================
97 TransformationGUI_MirrorDlg::~TransformationGUI_MirrorDlg()
99 /* no need to delete child widgets, Qt does it all for us */
103 //=================================================================================
106 //=================================================================================
107 void TransformationGUI_MirrorDlg::Init()
110 myEditCurrentArgument = GroupPoints->LineEdit1;
111 GroupPoints->LineEdit1->setReadOnly( true );
112 GroupPoints->LineEdit2->setReadOnly( true );
114 myArgument = GEOM::GEOM_Object::_nil();
116 // Activate Create a Copy mode
117 GroupPoints->CheckButton1->setChecked( true );
118 CreateCopyModeChanged( true );
120 /* signals and slots connections */
121 connect( buttonOk(), SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
122 connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
124 connect( this, SIGNAL( constructorsClicked( int ) ), this, SLOT( ConstructorsClicked( int ) ) );
126 connect( GroupPoints->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
127 connect( GroupPoints->PushButton2, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
129 connect( GroupPoints->LineEdit1, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
130 connect( GroupPoints->LineEdit2, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
132 connect( GroupPoints->CheckButton1, SIGNAL( toggled( bool ) ), this, SLOT( CreateCopyModeChanged( bool ) ) );
134 connect( myGeomGUI->getApp()->selectionMgr(),
135 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
137 initName( tr( "GEOM_MIRROR" ) );
139 ConstructorsClicked( 0 );
143 //=================================================================================
144 // function : ConstructorsClicked()
145 // purpose : Radio button management
146 //=================================================================================
147 void TransformationGUI_MirrorDlg::ConstructorsClicked( int constructorId )
149 disconnect( myGeomGUI->getApp()->selectionMgr(), 0, this, 0 );
152 myEditCurrentArgument = GroupPoints->LineEdit1;
153 GroupPoints->LineEdit2->clear();
154 myArgument = GEOM::GEOM_Object::_nil();
156 switch ( constructorId ) {
157 case 0: /* mirror an object by point */
158 GroupPoints->TextLabel2->setText( tr( "GEOM_POINT_MIRROR" ) );
160 case 1: /* mirror an object by axe */
161 GroupPoints->TextLabel2->setText( tr( "GEOM_AXE_MIRROR" ) );
163 case 2: /* mirror an object by plane */
164 GroupPoints->TextLabel2->setText( tr( "GEOM_PLANE_MIRROR" ) );
168 connect( myGeomGUI->getApp()->selectionMgr(),
169 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
174 //=================================================================================
175 // function : ClickOnOk()
177 //=================================================================================
178 void TransformationGUI_MirrorDlg::ClickOnOk()
180 if ( ClickOnApply() )
185 //=================================================================================
186 // function : ClickOnApply()
188 //=================================================================================
189 bool TransformationGUI_MirrorDlg::ClickOnApply()
191 if ( !onAccept( GroupPoints->CheckButton1->isChecked() ) )
195 ConstructorsClicked( getConstructorId() );
200 //=================================================================================
201 // function : SelectionIntoArgument()
202 // purpose : Called when selection has changed
203 //=================================================================================
204 void TransformationGUI_MirrorDlg::SelectionIntoArgument()
206 myEditCurrentArgument->setText( "" );
209 if ( myEditCurrentArgument == GroupPoints->LineEdit1 ) {
210 int aNbSel = GEOMBase::GetNameOfSelectedIObjects( selectedIO(), aName );
212 myObjects.length( 0 );
215 GEOMBase::ConvertListOfIOInListOfGO( selectedIO(), myObjects );
216 if ( !myObjects.length() )
219 aName = tr( "%1_objects" ).arg( aNbSel );
221 else if ( myEditCurrentArgument == GroupPoints->LineEdit2 ) {
222 if ( IObjectCount() != 1 ) {
223 myArgument = GEOM::GEOM_Object::_nil();
226 Standard_Boolean testResult = Standard_False;
227 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject( firstIObject(), testResult );
228 myArgument = aSelectedObject;
229 if ( !testResult || CORBA::is_nil( myArgument ) )
232 aName = GEOMBase::GetName( aSelectedObject );
234 if ( testResult && !aSelectedObject->_is_nil() ) {
236 if ( GEOMBase::GetShape( aSelectedObject, aShape, TopAbs_SHAPE ) && !aShape.IsNull() ) {
237 TopAbs_ShapeEnum aNeedType = TopAbs_VERTEX;
238 if ( getConstructorId() == 1 )
239 aNeedType = TopAbs_EDGE;
240 else if ( getConstructorId() == 2 )
241 aNeedType = TopAbs_FACE;
243 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
244 TColStd_IndexedMapOfInteger aMap;
245 aSelMgr->GetIndexes( firstIObject(), aMap );
246 if ( aMap.Extent() == 1 ) {
247 int anIndex = aMap( 1 );
248 if ( aNeedType == TopAbs_VERTEX )
249 aName += QString( ":vertex_%1" ).arg( anIndex );
251 aName += QString( ":edge_%1" ).arg( anIndex );
253 //Find SubShape Object in Father
254 GEOM::GEOM_Object_var aFindedObject = findObjectInFather( aSelectedObject, aName );
256 if ( aFindedObject == GEOM::GEOM_Object::_nil() ) { // Object not found in study
257 GEOM::GEOM_IShapesOperations_var aShapesOp =
258 getGeomEngine()->GetIShapesOperations( getStudyId() );
259 myArgument = aShapesOp->GetSubShape( aSelectedObject, anIndex );
262 myArgument = aFindedObject; // get Object from study
266 if ( aShape.ShapeType() != aNeedType ) {
267 myArgument = GEOM::GEOM_Object::_nil();
274 myEditCurrentArgument->setText( aName );
280 //=================================================================================
281 // function : LineEditReturnPressed()
283 //=================================================================================
284 void TransformationGUI_MirrorDlg::LineEditReturnPressed()
286 QLineEdit* send = (QLineEdit*)sender();
287 if ( send == GroupPoints->LineEdit1 ||
288 send == GroupPoints->LineEdit2 ) {
289 myEditCurrentArgument = send;
290 GEOMBase_Skeleton::LineEditReturnPressed();
295 //=================================================================================
296 // function : SetEditCurrentArgument()
298 //=================================================================================
299 void TransformationGUI_MirrorDlg::SetEditCurrentArgument()
301 QPushButton* send = (QPushButton*)sender();
304 if ( send == GroupPoints->PushButton1 ) {
305 myEditCurrentArgument = GroupPoints->LineEdit1;
307 else if ( send == GroupPoints->PushButton2 ) {
308 myEditCurrentArgument = GroupPoints->LineEdit2;
309 switch ( getConstructorId() ) {
311 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
314 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_EDGE );
317 globalSelection( GEOM_PLANE );
322 myEditCurrentArgument->setFocus();
323 SelectionIntoArgument();
327 //=================================================================================
328 // function : ActivateThisDialog()
330 //=================================================================================
331 void TransformationGUI_MirrorDlg::ActivateThisDialog()
333 GEOMBase_Skeleton::ActivateThisDialog();
334 connect( myGeomGUI->getApp()->selectionMgr(),
335 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
336 ConstructorsClicked( getConstructorId() );
340 //=================================================================================
341 // function : enterEvent()
342 // purpose : when mouse enter onto the QWidget
343 //=================================================================================
344 void TransformationGUI_MirrorDlg::enterEvent( QEvent* )
346 if ( !mainFrame()->GroupConstructors->isEnabled() )
347 ActivateThisDialog();
351 //=================================================================================
352 // function : createOperation
354 //=================================================================================
355 GEOM::GEOM_IOperations_ptr TransformationGUI_MirrorDlg::createOperation()
357 return getGeomEngine()->GetITransformOperations( getStudyId() );
361 //=================================================================================
362 // function : isValid
364 //=================================================================================
365 bool TransformationGUI_MirrorDlg::isValid( QString& /*msg*/ )
367 return !( myObjects.length() == 0 || myArgument->_is_nil() );
371 //=================================================================================
372 // function : execute
374 //=================================================================================
375 bool TransformationGUI_MirrorDlg::execute( ObjectList& objects )
378 bool toCreateCopy = IsPreview() || GroupPoints->CheckButton1->isChecked();
380 GEOM::GEOM_Object_var anObj;
382 switch ( getConstructorId() ) {
385 if ( toCreateCopy ) {
386 for ( int i = 0; i < myObjects.length(); i++ ) {
387 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->MirrorPointCopy( myObjects[i], myArgument );
388 if ( !anObj->_is_nil() )
389 objects.push_back( anObj._retn() );
393 for ( int i = 0; i < myObjects.length(); i++ ) {
394 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->MirrorPoint( myObjects[i], myArgument );
395 if ( !anObj->_is_nil() )
396 objects.push_back( anObj._retn() );
404 if ( toCreateCopy ) {
405 for ( int i = 0; i < myObjects.length(); i++ ) {
406 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->MirrorAxisCopy( myObjects[i], myArgument );
407 if ( !anObj->_is_nil() )
408 objects.push_back( anObj._retn() );
412 for ( int i = 0; i < myObjects.length(); i++ ) {
413 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->MirrorAxis( myObjects[i], myArgument );
414 if ( !anObj->_is_nil() )
415 objects.push_back( anObj._retn() );
423 if ( toCreateCopy ) {
424 for ( int i = 0; i < myObjects.length(); i++ ) {
425 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->MirrorPlaneCopy( myObjects[i], myArgument );
426 if ( !anObj->_is_nil() )
427 objects.push_back( anObj._retn() );
431 for ( int i = 0; i < myObjects.length(); i++ ) {
432 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->MirrorPlane( myObjects[i], myArgument );
433 if ( !anObj->_is_nil() )
434 objects.push_back( anObj._retn() );
445 //=================================================================================
446 // function : CreateCopyModeChanged()
448 //=================================================================================
449 void TransformationGUI_MirrorDlg::CreateCopyModeChanged( bool isCreateCopy )
451 mainFrame()->GroupBoxName->setEnabled( isCreateCopy );
454 //=================================================================================
455 // function : addSubshapeToStudy
456 // purpose : virtual method to add new SubObjects if local selection
457 //=================================================================================
458 void TransformationGUI_MirrorDlg::addSubshapesToStudy()
460 bool toCreateCopy = IsPreview() || GroupPoints->CheckButton1->isChecked();
461 if ( toCreateCopy ) {
462 QMap<QString, GEOM::GEOM_Object_var> objMap;
464 switch ( getConstructorId() ) {
466 objMap[GroupPoints->LineEdit2->text()] = myArgument;
469 objMap[GroupPoints->LineEdit2->text()] = myArgument;
474 addSubshapesToFather( objMap );