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 : MeasureGUI_CheckCompoundOfBlocksDlg.cxx
23 // Author : Vladimir KLYACHIN, Open CASCADE S.A.S. (vladimir.klyachin@opencascade.com)
26 #include "MeasureGUI_CheckCompoundOfBlocksDlg.h"
27 #include "MeasureGUI_Widgets.h"
29 #include <SUIT_Session.h>
30 #include <SUIT_ResourceMgr.h>
31 #include <LightApp_SelectionMgr.h>
32 #include <SalomeApp_Tools.h>
33 #include <SalomeApp_Application.h>
35 #include <TopTools_IndexedMapOfShape.hxx>
37 #include <TColStd_MapOfInteger.hxx>
39 #include <GEOM_DlgRef.h>
40 #include <GeometryGUI.h>
42 #include <GEOMImpl_Types.hxx>
44 #define TEXTEDIT_FONT_FAMILY "Courier"
45 #define TEXTEDIT_FONT_SIZE 11
47 //=================================================================================
48 // class : MeasureGUI_CheckCompoundOfBlocksDlg()
49 // purpose : Constructs a MeasureGUI_CheckCompoundOfBlocksDlg which is a child of 'parent', with the
50 // name 'name' and widget flags set to 'f'.
51 // The dialog will by default be modeless, unless you set 'modal' to
52 // true to construct a modal dialog.
53 //=================================================================================
54 MeasureGUI_CheckCompoundOfBlocksDlg::MeasureGUI_CheckCompoundOfBlocksDlg( GeometryGUI* GUI, QWidget* parent )
55 : GEOMBase_Skeleton( GUI, parent, false )
57 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
58 QPixmap image0( aResMgr->loadPixmap( "GEOM", tr( "ICON_DLG_CHECK_COMPOUND_OF_BLOCKS" ) ) );
59 QPixmap image1( aResMgr->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
61 setWindowTitle( tr( "GEOM_CHECK_BLOCKS_COMPOUND" ) );
63 /***************************************************************/
64 mainFrame()->GroupConstructors->setTitle( tr( "GEOM_CHECK_BLOCKS_COMPOUND" ) );
65 mainFrame()->RadioButton1->setIcon( image0 );
66 mainFrame()->RadioButton2->setAttribute( Qt::WA_DeleteOnClose );
67 mainFrame()->RadioButton2->close();
68 mainFrame()->RadioButton3->setAttribute( Qt::WA_DeleteOnClose );
69 mainFrame()->RadioButton3->close();
71 myGrp = new MeasureGUI_1Sel1TextView2ListBox( centralWidget() );
72 myGrp->GroupBox1->setTitle( tr( "GEOM_CHECK_INFOS" ) );
73 myGrp->TextLabel1->setText( tr( "GEOM_OBJECT" ) );
75 myGrp->TextView1->setReadOnly( true );
76 QFont aFont( TEXTEDIT_FONT_FAMILY, TEXTEDIT_FONT_SIZE );
77 aFont.setStyleHint( QFont::TypeWriter, QFont::PreferAntialias );
78 myGrp->TextView1->setFont( aFont );
80 myGrp->PushButton1->setIcon( image1 );
81 myGrp->LineEdit1->setReadOnly( true );
83 myGrp->TextLabel2->setText( tr( "GEOM_CHECK_BLOCKS_COMPOUND_ERRORS" ) );
84 myGrp->TextLabel3->setText( tr( "GEOM_CHECK_BLOCKS_COMPOUND_SUBSHAPES" ) );
86 myGrp->ListBox2->setSelectionMode( QAbstractItemView::ExtendedSelection );
88 QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
89 layout->setMargin( 0 ); layout->setSpacing( 6 );
90 layout->addWidget( myGrp );
92 connect( myGrp->ListBox1, SIGNAL( itemSelectionChanged() ), SLOT( onErrorsListSelectionChanged() ) );
93 connect( myGrp->ListBox2, SIGNAL( itemSelectionChanged() ), SLOT( onSubShapesListSelectionChanged() ) );
95 /***************************************************************/
97 myHelpFileName = "files/salome2_sp3_measuregui_functions.htm#Check_comp_blocks";
103 //=================================================================================
104 // function : ~MeasureGUI_CheckCompoundOfBlocksDlg()
105 // purpose : Destroys the object and frees any allocated resources
106 //=================================================================================
107 MeasureGUI_CheckCompoundOfBlocksDlg::~MeasureGUI_CheckCompoundOfBlocksDlg()
111 //=================================================================================
114 //=================================================================================
115 void MeasureGUI_CheckCompoundOfBlocksDlg::Init()
117 myEditCurrentArgument = myGrp->LineEdit1;
119 // signals and slots connections
120 connect( buttonOk(), SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
121 connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
123 connect( myGrp->LineEdit1, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
124 connect( myGrp->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
126 connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
127 this, SLOT( SelectionIntoArgument() ) );
129 initName( tr( "GEOM_BLOCKS_COMPOUND") );
130 buttonOk()->setEnabled( false );
131 buttonApply()->setEnabled( false );
133 SelectionIntoArgument();
136 //=================================================================================
137 // function : ClickOnOk()
139 //=================================================================================
140 void MeasureGUI_CheckCompoundOfBlocksDlg::ClickOnOk()
142 if ( ClickOnApply() )
146 //=================================================================================
147 // function : ClickOnApply()
149 //=================================================================================
150 bool MeasureGUI_CheckCompoundOfBlocksDlg::ClickOnApply()
159 //=================================================================================
160 // function : SelectionIntoArgument
162 //=================================================================================
163 void MeasureGUI_CheckCompoundOfBlocksDlg::SelectionIntoArgument()
166 myObj = GEOM::GEOM_Object::_nil();
168 if ( IObjectCount() != 1 ) {
169 myGrp->LineEdit1->setText( "" );
174 Standard_Boolean testResult = Standard_False;
175 GEOM::GEOM_Object_var aSelectedObject =
176 GEOMBase::ConvertIOinGEOMObject( firstIObject(), testResult );
178 if ( !testResult || aSelectedObject->_is_nil() ) {
179 myGrp->LineEdit1->setText( "" );
184 myObj = aSelectedObject;
185 myGrp->LineEdit1->setText( GEOMBase::GetName( myObj ) );
190 //=================================================================================
191 // function : SetEditCurrentArgument
193 //=================================================================================
194 void MeasureGUI_CheckCompoundOfBlocksDlg::SetEditCurrentArgument()
196 myGrp->LineEdit1->setFocus();
197 myEditCurrentArgument = myGrp->LineEdit1;
198 SelectionIntoArgument();
201 //=================================================================================
202 // function : LineEditReturnPressed()
204 //=================================================================================
205 void MeasureGUI_CheckCompoundOfBlocksDlg::LineEditReturnPressed()
207 QLineEdit* send = (QLineEdit*)sender();
208 if ( send == myGrp->LineEdit1 ) {
209 myEditCurrentArgument = myGrp->LineEdit1;
210 GEOMBase_Skeleton::LineEditReturnPressed();
214 //=================================================================================
215 // function : ActivateThisDialog()
217 //=================================================================================
218 void MeasureGUI_CheckCompoundOfBlocksDlg::ActivateThisDialog()
220 GEOMBase_Skeleton::ActivateThisDialog();
222 LightApp_SelectionMgr* aSel = myGeomGUI->getApp()->selectionMgr();
224 connect( aSel, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
230 //=================================================================================
231 // function : getBCErrors
233 //=================================================================================
234 bool MeasureGUI_CheckCompoundOfBlocksDlg::getBCErrors( bool& theIsCompoundOfBlocks,
235 GEOM::GEOM_IBlocksOperations::BCErrors& theErrors)
237 if ( myObj->_is_nil() )
241 GEOM::GEOM_IBlocksOperations::BCErrors_var aErrs;
242 theIsCompoundOfBlocks =
243 GEOM::GEOM_IBlocksOperations::_narrow( getOperation() )->CheckCompoundOfBlocks( myObj, aErrs );
246 catch ( const SALOME::SALOME_Exception& e ) {
247 SalomeApp_Tools::QtCatchCorbaException( e );
251 return getOperation()->IsDone();
255 //=================================================================================
256 // function : processObject
258 //=================================================================================
259 void MeasureGUI_CheckCompoundOfBlocksDlg::processObject()
262 bool isCompoundOfBlocks;
263 GEOM::GEOM_IBlocksOperations::BCErrors aErrs;
264 if ( !getBCErrors( isCompoundOfBlocks, aErrs ) ) {
265 myGrp->TextView1->setText( aMsg );
266 myGrp->ListBox1->clear();
267 myGrp->ListBox2->clear();
272 if ( isCompoundOfBlocks ) {
273 aMsg += tr( "GEOM_CHECK_BLOCKS_COMPOUND_HAS_NO_ERRORS" );
274 buttonOk()->setEnabled( false );
275 buttonApply()->setEnabled( false );
278 aMsg += tr( "GEOM_CHECK_BLOCKS_COMPOUND_HAS_ERRORS" );
279 buttonOk()->setEnabled( true );
280 buttonApply()->setEnabled( true );
282 myGrp->TextView1->setText( aMsg );
284 QStringList aErrList;
285 QString aErrStr( "" );
286 QString aConSfx( " # " );
287 QString aGluedSfx( " # " );
290 for ( int i = 0, n = aErrs.length(); i < n; i++ ) {
292 switch ( aErrs[i].error ) {
293 case GEOM::GEOM_IBlocksOperations::NOT_BLOCK :
294 aErrStr = "Not a Block";
296 case GEOM::GEOM_IBlocksOperations::EXTRA_EDGE :
297 aErrStr = "Extra Edge";
299 case GEOM::GEOM_IBlocksOperations::INVALID_CONNECTION :
300 aErrStr = "Invalid Connection";
302 aErrStr += QString::number( aConNum );
305 case GEOM::GEOM_IBlocksOperations::NOT_CONNECTED :
306 aErrStr = "Not Connected";
308 case GEOM::GEOM_IBlocksOperations::NOT_GLUED :
309 aErrStr = "Not Glued";
310 aErrStr += aGluedSfx;
311 aErrStr += QString::number( aGluedNum );
318 if ( !aErrStr.isEmpty() )
319 aErrList.append( aErrStr );
322 myGrp->ListBox1->clear();
323 myGrp->ListBox2->clear();
324 myGrp->ListBox1->addItems( aErrList );
327 //=================================================================================
328 // function : createOperation
330 //=================================================================================
331 GEOM::GEOM_IOperations_ptr MeasureGUI_CheckCompoundOfBlocksDlg::createOperation()
333 return getGeomEngine()->GetIBlocksOperations( getStudyId() );
336 //=================================================================================
337 // function : onErrorsListSelectionChanged
339 //=================================================================================
340 void MeasureGUI_CheckCompoundOfBlocksDlg::onErrorsListSelectionChanged()
343 int aCurItem = myGrp->ListBox1->currentRow();
346 bool isCompoundOfBlocks;
347 GEOM::GEOM_IBlocksOperations::BCErrors aErrs;
348 if ( !getBCErrors( isCompoundOfBlocks, aErrs ) ) {
349 myGrp->TextView1->setText( "" );
350 myGrp->ListBox1->clear();
351 myGrp->ListBox2->clear();
355 GEOM::GEOM_IBlocksOperations::BCError aErr = aErrs[aCurItem];
356 GEOM::ListOfLong aObjLst = aErr.incriminated;
357 TopoDS_Shape aSelShape;
358 TopoDS_Shape aSubShape;
359 TopTools_IndexedMapOfShape anIndices;
360 QStringList aSubShapeList;
361 QString aSubShapeName( "" );
362 Standard_CString aTypeString;
363 if ( !myObj->_is_nil() && GEOMBase::GetShape( myObj, aSelShape ) ) {
364 TopExp::MapShapes( aSelShape, anIndices);
365 for ( int i = 0, n = aObjLst.length(); i < n; i++ ) {
367 aSubShape = anIndices.FindKey(aObjLst[i]);
368 if ( GEOMBase::GetShapeTypeString( aSubShape, aTypeString ) )
369 aSubShapeName = QString( aTypeString ) + QString( "_" ) + QString::number( aObjLst[i] );
370 if ( !aSubShapeName.isEmpty() )
371 aSubShapeList.append( aSubShapeName );
374 myGrp->ListBox2->clear();
375 myGrp->ListBox2->addItems( aSubShapeList );
378 //=================================================================================
379 // function : onSubShapesListSelectionChanged
381 //=================================================================================
382 void MeasureGUI_CheckCompoundOfBlocksDlg::onSubShapesListSelectionChanged()
385 int aErrCurItem = myGrp->ListBox1->currentRow();
386 if ( aErrCurItem < 0 )
389 for ( int i = 0, n = myGrp->ListBox2->count(); i < n; i++ ) {
390 if ( myGrp->ListBox2->item( i )->isSelected() )
393 if ( aIds.count() < 1 )
395 bool isCompoundOfBlocks;
396 GEOM::GEOM_IBlocksOperations::BCErrors aErrs;
397 if ( !getBCErrors( isCompoundOfBlocks, aErrs ) ) {
398 myGrp->TextView1->setText( "" );
399 myGrp->ListBox1->clear();
400 myGrp->ListBox2->clear();
404 GEOM::GEOM_IBlocksOperations::BCError aErr = aErrs[aErrCurItem];
405 GEOM::ListOfLong aObjLst = aErr.incriminated;
406 TopoDS_Shape aSelShape;
407 TopoDS_Shape aSubShape;
408 TopTools_IndexedMapOfShape anIndices;
409 if ( !myObj->_is_nil() && GEOMBase::GetShape( myObj, aSelShape ) ) {
411 if ( !isValid( aMess ) ) {
414 SALOME_Prs* aPrs = 0;
415 TopExp::MapShapes( aSelShape, anIndices);
416 QList<int>::iterator it;
417 for ( it = aIds.begin(); it != aIds.end(); ++it ) {
418 aSubShape = anIndices.FindKey(aObjLst[(*it)]);
420 getDisplayer()->SetColor( Quantity_NOC_RED );
421 getDisplayer()->SetWidth( 3 );
422 getDisplayer()->SetToActivate( false );
423 aPrs = !aSubShape.IsNull() ? getDisplayer()->BuildPrs( aSubShape ) : 0;
425 displayPreview( aPrs, true );
427 catch ( const SALOME::SALOME_Exception& e ) {
428 SalomeApp_Tools::QtCatchCorbaException( e );
434 //=================================================================================
435 // function : activateSelection
436 // purpose : activate selection of faces, shells, and solids
437 //=================================================================================
438 void MeasureGUI_CheckCompoundOfBlocksDlg::activateSelection()
440 TColStd_MapOfInteger aMap;
441 aMap.Add( GEOM_SOLID );
442 aMap.Add( GEOM_COMPOUND );
443 globalSelection( aMap );
446 //=================================================================================
447 // function : enterEvent()
449 //=================================================================================
450 void MeasureGUI_CheckCompoundOfBlocksDlg::enterEvent( QEvent* )
452 if ( !mainFrame()->GroupConstructors->isEnabled() )
453 ActivateThisDialog();
456 //=================================================================================
457 // function : isValid
459 //=================================================================================
460 bool MeasureGUI_CheckCompoundOfBlocksDlg::isValid( QString& )
462 return !myObj->_is_nil();
465 //=================================================================================
466 // function : execute
468 //=================================================================================
469 bool MeasureGUI_CheckCompoundOfBlocksDlg::execute( ObjectList& objects )
471 GEOM::GEOM_Object_var anObj;
473 anObj = GEOM::GEOM_IBlocksOperations::_narrow( getOperation() )->CheckAndImprove( myObj );
475 if ( !anObj->_is_nil() )
476 objects.push_back( anObj._retn() );