1 // Copyright (C) 2007-2012 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.h"
28 #include "MeasureGUI_CheckCompoundOfBlocksDlg.h"
29 #include "MeasureGUI_Widgets.h"
31 #include <SUIT_Session.h>
32 #include <SUIT_ResourceMgr.h>
33 #include <LightApp_SelectionMgr.h>
34 #include <SalomeApp_Tools.h>
35 #include <SalomeApp_Application.h>
37 #include <TopTools_IndexedMapOfShape.hxx>
39 #include <TColStd_MapOfInteger.hxx>
42 #include <GeometryGUI.h>
44 #include <GEOMImpl_Types.hxx>
46 #define TEXTEDIT_FONT_FAMILY "Courier"
47 #define TEXTEDIT_FONT_SIZE 11
49 //=================================================================================
50 // class : MeasureGUI_CheckCompoundOfBlocksDlg()
51 // purpose : Constructs a MeasureGUI_CheckCompoundOfBlocksDlg which is a child of 'parent', with the
52 // name 'name' and widget flags set to 'f'.
53 // The dialog will by default be modeless, unless you set 'modal' to
54 // true to construct a modal dialog.
55 //=================================================================================
56 MeasureGUI_CheckCompoundOfBlocksDlg::MeasureGUI_CheckCompoundOfBlocksDlg( GeometryGUI* GUI, QWidget* parent )
57 : GEOMBase_Skeleton( GUI, parent, false )
59 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
60 QPixmap image0( aResMgr->loadPixmap( "GEOM", tr( "ICON_DLG_CHECK_COMPOUND_OF_BLOCKS" ) ) );
61 QPixmap image1( aResMgr->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
63 setWindowTitle( tr( "GEOM_CHECK_BLOCKS_COMPOUND" ) );
65 /***************************************************************/
66 mainFrame()->GroupConstructors->setTitle( tr( "GEOM_CHECK_BLOCKS_COMPOUND" ) );
67 mainFrame()->RadioButton1->setIcon( image0 );
68 mainFrame()->RadioButton2->setAttribute( Qt::WA_DeleteOnClose );
69 mainFrame()->RadioButton2->close();
70 mainFrame()->RadioButton3->setAttribute( Qt::WA_DeleteOnClose );
71 mainFrame()->RadioButton3->close();
73 myGrp = new MeasureGUI_1Sel1TextView2ListBox( centralWidget() );
74 myGrp->GroupBox1->setTitle( tr( "GEOM_CHECK_INFOS" ) );
75 myGrp->TextLabel1->setText( tr( "GEOM_OBJECT" ) );
77 myGrp->TextView1->setReadOnly( true );
78 QFont aFont( TEXTEDIT_FONT_FAMILY, TEXTEDIT_FONT_SIZE );
79 aFont.setStyleHint( QFont::TypeWriter, QFont::PreferAntialias );
80 myGrp->TextView1->setFont( aFont );
82 myGrp->PushButton1->setIcon( image1 );
83 myGrp->LineEdit1->setReadOnly( true );
85 myGrp->TextLabel2->setText( tr( "GEOM_CHECK_BLOCKS_COMPOUND_ERRORS" ) );
86 myGrp->TextLabel3->setText( tr( "GEOM_CHECK_BLOCKS_COMPOUND_SUBSHAPES" ) );
88 myGrp->ListBox2->setSelectionMode( QAbstractItemView::ExtendedSelection );
90 QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
91 layout->setMargin( 0 ); layout->setSpacing( 6 );
92 layout->addWidget( myGrp );
94 connect( myGrp->ListBox1, SIGNAL( itemSelectionChanged() ), SLOT( onErrorsListSelectionChanged() ) );
95 connect( myGrp->ListBox2, SIGNAL( itemSelectionChanged() ), SLOT( onSubShapesListSelectionChanged() ) );
97 /***************************************************************/
99 myHelpFileName = "using_measurement_tools_page.html#check_compound_anchor";
105 //=================================================================================
106 // function : ~MeasureGUI_CheckCompoundOfBlocksDlg()
107 // purpose : Destroys the object and frees any allocated resources
108 //=================================================================================
109 MeasureGUI_CheckCompoundOfBlocksDlg::~MeasureGUI_CheckCompoundOfBlocksDlg()
113 //=================================================================================
116 //=================================================================================
117 void MeasureGUI_CheckCompoundOfBlocksDlg::Init()
119 myEditCurrentArgument = myGrp->LineEdit1;
121 // signals and slots connections
122 connect( buttonOk(), SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
123 connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
125 connect( myGrp->LineEdit1, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
126 connect( myGrp->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
128 connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
129 this, SLOT( SelectionIntoArgument() ) );
131 initName( tr( "GEOM_BLOCKS_COMPOUND") );
132 buttonOk()->setEnabled( false );
133 buttonApply()->setEnabled( false );
135 SelectionIntoArgument();
138 //=================================================================================
139 // function : ClickOnOk()
141 //=================================================================================
142 void MeasureGUI_CheckCompoundOfBlocksDlg::ClickOnOk()
144 if ( ClickOnApply() )
148 //=================================================================================
149 // function : ClickOnApply()
151 //=================================================================================
152 bool MeasureGUI_CheckCompoundOfBlocksDlg::ClickOnApply()
161 //=================================================================================
162 // function : SelectionIntoArgument
164 //=================================================================================
165 void MeasureGUI_CheckCompoundOfBlocksDlg::SelectionIntoArgument()
168 myObj = GEOM::GEOM_Object::_nil();
170 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
171 SALOME_ListIO aSelList;
172 aSelMgr->selectedObjects(aSelList);
174 if (aSelList.Extent() != 1) {
175 myGrp->LineEdit1->setText( "" );
180 GEOM::GEOM_Object_var aSelectedObject =
181 GEOMBase::ConvertIOinGEOMObject( aSelList.First() );
183 if ( aSelectedObject->_is_nil() ) {
184 myGrp->LineEdit1->setText( "" );
189 myObj = aSelectedObject;
190 myGrp->LineEdit1->setText( GEOMBase::GetName( myObj ) );
192 DISPLAY_PREVIEW_MACRO;
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() ) );
232 DISPLAY_PREVIEW_MACRO
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 QStringList aSubShapeList;
366 TopoDS_Shape aSelShape;
367 if ( !myObj->_is_nil() && GEOMBase::GetShape( myObj, aSelShape ) ) {
368 TopTools_IndexedMapOfShape anIndices;
369 TopExp::MapShapes( aSelShape, anIndices );
370 for ( int i = 0, n = aObjLst.length(); i < n; i++ ) {
371 TopoDS_Shape aSubShape = anIndices.FindKey( aObjLst[i] );
372 QString aType = GEOMBase::GetShapeTypeString( aSubShape );
373 if ( !aType.isEmpty() )
374 aSubShapeList.append( QString( "%1_%2" ).arg( aType ).arg( aObjLst[i] ) );
377 myGrp->ListBox2->clear();
378 myGrp->ListBox2->addItems( aSubShapeList );
381 //=================================================================================
382 // function : onSubShapesListSelectionChanged
384 //=================================================================================
385 void MeasureGUI_CheckCompoundOfBlocksDlg::onSubShapesListSelectionChanged()
388 int aErrCurItem = myGrp->ListBox1->currentRow();
389 if ( aErrCurItem < 0 )
392 for ( int i = 0, n = myGrp->ListBox2->count(); i < n; i++ ) {
393 if ( myGrp->ListBox2->item( i )->isSelected() )
396 if ( aIds.count() < 1 )
398 bool isCompoundOfBlocks;
399 GEOM::GEOM_IBlocksOperations::BCErrors aErrs;
400 if ( !getBCErrors( isCompoundOfBlocks, aErrs ) ) {
401 myGrp->TextView1->setText( "" );
402 myGrp->ListBox1->clear();
403 myGrp->ListBox2->clear();
407 GEOM::GEOM_IBlocksOperations::BCError aErr = aErrs[aErrCurItem];
408 GEOM::ListOfLong aObjLst = aErr.incriminated;
409 TopoDS_Shape aSelShape;
410 TopoDS_Shape aSubShape;
411 TopTools_IndexedMapOfShape anIndices;
412 if ( !myObj->_is_nil() && GEOMBase::GetShape( myObj, aSelShape ) ) {
414 if ( !isValid( aMess ) ) {
417 SALOME_Prs* aPrs = 0;
418 TopExp::MapShapes( aSelShape, anIndices);
419 QList<int>::iterator it;
420 for ( it = aIds.begin(); it != aIds.end(); ++it ) {
421 aSubShape = anIndices.FindKey(aObjLst[(*it)]);
422 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
423 int w = resMgr->integerValue("Geometry", "measures_line_width", 1);
425 getDisplayer()->SetColor( Quantity_NOC_RED );
426 getDisplayer()->SetWidth( w );
427 getDisplayer()->SetToActivate( false );
428 aPrs = !aSubShape.IsNull() ? getDisplayer()->BuildPrs( aSubShape ) : 0;
430 displayPreview( aPrs, true );
432 catch ( const SALOME::SALOME_Exception& e ) {
433 SalomeApp_Tools::QtCatchCorbaException( e );
439 //=================================================================================
440 // function : activateSelection
441 // purpose : activate selection of faces, shells, and solids
442 //=================================================================================
443 void MeasureGUI_CheckCompoundOfBlocksDlg::activateSelection()
445 TColStd_MapOfInteger aMap;
446 aMap.Add( GEOM_SOLID );
447 aMap.Add( GEOM_COMPOUND );
448 globalSelection( aMap );
451 //=================================================================================
452 // function : enterEvent()
454 //=================================================================================
455 void MeasureGUI_CheckCompoundOfBlocksDlg::enterEvent( QEvent* )
457 if ( !mainFrame()->GroupConstructors->isEnabled() )
458 ActivateThisDialog();
461 //=================================================================================
462 // function : isValid
464 //=================================================================================
465 bool MeasureGUI_CheckCompoundOfBlocksDlg::isValid( QString& )
467 return !myObj->_is_nil();
470 //=================================================================================
471 // function : execute
473 //=================================================================================
474 bool MeasureGUI_CheckCompoundOfBlocksDlg::execute( ObjectList& objects )
476 GEOM::GEOM_IBlocksOperations_var anOper = GEOM::GEOM_IBlocksOperations::_narrow( getOperation() );
477 GEOM::GEOM_Object_var anObj = anOper->CheckAndImprove( myObj );
479 if ( !anObj->_is_nil() )
480 objects.push_back( anObj._retn() );