Back to index

salome-geom  6.5.0
RepairGUI_RemoveExtraEdgesDlg.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // This library is free software; you can redistribute it and/or
00004 // modify it under the terms of the GNU Lesser General Public
00005 // License as published by the Free Software Foundation; either
00006 // version 2.1 of the License.
00007 //
00008 // This library is distributed in the hope that it will be useful,
00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011 // Lesser General Public License for more details.
00012 //
00013 // You should have received a copy of the GNU Lesser General Public
00014 // License along with this library; if not, write to the Free Software
00015 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00016 //
00017 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00018 //
00019 
00020 //  GEOM RepairGUI : GUI for Geometry component
00021 //  File   : RepairGUI_RemoveExtraEdgesDlg.cxx
00022 //  Author : Michael Zorin, Open CASCADE S.A.S.
00023 //
00024 #include "RepairGUI_RemoveExtraEdgesDlg.h"
00025 
00026 #include <DlgRef.h>
00027 #include <GeometryGUI.h>
00028 #include <GEOMBase.h>
00029 
00030 #include <SalomeApp_Application.h>
00031 #include <LightApp_SelectionMgr.h>
00032 #include <SUIT_Session.h>
00033 #include <SUIT_ResourceMgr.h>
00034 
00035 #include <GEOMImpl_Types.hxx>
00036 
00037 #include <TColStd_MapOfInteger.hxx>
00038 
00039 //=================================================================================
00040 // class    : RepairGUI_RemoveExtraEdgesDlg()
00041 // purpose  : Constructs a RepairGUI_RemoveExtraEdgesDlg which is a child of 'parent', with the
00042 //            name 'name' and widget flags set to 'f'.
00043 //            The dialog will by default be modeless, unless you set 'modal' to
00044 //            TRUE to construct a modal dialog.
00045 //=================================================================================
00046 RepairGUI_RemoveExtraEdgesDlg::RepairGUI_RemoveExtraEdgesDlg( GeometryGUI* theGeometryGUI, QWidget* parent,
00047                                                               bool modal )
00048   : GEOMBase_Skeleton( theGeometryGUI, parent, modal )
00049 {
00050   SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
00051   QPixmap image0( aResMgr->loadPixmap( "GEOM", tr( "ICON_DLG_REMOVE_EXTRA_EDGES" ) ) );
00052   QPixmap image1( aResMgr->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
00053     
00054   setWindowTitle( tr( "GEOM_REMOVE_EXTRA_EDGES_TITLE" ) );
00055 
00056   /***************************************************************/
00057   mainFrame()->GroupConstructors->setTitle(tr("GEOM_REMOVE_EXTRA_EDGES_TITLE"));
00058   mainFrame()->RadioButton1->setIcon( image0 );
00059   mainFrame()->RadioButton2->setAttribute( Qt::WA_DeleteOnClose );
00060   mainFrame()->RadioButton2->close();
00061   mainFrame()->RadioButton3->setAttribute( Qt::WA_DeleteOnClose );
00062   mainFrame()->RadioButton3->close();
00063 
00064   GroupPoints = new DlgRef_1Sel1Check( centralWidget() );
00065 
00066   GroupPoints->GroupBox1->setTitle( tr( "GEOM_REMOVE_EXTRA_EDGES" ) );
00067   GroupPoints->TextLabel1->setText( tr( "GEOM_SELECTED_SHAPE" ) );
00068   GroupPoints->PushButton1->setIcon( image1 );
00069   GroupPoints->LineEdit1->setReadOnly( true );
00070 
00071   GroupPoints->CheckButton1->setText( tr( "GEOM_RMEE_UNION_FACES" ) );
00072 
00073   QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
00074   layout->setMargin( 0 ); layout->setSpacing( 6 );
00075   layout->addWidget( GroupPoints );
00076 
00077   /***************************************************************/
00078   
00079   setHelpFileName( "remove_extra_edges_operation_page.html" );
00080 
00081   Init();
00082 }
00083 
00084 
00085 //=================================================================================
00086 // function : ~RepairGUI_RemoveExtraEdgesDlg()
00087 // purpose  : Destroys the object and frees any allocated resources
00088 //=================================================================================
00089 RepairGUI_RemoveExtraEdgesDlg::~RepairGUI_RemoveExtraEdgesDlg()
00090 {
00091 }
00092 
00093 
00094 //=================================================================================
00095 // function : Init()
00096 // purpose  :
00097 //=================================================================================
00098 void RepairGUI_RemoveExtraEdgesDlg::Init()
00099 {
00100   /* init variables */
00101   myEditCurrentArgument = GroupPoints->LineEdit1;
00102   
00103   myOkObject = false;
00104 
00105   GroupPoints->CheckButton1->setChecked( false );
00106 
00107   activateSelection();
00108   
00109   mainFrame()->GroupBoxPublish->show();
00110   //Hide preview checkbox
00111   mainFrame()->CheckBoxPreview->hide();
00112 
00113   /* signals and slots connections */
00114   connect( buttonOk(),    SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
00115   connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
00116 
00117   connect( GroupPoints->PushButton1, SIGNAL( clicked() ),       this, SLOT( SetEditCurrentArgument() ) );
00118   connect( GroupPoints->LineEdit1,   SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
00119 
00120   connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
00121            this, SLOT( SelectionIntoArgument() ) );
00122 
00123   initName( tr( "REMOVE_EXTRA_EDGES_NEW_OBJ_NAME" ) );
00124   resize(100,100);
00125   SelectionIntoArgument();
00126 }
00127 
00128 
00129 //=================================================================================
00130 // function : ClickOnOk()
00131 // purpose  : Same than click on apply but close this dialog.
00132 //=================================================================================
00133 void RepairGUI_RemoveExtraEdgesDlg::ClickOnOk()
00134 {
00135   setIsApplyAndClose( true );
00136   if ( ClickOnApply() )
00137     ClickOnCancel();
00138 }
00139 
00140 //=================================================================================
00141 // function : ClickOnApply()
00142 // purpose  :
00143 //=================================================================================
00144 bool RepairGUI_RemoveExtraEdgesDlg::ClickOnApply()
00145 {
00146   if ( !onAccept() )
00147     return false;
00148 
00149   initName();
00150 
00151   myEditCurrentArgument->setText( "" );
00152   myObject = GEOM::GEOM_Object::_nil();
00153   
00154   myOkObject = false;
00155 
00156   activateSelection();
00157 
00158   return true;
00159 }
00160 
00161 
00162 //=================================================================================
00163 // function : SelectionIntoArgument()
00164 // purpose  : Called when selection as changed or other case
00165 //          : used only by SelectButtonC1A1 (LineEditC1A1)
00166 //=================================================================================
00167 void RepairGUI_RemoveExtraEdgesDlg::SelectionIntoArgument()
00168 {
00169   myEditCurrentArgument->setText( "" );
00170   QString aName;
00171   
00172   LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
00173   SALOME_ListIO aSelList;
00174   aSelMgr->selectedObjects(aSelList);
00175 
00176   if ( myEditCurrentArgument == GroupPoints->LineEdit1 ) {
00177     if ( aSelList.Extent() != 1 ) {
00178       if ( myEditCurrentArgument == GroupPoints->LineEdit1 )
00179         myOkObject = false;
00180       return;
00181     }
00182   }
00183   
00184   // nbSel == 1
00185   GEOM::GEOM_Object_ptr aSelectedObject =
00186     GEOMBase::ConvertIOinGEOMObject( aSelList.First() );
00187 
00188   if ( CORBA::is_nil( aSelectedObject ) )
00189     return;
00190   
00191   if ( myEditCurrentArgument == GroupPoints->LineEdit1 ) {
00192     myObject = aSelectedObject;
00193     myOkObject = true;
00194   }
00195 
00196   myEditCurrentArgument->setText( GEOMBase::GetName( aSelectedObject ) );
00197 }
00198 
00199 //=================================================================================
00200 // function : SetEditCurrentArgument()
00201 // purpose  :
00202 //=================================================================================
00203 void RepairGUI_RemoveExtraEdgesDlg::SetEditCurrentArgument()
00204 {
00205   if( sender() == GroupPoints->PushButton1 ) {
00206     GroupPoints->LineEdit1->setFocus();
00207     myEditCurrentArgument = GroupPoints->LineEdit1;
00208   }
00209   SelectionIntoArgument();
00210 }
00211 
00212 
00213 //=================================================================================
00214 // function : LineEditReturnPressed()
00215 // purpose  :
00216 //=================================================================================
00217 void RepairGUI_RemoveExtraEdgesDlg::LineEditReturnPressed()
00218 {
00219   if ( sender() == GroupPoints->LineEdit1 ) {
00220     myEditCurrentArgument = GroupPoints->LineEdit1;
00221     GEOMBase_Skeleton::LineEditReturnPressed();
00222   }
00223 }
00224 
00225 
00226 //=================================================================================
00227 // function : ActivateThisDialog()
00228 // purpose  :
00229 //=================================================================================
00230 void RepairGUI_RemoveExtraEdgesDlg::ActivateThisDialog()
00231 {
00232   GEOMBase_Skeleton::ActivateThisDialog();
00233   connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
00234            this, SLOT( SelectionIntoArgument() ) );
00235 
00236   activateSelection();
00237 }
00238 
00239 
00240 //=================================================================================
00241 // function : enterEvent()
00242 // purpose  : Mouse enter onto the dialog to activate it
00243 //=================================================================================
00244 void RepairGUI_RemoveExtraEdgesDlg::enterEvent(QEvent* e)
00245 {
00246   if ( !mainFrame()->GroupConstructors->isEnabled() )
00247     ActivateThisDialog();
00248 }
00249 
00250 
00251 //=================================================================================
00252 // function : activateSelection
00253 // purpose  : activate selection of solids and compounds
00254 //=================================================================================
00255 void RepairGUI_RemoveExtraEdgesDlg::activateSelection()
00256 {
00257   TColStd_MapOfInteger aTypes;
00258   aTypes.Add( GEOM_SHELL );
00259   aTypes.Add( GEOM_SOLID );
00260   aTypes.Add( GEOM_COMPOUND );
00261   globalSelection( aTypes );
00262 }
00263 
00264 //=================================================================================
00265 // function : createOperation
00266 // purpose  :
00267 //=================================================================================
00268 GEOM::GEOM_IOperations_ptr RepairGUI_RemoveExtraEdgesDlg::createOperation()
00269 {
00270   return getGeomEngine()->GetIBlocksOperations( getStudyId() );
00271 }
00272 
00273 //=================================================================================
00274 // function : isValid
00275 // purpose  :
00276 //=================================================================================
00277 bool RepairGUI_RemoveExtraEdgesDlg::isValid( QString& msg )
00278 {
00279   return myOkObject;
00280 }
00281 
00282 //=================================================================================
00283 // function : execute
00284 // purpose  :
00285 //=================================================================================
00286 bool RepairGUI_RemoveExtraEdgesDlg::execute( ObjectList& objects )
00287 {
00288   GEOM::GEOM_Object_var anObj;
00289 
00290   int nbFacesOptimum = -1; // -1 means do not union faces
00291   if (GroupPoints->CheckButton1->isChecked())
00292     nbFacesOptimum = 0; // 0 means union all faces, that possible
00293   GEOM::GEOM_IBlocksOperations_var anOper = GEOM::GEOM_IBlocksOperations::_narrow(getOperation());
00294   anObj = anOper->RemoveExtraEdges(myObject, nbFacesOptimum);
00295 
00296   if (!anObj->_is_nil())
00297     objects.push_back(anObj._retn());
00298 
00299   return true;
00300 }
00301 
00302 //=================================================================================
00303 // function : restoreSubShapes
00304 // purpose  :
00305 //=================================================================================
00306 void RepairGUI_RemoveExtraEdgesDlg::restoreSubShapes( SALOMEDS::Study_ptr   theStudy,
00307                                                       SALOMEDS::SObject_ptr theSObject )
00308 {
00309   if ( mainFrame()->CheckBoxRestoreSS->isChecked() ) {
00310     // empty list of arguments means that all arguments should be restored
00311     getGeomEngine()->RestoreSubShapesSO( theStudy, theSObject, GEOM::ListOfGO(),
00312                                          /*theFindMethod=*/GEOM::FSM_GetInPlace, // ? GetInPlaceByHistory
00313                                          /*theInheritFirstArg=*/true,
00314                                          mainFrame()->CheckBoxAddPrefix->isChecked() );
00315   }
00316 }