Back to index

salome-geom  6.5.0
GroupGUI_GroupDlg.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   : GroupGUI_GroupDlg.cxx
00025 //  Author : Sergey ANIKIN, Open CASCADE S.A.S. (sergey.anikin@opencascade.com)
00026 
00027 #include "GroupGUI_GroupDlg.h"
00028 
00029 #include <DlgRef.h>
00030 #include <GEOMBase.h>
00031 #include <GeometryGUI.h>
00032 #include <GEOM_Displayer.h>
00033 
00034 #include <SalomeApp_Application.h>
00035 #include <SalomeApp_Study.h>
00036 
00037 #include <LightApp_SelectionMgr.h>
00038 
00039 #include <OCCViewer_ViewModel.h>
00040 #include <OCCViewer_ViewManager.h>
00041 #include <SVTK_ViewModel.h>
00042 #include <SALOME_Prs.h>
00043 #include <SALOME_ListIteratorOfListIO.hxx>
00044 
00045 #include <SUIT_ResourceMgr.h>
00046 #include <SUIT_Desktop.h>
00047 #include <SUIT_OverrideCursor.h>
00048 #include <SUIT_Session.h>
00049 #include <SUIT_ViewWindow.h>
00050 #include <SUIT_ViewManager.h>
00051 
00052 #include <QLabel>
00053 #include <QListWidget>
00054 #include <QLineEdit>
00055 #include <QMap>
00056 
00057 #include <AIS_ListOfInteractive.hxx>
00058 #include <AIS_ListIteratorOfListOfInteractive.hxx>
00059 
00060 #include <TopExp.hxx>
00061 #include <TopExp_Explorer.hxx>
00062 #include <TopTools_IndexedMapOfShape.hxx>
00063 #include <TColStd_IndexedMapOfInteger.hxx>
00064 #include <TColStd_MapOfInteger.hxx>
00065 #include <TColStd_DataMapIteratorOfDataMapOfIntegerInteger.hxx>
00066 
00067 #include <GEOMImpl_Types.hxx>
00068 
00069 enum { ALL_SUBSHAPES = 0, GET_IN_PLACE, SUBSHAPES_OF_SHAPE2, SUBSHAPES_OF_INVISIBLE_SHAPE2 };
00070 
00071 GroupGUI_GroupDlg::GroupGUI_GroupDlg (Mode mode, GeometryGUI* theGeometryGUI, QWidget* parent)
00072   : GEOMBase_Skeleton(theGeometryGUI, parent, false),
00073     myMode(mode),
00074     myBusy(false),
00075     myIsShapeType(false),
00076     myIsHiddenMain(false)
00077 {
00078   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
00079 
00080   QPixmap image0     (resMgr->loadPixmap("GEOM", tr("ICON_OBJBROWSER_VERTEX")));
00081   QPixmap image1     (resMgr->loadPixmap("GEOM", tr("ICON_OBJBROWSER_EDGE")));
00082   QPixmap image2     (resMgr->loadPixmap("GEOM", tr("ICON_OBJBROWSER_FACE")));
00083   QPixmap image3     (resMgr->loadPixmap("GEOM", tr("ICON_OBJBROWSER_SOLID")));
00084   QPixmap iconSelect (resMgr->loadPixmap("GEOM", tr("ICON_SELECT")));
00085 
00086   setWindowTitle(myMode == CreateGroup ? tr("CREATE_GROUP_TITLE") : tr("EDIT_GROUP_TITLE"));
00087 
00088   // Shape type button group
00089   mainFrame()->GroupConstructors->setEnabled(myMode == CreateGroup);
00090   mainFrame()->GroupConstructors->setTitle(tr("SHAPE_TYPE"));
00091   mainFrame()->RadioButton1->setIcon(image0);
00092   mainFrame()->RadioButton2->setIcon(image1);
00093   mainFrame()->RadioButton3->setIcon(image2);
00094   mainFrame()->RadioButton4->setIcon(image3);
00095   mainFrame()->RadioButton4->show();
00096 
00097   // Group name
00098   mainFrame()->GroupBoxName->setTitle(tr("GROUP_NAME"));
00099 
00100   // Main shape and sub-shapes
00101   QGroupBox* GroupMedium = new QGroupBox(tr("MAIN_SUB_SHAPES"), centralWidget());
00102   QGridLayout* aMedLayout = new QGridLayout(GroupMedium);
00103   aMedLayout->setMargin(9);
00104   aMedLayout->setSpacing(6);
00105 
00106   QLabel* aMainLabel = new QLabel(tr("MAIN_SHAPE"), GroupMedium);
00107 
00108   mySelBtn = new QPushButton(GroupMedium);
00109   mySelBtn->setIcon(iconSelect);
00110   mySelBtn->setEnabled(myMode == CreateGroup);
00111 
00112   myMainName = new QLineEdit(GroupMedium);
00113   myMainName->setReadOnly(true);
00114   myMainName->setEnabled(myMode == CreateGroup);
00115 
00116   myRestrictGroupBox = new QGroupBox(tr("SHAPE_SEL_RESTR"), GroupMedium);
00117   myRestrictGroup = new QButtonGroup(myRestrictGroupBox);
00118   QRadioButton* allSubs     = new QRadioButton(tr("NO_RESTR")            , myRestrictGroupBox);
00119   QRadioButton* inPlaceSubs = new QRadioButton(tr("GEOM_PARTS_OF_SHAPE2"), myRestrictGroupBox);
00120   QRadioButton* shape2Subs  = new QRadioButton(tr("SUBSHAPES_OF_SHAPE2") , myRestrictGroupBox);
00121   QGridLayout* aRestrictLayout = new QGridLayout(myRestrictGroupBox);
00122 
00123   QLabel* aSecondLabel = new QLabel(tr("SECOND_SHAPE"), myRestrictGroupBox);
00124   mySelBtn2 = new QPushButton(myRestrictGroupBox);
00125   mySelBtn2->setIcon(iconSelect);
00126   mySelBtn2->setEnabled(false);
00127   myShape2Name = new QLineEdit(myRestrictGroupBox);
00128   myShape2Name->setReadOnly(true);
00129   myShape2Name->setEnabled(false);
00130 
00131   aRestrictLayout->setMargin(9);
00132   aRestrictLayout->setSpacing(6);
00133   aRestrictLayout->addWidget(allSubs,      0, 0, 1, 3);
00134   aRestrictLayout->addWidget(inPlaceSubs,  1, 0, 1, 3);
00135   aRestrictLayout->addWidget(shape2Subs,   2, 0, 1, 3);
00136   aRestrictLayout->addWidget(aSecondLabel, 3, 0);
00137   aRestrictLayout->addWidget(mySelBtn2,    3, 1);
00138   aRestrictLayout->addWidget(myShape2Name, 3, 2);
00139   myRestrictGroup->addButton(allSubs,      ALL_SUBSHAPES);
00140   myRestrictGroup->addButton(inPlaceSubs,  GET_IN_PLACE);
00141   myRestrictGroup->addButton(shape2Subs,   SUBSHAPES_OF_SHAPE2);
00142   myRestrictGroupBox->setEnabled(!CORBA::is_nil(myMainObj));
00143   allSubs->setChecked(true);
00144 
00145   myShowOnlyBtn = new QPushButton(tr("SHOW_ONLY_SELECTED"), GroupMedium);
00146   myHideSelBtn  = new QPushButton(tr("HIDE_SELECTED"), GroupMedium);
00147   myShowAllBtn  = new QPushButton(tr("SHOW_ALL_SUB_SHAPES"), GroupMedium);
00148 
00149   mySelAllBtn   = new QPushButton(tr("SELECT_ALL"), GroupMedium);
00150   myAddBtn      = new QPushButton(tr("ADD"), GroupMedium);
00151   myRemBtn      = new QPushButton(tr("REMOVE"), GroupMedium);
00152 
00153   myIdList    = new QListWidget(GroupMedium);
00154 
00155   myIdList->setSelectionMode(QAbstractItemView::ExtendedSelection);
00156   myIdList->setFlow(QListView::TopToBottom);
00157   myIdList->setWrapping(true);
00158 
00159   aMedLayout->addWidget(aMainLabel,         0, 0);
00160   aMedLayout->addWidget(mySelBtn,           0, 1);
00161   aMedLayout->addWidget(myMainName,         0, 2, 1, 2);
00162   aMedLayout->addWidget(myRestrictGroupBox, 1, 0, 4, 3);
00163 
00164   aMedLayout->addWidget(myShowOnlyBtn,      1, 3);
00165   aMedLayout->addWidget(myHideSelBtn,       2, 3);
00166   aMedLayout->addWidget(myShowAllBtn,       3, 3);
00167 
00168   aMedLayout->addWidget(myIdList,           5, 0, 4, 3);
00169   aMedLayout->addWidget(mySelAllBtn,        5, 3);
00170   aMedLayout->addWidget(myAddBtn,           6, 3);
00171   aMedLayout->addWidget(myRemBtn,           7, 3);
00172 
00173   aMedLayout->setColumnStretch(2, 5);
00174   aMedLayout->setRowStretch(5, 5);
00175   aMedLayout->setRowStretch(8, 5);
00176 
00177   QVBoxLayout* layout = new QVBoxLayout(centralWidget());
00178   layout->setMargin(0); layout->setSpacing(6);
00179   layout->addWidget(GroupMedium);
00180 
00181   setHelpFileName("work_with_groups_page.html");
00182 
00183   Init();
00184   updateState();
00185 }
00186 
00187 GroupGUI_GroupDlg::~GroupGUI_GroupDlg()
00188 {
00189   if (myIsHiddenMain) {
00190     GEOM_Displayer* aDisplayer = getDisplayer();
00191     aDisplayer->Display(myMainObj);
00192     myIsHiddenMain = false;
00193   }
00194 }
00195 
00196 //=================================================================================
00197 // function : Init()
00198 // purpose  :
00199 //=================================================================================
00200 void GroupGUI_GroupDlg::Init()
00201 {
00202   LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
00203 
00204   //unset shape type to avoid preparation of selection before exact user shape type selection
00205   unsetConstructorId();
00206   myIsShapeType = false;
00207 
00208   if (myMode == CreateGroup) {
00209     initName(tr("GROUP_PREFIX"));
00210 
00211     // Get ready for main shape selection
00212     myEditCurrentArgument = myMainName;
00213 
00214     connect(this, SIGNAL(constructorsClicked(int)), this, SLOT(ConstructorsClicked(int)));
00215     connect(mySelBtn,         SIGNAL(clicked()),    this, SLOT(SetEditCurrentArgument()));
00216     connect(mySelBtn2,        SIGNAL(clicked()),    this, SLOT(SetEditCurrentArgument()));
00217   }
00218   else if (myMode == EditGroup) {
00219     SALOME_ListIO aSelList;
00220     aSelMgr->selectedObjects(aSelList);
00221 
00222     if (aSelList.Extent()) {
00223       GEOM::GEOM_Object_var anObj =
00224         GEOMBase::ConvertIOinGEOMObject(aSelList.First());
00225 
00226       if (!CORBA::is_nil(anObj) && anObj->GetType() == GEOM_GROUP) {
00227         myGroup = anObj;
00228 
00229         mainFrame()->ResultName->setText(GEOMBase::GetName(myGroup));
00230 
00231         GEOM::GEOM_IGroupOperations_var anOper = GEOM::GEOM_IGroupOperations::_narrow(getOperation());
00232         myMainObj = anOper->GetMainShape(myGroup);
00233         if (!CORBA::is_nil(myMainObj))
00234           myMainName->setText(GEOMBase::GetName(myMainObj));
00235 
00236         setShapeType((TopAbs_ShapeEnum)anOper->GetType(myGroup));
00237 
00238         GEOM::ListOfLong_var aCurrList = anOper->GetObjects(myGroup);
00239         for (int i = 0, n = aCurrList->length(); i < n; i++)
00240           myIdList->addItem(new QListWidgetItem(QString("%1").arg(aCurrList[i])));
00241 
00242         myEditCurrentArgument = 0;
00243       }
00244       connect(mySelBtn2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
00245     }
00246   }
00247 
00248   connect(aSelMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
00249 
00250   connect(buttonOk(),    SIGNAL(clicked()), this, SLOT(ClickOnOk()));
00251   connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
00252 
00253   connect(myRestrictGroup, SIGNAL(buttonClicked(int)),     this, SLOT(SetEditCurrentArgument()));
00254   connect(mySelAllBtn,     SIGNAL(clicked()),              this, SLOT(selectAllSubShapes()));
00255   connect(myAddBtn,        SIGNAL(clicked()),              this, SLOT(add()));
00256   connect(myRemBtn,        SIGNAL(clicked()),              this, SLOT(remove()));
00257   connect(myShowOnlyBtn,   SIGNAL(clicked()),              this, SLOT(showOnlySelected()));
00258   connect(myHideSelBtn,    SIGNAL(clicked()),              this, SLOT(showOnlySelected()));
00259   connect(myShowAllBtn,    SIGNAL(clicked()),              this, SLOT(showOnlySelected()));
00260   connect(myIdList,        SIGNAL(itemSelectionChanged()), this, SLOT(selectionChanged()));
00261 
00262   setInPlaceObj(GEOM::GEOM_Object::_nil());
00263 
00264   myBusy = true; // just activate but do not select in the list
00265   activateSelection();
00266   myBusy = false;
00267 }
00268 
00269 //=================================================================================
00270 // function : enterEvent()
00271 // purpose  :
00272 //=================================================================================
00273 void GroupGUI_GroupDlg::enterEvent(QEvent* e)
00274 {
00275   if (!buttonCancel()->isEnabled())
00276     ActivateThisDialog();
00277 }
00278 
00279 //=================================================================================
00280 //function : closeEvent
00281 //purpose  : remove temporary geom object
00282 //=================================================================================
00283 void GroupGUI_GroupDlg::closeEvent(QCloseEvent* e)
00284 {
00285   setInPlaceObj(GEOM::GEOM_Object::_nil());
00286   erasePreview(true);
00287 
00288   GEOMBase_Skeleton::closeEvent(e);
00289 }
00290 
00291 //=================================================================================
00292 // function : ClickOnOk()
00293 // purpose  :
00294 //=================================================================================
00295 void GroupGUI_GroupDlg::ClickOnOk()
00296 {
00297   setIsApplyAndClose(true);
00298   if (ClickOnApply())
00299     ClickOnCancel();
00300 }
00301 
00302 //=================================================================================
00303 // function : ClickOnApply()
00304 // purpose  :
00305 //=================================================================================
00306 bool GroupGUI_GroupDlg::ClickOnApply()
00307 {
00308   if (!onAccept(myMode == CreateGroup, true))
00309     return false;
00310 
00311   if (myMode == CreateGroup)
00312   {
00313     initName();
00314     myIdList->clear();
00315     ConstructorsClicked(getConstructorId());
00316   }
00317   else
00318     activateSelection();
00319 
00320   return true;
00321 }
00322 
00323 //=================================================================================
00324 // function : ActivateThisDialog()
00325 // purpose  :
00326 //=================================================================================
00327 void GroupGUI_GroupDlg::ActivateThisDialog()
00328 {
00329   GEOMBase_Skeleton::ActivateThisDialog();
00330 
00331   connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
00332           this, SLOT(SelectionIntoArgument()));
00333 
00334   activateSelection();
00335 }
00336 
00337 //=================================================================================
00338 // function : SetEditCurrentArgument()
00339 // purpose  :
00340 //=================================================================================
00341 void GroupGUI_GroupDlg::SetEditCurrentArgument()
00342 {
00343   QPushButton* send = (QPushButton*)sender();
00344 
00345   if (send == mySelBtn) {
00346     myEditCurrentArgument = myMainName;
00347     myShape2Name->setText("");
00348   }
00349   else if (send == mySelBtn2 || sender() == myRestrictGroup) {
00350     setInPlaceObj(GEOM::GEOM_Object::_nil());
00351     myShape2Name->setText("");
00352     if (subSelectionWay() != ALL_SUBSHAPES) {
00353       myEditCurrentArgument = myShape2Name;
00354     }
00355     else {
00356       myEditCurrentArgument = 0;
00357     }
00358   }
00359 
00360   activateSelection();
00361 
00362   updateState();
00363 }
00364 
00365 //=================================================================================
00366 // function : onGetInPlace()
00367 // purpose  :
00368 //=================================================================================
00369 void GroupGUI_GroupDlg::onGetInPlace()
00370 {
00371   setInPlaceObj(GEOM::GEOM_Object::_nil());
00372   myEditCurrentArgument->setText("");
00373 
00374   bool isBlocked = myIdList->signalsBlocked();
00375   myIdList->blockSignals(true);
00376   myIdList->clearSelection();
00377   myIdList->blockSignals(isBlocked);
00378 
00379   LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
00380   SALOME_ListIO aSelList;
00381   aSelMgr->selectedObjects(aSelList);
00382 
00383   if (aSelList.Extent() != 1)
00384     return;
00385 
00386   GEOM::GEOM_Object_var anObj =
00387     GEOMBase::ConvertIOinGEOMObject(aSelList.First());
00388   if (GEOMBase::IsShape(anObj)) {
00389     if (!anObj->_is_equivalent(myMainObj) && !anObj->_is_equivalent(myGroup)) {
00390       SUIT_OverrideCursor wc;
00391       myEditCurrentArgument->setText(GEOMBase::GetName(anObj));
00392       GEOM::GEOM_IShapesOperations_var aShapesOp =
00393         getGeomEngine()->GetIShapesOperations(getStudyId());
00394       if (subSelectionWay() == GET_IN_PLACE) {
00395         GEOM::GEOM_Object_var aGetInPlaceObj = aShapesOp->GetInPlace(myMainObj, anObj);
00396         setInPlaceObj(aGetInPlaceObj);
00397       }
00398       else {
00399         bool isVisible = true;
00400         if (SALOME_View* view = GEOM_Displayer::GetActiveView())
00401           isVisible = view->isVisible(aSelList.First());
00402         setInPlaceObj(anObj, isVisible);
00403       }
00404       myEditCurrentArgument = 0;
00405       //myBusy = true; // just activate but do not select in the list
00406       activateSelection();
00407       //myBusy = false;
00408     }
00409   }
00410 }
00411 
00412 //=================================================================================
00413 //function : setInPlaceObj
00414 //purpose  : temporarily add an object to study and remove old InPlaceObj
00415 //=================================================================================
00416 void GroupGUI_GroupDlg::setInPlaceObj(GEOM::GEOM_Object_var theObj, const bool isVisible)
00417 {
00418   if (!myInPlaceObj->_is_equivalent(theObj))
00419   {
00420     myInPlaceObj = theObj;
00421   }
00422 
00423   // build map of indices
00424   myMain2InPlaceIndices.Clear();
00425   if (!myInPlaceObj->_is_nil()) {
00426     GEOM::GEOM_IShapesOperations_var aShapesOp = getGeomEngine()->GetIShapesOperations(getStudyId());
00427     GEOM::GEOM_ILocalOperations_var aLocOp = getGeomEngine()->GetILocalOperations(getStudyId());
00428 
00429     GEOM::ListOfGO_var aSubObjects = aShapesOp->MakeExplode(myInPlaceObj, getShapeType(), false);
00430     for ( int i = 0; i < aSubObjects->length(); i++ )
00431     {
00432       GEOM::ListOfLong_var aCurrList = aShapesOp->GetSameIDs( myMainObj, aSubObjects[i] );
00433       if( aCurrList->length() > 1 ) {
00434         //rnv : To Fix the 21561: EDF 2184 GEOM: Group with second shape restriction.
00435         //      In case if GetSameIDs(...) method return more then one ID use 
00436         //      GetSharedShapes(...) method to get sub-shapes of the second shape.
00437         GEOM::ListOfGO_var aSubObjects2 = aShapesOp->GetSharedShapes( myMainObj, aSubObjects[i], getShapeType() );
00438         for( int j = 0; j < aSubObjects2->length(); j++ ) {
00439           CORBA::Long aMainIndex =  aLocOp->GetSubShapeIndex( myMainObj, aSubObjects2[j] );
00440           CORBA::Long aPlaceIndex = aLocOp->GetSubShapeIndex( myInPlaceObj, aSubObjects[i]);
00441           if ( aMainIndex >= 0 && aPlaceIndex > 0 ) {
00442             myMain2InPlaceIndices.Bind( aMainIndex, aPlaceIndex );
00443           }
00444         }
00445       } else if(aCurrList->length() > 0 ) {
00446         CORBA::Long aMainIndex = aCurrList[0];
00447         CORBA::Long aPlaceIndex = aLocOp->GetSubShapeIndex( myInPlaceObj, aSubObjects[i] );
00448         if ( aMainIndex >= 0 && aPlaceIndex > 0) {
00449           myMain2InPlaceIndices.Bind( aMainIndex, aPlaceIndex );
00450         }
00451       }
00452     }
00453   }
00454   myInPlaceObjSelectState = subSelectionWay();
00455   if (myInPlaceObjSelectState == SUBSHAPES_OF_SHAPE2 && !isVisible)
00456     myInPlaceObjSelectState = SUBSHAPES_OF_INVISIBLE_SHAPE2;
00457 }
00458 
00459 //=================================================================================
00460 // function : SelectionIntoArgument()
00461 // purpose  : Called when selection has changed
00462 //=================================================================================
00463 void GroupGUI_GroupDlg::SelectionIntoArgument()
00464 {
00465   if (subSelectionWay() != ALL_SUBSHAPES && myEditCurrentArgument == myShape2Name) {
00466     onGetInPlace();
00467     return;
00468   }
00469 
00470   if (myEditCurrentArgument == myMainName) {  // Selection of a main shape is active
00471     myEditCurrentArgument->setText("");
00472     myIdList->clear();
00473 
00474     LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
00475     SALOME_ListIO aSelList;
00476     aSelMgr->selectedObjects(aSelList);
00477     int nbSel = aSelList.Extent();
00478 
00479     if (nbSel == 1) {
00480       GEOM::GEOM_Object_var anObj =
00481         GEOMBase::ConvertIOinGEOMObject(aSelList.First());
00482 
00483       if (GEOMBase::IsShape(anObj)) {
00484         if (myIsHiddenMain) {
00485           GEOM_Displayer* aDisplayer = getDisplayer();
00486           aDisplayer->Display(myMainObj);
00487           myIsHiddenMain = false;
00488         }
00489         myMainObj = anObj;
00490         myEditCurrentArgument->setText(GEOMBase::GetName(anObj));
00491         // activate sub-shapes selection by default
00492         myEditCurrentArgument = 0;
00493         activateSelection();
00494         updateState();
00495       }
00496     }
00497     else {
00498       if (myIsHiddenMain) {
00499         GEOM_Displayer* aDisplayer = getDisplayer();
00500         aDisplayer->Display(myMainObj);
00501         myIsHiddenMain = false;
00502       }
00503       myMainObj = GEOM::GEOM_Object::_nil();
00504     }
00505   }
00506   else { // an attempt to synchronize list box selection with 3d viewer
00507     if (myBusy || myMainObj->_is_nil()) {
00508       return;
00509     }
00510 
00511     bool isBlocked = myIdList->signalsBlocked();
00512     myIdList->blockSignals(true);
00513     myIdList->clearSelection();
00514 
00515     TColStd_IndexedMapOfInteger aMapIndex;
00516     int nbSel = getSelectedSubshapes(aMapIndex);
00517 
00518     if (nbSel) {
00519       QMap<int, int> aMap;
00520       for (int i = 0, n = myIdList->count(); i < n; i++)
00521         aMap.insert(myIdList->item(i)->text().toInt(), i);
00522 
00523       bool highlight = false;
00524       for (int ii = 1, nn = aMapIndex.Extent(); ii <= nn; ii++) {
00525         if (aMap.contains(aMapIndex(ii))) {
00526           myIdList->item(aMap[aMapIndex(ii)])->setSelected(true);
00527           highlight = true;
00528         }
00529       }
00530       if (highlight)
00531         highlightSubShapes();
00532     }
00533     myIdList->blockSignals(isBlocked);
00534 
00535     updateState(nbSel);
00536   }
00537 }
00538 
00539 //=================================================================================
00540 // function : ConstructorsClicked()
00541 // purpose  : Radio button management
00542 //=================================================================================
00543 void GroupGUI_GroupDlg::ConstructorsClicked(int constructorId)
00544 {
00545   if (getConstructorId() != constructorId)
00546     setConstructorId(constructorId);
00547 
00548   myIsShapeType = true;
00549   myIdList->clear();
00550   myEditCurrentArgument = 0;
00551 
00552   setInPlaceObj(myInPlaceObj); // to rebuild myMain2InPlaceIndices
00553   activateSelection();
00554   updateState();
00555 }
00556 
00557 //=================================================================================
00558 // function : selectAllSubShapes
00559 // purpose  :
00560 //=================================================================================
00561 void GroupGUI_GroupDlg::selectAllSubShapes()
00562 {
00563   if (CORBA::is_nil(myMainObj) || !myIsShapeType)
00564     return;
00565 
00566   GEOM::ListOfLong_var aSubShapes;
00567   GEOM::GEOM_IShapesOperations_var aShOp = getGeomEngine()->GetIShapesOperations(getStudyId());
00568   aSubShapes = aShOp->SubShapeAllIDs(myMainObj, getShapeType(), false);
00569   if (aSubShapes->length() > 0) {
00570     if (subSelectionWay() == ALL_SUBSHAPES)
00571     {
00572       myIdList->clear(); // for sorted final list?
00573 
00574       if (!aShOp->IsDone())
00575         return;
00576     }
00577     else
00578     {
00579       aSubShapes = new GEOM::ListOfLong();
00580       aSubShapes->length(myMain2InPlaceIndices.Extent());
00581       TColStd_DataMapIteratorOfDataMapOfIntegerInteger m2ip (myMain2InPlaceIndices);
00582       for (int i = 0; m2ip.More(); i++, m2ip.Next())
00583         aSubShapes[i] = m2ip.Key();
00584     }
00585 
00586     bool isBlocked = myIdList->signalsBlocked();
00587     myIdList->blockSignals(true);
00588 
00589     for (int i = 0, n = aSubShapes->length(); i < n; i++) {
00590       CORBA::Long anIndex = aSubShapes[i];
00591       if (anIndex < 0)
00592         continue;
00593 
00594       QListWidgetItem* anItem = 0;
00595       QString text = QString("%1").arg(anIndex);
00596       if (!myInPlaceObj->_is_nil()) {
00597         QList<QListWidgetItem*> found = myIdList->findItems(text, Qt::MatchExactly);
00598         if (found.count()) anItem = found[0];
00599       }
00600       if (!anItem) {
00601         anItem = new QListWidgetItem(text);
00602         myIdList->addItem(anItem);
00603       }
00604       anItem->setSelected(true);
00605     }
00606 
00607     myIdList->blockSignals(isBlocked);
00608     highlightSubShapes();
00609   }
00610 }
00611 
00612 //=================================================================================
00613 // function : showOnlySelected
00614 // purpose  :
00615 //=================================================================================
00616 void GroupGUI_GroupDlg::showOnlySelected()
00617 {
00618   if (CORBA::is_nil(myMainObj) || !myIsShapeType)
00619     return;
00620 
00621   QPushButton* send = (QPushButton*)sender();
00622   if (send == myShowAllBtn) {
00623     activateSelection();
00624     return;
00625   }
00626 
00627   LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
00628   SALOME_ListIO aSelList;
00629   aSelMgr->selectedObjects(aSelList);
00630 
00631   GEOM_Displayer* aDisplayer = getDisplayer();
00632 
00633   if (send == myHideSelBtn) {
00634     aDisplayer->Erase(aSelList, /*forced=*/false, /*updateViewer=*/true);
00635   }
00636   else {
00637     // Mantis issue 0021421: do not hide main shape, if explode on VERTEX
00638     SALOME_View* view = GEOM_Displayer::GetActiveView();
00639     if (view) {
00640       CORBA::String_var aMainEntry = myMainObj->GetStudyEntry();
00641       Handle(SALOME_InteractiveObject) io =
00642         new SALOME_InteractiveObject (aMainEntry.in(), "GEOM", "TEMP_IO");
00643       if (view->isVisible(io)) myIsHiddenMain = true;
00644     }
00645 
00646     aDisplayer->EraseAll(/*forced = false, updateViewer = true*/);
00647     aDisplayer->Display(aSelList, true);
00648 
00649     // Mantis issue 0021421: do not hide main shape, if explode on VERTEX
00650     if (getShapeType() == TopAbs_VERTEX && myIsHiddenMain) {
00651       aDisplayer->Display(myMainObj);
00652     }
00653 
00654     // for the case when selected ids were not displayed in the viewer: Mantis issue 0021367
00655     highlightSubShapes();
00656   }
00657 }
00658 
00659 //=================================================================================
00660 // function : getSelectedSubshapes
00661 // purpose  :
00662 //=================================================================================
00663 int GroupGUI_GroupDlg::getSelectedSubshapes (TColStd_IndexedMapOfInteger& theMapIndex)
00664 {
00665   theMapIndex.Clear();
00666 
00667   SalomeApp_Application* app = myGeomGUI->getApp();
00668   if (!app || myMainObj->_is_nil())
00669     return 0;
00670 
00671   LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
00672   SALOME_ListIO aSelList;
00673   aSelMgr->selectedObjects(aSelList);
00674 
00675   // try to find out and process the global selection
00676   // (of not published objects and of published sub-shapes)
00677   {
00678     SALOME_ListIteratorOfListIO anIter (aSelList);
00679     for (int i = 0; anIter.More(); anIter.Next(), i++)
00680     {
00681       Handle(SALOME_InteractiveObject) anIObj = anIter.Value();
00682       QString anEntry = anIObj->getEntry();
00683       QString str = "_";
00684       int index = anEntry.lastIndexOf(str);
00685       if (index > 0) // selection among special preview
00686       {
00687         anEntry.remove(0, index+1);
00688         int anIndex = anEntry.toInt();
00689         if (anIndex)
00690         theMapIndex.Add(anIndex);
00691       }
00692       else // selection among published shapes
00693       {
00694         SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>(app->activeStudy());
00695         if (!appStudy) return 0;
00696         _PTR(Study) aStudy = appStudy->studyDS();
00697 
00698         _PTR(SObject) aSObj (aStudy->FindObjectID(anEntry.toLatin1().constData()));
00699         GEOM::GEOM_Object_var aGeomObj =
00700           GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aSObj));
00701         TopoDS_Shape aShape;
00702         if (GEOMBase::GetShape(aGeomObj, aShape)) {
00703           if (aGeomObj->GetType() == GEOM_GROUP || aShape.ShapeType() == getShapeType()) {
00704             TopTools_IndexedMapOfShape aMainMap;
00705             TopoDS_Shape aMainShape = GEOM_Client::get_client().GetShape(GeometryGUI::GetGeomGen(), myMainObj);
00706             TopExp::MapShapes(aMainShape, aMainMap);
00707 
00708             TopExp_Explorer anExp (aShape, getShapeType());
00709             for (; anExp.More(); anExp.Next()) {
00710               TopoDS_Shape aSubShape = anExp.Current();
00711               int anIndex = aMainMap.FindIndex(aSubShape);
00712               if (anIndex >= 0) {
00713                 if (subSelectionWay() != ALL_SUBSHAPES &&
00714                     !myMain2InPlaceIndices.IsBound(anIndex))
00715                   continue;
00716                 theMapIndex.Add(anIndex);
00717               }
00718             }
00719           }
00720         }
00721       }
00722     } // for aSelList
00723   }
00724 
00725   return theMapIndex.Extent();
00726 }
00727 
00728 //=================================================================================
00729 // function : add
00730 // purpose  :
00731 //=================================================================================
00732 void GroupGUI_GroupDlg::add()
00733 {
00734   TColStd_IndexedMapOfInteger aMapIndex;
00735   int nbSel = getSelectedSubshapes(aMapIndex);
00736 
00737   TColStd_MapOfInteger aMap;
00738   for (int i = 0, n = myIdList->count(); i < n; i++)
00739     aMap.Add(myIdList->item(i)->text().toInt());
00740 
00741   if (nbSel > 0) {
00742     bool isBlocked = myIdList->signalsBlocked();
00743     myIdList->blockSignals(true);
00744 
00745     for (int i = 1, n = aMapIndex.Extent(); i <= n; i++) {
00746       if (aMap.Contains(aMapIndex(i)))
00747         continue;
00748 
00749       QListWidgetItem* anItem = new QListWidgetItem(QString("%1").arg(aMapIndex(i)));
00750       myIdList->addItem(anItem);
00751       anItem->setSelected(true);
00752     }
00753 
00754     myIdList->blockSignals(isBlocked);
00755   }
00756 
00757   updateState();
00758 }
00759 
00760 //=================================================================================
00761 // function : remove
00762 // purpose  :
00763 //=================================================================================
00764 void GroupGUI_GroupDlg::remove()
00765 {
00766   bool isBlocked = myIdList->signalsBlocked();
00767   myIdList->blockSignals(true);
00768 
00769   QListIterator<QListWidgetItem*> it (myIdList->selectedItems());
00770   while (it.hasNext())
00771     delete it.next();
00772 
00773   myIdList->blockSignals(isBlocked);
00774 
00775   highlightSubShapes();
00776 }
00777 
00778 //=================================================================================
00779 //function : subSelectionWay
00780 //purpose  :
00781 //=================================================================================
00782 int GroupGUI_GroupDlg::subSelectionWay() const
00783 {
00784   return myRestrictGroup->checkedId();
00785 }
00786 
00787 //=================================================================================
00788 // function : getShapeType()
00789 // purpose  :
00790 //=================================================================================
00791 TopAbs_ShapeEnum GroupGUI_GroupDlg::getShapeType() const
00792 {
00793   switch (getConstructorId()) {
00794   case 0:  return TopAbs_VERTEX;
00795   case 1:  return TopAbs_EDGE;
00796   case 2:  return TopAbs_FACE;
00797   case 3:  return TopAbs_SOLID;
00798   default: return TopAbs_SHAPE;
00799   }
00800 }
00801 
00802 //=================================================================================
00803 // function : setShapeType()
00804 // purpose  :
00805 //=================================================================================
00806 void GroupGUI_GroupDlg::setShapeType(const TopAbs_ShapeEnum theType)
00807 {
00808   int anId = 0;
00809   switch (theType) {
00810   case TopAbs_VERTEX: anId = 0; break;
00811   case TopAbs_EDGE:   anId = 1; break;
00812   case TopAbs_FACE:   anId = 2; break;
00813   case TopAbs_SOLID:  anId = 3; break;
00814   }
00815   setConstructorId(anId);
00816   if (!myIsShapeType)
00817   {
00818     myIsShapeType = true;
00819     // workaround to avoid set checked button 0
00820     setConstructorId(anId);
00821   }
00822 }
00823 
00824 //=================================================================================
00825 // function : activateSelection
00826 // purpose  : Activate selection in accordance with myEditCurrentArgument
00827 //=================================================================================
00828 void GroupGUI_GroupDlg::activateSelection()
00829 {
00830   erasePreview(false);
00831 
00832   // local selection
00833   if (!myMainObj->_is_nil() &&
00834       !myEditCurrentArgument &&
00835       myIsShapeType) // check if shape type is already choosen by user
00836   {
00837     GEOM_Displayer* aDisplayer = getDisplayer();
00838 
00839     // Mantis issue 0021421: do not hide main shape, if explode on VERTEX
00840     if (getShapeType() == TopAbs_VERTEX) {
00841       if (myIsHiddenMain)
00842         aDisplayer->Display(myMainObj);
00843     }
00844     else {
00845       SALOME_View* view = GEOM_Displayer::GetActiveView();
00846       if (view) {
00847         CORBA::String_var aMainEntry = myMainObj->GetStudyEntry();
00848         Handle(SALOME_InteractiveObject) io =
00849           new SALOME_InteractiveObject (aMainEntry.in(), "GEOM", "TEMP_IO");
00850         if (view->isVisible(io)) {
00851           aDisplayer->Erase(myMainObj, false, false);
00852           myIsHiddenMain = true;
00853         }
00854       }
00855     }
00856 
00857     int prevDisplayMode = aDisplayer->SetDisplayMode(0);
00858 
00859     SUIT_ViewWindow* aViewWindow = 0;
00860     SUIT_Study* activeStudy = SUIT_Session::session()->activeApplication()->activeStudy();
00861     if (activeStudy)
00862       aViewWindow = SUIT_Session::session()->activeApplication()->desktop()->activeWindow();
00863     if (aViewWindow == 0) return;
00864 
00865     SUIT_ViewManager* aViewManager = aViewWindow->getViewManager();
00866     if (aViewManager->getType() != OCCViewer_Viewer::Type() &&
00867         aViewManager->getType() != SVTK_Viewer::Type())
00868       return;
00869 
00870     SUIT_ViewModel* aViewModel = aViewManager->getViewModel();
00871     SALOME_View* aView = dynamic_cast<SALOME_View*>(aViewModel);
00872     if (aView == 0) return;
00873 
00874     TopoDS_Shape aMainShape = GEOM_Client::get_client().GetShape(GeometryGUI::GetGeomGen(), myMainObj);
00875     TopoDS_Shape aRestrictionShape;
00876 
00877     if (subSelectionWay() == ALL_SUBSHAPES) {
00878       aRestrictionShape = aMainShape;
00879 
00880       TopTools_IndexedMapOfShape aSubShapesMap;
00881       TopExp::MapShapes(aMainShape, aSubShapesMap);
00882       CORBA::String_var aMainEntry = myMainObj->GetStudyEntry();
00883       QString anEntryBase = aMainEntry.in();
00884 
00885       TopExp_Explorer anExp (aRestrictionShape, getShapeType());
00886       for (; anExp.More(); anExp.Next()) {
00887         TopoDS_Shape aSubShape = anExp.Current();
00888         int index = aSubShapesMap.FindIndex(aSubShape);
00889         QString anEntry = anEntryBase + QString("_%1").arg(index);
00890 
00891         SALOME_Prs* aPrs = aDisplayer->buildSubshapePresentation(aSubShape, anEntry, aView);
00892         if (aPrs) {
00893           displayPreview(aPrs, true, false); // append, do not update
00894           // TODO: map or delete Prs
00895         }
00896       }
00897     }
00898     else if (!myInPlaceObj->_is_nil()) {
00899       TopTools_IndexedMapOfShape aSubShapesMap;
00900       TopExp::MapShapes(aMainShape, aSubShapesMap);
00901       CORBA::String_var aMainEntry = myMainObj->GetStudyEntry();
00902       QString anEntryBase = aMainEntry.in();
00903 
00904       TColStd_DataMapIteratorOfDataMapOfIntegerInteger aM2IPit (myMain2InPlaceIndices);
00905       for (; aM2IPit.More(); aM2IPit.Next()) {
00906         int index = aM2IPit.Key();
00907         TopoDS_Shape aSubShape = aSubShapesMap.FindKey(index);
00908         QString anEntry = anEntryBase + QString("_%1").arg(index);
00909 
00910         SALOME_Prs* aPrs = aDisplayer->buildSubshapePresentation(aSubShape, anEntry, aView);
00911         if (aPrs) {
00912           displayPreview(aPrs, true, false); // append, do not update
00913         }
00914       }
00915     }
00916     else ;
00917 
00918     aDisplayer->UpdateViewer();
00919     aDisplayer->SetDisplayMode(prevDisplayMode);
00920   }
00921 
00922   globalSelection(GEOM_ALLSHAPES);
00923 
00924   SelectionIntoArgument();
00925 }
00926 
00927 //=================================================================================
00928 // function : updateState
00929 // purpose  :
00930 //=================================================================================
00931 void GroupGUI_GroupDlg::updateState (bool isAdd)
00932 {
00933   myAddBtn->setEnabled(!myEditCurrentArgument && !CORBA::is_nil(myMainObj) && isAdd);
00934   //myShowOnlyBtn->setEnabled(!myEditCurrentArgument && !CORBA::is_nil(myMainObj) && isAdd);
00935 
00936   bool hasSel = myIdList->selectedItems().count() > 0;
00937 
00938   myRemBtn->setEnabled(hasSel);
00939   myRestrictGroupBox->setEnabled(!CORBA::is_nil(myMainObj));
00940   mySelAllBtn->setEnabled(!CORBA::is_nil(myMainObj));
00941 
00942   mySelBtn2->setEnabled(subSelectionWay() != ALL_SUBSHAPES);
00943   myShape2Name->setEnabled(subSelectionWay() != ALL_SUBSHAPES);
00944   if (subSelectionWay() == ALL_SUBSHAPES)
00945     setInPlaceObj(GEOM::GEOM_Object::_nil());
00946 }
00947 
00948 //=================================================================================
00949 // function : selectionChanged
00950 // purpose  :
00951 //=================================================================================
00952 void GroupGUI_GroupDlg::selectionChanged()
00953 {
00954   highlightSubShapes();
00955 }
00956 
00957 //=================================================================================
00958 // function : highlightSubShapes
00959 // purpose  :
00960 //=================================================================================
00961 void GroupGUI_GroupDlg::highlightSubShapes()
00962 {
00963   if (CORBA::is_nil(myMainObj))
00964     return;
00965 
00966   TColStd_MapOfInteger anIds;
00967 
00968   myBusy = true;
00969 
00970   int ii = 0, nn = myIdList->count();
00971   for (; ii < nn; ii++)
00972   {
00973     if (myIdList->item(ii)->isSelected()) {
00974       int id = myIdList->item(ii)->text().toInt();
00975       if (subSelectionWay() != ALL_SUBSHAPES &&
00976           !myMain2InPlaceIndices.IsBound(id)) {
00977         //myIdList->item(ii)->setSelected(false);
00978       }
00979       else {
00980         anIds.Add(id);
00981       }
00982     }
00983   }
00984   SalomeApp_Application* app = myGeomGUI->getApp();
00985   LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
00986   aSelMgr->clearSelected();
00987 
00988   SUIT_ViewWindow* aViewWindow = 0;
00989   SUIT_Study* activeStudy = app->activeStudy();
00990   if (activeStudy)
00991     aViewWindow = app->desktop()->activeWindow();
00992   if (aViewWindow == 0) return;
00993 
00994   SUIT_ViewManager* aViewManager = aViewWindow->getViewManager();
00995   if (aViewManager->getType() != OCCViewer_Viewer::Type() &&
00996       aViewManager->getType() != SVTK_Viewer::Type())
00997     return;
00998 
00999   SUIT_ViewModel* aViewModel = aViewManager->getViewModel();
01000   SALOME_View* aView = dynamic_cast<SALOME_View*>(aViewModel);
01001   if (aView == 0) return;
01002 
01003   // TODO??: use here GEOMBase_Helper::myPreview instead of ic->DisplayedObjects()
01004 
01005   OCCViewer_Viewer* v3d = ((OCCViewer_ViewManager*)aViewManager)->getOCCViewer();
01006   Handle(AIS_InteractiveContext) ic = v3d->getAISContext();
01007   AIS_ListOfInteractive List;
01008   //ic->DisplayedObjects(List);
01009   ic->ObjectsInside(List); // Mantis issue 0021367
01010 
01011   SALOME_ListIO aSelList;
01012 
01013   // To highlight the selected sub-shape in Object Browser, if it's already published under the main shape
01014   GEOM::GEOM_ILocalOperations_var aLocOp = getGeomEngine()->GetILocalOperations(getStudyId());
01015   QMap<int, QString> childsMap;
01016   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>(app->activeStudy());
01017   if (appStudy) {
01018     _PTR(Study) aStudy = appStudy->studyDS();
01019     CORBA::String_var aMainEntry = myMainObj->GetStudyEntry();
01020     QString anEntry = aMainEntry.in();
01021     _PTR(SObject) aSObj (aStudy->FindObjectID(anEntry.toLatin1().constData()));
01022     _PTR(ChildIterator) anIt (aStudy->NewChildIterator(aSObj));
01023     for (anIt->InitEx(true); anIt->More(); anIt->Next()) {
01024       GEOM::GEOM_Object_var aChild = GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(anIt->Value()));
01025       if (!CORBA::is_nil(aChild)) {
01026         int index = aLocOp->GetSubShapeIndex(myMainObj, aChild);
01027         CORBA::String_var aChildEntry = aChild->GetStudyEntry();
01028         QString anEntry = aChildEntry.in();
01029         childsMap.insert(index, anEntry);
01030       }
01031     }
01032   }
01033 
01034   AIS_ListIteratorOfListOfInteractive ite (List);
01035   for (; ite.More(); ite.Next()) {
01036     if (ite.Value()->IsInstance(STANDARD_TYPE(GEOM_AISShape))) {
01037       Handle(GEOM_AISShape) aSh = Handle(GEOM_AISShape)::DownCast(ite.Value());
01038       if (aSh->hasIO()) {
01039         Handle(SALOME_InteractiveObject) anIO = aSh->getIO();
01040         QString anEntry = anIO->getEntry();
01041         int index = anEntry.lastIndexOf("_");
01042         anEntry.remove(0, index+1);
01043         int anIndex = anEntry.toInt();
01044         if (anIds.Contains(anIndex)) {
01045           aSelList.Append(anIO);
01046           if (childsMap.contains (anIndex)) {
01047             Handle(SALOME_InteractiveObject) tmpIO = new SALOME_InteractiveObject(childsMap.value(anIndex).toLatin1().constData(), "GEOM", "TEMP_IO");
01048             aSelList.Append(tmpIO);
01049           }
01050         }
01051       }
01052     }
01053   }
01054   aSelMgr->setSelectedObjects(aSelList);
01055 
01056   myBusy = false;
01057 
01058   if (nn < 3000)
01059     updateState(aSelList.Extent() > 0);
01060   else {
01061     myAddBtn->setEnabled(true);
01062     myAddBtn->setEnabled(true);
01063     myRemBtn->setEnabled(true);
01064   }
01065 }
01066 
01067 //=================================================================================
01068 // function : createOperation
01069 // purpose  :
01070 //=================================================================================
01071 GEOM::GEOM_IOperations_ptr GroupGUI_GroupDlg::createOperation()
01072 {
01073   return getGeomEngine()->GetIGroupOperations(getStudyId());
01074 }
01075 
01076 #define RETURN_WITH_MSG(a, b) \
01077   if (!(a)) { \
01078     theMessage += (b); \
01079     return false; \
01080   }
01081 
01082 //=================================================================================
01083 // function : isValid()
01084 // purpose  : Verify validity of input data
01085 //=================================================================================
01086 bool GroupGUI_GroupDlg::isValid(QString& theMessage)
01087 {
01088   SalomeApp_Study* study = getStudy();
01089   ASSERT(study);
01090   RETURN_WITH_MSG  (!study->studyDS()->GetProperties()->IsLocked(), tr("GEOM_STUDY_LOCKED"))
01091 
01092   if (myMode == CreateGroup) {
01093     RETURN_WITH_MSG(!CORBA::is_nil(myMainObj), tr("NO_MAIN_OBJ"))
01094   }
01095   else {
01096     RETURN_WITH_MSG(!CORBA::is_nil(myMainObj), tr("NO_GROUP"))
01097   }
01098 
01099   QString aName (getNewObjectName());
01100   RETURN_WITH_MSG  (!aName.trimmed().isEmpty(), tr("EMPTY_NAME"))
01101 
01102   RETURN_WITH_MSG  (myIdList->count(), tr("EMPTY_LIST"))
01103   return true;
01104 }
01105 
01106 //=================================================================================
01107 // function : execute
01108 // purpose  :
01109 //=================================================================================
01110 bool GroupGUI_GroupDlg::execute(ObjectList& objects)
01111 {
01112   GEOM::GEOM_IGroupOperations_var anOper = GEOM::GEOM_IGroupOperations::_narrow(getOperation());
01113 
01114   GEOM::GEOM_Object_var aGroup;
01115   if (myMode == CreateGroup)
01116     aGroup = anOper->CreateGroup(myMainObj, getShapeType());
01117   else if (myMode == EditGroup)
01118     aGroup = myGroup;
01119 
01120   if (CORBA::is_nil(aGroup) || (myMode == CreateGroup && !anOper->IsDone()))
01121     return false;
01122 
01123   GEOM::ListOfLong_var aCurrList = anOper->GetObjects(aGroup);
01124   if (!anOper->IsDone())
01125     return false;
01126 
01127   if (aCurrList->length() > 0)
01128   {
01129     anOper->DifferenceIDs(aGroup, aCurrList);
01130     if (!anOper->IsDone())
01131       return false;
01132   }
01133 
01134   int ii, nn = myIdList->count();
01135   if (nn > 0)
01136   {
01137     GEOM::ListOfLong_var aNewList = new GEOM::ListOfLong;
01138     aNewList->length(nn);
01139     for (ii = 0; ii < nn; ii++) {
01140       aNewList[ii] = myIdList->item(ii)->text().toInt();
01141     }
01142     anOper->UnionIDs(aGroup, aNewList);
01143     if (!anOper->IsDone())
01144       return false;
01145   }
01146 
01147   SalomeApp_Study* study = getStudy();
01148   if (study) {
01149     QString objIOR = GEOMBase::GetIORFromObject(aGroup);
01150     if (objIOR != "") {
01151       _PTR(SObject) SO (study->studyDS()->FindObjectIOR(objIOR.toLatin1().constData()));
01152       if (SO) {
01153         _PTR(StudyBuilder) aBuilder (study->studyDS()->NewBuilder());
01154         aBuilder->SetName(SO, getNewObjectName().toLatin1().constData());
01155       }
01156     }
01157   }
01158 
01159   objects.push_back(aGroup._retn());
01160 
01161   return true;
01162 }
01163 
01164 //================================================================
01165 // Function : getFather
01166 // Purpose  : Get father object for object to be added in study
01167 //            (called with addInStudy method)
01168 //================================================================
01169 GEOM::GEOM_Object_ptr GroupGUI_GroupDlg::getFather(GEOM::GEOM_Object_ptr theObj)
01170 {
01171   GEOM::GEOM_Object_var aFatherObj;
01172   if (theObj->GetType() == GEOM_GROUP) {
01173     GEOM::GEOM_IGroupOperations_var anOper = GEOM::GEOM_IGroupOperations::_narrow(getOperation());
01174     aFatherObj = anOper->GetMainShape(theObj);
01175   }
01176   return aFatherObj._retn();
01177 }