Back to index

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