Back to index

salome-geom  6.5.0
RepairGUI_GlueDlg.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 RepairGUI : GUI for Geometry component
00024 // File   : RepairGUI_GlueDlg.cxx
00025 // Author : Lucien PIGNOLONI, Open CASCADE S.A.S.
00026 
00027 #include "RepairGUI_GlueDlg.h"
00028 
00029 #include <DlgRef.h>
00030 #include <GeometryGUI.h>
00031 #include <GEOMBase.h>
00032 #include <SalomeApp_DoubleSpinBox.h>
00033 
00034 #include <SalomeApp_Application.h>
00035 #include <SalomeApp_Study.h>
00036 #include <SalomeApp_Tools.h>
00037 #include <LightApp_SelectionMgr.h>
00038 #include <SUIT_Session.h>
00039 #include <SUIT_Desktop.h>
00040 #include <SUIT_MessageBox.h>
00041 #include <SUIT_OverrideCursor.h>
00042 #include <SUIT_ResourceMgr.h>
00043 #include <SUIT_ViewWindow.h>
00044 #include <SUIT_ViewManager.h>
00045 #include <OCCViewer_ViewModel.h>
00046 #include <SALOME_ListIteratorOfListIO.hxx>
00047 
00048 #include <GEOMImpl_Types.hxx>
00049 
00050 #include <TCollection_AsciiString.hxx>
00051 
00052 #define DEFAULT_TOLERANCE_VALUE 1e-07
00053 
00054 //=================================================================================
00055 // class    : RepairGUI_GlueDlg()
00056 // purpose  : Constructs a RepairGUI_GlueDlg  which is a child of 'parent', with the
00057 //            name 'name' and widget flags set to 'f'.
00058 //            The dialog will by default be modeless, unless you set 'modal' to
00059 //            TRUE to construct a modal dialog.
00060 //=================================================================================
00061 RepairGUI_GlueDlg::RepairGUI_GlueDlg(GeometryGUI* theGeometryGUI, QWidget* parent,
00062                                      bool modal, TopAbs_ShapeEnum theGlueMode)
00063   : GEOMBase_Skeleton(theGeometryGUI, parent, modal),
00064     myCurrConstrId(-1), myGlueMode(theGlueMode)
00065 {
00066   QPixmap image0 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_SELECT")));
00067   QPixmap image1 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_DLG_GLUE_FACES")));
00068   QPixmap image2 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_DLG_GLUE_FACES2")));
00069   QPixmap image3 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_DLG_GLUE_EDGES")));
00070   QPixmap image4 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_DLG_GLUE_EDGES2")));
00071 
00072   QString aTitle;
00073   if (theGlueMode == TopAbs_FACE)
00074     aTitle = tr("GEOM_GLUE_FACES_TITLE");
00075   else if (theGlueMode == TopAbs_EDGE)
00076     aTitle = tr("GEOM_GLUE_EDGES_TITLE");
00077   setWindowTitle(aTitle);
00078 
00079   /***************************************************************/
00080   mainFrame()->GroupConstructors->setTitle(aTitle);
00081   if (theGlueMode == TopAbs_FACE) {
00082     mainFrame()->RadioButton1->setIcon(image1);
00083     mainFrame()->RadioButton2->setIcon(image2);
00084   }
00085   else if (theGlueMode == TopAbs_EDGE) {
00086     mainFrame()->RadioButton1->setIcon(image3);
00087     mainFrame()->RadioButton2->setIcon(image4);
00088   }
00089   mainFrame()->RadioButton3->setAttribute(Qt::WA_DeleteOnClose);
00090   mainFrame()->RadioButton3->close();
00091 
00092   GroupPoints = new DlgRef_1SelExt(centralWidget());
00093   GroupPoints->GroupBox1->setTitle(tr("GEOM_GLUE"));
00094   GroupPoints->TextLabel1->setText(tr("GEOM_SELECTED_SHAPE"));
00095   GroupPoints->PushButton1->setIcon(image0);
00096   GroupPoints->LineEdit1->setReadOnly(true);
00097 
00098   QLabel* aTolLab = new QLabel(tr("GEOM_TOLERANCE"), GroupPoints->Box);
00099   myTolEdt = new SalomeApp_DoubleSpinBox(GroupPoints->Box);
00100   initSpinBox(myTolEdt, 0., 100., DEFAULT_TOLERANCE_VALUE, "len_tol_precision");
00101   myTolEdt->setValue(DEFAULT_TOLERANCE_VALUE);
00102 
00103   QGridLayout* boxLayout = new QGridLayout(GroupPoints->Box);
00104   boxLayout->setMargin(0); boxLayout->setSpacing(6);
00105   boxLayout->addWidget(aTolLab,  0, 0);
00106   boxLayout->addWidget(myTolEdt, 0, 2);
00107   /***************************************************************/
00108 
00109   GroupPoints2 = new DlgRef_1SelExt(centralWidget());
00110   GroupPoints2->GroupBox1->setTitle(tr("GEOM_GLUE"));
00111   GroupPoints2->TextLabel1->setText(tr("GEOM_SELECTED_SHAPE"));
00112   GroupPoints2->PushButton1->setIcon(image0);
00113   GroupPoints2->LineEdit1->setReadOnly(true);
00114 
00115   QLabel* aTolLab2 = new QLabel(tr("GEOM_TOLERANCE"), GroupPoints2->Box);
00116   myTolEdt2 = new SalomeApp_DoubleSpinBox(GroupPoints2->Box);
00117   initSpinBox(myTolEdt2, 0., 100., DEFAULT_TOLERANCE_VALUE, "len_tol_precision");
00118   myTolEdt2->setValue(DEFAULT_TOLERANCE_VALUE);
00119 
00120   QString aGlueString (" [%1]");
00121   QString aSelString;
00122   if (theGlueMode == TopAbs_FACE) {
00123     aGlueString = aGlueString.arg(tr("GLUE_FACES"));
00124     aSelString = tr("SELECT_FACES");
00125   }
00126   else if (theGlueMode == TopAbs_EDGE) {
00127     aGlueString = aGlueString.arg(tr("GLUE_EDGES"));
00128     aSelString = tr("SELECT_EDGES");
00129   }
00130   myDetectBtn = new QPushButton (tr("GEOM_DETECT") + aGlueString, GroupPoints2->Box);
00131   mySubShapesChk = new QCheckBox (aSelString, GroupPoints2->Box);
00132   myGlueAllEdgesChk = 0;
00133 
00134   boxLayout = new QGridLayout(GroupPoints2->Box);
00135   boxLayout->setMargin(0); boxLayout->setSpacing(6);
00136   boxLayout->addWidget(aTolLab2,    0, 0);
00137   boxLayout->addWidget(myTolEdt2,   0, 2);
00138   boxLayout->addWidget(myDetectBtn, 1, 0, 1, 3);
00139   boxLayout->addWidget(mySubShapesChk, 2, 0, 1, 3);
00140 
00141   if (theGlueMode == TopAbs_FACE) {
00142     myGlueAllEdgesChk = new QCheckBox (tr("GLUE_ALL_EDGES"), GroupPoints2->Box);
00143     boxLayout->addWidget(myGlueAllEdgesChk, 3, 0, 1, 3);
00144     myGlueAllEdgesChk->setChecked(false);
00145   }
00146 
00147   QVBoxLayout* layout = new QVBoxLayout(centralWidget());
00148   layout->setMargin(0); layout->setSpacing(6);
00149   layout->addWidget(GroupPoints);
00150   layout->addWidget(GroupPoints2);
00151 
00152   /***************************************************************/
00153 
00154   QString aHelpFileName; 
00155   switch ( myGlueMode ) {
00156     case TopAbs_EDGE:
00157       {
00158         aHelpFileName = "glue_edges_operation_page.html";
00159         break;
00160       }
00161     case TopAbs_FACE:
00162       {
00163         aHelpFileName = "glue_faces_operation_page.html";
00164         break;
00165       }
00166   }
00167   setHelpFileName(aHelpFileName);
00168 
00169   // Disable second way of gluing if OCC viewer is not active one
00170   if (myGeomGUI->getApp()->desktop()->activeWindow()->getViewManager()->getType()
00171        != OCCViewer_Viewer::Type())
00172     mainFrame()->RadioButton2->setEnabled(false);
00173 
00174   Init();
00175 }
00176 
00177 //=================================================================================
00178 // function : ~RepairGUI_GlueDlg()
00179 // purpose  : Destroys the object and frees any allocated resources
00180 //=================================================================================
00181 RepairGUI_GlueDlg::~RepairGUI_GlueDlg()
00182 {
00183 }
00184 
00185 //=================================================================================
00186 // function : Init()
00187 // purpose  :
00188 //=================================================================================
00189 void RepairGUI_GlueDlg::Init()
00190 {
00191   /* init variables */
00192   myEditCurrentArgument = GroupPoints->LineEdit1;
00193 
00194   myObject = GEOM::GEOM_Object::_nil();
00195 
00196   //myGeomGUI->SetState(0);
00197   //globalSelection(GEOM_COMPOUND);
00198 
00199   mainFrame()->GroupBoxPublish->show();
00200   //Hide preview checkbox
00201   mainFrame()->CheckBoxPreview->hide();
00202 
00203   /* signals and slots connections */
00204   connect(buttonOk(),    SIGNAL(clicked()), this, SLOT(ClickOnOk()));
00205   connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
00206 
00207   connect(this,          SIGNAL(constructorsClicked(int)), this, SLOT(ConstructorsClicked(int)));
00208 
00209   connect(GroupPoints->PushButton1,  SIGNAL(clicked()),       this, SLOT(SetEditCurrentArgument()));
00210   connect(GroupPoints->LineEdit1,    SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
00211 
00212   connect(GroupPoints2->PushButton1, SIGNAL(clicked()),       this, SLOT(SetEditCurrentArgument()));
00213   connect(GroupPoints2->LineEdit1,   SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
00214   connect(myTolEdt2, SIGNAL(valueChanged(double)), this, SLOT(onTolerChanged(double)));
00215   connect(mySubShapesChk, SIGNAL(stateChanged(int)), this, SLOT(onSubShapesChk()));
00216 
00217   connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
00218            this, SLOT(SelectionIntoArgument()));
00219 
00220   connect(myDetectBtn, SIGNAL(clicked()), this, SLOT(onDetect()));
00221 
00222   initName(tr("GLUE_NEW_OBJ_NAME"));
00223 
00224   ConstructorsClicked(0);
00225 
00226   activateSelection();
00227   updateButtonState();
00228 }
00229 
00230 //=================================================================================
00231 // function : ConstructorsClicked()
00232 // purpose  : Radio button management
00233 //=================================================================================
00234 void RepairGUI_GlueDlg::ConstructorsClicked(int constructorId)
00235 {
00236   if (myCurrConstrId == constructorId)
00237     return;
00238 
00239   disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
00240 
00241   switch (constructorId) {
00242   case 0:
00243     GroupPoints2->hide();
00244     GroupPoints->show();
00245     GroupPoints->LineEdit1->setText("");
00246     myEditCurrentArgument = GroupPoints->LineEdit1;
00247 
00248     if (myCurrConstrId >= 0) {
00249       // i.e. it is not initialisation
00250       // copy tolerance from previous tolerance field
00251       myTolEdt->setValue(myTolEdt2->value());
00252     }
00253     break;
00254   case 1:
00255     GroupPoints->hide();
00256     GroupPoints2->show();
00257     GroupPoints->LineEdit1->setText("");
00258     myEditCurrentArgument = GroupPoints2->LineEdit1;
00259 
00260     if (myCurrConstrId >= 0) {
00261       // i.e. it is not initialisation
00262       // copy tolerance from previous tolerance field
00263       myTolEdt2->setValue(myTolEdt->value());
00264       mySubShapesChk->setChecked(false);
00265       clearTemporary();
00266     }
00267     break;
00268   }
00269 
00270   myCurrConstrId = constructorId;
00271 
00272   myEditCurrentArgument->setFocus();
00273 
00274   connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
00275            this, SLOT(SelectionIntoArgument()));
00276 
00277   qApp->processEvents();
00278   updateGeometry();
00279   resize(minimumSizeHint());
00280 
00281   processPreview();
00282   updateButtonState();
00283   activateSelection();
00284   SelectionIntoArgument();
00285 }
00286 
00287 //=================================================================================
00288 // function : ClickOnOk()
00289 // purpose  : Same than click on apply but close this dialog.
00290 //=================================================================================
00291 void RepairGUI_GlueDlg::ClickOnOk()
00292 {
00293   setIsApplyAndClose(true);
00294   if (ClickOnApply())
00295     ClickOnCancel();
00296 }
00297 
00298 //=================================================================================
00299 // function : ClickOnApply()
00300 // purpose  :
00301 //=================================================================================
00302 bool RepairGUI_GlueDlg::ClickOnApply()
00303 {
00304   if (!onAcceptLocal())
00305     return false;
00306 
00307   initName();
00308 
00309   //GroupPoints->LineEdit1->setText("");
00310   //myObject = GEOM::GEOM_Object::_nil();
00311 
00312   //globalSelection(GEOM_COMPOUND);
00313 
00314   ConstructorsClicked(getConstructorId());
00315 
00316   return true;
00317 }
00318 
00319 
00320 //=================================================================================
00321 // function : SelectionIntoArgument()
00322 // purpose  : Called when selection
00323 //=================================================================================
00324 void RepairGUI_GlueDlg::SelectionIntoArgument()
00325 {
00326   if (mySubShapesChk->isChecked() &&  getConstructorId() == 1) {
00327     updateButtonState();
00328     return;
00329   }
00330 
00331   erasePreview();
00332   myEditCurrentArgument->setText("");
00333   myObject = GEOM::GEOM_Object::_nil();
00334 
00335   LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
00336   SALOME_ListIO aSelList;
00337   aSelMgr->selectedObjects(aSelList);
00338 
00339   if (aSelList.Extent() == 1) {
00340     Handle(SALOME_InteractiveObject) anIO = aSelList.First();
00341     myObject = GEOMBase::ConvertIOinGEOMObject(anIO);
00342     if (!CORBA::is_nil(myObject))
00343       myEditCurrentArgument->setText(GEOMBase::GetName(myObject));
00344   }
00345   updateButtonState();
00346 }
00347 
00348 //=================================================================================
00349 // function : SetEditCurrentArgument()
00350 // purpose  :
00351 //=================================================================================
00352 void RepairGUI_GlueDlg::SetEditCurrentArgument()
00353 {
00354   const QObject* send = sender();
00355   if (send == GroupPoints->PushButton1 || send == GroupPoints2->PushButton1)  {
00356     myEditCurrentArgument->setFocus();
00357     SelectionIntoArgument();
00358   }
00359 }
00360 
00361 //=================================================================================
00362 // function : LineEditReturnPressed()
00363 // purpose  :
00364 //=================================================================================
00365 void RepairGUI_GlueDlg::LineEditReturnPressed()
00366 {
00367   const QObject* send = sender();
00368   if (send == GroupPoints->LineEdit1) {
00369     myEditCurrentArgument = GroupPoints->LineEdit1;
00370     GEOMBase_Skeleton::LineEditReturnPressed();
00371   }
00372   else if (send == GroupPoints2->LineEdit1) {
00373     myEditCurrentArgument = GroupPoints2->LineEdit1;
00374     GEOMBase_Skeleton::LineEditReturnPressed();
00375   }
00376 }
00377 
00378 //=================================================================================
00379 // function : ActivateThisDialog()
00380 // purpose  :
00381 //=================================================================================
00382 void RepairGUI_GlueDlg::ActivateThisDialog()
00383 {
00384   GEOMBase_Skeleton::ActivateThisDialog();
00385   connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
00386            this, SLOT(SelectionIntoArgument()));
00387 
00388   //GroupPoints->LineEdit1->setText("");
00389   //GroupPoints2->LineEdit1->setText("");
00390   //myObject = GEOM::GEOM_Object::_nil();
00391 
00392   //myGeomGUI->SetState(0);
00393   //globalSelection(GEOM_COMPOUND);
00394   activateSelection();
00395 }
00396 
00397 //=================================================================================
00398 // function : enterEvent()
00399 // purpose  : Mouse enter onto the dialog to activate it
00400 //=================================================================================
00401 void RepairGUI_GlueDlg::enterEvent(QEvent*)
00402 {
00403   if (!mainFrame()->GroupConstructors->isEnabled())
00404     ActivateThisDialog();
00405 }
00406 
00407 //=================================================================================
00408 // function : createOperation
00409 // purpose  :
00410 //=================================================================================
00411 GEOM::GEOM_IOperations_ptr RepairGUI_GlueDlg::createOperation()
00412 {
00413   return getGeomEngine()->GetIShapesOperations(getStudyId());
00414 }
00415 
00416 //=================================================================================
00417 // function : isValid
00418 // purpose  :
00419 //=================================================================================
00420 bool RepairGUI_GlueDlg::isValid(QString& msg)
00421 {
00422   bool ok = true;
00423   double v = 0;
00424   switch (getConstructorId())
00425   {
00426   case 0:
00427     v = myTolEdt->value();
00428     ok = myTolEdt->isValid(msg, !IsPreview());
00429     break;
00430   case 1:
00431     v = myTolEdt2->value();
00432     ok = myTolEdt2->isValid(msg, !IsPreview());
00433     break;
00434   }
00435   return !myObject->_is_nil() && (IsPreview() || v > 0.) && ok;
00436 }
00437 
00438 //=================================================================================
00439 // function : execute
00440 // purpose  :
00441 //=================================================================================
00442 bool RepairGUI_GlueDlg::execute(ObjectList& objects)
00443 {
00444   bool aResult = false;
00445   objects.clear();
00446 
00447   GEOM::GEOM_IShapesOperations_var anOper = GEOM::GEOM_IShapesOperations::_narrow(getOperation());
00448   switch (getConstructorId()) {
00449   case 0:
00450     {
00451       GEOM::GEOM_Object_var anObj;
00452       if (myGlueMode == TopAbs_FACE)
00453         anObj = anOper->MakeGlueFaces(myObject, myTolEdt->value(), true);
00454       else if (myGlueMode == TopAbs_EDGE)
00455         anObj = anOper->MakeGlueEdges(myObject, myTolEdt->value());
00456 
00457       aResult = !anObj->_is_nil();
00458       if (aResult && !IsPreview())
00459       {
00460         QStringList aParameters;
00461         aParameters << myTolEdt->text();
00462         anObj->SetParameters(aParameters.join(":").toLatin1().constData());
00463 
00464         objects.push_back(anObj._retn());
00465       }
00466       break;
00467     }
00468   case 1:
00469     {
00470       if (IsPreview()) {
00471         // if this method is used for displaying preview then we must detect glue faces/edges only
00472         for (int i = 0; i < myTmpObjs.count(); i++) {
00473           myTmpObjs[i].get()->Register(); // increment counter, since calling function will call UnRegister()
00474           objects.push_back(myTmpObjs[i].copy());
00475         }
00476         return !myTmpObjs.isEmpty();
00477       } // IsPreview
00478 
00479       // Make glue faces/edges by list.
00480       // Iterate through myTmpObjs and verifies where each object is currently selected or not.
00481       QSet<QString> selected;
00482 
00483       // Get names of selected objects
00484       LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
00485       SALOME_ListIO aSelList;
00486       aSelMgr->selectedObjects(aSelList);
00487 
00488       SALOME_ListIteratorOfListIO it (aSelList);
00489       for (; it.More(); it.Next())
00490         selected.insert(it.Value()->getName());
00491 
00492       // Iterate through result and select objects with names from selection
00493       // ObjectList toRemoveFromEnggine;
00494 
00495       // make glue faces/edges
00496       GEOM::ListOfGO_var aListForGlue = new GEOM::ListOfGO();
00497       aListForGlue->length(myTmpObjs.count());
00498       int added = 0;
00499       for (int i = 0; i < myTmpObjs.count(); i++) {
00500         CORBA::String_var tmpior = myGeomGUI->getApp()->orb()->object_to_string(myTmpObjs[i].get());
00501         if (selected.contains(tmpior.in()))
00502           aListForGlue[ added++ ] = myTmpObjs[i].copy();
00503       }
00504       aListForGlue->length(added);
00505 
00506       GEOM::GEOM_Object_var anObj;
00507       if (myGlueMode == TopAbs_FACE) {
00508         bool doGlueAllEdges = myGlueAllEdgesChk->isChecked();
00509         anObj = anOper->MakeGlueFacesByList(myObject, myTolEdt2->value(), aListForGlue.in(),
00510                                             true, doGlueAllEdges);
00511       }
00512       else if (myGlueMode == TopAbs_EDGE)
00513         anObj = anOper->MakeGlueEdgesByList(myObject, myTolEdt2->value(), aListForGlue.in());
00514 
00515       aResult = !anObj->_is_nil();
00516 
00517       if (aResult) {
00518         if (!IsPreview()) {
00519           QStringList aParameters;
00520           aParameters << myTolEdt2->text();
00521           anObj->SetParameters(aParameters.join(":").toLatin1().constData());
00522         }
00523         objects.push_back(anObj._retn());
00524       }
00525 
00526       // Remove from engine useless objects
00527       clearTemporary();
00528 
00529       updateButtonState();
00530 
00531       break;
00532     } // case 1
00533   } // switch
00534 
00535   return aResult;
00536 }
00537 
00538 //=================================================================================
00539 // function : restoreSubShapes
00540 // purpose  :
00541 //=================================================================================
00542 void RepairGUI_GlueDlg::restoreSubShapes(SALOMEDS::Study_ptr   theStudy,
00543                                           SALOMEDS::SObject_ptr theSObject)
00544 {
00545   if (mainFrame()->CheckBoxRestoreSS->isChecked()) {
00546     GEOM::find_shape_method aFindMethod = GEOM::FSM_GetInPlace;
00547     if (getConstructorId() == 0) // MakeGlueFaces or MakeGlueEdges
00548       aFindMethod = GEOM::FSM_GetInPlaceByHistory;
00549 
00550     // empty list of arguments means that all arguments should be restored
00551     getGeomEngine()->RestoreSubShapesSO(theStudy, theSObject, GEOM::ListOfGO(),
00552                                          aFindMethod, /*theInheritFirstArg=*/true,
00553                                          mainFrame()->CheckBoxAddPrefix->isChecked());
00554   }
00555 }
00556 
00557 //================================================================
00558 // Function : clearShapeBufferLocal
00559 // Purpose  :
00560 //================================================================
00561 void RepairGUI_GlueDlg::clearShapeBufferLocal(GEOM::GEOM_Object_ptr theObj)
00562 {
00563   if (CORBA::is_nil(theObj))
00564     return;
00565 
00566   CORBA::String_var IOR = myGeomGUI->getApp()->orb()->object_to_string(theObj);
00567   TCollection_AsciiString asciiIOR((char *)(IOR.in()));
00568   myGeomGUI->GetShapeReader().RemoveShapeFromBuffer(asciiIOR);
00569 
00570   if (!getStudy() || !(getStudy()->studyDS()))
00571     return;
00572 
00573   _PTR(Study) aStudy = getStudy()->studyDS();
00574   _PTR(SObject) aSObj (aStudy->FindObjectIOR(std::string(IOR.in())));
00575   if (!aSObj)
00576     return;
00577 
00578   _PTR(ChildIterator) anIt (aStudy->NewChildIterator(aSObj));
00579   for (anIt->InitEx(true); anIt->More(); anIt->Next()) {
00580     _PTR(GenericAttribute) anAttr;
00581     if (anIt->Value()->FindAttribute(anAttr, "AttributeIOR")) {
00582       _PTR(AttributeIOR) anIOR (anAttr);
00583       TCollection_AsciiString asciiIOR((char*)anIOR->Value().c_str());
00584       myGeomGUI->GetShapeReader().RemoveShapeFromBuffer(asciiIOR);
00585     }
00586   }
00587 }
00588 
00589 //================================================================
00590 // Function : onAccept
00591 // Purpose  : This method should be called from dialog's slots onOk() and onApply()
00592 //            It perfroms user input validation, then it
00593 //            performs a proper operation and manages transactions, etc.
00594 //================================================================
00595 bool RepairGUI_GlueDlg::onAcceptLocal()
00596 {
00597   if (!getStudy() || !(getStudy()->studyDS()))
00598     return false;
00599 
00600   _PTR(Study) aStudy = getStudy()->studyDS();
00601 
00602   bool aLocked = aStudy->GetProperties()->IsLocked();
00603   if (aLocked) {
00604     MESSAGE("GEOMBase_Helper::onAccept - ActiveStudy is locked");
00605     SUIT_MessageBox::warning(this, tr("WRN_WARNING"), tr("WRN_STUDY_LOCKED"), tr("BUT_OK"));
00606     return false;
00607   }
00608 
00609   QString msg;
00610   if (!isValid(msg)) {
00611     showError(msg);
00612     return false;
00613   }
00614 
00615   erasePreview(false);
00616 
00617   try {
00618     if (openCommand()) {
00619       SUIT_OverrideCursor wc;
00620 
00621       myGeomGUI->getApp()->putInfo("");
00622       ObjectList objects;
00623 
00624       if (!execute(objects)) {
00625         wc.suspend();
00626         abortCommand();
00627         showError();
00628       }
00629       else {
00630         const int nbObjs = objects.size();
00631         for (ObjectList::iterator it = objects.begin(); it != objects.end(); ++it) {
00632           QString aName = getNewObjectName();
00633           if (nbObjs > 1) {
00634             if (aName.isEmpty())
00635               aName = getPrefix(*it);
00636             aName = GEOMBase::GetDefaultName(aName);
00637           }
00638           else {
00639             // PAL6521: use a prefix, if some dialog box doesn't reimplement getNewObjectName()
00640             if (aName.isEmpty())
00641               aName = GEOMBase::GetDefaultName(getPrefix(*it));
00642           }
00643           addInStudy(*it, aName.toLatin1().data());
00644           display(*it, false);
00645         }
00646 
00647         if (nbObjs) {
00648           commitCommand();
00649           updateObjBrowser();
00650           myGeomGUI->getApp()->putInfo(QObject::tr("GEOM_PRP_DONE"));
00651         }
00652         else {
00653           abortCommand();
00654         }
00655 
00656         // JFA 28.12.2004 BEGIN // To enable warnings
00657         GEOM::GEOM_IShapesOperations_var anOper = GEOM::GEOM_IShapesOperations::_narrow(getOperation());
00658         if (!CORBA::is_nil(anOper) && !anOper->IsDone()) {
00659           wc.suspend();
00660           QString msgw = QObject::tr(anOper->GetErrorCode());
00661           SUIT_MessageBox::warning(this, tr("WRN_WARNING"), msgw, tr("BUT_OK"));
00662         }
00663         // JFA 28.12.2004 END
00664       }
00665     }
00666   }
00667   catch(const SALOME::SALOME_Exception& e) {
00668     SalomeApp_Tools::QtCatchCorbaException(e);
00669     abortCommand();
00670   }
00671 
00672   updateViewer();
00673   activateSelection();
00674   updateButtonState();
00675 
00676   return true;
00677 }
00678 
00679 //=================================================================================
00680 // function : onDetect
00681 // purpose  :
00682 //=================================================================================
00683 void RepairGUI_GlueDlg::onDetect()
00684 {
00685   clearTemporary();
00686   QString msg;
00687   if (!isValid(msg)) {
00688     showError(msg);
00689     return;
00690   }
00691 
00692   buttonOk()->setEnabled(false);
00693   buttonApply()->setEnabled(false);
00694   globalSelection(GEOM_ALLSHAPES);
00695 
00696   GEOM::GEOM_IShapesOperations_var anOper = GEOM::GEOM_IShapesOperations::_narrow(getOperation());
00697   GEOM::ListOfGO_var aList;
00698   if (myGlueMode == TopAbs_FACE)
00699     aList = anOper->GetGlueFaces(myObject.in(), myTolEdt2->value());
00700   else if (myGlueMode == TopAbs_EDGE)
00701     aList = anOper->GetGlueEdges(myObject.in(), myTolEdt2->value());
00702 
00703   for (int i = 0, n = aList->length(); i < n; i++)
00704     myTmpObjs << GEOM::GeomObjPtr(aList[i].in());
00705 
00706   if (!myTmpObjs.isEmpty()) {
00707     if (myGlueMode == TopAbs_FACE)
00708       msg = tr("FACES_FOR_GLUING_ARE_DETECTED").arg(myTmpObjs.count());
00709     else if (myGlueMode == TopAbs_EDGE)
00710       msg = tr("EDGES_FOR_GLUING_ARE_DETECTED").arg(myTmpObjs.count());
00711     mySubShapesChk->setChecked(true);
00712   }
00713   else {
00714     if (myGlueMode == TopAbs_FACE)
00715       msg = tr("THERE_ARE_NO_FACES_FOR_GLUING");
00716     else if (myGlueMode == TopAbs_EDGE)
00717       msg = tr("THERE_ARE_NO_EDGES_FOR_GLUING");
00718   }
00719 
00720   connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
00721           this, SLOT(SelectionIntoArgument())) ;
00722   SUIT_MessageBox::information(this, tr("GEOM_FREE_BOUNDS_TLT"), msg, tr("Close"));
00723   updateButtonState();
00724   activateSelection();
00725 }
00726 
00727 //=================================================================================
00728 // function : activateSelection
00729 // purpose  : Redisplay preview and Activate selection
00730 //=================================================================================
00731 void RepairGUI_GlueDlg::activateSelection()
00732 {
00733   erasePreview(false);
00734 
00735   int anId = getConstructorId();
00736   if (anId == 0) {
00737     // Case of whole gluing
00738     disconnect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
00739                 this, SLOT(SelectionIntoArgument()));
00740 
00741     globalSelection(GEOM_ALLSHAPES);
00742     if (myObject->_is_nil())
00743       SelectionIntoArgument();
00744 
00745     connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
00746              this, SLOT(SelectionIntoArgument()));
00747   }
00748   else {
00749     // Second case of gluing
00750     if (!mySubShapesChk->isChecked())
00751       globalSelection(GEOM_ALLSHAPES);
00752     else {
00753       displayPreview(true, true, false, false, 2/*line width*/, 1/*display mode*/, Quantity_NOC_RED);
00754       disconnect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
00755                   this, SLOT(SelectionIntoArgument())) ;
00756       globalSelection(GEOM_PREVIEW);
00757       connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
00758                this, SLOT(SelectionIntoArgument())) ;
00759     }
00760   }
00761   updateViewer();
00762 }
00763 
00764 //=================================================================================
00765 // function : updateButtonState
00766 // purpose  : Update button state
00767 //=================================================================================
00768 void RepairGUI_GlueDlg::updateButtonState()
00769 {
00770   int anId = getConstructorId();
00771   bool hasMainObj = !myObject->_is_nil();
00772   if (anId == 0) {
00773     buttonOk()->setEnabled(hasMainObj);
00774     buttonApply()->setEnabled(hasMainObj);
00775   }
00776   else
00777   {
00778     LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
00779     SALOME_ListIO aSelList;
00780     aSelMgr->selectedObjects(aSelList);
00781 
00782     SALOME_ListIteratorOfListIO it (aSelList);
00783     bool wasSelected = it.More() > 0;
00784     bool wasDetected = !myTmpObjs.isEmpty();
00785     buttonOk()->setEnabled(hasMainObj && wasDetected && wasSelected);
00786     buttonApply()->setEnabled(hasMainObj && wasDetected && wasSelected);
00787     mySubShapesChk->setEnabled(hasMainObj && wasDetected);
00788     myDetectBtn->setEnabled(hasMainObj);
00789     if (!hasMainObj || !wasDetected)
00790       mySubShapesChk->setChecked(false);
00791   }
00792 }
00793 
00794 //=================================================================================
00795 // function : clearTemporary
00796 // purpose  : Remove temporary objects from engine
00797 //=================================================================================
00798 void RepairGUI_GlueDlg::clearTemporary()
00799 {
00800   myTmpObjs.clear();
00801 }
00802 
00803 //=================================================================================
00804 // function : onTolerChanged
00805 // purpose  : Remove temporary objects from engine
00806 //=================================================================================
00807 void RepairGUI_GlueDlg::onTolerChanged(double /*theVal*/)
00808 {
00809   clearTemporary();
00810   activateSelection();
00811   updateButtonState();
00812 }
00813 
00814 //=================================================================================
00815 // function : onSubShapesChk
00816 // purpose  : Update selection mode
00817 //=================================================================================
00818 void RepairGUI_GlueDlg::onSubShapesChk()
00819 {
00820   if (!mySubShapesChk->isChecked())
00821     clearTemporary();
00822   activateSelection();
00823   updateButtonState();
00824 }
00825 
00826 //=================================================================================
00827 // function : ClickOnCancel
00828 // purpose  : Remove temporary objects from engine and call method of base class
00829 //=================================================================================
00830 void RepairGUI_GlueDlg::ClickOnCancel()
00831 {
00832   clearTemporary();
00833   GEOMBase_Skeleton::ClickOnCancel();
00834 }