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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : RepairGUI_FreeFacesDlg.cxx
30 #include "RepairGUI_FreeFacesDlg.h"
32 #include "QAD_Desktop.h"
33 #include "QAD_WaitCursor.h"
35 #include "SALOME_ListIteratorOfListIO.hxx"
37 #include "GEOMImpl_Types.hxx"
38 #include <TopTools_IndexedMapOfShape.hxx>
41 #include "GeometryGUI.h"
42 #include "GEOM_Displayer.h"
43 #include "SALOMEGUI_QtCatchCorbaException.hxx"
44 #include "SALOME_Selection.h"
45 #include "SALOME_Prs.h"
48 #include <qlineedit.h>
51 #include <qgroupbox.h>
52 #include <qpushbutton.h>
58 //=================================================================================
59 // class : RepairGUI_FreeFacesDlg()
60 // purpose : Constructs a RepairGUI_FreeFacesDlg which is a child of 'parent', with the
61 // name 'name' and widget flags set to 'f'.
62 // The dialog will by default be modeless, unless you set 'modal' to
63 // TRUE to construct a modal dialog.
64 //=================================================================================
65 RepairGUI_FreeFacesDlg::RepairGUI_FreeFacesDlg(QWidget* parent, const char* name, SALOME_Selection* theSelection, bool modal, WFlags fl)
66 :QDialog( parent, "RepairGUI_FreeBoundDlg", false,
67 WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu | WDestructiveClose )
71 setSizeGripEnabled( TRUE );
72 QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_SELECT")));
74 setCaption(tr("GEOM_FREE_FACES_TITLE"));
76 /***************************************************************/
78 QGroupBox* aMainGrp = new QGroupBox( 1, Qt::Horizontal, tr( "GEOM_SELECTED_SHAPE" ), this );
81 QGroupBox* aSelGrp = new QGroupBox( 1, Qt::Vertical, aMainGrp );
83 aSelGrp->setInsideMargin( 0 );
84 aSelGrp->setFrameStyle( QFrame::NoFrame );
85 new QLabel( tr( "GEOM_OBJECT" ), aSelGrp );
86 mySelBtn = new QPushButton( aSelGrp );
87 mySelBtn->setPixmap( image1 );
88 myEdit = new QLineEdit( aSelGrp );
89 myEdit->setReadOnly( true );
90 myEdit->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
91 myEdit->setMinimumWidth( MIN_WIDTH );
93 QFrame* aFrame = new QFrame( this );
94 aFrame->setFrameStyle( QFrame::Box | QFrame::Sunken );
95 QPushButton* aCloseBtn = new QPushButton( tr( "GEOM_BUT_CLOSE" ), aFrame );
96 QHBoxLayout* aBtnLay = new QHBoxLayout( aFrame, MARGIN, SPACING );
97 aBtnLay->addItem( new QSpacerItem( 0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum ) );
98 aBtnLay->addWidget( aCloseBtn );
99 aBtnLay->addItem( new QSpacerItem( 0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum ) );
101 QVBoxLayout* aLay = new QVBoxLayout( this );
102 aLay->setSpacing( SPACING );
103 aLay->setMargin( MARGIN );
104 aLay->addWidget( aMainGrp );
105 aLay->addItem( new QSpacerItem( 0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum ) );
106 aLay->addWidget( aFrame );
108 connect( aCloseBtn, SIGNAL( clicked() ), SLOT( onClose() ) );
109 connect( mySelBtn, SIGNAL( clicked() ),
110 this, SLOT ( onSetEditCurrentArgument() ) );
111 /***************************************************************/
113 Init( theSelection );
117 //=================================================================================
118 // function : ~RepairGUI_FreeFacesDlg()
119 // purpose : Destroys the object and frees any allocated resources
120 //=================================================================================
121 RepairGUI_FreeFacesDlg::~RepairGUI_FreeFacesDlg()
126 //=================================================================================
127 // function : onClose
128 // purpose : SLOT. Called when "close" button pressed. Close dialog
129 //=================================================================================
130 void RepairGUI_FreeFacesDlg::onClose()
133 disconnect( mySelection, 0, this, 0 );
134 GeometryGUI::GetGeomGUI()->SetActiveDialogBox( 0 );
139 //=================================================================================
140 // function : onDeactivate
141 // purpose : Deactivate this dialog
142 //=================================================================================
143 void RepairGUI_FreeFacesDlg::onDeactivate()
147 disconnect( mySelection, 0, this, 0 );
148 GeometryGUI::GetGeomGUI()->SetActiveDialogBox( 0 );
151 //=================================================================================
152 // function : onActivate
153 // purpose : Activate this dialog
154 //=================================================================================
155 void RepairGUI_FreeFacesDlg::onActivate()
157 GeometryGUI::GetGeomGUI()->EmitSignalDeactivateDialog();
159 GeometryGUI::GetGeomGUI()->SetActiveDialogBox( this );
160 connect( mySelection, SIGNAL( currentSelectionChanged() ), SLOT ( onSelectionDone() ) );
164 //=================================================================================
167 //=================================================================================
168 void RepairGUI_FreeFacesDlg::Init(SALOME_Selection* theSel)
170 myObj = GEOM::GEOM_Object::_nil();
172 mySelection = theSel;
174 /* signals and slots connections */
175 GeometryGUI* aGeomGUI = GeometryGUI::GetGeomGUI();
176 connect( aGeomGUI, SIGNAL( SignalDeactivateActiveDialog() ), SLOT ( onDeactivate() ) );
177 connect( mySelection, SIGNAL( currentSelectionChanged() ), SLOT ( onSelectionDone() ) );
183 //=================================================================================
184 // function : onSelectionDone
185 // purpose : SLOT. Called when selection changed.
186 //=================================================================================
187 void RepairGUI_FreeFacesDlg::onSelectionDone()
190 if( mySelection->IObjectCount() != 1 )
192 myEdit->setText( "" );
196 Standard_Boolean isOk = Standard_False;
197 GEOM::GEOM_Object_var anObj =
198 GEOMBase::ConvertIOinGEOMObject( mySelection->firstIObject(), isOk );
200 if ( !isOk || anObj->_is_nil() || !GEOMBase::IsShape( anObj ) )
202 myEdit->setText( "" );
208 displayPreview( false, true, true, 3 );
212 //=================================================================================
213 // function : enterEvent()
214 // purpose : Mouse enter onto the dialog to activate it
215 //=================================================================================
216 void RepairGUI_FreeFacesDlg::enterEvent(QEvent* e)
221 //=================================================================================
222 // function : activateSelection
223 // purpose : activate selection of faces, shells, and solids
224 //=================================================================================
225 void RepairGUI_FreeFacesDlg::activateSelection()
227 TColStd_MapOfInteger aMap;
228 aMap.Add( GEOM_SOLID );
229 aMap.Add( GEOM_COMPOUND );
230 globalSelection( aMap );
233 //=================================================================================
234 // function : closeEvent()
236 //=================================================================================
237 void RepairGUI_FreeFacesDlg::closeEvent(QCloseEvent* e)
242 //=================================================================================
243 // function : createOperation
245 //=================================================================================
246 GEOM::GEOM_IOperations_ptr RepairGUI_FreeFacesDlg::createOperation()
248 return getGeomEngine()->GetIShapesOperations( getStudyId() );
251 //=================================================================================
252 // function : isValid
254 //=================================================================================
255 bool RepairGUI_FreeFacesDlg::isValid( QString& msg )
257 return !myObj->_is_nil() ;
260 //=================================================================================
261 // function : execute
263 //=================================================================================
264 bool RepairGUI_FreeFacesDlg::execute( ObjectList& objects )
266 bool aResult = false;
267 GEOM::ListOfLong_var aFaceLst =
268 GEOM::GEOM_IShapesOperations::_narrow( getOperation() )->GetFreeFacesIDs( myObj );
269 TopoDS_Shape aSelShape;
271 TopTools_IndexedMapOfShape anIndices;
272 if ( !myObj->_is_nil() && GEOMBase::GetShape( myObj, aSelShape ) )
274 myEdit->setText( GEOMBase::GetName( myObj ) );
276 if ( !isValid( aMess ) )
278 erasePreview( true );
282 TopExp::MapShapes( aSelShape, anIndices);
283 SALOME_Prs* aPrs = 0;
286 for ( int i = 0, n = aFaceLst->length(); i < n; i++ )
288 aFace = anIndices.FindKey( aFaceLst[i] );
291 getDisplayer()->SetColor( Quantity_NOC_RED );
292 getDisplayer()->SetToActivate( false );
293 aPrs = !aFace.IsNull() ? getDisplayer()->BuildPrs( aFace ) : 0;
295 displayPreview( aPrs, true );
297 catch( const SALOME::SALOME_Exception& e )
299 QtCatchCorbaException( e );
306 //================================================================
307 // Function : getDisplayer
309 //================================================================
310 GEOM_Displayer* RepairGUI_FreeFacesDlg::getDisplayer()
313 myDisplayer = new GEOM_Displayer();
317 //=================================================================================
318 // function : SetEditCurrentArgument
320 //=================================================================================
321 void RepairGUI_FreeFacesDlg::onSetEditCurrentArgument()