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() )
245 GEOM::GEOM_IBlocksOperations::BCErrors_var aErrs;
246 theIsCompoundOfBlocks =
247 GEOM::GEOM_IBlocksOperations::_narrow( getOperation() )->CheckCompoundOfBlocks( myObj, aErrs );
250 catch ( const SALOME::SALOME_Exception& e ) {
251 SalomeApp_Tools::QtCatchCorbaException( e );
255 return getOperation()->IsDone();
259 //=================================================================================
260 // function : processObject
262 //=================================================================================
263 void MeasureGUI_CheckCompoundOfBlocksDlg::processObject()
266 bool isCompoundOfBlocks;
267 GEOM::GEOM_IBlocksOperations::BCErrors aErrs;
268 if ( !getBCErrors( isCompoundOfBlocks, aErrs ) ) {
269 myGrp->TextView1->setText( aMsg );
270 myGrp->ListBox1->clear();
271 myGrp->ListBox2->clear();
276 if ( isCompoundOfBlocks ) {
277 aMsg += tr( "GEOM_CHECK_BLOCKS_COMPOUND_HAS_NO_ERRORS" );
278 buttonOk()->setEnabled( false );
279 buttonApply()->setEnabled( false );
282 aMsg += tr( "GEOM_CHECK_BLOCKS_COMPOUND_HAS_ERRORS" );
283 buttonOk()->setEnabled( true );
284 buttonApply()->setEnabled( true );
286 myGrp->TextView1->setText( aMsg );
288 QStringList aErrList;
289 QString aErrStr( "" );
290 QString aConSfx( " # " );
291 QString aGluedSfx( " # " );
294 for ( int i = 0, n = aErrs.length(); i < n; i++ ) {
296 switch ( aErrs[i].error ) {
297 case GEOM::GEOM_IBlocksOperations::NOT_BLOCK :
298 aErrStr = "Not a Block";
300 case GEOM::GEOM_IBlocksOperations::EXTRA_EDGE :
301 aErrStr = "Extra Edge";
303 case GEOM::GEOM_IBlocksOperations::INVALID_CONNECTION :
304 aErrStr = "Invalid Connection";
306 aErrStr += QString::number( aConNum );
309 case GEOM::GEOM_IBlocksOperations::NOT_CONNECTED :
310 aErrStr = "Not Connected";
312 case GEOM::GEOM_IBlocksOperations::NOT_GLUED :
313 aErrStr = "Not Glued";
314 aErrStr += aGluedSfx;
315 aErrStr += QString::number( aGluedNum );
322 if ( !aErrStr.isEmpty() )
323 aErrList.append( aErrStr );
326 myGrp->ListBox1->clear();
327 myGrp->ListBox2->clear();
328 myGrp->ListBox1->addItems( aErrList );
331 //=================================================================================
332 // function : createOperation
334 //=================================================================================
335 GEOM::GEOM_IOperations_ptr MeasureGUI_CheckCompoundOfBlocksDlg::createOperation()
337 return getGeomEngine()->GetIBlocksOperations( getStudyId() );
340 //=================================================================================
341 // function : onErrorsListSelectionChanged
343 //=================================================================================
344 void MeasureGUI_CheckCompoundOfBlocksDlg::onErrorsListSelectionChanged()
347 int aCurItem = myGrp->ListBox1->currentRow();
350 bool isCompoundOfBlocks;
351 GEOM::GEOM_IBlocksOperations::BCErrors aErrs;
352 if ( !getBCErrors( isCompoundOfBlocks, aErrs ) ) {
353 myGrp->TextView1->setText( "" );
354 myGrp->ListBox1->clear();
355 myGrp->ListBox2->clear();
359 GEOM::GEOM_IBlocksOperations::BCError aErr = aErrs[aCurItem];
360 GEOM::ListOfLong aObjLst = aErr.incriminated;
361 TopoDS_Shape aSelShape;
362 TopoDS_Shape aSubShape;
363 TopTools_IndexedMapOfShape anIndices;
364 QStringList aSubShapeList;
365 QString aSubShapeName( "" );
366 Standard_CString aTypeString;
367 if ( !myObj->_is_nil() && GEOMBase::GetShape( myObj, aSelShape ) ) {
368 TopExp::MapShapes( aSelShape, anIndices);
369 for ( int i = 0, n = aObjLst.length(); i < n; i++ ) {
371 aSubShape = anIndices.FindKey(aObjLst[i]);
372 if ( GEOMBase::GetShapeTypeString( aSubShape, aTypeString ) )
373 aSubShapeName = QString( aTypeString ) + QString( "_" ) + QString::number( aObjLst[i] );
374 if ( !aSubShapeName.isEmpty() )
375 aSubShapeList.append( aSubShapeName );
378 myGrp->ListBox2->clear();
379 myGrp->ListBox2->addItems( aSubShapeList );
382 //=================================================================================
383 // function : onSubShapesListSelectionChanged
385 //=================================================================================
386 void MeasureGUI_CheckCompoundOfBlocksDlg::onSubShapesListSelectionChanged()
389 int aErrCurItem = myGrp->ListBox1->currentRow();
390 if ( aErrCurItem < 0 )
393 for ( int i = 0, n = myGrp->ListBox2->count(); i < n; i++ ) {
394 if ( myGrp->ListBox2->item( i )->isSelected() )
397 if ( aIds.count() < 1 )
399 bool isCompoundOfBlocks;
400 GEOM::GEOM_IBlocksOperations::BCErrors aErrs;
401 if ( !getBCErrors( isCompoundOfBlocks, aErrs ) ) {
402 myGrp->TextView1->setText( "" );
403 myGrp->ListBox1->clear();
404 myGrp->ListBox2->clear();
408 GEOM::GEOM_IBlocksOperations::BCError aErr = aErrs[aErrCurItem];
409 GEOM::ListOfLong aObjLst = aErr.incriminated;
410 TopoDS_Shape aSelShape;
411 TopoDS_Shape aSubShape;
412 TopTools_IndexedMapOfShape anIndices;
413 if ( !myObj->_is_nil() && GEOMBase::GetShape( myObj, aSelShape ) ) {
415 if ( !isValid( aMess ) ) {
418 SALOME_Prs* aPrs = 0;
419 TopExp::MapShapes( aSelShape, anIndices);
420 QList<int>::iterator it;
421 for ( it = aIds.begin(); it != aIds.end(); ++it ) {
422 aSubShape = anIndices.FindKey(aObjLst[(*it)]);
424 getDisplayer()->SetColor( Quantity_NOC_RED );
425 getDisplayer()->SetWidth( 3 );
426 getDisplayer()->SetToActivate( false );
427 aPrs = !aSubShape.IsNull() ? getDisplayer()->BuildPrs( aSubShape ) : 0;
429 displayPreview( aPrs, true );
431 catch ( const SALOME::SALOME_Exception& e ) {
432 SalomeApp_Tools::QtCatchCorbaException( e );
438 //=================================================================================
439 // function : activateSelection
440 // purpose : activate selection of faces, shells, and solids
441 //=================================================================================
442 void MeasureGUI_CheckCompoundOfBlocksDlg::activateSelection()
444 TColStd_MapOfInteger aMap;
445 aMap.Add( GEOM_SOLID );
446 aMap.Add( GEOM_COMPOUND );
447 globalSelection( aMap );
450 //=================================================================================
451 // function : enterEvent()
453 //=================================================================================
454 void MeasureGUI_CheckCompoundOfBlocksDlg::enterEvent( QEvent* )
456 if ( !mainFrame()->GroupConstructors->isEnabled() )
457 ActivateThisDialog();
460 //=================================================================================
461 // function : isValid
463 //=================================================================================
464 bool MeasureGUI_CheckCompoundOfBlocksDlg::isValid( QString& )
466 return !myObj->_is_nil();
469 //=================================================================================
470 // function : execute
472 //=================================================================================
473 bool MeasureGUI_CheckCompoundOfBlocksDlg::execute( ObjectList& objects )
475 GEOM::GEOM_Object_var anObj;
477 anObj = GEOM::GEOM_IBlocksOperations::_narrow( getOperation() )->CheckAndImprove( myObj );
479 if ( !anObj->_is_nil() )
480 objects.push_back( anObj._retn() );