Back to index

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