1 // Copyright (C) 2007-2016 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, or (at your option) any later version.
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"
30 #include <SUIT_Session.h>
31 #include <SUIT_ResourceMgr.h>
32 #include <LightApp_SelectionMgr.h>
33 #include <SalomeApp_Tools.h>
34 #include <SalomeApp_Application.h>
36 #include <TopTools_IndexedMapOfShape.hxx>
38 #include <TColStd_MapOfInteger.hxx>
41 #include <GeometryGUI.h>
43 #include <GEOMImpl_Types.hxx>
45 #include <QListWidget>
47 #define TEXTEDIT_FONT_FAMILY "Courier"
48 #define TEXTEDIT_FONT_SIZE 11
50 //=================================================================================
51 // class : MeasureGUI_CheckCompoundOfBlocksDlg()
52 // purpose : Constructs a MeasureGUI_CheckCompoundOfBlocksDlg which is a child of 'parent', with the
53 // name 'name' and widget flags set to 'f'.
54 // The dialog will by default be modeless, unless you set 'modal' to
55 // true to construct a modal dialog.
56 //=================================================================================
57 MeasureGUI_CheckCompoundOfBlocksDlg::MeasureGUI_CheckCompoundOfBlocksDlg( GeometryGUI* GUI, QWidget* parent )
58 : GEOMBase_Skeleton(GUI, parent, false),
68 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
69 QPixmap image0( aResMgr->loadPixmap( "GEOM", tr( "ICON_DLG_CHECK_COMPOUND_OF_BLOCKS" ) ) );
70 QPixmap image1( aResMgr->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
72 setWindowTitle( tr( "GEOM_CHECK_BLOCKS_COMPOUND" ) );
74 /***************************************************************/
75 mainFrame()->GroupConstructors->setTitle( tr( "GEOM_CHECK_BLOCKS_COMPOUND" ) );
76 mainFrame()->RadioButton1->setIcon( image0 );
77 mainFrame()->RadioButton2->setAttribute( Qt::WA_DeleteOnClose );
78 mainFrame()->RadioButton2->close();
79 mainFrame()->RadioButton3->setAttribute( Qt::WA_DeleteOnClose );
80 mainFrame()->RadioButton3->close();
82 QGroupBox *aGrpParams =
83 new QGroupBox(tr("GEOM_CHECK_INFOS"), centralWidget());
84 QGridLayout *aParamsLayout = new QGridLayout(aGrpParams);
85 QLabel *anObjLbl = new QLabel(tr("GEOM_OBJECT"), aGrpParams);
87 new QLabel(tr("GEOM_CHECK_BLOCKS_COMPOUND_ERRORS"), aGrpParams);
88 QLabel *aNonBlocksLbl =
89 new QLabel(tr("GEOM_CHECK_BLOCKS_COMPOUND_SUBSHAPES"), aGrpParams);
91 myObjectName = new QLineEdit(aGrpParams);
92 mySelButton = new QPushButton(aGrpParams);
93 myUseC1Check = new QCheckBox(tr("GEOM_USE_C1_CRITERION"), aGrpParams);
94 myTolLbl = new QLabel(tr("GEOM_ANGULAR_TOLERANCE"), aGrpParams);
95 mySpinTol = new SalomeApp_DoubleSpinBox(aGrpParams);
96 myTextView = new QTextBrowser(aGrpParams);
97 myListBox1 = new QListWidget(aGrpParams);
98 myListBox2 = new QListWidget(aGrpParams);
100 myObjectName->setReadOnly(true);
101 mySelButton->setIcon(image1);
102 mySelButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
103 myUseC1Check->setText(tr("GEOM_USE_C1_CRITERION"));
104 myUseC1Check->setChecked(true);
105 myTextView->setReadOnly(true);
106 myListBox2->setSelectionMode(QAbstractItemView::ExtendedSelection);
108 // Set text view font.
109 QFont aFont(TEXTEDIT_FONT_FAMILY, TEXTEDIT_FONT_SIZE);
111 aFont.setStyleHint(QFont::TypeWriter, QFont::PreferAntialias);
112 myTextView->setFont(aFont);
114 aParamsLayout->setMargin(9);
115 aParamsLayout->setSpacing(6);
116 aParamsLayout->addWidget(anObjLbl, 0, 0);
117 aParamsLayout->addWidget(mySelButton, 0, 1);
118 aParamsLayout->addWidget(myObjectName, 0, 2);
119 aParamsLayout->addWidget(myUseC1Check, 1, 0, 1, 3);
120 aParamsLayout->addWidget(myTolLbl, 2, 0);
121 aParamsLayout->addWidget(mySpinTol, 2, 1, 1, 2);
122 aParamsLayout->addWidget(myTextView, 3, 0, 1, 3);
123 aParamsLayout->addWidget(anErrorsLbl, 4, 0);
124 aParamsLayout->addWidget(myListBox1, 5, 0, 1, 2);
125 aParamsLayout->addWidget(aNonBlocksLbl, 4, 2);
126 aParamsLayout->addWidget(myListBox2, 5, 2);
128 QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
129 layout->setMargin( 0 ); layout->setSpacing( 6 );
130 layout->addWidget( aGrpParams );
132 /***************************************************************/
134 myHelpFileName = "check_compound_of_blocks_page.html";
140 //=================================================================================
141 // function : ~MeasureGUI_CheckCompoundOfBlocksDlg()
142 // purpose : Destroys the object and frees any allocated resources
143 //=================================================================================
144 MeasureGUI_CheckCompoundOfBlocksDlg::~MeasureGUI_CheckCompoundOfBlocksDlg()
148 //=================================================================================
151 //=================================================================================
152 void MeasureGUI_CheckCompoundOfBlocksDlg::Init()
155 double SpecificStep = 0.0001;
156 double aDefaultTol = Precision::Angular();
158 initSpinBox(mySpinTol, aDefaultTol, MAX_NUMBER, SpecificStep, "ang_tol_precision");
159 mySpinTol->setValue(aDefaultTol);
160 myEditCurrentArgument = myObjectName;
162 // signals and slots connections
163 connect( buttonOk(), SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
164 connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
166 connect(myObjectName, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
167 connect(mySelButton, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
168 connect(myListBox1, SIGNAL(itemSelectionChanged()), this, SLOT(onErrorsListSelectionChanged()));
169 connect(myListBox2, SIGNAL(itemSelectionChanged()), this, SLOT(onSubShapesListSelectionChanged()));
170 connect(myUseC1Check, SIGNAL(clicked()), this, SLOT(SetUseC1Tolerance()));
171 connect(mySpinTol, SIGNAL(valueChanged(double)), this, SLOT(processObject()));
173 connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
174 this, SLOT( SelectionIntoArgument() ) );
176 initName( tr( "GEOM_BLOCKS_COMPOUND") );
177 buttonOk()->setEnabled( false );
178 buttonApply()->setEnabled( false );
180 SelectionIntoArgument();
183 //=================================================================================
184 // function : ClickOnOk()
186 //=================================================================================
187 void MeasureGUI_CheckCompoundOfBlocksDlg::ClickOnOk()
189 if ( ClickOnApply() )
193 //=================================================================================
194 // function : ClickOnApply()
196 //=================================================================================
197 bool MeasureGUI_CheckCompoundOfBlocksDlg::ClickOnApply()
206 //=================================================================================
207 // function : SelectionIntoArgument
209 //=================================================================================
210 void MeasureGUI_CheckCompoundOfBlocksDlg::SelectionIntoArgument()
213 myObj = GEOM::GEOM_Object::_nil();
215 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
216 SALOME_ListIO aSelList;
217 aSelMgr->selectedObjects(aSelList);
219 if (aSelList.Extent() != 1) {
220 myObjectName->setText( "" );
225 GEOM::GEOM_Object_var aSelectedObject =
226 GEOMBase::ConvertIOinGEOMObject( aSelList.First() );
228 if ( aSelectedObject->_is_nil() ) {
229 myObjectName->setText( "" );
234 myObj = aSelectedObject;
235 myObjectName->setText( GEOMBase::GetName( myObj ) );
237 DISPLAY_PREVIEW_MACRO;
240 //=================================================================================
241 // function : SetEditCurrentArgument
243 //=================================================================================
244 void MeasureGUI_CheckCompoundOfBlocksDlg::SetEditCurrentArgument()
246 myObjectName->setFocus();
247 myEditCurrentArgument = myObjectName;
248 SelectionIntoArgument();
251 //=================================================================================
252 // function : SetUseC1Tolerance()
254 //=================================================================================
255 void MeasureGUI_CheckCompoundOfBlocksDlg::SetUseC1Tolerance()
257 myTolLbl->setEnabled(myUseC1Check->isChecked());
258 mySpinTol->setEnabled(myUseC1Check->isChecked());
262 //=================================================================================
263 // function : LineEditReturnPressed()
265 //=================================================================================
266 void MeasureGUI_CheckCompoundOfBlocksDlg::LineEditReturnPressed()
268 QLineEdit* send = (QLineEdit*)sender();
269 if ( send == myObjectName ) {
270 myEditCurrentArgument = myObjectName;
271 GEOMBase_Skeleton::LineEditReturnPressed();
275 //=================================================================================
276 // function : ActivateThisDialog()
278 //=================================================================================
279 void MeasureGUI_CheckCompoundOfBlocksDlg::ActivateThisDialog()
281 GEOMBase_Skeleton::ActivateThisDialog();
283 LightApp_SelectionMgr* aSel = myGeomGUI->getApp()->selectionMgr();
285 connect( aSel, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
288 DISPLAY_PREVIEW_MACRO
291 //=================================================================================
292 // function : getBCErrors
294 //=================================================================================
295 bool MeasureGUI_CheckCompoundOfBlocksDlg::getBCErrors( bool& theIsCompoundOfBlocks,
296 GEOM::GEOM_IBlocksOperations::BCErrors& theErrors)
298 if ( myObj->_is_nil() )
301 GEOM::GEOM_IBlocksOperations_var anOper = GEOM::GEOM_IBlocksOperations::_narrow( getOperation() );
303 GEOM::GEOM_IBlocksOperations::BCErrors_var aErrs;
306 if (myUseC1Check->isChecked()) {
307 aC1Tol = mySpinTol->value();
310 theIsCompoundOfBlocks = anOper->CheckCompoundOfBlocks( myObj, aC1Tol, aErrs );
311 if (anOper->IsDone() && aErrs->length() > 0)
312 //if (anOper->IsDone() && !aErrs._is_nil())
315 catch ( const SALOME::SALOME_Exception& e ) {
316 SalomeApp_Tools::QtCatchCorbaException( e );
320 return anOper->IsDone();
324 //=================================================================================
325 // function : processObject
327 //=================================================================================
328 void MeasureGUI_CheckCompoundOfBlocksDlg::processObject()
331 bool isCompoundOfBlocks;
332 GEOM::GEOM_IBlocksOperations::BCErrors aErrs;
333 if ( !getBCErrors( isCompoundOfBlocks, aErrs ) ) {
334 aMsg += tr( "GEOM_CHECK_BLOCKS_COMPOUND_FAILED" );
335 myTextView->setText( aMsg );
342 if ( isCompoundOfBlocks ) {
343 aMsg += tr( "GEOM_CHECK_BLOCKS_COMPOUND_HAS_NO_ERRORS" );
344 buttonOk()->setEnabled( false );
345 buttonApply()->setEnabled( false );
348 aMsg += tr( "GEOM_CHECK_BLOCKS_COMPOUND_HAS_ERRORS" );
349 buttonOk()->setEnabled( true );
350 buttonApply()->setEnabled( true );
352 myTextView->setText( aMsg );
354 QStringList aErrList;
355 QString aErrStr( "" );
356 QString aConSfx( " # " );
357 QString aGluedSfx( " # " );
360 for ( int i = 0, n = aErrs.length(); i < n; i++ ) {
362 switch ( aErrs[i].error ) {
363 case GEOM::GEOM_IBlocksOperations::NOT_BLOCK :
364 aErrStr = tr("GEOM_CHECK_BLOCKS_NOT_BLOCK");
366 case GEOM::GEOM_IBlocksOperations::EXTRA_EDGE :
367 aErrStr = tr("GEOM_CHECK_BLOCKS_EXTRA_EDGE");
369 case GEOM::GEOM_IBlocksOperations::INVALID_CONNECTION :
370 aErrStr = tr("GEOM_CHECK_BLOCKS_INVALID_CONNECTION").arg(aConNum++);
372 case GEOM::GEOM_IBlocksOperations::NOT_CONNECTED :
373 aErrStr = tr("GEOM_CHECK_BLOCKS_NOT_CONNECTED");
375 case GEOM::GEOM_IBlocksOperations::NOT_GLUED :
376 aErrStr = tr("GEOM_CHECK_BLOCKS_NOT_GLUED").arg(aGluedNum++);
382 if ( !aErrStr.isEmpty() )
383 aErrList.append( aErrStr );
388 myListBox1->addItems( aErrList );
391 //=================================================================================
392 // function : createOperation
394 //=================================================================================
395 GEOM::GEOM_IOperations_ptr MeasureGUI_CheckCompoundOfBlocksDlg::createOperation()
397 return getGeomEngine()->GetIBlocksOperations( getStudyId() );
400 //=================================================================================
401 // function : onErrorsListSelectionChanged
403 //=================================================================================
404 void MeasureGUI_CheckCompoundOfBlocksDlg::onErrorsListSelectionChanged()
407 int aCurItem = myListBox1->currentRow();
410 bool isCompoundOfBlocks;
411 GEOM::GEOM_IBlocksOperations::BCErrors aErrs;
412 if ( !getBCErrors( isCompoundOfBlocks, aErrs ) ) {
413 myTextView->setText( "" );
421 if (aCurItem < (int)aErrs.length()) {
422 GEOM::GEOM_IBlocksOperations::BCError aErr = aErrs[aCurItem];
423 GEOM::ListOfLong aObjLst = aErr.incriminated;
424 QStringList aSubShapeList;
425 TopoDS_Shape aSelShape;
426 if ( !myObj->_is_nil() && GEOMBase::GetShape( myObj, aSelShape ) ) {
427 TopTools_IndexedMapOfShape anIndices;
428 TopExp::MapShapes( aSelShape, anIndices );
429 for ( int i = 0, n = aObjLst.length(); i < n; i++ ) {
430 TopoDS_Shape aSubShape = anIndices.FindKey( aObjLst[i] );
431 QString aType = GEOMBase::GetShapeTypeString( aSubShape );
432 if ( !aType.isEmpty() )
433 aSubShapeList.append( QString( "%1_%2" ).arg( aType ).arg( aObjLst[i] ) );
436 myListBox2->addItems( aSubShapeList );
440 //=================================================================================
441 // function : onSubShapesListSelectionChanged
443 //=================================================================================
444 void MeasureGUI_CheckCompoundOfBlocksDlg::onSubShapesListSelectionChanged()
447 int aErrCurItem = myListBox1->currentRow();
448 if ( aErrCurItem < 0 )
451 for ( int i = 0, n = myListBox2->count(); i < n; i++ ) {
452 if ( myListBox2->item( i )->isSelected() )
455 if ( aIds.count() < 1 )
457 bool isCompoundOfBlocks;
458 GEOM::GEOM_IBlocksOperations::BCErrors aErrs;
459 if ( !getBCErrors( isCompoundOfBlocks, aErrs ) ) {
460 myTextView->setText( "" );
466 GEOM::GEOM_IBlocksOperations::BCError aErr = aErrs[aErrCurItem];
467 GEOM::ListOfLong aObjLst = aErr.incriminated;
468 TopoDS_Shape aSelShape;
469 TopoDS_Shape aSubShape;
470 TopTools_IndexedMapOfShape anIndices;
471 if ( !myObj->_is_nil() && GEOMBase::GetShape( myObj, aSelShape ) ) {
473 if ( !isValid( aMess ) ) {
476 SALOME_Prs* aPrs = 0;
477 TopExp::MapShapes( aSelShape, anIndices);
478 QList<int>::iterator it;
479 for ( it = aIds.begin(); it != aIds.end(); ++it ) {
480 aSubShape = anIndices.FindKey(aObjLst[(*it)]);
481 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
482 int w = resMgr->integerValue("Geometry", "preview_edge_width", 1);
484 getDisplayer()->SetColor( Quantity_NOC_RED );
485 getDisplayer()->SetWidth( w );
486 getDisplayer()->SetToActivate( false );
487 aPrs = !aSubShape.IsNull() ? getDisplayer()->BuildPrs( aSubShape ) : 0;
489 displayPreview( aPrs, true );
491 catch ( const SALOME::SALOME_Exception& e ) {
492 SalomeApp_Tools::QtCatchCorbaException( e );
498 //=================================================================================
499 // function : onDisplayPreview
501 //=================================================================================
502 void MeasureGUI_CheckCompoundOfBlocksDlg::onDisplayPreview()
504 DISPLAY_PREVIEW_MACRO;
507 //=================================================================================
508 // function : activateSelection
509 // purpose : activate selection of faces, shells, and solids
510 //=================================================================================
511 void MeasureGUI_CheckCompoundOfBlocksDlg::activateSelection()
513 TColStd_MapOfInteger aMap;
514 aMap.Add( GEOM_SOLID );
515 aMap.Add( GEOM_COMPOUND );
516 globalSelection( aMap );
519 //=================================================================================
520 // function : enterEvent()
522 //=================================================================================
523 void MeasureGUI_CheckCompoundOfBlocksDlg::enterEvent( QEvent* )
525 if ( !mainFrame()->GroupConstructors->isEnabled() )
526 ActivateThisDialog();
529 //=================================================================================
530 // function : isValid
532 //=================================================================================
533 bool MeasureGUI_CheckCompoundOfBlocksDlg::isValid( QString &msg)
535 return !myObj->_is_nil() && mySpinTol->isValid(msg, !IsPreview());
538 //=================================================================================
539 // function : execute
541 //=================================================================================
542 bool MeasureGUI_CheckCompoundOfBlocksDlg::execute( ObjectList& objects )
544 GEOM::GEOM_IBlocksOperations_var anOper = GEOM::GEOM_IBlocksOperations::_narrow( getOperation() );
545 GEOM::GEOM_Object_var anObj = anOper->CheckAndImprove( myObj );
547 if ( !anObj->_is_nil() )
548 objects.push_back( anObj._retn() );