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 mainFrame()->GroupBoxPublish->show();
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( GroupPoints->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
129 connect( GroupPoints->PushButton2, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
131 connect( GroupPoints->LineEdit1, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
132 connect( GroupPoints->LineEdit2, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
134 connect( GroupPoints->CheckButton1, SIGNAL( toggled( bool ) ), this, SLOT( CreateCopyModeChanged( bool ) ) );
136 connect( myGeomGUI->getApp()->selectionMgr(),
137 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
139 initName( tr( "GEOM_MIRROR" ) );
141 ConstructorsClicked( 0 );
145 //=================================================================================
146 // function : ConstructorsClicked()
147 // purpose : Radio button management
148 //=================================================================================
149 void TransformationGUI_MirrorDlg::ConstructorsClicked( int constructorId )
151 disconnect( myGeomGUI->getApp()->selectionMgr(), 0, this, 0 );
154 myEditCurrentArgument = GroupPoints->LineEdit1;
155 GroupPoints->LineEdit2->clear();
156 myArgument = GEOM::GEOM_Object::_nil();
158 switch ( constructorId ) {
159 case 0: /* mirror an object by point */
160 GroupPoints->TextLabel2->setText( tr( "GEOM_POINT_MIRROR" ) );
162 case 1: /* mirror an object by axe */
163 GroupPoints->TextLabel2->setText( tr( "GEOM_AXE_MIRROR" ) );
165 case 2: /* mirror an object by plane */
166 GroupPoints->TextLabel2->setText( tr( "GEOM_PLANE_MIRROR" ) );
170 connect( myGeomGUI->getApp()->selectionMgr(),
171 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
176 //=================================================================================
177 // function : ClickOnOk()
179 //=================================================================================
180 void TransformationGUI_MirrorDlg::ClickOnOk()
182 if ( ClickOnApply() )
187 //=================================================================================
188 // function : ClickOnApply()
190 //=================================================================================
191 bool TransformationGUI_MirrorDlg::ClickOnApply()
193 if ( !onAccept( GroupPoints->CheckButton1->isChecked() ) )
197 ConstructorsClicked( getConstructorId() );
202 //=================================================================================
203 // function : SelectionIntoArgument()
204 // purpose : Called when selection has changed
205 //=================================================================================
206 void TransformationGUI_MirrorDlg::SelectionIntoArgument()
208 myEditCurrentArgument->setText( "" );
211 if ( myEditCurrentArgument == GroupPoints->LineEdit1 ) {
212 int aNbSel = GEOMBase::GetNameOfSelectedIObjects( selectedIO(), aName );
214 myObjects.length( 0 );
217 GEOMBase::ConvertListOfIOInListOfGO( selectedIO(), myObjects );
218 if ( !myObjects.length() )
221 aName = tr( "%1_objects" ).arg( aNbSel );
223 else if ( myEditCurrentArgument == GroupPoints->LineEdit2 ) {
224 if ( IObjectCount() != 1 ) {
225 myArgument = GEOM::GEOM_Object::_nil();
228 Standard_Boolean testResult = Standard_False;
229 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject( firstIObject(), testResult );
230 myArgument = aSelectedObject;
231 if ( !testResult || CORBA::is_nil( myArgument ) )
234 aName = GEOMBase::GetName( aSelectedObject );
236 if ( testResult && !aSelectedObject->_is_nil() ) {
238 if ( GEOMBase::GetShape( aSelectedObject, aShape, TopAbs_SHAPE ) && !aShape.IsNull() ) {
239 TopAbs_ShapeEnum aNeedType = TopAbs_VERTEX;
240 if ( getConstructorId() == 1 )
241 aNeedType = TopAbs_EDGE;
242 else if ( getConstructorId() == 2 )
243 aNeedType = TopAbs_FACE;
245 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
246 TColStd_IndexedMapOfInteger aMap;
247 aSelMgr->GetIndexes( firstIObject(), aMap );
248 if ( aMap.Extent() == 1 ) {
249 int anIndex = aMap( 1 );
250 if ( aNeedType == TopAbs_VERTEX )
251 aName += QString( ":vertex_%1" ).arg( anIndex );
253 aName += QString( ":edge_%1" ).arg( anIndex );
255 //Find SubShape Object in Father
256 GEOM::GEOM_Object_var aFindedObject = findObjectInFather( aSelectedObject, aName );
258 if ( aFindedObject == GEOM::GEOM_Object::_nil() ) { // Object not found in study
259 GEOM::GEOM_IShapesOperations_var aShapesOp =
260 getGeomEngine()->GetIShapesOperations( getStudyId() );
261 myArgument = aShapesOp->GetSubShape( aSelectedObject, anIndex );
264 myArgument = aFindedObject; // get Object from study
268 if ( aShape.ShapeType() != aNeedType ) {
269 myArgument = GEOM::GEOM_Object::_nil();
276 myEditCurrentArgument->setText( aName );
282 //=================================================================================
283 // function : LineEditReturnPressed()
285 //=================================================================================
286 void TransformationGUI_MirrorDlg::LineEditReturnPressed()
288 QLineEdit* send = (QLineEdit*)sender();
289 if ( send == GroupPoints->LineEdit1 ||
290 send == GroupPoints->LineEdit2 ) {
291 myEditCurrentArgument = send;
292 GEOMBase_Skeleton::LineEditReturnPressed();
297 //=================================================================================
298 // function : SetEditCurrentArgument()
300 //=================================================================================
301 void TransformationGUI_MirrorDlg::SetEditCurrentArgument()
303 QPushButton* send = (QPushButton*)sender();
306 if ( send == GroupPoints->PushButton1 ) {
307 myEditCurrentArgument = GroupPoints->LineEdit1;
309 else if ( send == GroupPoints->PushButton2 ) {
310 myEditCurrentArgument = GroupPoints->LineEdit2;
311 switch ( getConstructorId() ) {
313 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
316 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_EDGE );
319 globalSelection( GEOM_PLANE );
324 myEditCurrentArgument->setFocus();
325 SelectionIntoArgument();
329 //=================================================================================
330 // function : ActivateThisDialog()
332 //=================================================================================
333 void TransformationGUI_MirrorDlg::ActivateThisDialog()
335 GEOMBase_Skeleton::ActivateThisDialog();
336 connect( myGeomGUI->getApp()->selectionMgr(),
337 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
338 ConstructorsClicked( getConstructorId() );
342 //=================================================================================
343 // function : enterEvent()
344 // purpose : when mouse enter onto the QWidget
345 //=================================================================================
346 void TransformationGUI_MirrorDlg::enterEvent( QEvent* )
348 if ( !mainFrame()->GroupConstructors->isEnabled() )
349 ActivateThisDialog();
353 //=================================================================================
354 // function : createOperation
356 //=================================================================================
357 GEOM::GEOM_IOperations_ptr TransformationGUI_MirrorDlg::createOperation()
359 return getGeomEngine()->GetITransformOperations( getStudyId() );
363 //=================================================================================
364 // function : isValid
366 //=================================================================================
367 bool TransformationGUI_MirrorDlg::isValid( QString& /*msg*/ )
369 return !( myObjects.length() == 0 || myArgument->_is_nil() );
373 //=================================================================================
374 // function : execute
376 //=================================================================================
377 bool TransformationGUI_MirrorDlg::execute( ObjectList& objects )
380 bool toCreateCopy = IsPreview() || GroupPoints->CheckButton1->isChecked();
382 GEOM::GEOM_Object_var anObj;
384 switch ( getConstructorId() ) {
387 if ( toCreateCopy ) {
388 for ( int i = 0; i < myObjects.length(); i++ ) {
389 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->
390 MirrorPointCopy( myObjects[i], myArgument );
391 if ( !anObj->_is_nil() )
392 objects.push_back( anObj._retn() );
396 for ( int i = 0; i < myObjects.length(); i++ ) {
397 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->
398 MirrorPoint( myObjects[i], myArgument );
399 if ( !anObj->_is_nil() )
400 objects.push_back( anObj._retn() );
408 if ( toCreateCopy ) {
409 for ( int i = 0; i < myObjects.length(); i++ ) {
410 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->
411 MirrorAxisCopy( myObjects[i], myArgument );
412 if ( !anObj->_is_nil() )
413 objects.push_back( anObj._retn() );
417 for ( int i = 0; i < myObjects.length(); i++ ) {
418 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->
419 MirrorAxis( myObjects[i], myArgument );
420 if ( !anObj->_is_nil() )
421 objects.push_back( anObj._retn() );
429 if ( toCreateCopy ) {
430 for ( int i = 0; i < myObjects.length(); i++ ) {
431 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->MirrorPlaneCopy( myObjects[i], myArgument );
432 if ( !anObj->_is_nil() )
433 objects.push_back( anObj._retn() );
437 for ( int i = 0; i < myObjects.length(); i++ ) {
438 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->MirrorPlane( myObjects[i], myArgument );
439 if ( !anObj->_is_nil() )
440 objects.push_back( anObj._retn() );
451 //=================================================================================
452 // function : restoreSubShapes
454 //=================================================================================
455 void TransformationGUI_MirrorDlg::restoreSubShapes( SALOMEDS::Study_ptr theStudy,
456 SALOMEDS::SObject_ptr theSObject )
458 if ( mainFrame()->CheckBoxRestoreSS->isChecked() ) {
459 // empty list of arguments means that all arguments should be restored
460 getGeomEngine()->RestoreSubShapesSO( theStudy, theSObject, GEOM::ListOfGO(),
461 /*theFindMethod=*/GEOM::FSM_Transformed,
462 /*theInheritFirstArg=*/true );
466 //=================================================================================
467 // function : CreateCopyModeChanged()
469 //=================================================================================
470 void TransformationGUI_MirrorDlg::CreateCopyModeChanged( bool isCreateCopy )
472 mainFrame()->GroupBoxName->setEnabled( isCreateCopy );
475 //=================================================================================
476 // function : addSubshapeToStudy
477 // purpose : virtual method to add new SubObjects if local selection
478 //=================================================================================
479 void TransformationGUI_MirrorDlg::addSubshapesToStudy()
481 bool toCreateCopy = IsPreview() || GroupPoints->CheckButton1->isChecked();
482 if ( toCreateCopy ) {
483 QMap<QString, GEOM::GEOM_Object_var> objMap;
485 switch ( getConstructorId() ) {
487 objMap[GroupPoints->LineEdit2->text()] = myArgument;
490 objMap[GroupPoints->LineEdit2->text()] = myArgument;
495 addSubshapesToFather( objMap );