1 // Copyright (C) 2007-2010 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
23 // GEOM GEOMGUI : GUI for Geometry component
24 // File : MeasureGUI_CheckCompoundOfBlocksDlg.cxx
25 // Author : Vladimir KLYACHIN, Open CASCADE S.A.S. (vladimir.klyachin@opencascade.com)
27 #include "MeasureGUI_CheckCompoundOfBlocksDlg.h"
28 #include "MeasureGUI_Widgets.h"
30 #include <SUIT_Session.h>
31 #include <SUIT_ResourceMgr.h>
32 #include <LightApp_SelectionMgr.h>
33 #include <SalomeApp_Tools.h>
34 #include <SalomeApp_Application.h>
36 #include <TopTools_IndexedMapOfShape.hxx>
38 #include <TColStd_MapOfInteger.hxx>
41 #include <GeometryGUI.h>
43 #include <GEOMImpl_Types.hxx>
45 #define TEXTEDIT_FONT_FAMILY "Courier"
46 #define TEXTEDIT_FONT_SIZE 11
48 //=================================================================================
49 // class : MeasureGUI_CheckCompoundOfBlocksDlg()
50 // purpose : Constructs a MeasureGUI_CheckCompoundOfBlocksDlg which is a child of 'parent', with the
51 // name 'name' and widget flags set to 'f'.
52 // The dialog will by default be modeless, unless you set 'modal' to
53 // true to construct a modal dialog.
54 //=================================================================================
55 MeasureGUI_CheckCompoundOfBlocksDlg::MeasureGUI_CheckCompoundOfBlocksDlg( GeometryGUI* GUI, QWidget* parent )
56 : GEOMBase_Skeleton( GUI, parent, false )
58 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
59 QPixmap image0( aResMgr->loadPixmap( "GEOM", tr( "ICON_DLG_CHECK_COMPOUND_OF_BLOCKS" ) ) );
60 QPixmap image1( aResMgr->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
62 setWindowTitle( tr( "GEOM_CHECK_BLOCKS_COMPOUND" ) );
64 /***************************************************************/
65 mainFrame()->GroupConstructors->setTitle( tr( "GEOM_CHECK_BLOCKS_COMPOUND" ) );
66 mainFrame()->RadioButton1->setIcon( image0 );
67 mainFrame()->RadioButton2->setAttribute( Qt::WA_DeleteOnClose );
68 mainFrame()->RadioButton2->close();
69 mainFrame()->RadioButton3->setAttribute( Qt::WA_DeleteOnClose );
70 mainFrame()->RadioButton3->close();
72 myGrp = new MeasureGUI_1Sel1TextView2ListBox( centralWidget() );
73 myGrp->GroupBox1->setTitle( tr( "GEOM_CHECK_INFOS" ) );
74 myGrp->TextLabel1->setText( tr( "GEOM_OBJECT" ) );
76 myGrp->TextView1->setReadOnly( true );
77 QFont aFont( TEXTEDIT_FONT_FAMILY, TEXTEDIT_FONT_SIZE );
78 aFont.setStyleHint( QFont::TypeWriter, QFont::PreferAntialias );
79 myGrp->TextView1->setFont( aFont );
81 myGrp->PushButton1->setIcon( image1 );
82 myGrp->LineEdit1->setReadOnly( true );
84 myGrp->TextLabel2->setText( tr( "GEOM_CHECK_BLOCKS_COMPOUND_ERRORS" ) );
85 myGrp->TextLabel3->setText( tr( "GEOM_CHECK_BLOCKS_COMPOUND_SUBSHAPES" ) );
87 myGrp->ListBox2->setSelectionMode( QAbstractItemView::ExtendedSelection );
89 QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
90 layout->setMargin( 0 ); layout->setSpacing( 6 );
91 layout->addWidget( myGrp );
93 connect( myGrp->ListBox1, SIGNAL( itemSelectionChanged() ), SLOT( onErrorsListSelectionChanged() ) );
94 connect( myGrp->ListBox2, SIGNAL( itemSelectionChanged() ), SLOT( onSubShapesListSelectionChanged() ) );
96 /***************************************************************/
98 myHelpFileName = "using_measurement_tools_page.html#check_compound_anchor";
104 //=================================================================================
105 // function : ~MeasureGUI_CheckCompoundOfBlocksDlg()
106 // purpose : Destroys the object and frees any allocated resources
107 //=================================================================================
108 MeasureGUI_CheckCompoundOfBlocksDlg::~MeasureGUI_CheckCompoundOfBlocksDlg()
112 //=================================================================================
115 //=================================================================================
116 void MeasureGUI_CheckCompoundOfBlocksDlg::Init()
118 myEditCurrentArgument = myGrp->LineEdit1;
120 // signals and slots connections
121 connect( buttonOk(), SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
122 connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
124 connect( myGrp->LineEdit1, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
125 connect( myGrp->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
127 connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
128 this, SLOT( SelectionIntoArgument() ) );
130 initName( tr( "GEOM_BLOCKS_COMPOUND") );
131 buttonOk()->setEnabled( false );
132 buttonApply()->setEnabled( false );
134 SelectionIntoArgument();
137 //=================================================================================
138 // function : ClickOnOk()
140 //=================================================================================
141 void MeasureGUI_CheckCompoundOfBlocksDlg::ClickOnOk()
143 if ( ClickOnApply() )
147 //=================================================================================
148 // function : ClickOnApply()
150 //=================================================================================
151 bool MeasureGUI_CheckCompoundOfBlocksDlg::ClickOnApply()
160 //=================================================================================
161 // function : SelectionIntoArgument
163 //=================================================================================
164 void MeasureGUI_CheckCompoundOfBlocksDlg::SelectionIntoArgument()
167 myObj = GEOM::GEOM_Object::_nil();
169 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
170 SALOME_ListIO aSelList;
171 aSelMgr->selectedObjects(aSelList);
173 if (aSelList.Extent() != 1) {
174 myGrp->LineEdit1->setText( "" );
179 Standard_Boolean testResult = Standard_False;
180 GEOM::GEOM_Object_var aSelectedObject =
181 GEOMBase::ConvertIOinGEOMObject(aSelList.First(), testResult);
183 if ( !testResult || aSelectedObject->_is_nil() ) {
184 myGrp->LineEdit1->setText( "" );
189 myObj = aSelectedObject;
190 myGrp->LineEdit1->setText( GEOMBase::GetName( myObj ) );
195 //=================================================================================
196 // function : SetEditCurrentArgument
198 //=================================================================================
199 void MeasureGUI_CheckCompoundOfBlocksDlg::SetEditCurrentArgument()
201 myGrp->LineEdit1->setFocus();
202 myEditCurrentArgument = myGrp->LineEdit1;
203 SelectionIntoArgument();
206 //=================================================================================
207 // function : LineEditReturnPressed()
209 //=================================================================================
210 void MeasureGUI_CheckCompoundOfBlocksDlg::LineEditReturnPressed()
212 QLineEdit* send = (QLineEdit*)sender();
213 if ( send == myGrp->LineEdit1 ) {
214 myEditCurrentArgument = myGrp->LineEdit1;
215 GEOMBase_Skeleton::LineEditReturnPressed();
219 //=================================================================================
220 // function : ActivateThisDialog()
222 //=================================================================================
223 void MeasureGUI_CheckCompoundOfBlocksDlg::ActivateThisDialog()
225 GEOMBase_Skeleton::ActivateThisDialog();
227 LightApp_SelectionMgr* aSel = myGeomGUI->getApp()->selectionMgr();
229 connect( aSel, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
235 //=================================================================================
236 // function : getBCErrors
238 //=================================================================================
239 bool MeasureGUI_CheckCompoundOfBlocksDlg::getBCErrors( bool& theIsCompoundOfBlocks,
240 GEOM::GEOM_IBlocksOperations::BCErrors& theErrors)
242 if ( myObj->_is_nil() )
245 GEOM::GEOM_IBlocksOperations_var anOper = GEOM::GEOM_IBlocksOperations::_narrow( getOperation() );
247 GEOM::GEOM_IBlocksOperations::BCErrors_var aErrs;
248 theIsCompoundOfBlocks = anOper->CheckCompoundOfBlocks( myObj, aErrs );
249 if (anOper->IsDone() && aErrs->length() > 0)
250 //if (anOper->IsDone() && !aErrs._is_nil())
253 catch ( const SALOME::SALOME_Exception& e ) {
254 SalomeApp_Tools::QtCatchCorbaException( e );
258 return anOper->IsDone();
262 //=================================================================================
263 // function : processObject
265 //=================================================================================
266 void MeasureGUI_CheckCompoundOfBlocksDlg::processObject()
269 bool isCompoundOfBlocks;
270 GEOM::GEOM_IBlocksOperations::BCErrors aErrs;
271 if ( !getBCErrors( isCompoundOfBlocks, aErrs ) ) {
272 aMsg += tr( "GEOM_CHECK_BLOCKS_COMPOUND_FAILED" );
273 myGrp->TextView1->setText( aMsg );
274 myGrp->ListBox1->clear();
275 myGrp->ListBox2->clear();
280 if ( isCompoundOfBlocks ) {
281 aMsg += tr( "GEOM_CHECK_BLOCKS_COMPOUND_HAS_NO_ERRORS" );
282 buttonOk()->setEnabled( false );
283 buttonApply()->setEnabled( false );
286 aMsg += tr( "GEOM_CHECK_BLOCKS_COMPOUND_HAS_ERRORS" );
287 buttonOk()->setEnabled( true );
288 buttonApply()->setEnabled( true );
290 myGrp->TextView1->setText( aMsg );
292 QStringList aErrList;
293 QString aErrStr( "" );
294 QString aConSfx( " # " );
295 QString aGluedSfx( " # " );
298 for ( int i = 0, n = aErrs.length(); i < n; i++ ) {
300 switch ( aErrs[i].error ) {
301 case GEOM::GEOM_IBlocksOperations::NOT_BLOCK :
302 aErrStr = "Not a Block";
304 case GEOM::GEOM_IBlocksOperations::EXTRA_EDGE :
305 aErrStr = "Extra Edge";
307 case GEOM::GEOM_IBlocksOperations::INVALID_CONNECTION :
308 aErrStr = "Invalid Connection";
310 aErrStr += QString::number( aConNum );
313 case GEOM::GEOM_IBlocksOperations::NOT_CONNECTED :
314 aErrStr = "Not Connected";
316 case GEOM::GEOM_IBlocksOperations::NOT_GLUED :
317 aErrStr = "Not Glued";
318 aErrStr += aGluedSfx;
319 aErrStr += QString::number( aGluedNum );
326 if ( !aErrStr.isEmpty() )
327 aErrList.append( aErrStr );
330 myGrp->ListBox1->clear();
331 myGrp->ListBox2->clear();
332 myGrp->ListBox1->addItems( aErrList );
335 //=================================================================================
336 // function : createOperation
338 //=================================================================================
339 GEOM::GEOM_IOperations_ptr MeasureGUI_CheckCompoundOfBlocksDlg::createOperation()
341 return getGeomEngine()->GetIBlocksOperations( getStudyId() );
344 //=================================================================================
345 // function : onErrorsListSelectionChanged
347 //=================================================================================
348 void MeasureGUI_CheckCompoundOfBlocksDlg::onErrorsListSelectionChanged()
351 int aCurItem = myGrp->ListBox1->currentRow();
354 bool isCompoundOfBlocks;
355 GEOM::GEOM_IBlocksOperations::BCErrors aErrs;
356 if ( !getBCErrors( isCompoundOfBlocks, aErrs ) ) {
357 myGrp->TextView1->setText( "" );
358 myGrp->ListBox1->clear();
359 myGrp->ListBox2->clear();
363 GEOM::GEOM_IBlocksOperations::BCError aErr = aErrs[aCurItem];
364 GEOM::ListOfLong aObjLst = aErr.incriminated;
365 TopoDS_Shape aSelShape;
366 TopoDS_Shape aSubShape;
367 TopTools_IndexedMapOfShape anIndices;
368 QStringList aSubShapeList;
369 QString aSubShapeName( "" );
370 Standard_CString aTypeString;
371 if ( !myObj->_is_nil() && GEOMBase::GetShape( myObj, aSelShape ) ) {
372 TopExp::MapShapes( aSelShape, anIndices);
373 for ( int i = 0, n = aObjLst.length(); i < n; i++ ) {
375 aSubShape = anIndices.FindKey(aObjLst[i]);
376 if ( GEOMBase::GetShapeTypeString( aSubShape, aTypeString ) )
377 aSubShapeName = QString( aTypeString ) + QString( "_" ) + QString::number( aObjLst[i] );
378 if ( !aSubShapeName.isEmpty() )
379 aSubShapeList.append( aSubShapeName );
382 myGrp->ListBox2->clear();
383 myGrp->ListBox2->addItems( aSubShapeList );
386 //=================================================================================
387 // function : onSubShapesListSelectionChanged
389 //=================================================================================
390 void MeasureGUI_CheckCompoundOfBlocksDlg::onSubShapesListSelectionChanged()
393 int aErrCurItem = myGrp->ListBox1->currentRow();
394 if ( aErrCurItem < 0 )
397 for ( int i = 0, n = myGrp->ListBox2->count(); i < n; i++ ) {
398 if ( myGrp->ListBox2->item( i )->isSelected() )
401 if ( aIds.count() < 1 )
403 bool isCompoundOfBlocks;
404 GEOM::GEOM_IBlocksOperations::BCErrors aErrs;
405 if ( !getBCErrors( isCompoundOfBlocks, aErrs ) ) {
406 myGrp->TextView1->setText( "" );
407 myGrp->ListBox1->clear();
408 myGrp->ListBox2->clear();
412 GEOM::GEOM_IBlocksOperations::BCError aErr = aErrs[aErrCurItem];
413 GEOM::ListOfLong aObjLst = aErr.incriminated;
414 TopoDS_Shape aSelShape;
415 TopoDS_Shape aSubShape;
416 TopTools_IndexedMapOfShape anIndices;
417 if ( !myObj->_is_nil() && GEOMBase::GetShape( myObj, aSelShape ) ) {
419 if ( !isValid( aMess ) ) {
422 SALOME_Prs* aPrs = 0;
423 TopExp::MapShapes( aSelShape, anIndices);
424 QList<int>::iterator it;
425 for ( it = aIds.begin(); it != aIds.end(); ++it ) {
426 aSubShape = anIndices.FindKey(aObjLst[(*it)]);
428 getDisplayer()->SetColor( Quantity_NOC_RED );
429 getDisplayer()->SetWidth( 3 );
430 getDisplayer()->SetToActivate( false );
431 aPrs = !aSubShape.IsNull() ? getDisplayer()->BuildPrs( aSubShape ) : 0;
433 displayPreview( aPrs, true );
435 catch ( const SALOME::SALOME_Exception& e ) {
436 SalomeApp_Tools::QtCatchCorbaException( e );
442 //=================================================================================
443 // function : activateSelection
444 // purpose : activate selection of faces, shells, and solids
445 //=================================================================================
446 void MeasureGUI_CheckCompoundOfBlocksDlg::activateSelection()
448 TColStd_MapOfInteger aMap;
449 aMap.Add( GEOM_SOLID );
450 aMap.Add( GEOM_COMPOUND );
451 globalSelection( aMap );
454 //=================================================================================
455 // function : enterEvent()
457 //=================================================================================
458 void MeasureGUI_CheckCompoundOfBlocksDlg::enterEvent( QEvent* )
460 if ( !mainFrame()->GroupConstructors->isEnabled() )
461 ActivateThisDialog();
464 //=================================================================================
465 // function : isValid
467 //=================================================================================
468 bool MeasureGUI_CheckCompoundOfBlocksDlg::isValid( QString& )
470 return !myObj->_is_nil();
473 //=================================================================================
474 // function : execute
476 //=================================================================================
477 bool MeasureGUI_CheckCompoundOfBlocksDlg::execute( ObjectList& objects )
479 GEOM::GEOM_IBlocksOperations_var anOper = GEOM::GEOM_IBlocksOperations::_narrow( getOperation() );
480 GEOM::GEOM_Object_var anObj = anOper->CheckAndImprove( myObj );
482 if ( !anObj->_is_nil() )
483 objects.push_back( anObj._retn() );