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
24 // File : MeasureGUI_CheckCompoundOfBlocksDlg.cxx
29 #include "MeasureGUI_CheckCompoundOfBlocksDlg.h"
30 #include "MeasureGUI_1Sel1TextView_QTD.h"
32 #include "utilities.h"
33 #include "SUIT_Session.h"
34 #include "LightApp_SelectionMgr.h"
35 #include "SalomeApp_Tools.h"
36 #include "SalomeApp_Application.h"
38 #include <TopTools_IndexedMapOfShape.hxx>
40 #include <TColStd_MapOfInteger.hxx>
42 #include "GEOMImpl_Types.hxx"
44 #include <qtextedit.h>
45 #include <qlineedit.h>
47 #include <qpushbutton.h>
48 #include <qradiobutton.h>
49 #include <qbuttongroup.h>
51 #include <qgroupbox.h>
53 #include <qvaluelist.h>
55 //VRV: porting on Qt 3.0.5
56 #if QT_VERSION >= 0x030005
59 //VRV: porting on Qt 3.0.5
61 #define TEXTEDIT_FONT_FAMILY "Courier"
62 #define TEXTEDIT_FONT_SIZE 11
64 //=================================================================================
65 // class : MeasureGUI_CheckCompoundOfBlocksDlg()
66 // purpose : Constructs a MeasureGUI_CheckCompoundOfBlocksDlg which is a child of 'parent', with the
67 // name 'name' and widget flags set to 'f'.
68 // The dialog will by default be modeless, unless you set 'modal' to
69 // TRUE to construct a modal dialog.
70 //=================================================================================
71 MeasureGUI_CheckCompoundOfBlocksDlg::MeasureGUI_CheckCompoundOfBlocksDlg( GeometryGUI* GUI, QWidget* parent )
72 : GEOMBase_Skeleton(GUI, parent, "MeasureGUI_CheckCompoundOfBlocksDlg", false, WStyle_Customize |
73 WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu | WDestructiveClose)
75 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
76 QPixmap image0 (aResMgr->loadPixmap("GEOM", tr("ICON_DLG_CHECK_COMPOUND_OF_BLOCKS")));
77 QPixmap image1 (aResMgr->loadPixmap("GEOM", tr("ICON_SELECT")));
79 setCaption( tr( "GEOM_CHECK_BLOCKS_COMPOUND" ) );
81 /***************************************************************/
82 GroupConstructors->setTitle( tr( "GEOM_CHECK_BLOCKS_COMPOUND" ) );
83 RadioButton1->setPixmap( image0 );
84 RadioButton2->close( TRUE );
85 RadioButton3->close( TRUE );
87 myGrp = new MeasureGUI_1Sel1TextView_QTD( this, "myGrp" );
88 myGrp->GroupBox1->setTitle( tr( "GEOM_CHECK_INFOS" ) );
89 myGrp->TextLabel1->setText( tr( "GEOM_OBJECT" ) );
91 myGrp->TextEdit1->setReadOnly( TRUE );
92 QFont aFont( TEXTEDIT_FONT_FAMILY, TEXTEDIT_FONT_SIZE );
93 aFont.setStyleHint( QFont::TypeWriter, QFont::PreferAntialias );
94 myGrp->TextEdit1->setFont( aFont );
96 myGrp->PushButton1->setPixmap( image1 );
97 myGrp->LineEdit1->setReadOnly( true );
99 /***************************************************************/
100 QGridLayout* aGBLayout = new QGridLayout( myGrp->GroupBox1->layout() );
101 aGBLayout->setAlignment( Qt::AlignTop );
102 QGridLayout* Layout2 = new QGridLayout( 0, 1, 1, 0, 6, "Layout2");
103 myErrorsLbl = new QLabel( tr( "GEOM_CHECK_BLOCKS_COMPOUND_ERRORS" ), myGrp, "Errors" );
104 Layout2->addWidget( myErrorsLbl, 0, 0 );
106 myErrorsLBox = new QListBox( myGrp, "ListBlockCompoundErrors" );
107 myErrorsLBox->setMinimumSize( 100, 100 );
108 Layout2->addWidget( myErrorsLBox, 1, 0 );
110 mySubShapesLbl = new QLabel( tr( "GEOM_CHECK_BLOCKS_COMPOUND_SUBSHAPES" ),
111 myGrp, "BlockCompoundSubShapes" );
112 Layout2->addWidget( mySubShapesLbl, 0, 1 );
114 mySubShapesLBox = new QListBox( myGrp, "ListSubShapes" );
115 mySubShapesLBox->setMinimumSize( 100, 100 );
116 mySubShapesLBox->setSelectionMode(QListBox::Extended);
117 Layout2->addWidget( mySubShapesLBox, 1, 1 );
118 aGBLayout->addLayout( Layout2, 1, 0 );
120 Layout1->addWidget( myGrp, 2, 0 );
122 connect( myErrorsLBox, SIGNAL( selectionChanged() ), SLOT( onErrorsListSelectionChanged() ) );
123 connect( mySubShapesLBox, SIGNAL( selectionChanged() ), SLOT( onSubShapesListSelectionChanged() ) );
124 /***************************************************************/
126 myHelpFileName = "using_measurement_tools_page.html#check_compound_anchor";
132 //=================================================================================
133 // function : ~MeasureGUI_CheckCompoundOfBlocksDlg()
134 // purpose : Destroys the object and frees any allocated resources
135 //=================================================================================
136 MeasureGUI_CheckCompoundOfBlocksDlg::~MeasureGUI_CheckCompoundOfBlocksDlg()
140 //=================================================================================
143 //=================================================================================
144 void MeasureGUI_CheckCompoundOfBlocksDlg::Init()
146 myEditCurrentArgument = myGrp->LineEdit1;
148 // signals and slots connections
149 connect( buttonOk, SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
150 connect( buttonApply, SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
152 connect( myGrp->LineEdit1, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
153 connect( myGrp->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
155 connect(myGeomGUI->getApp()->selectionMgr(),
156 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
158 initName( tr( "GEOM_BLOCKS_COMPOUND") );
159 buttonOk->setEnabled(false);
160 buttonApply->setEnabled(false);
162 SelectionIntoArgument();
168 //=================================================================================
169 // function : ClickOnOk()
171 //=================================================================================
172 void MeasureGUI_CheckCompoundOfBlocksDlg::ClickOnOk()
178 //=================================================================================
179 // function : ClickOnApply()
181 //=================================================================================
182 bool MeasureGUI_CheckCompoundOfBlocksDlg::ClickOnApply()
191 //=================================================================================
192 // function : SelectionIntoArgument
194 //=================================================================================
195 void MeasureGUI_CheckCompoundOfBlocksDlg::SelectionIntoArgument()
198 myObj = GEOM::GEOM_Object::_nil();
200 if (IObjectCount() != 1) {
201 myGrp->LineEdit1->setText("");
206 Standard_Boolean testResult = Standard_False;
207 GEOM::GEOM_Object_var aSelectedObject =
208 GEOMBase::ConvertIOinGEOMObject( firstIObject(), testResult );
210 if (!testResult || aSelectedObject->_is_nil()) {
211 myGrp->LineEdit1->setText("");
216 myObj = aSelectedObject;
217 myGrp->LineEdit1->setText(GEOMBase::GetName(myObj));
222 //=================================================================================
223 // function : SetEditCurrentArgument
225 //=================================================================================
226 void MeasureGUI_CheckCompoundOfBlocksDlg::SetEditCurrentArgument()
228 myGrp->LineEdit1->setFocus();
229 myEditCurrentArgument = myGrp->LineEdit1;
230 SelectionIntoArgument();
233 //=================================================================================
234 // function : LineEditReturnPressed()
236 //=================================================================================
237 void MeasureGUI_CheckCompoundOfBlocksDlg::LineEditReturnPressed()
239 QLineEdit* send = (QLineEdit*)sender();
240 if (send == myGrp->LineEdit1) {
241 myEditCurrentArgument = myGrp->LineEdit1;
242 GEOMBase_Skeleton::LineEditReturnPressed();
246 //=================================================================================
247 // function : ActivateThisDialog()
249 //=================================================================================
250 void MeasureGUI_CheckCompoundOfBlocksDlg::ActivateThisDialog()
252 GEOMBase_Skeleton::ActivateThisDialog();
254 LightApp_SelectionMgr* aSel = myGeomGUI->getApp()->selectionMgr();
256 connect(aSel, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
262 //=================================================================================
263 // function : getBCErrors
265 //=================================================================================
266 bool MeasureGUI_CheckCompoundOfBlocksDlg::getBCErrors( bool& theIsCompoundOfBlocks,
267 GEOM::GEOM_IBlocksOperations::BCErrors& theErrors)
269 if ( myObj->_is_nil() )
275 GEOM::GEOM_IBlocksOperations::BCErrors_var aErrs;
276 theIsCompoundOfBlocks =
277 GEOM::GEOM_IBlocksOperations::_narrow( getOperation() )->CheckCompoundOfBlocks( myObj, aErrs );
280 catch( const SALOME::SALOME_Exception& e )
282 SalomeApp_Tools::QtCatchCorbaException( e );
286 return getOperation()->IsDone();
290 //=================================================================================
291 // function : processObject
293 //=================================================================================
294 void MeasureGUI_CheckCompoundOfBlocksDlg::processObject()
297 bool isCompoundOfBlocks;
298 GEOM::GEOM_IBlocksOperations::BCErrors aErrs;
299 if ( !getBCErrors( isCompoundOfBlocks, aErrs ) )
301 myGrp->TextEdit1->setText( aMsg );
302 myErrorsLBox->clear();
303 mySubShapesLBox->clear();
308 if (isCompoundOfBlocks) {
309 aMsg += tr( "GEOM_CHECK_BLOCKS_COMPOUND_HAS_NO_ERRORS" );
310 buttonOk->setEnabled(false);
311 buttonApply->setEnabled(false);
313 aMsg += tr( "GEOM_CHECK_BLOCKS_COMPOUND_HAS_ERRORS" );
314 buttonOk->setEnabled(true);
315 buttonApply->setEnabled(true);
317 myGrp->TextEdit1->setText(aMsg);
319 QStringList aErrList;
320 QString aErrStr( "" );
321 QString aConSfx( " # " );
322 QString aGluedSfx( " # " );
325 for ( int i = 0, n = aErrs.length(); i < n; i++ )
328 switch ( aErrs[i].error )
330 case GEOM::GEOM_IBlocksOperations::NOT_BLOCK :
331 aErrStr = "Not a Block";
333 case GEOM::GEOM_IBlocksOperations::EXTRA_EDGE :
334 aErrStr = "Extra Edge";
336 case GEOM::GEOM_IBlocksOperations::INVALID_CONNECTION :
337 aErrStr = "Invalid Connection";
339 aErrStr += QString::number(aConNum);
342 case GEOM::GEOM_IBlocksOperations::NOT_CONNECTED :
343 aErrStr = "Not Connected";
345 case GEOM::GEOM_IBlocksOperations::NOT_GLUED :
346 aErrStr = "Not Glued";
347 aErrStr += aGluedSfx;
348 aErrStr += QString::number(aGluedNum);
355 if ( !aErrStr.isEmpty() )
356 aErrList.append(aErrStr);
359 myErrorsLBox->clear();
360 mySubShapesLBox->clear();
361 myErrorsLBox->insertStringList(aErrList);
364 //=================================================================================
365 // function : createOperation
367 //=================================================================================
368 GEOM::GEOM_IOperations_ptr MeasureGUI_CheckCompoundOfBlocksDlg::createOperation()
370 return getGeomEngine()->GetIBlocksOperations(getStudyId());
373 //=================================================================================
374 // function : onErrorsListSelectionChanged
376 //=================================================================================
377 void MeasureGUI_CheckCompoundOfBlocksDlg::onErrorsListSelectionChanged()
380 int aCurItem = myErrorsLBox->currentItem();
383 bool isCompoundOfBlocks;
384 GEOM::GEOM_IBlocksOperations::BCErrors aErrs;
385 if ( !getBCErrors( isCompoundOfBlocks, aErrs ) )
387 myGrp->TextEdit1->setText( "" );
388 myErrorsLBox->clear();
389 mySubShapesLBox->clear();
393 GEOM::GEOM_IBlocksOperations::BCError aErr = aErrs[aCurItem];
394 GEOM::ListOfLong aObjLst = aErr.incriminated;
395 TopoDS_Shape aSelShape;
396 TopoDS_Shape aSubShape;
397 TopTools_IndexedMapOfShape anIndices;
398 QStringList aSubShapeList;
399 QString aSubShapeName("");
400 Standard_CString aTypeString;
401 if ( !myObj->_is_nil() && GEOMBase::GetShape( myObj, aSelShape ) )
403 TopExp::MapShapes( aSelShape, anIndices);
404 for ( int i = 0, n = aObjLst.length(); i < n; i++ )
407 aSubShape = anIndices.FindKey(aObjLst[i]);
408 if ( GEOMBase::GetShapeTypeString( aSubShape, aTypeString ) )
409 aSubShapeName = QString(aTypeString) + QString("_") + QString::number(aObjLst[i]);
410 if ( !aSubShapeName.isEmpty() )
411 aSubShapeList.append(aSubShapeName);
414 mySubShapesLBox->clear();
415 mySubShapesLBox->insertStringList(aSubShapeList);
418 //=================================================================================
419 // function : onSubShapesListSelectionChanged
421 //=================================================================================
422 void MeasureGUI_CheckCompoundOfBlocksDlg::onSubShapesListSelectionChanged()
425 int aErrCurItem = myErrorsLBox->currentItem();
426 if ( aErrCurItem < 0 )
428 QValueList<int> aIds;
429 for ( int i = 0, n = mySubShapesLBox->count(); i < n; i++ )
431 if ( mySubShapesLBox->isSelected( i ) )
434 if ( aIds.count() < 1 )
436 bool isCompoundOfBlocks;
437 GEOM::GEOM_IBlocksOperations::BCErrors aErrs;
438 if ( !getBCErrors( isCompoundOfBlocks, aErrs ) )
440 myGrp->TextEdit1->setText( "" );
441 myErrorsLBox->clear();
442 mySubShapesLBox->clear();
446 GEOM::GEOM_IBlocksOperations::BCError aErr = aErrs[aErrCurItem];
447 GEOM::ListOfLong aObjLst = aErr.incriminated;
448 TopoDS_Shape aSelShape;
449 TopoDS_Shape aSubShape;
450 TopTools_IndexedMapOfShape anIndices;
451 if ( !myObj->_is_nil() && GEOMBase::GetShape( myObj, aSelShape ) )
454 if ( !isValid( aMess ) )
458 SALOME_Prs* aPrs = 0;
459 TopExp::MapShapes( aSelShape, anIndices);
460 QValueList<int>::iterator it;
461 for ( it = aIds.begin(); it != aIds.end(); ++it )
463 aSubShape = anIndices.FindKey(aObjLst[(*it)]);
466 getDisplayer()->SetColor( Quantity_NOC_RED );
467 getDisplayer()->SetWidth( 3 );
468 getDisplayer()->SetToActivate( false );
469 aPrs = !aSubShape.IsNull() ? getDisplayer()->BuildPrs( aSubShape ) : 0;
471 displayPreview( aPrs, true );
473 catch( const SALOME::SALOME_Exception& e )
475 SalomeApp_Tools::QtCatchCorbaException( e );
481 //=================================================================================
482 // function : activateSelection
483 // purpose : activate selection of faces, shells, and solids
484 //=================================================================================
485 void MeasureGUI_CheckCompoundOfBlocksDlg::activateSelection()
487 TColStd_MapOfInteger aMap;
488 aMap.Add( GEOM_SOLID );
489 aMap.Add( GEOM_COMPOUND );
490 globalSelection( aMap );
493 //=================================================================================
494 // function : enterEvent()
496 //=================================================================================
497 void MeasureGUI_CheckCompoundOfBlocksDlg::enterEvent(QEvent* e)
499 if (!GroupConstructors->isEnabled())
500 ActivateThisDialog();
503 //=================================================================================
504 // function : isValid
506 //=================================================================================
507 bool MeasureGUI_CheckCompoundOfBlocksDlg::isValid( QString& )
509 return !myObj->_is_nil();
512 //=================================================================================
513 // function : execute
515 //=================================================================================
516 bool MeasureGUI_CheckCompoundOfBlocksDlg::execute( ObjectList& objects )
518 GEOM::GEOM_Object_var anObj;
520 anObj = GEOM::GEOM_IBlocksOperations::_narrow(getOperation())->CheckAndImprove(myObj);
522 if (!anObj->_is_nil())
523 objects.push_back(anObj._retn());