Back to index

salome-geom  6.5.0
EntityGUI_SubShapeDlg.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   : EntityGUI_SubShapeDlg.cxx
00025 // Author : Lucien PIGNOLONI, Open CASCADE S.A.S.
00026 
00027 #include "EntityGUI_SubShapeDlg.h"
00028 
00029 #include <DlgRef.h>
00030 #include <GeometryGUI.h>
00031 #include <GEOMBase.h>
00032 
00033 #include <OCCViewer_ViewModel.h>
00034 #include <SVTK_ViewModel.h>
00035 #include <SalomeApp_Study.h>
00036 #include <SalomeApp_Application.h>
00037 #include <LightApp_SelectionMgr.h>
00038 #include <SALOME_ListIteratorOfListIO.hxx>
00039 
00040 #include <SUIT_Desktop.h>
00041 #include <SUIT_ResourceMgr.h>
00042 #include <SUIT_Session.h>
00043 #include <SUIT_ViewManager.h>
00044 #include <SUIT_ViewWindow.h>
00045 
00046 #include <TopExp.hxx>
00047 #include <TopExp_Explorer.hxx>
00048 #include <TopoDS_Iterator.hxx>
00049 #include <TopTools_MapOfShape.hxx>
00050 #include <TopTools_IndexedMapOfShape.hxx>
00051 
00052 #include <TColStd_IndexedMapOfInteger.hxx>
00053 
00054 #include <QMessageBox>
00055 
00056 #include <GEOMImpl_Types.hxx>
00057 
00058 //=================================================================================
00059 // class    : EntityGUI_SubShapeDlg
00060 // purpose  : Constructs a EntityGUI_SubShapeDlg which is a child of 'parent', with the
00061 //            name 'name' and widget flags set to 'f'.
00062 //            The dialog will by default be modeless, unless you set 'modal' to
00063 //            TRUE to construct a modal dialog.
00064 //=================================================================================
00065 EntityGUI_SubShapeDlg::EntityGUI_SubShapeDlg(GeometryGUI* theGeometryGUI, QWidget* parent,
00066                                               bool modal, Qt::WindowFlags fl)
00067   : GEOMBase_Skeleton(theGeometryGUI, parent, modal, fl),
00068     myWithShape(true),
00069     myIsHiddenMain(false)
00070 {
00071   QPixmap image0(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_DLG_SUBSHAPE")));
00072   QPixmap image1(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_SELECT")));
00073 
00074   setWindowTitle(tr("GEOM_SUBSHAPE_TITLE"));
00075 
00076   /***************************************************************/
00077   mainFrame()->GroupConstructors->setTitle(tr("GEOM_SUB_SHAPE"));
00078   mainFrame()->RadioButton1->setIcon(image0);
00079   mainFrame()->RadioButton2->setAttribute(Qt::WA_DeleteOnClose);
00080   mainFrame()->RadioButton2->close();
00081   mainFrame()->RadioButton3->setAttribute(Qt::WA_DeleteOnClose);
00082   mainFrame()->RadioButton3->close();
00083 
00084   GroupPoints = new DlgRef_1Sel1List1Check3Btn(centralWidget());
00085 
00086   GroupPoints->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
00087   GroupPoints->TextLabel1->setText(tr("GEOM_MAIN_OBJECT"));
00088   GroupPoints->TextLabel2->setText(tr("GEOM_SUBSHAPE_TYPE"));
00089   GroupPoints->CheckButton1->setText(tr("GEOM_SUBSHAPE_SELECT"));
00090   GroupPoints->PushButton1->setIcon(image1);
00091   GroupPoints->PushButton2->setText(tr("SHOW_ONLY_SELECTED"));
00092   GroupPoints->PushButton3->setText(tr("HIDE_SELECTED"));
00093   GroupPoints->PushButton4->setText(tr("SHOW_ALL_SUB_SHAPES"));
00094   GroupPoints->LineEdit1->setReadOnly(true);
00095 
00096   QVBoxLayout* layout = new QVBoxLayout(centralWidget());
00097   layout->setMargin(0); layout->setSpacing(6);
00098   layout->addWidget(GroupPoints);
00099   /***************************************************************/
00100 
00101   setIsOptimizedBrowsing(true);
00102 
00103   setHelpFileName("create_explode_page.html");
00104 
00105   mainFrame()->GroupBoxName->hide();
00106 
00107   Init();
00108 }
00109 
00110 //=================================================================================
00111 // function : ~EntityGUI_SubShapeDlg()
00112 // purpose  : Destroys the object and frees any allocated resources
00113 //=================================================================================
00114 EntityGUI_SubShapeDlg::~EntityGUI_SubShapeDlg()
00115 {
00116   if (myIsHiddenMain) {
00117     GEOM_Displayer* aDisplayer = getDisplayer();
00118     aDisplayer->Display(myObject);
00119     myIsHiddenMain = false;
00120   }
00121 }
00122 
00123 //=================================================================================
00124 // function : Init()
00125 // purpose  :
00126 //=================================================================================
00127 void EntityGUI_SubShapeDlg::Init()
00128 {
00129   /* init variables */
00130   myEditCurrentArgument = GroupPoints->LineEdit1;
00131   myObject = GEOM::GEOM_Object::_nil();
00132 
00133   myWithShape = true;
00134 
00135   /* type for sub-shape selection */
00136   GroupPoints->ComboBox1->insertItem(GroupPoints->ComboBox1->count(), "Compound");
00137   GroupPoints->ComboBox1->insertItem(GroupPoints->ComboBox1->count(), "Compsolid");
00138   GroupPoints->ComboBox1->insertItem(GroupPoints->ComboBox1->count(), "Solid");
00139   GroupPoints->ComboBox1->insertItem(GroupPoints->ComboBox1->count(), "Shell");
00140   GroupPoints->ComboBox1->insertItem(GroupPoints->ComboBox1->count(), "Face");
00141   GroupPoints->ComboBox1->insertItem(GroupPoints->ComboBox1->count(), "Wire");
00142   GroupPoints->ComboBox1->insertItem(GroupPoints->ComboBox1->count(), "Edge");
00143   GroupPoints->ComboBox1->insertItem(GroupPoints->ComboBox1->count(), "Vertex");
00144   GroupPoints->ComboBox1->insertItem(GroupPoints->ComboBox1->count(), "Shape");
00145 
00146   if (SUIT_Session::session()->activeApplication()->desktop()->activeWindow()->getViewManager()->getType()
00147       != OCCViewer_Viewer::Type())
00148     GroupPoints->CheckButton1->setEnabled(false);
00149 
00150   /* signals and slots connections */
00151   connect(myGeomGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
00152 
00153   connect(buttonOk(),    SIGNAL(clicked()), this, SLOT(ClickOnOk()));
00154   connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
00155 
00156   connect(GroupPoints->PushButton1,  SIGNAL(clicked()),       this, SLOT(SetEditCurrentArgument()));
00157   connect(GroupPoints->LineEdit1,    SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
00158 
00159   connect(GroupPoints->ComboBox1,    SIGNAL(activated(int)),    this, SLOT(ComboTextChanged()));
00160   connect(GroupPoints->CheckButton1, SIGNAL(stateChanged(int)), this, SLOT(SubShapeToggled()));
00161 
00162   connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(showOnlySelected()));
00163   connect(GroupPoints->PushButton3, SIGNAL(clicked()), this, SLOT(showOnlySelected()));
00164   connect(GroupPoints->PushButton4, SIGNAL(clicked()), this, SLOT(showOnlySelected()));
00165 
00166   connect(myGeomGUI->getApp()->selectionMgr(),
00167           SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
00168 
00169   updateButtonState();
00170   resize(100,100);
00171   SelectionIntoArgument();
00172 }
00173 
00174 //=================================================================================
00175 // function : enterEvent()
00176 // purpose  :
00177 //=================================================================================
00178 void EntityGUI_SubShapeDlg::enterEvent(QEvent*)
00179 {
00180   if (!mainFrame()->GroupConstructors->isEnabled())
00181     ActivateThisDialog();
00182 }
00183 
00184 //=================================================================================
00185 // function : ActivateThisDialog()
00186 // purpose  :
00187 //=================================================================================
00188 void EntityGUI_SubShapeDlg::ActivateThisDialog()
00189 {
00190   GEOMBase_Skeleton::ActivateThisDialog();
00191   connect(myGeomGUI->getApp()->selectionMgr(),
00192            SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
00193   SubShapeToggled();
00194   updateButtonState();
00195 }
00196 
00197 //=================================================================================
00198 //function : closeEvent
00199 //purpose  : remove temporary geom object
00200 //=================================================================================
00201 void EntityGUI_SubShapeDlg::closeEvent(QCloseEvent* e)
00202 {
00203   erasePreview(true);
00204   GEOMBase_Skeleton::closeEvent(e);
00205 }
00206 
00207 //=================================================================================
00208 // function : ClickOnOk()
00209 // purpose  :
00210 //=================================================================================
00211 void EntityGUI_SubShapeDlg::ClickOnOk()
00212 {
00213   setIsApplyAndClose(true);
00214 
00215   SUIT_Session::session()->activeApplication()->putInfo("");
00216 
00217   /* Explode all sub-shapes */
00218   bool isOk = true;
00219   if (isAllSubShapes()) {
00220     /* More than 30 sub-shapes : ask confirmation */
00221     unsigned int nb = NumberOfSubShapes(myShape, shapeType());
00222     if (nb > 30) {
00223       const QString caption = tr("GEOM_CONFIRM");
00224       const QString text = tr("GEOM_CONFIRM_INFO").arg(nb);
00225       const QString button0 = tr("GEOM_BUT_EXPLODE");
00226       const QString button1 = tr("GEOM_BUT_CANCEL");
00227 
00228       if (QMessageBox::warning(this, caption, text, button0, button1) != 0)
00229         isOk = false;  /* aborted */
00230     }
00231   }
00232 
00233   if (isOk)
00234     isOk = onAccept();
00235 
00236   if (isOk)
00237     ClickOnCancel();
00238 }
00239 
00240 //=================================================================================
00241 // function : ClickOnApply()
00242 // purpose  :
00243 //=================================================================================
00244 bool EntityGUI_SubShapeDlg::ClickOnApply()
00245 {
00246   SUIT_Session::session()->activeApplication()->putInfo("");
00247 
00248   /* Explode all sub-shapes */
00249   if (isAllSubShapes()) {
00250     /* More than 30 sub-shapes : ask confirmation */
00251     unsigned int nb = NumberOfSubShapes(myShape, shapeType());
00252     if (nb > 30) {
00253       const QString caption = tr("GEOM_CONFIRM");
00254       const QString text = tr("GEOM_CONFIRM_INFO").arg(nb);
00255       const QString button0 = tr("GEOM_BUT_EXPLODE");
00256       const QString button1 = tr("GEOM_BUT_CANCEL");
00257 
00258       if (QMessageBox::warning(this, caption, text, button0, button1) != 0)
00259         return false;  /* aborted */
00260     }
00261   }
00262   
00263   setIsDisableBrowsing( true );
00264   bool isOk = onAccept( true, true, false );
00265   setIsDisableBrowsing( false );
00266 
00267   // restore selection, corresponding to current selection mode
00268   SubShapeToggled();
00269 
00270   return isOk;
00271 }
00272 
00273 //=================================================================================
00274 // function : SelectionIntoArgument()
00275 // purpose  : Called when selection has changed or other case
00276 //=================================================================================
00277 void EntityGUI_SubShapeDlg::SelectionIntoArgument()
00278 {
00279   if (!isAllSubShapes())
00280     return;
00281 
00282   ResetStateOfDialog();
00283 
00284   QString aString = ""; /* name of selection */
00285 
00286   LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
00287   SALOME_ListIO aSelList;
00288   aSelMgr->selectedObjects(aSelList);
00289 
00290   int nbSel = GEOMBase::GetNameOfSelectedIObjects(aSelList, aString, true);
00291   if (nbSel != 1)
00292     return;
00293 
00294   Handle(SALOME_InteractiveObject) IO = aSelList.First();
00295   if (!IO->hasEntry()) {
00296     SUIT_Session::session()->activeApplication()->putInfo(tr("GEOM_PRP_SHAPE_IN_STUDY"));
00297     updateButtonState();
00298     return;
00299   }
00300 
00301   if (myIsHiddenMain) {
00302     GEOM_Displayer* aDisplayer = getDisplayer();
00303     aDisplayer->Display(myObject);
00304     myIsHiddenMain = false;
00305   }
00306 
00307   TopoDS_Shape S = GEOMBase::GetTopoFromSelection(aSelList);
00308   if (S.IsNull() || S.ShapeType() == TopAbs_VERTEX) {
00309     myObject = GEOM::GEOM_Object::_nil();
00310     updateButtonState();
00311     return;
00312   }
00313 
00314   myObject = GEOMBase::ConvertIOinGEOMObject(IO);
00315   if (myObject->_is_nil()) {
00316     updateButtonState();
00317     return;
00318   }
00319 
00320   myShape = S;
00321   GroupPoints->LineEdit1->setText(aString);
00322 
00323   int SelectedShapeType = GroupPoints->ComboBox1->currentIndex();
00324   int count = GroupPoints->ComboBox1->count();
00325 
00326   if (myWithShape)
00327     count = count - 1;
00328 
00329   int i = 0;
00330   // Solving PAL5590
00331   if (myShape.ShapeType() == TopAbs_COMPOUND) {
00332     unsigned int nb = NumberOfSubShapes(myShape, TopAbs_COMPOUND);
00333     if (nb > 0)
00334       i++;
00335   }
00336   while (i <= myShape.ShapeType()) {
00337     GroupPoints->ComboBox1->removeItem(0);
00338     i++;
00339   }
00340 
00341   if (myShape.ShapeType() == TopAbs_COMPOUND) {
00342     if (myWithShape == false) {
00343       GroupPoints->ComboBox1->insertItem(GroupPoints->ComboBox1->count(), "Shape");
00344       myWithShape = true;
00345     }
00346   }
00347   else {
00348     if (myWithShape == true) {
00349       GroupPoints->ComboBox1->removeItem(GroupPoints->ComboBox1->count() - 1);
00350       myWithShape = false;
00351     }
00352   }
00353 
00354   int count1 = GroupPoints->ComboBox1->count();
00355   if (myWithShape)
00356     count1 = count1 - 1;
00357 
00358   if (SelectedShapeType > myShape.ShapeType()) {
00359     if (SelectedShapeType == 8) {
00360       if (myShape.ShapeType() != TopAbs_COMPOUND) {
00361         GroupPoints->ComboBox1->setCurrentIndex(0);
00362         ComboTextChanged();
00363       }
00364     }
00365     else
00366       GroupPoints->ComboBox1->setCurrentIndex(count1 - count + SelectedShapeType);
00367   }
00368   else {
00369     GroupPoints->ComboBox1->setCurrentIndex(0);
00370     ComboTextChanged();
00371   }
00372 
00373   updateButtonState();
00374 }
00375 
00376 //=================================================================================
00377 // function : SetEditCurrentArgument()
00378 // purpose  :
00379 //=================================================================================
00380 void EntityGUI_SubShapeDlg::SetEditCurrentArgument()
00381 {
00382   GroupPoints->LineEdit1->setFocus();
00383   myEditCurrentArgument = GroupPoints->LineEdit1;
00384 
00385   GroupPoints->CheckButton1->setChecked(false);
00386   SubShapeToggled();
00387   SelectionIntoArgument();
00388 }
00389 
00390 //=================================================================================
00391 // function : LineEditReturnPressed()
00392 // purpose  :
00393 //=================================================================================
00394 void EntityGUI_SubShapeDlg::LineEditReturnPressed()
00395 {
00396   QLineEdit* send = (QLineEdit*)sender();
00397   if (send == GroupPoints->LineEdit1)
00398     SetEditCurrentArgument();
00399   else
00400     return;
00401 
00402   GEOMBase_Skeleton::LineEditReturnPressed();
00403 }
00404 
00405 //=================================================================================
00406 // function : ResetStateOfDialog()
00407 // purpose  : Completely reset the state of method including local context
00408 //=================================================================================
00409 void EntityGUI_SubShapeDlg::ResetStateOfDialog()
00410 {
00411   if (myIsHiddenMain) {
00412     GEOM_Displayer* aDisplayer = getDisplayer();
00413     aDisplayer->Display(myObject);
00414     myIsHiddenMain = false;
00415   }
00416   myObject = GEOM::GEOM_Object::_nil();
00417   myShape.Nullify();
00418   myEditCurrentArgument->setText("");
00419 
00420   int SelectedShapeType = GroupPoints->ComboBox1->currentIndex();
00421   int count = GroupPoints->ComboBox1->count();
00422   if (myWithShape)
00423     count = count - 1;
00424 
00425   /* type for sub-shape selection */
00426   GroupPoints->ComboBox1->clear();
00427   GroupPoints->ComboBox1->insertItem(GroupPoints->ComboBox1->count(), "Compound");
00428   GroupPoints->ComboBox1->insertItem(GroupPoints->ComboBox1->count(), "Compsolid");
00429   GroupPoints->ComboBox1->insertItem(GroupPoints->ComboBox1->count(), "Solid");
00430   GroupPoints->ComboBox1->insertItem(GroupPoints->ComboBox1->count(), "Shell");
00431   GroupPoints->ComboBox1->insertItem(GroupPoints->ComboBox1->count(), "Face");
00432   GroupPoints->ComboBox1->insertItem(GroupPoints->ComboBox1->count(), "Wire");
00433   GroupPoints->ComboBox1->insertItem(GroupPoints->ComboBox1->count(), "Edge");
00434   GroupPoints->ComboBox1->insertItem(GroupPoints->ComboBox1->count(), "Vertex");
00435   GroupPoints->ComboBox1->insertItem(GroupPoints->ComboBox1->count(), "Shape");
00436 
00437   myWithShape = true;
00438 
00439   GroupPoints->ComboBox1->setCurrentIndex(8 - count + SelectedShapeType);
00440 
00441   // to avoid recursion: SelectionIntoArgument->ResetStateOfDialog->ComboTextChanged->SubShapeToggled->activateSelection->(currentSelectionChanged)->SelectionIntoArgument
00442   //ComboTextChanged();
00443 
00444   updateButtonState();
00445 }
00446 
00447 //=================================================================================
00448 // function : SubShapeToggled()
00449 // purpose  : Allow user selection of all or only selected sub-shapes
00450 //          : Called when 'CheckButton1' state change
00451 //=================================================================================
00452 void EntityGUI_SubShapeDlg::SubShapeToggled()
00453 {
00454   GroupPoints->PushButton2->setEnabled(!isAllSubShapes());
00455   GroupPoints->PushButton3->setEnabled(!isAllSubShapes());
00456   GroupPoints->PushButton4->setEnabled(!isAllSubShapes());
00457 
00458   activateSelection();
00459 }
00460 
00461 //=================================================================================
00462 // function : ComboTextChanged()
00463 // purpose  :
00464 //=================================================================================
00465 void EntityGUI_SubShapeDlg::ComboTextChanged()
00466 {
00467   /* Select sub-shapes mode not checked */
00468   updateButtonState();
00469   SubShapeToggled();
00470 }
00471 
00472 //=================================================================================
00473 // function : NumberOfSubShapes()
00474 // purpose  :
00475 //=================================================================================
00476 unsigned int EntityGUI_SubShapeDlg::NumberOfSubShapes(const TopoDS_Shape& S,
00477                                                       const int shapeType) const
00478 {
00479   if (S.IsNull())
00480     return 0;
00481 
00482   unsigned int index = 0;
00483   TopTools_MapOfShape M;
00484 
00485   if (S.ShapeType() == TopAbs_COMPOUND &&
00486        (TopAbs_ShapeEnum(shapeType) == TopAbs_SHAPE ||
00487          TopAbs_ShapeEnum(shapeType) == TopAbs_COMPSOLID ||
00488          TopAbs_ShapeEnum(shapeType) == TopAbs_COMPOUND)) {
00489     TopoDS_Iterator It(S, Standard_True, Standard_True);
00490     for (; It.More(); It.Next()) {
00491       if (M.Add(It.Value())) {
00492         if (TopAbs_ShapeEnum(shapeType) == TopAbs_SHAPE ||
00493              TopAbs_ShapeEnum(shapeType) == It.Value().ShapeType()) {
00494           index++;
00495         }
00496       }
00497     }
00498   }
00499   else {
00500     TopExp_Explorer Exp (S, TopAbs_ShapeEnum(shapeType));
00501     for (; Exp.More(); Exp.Next()) {
00502       if (M.Add(Exp.Current())) {
00503         index++;
00504       }
00505     }
00506   }
00507 
00508   M.Clear();
00509   return index;
00510 }
00511 
00512 //=================================================================================
00513 // function : updateButtonState
00514 // purpose  :
00515 //=================================================================================
00516 void EntityGUI_SubShapeDlg::updateButtonState()
00517 {
00518   if (SUIT_Session::session()->activeApplication()->desktop()->activeWindow()->getViewManager()->getType() != OCCViewer_Viewer::Type() ||
00519       myObject->_is_nil() || shapeType() == TopAbs_SHAPE || shapeType() == TopAbs_COMPOUND) {
00520     GroupPoints->CheckButton1->setChecked(false);
00521     GroupPoints->CheckButton1->setEnabled(false);
00522   }
00523   else
00524     GroupPoints->CheckButton1->setEnabled(true);
00525 }
00526 
00527 //=================================================================================
00528 // function : isAllSubShapes
00529 // purpose  :
00530 //=================================================================================
00531 bool EntityGUI_SubShapeDlg::isAllSubShapes() const
00532 {
00533   return !GroupPoints->CheckButton1->isChecked() || !GroupPoints->CheckButton1->isEnabled();
00534 }
00535 
00536 //=================================================================================
00537 // function : shapeType
00538 // purpose  :
00539 //=================================================================================
00540 int EntityGUI_SubShapeDlg::shapeType() const
00541 {
00542   int type = GroupPoints->ComboBox1->currentIndex();
00543 
00544   if (myObject->_is_nil())
00545     return type;
00546 
00547   // Solving PAL5590
00548   type += myShape.ShapeType() + 1;
00549   if (myShape.ShapeType() == TopAbs_COMPOUND &&
00550       NumberOfSubShapes(myShape, TopAbs_COMPOUND) > 0) {
00551     type--;
00552   }
00553 
00554   return type;
00555 }
00556 
00557 //=================================================================================
00558 // function : showOnlySelected
00559 // purpose  :
00560 //=================================================================================
00561 void EntityGUI_SubShapeDlg::showOnlySelected()
00562 {
00563   if (CORBA::is_nil(myObject) || isAllSubShapes())
00564     return;
00565 
00566   QPushButton* send = (QPushButton*)sender();
00567   if (send == GroupPoints->PushButton4) {
00568     activateSelection();
00569     return;
00570   }
00571 
00572   LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
00573   SALOME_ListIO aSelList;
00574   aSelMgr->selectedObjects(aSelList);
00575 
00576   GEOM_Displayer* aDisplayer = getDisplayer();
00577 
00578   if (send == GroupPoints->PushButton3) {
00579     aDisplayer->Erase(aSelList, /*forced=*/false, /*updateViewer=*/true);
00580   }
00581   else {
00582     // Mantis issue 0021421: do not hide main shape, if explode on VERTEX
00583     SALOME_View* view = GEOM_Displayer::GetActiveView();
00584     if (view) {
00585       CORBA::String_var aMainEntry = myObject->GetStudyEntry();
00586       Handle(SALOME_InteractiveObject) io =
00587         new SALOME_InteractiveObject (aMainEntry.in(), "GEOM", "TEMP_IO");
00588       if (view->isVisible(io)) myIsHiddenMain = true;
00589     }
00590 
00591     aDisplayer->EraseAll(/*forced = false, updateViewer = true*/);
00592     aDisplayer->Display(aSelList, true);
00593 
00594     // Mantis issue 0021421: do not hide main shape, if explode on VERTEX
00595     if ((TopAbs_ShapeEnum)shapeType() == TopAbs_VERTEX && myIsHiddenMain) {
00596       aDisplayer->Display(myObject);
00597     }
00598   }
00599 }
00600 
00601 //=================================================================================
00602 // function : getSelectedSubshapes
00603 // purpose  :
00604 //=================================================================================
00605 int EntityGUI_SubShapeDlg::getSelectedSubshapes (TColStd_IndexedMapOfInteger& theMapIndex)
00606 {
00607   theMapIndex.Clear();
00608 
00609   SalomeApp_Application* app = myGeomGUI->getApp();
00610   if (!app || myObject->_is_nil())
00611     return 0;
00612 
00613   LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
00614   SALOME_ListIO aSelList;
00615   aSelMgr->selectedObjects(aSelList);
00616 
00617   // try to find out and process the global selection
00618   // (of not published objects and of published sub-shapes)
00619   {
00620     SALOME_ListIteratorOfListIO anIter (aSelList);
00621     for (int i = 0; anIter.More(); anIter.Next(), i++)
00622     {
00623       Handle(SALOME_InteractiveObject) anIObj = anIter.Value();
00624       QString anEntry = anIObj->getEntry();
00625       QString str = "_";
00626       int index = anEntry.lastIndexOf(str);
00627       if (index > 0) // selection among special preview
00628       {
00629         anEntry.remove(0, index+1);
00630         int anIndex = anEntry.toInt();
00631         if (anIndex)
00632           theMapIndex.Add(anIndex);
00633       }
00634       else // selection among published shapes
00635       {
00636         SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>(app->activeStudy());
00637         if (!appStudy) return 0;
00638         _PTR(Study) aStudy = appStudy->studyDS();
00639 
00640         _PTR(SObject) aSObj (aStudy->FindObjectID(anEntry.toLatin1().constData()));
00641         GEOM::GEOM_Object_var aGeomObj =
00642           GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aSObj));
00643         TopoDS_Shape aShape;
00644         if (GEOMBase::GetShape(aGeomObj, aShape)) {
00645           if (aGeomObj->GetType() == GEOM_GROUP || aShape.ShapeType() == (TopAbs_ShapeEnum)shapeType()) {
00646             TopTools_IndexedMapOfShape aMainMap;
00647             TopExp::MapShapes(myShape, aMainMap);
00648 
00649             TopExp_Explorer anExp (aShape, (TopAbs_ShapeEnum)shapeType());
00650             for (; anExp.More(); anExp.Next()) {
00651               TopoDS_Shape aSubShape = anExp.Current();
00652               int anIndex = aMainMap.FindIndex(aSubShape);
00653               if (anIndex >= 0) {
00654                 theMapIndex.Add(anIndex);
00655               }
00656             }
00657           }
00658         }
00659       }
00660     } // for aSelList
00661   }
00662 
00663   return theMapIndex.Extent();
00664 }
00665 
00666 //=================================================================================
00667 // function : activateSelection
00668 // purpose  : Activate selection in accordance with myEditCurrentArgument
00669 //=================================================================================
00670 void EntityGUI_SubShapeDlg::activateSelection()
00671 {
00672   bool isApply = ((QPushButton*)sender() == buttonApply());
00673   
00674   if(!isApply)
00675     erasePreview(false);
00676 
00677   // local selection
00678   if (!myObject->_is_nil() && !isAllSubShapes())
00679   {
00680     GEOM_Displayer* aDisplayer = getDisplayer();
00681 
00682     // Mantis issue 0021421: do not hide main shape, if explode on VERTEX
00683     if ((TopAbs_ShapeEnum)shapeType() == TopAbs_VERTEX) {
00684       if (myIsHiddenMain)
00685         aDisplayer->Display(myObject);
00686     }
00687     else {
00688       SALOME_View* view = GEOM_Displayer::GetActiveView();
00689       if (view) {
00690         CORBA::String_var aMainEntry = myObject->GetStudyEntry();
00691         Handle(SALOME_InteractiveObject) io =
00692           new SALOME_InteractiveObject (aMainEntry.in(), "GEOM", "TEMP_IO");
00693         if (view->isVisible(io)) {
00694           aDisplayer->Erase(myObject, false, false);
00695           myIsHiddenMain = true;
00696         }
00697       }
00698     }
00699 
00700     if(!isApply) {
00701       int prevDisplayMode = aDisplayer->SetDisplayMode(0);
00702 
00703       SUIT_ViewWindow* aViewWindow = 0;
00704       SUIT_Study* activeStudy = SUIT_Session::session()->activeApplication()->activeStudy();
00705       if (activeStudy)
00706         aViewWindow = SUIT_Session::session()->activeApplication()->desktop()->activeWindow();
00707       if (aViewWindow == 0) return;
00708 
00709       SUIT_ViewManager* aViewManager = aViewWindow->getViewManager();
00710       if (aViewManager->getType() != OCCViewer_Viewer::Type() &&
00711           aViewManager->getType() != SVTK_Viewer::Type())
00712         return;
00713 
00714       SUIT_ViewModel* aViewModel = aViewManager->getViewModel();
00715       SALOME_View* aView = dynamic_cast<SALOME_View*>(aViewModel);
00716       if (aView == 0) return;
00717 
00718       //TopoDS_Shape aMainShape = GEOM_Client::get_client().GetShape(GeometryGUI::GetGeomGen(), myObject);
00719 
00720       TopTools_IndexedMapOfShape aSubShapesMap;
00721       TopExp::MapShapes(myShape, aSubShapesMap);
00722       CORBA::String_var aMainEntry = myObject->GetStudyEntry();
00723       QString anEntryBase = aMainEntry.in();
00724 
00725       TopExp_Explorer anExp (myShape, (TopAbs_ShapeEnum)shapeType());
00726       for (; anExp.More(); anExp.Next())
00727       {
00728         TopoDS_Shape aSubShape = anExp.Current();
00729         int index = aSubShapesMap.FindIndex(aSubShape);
00730         QString anEntry = anEntryBase + QString("_%1").arg(index);
00731 
00732         SALOME_Prs* aPrs = aDisplayer->buildSubshapePresentation(aSubShape, anEntry, aView);
00733         if (aPrs) {
00734           displayPreview(aPrs, true, false); // append, do not update
00735         }
00736       }
00737       aDisplayer->UpdateViewer();
00738       aDisplayer->SetDisplayMode(prevDisplayMode);
00739     }
00740   }
00741 
00742   globalSelection(GEOM_ALLSHAPES);
00743 }
00744 
00745 //=================================================================================
00746 // function : createOperation
00747 // purpose  :
00748 //=================================================================================
00749 GEOM::GEOM_IOperations_ptr EntityGUI_SubShapeDlg::createOperation()
00750 {
00751   return getGeomEngine()->GetIShapesOperations(getStudyId());
00752 }
00753 
00754 //=================================================================================
00755 // function : isValid
00756 // purpose  :
00757 //=================================================================================
00758 bool EntityGUI_SubShapeDlg::isValid (QString& msg)
00759 {
00760   bool isOk = false;
00761 
00762   if (myObject->_is_nil()) {
00763     updateButtonState();
00764     return isOk;
00765   }
00766 
00767   if (isAllSubShapes())
00768     isOk = true;
00769   else {
00770     TColStd_IndexedMapOfInteger aMapIndex;
00771     int nbSel = getSelectedSubshapes(aMapIndex);
00772     isOk = nbSel > 0;
00773 
00774     if (!isOk)
00775       msg += tr("NO_SUBSHAPES_SELECTED");
00776   }
00777 
00778   return isOk;
00779 }
00780 
00781 //=================================================================================
00782 // function : execute
00783 // purpose  :
00784 //=================================================================================
00785 bool EntityGUI_SubShapeDlg::execute (ObjectList& objects)
00786 {
00787   GEOM::GEOM_IShapesOperations_var anOper = GEOM::GEOM_IShapesOperations::_narrow(getOperation());
00788 
00789   if (!isAllSubShapes()) {
00790     // manual selection
00791     TColStd_IndexedMapOfInteger aMapIndex;
00792     int nbSel = getSelectedSubshapes(aMapIndex);
00793 
00794     if (nbSel > 0) {
00795       int i;
00796 
00797       GEOM::ListOfLong_var anArray = new GEOM::ListOfLong;
00798       anArray->length(nbSel);
00799 
00800       for (i = 1; i <= nbSel; i++)
00801         anArray[i - 1] = aMapIndex.FindKey(i);
00802 
00803       GEOM::ListOfGO_var aList = anOper->MakeSubShapes(myObject, anArray);
00804       int n = aList->length();
00805       for (i = 0; i < n; i++)
00806         objects.push_back(GEOM::GEOM_Object::_duplicate(aList[i]));
00807     }
00808   }
00809   else {
00810     GEOM::ListOfGO_var aList = anOper->ExtractSubShapes(myObject, shapeType(), true);
00811     if (!aList->length())
00812       return false;
00813     for (int i = 0, n = aList->length(); i < n; i++)
00814       objects.push_back(GEOM::GEOM_Object::_duplicate(aList[i]));
00815   }
00816 
00817   return objects.size();
00818 }
00819 
00820 //================================================================
00821 // Function : getFather
00822 // Purpose  : Get father object for object to be added in study
00823 //            (called with addInStudy method)
00824 //================================================================
00825 GEOM::GEOM_Object_ptr EntityGUI_SubShapeDlg::getFather(GEOM::GEOM_Object_ptr)
00826 {
00827   return myObject;
00828 }
00829 
00830 //================================================================
00831 // Function : getNewObjectName
00832 // Purpose  :
00833 //================================================================
00834 QString EntityGUI_SubShapeDlg::getNewObjectName() const
00835 {
00836   return QString::null;
00837 }