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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
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 "SalomeApp_Tools.h"
36 #include <TopTools_IndexedMapOfShape.hxx>
38 #include <TColStd_MapOfInteger.hxx>
40 #include "GEOMImpl_Types.hxx"
42 #include <qtextedit.h>
43 #include <qlineedit.h>
45 #include <qpushbutton.h>
46 #include <qradiobutton.h>
47 #include <qbuttongroup.h>
49 #include <qgroupbox.h>
51 #include <qvaluelist.h>
53 //VRV: porting on Qt 3.0.5
54 #if QT_VERSION >= 0x030005
57 //VRV: porting on Qt 3.0.5
59 #define TEXTEDIT_FONT_FAMILY "Courier"
60 #define TEXTEDIT_FONT_SIZE 11
62 //=================================================================================
63 // class : MeasureGUI_CheckCompoundOfBlocksDlg()
64 // purpose : Constructs a MeasureGUI_CheckCompoundOfBlocksDlg which is a child of 'parent', with the
65 // name 'name' and widget flags set to 'f'.
66 // The dialog will by default be modeless, unless you set 'modal' to
67 // TRUE to construct a modal dialog.
68 //=================================================================================
69 MeasureGUI_CheckCompoundOfBlocksDlg::MeasureGUI_CheckCompoundOfBlocksDlg( GeometryGUI* GUI, QWidget* parent )
70 : MeasureGUI_Skeleton( GUI, parent, "MeasureGUI_CheckCompoundOfBlocksDlg" )
72 QPixmap image0( SUIT_Session::session()->resourceMgr()->loadPixmap(
73 "GEOM",tr( "ICON_DLG_CHECK_COMPOUND_OF_BLOCKS" ) ) );
74 QPixmap image1( SUIT_Session::session()->resourceMgr()->loadPixmap(
75 "GEOM",tr( "ICON_SELECT" ) ) );
77 setCaption( tr( "GEOM_CHECK_BLOCKS_COMPOUND" ) );
79 /***************************************************************/
81 GroupConstructors->setTitle( tr( "GEOM_CHECK_BLOCKS_COMPOUND" ) );
82 RadioButton1->setPixmap( image0 );
84 myGrp = new MeasureGUI_1Sel1TextView_QTD( this, "myGrp" );
85 myGrp->GroupBox1->setTitle( tr( "GEOM_CHECK_INFOS" ) );
86 myGrp->TextLabel1->setText( tr( "GEOM_OBJECT" ) );
87 myGrp->TextEdit1->setReadOnly( TRUE );
89 QFont aFont( TEXTEDIT_FONT_FAMILY, TEXTEDIT_FONT_SIZE );
90 aFont.setStyleHint( QFont::TypeWriter, QFont::PreferAntialias );
91 myGrp->TextEdit1->setFont( aFont );
92 myGrp->PushButton1->setPixmap( image1 );
93 myGrp->LineEdit1->setReadOnly( true );
96 /***************************************************************/
97 QGridLayout* aGBLayout = new QGridLayout( myGrp->GroupBox1->layout() );
98 aGBLayout->setAlignment( Qt::AlignTop );
99 QGridLayout* Layout2 = new QGridLayout( 0, 1, 1, 0, 6, "Layout2");
100 myErrorsLbl = new QLabel( tr( "GEOM_CHECK_BLOCKS_COMPOUND_ERRORS" ), myGrp, "Errors" );
101 Layout2->addWidget( myErrorsLbl, 0, 0 );
103 myErrorsLBox = new QListBox( myGrp, "ListBlockCompoundErrors" );
104 myErrorsLBox->setMinimumSize( 100, 100 );
105 Layout2->addWidget( myErrorsLBox, 1, 0 );
108 mySubShapesLbl = new QLabel( tr( "GEOM_CHECK_BLOCKS_COMPOUND_SUBSHAPES" ), myGrp, "BlockCompoundSubShapes" );
109 Layout2->addWidget( mySubShapesLbl, 0, 1 );
111 mySubShapesLBox = new QListBox( myGrp, "ListSubShapes" );
112 mySubShapesLBox->setMinimumSize( 100, 100 );
113 mySubShapesLBox->setSelectionMode(QListBox::Extended);
114 Layout2->addWidget( mySubShapesLBox, 1, 1 );
115 aGBLayout->addLayout( Layout2, 1, 0 );
117 Layout1->addWidget( myGrp, 1, 0 );
118 connect( myErrorsLBox, SIGNAL( selectionChanged() ), SLOT( onErrorsListSelectionChanged() ) );
119 connect( mySubShapesLBox, SIGNAL( selectionChanged() ), SLOT( onSubShapesListSelectionChanged() ) );
125 //=================================================================================
126 // function : ~MeasureGUI_CheckCompoundOfBlocksDlg()
127 // purpose : Destroys the object and frees any allocated resources
128 //=================================================================================
129 MeasureGUI_CheckCompoundOfBlocksDlg::~MeasureGUI_CheckCompoundOfBlocksDlg()
134 //=================================================================================
137 //=================================================================================
138 void MeasureGUI_CheckCompoundOfBlocksDlg::Init()
141 mySelBtn = myGrp->PushButton1;
142 mySelEdit = myGrp->LineEdit1;
143 MeasureGUI_Skeleton::Init();
146 //=================================================================================
147 // function : getBCErrors
149 //=================================================================================
150 bool MeasureGUI_CheckCompoundOfBlocksDlg::getBCErrors( bool& theIsCompoundOfBlocks,
151 GEOM::GEOM_IBlocksOperations::BCErrors& theErrors)
153 if ( myObj->_is_nil() )
159 GEOM::GEOM_IBlocksOperations::BCErrors_var aErrs;
160 theIsCompoundOfBlocks =
161 GEOM::GEOM_IBlocksOperations::_narrow( getOperation() )->CheckCompoundOfBlocks( myObj, aErrs );
164 catch( const SALOME::SALOME_Exception& e )
166 SalomeApp_Tools::QtCatchCorbaException( e );
170 return getOperation()->IsDone();
174 //=================================================================================
175 // function : processObject
177 //=================================================================================
178 void MeasureGUI_CheckCompoundOfBlocksDlg::processObject()
181 bool isCompoundOfBlocks;
182 GEOM::GEOM_IBlocksOperations::BCErrors aErrs;
183 if ( !getBCErrors( isCompoundOfBlocks, aErrs ) )
185 myGrp->TextEdit1->setText( aMsg );
186 myErrorsLBox->clear();
187 mySubShapesLBox->clear();
192 if (isCompoundOfBlocks) {
193 aMsg += tr( "GEOM_CHECK_BLOCKS_COMPOUND_HAS_NO_ERRORS" );
195 aMsg += tr( "GEOM_CHECK_BLOCKS_COMPOUND_HAS_ERRORS" );
197 myGrp->TextEdit1->setText(aMsg);
198 QStringList aErrList;
199 QString aErrStr( "" );
200 QString aConSfx( " # " );
201 QString aGluedSfx( " # " );
204 for ( int i = 0, n = aErrs.length(); i < n; i++ )
207 switch ( aErrs[i].error )
209 case GEOM::GEOM_IBlocksOperations::NOT_BLOCK :
210 aErrStr = "Not a Block";
212 case GEOM::GEOM_IBlocksOperations::EXTRA_EDGE :
213 aErrStr = "Extra Edge";
215 case GEOM::GEOM_IBlocksOperations::INVALID_CONNECTION :
216 aErrStr = "Invalid Connection";
218 aErrStr += QString::number(aConNum);
221 case GEOM::GEOM_IBlocksOperations::NOT_CONNECTED :
222 aErrStr = "Not Connected";
224 case GEOM::GEOM_IBlocksOperations::NOT_GLUED :
225 aErrStr = "Not Glued";
226 aErrStr += aGluedSfx;
227 aErrStr += QString::number(aGluedNum);
234 if ( !aErrStr.isEmpty() )
235 aErrList.append(aErrStr);
237 myErrorsLBox->clear();
238 mySubShapesLBox->clear();
239 myErrorsLBox->insertStringList(aErrList);
243 //=================================================================================
244 // function : createOperation
246 //=================================================================================
247 GEOM::GEOM_IOperations_ptr MeasureGUI_CheckCompoundOfBlocksDlg::createOperation()
249 return getGeomEngine()->GetIBlocksOperations(getStudyId());
252 //=================================================================================
253 // function : onErrorsListSelectionChanged
255 //=================================================================================
256 void MeasureGUI_CheckCompoundOfBlocksDlg::onErrorsListSelectionChanged()
259 int aCurItem = myErrorsLBox->currentItem();
262 bool isCompoundOfBlocks;
263 GEOM::GEOM_IBlocksOperations::BCErrors aErrs;
264 if ( !getBCErrors( isCompoundOfBlocks, aErrs ) )
266 myGrp->TextEdit1->setText( "" );
267 myErrorsLBox->clear();
268 mySubShapesLBox->clear();
272 GEOM::GEOM_IBlocksOperations::BCError aErr = aErrs[aCurItem];
273 GEOM::ListOfLong aObjLst = aErr.incriminated;
274 TopoDS_Shape aSelShape;
275 TopoDS_Shape aSubShape;
276 TopTools_IndexedMapOfShape anIndices;
277 QStringList aSubShapeList;
278 QString aSubShapeName("");
279 Standard_CString aTypeString;
280 if ( !myObj->_is_nil() && GEOMBase::GetShape( myObj, aSelShape ) )
282 TopExp::MapShapes( aSelShape, anIndices);
283 for ( int i = 0, n = aObjLst.length(); i < n; i++ )
286 aSubShape = anIndices.FindKey(aObjLst[i]);
287 if ( GEOMBase::GetShapeTypeString( aSubShape, aTypeString ) )
288 aSubShapeName = QString(aTypeString) + QString("_") + QString::number(aObjLst[i]);
289 if ( !aSubShapeName.isEmpty() )
290 aSubShapeList.append(aSubShapeName);
293 mySubShapesLBox->clear();
294 mySubShapesLBox->insertStringList(aSubShapeList);
298 //=================================================================================
299 // function : onSubShapesListSelectionChanged
301 //=================================================================================
302 void MeasureGUI_CheckCompoundOfBlocksDlg::onSubShapesListSelectionChanged()
305 int aErrCurItem = myErrorsLBox->currentItem();
306 if ( aErrCurItem < 0 )
308 QValueList<int> aIds;
309 for ( int i = 0, n = mySubShapesLBox->count(); i < n; i++ )
311 if ( mySubShapesLBox->isSelected( i ) )
314 if ( aIds.count() < 1 )
316 bool isCompoundOfBlocks;
317 GEOM::GEOM_IBlocksOperations::BCErrors aErrs;
318 if ( !getBCErrors( isCompoundOfBlocks, aErrs ) )
320 myGrp->TextEdit1->setText( "" );
321 myErrorsLBox->clear();
322 mySubShapesLBox->clear();
326 GEOM::GEOM_IBlocksOperations::BCError aErr = aErrs[aErrCurItem];
327 GEOM::ListOfLong aObjLst = aErr.incriminated;
328 TopoDS_Shape aSelShape;
329 TopoDS_Shape aSubShape;
330 TopTools_IndexedMapOfShape anIndices;
331 if ( !myObj->_is_nil() && GEOMBase::GetShape( myObj, aSelShape ) )
334 if ( !isValid( aMess ) )
338 SALOME_Prs* aPrs = 0;
339 TopExp::MapShapes( aSelShape, anIndices);
340 QValueList<int>::iterator it;
341 for ( it = aIds.begin(); it != aIds.end(); ++it )
343 aSubShape = anIndices.FindKey(aObjLst[(*it)]);
346 getDisplayer()->SetColor( Quantity_NOC_RED );
347 getDisplayer()->SetToActivate( false );
348 aPrs = !aSubShape.IsNull() ? getDisplayer()->BuildPrs( aSubShape ) : 0;
350 displayPreview( aPrs, true );
352 catch( const SALOME::SALOME_Exception& e )
354 SalomeApp_Tools::QtCatchCorbaException( e );
361 //=================================================================================
362 // function : activateSelection
363 // purpose : activate selection of faces, shells, and solids
364 //=================================================================================
365 void MeasureGUI_CheckCompoundOfBlocksDlg::activateSelection()
367 TColStd_MapOfInteger aMap;
368 aMap.Add( GEOM_SOLID );
369 aMap.Add( GEOM_COMPOUND );
370 globalSelection( aMap );