Back to index

salome-geom  6.5.0
MeasureGUI_CheckCompoundOfBlocksDlg.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 // GEOM GEOMGUI : GUI for Geometry component
00024 // File   : MeasureGUI_CheckCompoundOfBlocksDlg.cxx
00025 // Author : Vladimir KLYACHIN, Open CASCADE S.A.S. (vladimir.klyachin@opencascade.com)
00026 //
00027 #include "MeasureGUI.h"
00028 #include "MeasureGUI_CheckCompoundOfBlocksDlg.h"
00029 #include "MeasureGUI_Widgets.h"
00030 
00031 #include <SUIT_Session.h>
00032 #include <SUIT_ResourceMgr.h>
00033 #include <LightApp_SelectionMgr.h>
00034 #include <SalomeApp_Tools.h>
00035 #include <SalomeApp_Application.h>
00036 
00037 #include <TopTools_IndexedMapOfShape.hxx>
00038 #include <TopExp.hxx>
00039 #include <TColStd_MapOfInteger.hxx>
00040 
00041 #include <DlgRef.h>
00042 #include <GeometryGUI.h>
00043 #include <GEOMBase.h>
00044 #include <GEOMImpl_Types.hxx>
00045 
00046 #define TEXTEDIT_FONT_FAMILY "Courier"
00047 #define TEXTEDIT_FONT_SIZE 11
00048 
00049 //=================================================================================
00050 // class    : MeasureGUI_CheckCompoundOfBlocksDlg()
00051 // purpose  : Constructs a MeasureGUI_CheckCompoundOfBlocksDlg which is a child of 'parent', with the
00052 //            name 'name' and widget flags set to 'f'.
00053 //            The dialog will by default be modeless, unless you set 'modal' to
00054 //            true to construct a modal dialog.
00055 //=================================================================================
00056 MeasureGUI_CheckCompoundOfBlocksDlg::MeasureGUI_CheckCompoundOfBlocksDlg( GeometryGUI* GUI, QWidget* parent )
00057   : GEOMBase_Skeleton( GUI, parent, false )
00058 {
00059   SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
00060   QPixmap image0( aResMgr->loadPixmap( "GEOM", tr( "ICON_DLG_CHECK_COMPOUND_OF_BLOCKS" ) ) );
00061   QPixmap image1( aResMgr->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
00062 
00063   setWindowTitle( tr( "GEOM_CHECK_BLOCKS_COMPOUND" ) );
00064 
00065   /***************************************************************/
00066   mainFrame()->GroupConstructors->setTitle( tr( "GEOM_CHECK_BLOCKS_COMPOUND" ) );
00067   mainFrame()->RadioButton1->setIcon( image0 );
00068   mainFrame()->RadioButton2->setAttribute( Qt::WA_DeleteOnClose );
00069   mainFrame()->RadioButton2->close();
00070   mainFrame()->RadioButton3->setAttribute( Qt::WA_DeleteOnClose );
00071   mainFrame()->RadioButton3->close();
00072 
00073   myGrp = new MeasureGUI_1Sel1TextView2ListBox( centralWidget() );
00074   myGrp->GroupBox1->setTitle( tr( "GEOM_CHECK_INFOS" ) );
00075   myGrp->TextLabel1->setText( tr( "GEOM_OBJECT" ) );
00076 
00077   myGrp->TextView1->setReadOnly( true );
00078   QFont aFont( TEXTEDIT_FONT_FAMILY, TEXTEDIT_FONT_SIZE );
00079   aFont.setStyleHint( QFont::TypeWriter, QFont::PreferAntialias );
00080   myGrp->TextView1->setFont( aFont );
00081 
00082   myGrp->PushButton1->setIcon( image1 );
00083   myGrp->LineEdit1->setReadOnly( true );
00084 
00085   myGrp->TextLabel2->setText( tr( "GEOM_CHECK_BLOCKS_COMPOUND_ERRORS" ) );
00086   myGrp->TextLabel3->setText( tr( "GEOM_CHECK_BLOCKS_COMPOUND_SUBSHAPES" ) );
00087 
00088   myGrp->ListBox2->setSelectionMode( QAbstractItemView::ExtendedSelection );
00089 
00090   QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
00091   layout->setMargin( 0 ); layout->setSpacing( 6 );
00092   layout->addWidget( myGrp );
00093 
00094   connect( myGrp->ListBox1, SIGNAL( itemSelectionChanged() ), SLOT( onErrorsListSelectionChanged() ) );
00095   connect( myGrp->ListBox2, SIGNAL( itemSelectionChanged() ), SLOT( onSubShapesListSelectionChanged() ) );
00096 
00097   /***************************************************************/
00098 
00099   myHelpFileName = "using_measurement_tools_page.html#check_compound_anchor";
00100 
00101   /* Initialisation */
00102   Init();
00103 }
00104 
00105 //=================================================================================
00106 // function : ~MeasureGUI_CheckCompoundOfBlocksDlg()
00107 // purpose  : Destroys the object and frees any allocated resources
00108 //=================================================================================
00109 MeasureGUI_CheckCompoundOfBlocksDlg::~MeasureGUI_CheckCompoundOfBlocksDlg()
00110 {
00111 }
00112 
00113 //=================================================================================
00114 // function : Init()
00115 // purpose  :
00116 //=================================================================================
00117 void MeasureGUI_CheckCompoundOfBlocksDlg::Init()
00118 {
00119   myEditCurrentArgument = myGrp->LineEdit1;
00120 
00121   // signals and slots connections
00122   connect( buttonOk(),    SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
00123   connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
00124 
00125   connect( myGrp->LineEdit1,   SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
00126   connect( myGrp->PushButton1, SIGNAL( clicked() ),       this, SLOT( SetEditCurrentArgument() ) );
00127 
00128   connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
00129            this, SLOT( SelectionIntoArgument() ) );
00130 
00131   initName( tr( "GEOM_BLOCKS_COMPOUND") );
00132   buttonOk()->setEnabled( false );
00133   buttonApply()->setEnabled( false );
00134   activateSelection();
00135   SelectionIntoArgument();
00136 }
00137 
00138 //=================================================================================
00139 // function : ClickOnOk()
00140 // purpose  :
00141 //=================================================================================
00142 void MeasureGUI_CheckCompoundOfBlocksDlg::ClickOnOk()
00143 {
00144   if ( ClickOnApply() )
00145     ClickOnCancel();
00146 }
00147 
00148 //=================================================================================
00149 // function : ClickOnApply()
00150 // purpose  :
00151 //=================================================================================
00152 bool MeasureGUI_CheckCompoundOfBlocksDlg::ClickOnApply()
00153 {
00154   if ( !onAccept() )
00155     return false;
00156 
00157   initName();
00158   return true;
00159 }
00160 
00161 //=================================================================================
00162 // function : SelectionIntoArgument
00163 // purpose  :
00164 //=================================================================================
00165 void MeasureGUI_CheckCompoundOfBlocksDlg::SelectionIntoArgument()
00166 {
00167   erasePreview();
00168   myObj = GEOM::GEOM_Object::_nil();
00169 
00170   LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
00171   SALOME_ListIO aSelList;
00172   aSelMgr->selectedObjects(aSelList);
00173 
00174   if (aSelList.Extent() != 1) {
00175     myGrp->LineEdit1->setText( "" );
00176     processObject();
00177     return;
00178   }
00179 
00180   GEOM::GEOM_Object_var aSelectedObject =
00181     GEOMBase::ConvertIOinGEOMObject( aSelList.First() );
00182 
00183   if ( aSelectedObject->_is_nil() ) {
00184     myGrp->LineEdit1->setText( "" );
00185     processObject();
00186     return;
00187   }
00188 
00189   myObj = aSelectedObject;
00190   myGrp->LineEdit1->setText( GEOMBase::GetName( myObj ) );
00191   processObject();
00192   DISPLAY_PREVIEW_MACRO;
00193 }
00194 
00195 //=================================================================================
00196 // function : SetEditCurrentArgument
00197 // purpose  :
00198 //=================================================================================
00199 void MeasureGUI_CheckCompoundOfBlocksDlg::SetEditCurrentArgument()
00200 {
00201   myGrp->LineEdit1->setFocus();
00202   myEditCurrentArgument = myGrp->LineEdit1;
00203   SelectionIntoArgument();
00204 }
00205 
00206 //=================================================================================
00207 // function : LineEditReturnPressed()
00208 // purpose  :
00209 //=================================================================================
00210 void MeasureGUI_CheckCompoundOfBlocksDlg::LineEditReturnPressed()
00211 {
00212   QLineEdit* send = (QLineEdit*)sender();
00213   if ( send == myGrp->LineEdit1 ) {
00214     myEditCurrentArgument = myGrp->LineEdit1;
00215     GEOMBase_Skeleton::LineEditReturnPressed();
00216   }
00217 }
00218 
00219 //=================================================================================
00220 // function : ActivateThisDialog()
00221 // purpose  :
00222 //=================================================================================
00223 void MeasureGUI_CheckCompoundOfBlocksDlg::ActivateThisDialog()
00224 {
00225   GEOMBase_Skeleton::ActivateThisDialog();
00226 
00227   LightApp_SelectionMgr* aSel = myGeomGUI->getApp()->selectionMgr();
00228   if ( aSel )
00229     connect( aSel, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
00230 
00231   activateSelection();
00232   DISPLAY_PREVIEW_MACRO
00233 }
00234 
00235 //=================================================================================
00236 // function : getBCErrors
00237 // purpose  :
00238 //=================================================================================
00239 bool MeasureGUI_CheckCompoundOfBlocksDlg::getBCErrors( bool& theIsCompoundOfBlocks,
00240                                                        GEOM::GEOM_IBlocksOperations::BCErrors& theErrors)
00241 {
00242   if ( myObj->_is_nil() )
00243     return false;
00244   else {
00245     GEOM::GEOM_IBlocksOperations_var anOper = GEOM::GEOM_IBlocksOperations::_narrow( getOperation() );
00246     try {
00247       GEOM::GEOM_IBlocksOperations::BCErrors_var aErrs;
00248       theIsCompoundOfBlocks = anOper->CheckCompoundOfBlocks( myObj, aErrs );
00249       if (anOper->IsDone() && aErrs->length() > 0)
00250       //if (anOper->IsDone() && !aErrs._is_nil())
00251         theErrors = aErrs;
00252     }
00253     catch ( const SALOME::SALOME_Exception& e ) {
00254       SalomeApp_Tools::QtCatchCorbaException( e );
00255       return false;
00256     }
00257 
00258     return anOper->IsDone();
00259   }
00260 }
00261 
00262 //=================================================================================
00263 // function : processObject
00264 // purpose  :
00265 //=================================================================================
00266 void MeasureGUI_CheckCompoundOfBlocksDlg::processObject()
00267 {
00268   QString aMsg ( "" );
00269   bool isCompoundOfBlocks;
00270   GEOM::GEOM_IBlocksOperations::BCErrors aErrs;
00271   if ( !getBCErrors( isCompoundOfBlocks, aErrs ) ) {
00272     aMsg += tr( "GEOM_CHECK_BLOCKS_COMPOUND_FAILED" );
00273     myGrp->TextView1->setText( aMsg );
00274     myGrp->ListBox1->clear();
00275     myGrp->ListBox2->clear();
00276     erasePreview();
00277     return;
00278   }
00279 
00280   if ( isCompoundOfBlocks ) {
00281     aMsg += tr( "GEOM_CHECK_BLOCKS_COMPOUND_HAS_NO_ERRORS" );
00282     buttonOk()->setEnabled( false );
00283     buttonApply()->setEnabled( false );
00284   }
00285   else {
00286     aMsg += tr( "GEOM_CHECK_BLOCKS_COMPOUND_HAS_ERRORS" );
00287     buttonOk()->setEnabled( true );
00288     buttonApply()->setEnabled( true );
00289   }
00290   myGrp->TextView1->setText( aMsg );
00291 
00292   QStringList aErrList;
00293   QString aErrStr( "" );
00294   QString aConSfx( " # " );
00295   QString aGluedSfx( " # " );
00296   int aConNum = 1;
00297   int aGluedNum = 1;
00298   for ( int i = 0, n = aErrs.length(); i < n; i++ ) {
00299     aErrStr = "";
00300     switch ( aErrs[i].error ) {
00301       case GEOM::GEOM_IBlocksOperations::NOT_BLOCK :
00302         aErrStr = "Not a Block";
00303         break;
00304       case GEOM::GEOM_IBlocksOperations::EXTRA_EDGE :
00305         aErrStr = "Extra Edge";
00306         break;
00307       case GEOM::GEOM_IBlocksOperations::INVALID_CONNECTION :
00308         aErrStr = "Invalid Connection";
00309         aErrStr += aConSfx;
00310         aErrStr += QString::number( aConNum );
00311         aConNum++;
00312         break;
00313       case GEOM::GEOM_IBlocksOperations::NOT_CONNECTED :
00314         aErrStr = "Not Connected";
00315         break;
00316       case GEOM::GEOM_IBlocksOperations::NOT_GLUED :
00317         aErrStr = "Not Glued";
00318         aErrStr += aGluedSfx;
00319         aErrStr += QString::number( aGluedNum );
00320         aGluedNum++;
00321         break;
00322       default :
00323         aErrStr = "";
00324         break;
00325     }
00326     if ( !aErrStr.isEmpty() )
00327       aErrList.append( aErrStr );
00328   }
00329 
00330   myGrp->ListBox1->clear();
00331   myGrp->ListBox2->clear();
00332   myGrp->ListBox1->addItems( aErrList );
00333 }
00334 
00335 //=================================================================================
00336 // function : createOperation
00337 // purpose  :
00338 //=================================================================================
00339 GEOM::GEOM_IOperations_ptr MeasureGUI_CheckCompoundOfBlocksDlg::createOperation()
00340 {
00341   return getGeomEngine()->GetIBlocksOperations( getStudyId() );
00342 }
00343 
00344 //=================================================================================
00345 // function : onErrorsListSelectionChanged
00346 // purpose  :
00347 //=================================================================================
00348 void MeasureGUI_CheckCompoundOfBlocksDlg::onErrorsListSelectionChanged()
00349 {
00350   erasePreview();
00351   int aCurItem = myGrp->ListBox1->currentRow();
00352   if ( aCurItem < 0 )
00353     return;
00354   bool isCompoundOfBlocks;
00355   GEOM::GEOM_IBlocksOperations::BCErrors aErrs;
00356   if ( !getBCErrors( isCompoundOfBlocks, aErrs ) ) {
00357     myGrp->TextView1->setText( "" );
00358     myGrp->ListBox1->clear();
00359     myGrp->ListBox2->clear();
00360     return;
00361   }
00362 
00363   GEOM::GEOM_IBlocksOperations::BCError aErr = aErrs[aCurItem];
00364   GEOM::ListOfLong aObjLst = aErr.incriminated;
00365   QStringList aSubShapeList;
00366   TopoDS_Shape aSelShape;
00367   if ( !myObj->_is_nil() && GEOMBase::GetShape( myObj, aSelShape ) ) {
00368     TopTools_IndexedMapOfShape anIndices;
00369     TopExp::MapShapes( aSelShape, anIndices );
00370     for ( int i = 0, n = aObjLst.length(); i < n; i++ ) {
00371       TopoDS_Shape aSubShape = anIndices.FindKey( aObjLst[i] );
00372       QString aType = GEOMBase::GetShapeTypeString( aSubShape );
00373       if ( !aType.isEmpty() )
00374        aSubShapeList.append( QString( "%1_%2" ).arg( aType ).arg( aObjLst[i] ) );
00375     }
00376   }
00377   myGrp->ListBox2->clear();
00378   myGrp->ListBox2->addItems( aSubShapeList );
00379 }
00380 
00381 //=================================================================================
00382 // function : onSubShapesListSelectionChanged
00383 // purpose  :
00384 //=================================================================================
00385 void MeasureGUI_CheckCompoundOfBlocksDlg::onSubShapesListSelectionChanged()
00386 {
00387   erasePreview();
00388   int aErrCurItem = myGrp->ListBox1->currentRow();
00389   if ( aErrCurItem < 0 )
00390     return;
00391   QList<int> aIds;
00392   for ( int i = 0, n = myGrp->ListBox2->count(); i < n; i++ ) {
00393     if ( myGrp->ListBox2->item( i )->isSelected() )
00394       aIds.append( i );
00395   }
00396   if ( aIds.count() < 1 )
00397     return;
00398   bool isCompoundOfBlocks;
00399   GEOM::GEOM_IBlocksOperations::BCErrors aErrs;
00400   if ( !getBCErrors( isCompoundOfBlocks, aErrs ) ) {
00401     myGrp->TextView1->setText( "" );
00402     myGrp->ListBox1->clear();
00403     myGrp->ListBox2->clear();
00404     return;
00405   }
00406 
00407   GEOM::GEOM_IBlocksOperations::BCError aErr = aErrs[aErrCurItem];
00408   GEOM::ListOfLong aObjLst = aErr.incriminated;
00409   TopoDS_Shape aSelShape;
00410   TopoDS_Shape aSubShape;
00411   TopTools_IndexedMapOfShape anIndices;
00412   if ( !myObj->_is_nil() && GEOMBase::GetShape( myObj, aSelShape ) ) {
00413     QString aMess;
00414     if ( !isValid( aMess ) ) {
00415       return;
00416     }
00417     SALOME_Prs* aPrs = 0;
00418     TopExp::MapShapes( aSelShape, anIndices);
00419     QList<int>::iterator it;
00420     for ( it = aIds.begin(); it != aIds.end(); ++it ) {
00421       aSubShape = anIndices.FindKey(aObjLst[(*it)]);
00422       SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
00423       int w = resMgr->integerValue("Geometry", "measures_line_width", 1);
00424       try {
00425         getDisplayer()->SetColor( Quantity_NOC_RED );
00426         getDisplayer()->SetWidth( w );
00427         getDisplayer()->SetToActivate( false );
00428         aPrs = !aSubShape.IsNull() ? getDisplayer()->BuildPrs( aSubShape ) : 0;
00429         if ( aPrs )
00430           displayPreview( aPrs, true );
00431       }
00432       catch ( const SALOME::SALOME_Exception& e ) {
00433         SalomeApp_Tools::QtCatchCorbaException( e );
00434       }
00435     }
00436   }
00437 }
00438 
00439 //=================================================================================
00440 // function : activateSelection
00441 // purpose  : activate selection of faces, shells, and solids
00442 //=================================================================================
00443 void MeasureGUI_CheckCompoundOfBlocksDlg::activateSelection()
00444 {
00445   TColStd_MapOfInteger aMap;
00446   aMap.Add( GEOM_SOLID );
00447   aMap.Add( GEOM_COMPOUND );
00448   globalSelection( aMap );
00449 }
00450 
00451 //=================================================================================
00452 // function : enterEvent()
00453 // purpose  :
00454 //=================================================================================
00455 void MeasureGUI_CheckCompoundOfBlocksDlg::enterEvent( QEvent* )
00456 {
00457   if ( !mainFrame()->GroupConstructors->isEnabled() )
00458     ActivateThisDialog();
00459 }
00460 
00461 //=================================================================================
00462 // function : isValid
00463 // purpose  :
00464 //=================================================================================
00465 bool MeasureGUI_CheckCompoundOfBlocksDlg::isValid( QString& )
00466 {
00467   return !myObj->_is_nil();
00468 }
00469 
00470 //=================================================================================
00471 // function : execute
00472 // purpose  :
00473 //=================================================================================
00474 bool MeasureGUI_CheckCompoundOfBlocksDlg::execute( ObjectList& objects )
00475 {
00476   GEOM::GEOM_IBlocksOperations_var anOper = GEOM::GEOM_IBlocksOperations::_narrow( getOperation() );
00477   GEOM::GEOM_Object_var anObj = anOper->CheckAndImprove( myObj );
00478 
00479   if ( !anObj->_is_nil() )
00480     objects.push_back( anObj._retn() );
00481 
00482   return true;
00483 }