Back to index

salome-geom  6.5.0
RepairGUI_RemoveHolesDlg.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   : RepairGUI_RemoveHolesDlg.cxx
00025 // Author : Lucien PIGNOLONI, Open CASCADE S.A.S.
00026 //
00027 #include "RepairGUI_RemoveHolesDlg.h"
00028 
00029 #include <DlgRef.h>
00030 #include <GeometryGUI.h>
00031 #include <GEOMBase.h>
00032 
00033 #include <SUIT_Session.h>
00034 #include <SUIT_ResourceMgr.h>
00035 #include <SUIT_MessageBox.h>
00036 #include <SalomeApp_Application.h>
00037 #include <LightApp_SelectionMgr.h>
00038 
00039 // OCCT Includes
00040 #include <TopAbs.hxx>
00041 #include <TColStd_MapOfInteger.hxx>
00042 #include <TColStd_IndexedMapOfInteger.hxx>
00043 
00044 #include <GEOMImpl_Types.hxx>
00045 
00046 //=================================================================================
00047 // class    : RepairGUI_RemoveHolesDlg()
00048 // purpose  : Constructs a RepairGUI_RemoveHolesDlg  which is a child of 'parent', with the
00049 //            name 'name' and widget flags set to 'f'.
00050 //            The dialog will by default be modeless, unless you set 'modal' to
00051 //            TRUE to construct a modal dialog.
00052 //=================================================================================
00053 RepairGUI_RemoveHolesDlg::RepairGUI_RemoveHolesDlg (GeometryGUI* theGeometryGUI, QWidget* parent,
00054                                                     bool modal)
00055   : GEOMBase_Skeleton(theGeometryGUI, parent, modal)
00056 {
00057   QPixmap image0 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_DLG_SUPPRESS_HOLES")));
00058   QPixmap image1 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_SELECT")));
00059 
00060   setWindowTitle(tr("GEOM_REMOVE_HOLES_TITLE"));
00061 
00062   /***************************************************************/
00063   mainFrame()->GroupConstructors->setTitle(tr("GEOM_REMOVE_HOLES_TITLE"));
00064   mainFrame()->RadioButton1->setIcon(image0);
00065   mainFrame()->RadioButton2->setAttribute(Qt::WA_DeleteOnClose);
00066   mainFrame()->RadioButton2->close();
00067   mainFrame()->RadioButton3->setAttribute(Qt::WA_DeleteOnClose);
00068   mainFrame()->RadioButton3->close();
00069 
00070   GroupPoints = new DlgRef_1Sel1Check1Sel(centralWidget());
00071   GroupPoints->GroupBox1->setTitle(tr("GEOM_HOLES"));
00072   GroupPoints->TextLabel1->setText(tr("GEOM_SELECTED_SHAPE"));
00073   GroupPoints->PushButton1->setIcon(image1);
00074   GroupPoints->LineEdit1->setReadOnly(true);
00075   GroupPoints->CheckButton1->setText(tr("GEOM_REMOVE_ALL_HOLES"));
00076   GroupPoints->TextLabel2->setText(tr("GEOM_WIRES_TO_REMOVE"));
00077   GroupPoints->PushButton2->setIcon(image1);
00078   GroupPoints->LineEdit2->setReadOnly(true);
00079 
00080   myFreeBoundBtn = new QPushButton(tr("GEOM_DETECT") + QString(" [%1]").arg(tr("GEOM_FREE_BOUNDARIES")),
00081                                     GroupPoints->Box);
00082   QVBoxLayout* l = new QVBoxLayout(GroupPoints->Box);
00083   l->setMargin(0); l->setSpacing(0);
00084   l->addWidget(myFreeBoundBtn);
00085 
00086   QVBoxLayout* layout = new QVBoxLayout(centralWidget());
00087   layout->setMargin(0); layout->setSpacing(6);
00088   layout->addWidget(GroupPoints);
00089   /***************************************************************/
00090 
00091   setHelpFileName("suppress_holes_operation_page.html");
00092 
00093   Init();
00094 }
00095 
00096 //=================================================================================
00097 // function : ~RepairGUI_RemoveHolesDlg()
00098 // purpose  : Destroys the object and frees any allocated resources
00099 //=================================================================================
00100 RepairGUI_RemoveHolesDlg::~RepairGUI_RemoveHolesDlg()
00101 {
00102 }
00103 
00104 //=================================================================================
00105 // function : Init()
00106 // purpose  :
00107 //=================================================================================
00108 void RepairGUI_RemoveHolesDlg::Init()
00109 {
00110   // init variables
00111   GroupPoints->LineEdit1->clear();
00112   GroupPoints->LineEdit2->clear();
00113   myObject = GEOM::GEOM_Object::_nil();
00114   myWiresInd = new GEOM::short_array();
00115   myWiresInd->length(0);
00116 
00117   myClosed = -1;
00118   myOpen = -1;
00119 
00120   // signals and slots connections
00121   connect(buttonOk(),    SIGNAL(clicked()), this, SLOT(ClickOnOk()));
00122   connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
00123 
00124   connect(GroupPoints->PushButton1, SIGNAL(clicked()),       this, SLOT(SetEditCurrentArgument()));
00125   connect(GroupPoints->PushButton2, SIGNAL(clicked()),       this, SLOT(SetEditCurrentArgument()));
00126 
00127   connect(GroupPoints->LineEdit1,   SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
00128   connect(GroupPoints->LineEdit2,   SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
00129 
00130   connect(GroupPoints->CheckButton1, SIGNAL(clicked()), this, SLOT(onRemoveAllClicked()));
00131 
00132   connect(myFreeBoundBtn, SIGNAL(clicked()), this, SLOT(onDetect()));
00133 
00134   initName(tr("REMOVE_HOLES_NEW_OBJ_NAME"));
00135 
00136   GroupPoints->PushButton1->click();
00137   SelectionIntoArgument();
00138   resize(100,100);
00139 }
00140 
00141 //=================================================================================
00142 // function : ClickOnOk()
00143 // purpose  : Same than click on apply but close this dialog.
00144 //=================================================================================
00145 void RepairGUI_RemoveHolesDlg::ClickOnOk()
00146 {
00147   setIsApplyAndClose( true );
00148   if (ClickOnApply())
00149     ClickOnCancel();
00150 }
00151 
00152 //=================================================================================
00153 // function : ClickOnApply()
00154 // purpose  :
00155 //=================================================================================
00156 bool RepairGUI_RemoveHolesDlg::ClickOnApply()
00157 {
00158   if (!onAccept())
00159     return false;
00160 
00161   initName();
00162   // activate first line edit
00163   GroupPoints->PushButton1->click();
00164   return true;
00165 }
00166 
00167 //=================================================================================
00168 // function : SelectionIntoArgument()
00169 // purpose  : Called when selection is changed or on dialog initialization or activation
00170 //=================================================================================
00171 void RepairGUI_RemoveHolesDlg::SelectionIntoArgument()
00172 {
00173   erasePreview();
00174   myEditCurrentArgument->setText("");
00175   // the second argument depends on the first one
00176   GroupPoints->LineEdit2->setText("");
00177   myWiresInd->length(0);
00178 
00179   if (myEditCurrentArgument == GroupPoints->LineEdit1)
00180     myObject = GEOM::GEOM_Object::_nil();
00181 
00182   LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
00183   SALOME_ListIO aSelList;
00184   aSelMgr->selectedObjects(aSelList);
00185 
00186   if (aSelList.Extent() == 1) {
00187     Handle(SALOME_InteractiveObject) anIO = aSelList.First();
00188 
00189     if (myEditCurrentArgument == GroupPoints->LineEdit1) { // face selection
00190       myObject = GEOMBase::ConvertIOinGEOMObject( anIO );
00191       if ( GEOMBase::IsShape(myObject) ) {
00192         myEditCurrentArgument->setText(GEOMBase::GetName(myObject));
00193 
00194         // clear selection
00195         disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
00196         myGeomGUI->getApp()->selectionMgr()->clearSelected();
00197         connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
00198                 this, SLOT(SelectionIntoArgument()));
00199 
00200         if (!GroupPoints->CheckButton1->isChecked())
00201           GroupPoints->PushButton2->click();
00202       }
00203       else
00204         myObject = GEOM::GEOM_Object::_nil();
00205     }
00206     else if (myEditCurrentArgument == GroupPoints->LineEdit2 &&
00207              !GroupPoints->CheckButton1->isChecked()) {
00208       TColStd_IndexedMapOfInteger aMap;
00209       aSelMgr->GetIndexes(anIO, aMap);
00210       const int n = aMap.Extent();
00211       myWiresInd->length(n);
00212       for (int i = 1; i <= n; i++)
00213         myWiresInd[i-1] = aMap(i);
00214       if (n)
00215         myEditCurrentArgument->setText(QString::number(n) + "_" + tr("GEOM_WIRE") + tr("_S_"));
00216     }
00217   }
00218 }
00219 
00220 //=================================================================================
00221 // function : SetEditCurrentArgument()
00222 // purpose  :
00223 //=================================================================================
00224 void RepairGUI_RemoveHolesDlg::SetEditCurrentArgument()
00225 {
00226   QPushButton* send = (QPushButton*)sender();
00227 
00228   bool isEffective = false;
00229 
00230   if (send == GroupPoints->PushButton1) {
00231     isEffective = true;
00232     myEditCurrentArgument = GroupPoints->LineEdit1;
00233 
00234     GroupPoints->PushButton2->setDown(false);
00235     GroupPoints->LineEdit2->setEnabled(false);
00236   }
00237   else if (send == GroupPoints->PushButton2 && !myObject->_is_nil()) {
00238     isEffective = true;
00239     myEditCurrentArgument = GroupPoints->LineEdit2;
00240 
00241     GroupPoints->PushButton1->setDown(false);
00242     GroupPoints->LineEdit1->setEnabled(false);
00243   }
00244 
00245   if (isEffective) {
00246     initSelection();
00247 
00248     // enable line edit
00249     myEditCurrentArgument->setEnabled(true);
00250     myEditCurrentArgument->setFocus();
00251     // after setFocus(), because it will be setDown(false) when loses focus
00252     send->setDown(true);
00253   }
00254 }
00255 
00256 //=================================================================================
00257 // function : LineEditReturnPressed()
00258 // purpose  :
00259 //=================================================================================
00260 void RepairGUI_RemoveHolesDlg::LineEditReturnPressed()
00261 {
00262   const QObject* send = sender();
00263   if (send == GroupPoints->LineEdit1 || send == GroupPoints->LineEdit2) {
00264     myEditCurrentArgument = (QLineEdit*)send;
00265     GEOMBase_Skeleton::LineEditReturnPressed();
00266   }
00267 }
00268 
00269 //=================================================================================
00270 // function : ActivateThisDialog()
00271 // purpose  :
00272 //=================================================================================
00273 void RepairGUI_RemoveHolesDlg::ActivateThisDialog()
00274 {
00275   GEOMBase_Skeleton::ActivateThisDialog();
00276   connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
00277            this, SLOT( SelectionIntoArgument() ) );
00278 
00279   myEditCurrentArgument = GroupPoints->LineEdit1;
00280   myEditCurrentArgument->setText( "" );
00281   GroupPoints->LineEdit2->setText( "" );
00282   myObject = GEOM::GEOM_Object::_nil();
00283   myWiresInd->length( 0 );
00284 
00285   myClosed = -1;
00286   myOpen = -1;
00287 
00288   initSelection();
00289 }
00290 
00291 //=================================================================================
00292 // function : enterEvent()
00293 // purpose  : Mouse enter onto the dialog to activate it
00294 //=================================================================================
00295 void RepairGUI_RemoveHolesDlg::enterEvent (QEvent*)
00296 {
00297   if (!mainFrame()->GroupConstructors->isEnabled())
00298     ActivateThisDialog();
00299 }
00300 
00301 //=================================================================================
00302 // function : createOperation
00303 // purpose  :
00304 //=================================================================================
00305 GEOM::GEOM_IOperations_ptr RepairGUI_RemoveHolesDlg::createOperation()
00306 {
00307   return getGeomEngine()->GetIHealingOperations(getStudyId());
00308 }
00309 
00310 //=================================================================================
00311 // function : isValid
00312 // purpose  :
00313 //=================================================================================
00314 bool RepairGUI_RemoveHolesDlg::isValid (QString&)
00315 {
00316   myClosed = -1;
00317   return !myObject->_is_nil() && (IsPreview() || GroupPoints->CheckButton1->isChecked() || myWiresInd->length());
00318 }
00319 
00320 //=================================================================================
00321 // function : execute
00322 // purpose  :
00323 //=================================================================================
00324 bool RepairGUI_RemoveHolesDlg::execute (ObjectList& objects)
00325 {
00326   bool aResult = false;
00327 
00328   if (IsPreview()) {
00329     // called from onDetect(): detect free boundary edges,
00330     // highlight them (add to objects), display message dialog
00331     GEOM::ListOfGO_var aClosed, anOpen;
00332 
00333     GEOM::GEOM_IHealingOperations_var anOper = GEOM::GEOM_IHealingOperations::_narrow(getOperation());
00334     aResult = anOper->GetFreeBoundary(myObject, aClosed, anOpen);
00335 
00336     if (aResult) {
00337       myClosed = aClosed->length();
00338       myOpen = anOpen->length();
00339       int i;
00340       for (i = 0; i < myClosed; i++)
00341         objects.push_back(aClosed[i]._retn());
00342       for (i = 0; i < myOpen; i++)
00343         objects.push_back(anOpen[i]._retn());
00344     }
00345     else
00346       myClosed = -1;
00347   }
00348   else {
00349     GEOM::GEOM_IHealingOperations_var anOper = GEOM::GEOM_IHealingOperations::_narrow(getOperation());
00350     GEOM::GEOM_Object_var anObj = anOper->FillHoles(myObject, myWiresInd);
00351     aResult = !anObj->_is_nil();
00352     if (aResult)
00353       objects.push_back(anObj._retn());
00354   }
00355 
00356   return aResult;
00357 }
00358 
00359 //=================================================================================
00360 // function : onRemoveAllClicked
00361 // purpose  :
00362 //=================================================================================
00363 void RepairGUI_RemoveHolesDlg::onRemoveAllClicked()
00364 {
00365   bool b = GroupPoints->CheckButton1->isChecked();
00366   GroupPoints->TextLabel2->setEnabled(!b);
00367   GroupPoints->PushButton2->setEnabled(!b);
00368   GroupPoints->LineEdit2->setEnabled(!b);
00369   if (b) {
00370     GroupPoints->LineEdit2->setText("");
00371     myWiresInd->length(0);
00372   }
00373 }
00374 
00375 //=================================================================================
00376 // function : initSelection
00377 // purpose  :
00378 //=================================================================================
00379 void RepairGUI_RemoveHolesDlg::initSelection()
00380 {
00381   disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
00382 
00383   if (myEditCurrentArgument == GroupPoints->LineEdit1) {
00384     TColStd_MapOfInteger aTypes;
00385     aTypes.Add(GEOM_COMPOUND);
00386     aTypes.Add(GEOM_SOLID);
00387     aTypes.Add(GEOM_SHELL);
00388     aTypes.Add(GEOM_FACE);
00389 
00390     globalSelection(aTypes);
00391   }
00392   else if (myEditCurrentArgument == GroupPoints->LineEdit2) {
00393     localSelection(myObject, TopAbs_EDGE);
00394     localSelection(myObject, TopAbs_WIRE);
00395   }
00396 
00397   connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
00398           this, SLOT(SelectionIntoArgument()));
00399 }
00400 
00401 //=================================================================================
00402 // function : onDetect
00403 // purpose  :
00404 //=================================================================================
00405 void RepairGUI_RemoveHolesDlg::onDetect()
00406 {
00407   displayPreview(true, false, true, true, 3);
00408 
00409   // field myClosed,myOpen is initialized in execute() method, called by displayPreview().
00410   QString msg;
00411   if (myClosed != -1)
00412     msg = tr("GEOM_FREE_BOUNDS_MSG").arg(myClosed + myOpen).arg(myClosed).arg(myOpen);
00413   else
00414     msg = tr("GEOM_FREE_BOUNDS_ERROR");
00415   SUIT_MessageBox::information(this, tr("GEOM_FREE_BOUNDS_TLT"), msg);
00416 }