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
28 #include "MeasureGUI_CheckCompoundOfBlocksDlg.h"
29 #include "MeasureGUI_1Sel1TextView_QTD.h"
31 #include "utilities.h"
32 #include "SUIT_Session.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>
41 #include "GEOMImpl_Types.hxx"
43 #include <qtextedit.h>
44 #include <qlineedit.h>
46 #include <qpushbutton.h>
47 #include <qradiobutton.h>
48 #include <qbuttongroup.h>
50 #include <qgroupbox.h>
52 #include <qvaluelist.h>
54 //VRV: porting on Qt 3.0.5
55 #if QT_VERSION >= 0x030005
58 //VRV: porting on Qt 3.0.5
60 #define TEXTEDIT_FONT_FAMILY "Courier"
61 #define TEXTEDIT_FONT_SIZE 11
63 //=================================================================================
64 // class : MeasureGUI_CheckCompoundOfBlocksDlg()
65 // purpose : Constructs a MeasureGUI_CheckCompoundOfBlocksDlg which is a child of 'parent', with the
66 // name 'name' and widget flags set to 'f'.
67 // The dialog will by default be modeless, unless you set 'modal' to
68 // TRUE to construct a modal dialog.
69 //=================================================================================
70 MeasureGUI_CheckCompoundOfBlocksDlg::MeasureGUI_CheckCompoundOfBlocksDlg( GeometryGUI* GUI, QWidget* parent )
71 : GEOMBase_Skeleton(GUI, parent, "MeasureGUI_CheckCompoundOfBlocksDlg", false, WStyle_Customize |
72 WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu | WDestructiveClose)
74 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
75 QPixmap image0 (aResMgr->loadPixmap("GEOM", tr("ICON_DLG_CHECK_COMPOUND_OF_BLOCKS")));
76 QPixmap image1 (aResMgr->loadPixmap("GEOM", tr("ICON_SELECT")));
78 setCaption( tr( "GEOM_CHECK_BLOCKS_COMPOUND" ) );
80 /***************************************************************/
81 GroupConstructors->setTitle( tr( "GEOM_CHECK_BLOCKS_COMPOUND" ) );
82 RadioButton1->setPixmap( image0 );
83 RadioButton2->close( TRUE );
84 RadioButton3->close( TRUE );
86 myGrp = new MeasureGUI_1Sel1TextView_QTD( this, "myGrp" );
87 myGrp->GroupBox1->setTitle( tr( "GEOM_CHECK_INFOS" ) );
88 myGrp->TextLabel1->setText( tr( "GEOM_OBJECT" ) );
90 myGrp->TextEdit1->setReadOnly( TRUE );
91 QFont aFont( TEXTEDIT_FONT_FAMILY, TEXTEDIT_FONT_SIZE );
92 aFont.setStyleHint( QFont::TypeWriter, QFont::PreferAntialias );
93 myGrp->TextEdit1->setFont( aFont );
95 myGrp->PushButton1->setPixmap( image1 );
96 myGrp->LineEdit1->setReadOnly( true );
98 /***************************************************************/
99 QGridLayout* aGBLayout = new QGridLayout( myGrp->GroupBox1->layout() );
100 aGBLayout->setAlignment( Qt::AlignTop );
101 QGridLayout* Layout2 = new QGridLayout( 0, 1, 1, 0, 6, "Layout2");
102 myErrorsLbl = new QLabel( tr( "GEOM_CHECK_BLOCKS_COMPOUND_ERRORS" ), myGrp, "Errors" );
103 Layout2->addWidget( myErrorsLbl, 0, 0 );
105 myErrorsLBox = new QListBox( myGrp, "ListBlockCompoundErrors" );
106 myErrorsLBox->setMinimumSize( 100, 100 );
107 Layout2->addWidget( myErrorsLBox, 1, 0 );
109 mySubShapesLbl = new QLabel( tr( "GEOM_CHECK_BLOCKS_COMPOUND_SUBSHAPES" ),
110 myGrp, "BlockCompoundSubShapes" );
111 Layout2->addWidget( mySubShapesLbl, 0, 1 );
113 mySubShapesLBox = new QListBox( myGrp, "ListSubShapes" );
114 mySubShapesLBox->setMinimumSize( 100, 100 );
115 mySubShapesLBox->setSelectionMode(QListBox::Extended);
116 Layout2->addWidget( mySubShapesLBox, 1, 1 );
117 aGBLayout->addLayout( Layout2, 1, 0 );
119 Layout1->addWidget( myGrp, 2, 0 );
121 connect( myErrorsLBox, SIGNAL( selectionChanged() ), SLOT( onErrorsListSelectionChanged() ) );
122 connect( mySubShapesLBox, SIGNAL( selectionChanged() ), SLOT( onSubShapesListSelectionChanged() ) );
123 /***************************************************************/
125 myHelpFileName = "using_measurement_tools_page.html#check_compound_anchor";
131 //=================================================================================
132 // function : ~MeasureGUI_CheckCompoundOfBlocksDlg()
133 // purpose : Destroys the object and frees any allocated resources
134 //=================================================================================
135 MeasureGUI_CheckCompoundOfBlocksDlg::~MeasureGUI_CheckCompoundOfBlocksDlg()
139 //=================================================================================
142 //=================================================================================
143 void MeasureGUI_CheckCompoundOfBlocksDlg::Init()
145 myEditCurrentArgument = myGrp->LineEdit1;
147 // signals and slots connections
148 connect( buttonOk, SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
149 connect( buttonApply, SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
151 connect( myGrp->LineEdit1, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
152 connect( myGrp->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
154 connect(myGeomGUI->getApp()->selectionMgr(),
155 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
157 initName( tr( "GEOM_BLOCKS_COMPOUND") );
158 buttonOk->setEnabled(false);
159 buttonApply->setEnabled(false);
161 SelectionIntoArgument();
167 //=================================================================================
168 // function : ClickOnOk()
170 //=================================================================================
171 void MeasureGUI_CheckCompoundOfBlocksDlg::ClickOnOk()
177 //=================================================================================
178 // function : ClickOnApply()
180 //=================================================================================
181 bool MeasureGUI_CheckCompoundOfBlocksDlg::ClickOnApply()
190 //=================================================================================
191 // function : SelectionIntoArgument
193 //=================================================================================
194 void MeasureGUI_CheckCompoundOfBlocksDlg::SelectionIntoArgument()
197 myObj = GEOM::GEOM_Object::_nil();
199 if (IObjectCount() != 1) {
200 myGrp->LineEdit1->setText("");
205 Standard_Boolean testResult = Standard_False;
206 GEOM::GEOM_Object_var aSelectedObject =
207 GEOMBase::ConvertIOinGEOMObject( firstIObject(), testResult );
209 if (!testResult || aSelectedObject->_is_nil()) {
210 myGrp->LineEdit1->setText("");
215 myObj = aSelectedObject;
216 myGrp->LineEdit1->setText(GEOMBase::GetName(myObj));
221 //=================================================================================
222 // function : SetEditCurrentArgument
224 //=================================================================================
225 void MeasureGUI_CheckCompoundOfBlocksDlg::SetEditCurrentArgument()
227 myGrp->LineEdit1->setFocus();
228 myEditCurrentArgument = myGrp->LineEdit1;
229 SelectionIntoArgument();
232 //=================================================================================
233 // function : LineEditReturnPressed()
235 //=================================================================================
236 void MeasureGUI_CheckCompoundOfBlocksDlg::LineEditReturnPressed()
238 QLineEdit* send = (QLineEdit*)sender();
239 if (send == myGrp->LineEdit1) {
240 myEditCurrentArgument = myGrp->LineEdit1;
241 GEOMBase_Skeleton::LineEditReturnPressed();
245 //=================================================================================
246 // function : ActivateThisDialog()
248 //=================================================================================
249 void MeasureGUI_CheckCompoundOfBlocksDlg::ActivateThisDialog()
251 GEOMBase_Skeleton::ActivateThisDialog();
253 LightApp_SelectionMgr* aSel = myGeomGUI->getApp()->selectionMgr();
255 connect(aSel, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
261 //=================================================================================
262 // function : getBCErrors
264 //=================================================================================
265 bool MeasureGUI_CheckCompoundOfBlocksDlg::getBCErrors( bool& theIsCompoundOfBlocks,
266 GEOM::GEOM_IBlocksOperations::BCErrors& theErrors)
268 if ( myObj->_is_nil() )
274 GEOM::GEOM_IBlocksOperations::BCErrors_var aErrs;
275 theIsCompoundOfBlocks =
276 GEOM::GEOM_IBlocksOperations::_narrow( getOperation() )->CheckCompoundOfBlocks( myObj, aErrs );
279 catch( const SALOME::SALOME_Exception& e )
281 SalomeApp_Tools::QtCatchCorbaException( e );
285 return getOperation()->IsDone();
289 //=================================================================================
290 // function : processObject
292 //=================================================================================
293 void MeasureGUI_CheckCompoundOfBlocksDlg::processObject()
296 bool isCompoundOfBlocks;
297 GEOM::GEOM_IBlocksOperations::BCErrors aErrs;
298 if ( !getBCErrors( isCompoundOfBlocks, aErrs ) )
300 myGrp->TextEdit1->setText( aMsg );
301 myErrorsLBox->clear();
302 mySubShapesLBox->clear();
307 if (isCompoundOfBlocks) {
308 aMsg += tr( "GEOM_CHECK_BLOCKS_COMPOUND_HAS_NO_ERRORS" );
309 buttonOk->setEnabled(false);
310 buttonApply->setEnabled(false);
312 aMsg += tr( "GEOM_CHECK_BLOCKS_COMPOUND_HAS_ERRORS" );
313 buttonOk->setEnabled(true);
314 buttonApply->setEnabled(true);
316 myGrp->TextEdit1->setText(aMsg);
318 QStringList aErrList;
319 QString aErrStr( "" );
320 QString aConSfx( " # " );
321 QString aGluedSfx( " # " );
324 for ( int i = 0, n = aErrs.length(); i < n; i++ )
327 switch ( aErrs[i].error )
329 case GEOM::GEOM_IBlocksOperations::NOT_BLOCK :
330 aErrStr = "Not a Block";
332 case GEOM::GEOM_IBlocksOperations::EXTRA_EDGE :
333 aErrStr = "Extra Edge";
335 case GEOM::GEOM_IBlocksOperations::INVALID_CONNECTION :
336 aErrStr = "Invalid Connection";
338 aErrStr += QString::number(aConNum);
341 case GEOM::GEOM_IBlocksOperations::NOT_CONNECTED :
342 aErrStr = "Not Connected";
344 case GEOM::GEOM_IBlocksOperations::NOT_GLUED :
345 aErrStr = "Not Glued";
346 aErrStr += aGluedSfx;
347 aErrStr += QString::number(aGluedNum);
354 if ( !aErrStr.isEmpty() )
355 aErrList.append(aErrStr);
358 myErrorsLBox->clear();
359 mySubShapesLBox->clear();
360 myErrorsLBox->insertStringList(aErrList);
363 //=================================================================================
364 // function : createOperation
366 //=================================================================================
367 GEOM::GEOM_IOperations_ptr MeasureGUI_CheckCompoundOfBlocksDlg::createOperation()
369 return getGeomEngine()->GetIBlocksOperations(getStudyId());
372 //=================================================================================
373 // function : onErrorsListSelectionChanged
375 //=================================================================================
376 void MeasureGUI_CheckCompoundOfBlocksDlg::onErrorsListSelectionChanged()
379 int aCurItem = myErrorsLBox->currentItem();
382 bool isCompoundOfBlocks;
383 GEOM::GEOM_IBlocksOperations::BCErrors aErrs;
384 if ( !getBCErrors( isCompoundOfBlocks, aErrs ) )
386 myGrp->TextEdit1->setText( "" );
387 myErrorsLBox->clear();
388 mySubShapesLBox->clear();
392 GEOM::GEOM_IBlocksOperations::BCError aErr = aErrs[aCurItem];
393 GEOM::ListOfLong aObjLst = aErr.incriminated;
394 TopoDS_Shape aSelShape;
395 TopoDS_Shape aSubShape;
396 TopTools_IndexedMapOfShape anIndices;
397 QStringList aSubShapeList;
398 QString aSubShapeName("");
399 Standard_CString aTypeString;
400 if ( !myObj->_is_nil() && GEOMBase::GetShape( myObj, aSelShape ) )
402 TopExp::MapShapes( aSelShape, anIndices);
403 for ( int i = 0, n = aObjLst.length(); i < n; i++ )
406 aSubShape = anIndices.FindKey(aObjLst[i]);
407 if ( GEOMBase::GetShapeTypeString( aSubShape, aTypeString ) )
408 aSubShapeName = QString(aTypeString) + QString("_") + QString::number(aObjLst[i]);
409 if ( !aSubShapeName.isEmpty() )
410 aSubShapeList.append(aSubShapeName);
413 mySubShapesLBox->clear();
414 mySubShapesLBox->insertStringList(aSubShapeList);
417 //=================================================================================
418 // function : onSubShapesListSelectionChanged
420 //=================================================================================
421 void MeasureGUI_CheckCompoundOfBlocksDlg::onSubShapesListSelectionChanged()
424 int aErrCurItem = myErrorsLBox->currentItem();
425 if ( aErrCurItem < 0 )
427 QValueList<int> aIds;
428 for ( int i = 0, n = mySubShapesLBox->count(); i < n; i++ )
430 if ( mySubShapesLBox->isSelected( i ) )
433 if ( aIds.count() < 1 )
435 bool isCompoundOfBlocks;
436 GEOM::GEOM_IBlocksOperations::BCErrors aErrs;
437 if ( !getBCErrors( isCompoundOfBlocks, aErrs ) )
439 myGrp->TextEdit1->setText( "" );
440 myErrorsLBox->clear();
441 mySubShapesLBox->clear();
445 GEOM::GEOM_IBlocksOperations::BCError aErr = aErrs[aErrCurItem];
446 GEOM::ListOfLong aObjLst = aErr.incriminated;
447 TopoDS_Shape aSelShape;
448 TopoDS_Shape aSubShape;
449 TopTools_IndexedMapOfShape anIndices;
450 if ( !myObj->_is_nil() && GEOMBase::GetShape( myObj, aSelShape ) )
453 if ( !isValid( aMess ) )
457 SALOME_Prs* aPrs = 0;
458 TopExp::MapShapes( aSelShape, anIndices);
459 QValueList<int>::iterator it;
460 for ( it = aIds.begin(); it != aIds.end(); ++it )
462 aSubShape = anIndices.FindKey(aObjLst[(*it)]);
465 getDisplayer()->SetColor( Quantity_NOC_RED );
466 getDisplayer()->SetWidth( 3 );
467 getDisplayer()->SetToActivate( false );
468 aPrs = !aSubShape.IsNull() ? getDisplayer()->BuildPrs( aSubShape ) : 0;
470 displayPreview( aPrs, true );
472 catch( const SALOME::SALOME_Exception& e )
474 SalomeApp_Tools::QtCatchCorbaException( e );
480 //=================================================================================
481 // function : activateSelection
482 // purpose : activate selection of faces, shells, and solids
483 //=================================================================================
484 void MeasureGUI_CheckCompoundOfBlocksDlg::activateSelection()
486 TColStd_MapOfInteger aMap;
487 aMap.Add( GEOM_SOLID );
488 aMap.Add( GEOM_COMPOUND );
489 globalSelection( aMap );
492 //=================================================================================
493 // function : enterEvent()
495 //=================================================================================
496 void MeasureGUI_CheckCompoundOfBlocksDlg::enterEvent(QEvent* e)
498 if (!GroupConstructors->isEnabled())
499 ActivateThisDialog();
502 //=================================================================================
503 // function : isValid
505 //=================================================================================
506 bool MeasureGUI_CheckCompoundOfBlocksDlg::isValid( QString& )
508 return !myObj->_is_nil();
511 //=================================================================================
512 // function : execute
514 //=================================================================================
515 bool MeasureGUI_CheckCompoundOfBlocksDlg::execute( ObjectList& objects )
517 GEOM::GEOM_Object_var anObj;
519 anObj = GEOM::GEOM_IBlocksOperations::_narrow(getOperation())->CheckAndImprove(myObj);
521 if (!anObj->_is_nil())
522 objects.push_back(anObj._retn());