1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 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 // GEOM GEOMGUI : GUI for Geometry component
23 // File : MeasureGUI_CheckCompoundOfBlocksDlg.cxx
24 // 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>
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 = "using_measurement_tools_page.html#check_compound_anchor";
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 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
169 SALOME_ListIO aSelList;
170 aSelMgr->selectedObjects(aSelList);
172 if (aSelList.Extent() != 1) {
173 myGrp->LineEdit1->setText( "" );
178 Standard_Boolean testResult = Standard_False;
179 GEOM::GEOM_Object_var aSelectedObject =
180 GEOMBase::ConvertIOinGEOMObject(aSelList.First(), testResult);
182 if ( !testResult || aSelectedObject->_is_nil() ) {
183 myGrp->LineEdit1->setText( "" );
188 myObj = aSelectedObject;
189 myGrp->LineEdit1->setText( GEOMBase::GetName( myObj ) );
194 //=================================================================================
195 // function : SetEditCurrentArgument
197 //=================================================================================
198 void MeasureGUI_CheckCompoundOfBlocksDlg::SetEditCurrentArgument()
200 myGrp->LineEdit1->setFocus();
201 myEditCurrentArgument = myGrp->LineEdit1;
202 SelectionIntoArgument();
205 //=================================================================================
206 // function : LineEditReturnPressed()
208 //=================================================================================
209 void MeasureGUI_CheckCompoundOfBlocksDlg::LineEditReturnPressed()
211 QLineEdit* send = (QLineEdit*)sender();
212 if ( send == myGrp->LineEdit1 ) {
213 myEditCurrentArgument = myGrp->LineEdit1;
214 GEOMBase_Skeleton::LineEditReturnPressed();
218 //=================================================================================
219 // function : ActivateThisDialog()
221 //=================================================================================
222 void MeasureGUI_CheckCompoundOfBlocksDlg::ActivateThisDialog()
224 GEOMBase_Skeleton::ActivateThisDialog();
226 LightApp_SelectionMgr* aSel = myGeomGUI->getApp()->selectionMgr();
228 connect( aSel, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
234 //=================================================================================
235 // function : getBCErrors
237 //=================================================================================
238 bool MeasureGUI_CheckCompoundOfBlocksDlg::getBCErrors( bool& theIsCompoundOfBlocks,
239 GEOM::GEOM_IBlocksOperations::BCErrors& theErrors)
241 if ( myObj->_is_nil() )
244 GEOM::GEOM_IBlocksOperations_var anOper = GEOM::GEOM_IBlocksOperations::_narrow( getOperation() );
246 GEOM::GEOM_IBlocksOperations::BCErrors_var aErrs;
247 theIsCompoundOfBlocks = anOper->CheckCompoundOfBlocks( myObj, aErrs );
248 if (anOper->IsDone() && aErrs->length() > 0)
249 //if (anOper->IsDone() && !aErrs._is_nil())
252 catch ( const SALOME::SALOME_Exception& e ) {
253 SalomeApp_Tools::QtCatchCorbaException( e );
257 return anOper->IsDone();
261 //=================================================================================
262 // function : processObject
264 //=================================================================================
265 void MeasureGUI_CheckCompoundOfBlocksDlg::processObject()
268 bool isCompoundOfBlocks;
269 GEOM::GEOM_IBlocksOperations::BCErrors aErrs;
270 if ( !getBCErrors( isCompoundOfBlocks, aErrs ) ) {
271 aMsg += tr( "GEOM_CHECK_BLOCKS_COMPOUND_FAILED" );
272 myGrp->TextView1->setText( aMsg );
273 myGrp->ListBox1->clear();
274 myGrp->ListBox2->clear();
279 if ( isCompoundOfBlocks ) {
280 aMsg += tr( "GEOM_CHECK_BLOCKS_COMPOUND_HAS_NO_ERRORS" );
281 buttonOk()->setEnabled( false );
282 buttonApply()->setEnabled( false );
285 aMsg += tr( "GEOM_CHECK_BLOCKS_COMPOUND_HAS_ERRORS" );
286 buttonOk()->setEnabled( true );
287 buttonApply()->setEnabled( true );
289 myGrp->TextView1->setText( aMsg );
291 QStringList aErrList;
292 QString aErrStr( "" );
293 QString aConSfx( " # " );
294 QString aGluedSfx( " # " );
297 for ( int i = 0, n = aErrs.length(); i < n; i++ ) {
299 switch ( aErrs[i].error ) {
300 case GEOM::GEOM_IBlocksOperations::NOT_BLOCK :
301 aErrStr = "Not a Block";
303 case GEOM::GEOM_IBlocksOperations::EXTRA_EDGE :
304 aErrStr = "Extra Edge";
306 case GEOM::GEOM_IBlocksOperations::INVALID_CONNECTION :
307 aErrStr = "Invalid Connection";
309 aErrStr += QString::number( aConNum );
312 case GEOM::GEOM_IBlocksOperations::NOT_CONNECTED :
313 aErrStr = "Not Connected";
315 case GEOM::GEOM_IBlocksOperations::NOT_GLUED :
316 aErrStr = "Not Glued";
317 aErrStr += aGluedSfx;
318 aErrStr += QString::number( aGluedNum );
325 if ( !aErrStr.isEmpty() )
326 aErrList.append( aErrStr );
329 myGrp->ListBox1->clear();
330 myGrp->ListBox2->clear();
331 myGrp->ListBox1->addItems( aErrList );
334 //=================================================================================
335 // function : createOperation
337 //=================================================================================
338 GEOM::GEOM_IOperations_ptr MeasureGUI_CheckCompoundOfBlocksDlg::createOperation()
340 return getGeomEngine()->GetIBlocksOperations( getStudyId() );
343 //=================================================================================
344 // function : onErrorsListSelectionChanged
346 //=================================================================================
347 void MeasureGUI_CheckCompoundOfBlocksDlg::onErrorsListSelectionChanged()
350 int aCurItem = myGrp->ListBox1->currentRow();
353 bool isCompoundOfBlocks;
354 GEOM::GEOM_IBlocksOperations::BCErrors aErrs;
355 if ( !getBCErrors( isCompoundOfBlocks, aErrs ) ) {
356 myGrp->TextView1->setText( "" );
357 myGrp->ListBox1->clear();
358 myGrp->ListBox2->clear();
362 GEOM::GEOM_IBlocksOperations::BCError aErr = aErrs[aCurItem];
363 GEOM::ListOfLong aObjLst = aErr.incriminated;
364 TopoDS_Shape aSelShape;
365 TopoDS_Shape aSubShape;
366 TopTools_IndexedMapOfShape anIndices;
367 QStringList aSubShapeList;
368 QString aSubShapeName( "" );
369 Standard_CString aTypeString;
370 if ( !myObj->_is_nil() && GEOMBase::GetShape( myObj, aSelShape ) ) {
371 TopExp::MapShapes( aSelShape, anIndices);
372 for ( int i = 0, n = aObjLst.length(); i < n; i++ ) {
374 aSubShape = anIndices.FindKey(aObjLst[i]);
375 if ( GEOMBase::GetShapeTypeString( aSubShape, aTypeString ) )
376 aSubShapeName = QString( aTypeString ) + QString( "_" ) + QString::number( aObjLst[i] );
377 if ( !aSubShapeName.isEmpty() )
378 aSubShapeList.append( aSubShapeName );
381 myGrp->ListBox2->clear();
382 myGrp->ListBox2->addItems( aSubShapeList );
385 //=================================================================================
386 // function : onSubShapesListSelectionChanged
388 //=================================================================================
389 void MeasureGUI_CheckCompoundOfBlocksDlg::onSubShapesListSelectionChanged()
392 int aErrCurItem = myGrp->ListBox1->currentRow();
393 if ( aErrCurItem < 0 )
396 for ( int i = 0, n = myGrp->ListBox2->count(); i < n; i++ ) {
397 if ( myGrp->ListBox2->item( i )->isSelected() )
400 if ( aIds.count() < 1 )
402 bool isCompoundOfBlocks;
403 GEOM::GEOM_IBlocksOperations::BCErrors aErrs;
404 if ( !getBCErrors( isCompoundOfBlocks, aErrs ) ) {
405 myGrp->TextView1->setText( "" );
406 myGrp->ListBox1->clear();
407 myGrp->ListBox2->clear();
411 GEOM::GEOM_IBlocksOperations::BCError aErr = aErrs[aErrCurItem];
412 GEOM::ListOfLong aObjLst = aErr.incriminated;
413 TopoDS_Shape aSelShape;
414 TopoDS_Shape aSubShape;
415 TopTools_IndexedMapOfShape anIndices;
416 if ( !myObj->_is_nil() && GEOMBase::GetShape( myObj, aSelShape ) ) {
418 if ( !isValid( aMess ) ) {
421 SALOME_Prs* aPrs = 0;
422 TopExp::MapShapes( aSelShape, anIndices);
423 QList<int>::iterator it;
424 for ( it = aIds.begin(); it != aIds.end(); ++it ) {
425 aSubShape = anIndices.FindKey(aObjLst[(*it)]);
427 getDisplayer()->SetColor( Quantity_NOC_RED );
428 getDisplayer()->SetWidth( 3 );
429 getDisplayer()->SetToActivate( false );
430 aPrs = !aSubShape.IsNull() ? getDisplayer()->BuildPrs( aSubShape ) : 0;
432 displayPreview( aPrs, true );
434 catch ( const SALOME::SALOME_Exception& e ) {
435 SalomeApp_Tools::QtCatchCorbaException( e );
441 //=================================================================================
442 // function : activateSelection
443 // purpose : activate selection of faces, shells, and solids
444 //=================================================================================
445 void MeasureGUI_CheckCompoundOfBlocksDlg::activateSelection()
447 TColStd_MapOfInteger aMap;
448 aMap.Add( GEOM_SOLID );
449 aMap.Add( GEOM_COMPOUND );
450 globalSelection( aMap );
453 //=================================================================================
454 // function : enterEvent()
456 //=================================================================================
457 void MeasureGUI_CheckCompoundOfBlocksDlg::enterEvent( QEvent* )
459 if ( !mainFrame()->GroupConstructors->isEnabled() )
460 ActivateThisDialog();
463 //=================================================================================
464 // function : isValid
466 //=================================================================================
467 bool MeasureGUI_CheckCompoundOfBlocksDlg::isValid( QString& )
469 return !myObj->_is_nil();
472 //=================================================================================
473 // function : execute
475 //=================================================================================
476 bool MeasureGUI_CheckCompoundOfBlocksDlg::execute( ObjectList& objects )
478 GEOM::GEOM_IBlocksOperations_var anOper = GEOM::GEOM_IBlocksOperations::_narrow( getOperation() );
479 GEOM::GEOM_Object_var anObj = anOper->CheckAndImprove( myObj );
481 if ( !anObj->_is_nil() )
482 objects.push_back( anObj._retn() );