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"
31 #include "SALOMEGUI_QtCatchCorbaException.hxx"
33 #include "utilities.h"
34 #include "QAD_Desktop.h"
35 #include <TopTools_IndexedMapOfShape.hxx>
38 #include "GEOMImpl_Types.hxx"
40 #include <qtextedit.h>
41 #include <qlineedit.h>
43 #include <qpushbutton.h>
44 #include <qradiobutton.h>
45 #include <qbuttongroup.h>
47 #include <qgroupbox.h>
49 #include <qvaluelist.h>
51 //VRV: porting on Qt 3.0.5
52 #if QT_VERSION >= 0x030005
55 //VRV: porting on Qt 3.0.5
57 #define TEXTEDIT_FONT_FAMILY "Courier"
58 #define TEXTEDIT_FONT_SIZE 11
60 //=================================================================================
61 // class : MeasureGUI_CheckCompoundOfBlocksDlg()
62 // purpose : Constructs a MeasureGUI_CheckCompoundOfBlocksDlg which is a child of 'parent', with the
63 // name 'name' and widget flags set to 'f'.
64 // The dialog will by default be modeless, unless you set 'modal' to
65 // TRUE to construct a modal dialog.
66 //=================================================================================
67 MeasureGUI_CheckCompoundOfBlocksDlg::MeasureGUI_CheckCompoundOfBlocksDlg( QWidget* parent, SALOME_Selection* Sel )
68 : MeasureGUI_Skeleton( parent, "MeasureGUI_CheckCompoundOfBlocksDlg", Sel )
70 QPixmap image0( QAD_Desktop::getResourceManager()->loadPixmap(
71 "GEOM",tr( "ICON_DLG_CHECK_COMPOUND_OF_BLOCKS" ) ) );
72 QPixmap image1( QAD_Desktop::getResourceManager()->loadPixmap(
73 "GEOM",tr( "ICON_SELECT" ) ) );
75 setCaption( tr( "GEOM_CHECK_BLOCKS_COMPOUND" ) );
77 /***************************************************************/
79 GroupConstructors->setTitle( tr( "GEOM_CHECK_BLOCKS_COMPOUND" ) );
80 RadioButton1->setPixmap( image0 );
82 myGrp = new MeasureGUI_1Sel1TextView_QTD( this, "myGrp" );
83 myGrp->GroupBox1->setTitle( tr( "GEOM_CHECK_INFOS" ) );
84 myGrp->TextLabel1->setText( tr( "GEOM_OBJECT" ) );
85 myGrp->TextEdit1->setReadOnly( TRUE );
87 QFont aFont( TEXTEDIT_FONT_FAMILY, TEXTEDIT_FONT_SIZE );
88 aFont.setStyleHint( QFont::TypeWriter, QFont::PreferAntialias );
89 myGrp->TextEdit1->setFont( aFont );
90 myGrp->PushButton1->setPixmap( image1 );
91 myGrp->LineEdit1->setReadOnly( true );
94 /***************************************************************/
95 QGridLayout* aGBLayout = new QGridLayout( myGrp->GroupBox1->layout() );
96 aGBLayout->setAlignment( Qt::AlignTop );
97 QGridLayout* Layout2 = new QGridLayout( 0, 1, 1, 0, 6, "Layout2");
98 myErrorsLbl = new QLabel( tr( "GEOM_CHECK_BLOCKS_COMPOUND_ERRORS" ), myGrp, "Errors" );
99 Layout2->addWidget( myErrorsLbl, 0, 0 );
101 myErrorsLBox = new QListBox( myGrp, "ListBlockCompoundErrors" );
102 myErrorsLBox->setMinimumSize( 100, 100 );
103 Layout2->addWidget( myErrorsLBox, 1, 0 );
106 mySubShapesLbl = new QLabel( tr( "GEOM_CHECK_BLOCKS_COMPOUND_SUBSHAPES" ), myGrp, "BlockCompoundSubShapes" );
107 Layout2->addWidget( mySubShapesLbl, 0, 1 );
109 mySubShapesLBox = new QListBox( myGrp, "ListSubShapes" );
110 mySubShapesLBox->setMinimumSize( 100, 100 );
111 mySubShapesLBox->setSelectionMode(QListBox::Extended);
112 Layout2->addWidget( mySubShapesLBox, 1, 1 );
113 aGBLayout->addLayout( Layout2, 1, 0 );
115 Layout1->addWidget( myGrp, 1, 0 );
116 connect( myErrorsLBox, SIGNAL( selectionChanged() ), SLOT( onErrorsListSelectionChanged() ) );
117 connect( mySubShapesLBox, SIGNAL( selectionChanged() ), SLOT( onSubShapesListSelectionChanged() ) );
123 //=================================================================================
124 // function : ~MeasureGUI_CheckCompoundOfBlocksDlg()
125 // purpose : Destroys the object and frees any allocated resources
126 //=================================================================================
127 MeasureGUI_CheckCompoundOfBlocksDlg::~MeasureGUI_CheckCompoundOfBlocksDlg()
132 //=================================================================================
135 //=================================================================================
136 void MeasureGUI_CheckCompoundOfBlocksDlg::Init( SALOME_Selection* Sel )
139 mySelBtn = myGrp->PushButton1;
140 mySelEdit = myGrp->LineEdit1;
141 MeasureGUI_Skeleton::Init( Sel );
144 //=================================================================================
145 // function : getBCErrors
147 //=================================================================================
148 bool MeasureGUI_CheckCompoundOfBlocksDlg::getBCErrors( bool& theIsCompoundOfBlocks,
149 GEOM::GEOM_IBlocksOperations::BCErrors& theErrors)
151 if ( myObj->_is_nil() )
157 GEOM::GEOM_IBlocksOperations::BCErrors_var aErrs;
158 theIsCompoundOfBlocks =
159 GEOM::GEOM_IBlocksOperations::_narrow( getOperation() )->CheckCompoundOfBlocks( myObj, aErrs );
162 catch( const SALOME::SALOME_Exception& e )
164 QtCatchCorbaException( e );
168 return getOperation()->IsDone();
172 //=================================================================================
173 // function : processObject
175 //=================================================================================
176 void MeasureGUI_CheckCompoundOfBlocksDlg::processObject()
179 bool isCompoundOfBlocks;
180 GEOM::GEOM_IBlocksOperations::BCErrors aErrs;
181 if ( !getBCErrors( isCompoundOfBlocks, aErrs ) )
183 myGrp->TextEdit1->setText( aMsg );
184 myErrorsLBox->clear();
185 mySubShapesLBox->clear();
190 if (isCompoundOfBlocks) {
191 aMsg += tr( "GEOM_CHECK_BLOCKS_COMPOUND_HAS_NO_ERRORS" );
193 aMsg += tr( "GEOM_CHECK_BLOCKS_COMPOUND_HAS_ERRORS" );
195 myGrp->TextEdit1->setText(aMsg);
196 QStringList aErrList;
197 QString aErrStr( "" );
198 QString aConSfx( " # " );
199 QString aGluedSfx( " # " );
202 for ( int i = 0, n = aErrs.length(); i < n; i++ )
205 switch ( aErrs[i].error )
207 case GEOM::GEOM_IBlocksOperations::NOT_BLOCK :
208 aErrStr = "Not a Block";
210 case GEOM::GEOM_IBlocksOperations::EXTRA_EDGE :
211 aErrStr = "Extra Edge";
213 case GEOM::GEOM_IBlocksOperations::INVALID_CONNECTION :
214 aErrStr = "Invalid Connection";
216 aErrStr += QString::number(aConNum);
219 case GEOM::GEOM_IBlocksOperations::NOT_CONNECTED :
220 aErrStr = "Not Connected";
222 case GEOM::GEOM_IBlocksOperations::NOT_GLUED :
223 aErrStr = "Not Glued";
224 aErrStr += aGluedSfx;
225 aErrStr += QString::number(aGluedNum);
232 if ( !aErrStr.isEmpty() )
233 aErrList.append(aErrStr);
235 myErrorsLBox->clear();
236 mySubShapesLBox->clear();
237 myErrorsLBox->insertStringList(aErrList);
241 //=================================================================================
242 // function : createOperation
244 //=================================================================================
245 GEOM::GEOM_IOperations_ptr MeasureGUI_CheckCompoundOfBlocksDlg::createOperation()
247 return getGeomEngine()->GetIBlocksOperations(getStudyId());
250 //=================================================================================
251 // function : onErrorsListSelectionChanged
253 //=================================================================================
254 void MeasureGUI_CheckCompoundOfBlocksDlg::onErrorsListSelectionChanged()
257 int aCurItem = myErrorsLBox->currentItem();
260 bool isCompoundOfBlocks;
261 GEOM::GEOM_IBlocksOperations::BCErrors aErrs;
262 if ( !getBCErrors( isCompoundOfBlocks, aErrs ) )
264 myGrp->TextEdit1->setText( "" );
265 myErrorsLBox->clear();
266 mySubShapesLBox->clear();
270 GEOM::GEOM_IBlocksOperations::BCError aErr = aErrs[aCurItem];
271 GEOM::ListOfLong aObjLst = aErr.incriminated;
272 TopoDS_Shape aSelShape;
273 TopoDS_Shape aSubShape;
274 TopTools_IndexedMapOfShape anIndices;
275 QStringList aSubShapeList;
276 QString aSubShapeName("");
277 Standard_CString aTypeString;
278 if ( !myObj->_is_nil() && GEOMBase::GetShape( myObj, aSelShape ) )
280 TopExp::MapShapes( aSelShape, anIndices);
281 for ( int i = 0, n = aObjLst.length(); i < n; i++ )
284 aSubShape = anIndices.FindKey(aObjLst[i]);
285 if ( GEOMBase::GetShapeTypeString( aSubShape, aTypeString ) )
286 aSubShapeName = QString(aTypeString) + QString("_") + QString::number(aObjLst[i]);
287 if ( !aSubShapeName.isEmpty() )
288 aSubShapeList.append(aSubShapeName);
291 mySubShapesLBox->clear();
292 mySubShapesLBox->insertStringList(aSubShapeList);
296 //=================================================================================
297 // function : onSubShapesListSelectionChanged
299 //=================================================================================
300 void MeasureGUI_CheckCompoundOfBlocksDlg::onSubShapesListSelectionChanged()
303 int aErrCurItem = myErrorsLBox->currentItem();
304 if ( aErrCurItem < 0 )
306 QValueList<int> aIds;
307 for ( int i = 0, n = mySubShapesLBox->count(); i < n; i++ )
309 if ( mySubShapesLBox->isSelected( i ) )
312 if ( aIds.count() < 1 )
314 bool isCompoundOfBlocks;
315 GEOM::GEOM_IBlocksOperations::BCErrors aErrs;
316 if ( !getBCErrors( isCompoundOfBlocks, aErrs ) )
318 myGrp->TextEdit1->setText( "" );
319 myErrorsLBox->clear();
320 mySubShapesLBox->clear();
324 GEOM::GEOM_IBlocksOperations::BCError aErr = aErrs[aErrCurItem];
325 GEOM::ListOfLong aObjLst = aErr.incriminated;
326 TopoDS_Shape aSelShape;
327 TopoDS_Shape aSubShape;
328 TopTools_IndexedMapOfShape anIndices;
329 if ( !myObj->_is_nil() && GEOMBase::GetShape( myObj, aSelShape ) )
332 if ( !isValid( aMess ) )
336 SALOME_Prs* aPrs = 0;
337 TopExp::MapShapes( aSelShape, anIndices);
338 QValueList<int>::iterator it;
339 for ( it = aIds.begin(); it != aIds.end(); ++it )
341 aSubShape = anIndices.FindKey(aObjLst[(*it)]);
344 getDisplayer()->SetColor( Quantity_NOC_RED );
345 getDisplayer()->SetToActivate( false );
346 aPrs = !aSubShape.IsNull() ? getDisplayer()->BuildPrs( aSubShape ) : 0;
348 displayPreview( aPrs, true );
350 catch( const SALOME::SALOME_Exception& e )
352 QtCatchCorbaException( e );
359 //=================================================================================
360 // function : activateSelection
361 // purpose : activate selection of faces, shells, and solids
362 //=================================================================================
363 void MeasureGUI_CheckCompoundOfBlocksDlg::activateSelection()
365 TColStd_MapOfInteger aMap;
366 aMap.Add( GEOM_SOLID );
367 aMap.Add( GEOM_COMPOUND );
368 globalSelection( aMap );