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 bool highlight = false;
492 for (int ii = 1, nn = aMapIndex.Extent(); ii <= nn; ii++) {
493 if (aMap.contains(aMapIndex(ii))) {
494 myIdList->item(aMap[aMapIndex(ii)])->setSelected(true);
499 highlightSubShapes();
501 myIdList->blockSignals(isBlocked);
507 //=================================================================================
508 // function : ConstructorsClicked()
509 // purpose : Radio button management
510 //=================================================================================
511 void GroupGUI_GroupDlg::ConstructorsClicked(int constructorId)
513 if (getConstructorId() != constructorId)
514 setConstructorId(constructorId);
516 myIsShapeType = true;
518 myEditCurrentArgument = 0;
520 setInPlaceObj(myInPlaceObj); // to rebuild myMain2InPlaceIndices
525 //=================================================================================
526 // function : selectAllSubShapes
528 //=================================================================================
529 void GroupGUI_GroupDlg::selectAllSubShapes()
531 if (CORBA::is_nil(myMainObj) || !myIsShapeType)
534 GEOM::ListOfLong_var aSubShapes;
535 GEOM::GEOM_IShapesOperations_var aShOp = getGeomEngine()->GetIShapesOperations(getStudyId());
536 aSubShapes = aShOp->SubShapeAllIDs(myMainObj, getShapeType(), false);
537 if (aSubShapes->length() > 0) {
538 if (subSelectionWay() == ALL_SUBSHAPES)
540 myIdList->clear(); // for sorted final list?
542 if (!aShOp->IsDone())
547 aSubShapes = new GEOM::ListOfLong();
548 aSubShapes->length(myMain2InPlaceIndices.Extent());
549 TColStd_DataMapIteratorOfDataMapOfIntegerInteger m2ip (myMain2InPlaceIndices);
550 for (int i = 0; m2ip.More(); i++, m2ip.Next())
551 aSubShapes[i] = m2ip.Key();
554 bool isBlocked = myIdList->signalsBlocked();
555 myIdList->blockSignals(true);
557 for (int i = 0, n = aSubShapes->length(); i < n; i++) {
558 CORBA::Long anIndex = aSubShapes[i];
562 QListWidgetItem* anItem = 0;
563 QString text = QString("%1").arg(anIndex);
564 if (!myInPlaceObj->_is_nil()) {
565 QList<QListWidgetItem*> found = myIdList->findItems(text, Qt::MatchExactly);
566 if (found.count()) anItem = found[0];
569 anItem = new QListWidgetItem(text);
570 myIdList->addItem(anItem);
572 anItem->setSelected(true);
575 myIdList->blockSignals(isBlocked);
576 highlightSubShapes();
580 //=================================================================================
581 // function : showOnlySelected
583 //=================================================================================
584 void GroupGUI_GroupDlg::showOnlySelected()
586 if (CORBA::is_nil(myMainObj) || !myIsShapeType)
589 QPushButton* send = (QPushButton*)sender();
590 if (send == myShowAllBtn) {
595 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
596 SALOME_ListIO aSelList;
597 aSelMgr->selectedObjects(aSelList);
599 GEOM_Displayer* aDisplayer = getDisplayer();
601 if (send == myHideSelBtn) {
602 aDisplayer->Erase(aSelList, false, true);
605 aDisplayer->EraseAll();
606 aDisplayer->Display(aSelList, true);
610 //=================================================================================
611 // function : getSelectedSubshapes
613 //=================================================================================
614 int GroupGUI_GroupDlg::getSelectedSubshapes (TColStd_IndexedMapOfInteger& theMapIndex)
618 SalomeApp_Application* app = myGeomGUI->getApp();
621 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
622 SALOME_ListIO aSelList;
623 aSelMgr->selectedObjects(aSelList);
625 // try to find out and process the global selection
626 // (of not published objects and of published sub-shapes)
628 SALOME_ListIteratorOfListIO anIter (aSelList);
629 for (int i = 0; anIter.More(); anIter.Next(), i++)
631 Handle(SALOME_InteractiveObject) anIObj = anIter.Value();
632 QString anEntry = anIObj->getEntry();
634 int index = anEntry.lastIndexOf(str);
635 if (index > 0) // selection among special preview
637 anEntry.remove(0, index+1);
638 int anIndex = anEntry.toInt();
640 theMapIndex.Add(anIndex);
642 else // selection among published shapes
644 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>(app->activeStudy());
645 if (!appStudy) return 0;
646 _PTR(Study) aStudy = appStudy->studyDS();
648 _PTR(SObject) aSObj (aStudy->FindObjectID(anEntry.toLatin1().constData()));
649 GEOM::GEOM_Object_var aGeomObj =
650 GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aSObj));
652 if (GEOMBase::GetShape(aGeomObj, aShape)) {
653 if (aGeomObj->GetType() == GEOM_GROUP || aShape.ShapeType() == getShapeType()) {
654 TopTools_IndexedMapOfShape aMainMap;
655 TopoDS_Shape aMainShape = GEOM_Client().GetShape(GeometryGUI::GetGeomGen(), myMainObj);
656 TopExp::MapShapes(aMainShape, aMainMap);
658 TopExp_Explorer anExp (aShape, getShapeType());
659 for (; anExp.More(); anExp.Next()) {
660 TopoDS_Shape aSubShape = anExp.Current();
661 int anIndex = aMainMap.FindIndex(aSubShape);
663 if (subSelectionWay() != ALL_SUBSHAPES &&
664 !myMain2InPlaceIndices.IsBound(anIndex))
666 theMapIndex.Add(anIndex);
675 return theMapIndex.Extent();
678 //=================================================================================
681 //=================================================================================
682 void GroupGUI_GroupDlg::add()
684 TColStd_IndexedMapOfInteger aMapIndex;
685 int nbSel = getSelectedSubshapes(aMapIndex);
687 TColStd_MapOfInteger aMap;
688 for (int i = 0, n = myIdList->count(); i < n; i++)
689 aMap.Add(myIdList->item(i)->text().toInt());
692 bool isBlocked = myIdList->signalsBlocked();
693 myIdList->blockSignals(true);
695 for (int i = 1, n = aMapIndex.Extent(); i <= n; i++) {
696 if (aMap.Contains(aMapIndex(i)))
699 QListWidgetItem* anItem = new QListWidgetItem(QString("%1").arg(aMapIndex(i)));
700 myIdList->addItem(anItem);
701 anItem->setSelected(true);
704 myIdList->blockSignals(isBlocked);
710 //=================================================================================
713 //=================================================================================
714 void GroupGUI_GroupDlg::remove()
716 bool isBlocked = myIdList->signalsBlocked();
717 myIdList->blockSignals(true);
719 QListIterator<QListWidgetItem*> it (myIdList->selectedItems());
723 myIdList->blockSignals(isBlocked);
725 highlightSubShapes();
728 //=================================================================================
729 //function : subSelectionWay
731 //=================================================================================
732 int GroupGUI_GroupDlg::subSelectionWay() const
734 return myRestrictGroup->checkedId();
737 //=================================================================================
738 // function : getShapeType()
740 //=================================================================================
741 TopAbs_ShapeEnum GroupGUI_GroupDlg::getShapeType() const
743 switch (getConstructorId()) {
744 case 0: return TopAbs_VERTEX;
745 case 1: return TopAbs_EDGE;
746 case 2: return TopAbs_FACE;
747 case 3: return TopAbs_SOLID;
748 default: return TopAbs_SHAPE;
752 //=================================================================================
753 // function : setShapeType()
755 //=================================================================================
756 void GroupGUI_GroupDlg::setShapeType(const TopAbs_ShapeEnum theType)
760 case TopAbs_VERTEX: anId = 0; break;
761 case TopAbs_EDGE: anId = 1; break;
762 case TopAbs_FACE: anId = 2; break;
763 case TopAbs_SOLID: anId = 3; break;
765 setConstructorId(anId);
768 myIsShapeType = true;
769 // workaround to avoid set checked button 0
770 setConstructorId(anId);
774 //=================================================================================
775 // function : activateSelection
776 // purpose : Activate selection in accordance with myEditCurrentArgument
777 //=================================================================================
778 void GroupGUI_GroupDlg::activateSelection()
783 if (!myMainObj->_is_nil() &&
784 !myEditCurrentArgument &&
785 myIsShapeType) // check if shape type is already choosen by user
787 GEOM_Displayer* aDisplayer = getDisplayer();
789 SUIT_ViewWindow* aViewWindow = 0;
790 SUIT_Study* activeStudy = SUIT_Session::session()->activeApplication()->activeStudy();
792 aViewWindow = SUIT_Session::session()->activeApplication()->desktop()->activeWindow();
793 if (aViewWindow == 0) return;
795 SUIT_ViewManager* aViewManager = aViewWindow->getViewManager();
796 if (aViewManager->getType() != OCCViewer_Viewer::Type() &&
797 aViewManager->getType() != SVTK_Viewer::Type())
800 SUIT_ViewModel* aViewModel = aViewManager->getViewModel();
801 SALOME_View* aView = dynamic_cast<SALOME_View*>(aViewModel);
802 if (aView == 0) return;
804 TopoDS_Shape aMainShape = GEOM_Client().GetShape(GeometryGUI::GetGeomGen(), myMainObj);
805 TopoDS_Shape aRestrictionShape;
806 if (subSelectionWay() == ALL_SUBSHAPES)
807 aRestrictionShape = aMainShape;
808 else if (!myInPlaceObj->_is_nil())
809 aRestrictionShape = GEOM_Client().GetShape(GeometryGUI::GetGeomGen(), myInPlaceObj);
812 TopTools_IndexedMapOfShape aSubShapesMap;
813 TopExp::MapShapes(aMainShape, aSubShapesMap);
814 CORBA::String_var aMainEntry = myMainObj->GetStudyEntry();
815 QString anEntryBase = aMainEntry.in();
817 TopExp_Explorer anExp (aRestrictionShape, getShapeType());
818 for (; anExp.More(); anExp.Next())
820 TopoDS_Shape aSubShape = anExp.Current();
821 int index = aSubShapesMap.FindIndex(aSubShape);
822 QString anEntry = anEntryBase + QString("_%1").arg(index);
824 SALOME_Prs* aPrs = aDisplayer->buildSubshapePresentation(aSubShape, anEntry, aView);
826 displayPreview(aPrs, true, false); // append, do not update
829 aDisplayer->UpdateViewer();
832 globalSelection(GEOM_ALLSHAPES);
834 SelectionIntoArgument();
837 //=================================================================================
838 // function : updateState
840 //=================================================================================
841 void GroupGUI_GroupDlg::updateState (bool isAdd)
843 myAddBtn->setEnabled(!myEditCurrentArgument && !CORBA::is_nil(myMainObj) && isAdd);
844 //myShowOnlyBtn->setEnabled(!myEditCurrentArgument && !CORBA::is_nil(myMainObj) && isAdd);
846 bool hasSel = myIdList->selectedItems().count() > 0;
848 myRemBtn->setEnabled(hasSel);
849 myRestrictGroupBox->setEnabled(!CORBA::is_nil(myMainObj));
850 mySelAllBtn->setEnabled(!CORBA::is_nil(myMainObj));
852 mySelBtn2->setEnabled( subSelectionWay() != ALL_SUBSHAPES);
853 myShape2Name->setEnabled(subSelectionWay() != ALL_SUBSHAPES);
854 if (subSelectionWay() == ALL_SUBSHAPES)
855 setInPlaceObj(GEOM::GEOM_Object::_nil());
858 //=================================================================================
859 // function : selectionChanged
861 //=================================================================================
862 void GroupGUI_GroupDlg::selectionChanged()
864 highlightSubShapes();
867 //=================================================================================
868 // function : highlightSubShapes
870 //=================================================================================
871 void GroupGUI_GroupDlg::highlightSubShapes()
873 if (CORBA::is_nil(myMainObj))
876 TColStd_MapOfInteger anIds;
880 int ii = 0, nn = myIdList->count();
881 for (; ii < nn; ii++)
883 if (myIdList->item(ii)->isSelected()) {
884 int id = myIdList->item(ii)->text().toInt();
885 if (subSelectionWay() != ALL_SUBSHAPES &&
886 !myMain2InPlaceIndices.IsBound(id)) {
887 myIdList->item(ii)->setSelected(false);
894 SalomeApp_Application* app = myGeomGUI->getApp();
895 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
896 aSelMgr->clearSelected();
898 SUIT_ViewWindow* aViewWindow = 0;
899 SUIT_Study* activeStudy = app->activeStudy();
901 aViewWindow = app->desktop()->activeWindow();
902 if (aViewWindow == 0) return;
904 SUIT_ViewManager* aViewManager = aViewWindow->getViewManager();
905 if (aViewManager->getType() != OCCViewer_Viewer::Type() &&
906 aViewManager->getType() != SVTK_Viewer::Type())
909 SUIT_ViewModel* aViewModel = aViewManager->getViewModel();
910 SALOME_View* aView = dynamic_cast<SALOME_View*>(aViewModel);
911 if (aView == 0) return;
913 // TODO: use here GEOMBase_Helper::myPreview instead of ic->DisplayedObjects()
915 OCCViewer_Viewer* v3d = ((OCCViewer_ViewManager*)aViewManager)->getOCCViewer();
916 Handle(AIS_InteractiveContext) ic = v3d->getAISContext();
917 AIS_ListOfInteractive List;
918 ic->DisplayedObjects(List);
920 SALOME_ListIO aSelList;
922 // To highlight the selected subshape in Object Browser, if it's already pudlished under the main shape
923 GEOM::GEOM_ILocalOperations_var aLocOp = getGeomEngine()->GetILocalOperations(getStudyId());
924 QMap<int, QString> childsMap;
925 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>(app->activeStudy());
927 _PTR(Study) aStudy = appStudy->studyDS();
928 CORBA::String_var aMainEntry = myMainObj->GetStudyEntry();
929 QString anEntry = aMainEntry.in();
930 _PTR(SObject) aSObj (aStudy->FindObjectID(anEntry.toLatin1().constData()));
931 _PTR(ChildIterator) anIt ( aStudy->NewChildIterator( aSObj ) );
932 for ( anIt->InitEx( true ); anIt->More(); anIt->Next() ) {
933 GEOM::GEOM_Object_var aChild = GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(anIt->Value()));
934 if ( !CORBA::is_nil( aChild ) ) {
935 int index = aLocOp->GetSubShapeIndex(myMainObj, aChild);
936 CORBA::String_var aChildEntry = aChild->GetStudyEntry();
937 QString anEntry = aChildEntry.in();
938 childsMap.insert(index, anEntry);
943 AIS_ListIteratorOfListOfInteractive ite (List);
944 for (; ite.More(); ite.Next()) {
945 if (ite.Value()->IsInstance(STANDARD_TYPE(GEOM_AISShape))) {
946 Handle(GEOM_AISShape) aSh = Handle(GEOM_AISShape)::DownCast(ite.Value());
948 Handle(SALOME_InteractiveObject) anIO = aSh->getIO();
949 QString anEntry = anIO->getEntry();
950 int index = anEntry.lastIndexOf("_");
951 anEntry.remove(0, index+1);
952 int anIndex = anEntry.toInt();
953 if ( anIds.Contains(anIndex) ) {
954 aSelList.Append(anIO);
955 if ( childsMap.contains ( anIndex )) {
956 Handle(SALOME_InteractiveObject) tmpIO = new SALOME_InteractiveObject( childsMap.value(anIndex).toLatin1().constData(), "GEOM", "TEMP_IO" );
957 aSelList.Append(tmpIO);
963 aSelMgr->setSelectedObjects(aSelList);
968 updateState(aSelList.Extent() > 0);
970 myAddBtn->setEnabled(true);
971 myAddBtn->setEnabled(true);
972 myRemBtn->setEnabled(true);
976 //=================================================================================
977 // function : createOperation
979 //=================================================================================
980 GEOM::GEOM_IOperations_ptr GroupGUI_GroupDlg::createOperation()
982 return getGeomEngine()->GetIGroupOperations(getStudyId());
985 #define RETURN_WITH_MSG(a, b) \
991 //=================================================================================
992 // function : isValid()
993 // purpose : Verify validity of input data
994 //=================================================================================
995 bool GroupGUI_GroupDlg::isValid(QString& theMessage)
997 SalomeApp_Study* study = getStudy();
999 RETURN_WITH_MSG (!study->studyDS()->GetProperties()->IsLocked(), tr("GEOM_STUDY_LOCKED"))
1001 if (myMode == CreateGroup) {
1002 RETURN_WITH_MSG(!CORBA::is_nil(myMainObj), tr("NO_MAIN_OBJ"))
1005 RETURN_WITH_MSG(!CORBA::is_nil(myMainObj), tr("NO_GROUP"))
1008 QString aName (getNewObjectName());
1009 RETURN_WITH_MSG (!aName.trimmed().isEmpty(), tr("EMPTY_NAME"))
1011 RETURN_WITH_MSG (myIdList->count(), tr("EMPTY_LIST"))
1015 //=================================================================================
1016 // function : execute
1018 //=================================================================================
1019 bool GroupGUI_GroupDlg::execute(ObjectList& objects)
1021 GEOM::GEOM_IGroupOperations_var anOper = GEOM::GEOM_IGroupOperations::_narrow(getOperation());
1023 GEOM::GEOM_Object_var aGroup;
1024 if (myMode == CreateGroup)
1025 aGroup = anOper->CreateGroup(myMainObj, getShapeType());
1026 else if (myMode == EditGroup)
1029 if (CORBA::is_nil(aGroup) || (myMode == CreateGroup && !anOper->IsDone()))
1032 GEOM::ListOfLong_var aCurrList = anOper->GetObjects(aGroup);
1033 if (!anOper->IsDone())
1036 if (aCurrList->length() > 0)
1038 anOper->DifferenceIDs(aGroup, aCurrList);
1039 if (!anOper->IsDone())
1043 int ii, nn = myIdList->count();
1046 GEOM::ListOfLong_var aNewList = new GEOM::ListOfLong;
1047 aNewList->length(nn);
1048 for (ii = 0; ii < nn; ii++) {
1049 aNewList[ii] = myIdList->item(ii)->text().toInt();
1051 anOper->UnionIDs(aGroup, aNewList);
1052 if (!anOper->IsDone())
1056 SalomeApp_Study* study = getStudy();
1058 char* objIOR = GEOMBase::GetIORFromObject(aGroup);
1059 std::string IOR(objIOR);
1062 _PTR(SObject) SO (study->studyDS()->FindObjectIOR(IOR));
1064 _PTR(StudyBuilder) aBuilder (study->studyDS()->NewBuilder());
1065 aBuilder->SetName(SO, getNewObjectName().toLatin1().constData());
1070 objects.push_back(aGroup._retn());
1075 //================================================================
1076 // Function : getFather
1077 // Purpose : Get father object for object to be added in study
1078 // ( called with addInStudy method )
1079 //================================================================
1080 GEOM::GEOM_Object_ptr GroupGUI_GroupDlg::getFather(GEOM::GEOM_Object_ptr theObj)
1082 GEOM::GEOM_Object_var aFatherObj;
1083 if (theObj->GetType() == GEOM_GROUP) {
1084 GEOM::GEOM_IGroupOperations_var anOper = GEOM::GEOM_IGroupOperations::_narrow(getOperation());
1085 aFatherObj = anOper->GetMainShape(theObj);
1087 return aFatherObj._retn();