1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // GEOM GEOMGUI : GUI for Geometry component
23 // File : GroupGUI_GroupDlg.cxx
24 // Author : Sergey ANIKIN, Open CASCADE S.A.S. (sergey.anikin@opencascade.com)
26 #include "GroupGUI_GroupDlg.h"
30 #include <GeometryGUI.h>
31 #include <GEOM_Displayer.h>
33 #include <SalomeApp_Application.h>
34 #include <SalomeApp_Study.h>
36 #include <LightApp_SelectionMgr.h>
38 #include <OCCViewer_ViewModel.h>
39 #include <OCCViewer_ViewManager.h>
40 #include <SVTK_ViewModel.h>
41 #include <SALOME_Prs.h>
42 #include <SALOME_ListIteratorOfListIO.hxx>
44 #include <SUIT_ResourceMgr.h>
45 #include <SUIT_Desktop.h>
46 #include <SUIT_OverrideCursor.h>
47 #include <SUIT_Session.h>
48 #include <SUIT_ViewWindow.h>
49 #include <SUIT_ViewManager.h>
52 #include <QListWidget>
56 #include <AIS_ListOfInteractive.hxx>
57 #include <AIS_ListIteratorOfListOfInteractive.hxx>
60 #include <TopExp_Explorer.hxx>
61 #include <TopTools_IndexedMapOfShape.hxx>
62 #include <TColStd_IndexedMapOfInteger.hxx>
63 #include <TColStd_MapOfInteger.hxx>
64 #include <TColStd_DataMapIteratorOfDataMapOfIntegerInteger.hxx>
66 #include <GEOMImpl_Types.hxx>
68 enum { ALL_SUBSHAPES = 0, GET_IN_PLACE, SUBSHAPES_OF_SHAPE2, SUBSHAPES_OF_INVISIBLE_SHAPE2 };
70 GroupGUI_GroupDlg::GroupGUI_GroupDlg (Mode mode, GeometryGUI* theGeometryGUI, QWidget* parent)
71 : GEOMBase_Skeleton(theGeometryGUI, parent, false),
76 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
78 QPixmap image0 (resMgr->loadPixmap("GEOM", tr("ICON_OBJBROWSER_VERTEX")));
79 QPixmap image1 (resMgr->loadPixmap("GEOM", tr("ICON_OBJBROWSER_EDGE")));
80 QPixmap image2 (resMgr->loadPixmap("GEOM", tr("ICON_OBJBROWSER_FACE")));
81 QPixmap image3 (resMgr->loadPixmap("GEOM", tr("ICON_OBJBROWSER_SOLID")));
82 QPixmap iconSelect (resMgr->loadPixmap("GEOM", tr("ICON_SELECT")));
84 setWindowTitle(myMode == CreateGroup ? tr("CREATE_GROUP_TITLE") : tr("EDIT_GROUP_TITLE"));
86 // Shape type button group
87 mainFrame()->GroupConstructors->setEnabled(myMode == CreateGroup);
88 mainFrame()->GroupConstructors->setTitle(tr("SHAPE_TYPE"));
89 mainFrame()->RadioButton1->setIcon(image0);
90 mainFrame()->RadioButton2->setIcon(image1);
91 mainFrame()->RadioButton3->setIcon(image2);
92 mainFrame()->RadioButton4->setIcon(image3);
93 mainFrame()->RadioButton4->show();
96 mainFrame()->GroupBoxName->setTitle(tr("GROUP_NAME"));
98 // Main shape and sub-shapes
99 QGroupBox* GroupMedium = new QGroupBox(tr("MAIN_SUB_SHAPES"), centralWidget());
100 QGridLayout* aMedLayout = new QGridLayout(GroupMedium);
101 aMedLayout->setMargin(9);
102 aMedLayout->setSpacing(6);
104 QLabel* aMainLabel = new QLabel(tr("MAIN_SHAPE"), GroupMedium);
106 mySelBtn = new QPushButton(GroupMedium);
107 mySelBtn->setIcon(iconSelect);
108 mySelBtn->setEnabled(myMode == CreateGroup);
110 myMainName = new QLineEdit(GroupMedium);
111 myMainName->setReadOnly(true);
112 myMainName->setEnabled(myMode == CreateGroup);
114 myRestrictGroupBox = new QGroupBox(tr("SHAPE_SEL_RESTR"), GroupMedium);
115 myRestrictGroup = new QButtonGroup(myRestrictGroupBox);
116 QRadioButton* allSubs = new QRadioButton(tr("NO_RESTR") , myRestrictGroupBox);
117 QRadioButton* inPlaceSubs = new QRadioButton(tr("GEOM_PARTS_OF_SHAPE2"), myRestrictGroupBox);
118 QRadioButton* shape2Subs = new QRadioButton(tr("SUBSHAPES_OF_SHAPE2") , myRestrictGroupBox);
119 QGridLayout* aRestrictLayout = new QGridLayout(myRestrictGroupBox);
121 QLabel* aSecondLabel = new QLabel(tr("SECOND_SHAPE"), myRestrictGroupBox);
122 mySelBtn2 = new QPushButton(myRestrictGroupBox);
123 mySelBtn2->setIcon(iconSelect);
124 mySelBtn2->setEnabled(false);
125 myShape2Name = new QLineEdit(myRestrictGroupBox);
126 myShape2Name->setReadOnly(true);
127 myShape2Name->setEnabled(false);
129 aRestrictLayout->setMargin(9);
130 aRestrictLayout->setSpacing(6);
131 aRestrictLayout->addWidget(allSubs, 0, 0, 1, 3);
132 aRestrictLayout->addWidget(inPlaceSubs, 1, 0, 1, 3);
133 aRestrictLayout->addWidget(shape2Subs, 2, 0, 1, 3);
134 aRestrictLayout->addWidget(aSecondLabel, 3, 0);
135 aRestrictLayout->addWidget(mySelBtn2, 3, 1);
136 aRestrictLayout->addWidget(myShape2Name, 3, 2);
137 myRestrictGroup->addButton(allSubs, ALL_SUBSHAPES);
138 myRestrictGroup->addButton(inPlaceSubs, GET_IN_PLACE);
139 myRestrictGroup->addButton(shape2Subs, SUBSHAPES_OF_SHAPE2);
140 myRestrictGroupBox->setEnabled(!CORBA::is_nil(myMainObj));
141 allSubs->setChecked(true);
143 myShowOnlyBtn = new QPushButton(tr("Show only selected"), GroupMedium);
144 myHideSelBtn = new QPushButton(tr("Hide selected"), GroupMedium);
145 myShowAllBtn = new QPushButton(tr("Show all sub-shapes"), GroupMedium);
147 mySelAllBtn = new QPushButton(tr("SELECT_ALL"), GroupMedium);
148 myAddBtn = new QPushButton(tr("ADD"), GroupMedium);
149 myRemBtn = new QPushButton(tr("REMOVE"), GroupMedium);
151 myIdList = new QListWidget(GroupMedium);
153 myIdList->setSelectionMode(QAbstractItemView::ExtendedSelection);
154 myIdList->setFlow(QListView::TopToBottom);
155 myIdList->setWrapping(true);
157 aMedLayout->addWidget(aMainLabel, 0, 0);
158 aMedLayout->addWidget(mySelBtn, 0, 1);
159 aMedLayout->addWidget(myMainName, 0, 2, 1, 2);
160 aMedLayout->addWidget(myRestrictGroupBox, 1, 0, 4, 3);
162 aMedLayout->addWidget(myShowOnlyBtn, 1, 3);
163 aMedLayout->addWidget(myHideSelBtn, 2, 3);
164 aMedLayout->addWidget(myShowAllBtn, 3, 3);
166 aMedLayout->addWidget(myIdList, 5, 0, 4, 3);
167 aMedLayout->addWidget(mySelAllBtn, 5, 3);
168 aMedLayout->addWidget(myAddBtn, 6, 3);
169 aMedLayout->addWidget(myRemBtn, 7, 3);
171 aMedLayout->setColumnStretch( 2, 5 );
172 aMedLayout->setRowStretch(5, 5);
173 aMedLayout->setRowStretch(8, 5);
175 QVBoxLayout* layout = new QVBoxLayout(centralWidget());
176 layout->setMargin(0); layout->setSpacing(6);
177 layout->addWidget(GroupMedium);
179 setHelpFileName("work_with_groups_page.html");
184 GroupGUI_GroupDlg::~GroupGUI_GroupDlg()
188 //=================================================================================
191 //=================================================================================
192 void GroupGUI_GroupDlg::Init()
194 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
196 //unset shape type to avoid preparation of selection before exact user shape type selection
197 unsetConstructorId();
198 myIsShapeType = false;
200 if (myMode == CreateGroup) {
201 initName(tr("GROUP_PREFIX"));
203 // Get ready for main shape selection
204 myEditCurrentArgument = myMainName;
206 connect(this, SIGNAL(constructorsClicked(int)), this, SLOT(ConstructorsClicked(int)));
207 connect(mySelBtn, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
208 connect(mySelBtn2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
210 else if (myMode == EditGroup) {
211 SALOME_ListIO aSelList;
212 aSelMgr->selectedObjects(aSelList);
214 if (aSelList.Extent()) {
215 Standard_Boolean aResult = Standard_False;
216 GEOM::GEOM_Object_var anObj =
217 GEOMBase::ConvertIOinGEOMObject(aSelList.First(), aResult);
219 if (aResult && !CORBA::is_nil(anObj) && anObj->GetType() == GEOM_GROUP) {
222 mainFrame()->ResultName->setText(GEOMBase::GetName(myGroup));
224 GEOM::GEOM_IGroupOperations_var anOper = GEOM::GEOM_IGroupOperations::_narrow(getOperation());
225 myMainObj = anOper->GetMainShape(myGroup);
226 if (!CORBA::is_nil(myMainObj))
227 myMainName->setText(GEOMBase::GetName(myMainObj));
229 setShapeType((TopAbs_ShapeEnum)anOper->GetType(myGroup));
231 GEOM::ListOfLong_var aCurrList = anOper->GetObjects(myGroup);
232 for (int i = 0, n = aCurrList->length(); i < n; i++)
233 myIdList->addItem(new QListWidgetItem(QString("%1").arg(aCurrList[i])));
235 myEditCurrentArgument = 0;
237 connect(mySelBtn2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
241 connect(aSelMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
243 connect(buttonOk(), SIGNAL(clicked()), this, SLOT(ClickOnOk()));
244 connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
246 connect(myRestrictGroup, SIGNAL(buttonClicked(int)), this, SLOT(SetEditCurrentArgument()));
247 connect(mySelAllBtn, SIGNAL(clicked()), this, SLOT(selectAllSubShapes()));
248 connect(myAddBtn, SIGNAL(clicked()), this, SLOT(add()));
249 connect(myRemBtn, SIGNAL(clicked()), this, SLOT(remove()));
250 connect(myShowOnlyBtn, SIGNAL(clicked()), this, SLOT(showOnlySelected()));
251 connect(myHideSelBtn, SIGNAL(clicked()), this, SLOT(showOnlySelected()));
252 connect(myShowAllBtn, SIGNAL(clicked()), this, SLOT(showOnlySelected()));
253 connect(myIdList, SIGNAL(itemSelectionChanged()), this, SLOT(selectionChanged()));
255 setInPlaceObj(GEOM::GEOM_Object::_nil());
257 myBusy = true; // just activate but do not select in the list
262 //=================================================================================
263 // function : enterEvent()
265 //=================================================================================
266 void GroupGUI_GroupDlg::enterEvent(QEvent* e)
268 if (!buttonCancel()->isEnabled())
269 ActivateThisDialog();
272 //=================================================================================
273 //function : closeEvent
274 //purpose : remove temporary geom object
275 //=================================================================================
276 void GroupGUI_GroupDlg::closeEvent(QCloseEvent* e)
278 setInPlaceObj(GEOM::GEOM_Object::_nil());
281 GEOMBase_Skeleton::closeEvent(e);
284 //=================================================================================
285 // function : ClickOnOk()
287 //=================================================================================
288 void GroupGUI_GroupDlg::ClickOnOk()
294 //=================================================================================
295 // function : ClickOnApply()
297 //=================================================================================
298 bool GroupGUI_GroupDlg::ClickOnApply()
300 if (!onAccept(myMode == CreateGroup, true))
303 if (myMode == CreateGroup)
307 ConstructorsClicked(getConstructorId());
315 //=================================================================================
316 // function : ActivateThisDialog()
318 //=================================================================================
319 void GroupGUI_GroupDlg::ActivateThisDialog()
321 GEOMBase_Skeleton::ActivateThisDialog();
323 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
324 this, SLOT(SelectionIntoArgument()));
329 //=================================================================================
330 // function : SetEditCurrentArgument()
332 //=================================================================================
333 void GroupGUI_GroupDlg::SetEditCurrentArgument()
335 QPushButton* send = (QPushButton*)sender();
337 if (send == mySelBtn) {
338 myEditCurrentArgument = myMainName;
339 myShape2Name->setText("");
341 else if (send == mySelBtn2 || sender() == myRestrictGroup) {
342 setInPlaceObj(GEOM::GEOM_Object::_nil());
343 myShape2Name->setText("");
344 if (subSelectionWay() != ALL_SUBSHAPES) {
345 myEditCurrentArgument = myShape2Name;
348 myEditCurrentArgument = 0;
357 //=================================================================================
358 // function : onGetInPlace()
360 //=================================================================================
361 void GroupGUI_GroupDlg::onGetInPlace()
363 setInPlaceObj(GEOM::GEOM_Object::_nil());
364 myEditCurrentArgument->setText("");
366 bool isBlocked = myIdList->signalsBlocked();
367 myIdList->blockSignals(true);
368 myIdList->clearSelection();
369 myIdList->blockSignals(isBlocked);
371 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
372 SALOME_ListIO aSelList;
373 aSelMgr->selectedObjects(aSelList);
375 if (aSelList.Extent() != 1)
378 Standard_Boolean aResult = Standard_False;
379 GEOM::GEOM_Object_var anObj =
380 GEOMBase::ConvertIOinGEOMObject(aSelList.First(), aResult);
381 if (aResult && !anObj->_is_nil() && GEOMBase::IsShape(anObj)) {
382 if (!anObj->_is_equivalent(myMainObj) && !anObj->_is_equivalent(myGroup)) {
383 SUIT_OverrideCursor wc;
384 myEditCurrentArgument->setText(GEOMBase::GetName(anObj));
385 GEOM::GEOM_IShapesOperations_var aShapesOp =
386 getGeomEngine()->GetIShapesOperations(getStudyId());
387 if (subSelectionWay() == GET_IN_PLACE) {
388 GEOM::GEOM_Object_var aGetInPlaceObj = aShapesOp->GetInPlace(myMainObj, anObj);
389 setInPlaceObj(aGetInPlaceObj);
392 bool isVisible = true;
393 if (SALOME_View* view = GEOM_Displayer::GetActiveView())
394 isVisible = view->isVisible(aSelList.First());
395 setInPlaceObj(anObj, isVisible);
397 myEditCurrentArgument = 0;
398 //myBusy = true; // just activate but do not select in the list
405 //=================================================================================
406 //function : setInPlaceObj
407 //purpose : temporarily add an object to study and remove old InPlaceObj
408 //=================================================================================
409 void GroupGUI_GroupDlg::setInPlaceObj(GEOM::GEOM_Object_var theObj, const bool isVisible)
411 if (!myInPlaceObj->_is_equivalent(theObj))
413 myInPlaceObj = theObj;
416 // build map of indices
417 myMain2InPlaceIndices.Clear();
418 if (!myInPlaceObj->_is_nil()) {
419 GEOM::GEOM_IShapesOperations_var aShapesOp = getGeomEngine()->GetIShapesOperations(getStudyId());
420 GEOM::GEOM_ILocalOperations_var aLocOp = getGeomEngine()->GetILocalOperations(getStudyId());
422 GEOM::ListOfGO_var aSubObjects = aShapesOp->MakeExplode(myInPlaceObj, getShapeType(), false);
423 for (int i = 0; i < aSubObjects->length(); i++)
425 CORBA::Long aMainIndex = aLocOp->GetSubShapeIndex(myMainObj, aSubObjects[i]);
426 CORBA::Long aPlaceIndex = aLocOp->GetSubShapeIndex(myInPlaceObj, aSubObjects[i]);
427 if (aMainIndex >= 0 && aPlaceIndex > 0)
428 myMain2InPlaceIndices.Bind(aMainIndex, aPlaceIndex);
431 myInPlaceObjSelectState = subSelectionWay();
432 if (myInPlaceObjSelectState == SUBSHAPES_OF_SHAPE2 && !isVisible)
433 myInPlaceObjSelectState = SUBSHAPES_OF_INVISIBLE_SHAPE2;
436 //=================================================================================
437 // function : SelectionIntoArgument()
438 // purpose : Called when selection has changed
439 //=================================================================================
440 void GroupGUI_GroupDlg::SelectionIntoArgument()
442 if (subSelectionWay() != ALL_SUBSHAPES && myEditCurrentArgument == myShape2Name) {
447 if (myEditCurrentArgument == myMainName) { // Selection of a main shape is active
448 myEditCurrentArgument->setText("");
451 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
452 SALOME_ListIO aSelList;
453 aSelMgr->selectedObjects(aSelList);
454 int nbSel = aSelList.Extent();
457 Standard_Boolean aResult = Standard_False;
458 GEOM::GEOM_Object_var anObj =
459 GEOMBase::ConvertIOinGEOMObject(aSelList.First(), aResult);
461 if (aResult && !anObj->_is_nil() && GEOMBase::IsShape(anObj)) {
463 myEditCurrentArgument->setText(GEOMBase::GetName(anObj));
464 // activate subshapes selection by default
465 myEditCurrentArgument = 0;
471 myMainObj = GEOM::GEOM_Object::_nil();
474 else { // an attempt to synchronize list box selection with 3d viewer
479 bool isBlocked = myIdList->signalsBlocked();
480 myIdList->blockSignals(true);
481 myIdList->clearSelection();
483 TColStd_IndexedMapOfInteger aMapIndex;
484 int nbSel = getSelectedSubshapes(aMapIndex);
488 for (int i = 0, n = myIdList->count(); i < n; i++)
489 aMap.insert(myIdList->item(i)->text().toInt(), i);
491 for (int ii = 1, nn = aMapIndex.Extent(); ii <= nn; ii++) {
492 if (aMap.contains(aMapIndex(ii)))
493 myIdList->item(aMap[aMapIndex(ii)])->setSelected(true);
496 myIdList->blockSignals(isBlocked);
502 //=================================================================================
503 // function : ConstructorsClicked()
504 // purpose : Radio button management
505 //=================================================================================
506 void GroupGUI_GroupDlg::ConstructorsClicked(int constructorId)
508 if (getConstructorId() != constructorId)
509 setConstructorId(constructorId);
511 myIsShapeType = true;
513 myEditCurrentArgument = 0;
515 setInPlaceObj(myInPlaceObj); // to rebuild myMain2InPlaceIndices
520 //=================================================================================
521 // function : selectAllSubShapes
523 //=================================================================================
524 void GroupGUI_GroupDlg::selectAllSubShapes()
526 if (CORBA::is_nil(myMainObj) || !myIsShapeType)
529 GEOM::ListOfLong_var aSubShapes;
530 GEOM::GEOM_IShapesOperations_var aShOp = getGeomEngine()->GetIShapesOperations(getStudyId());
531 aSubShapes = aShOp->SubShapeAllIDs(myMainObj, getShapeType(), false);
532 if (aSubShapes->length() > 0) {
533 if (subSelectionWay() == ALL_SUBSHAPES)
535 myIdList->clear(); // for sorted final list?
537 if (!aShOp->IsDone())
542 aSubShapes = new GEOM::ListOfLong();
543 aSubShapes->length(myMain2InPlaceIndices.Extent());
544 TColStd_DataMapIteratorOfDataMapOfIntegerInteger m2ip (myMain2InPlaceIndices);
545 for (int i = 0; m2ip.More(); i++, m2ip.Next())
546 aSubShapes[i] = m2ip.Key();
549 bool isBlocked = myIdList->signalsBlocked();
550 myIdList->blockSignals(true);
552 for (int i = 0, n = aSubShapes->length(); i < n; i++) {
553 CORBA::Long anIndex = aSubShapes[i];
557 QListWidgetItem* anItem = 0;
558 QString text = QString("%1").arg(anIndex);
559 if (!myInPlaceObj->_is_nil()) {
560 QList<QListWidgetItem*> found = myIdList->findItems(text, Qt::MatchExactly);
561 if (found.count()) anItem = found[0];
564 anItem = new QListWidgetItem(text);
565 myIdList->addItem(anItem);
567 anItem->setSelected(true);
570 myIdList->blockSignals(isBlocked);
571 highlightSubShapes();
575 //=================================================================================
576 // function : showOnlySelected
578 //=================================================================================
579 void GroupGUI_GroupDlg::showOnlySelected()
581 if (CORBA::is_nil(myMainObj) || !myIsShapeType)
584 QPushButton* send = (QPushButton*)sender();
585 if (send == myShowAllBtn) {
590 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
591 SALOME_ListIO aSelList;
592 aSelMgr->selectedObjects(aSelList);
594 GEOM_Displayer* aDisplayer = getDisplayer();
596 if (send == myHideSelBtn) {
597 aDisplayer->Erase(aSelList, false, true);
600 aDisplayer->EraseAll();
601 aDisplayer->Display(aSelList, true);
605 //=================================================================================
606 // function : getSelectedSubshapes
608 //=================================================================================
609 int GroupGUI_GroupDlg::getSelectedSubshapes (TColStd_IndexedMapOfInteger& theMapIndex)
613 SalomeApp_Application* app = myGeomGUI->getApp();
616 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
617 SALOME_ListIO aSelList;
618 aSelMgr->selectedObjects(aSelList);
620 // try to find out and process the global selection
621 // (of not published objects and of published sub-shapes)
623 SALOME_ListIteratorOfListIO anIter (aSelList);
624 for (int i = 0; anIter.More(); anIter.Next(), i++)
626 Handle(SALOME_InteractiveObject) anIObj = anIter.Value();
627 QString anEntry = anIObj->getEntry();
629 int index = anEntry.lastIndexOf(str);
630 if (index > 0) // selection among special preview
632 anEntry.remove(0, index+1);
633 int anIndex = anEntry.toInt();
635 theMapIndex.Add(anIndex);
637 else // selection among published shapes
639 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>(app->activeStudy());
640 if (!appStudy) return 0;
641 _PTR(Study) aStudy = appStudy->studyDS();
643 _PTR(SObject) aSObj (aStudy->FindObjectID(anEntry.toLatin1().constData()));
644 GEOM::GEOM_Object_var aGeomObj =
645 GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aSObj));
647 if (GEOMBase::GetShape(aGeomObj, aShape)) {
648 if (aGeomObj->GetType() == GEOM_GROUP || aShape.ShapeType() == getShapeType()) {
649 TopTools_IndexedMapOfShape aMainMap;
650 TopoDS_Shape aMainShape = GEOM_Client().GetShape(GeometryGUI::GetGeomGen(), myMainObj);
651 TopExp::MapShapes(aMainShape, aMainMap);
653 TopExp_Explorer anExp (aShape, getShapeType());
654 for (; anExp.More(); anExp.Next()) {
655 TopoDS_Shape aSubShape = anExp.Current();
656 int anIndex = aMainMap.FindIndex(aSubShape);
658 if (subSelectionWay() != ALL_SUBSHAPES &&
659 !myMain2InPlaceIndices.IsBound(anIndex))
661 theMapIndex.Add(anIndex);
670 return theMapIndex.Extent();
673 //=================================================================================
676 //=================================================================================
677 void GroupGUI_GroupDlg::add()
679 TColStd_IndexedMapOfInteger aMapIndex;
680 int nbSel = getSelectedSubshapes(aMapIndex);
682 TColStd_MapOfInteger aMap;
683 for (int i = 0, n = myIdList->count(); i < n; i++)
684 aMap.Add(myIdList->item(i)->text().toInt());
687 bool isBlocked = myIdList->signalsBlocked();
688 myIdList->blockSignals(true);
690 for (int i = 1, n = aMapIndex.Extent(); i <= n; i++) {
691 if (aMap.Contains(aMapIndex(i)))
694 QListWidgetItem* anItem = new QListWidgetItem(QString("%1").arg(aMapIndex(i)));
695 myIdList->addItem(anItem);
696 anItem->setSelected(true);
699 myIdList->blockSignals(isBlocked);
705 //=================================================================================
708 //=================================================================================
709 void GroupGUI_GroupDlg::remove()
711 bool isBlocked = myIdList->signalsBlocked();
712 myIdList->blockSignals(true);
714 QListIterator<QListWidgetItem*> it (myIdList->selectedItems());
718 myIdList->blockSignals(isBlocked);
720 highlightSubShapes();
723 //=================================================================================
724 //function : subSelectionWay
726 //=================================================================================
727 int GroupGUI_GroupDlg::subSelectionWay() const
729 return myRestrictGroup->checkedId();
732 //=================================================================================
733 // function : getShapeType()
735 //=================================================================================
736 TopAbs_ShapeEnum GroupGUI_GroupDlg::getShapeType() const
738 switch (getConstructorId()) {
739 case 0: return TopAbs_VERTEX;
740 case 1: return TopAbs_EDGE;
741 case 2: return TopAbs_FACE;
742 case 3: return TopAbs_SOLID;
743 default: return TopAbs_SHAPE;
747 //=================================================================================
748 // function : setShapeType()
750 //=================================================================================
751 void GroupGUI_GroupDlg::setShapeType(const TopAbs_ShapeEnum theType)
755 case TopAbs_VERTEX: anId = 0; break;
756 case TopAbs_EDGE: anId = 1; break;
757 case TopAbs_FACE: anId = 2; break;
758 case TopAbs_SOLID: anId = 3; break;
760 setConstructorId(anId);
763 myIsShapeType = true;
764 // workaround to avoid set checked button 0
765 setConstructorId(anId);
769 //=================================================================================
770 // function : activateSelection
771 // purpose : Activate selection in accordance with myEditCurrentArgument
772 //=================================================================================
773 void GroupGUI_GroupDlg::activateSelection()
778 if (!myMainObj->_is_nil() &&
779 !myEditCurrentArgument &&
780 myIsShapeType) // check if shape type is already choosen by user
782 GEOM_Displayer* aDisplayer = getDisplayer();
784 SUIT_ViewWindow* aViewWindow = 0;
785 SUIT_Study* activeStudy = SUIT_Session::session()->activeApplication()->activeStudy();
787 aViewWindow = SUIT_Session::session()->activeApplication()->desktop()->activeWindow();
788 if (aViewWindow == 0) return;
790 SUIT_ViewManager* aViewManager = aViewWindow->getViewManager();
791 if (aViewManager->getType() != OCCViewer_Viewer::Type() &&
792 aViewManager->getType() != SVTK_Viewer::Type())
795 SUIT_ViewModel* aViewModel = aViewManager->getViewModel();
796 SALOME_View* aView = dynamic_cast<SALOME_View*>(aViewModel);
797 if (aView == 0) return;
799 TopoDS_Shape aMainShape = GEOM_Client().GetShape(GeometryGUI::GetGeomGen(), myMainObj);
800 TopoDS_Shape aRestrictionShape;
801 if (subSelectionWay() == ALL_SUBSHAPES)
802 aRestrictionShape = aMainShape;
803 else if (!myInPlaceObj->_is_nil())
804 aRestrictionShape = GEOM_Client().GetShape(GeometryGUI::GetGeomGen(), myInPlaceObj);
807 TopTools_IndexedMapOfShape aSubShapesMap;
808 TopExp::MapShapes(aMainShape, aSubShapesMap);
809 CORBA::String_var aMainEntry = myMainObj->GetStudyEntry();
810 QString anEntryBase = aMainEntry.in();
812 TopExp_Explorer anExp (aRestrictionShape, getShapeType());
813 for (; anExp.More(); anExp.Next())
815 TopoDS_Shape aSubShape = anExp.Current();
816 int index = aSubShapesMap.FindIndex(aSubShape);
817 QString anEntry = anEntryBase + QString("_%1").arg(index);
819 SALOME_Prs* aPrs = aDisplayer->buildSubshapePresentation(aSubShape, anEntry, aView);
821 displayPreview(aPrs, true, false); // append, do not update
824 aDisplayer->UpdateViewer();
827 globalSelection(GEOM_ALLSHAPES);
829 SelectionIntoArgument();
832 //=================================================================================
833 // function : updateState
835 //=================================================================================
836 void GroupGUI_GroupDlg::updateState (bool isAdd)
838 myAddBtn->setEnabled(!myEditCurrentArgument && !CORBA::is_nil(myMainObj) && isAdd);
839 //myShowOnlyBtn->setEnabled(!myEditCurrentArgument && !CORBA::is_nil(myMainObj) && isAdd);
841 bool hasSel = myIdList->selectedItems().count() > 0;
843 myRemBtn->setEnabled(hasSel);
844 myRestrictGroupBox->setEnabled(!CORBA::is_nil(myMainObj));
845 mySelAllBtn->setEnabled(!CORBA::is_nil(myMainObj));
847 mySelBtn2->setEnabled( subSelectionWay() != ALL_SUBSHAPES);
848 myShape2Name->setEnabled(subSelectionWay() != ALL_SUBSHAPES);
849 if (subSelectionWay() == ALL_SUBSHAPES)
850 setInPlaceObj(GEOM::GEOM_Object::_nil());
853 //=================================================================================
854 // function : selectionChanged
856 //=================================================================================
857 void GroupGUI_GroupDlg::selectionChanged()
859 highlightSubShapes();
862 //=================================================================================
863 // function : highlightSubShapes
865 //=================================================================================
866 void GroupGUI_GroupDlg::highlightSubShapes()
868 if (CORBA::is_nil(myMainObj))
871 TColStd_MapOfInteger anIds;
875 int ii = 0, nn = myIdList->count();
876 for (; ii < nn; ii++)
878 if (myIdList->item(ii)->isSelected()) {
879 int id = myIdList->item(ii)->text().toInt();
880 if (subSelectionWay() != ALL_SUBSHAPES &&
881 !myMain2InPlaceIndices.IsBound(id)) {
882 myIdList->item(ii)->setSelected(false);
889 SalomeApp_Application* app = myGeomGUI->getApp();
890 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
891 aSelMgr->clearSelected();
893 SUIT_ViewWindow* aViewWindow = 0;
894 SUIT_Study* activeStudy = app->activeStudy();
896 aViewWindow = app->desktop()->activeWindow();
897 if (aViewWindow == 0) return;
899 SUIT_ViewManager* aViewManager = aViewWindow->getViewManager();
900 if (aViewManager->getType() != OCCViewer_Viewer::Type() &&
901 aViewManager->getType() != SVTK_Viewer::Type())
904 SUIT_ViewModel* aViewModel = aViewManager->getViewModel();
905 SALOME_View* aView = dynamic_cast<SALOME_View*>(aViewModel);
906 if (aView == 0) return;
908 // TODO: use here GEOMBase_Helper::myPreview instead of ic->DisplayedObjects()
910 OCCViewer_Viewer* v3d = ((OCCViewer_ViewManager*)aViewManager)->getOCCViewer();
911 Handle(AIS_InteractiveContext) ic = v3d->getAISContext();
912 AIS_ListOfInteractive List;
913 ic->DisplayedObjects(List);
915 SALOME_ListIO aSelList;
917 AIS_ListIteratorOfListOfInteractive ite (List);
918 for (; ite.More(); ite.Next()) {
919 if (ite.Value()->IsInstance(STANDARD_TYPE(GEOM_AISShape))) {
920 Handle(GEOM_AISShape) aSh = Handle(GEOM_AISShape)::DownCast(ite.Value());
922 Handle(SALOME_InteractiveObject) anIO = aSh->getIO();
923 QString anEntry = anIO->getEntry();
924 int index = anEntry.lastIndexOf("_");
925 anEntry.remove(0, index+1);
926 int anIndex = anEntry.toInt();
927 if (anIds.Contains(anIndex))
928 aSelList.Append(anIO);
932 aSelMgr->setSelectedObjects(aSelList);
937 updateState(aSelList.Extent() > 0);
939 myAddBtn->setEnabled(true);
940 myAddBtn->setEnabled(true);
941 myRemBtn->setEnabled(true);
945 //=================================================================================
946 // function : createOperation
948 //=================================================================================
949 GEOM::GEOM_IOperations_ptr GroupGUI_GroupDlg::createOperation()
951 return getGeomEngine()->GetIGroupOperations(getStudyId());
954 #define RETURN_WITH_MSG(a, b) \
960 //=================================================================================
961 // function : isValid()
962 // purpose : Verify validity of input data
963 //=================================================================================
964 bool GroupGUI_GroupDlg::isValid(QString& theMessage)
966 SalomeApp_Study* study = getStudy();
968 RETURN_WITH_MSG (!study->studyDS()->GetProperties()->IsLocked(), tr("GEOM_STUDY_LOCKED"))
970 if (myMode == CreateGroup) {
971 RETURN_WITH_MSG(!CORBA::is_nil(myMainObj), tr("NO_MAIN_OBJ"))
974 RETURN_WITH_MSG(!CORBA::is_nil(myMainObj), tr("NO_GROUP"))
977 QString aName (getNewObjectName());
978 RETURN_WITH_MSG (!aName.trimmed().isEmpty(), tr("EMPTY_NAME"))
980 RETURN_WITH_MSG (myIdList->count(), tr("EMPTY_LIST"))
984 //=================================================================================
985 // function : execute
987 //=================================================================================
988 bool GroupGUI_GroupDlg::execute(ObjectList& objects)
990 GEOM::GEOM_IGroupOperations_var anOper = GEOM::GEOM_IGroupOperations::_narrow(getOperation());
992 GEOM::GEOM_Object_var aGroup;
993 if (myMode == CreateGroup)
994 aGroup = anOper->CreateGroup(myMainObj, getShapeType());
995 else if (myMode == EditGroup)
998 if (CORBA::is_nil(aGroup) || (myMode == CreateGroup && !anOper->IsDone()))
1001 GEOM::ListOfLong_var aCurrList = anOper->GetObjects(aGroup);
1002 if (!anOper->IsDone())
1005 if (aCurrList->length() > 0)
1007 anOper->DifferenceIDs(aGroup, aCurrList);
1008 if (!anOper->IsDone())
1012 int ii, nn = myIdList->count();
1015 GEOM::ListOfLong_var aNewList = new GEOM::ListOfLong;
1016 aNewList->length(nn);
1017 for (ii = 0; ii < nn; ii++) {
1018 aNewList[ii] = myIdList->item(ii)->text().toInt();
1020 anOper->UnionIDs(aGroup, aNewList);
1021 if (!anOper->IsDone())
1025 SalomeApp_Study* study = getStudy();
1027 char* objIOR = GEOMBase::GetIORFromObject(aGroup);
1028 std::string IOR(objIOR);
1031 _PTR(SObject) SO (study->studyDS()->FindObjectIOR(IOR));
1033 _PTR(StudyBuilder) aBuilder (study->studyDS()->NewBuilder());
1034 aBuilder->SetName(SO, getNewObjectName().toLatin1().constData());
1039 objects.push_back(aGroup._retn());
1044 //================================================================
1045 // Function : getFather
1046 // Purpose : Get father object for object to be added in study
1047 // ( called with addInStudy method )
1048 //================================================================
1049 GEOM::GEOM_Object_ptr GroupGUI_GroupDlg::getFather(GEOM::GEOM_Object_ptr theObj)
1051 GEOM::GEOM_Object_var aFatherObj;
1052 if (theObj->GetType() == GEOM_GROUP) {
1053 GEOM::GEOM_IGroupOperations_var anOper = GEOM::GEOM_IGroupOperations::_narrow(getOperation());
1054 aFatherObj = anOper->GetMainShape(theObj);
1056 return aFatherObj._retn();