Back to index

salome-geom  6.5.0
RepairGUI_LimitToleranceDlg.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_LimitToleranceDlg.cxx
00023 
00024 #include "RepairGUI_LimitToleranceDlg.h"
00025 
00026 #include <DlgRef.h>
00027 #include <GeometryGUI.h>
00028 #include <GEOMBase.h>
00029 #include <SalomeApp_DoubleSpinBox.h>
00030 
00031 #include <SalomeApp_Application.h>
00032 #include <LightApp_SelectionMgr.h>
00033 #include <SalomeApp_Study.h>
00034 #include <SalomeApp_Tools.h>
00035 #include <SUIT_Session.h>
00036 #include <SUIT_Desktop.h>
00037 #include <SUIT_MessageBox.h>
00038 #include <SUIT_OverrideCursor.h>
00039 #include <SUIT_ResourceMgr.h>
00040 #include <SUIT_ViewWindow.h>
00041 #include <SUIT_ViewManager.h>
00042 #include <OCCViewer_ViewModel.h>
00043 #include <SALOME_ListIteratorOfListIO.hxx>
00044 
00045 #include <GEOMImpl_Types.hxx>
00046 
00047 #include <TCollection_AsciiString.hxx>
00048 
00049 #define DEFAULT_TOLERANCE_VALUE 1e-07
00050 
00051 //=================================================================================
00052 // class    : RepairGUI_LimitToleranceDlg()
00053 // purpose  : Constructs a RepairGUI_LimitToleranceDlg  which is a child of 'parent', with the
00054 //            name 'name' and widget flags set to 'f'.
00055 //            The dialog will by default be modeless, unless you set 'modal' to
00056 //            TRUE to construct a modal dialog.
00057 //=================================================================================
00058 RepairGUI_LimitToleranceDlg::RepairGUI_LimitToleranceDlg(GeometryGUI* theGeometryGUI,
00059                                                          QWidget* parent, bool modal)
00060   : GEOMBase_Skeleton(theGeometryGUI, parent, modal)
00061 {
00062   QPixmap image0 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_DLG_LIMIT_TOLERANCE")));
00063   QPixmap image1 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_SELECT")));
00064 
00065   setWindowTitle(tr("GEOM_LIMIT_TOLERANCE_TITLE"));
00066 
00067   /***************************************************************/
00068   mainFrame()->GroupConstructors->setTitle(tr("GEOM_LIMIT_TOLERANCE_TITLE"));
00069   mainFrame()->RadioButton1->setIcon(image0);
00070   mainFrame()->RadioButton2->setAttribute(Qt::WA_DeleteOnClose);
00071   mainFrame()->RadioButton3->setAttribute(Qt::WA_DeleteOnClose);
00072   mainFrame()->RadioButton2->close();
00073   mainFrame()->RadioButton3->close();
00074 
00075   GroupPoints = new DlgRef_1SelExt(centralWidget());
00076   GroupPoints->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
00077   GroupPoints->TextLabel1->setText(tr("GEOM_SELECTED_SHAPE"));
00078   GroupPoints->PushButton1->setIcon(image1);
00079   GroupPoints->LineEdit1->setReadOnly(true);
00080 
00081   QLabel* aTolLab = new QLabel(tr("GEOM_TOLERANCE"), GroupPoints->Box);
00082   myTolEdt = new SalomeApp_DoubleSpinBox(GroupPoints->Box);
00083   initSpinBox(myTolEdt, 0., 100., DEFAULT_TOLERANCE_VALUE, "len_tol_precision");
00084   myTolEdt->setValue(DEFAULT_TOLERANCE_VALUE);
00085 
00086   QGridLayout* boxLayout = new QGridLayout(GroupPoints->Box);
00087   boxLayout->setMargin(0); boxLayout->setSpacing(6);
00088   boxLayout->addWidget(aTolLab,  0, 0);
00089   boxLayout->addWidget(myTolEdt, 0, 2);
00090 
00091   QVBoxLayout* layout = new QVBoxLayout(centralWidget());
00092   layout->setMargin(0); layout->setSpacing(6);
00093   layout->addWidget(GroupPoints);
00094 
00095   setHelpFileName("limit_tolerance_operation_page.html");
00096 
00097   Init();
00098 }
00099 
00100 
00101 //=================================================================================
00102 // function : ~RepairGUI_LimitToleranceDlg()
00103 // purpose  : Destroys the object and frees any allocated resources
00104 //=================================================================================
00105 RepairGUI_LimitToleranceDlg::~RepairGUI_LimitToleranceDlg()
00106 {
00107 }
00108 
00109 
00110 //=================================================================================
00111 // function : Init()
00112 // purpose  :
00113 //=================================================================================
00114 void RepairGUI_LimitToleranceDlg::Init()
00115 {
00116   /* init variables */
00117   myEditCurrentArgument = GroupPoints->LineEdit1;
00118 
00119   myObject = GEOM::GEOM_Object::_nil();
00120 
00121   //myGeomGUI->SetState(0);
00122   //globalSelection(GEOM_COMPOUND);
00123 
00124   mainFrame()->GroupBoxPublish->show();
00125   //Hide preview checkbox
00126   mainFrame()->CheckBoxPreview->hide();
00127 
00128   /* signals and slots connections */
00129   connect(buttonOk(),    SIGNAL(clicked()), this, SLOT(ClickOnOk()));
00130   connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
00131 
00132   connect(GroupPoints->PushButton1,  SIGNAL(clicked()),       this, SLOT(SetEditCurrentArgument()));
00133   connect(GroupPoints->LineEdit1,    SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
00134 
00135   connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
00136           this, SLOT(SelectionIntoArgument()));
00137 
00138   initName(tr("LIMIT_TOLERANCE_NEW_OBJ_NAME"));
00139 
00140   ConstructorsClicked(0);
00141 
00142   activateSelection();
00143   updateButtonState();
00144 }
00145 
00146 
00147 //=================================================================================
00148 // function : ConstructorsClicked()
00149 // purpose  : Radio button management
00150 //=================================================================================
00151 void RepairGUI_LimitToleranceDlg::ConstructorsClicked(int constructorId)
00152 {
00153   disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
00154 
00155   GroupPoints->show();
00156   GroupPoints->LineEdit1->setText("");
00157   myEditCurrentArgument = GroupPoints->LineEdit1;
00158   myEditCurrentArgument->setFocus();
00159 
00160   connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
00161            this, SLOT(SelectionIntoArgument()));
00162 
00163   qApp->processEvents();
00164   updateGeometry();
00165   resize(minimumSizeHint());
00166 
00167   updateButtonState();
00168   activateSelection();
00169   SelectionIntoArgument();
00170 }
00171 
00172 
00173 //=================================================================================
00174 // function : ClickOnOk()
00175 // purpose  : Same than click on apply but close this dialog.
00176 //=================================================================================
00177 void RepairGUI_LimitToleranceDlg::ClickOnOk()
00178 {
00179   setIsApplyAndClose( true );
00180   if (ClickOnApply())
00181     ClickOnCancel();
00182 }
00183 
00184 //=================================================================================
00185 // function : ClickOnApply()
00186 // purpose  :
00187 //=================================================================================
00188 bool RepairGUI_LimitToleranceDlg::ClickOnApply()
00189 {
00190   if (!onAcceptLocal())
00191     return false;
00192 
00193   initName();
00194 
00195   ConstructorsClicked(0);
00196 
00197   return true;
00198 }
00199 
00200 //=================================================================================
00201 // function : SelectionIntoArgument()
00202 // purpose  : Called when selection
00203 //=================================================================================
00204 void RepairGUI_LimitToleranceDlg::SelectionIntoArgument()
00205 {
00206   myEditCurrentArgument->setText("");
00207   myObject = GEOM::GEOM_Object::_nil();
00208 
00209   LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
00210   SALOME_ListIO aSelList;
00211   aSelMgr->selectedObjects(aSelList);
00212 
00213   if (aSelList.Extent() == 1) {
00214     Handle(SALOME_InteractiveObject) anIO = aSelList.First();
00215     myObject = GEOMBase::ConvertIOinGEOMObject( anIO );
00216     if ( !CORBA::is_nil( myObject ) )
00217       myEditCurrentArgument->setText(GEOMBase::GetName(myObject));
00218   }
00219   updateButtonState();
00220 }
00221 
00222 //=================================================================================
00223 // function : SetEditCurrentArgument()
00224 // purpose  :
00225 //=================================================================================
00226 void RepairGUI_LimitToleranceDlg::SetEditCurrentArgument()
00227 {
00228   const QObject* send = sender();
00229   if (send == GroupPoints->PushButton1)  {
00230     myEditCurrentArgument->setFocus();
00231     SelectionIntoArgument();
00232   }
00233 }
00234 
00235 //=================================================================================
00236 // function : LineEditReturnPressed()
00237 // purpose  :
00238 //=================================================================================
00239 void RepairGUI_LimitToleranceDlg::LineEditReturnPressed()
00240 {
00241   const QObject* send = sender();
00242   if (send == GroupPoints->LineEdit1) {
00243     myEditCurrentArgument = GroupPoints->LineEdit1;
00244     GEOMBase_Skeleton::LineEditReturnPressed();
00245   }
00246 }
00247 
00248 //=================================================================================
00249 // function : ActivateThisDialog()
00250 // purpose  :
00251 //=================================================================================
00252 void RepairGUI_LimitToleranceDlg::ActivateThisDialog()
00253 {
00254   GEOMBase_Skeleton::ActivateThisDialog();
00255   connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
00256            this, SLOT(SelectionIntoArgument()));
00257   activateSelection();
00258 }
00259 
00260 //=================================================================================
00261 // function : enterEvent()
00262 // purpose  : Mouse enter onto the dialog to activate it
00263 //=================================================================================
00264 void RepairGUI_LimitToleranceDlg::enterEvent(QEvent*)
00265 {
00266   if (!mainFrame()->GroupConstructors->isEnabled())
00267     ActivateThisDialog();
00268 }
00269 
00270 //=================================================================================
00271 // function : createOperation
00272 // purpose  :
00273 //=================================================================================
00274 GEOM::GEOM_IOperations_ptr RepairGUI_LimitToleranceDlg::createOperation()
00275 {
00276   return getGeomEngine()->GetIHealingOperations(getStudyId());
00277 }
00278 
00279 //=================================================================================
00280 // function : isValid
00281 // purpose  :
00282 //=================================================================================
00283 bool RepairGUI_LimitToleranceDlg::isValid(QString& msg)
00284 {
00285   double v = myTolEdt->value();
00286   bool ok = myTolEdt->isValid(msg, true);
00287   return !myObject->_is_nil() && (v > 0.) && ok;
00288 }
00289 
00290 //=================================================================================
00291 // function : execute
00292 // purpose  :
00293 //=================================================================================
00294 bool RepairGUI_LimitToleranceDlg::execute(ObjectList& objects)
00295 {
00296   bool aResult = false;
00297   objects.clear();
00298 
00299   GEOM::GEOM_IHealingOperations_var anOper = GEOM::GEOM_IHealingOperations::_narrow(getOperation());
00300   GEOM::GEOM_Object_var anObj = anOper->LimitTolerance(myObject, myTolEdt->value());
00301   aResult = !anObj->_is_nil();
00302   if (aResult) {
00303     QStringList aParameters;
00304     aParameters << myTolEdt->text();
00305     anObj->SetParameters(aParameters.join(":").toLatin1().constData());
00306     objects.push_back(anObj._retn());
00307   }
00308 
00309   return aResult;
00310 }
00311 
00312 //================================================================
00313 // Function : onAccept
00314 // Purpose  : This method should be called from dialog's slots onOk() and onApply()
00315 //            It perfroms user input validation, then it
00316 //            performs a proper operation and manages transactions, etc.
00317 //================================================================
00318 bool RepairGUI_LimitToleranceDlg::onAcceptLocal()
00319 {
00320   if (!getStudy() || !(getStudy()->studyDS()))
00321     return false;
00322 
00323   _PTR(Study) aStudy = getStudy()->studyDS();
00324 
00325   bool aLocked = aStudy->GetProperties()->IsLocked();
00326   if (aLocked) {
00327     MESSAGE("GEOMBase_Helper::onAccept - ActiveStudy is locked");
00328     SUIT_MessageBox::warning(this, tr("WRN_WARNING"), tr("WRN_STUDY_LOCKED"), tr("BUT_OK"));
00329     return false;
00330   }
00331 
00332   QString msg;
00333   if (!isValid(msg)) {
00334     showError(msg);
00335     return false;
00336   }
00337 
00338   try {
00339     if (openCommand()) {
00340       SUIT_OverrideCursor wc;
00341 
00342       myGeomGUI->getApp()->putInfo("");
00343       ObjectList objects;
00344 
00345       if (!execute(objects)) {
00346         wc.suspend();
00347         abortCommand();
00348         showError();
00349       }
00350       else {
00351         const int nbObjs = objects.size();
00352         for (ObjectList::iterator it = objects.begin(); it != objects.end(); ++it) {
00353           QString aName = getNewObjectName();
00354           if (nbObjs > 1) {
00355             if (aName.isEmpty())
00356               aName = getPrefix(*it);
00357             aName = GEOMBase::GetDefaultName(aName);
00358           }
00359           else {
00360             // PAL6521: use a prefix, if some dialog box doesn't reimplement getNewObjectName()
00361             if (aName.isEmpty())
00362               aName = GEOMBase::GetDefaultName(getPrefix(*it));
00363           }
00364           addInStudy(*it, aName.toLatin1().data());
00365           display(*it, false);
00366         }
00367 
00368         if (nbObjs) {
00369           commitCommand();
00370           updateObjBrowser();
00371           myGeomGUI->getApp()->putInfo(QObject::tr("GEOM_PRP_DONE"));
00372         }
00373         else {
00374           abortCommand();
00375         }
00376 
00377         // JFA 28.12.2004 BEGIN // To enable warnings
00378         GEOM::GEOM_IHealingOperations_var anOper = GEOM::GEOM_IHealingOperations::_narrow(getOperation());
00379         if (!CORBA::is_nil(anOper) && !anOper->IsDone()) {
00380           wc.suspend();
00381           QString msgw = QObject::tr(anOper->GetErrorCode());
00382           SUIT_MessageBox::warning(this, tr("WRN_WARNING"), msgw, tr("BUT_OK"));
00383         }
00384         // JFA 28.12.2004 END
00385       }
00386     }
00387   }
00388   catch(const SALOME::SALOME_Exception& e) {
00389     SalomeApp_Tools::QtCatchCorbaException(e);
00390     abortCommand();
00391   }
00392 
00393   updateViewer();
00394   activateSelection();
00395   updateButtonState();
00396 
00397   return true;
00398 }
00399 
00400 //=================================================================================
00401 // function : activateSelection
00402 // purpose  : Activate selection
00403 //=================================================================================
00404 void RepairGUI_LimitToleranceDlg::activateSelection()
00405 {
00406   disconnect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
00407              this, SLOT(SelectionIntoArgument()));
00408 
00409   globalSelection(GEOM_ALLSHAPES);
00410   if (myObject->_is_nil())
00411     SelectionIntoArgument();
00412 
00413   connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
00414           this, SLOT(SelectionIntoArgument()));
00415   updateViewer();
00416 }
00417 
00418 //=================================================================================
00419 // function : updateButtonState
00420 // purpose  : Update button state
00421 //=================================================================================
00422 void RepairGUI_LimitToleranceDlg::updateButtonState()
00423 {
00424   bool hasMainObj = !myObject->_is_nil();
00425   buttonOk()->setEnabled(hasMainObj);
00426   buttonApply()->setEnabled(hasMainObj);
00427 }
00428 
00429 //=================================================================================
00430 // function : restoreSubShapes
00431 // purpose  :
00432 //=================================================================================
00433 void RepairGUI_LimitToleranceDlg::restoreSubShapes(SALOMEDS::Study_ptr   theStudy,
00434                                                    SALOMEDS::SObject_ptr theSObject)
00435 {
00436   if (mainFrame()->CheckBoxRestoreSS->isChecked()) {
00437     // empty list of arguments means that all arguments should be restored
00438     getGeomEngine()->RestoreSubShapesSO(theStudy, theSObject, GEOM::ListOfGO(),
00439                                         GEOM::FSM_GetInPlace, /*theInheritFirstArg=*/true,
00440                                         mainFrame()->CheckBoxAddPrefix->isChecked());
00441   }
00442 }