Back to index

salome-geom  6.5.0
RepairGUI_SuppressFacesDlg.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 //  File   : RepairGUI_SuppressFacesDlg.cxx
00023 //  Author : Lucien PIGNOLONI, Open CASCADE S.A.S.
00024 
00025 #include "RepairGUI_SuppressFacesDlg.h"
00026 
00027 #include <DlgRef.h>
00028 #include <GeometryGUI.h>
00029 #include <GEOMBase.h>
00030 
00031 #include <SUIT_Session.h>
00032 #include <SUIT_ResourceMgr.h>
00033 #include <SalomeApp_Application.h>
00034 #include <SalomeApp_Study.h>
00035 #include <LightApp_SelectionMgr.h>
00036 #include <SALOME_ListIteratorOfListIO.hxx>
00037 
00038 // OCCT Includes
00039 #include <TopAbs.hxx>
00040 #include <TopExp.hxx>
00041 #include <TopExp_Explorer.hxx>
00042 #include <TopTools_IndexedMapOfShape.hxx>
00043 #include <TColStd_MapOfInteger.hxx>
00044 #include <TColStd_IndexedMapOfInteger.hxx>
00045 
00046 #include <GEOMImpl_Types.hxx>
00047 
00048 //=================================================================================
00049 // class    : RepairGUI_SuppressFacesDlg()
00050 // purpose  : Constructs a RepairGUI_SuppressFacesDlg  which is a child of 'parent', with the
00051 //            name 'name' and widget flags set to 'f'.
00052 //            The dialog will by default be modeless, unless you set 'modal' to
00053 //            TRUE to construct a modal dialog.
00054 //=================================================================================
00055 RepairGUI_SuppressFacesDlg::RepairGUI_SuppressFacesDlg (GeometryGUI* theGeometryGUI, QWidget* parent,
00056                                                         bool modal)
00057   : GEOMBase_Skeleton(theGeometryGUI, parent, modal)
00058 {
00059   QPixmap image0 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_DLG_SUPRESS_FACE")));
00060   QPixmap image1 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_SELECT")));
00061 
00062   setWindowTitle(tr("GEOM_SUPRESSFACE_TITLE"));
00063 
00064   /***************************************************************/
00065   mainFrame()->GroupConstructors->setTitle(tr("GEOM_SUPRESSFACE"));
00066   mainFrame()->RadioButton1->setIcon(image0);
00067   mainFrame()->RadioButton2->setAttribute(Qt::WA_DeleteOnClose);
00068   mainFrame()->RadioButton2->close();
00069   mainFrame()->RadioButton3->setAttribute(Qt::WA_DeleteOnClose);
00070   mainFrame()->RadioButton3->close();
00071 
00072   GroupArgs = new DlgRef_2Sel(centralWidget());
00073   GroupArgs->GroupBox1->setTitle(tr("Faces to remove"));
00074   GroupArgs->TextLabel1->setText(tr("GEOM_SELECTED_SHAPE"));
00075   GroupArgs->PushButton1->setIcon(image1);
00076   GroupArgs->LineEdit1->setReadOnly(true);
00077 
00078   GroupArgs->TextLabel2->setText(tr("Faces to remove"));
00079   GroupArgs->PushButton2->setIcon(image1);
00080   GroupArgs->LineEdit2->setReadOnly(true);
00081 
00082   QVBoxLayout* layout = new QVBoxLayout(centralWidget());
00083   layout->setMargin(0); layout->setSpacing(6);
00084   layout->addWidget(GroupArgs);
00085   /***************************************************************/
00086 
00087   setHelpFileName("suppress_faces_operation_page.html");
00088 
00089   Init();
00090 }
00091 
00092 //=================================================================================
00093 // function : ~RepairGUI_SuppressFacesDlg()
00094 // purpose  : Destroys the object and frees any allocated resources
00095 //=================================================================================
00096 RepairGUI_SuppressFacesDlg::~RepairGUI_SuppressFacesDlg()
00097 {
00098 }
00099 
00100 //=================================================================================
00101 // function : Init()
00102 // purpose  :
00103 //=================================================================================
00104 void RepairGUI_SuppressFacesDlg::Init()
00105 {
00106   // init variables
00107   GroupArgs->LineEdit1->clear();
00108   GroupArgs->LineEdit2->clear();
00109   myObject = GEOM::GEOM_Object::_nil();
00110   myFacesInd = new GEOM::short_array();
00111   myFacesInd->length(0);
00112 
00113   mainFrame()->GroupBoxPublish->show();
00114   //Hide preview checkbox
00115   mainFrame()->CheckBoxPreview->hide();
00116 
00117   // signals and slots connections
00118   connect(buttonOk(),    SIGNAL(clicked()), this, SLOT(ClickOnOk()));
00119   connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
00120 
00121   connect(GroupArgs->PushButton1, SIGNAL(clicked()),       this, SLOT(SetEditCurrentArgument()));
00122   connect(GroupArgs->PushButton2, SIGNAL(clicked()),       this, SLOT(SetEditCurrentArgument()));
00123 
00124   connect(GroupArgs->LineEdit1,   SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
00125   connect(GroupArgs->LineEdit2,   SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
00126 
00127   initName(tr("SUPRESS_FACE_NEW_OBJ_NAME"));
00128 
00129   GroupArgs->PushButton1->click();
00130   SelectionIntoArgument();
00131   resize(100,100);
00132 }
00133 
00134 //=================================================================================
00135 // function : ClickOnOk()
00136 // purpose  : Same than click on apply but close this dialog.
00137 //=================================================================================
00138 void RepairGUI_SuppressFacesDlg::ClickOnOk()
00139 {
00140   setIsApplyAndClose( true );
00141   if (ClickOnApply())
00142     ClickOnCancel();
00143 }
00144 
00145 //=================================================================================
00146 // function : ClickOnApply()
00147 // purpose  :
00148 //=================================================================================
00149 bool RepairGUI_SuppressFacesDlg::ClickOnApply()
00150 {
00151   if (!onAccept())
00152     return false;
00153 
00154   initName();
00155   // activate first line edit
00156   GroupArgs->PushButton1->click();
00157   return true;
00158 }
00159 
00160 //=================================================================================
00161 // function : SelectionIntoArgument()
00162 // purpose  : Called when selection is changed or on dialog initialization or activation
00163 //=================================================================================
00164 void RepairGUI_SuppressFacesDlg::SelectionIntoArgument()
00165 {
00166   myEditCurrentArgument->setText("");
00167   // the second argument depends on the first one
00168   GroupArgs->LineEdit2->setText("");
00169   myFacesInd->length(0);
00170 
00171   if (myEditCurrentArgument == GroupArgs->LineEdit1)
00172     myObject = GEOM::GEOM_Object::_nil();
00173 
00174   LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
00175   SALOME_ListIO aSelList;
00176   aSelMgr->selectedObjects(aSelList);
00177 
00178   if (myEditCurrentArgument == GroupArgs->LineEdit1) {
00179     if (aSelList.Extent() == 1) {
00180       Handle(SALOME_InteractiveObject) anIO = aSelList.First();
00181 
00182       myObject = GEOMBase::ConvertIOinGEOMObject( anIO );
00183       if ( GEOMBase::IsShape(myObject) ) {
00184         myEditCurrentArgument->setText(GEOMBase::GetName(myObject));
00185         TopoDS_Shape aShape;
00186         if (GEOMBase::GetShape(myObject, aShape, TopAbs_FACE))
00187           GroupArgs->LineEdit2->setText(myEditCurrentArgument->text());
00188 
00189         // clear selection
00190         disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
00191         myGeomGUI->getApp()->selectionMgr()->clearSelected();
00192         connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
00193                 this, SLOT(SelectionIntoArgument()));
00194 
00195         GroupArgs->PushButton2->click();
00196       }
00197       else
00198         myObject = GEOM::GEOM_Object::_nil();
00199     }
00200   }
00201   else if (myEditCurrentArgument == GroupArgs->LineEdit2) {
00202     TColStd_IndexedMapOfInteger aMap;
00203 
00204     if (aSelList.Extent() == 1) {
00205       Handle(SALOME_InteractiveObject) anIO = aSelList.First();
00206       aSelMgr->GetIndexes(anIO, aMap);
00207     }
00208 
00209     if (aMap.IsEmpty() && aSelList.Extent() > 0) { // try to detect selected published sub-shape
00210       TColStd_MapOfInteger anIds;
00211 
00212       SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>(myGeomGUI->getApp()->activeStudy());
00213       if (!appStudy) return;
00214       _PTR(Study) aStudy = appStudy->studyDS();
00215 
00216       TopTools_IndexedMapOfShape aMainMap;
00217       TopoDS_Shape aMainShape = GEOM_Client::get_client().GetShape(GeometryGUI::GetGeomGen(), myObject);
00218       TopExp::MapShapes(aMainShape, aMainMap);
00219 
00220       SALOME_ListIteratorOfListIO anIter (aSelList);
00221       for (int i = 0; anIter.More(); anIter.Next(), i++) {
00222         Handle(SALOME_InteractiveObject) anIO = anIter.Value();
00223         QString anEntry = anIO->getEntry();
00224 
00225         _PTR(SObject) aSObj (aStudy->FindObjectID(anEntry.toLatin1().constData()));
00226         GEOM::GEOM_Object_var aGeomObj =
00227           GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aSObj));
00228         TopoDS_Shape aShape;
00229         if (GEOMBase::GetShape(aGeomObj, aShape)) {
00230           if (aGeomObj->GetType() == GEOM_GROUP || aShape.ShapeType() == TopAbs_FACE) {
00231             TopExp_Explorer anExp (aShape, TopAbs_FACE);
00232             for (; anExp.More(); anExp.Next()) {
00233               TopoDS_Shape aSubShape = anExp.Current();
00234               int anIndex = aMainMap.FindIndex(aSubShape);
00235               if (anIndex >= 0) {
00236                 aMap.Add(anIndex);
00237                 anIds.Add(anIndex);
00238               }
00239             }
00240           }
00241         }
00242       }
00243       if (!aMap.IsEmpty()) {
00244         // highlight local faces, correspondent to OB selection
00245         disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
00246 
00247         aSelMgr->clearSelected();
00248 
00249         QString objIOR = GEOMBase::GetIORFromObject(myObject);
00250         Handle(GEOM_AISShape) aSh = GEOMBase::ConvertIORinGEOMAISShape( objIOR, true );
00251         if ( aSh.IsNull() )
00252           return;
00253 
00254         aSelMgr->AddOrRemoveIndex(aSh->getIO(), anIds, false);
00255 
00256         connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
00257                 this, SLOT(SelectionIntoArgument()));
00258       }
00259     }
00260 
00261     const int n = aMap.Extent();
00262     myFacesInd->length(n);
00263     for (int i = 1; i <= n; i++)
00264       myFacesInd[i-1] = aMap(i);
00265     if (n)
00266       myEditCurrentArgument->setText(QString::number(n) + "_" + tr("GEOM_FACE") + tr("_S_"));
00267   }
00268 }
00269 
00270 //=================================================================================
00271 // function : SetEditCurrentArgument()
00272 // purpose  :
00273 //=================================================================================
00274 void RepairGUI_SuppressFacesDlg::SetEditCurrentArgument()
00275 {
00276   QPushButton* send = (QPushButton*)sender();
00277 
00278   bool isEffective = false;
00279 
00280   if (send == GroupArgs->PushButton1) {
00281     isEffective = true;
00282     myEditCurrentArgument = GroupArgs->LineEdit1;
00283 
00284     GroupArgs->PushButton2->setDown(false);
00285     GroupArgs->LineEdit2->setEnabled(false);
00286   }
00287   else if (send == GroupArgs->PushButton2 && !myObject->_is_nil()) {
00288     isEffective = true;
00289     myEditCurrentArgument = GroupArgs->LineEdit2;
00290 
00291     GroupArgs->PushButton1->setDown(false);
00292     GroupArgs->LineEdit1->setEnabled(false);
00293   }
00294 
00295   if (isEffective) {
00296     initSelection();
00297 
00298     // enable line edit
00299     myEditCurrentArgument->setEnabled(true);
00300     myEditCurrentArgument->setFocus();
00301     // after setFocus(), because it will be setDown(false) when loses focus
00302     send->setDown(true);
00303   }
00304 }
00305 
00306 //=================================================================================
00307 // function : LineEditReturnPressed()
00308 // purpose  :
00309 //=================================================================================
00310 void RepairGUI_SuppressFacesDlg::LineEditReturnPressed()
00311 {
00312   const QObject* send = sender();
00313   if (send == GroupArgs->LineEdit1 || send == GroupArgs->LineEdit2) {
00314     myEditCurrentArgument = (QLineEdit*)send;
00315     GEOMBase_Skeleton::LineEditReturnPressed();
00316   }
00317 }
00318 
00319 //=================================================================================
00320 // function : ActivateThisDialog()
00321 // purpose  :
00322 //=================================================================================
00323 void RepairGUI_SuppressFacesDlg::ActivateThisDialog()
00324 {
00325   GEOMBase_Skeleton::ActivateThisDialog();
00326   connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
00327            this, SLOT( SelectionIntoArgument() ) );
00328 
00329   myEditCurrentArgument = GroupArgs->LineEdit1;
00330   myEditCurrentArgument->setText( "" );
00331   GroupArgs->LineEdit2->setText( "" );
00332   myObject = GEOM::GEOM_Object::_nil();
00333   myFacesInd->length( 0 );
00334 
00335   initSelection();
00336 }
00337 
00338 //=================================================================================
00339 // function : enterEvent()
00340 // purpose  : Mouse enter onto the dialog to activate it
00341 //=================================================================================
00342 void RepairGUI_SuppressFacesDlg::enterEvent (QEvent*)
00343 {
00344   if (!mainFrame()->GroupConstructors->isEnabled())
00345     ActivateThisDialog();
00346 }
00347 
00348 //=================================================================================
00349 // function : createOperation
00350 // purpose  :
00351 //=================================================================================
00352 GEOM::GEOM_IOperations_ptr RepairGUI_SuppressFacesDlg::createOperation()
00353 {
00354   return getGeomEngine()->GetIHealingOperations(getStudyId());
00355 }
00356 
00357 //=================================================================================
00358 // function : isValid
00359 // purpose  :
00360 //=================================================================================
00361 bool RepairGUI_SuppressFacesDlg::isValid (QString&)
00362 {
00363   TopoDS_Shape aTmpShape;
00364   return !myObject->_is_nil() && (myFacesInd->length() ||
00365                                   GEOMBase::GetShape(myObject, aTmpShape, TopAbs_WIRE));
00366 }
00367 
00368 //=================================================================================
00369 // function : execute
00370 // purpose  :
00371 //=================================================================================
00372 bool RepairGUI_SuppressFacesDlg::execute (ObjectList& objects)
00373 {
00374   GEOM::GEOM_IHealingOperations_var anOper = GEOM::GEOM_IHealingOperations::_narrow(getOperation());
00375   GEOM::GEOM_Object_var anObj = anOper->SuppressFaces(myObject, myFacesInd);
00376 
00377   bool aResult = !anObj->_is_nil();
00378   if (aResult)
00379     objects.push_back(anObj._retn());
00380 
00381   return aResult;
00382 }
00383 
00384 //=================================================================================
00385 // function : initSelection
00386 // purpose  :
00387 //=================================================================================
00388 void RepairGUI_SuppressFacesDlg::initSelection()
00389 {
00390   disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
00391 
00392   if (myEditCurrentArgument == GroupArgs->LineEdit1) {
00393     TColStd_MapOfInteger aTypes;
00394     aTypes.Add(GEOM_COMPOUND);
00395     aTypes.Add(GEOM_SOLID);
00396     aTypes.Add(GEOM_SHELL);
00397     aTypes.Add(GEOM_FACE);
00398 
00399     globalSelection(aTypes);
00400   }
00401   else if (myEditCurrentArgument == GroupArgs->LineEdit2) {
00402     localSelection(myObject, TopAbs_FACE);
00403   }
00404 
00405   connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
00406           this, SLOT(SelectionIntoArgument()));
00407 }
00408 
00409 //=================================================================================
00410 // function : restoreSubShapes
00411 // purpose  :
00412 //=================================================================================
00413 void RepairGUI_SuppressFacesDlg::restoreSubShapes (SALOMEDS::Study_ptr   theStudy,
00414                                                    SALOMEDS::SObject_ptr theSObject)
00415 {
00416   if (mainFrame()->CheckBoxRestoreSS->isChecked()) {
00417     // empty list of arguments means that all arguments should be restored
00418     getGeomEngine()->RestoreSubShapesSO(theStudy, theSObject, GEOM::ListOfGO(),
00419                                         /*theFindMethod=*/GEOM::FSM_GetInPlace,
00420                                         /*theInheritFirstArg=*/true,
00421                                         mainFrame()->CheckBoxAddPrefix->isChecked());
00422   }
00423 }