1 // Copyright (C) 2007-2011 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),
77 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
79 QPixmap image0 (resMgr->loadPixmap("GEOM", tr("ICON_OBJBROWSER_VERTEX")));
80 QPixmap image1 (resMgr->loadPixmap("GEOM", tr("ICON_OBJBROWSER_EDGE")));
81 QPixmap image2 (resMgr->loadPixmap("GEOM", tr("ICON_OBJBROWSER_FACE")));
82 QPixmap image3 (resMgr->loadPixmap("GEOM", tr("ICON_OBJBROWSER_SOLID")));
83 QPixmap iconSelect (resMgr->loadPixmap("GEOM", tr("ICON_SELECT")));
85 setWindowTitle(myMode == CreateGroup ? tr("CREATE_GROUP_TITLE") : tr("EDIT_GROUP_TITLE"));
87 // Shape type button group
88 mainFrame()->GroupConstructors->setEnabled(myMode == CreateGroup);
89 mainFrame()->GroupConstructors->setTitle(tr("SHAPE_TYPE"));
90 mainFrame()->RadioButton1->setIcon(image0);
91 mainFrame()->RadioButton2->setIcon(image1);
92 mainFrame()->RadioButton3->setIcon(image2);
93 mainFrame()->RadioButton4->setIcon(image3);
94 mainFrame()->RadioButton4->show();
97 mainFrame()->GroupBoxName->setTitle(tr("GROUP_NAME"));
99 // Main shape and sub-shapes
100 QGroupBox* GroupMedium = new QGroupBox(tr("MAIN_SUB_SHAPES"), centralWidget());
101 QGridLayout* aMedLayout = new QGridLayout(GroupMedium);
102 aMedLayout->setMargin(9);
103 aMedLayout->setSpacing(6);
105 QLabel* aMainLabel = new QLabel(tr("MAIN_SHAPE"), GroupMedium);
107 mySelBtn = new QPushButton(GroupMedium);
108 mySelBtn->setIcon(iconSelect);
109 mySelBtn->setEnabled(myMode == CreateGroup);
111 myMainName = new QLineEdit(GroupMedium);
112 myMainName->setReadOnly(true);
113 myMainName->setEnabled(myMode == CreateGroup);
115 myRestrictGroupBox = new QGroupBox(tr("SHAPE_SEL_RESTR"), GroupMedium);
116 myRestrictGroup = new QButtonGroup(myRestrictGroupBox);
117 QRadioButton* allSubs = new QRadioButton(tr("NO_RESTR") , myRestrictGroupBox);
118 QRadioButton* inPlaceSubs = new QRadioButton(tr("GEOM_PARTS_OF_SHAPE2"), myRestrictGroupBox);
119 QRadioButton* shape2Subs = new QRadioButton(tr("SUBSHAPES_OF_SHAPE2") , myRestrictGroupBox);
120 QGridLayout* aRestrictLayout = new QGridLayout(myRestrictGroupBox);
122 QLabel* aSecondLabel = new QLabel(tr("SECOND_SHAPE"), myRestrictGroupBox);
123 mySelBtn2 = new QPushButton(myRestrictGroupBox);
124 mySelBtn2->setIcon(iconSelect);
125 mySelBtn2->setEnabled(false);
126 myShape2Name = new QLineEdit(myRestrictGroupBox);
127 myShape2Name->setReadOnly(true);
128 myShape2Name->setEnabled(false);
130 aRestrictLayout->setMargin(9);
131 aRestrictLayout->setSpacing(6);
132 aRestrictLayout->addWidget(allSubs, 0, 0, 1, 3);
133 aRestrictLayout->addWidget(inPlaceSubs, 1, 0, 1, 3);
134 aRestrictLayout->addWidget(shape2Subs, 2, 0, 1, 3);
135 aRestrictLayout->addWidget(aSecondLabel, 3, 0);
136 aRestrictLayout->addWidget(mySelBtn2, 3, 1);
137 aRestrictLayout->addWidget(myShape2Name, 3, 2);
138 myRestrictGroup->addButton(allSubs, ALL_SUBSHAPES);
139 myRestrictGroup->addButton(inPlaceSubs, GET_IN_PLACE);
140 myRestrictGroup->addButton(shape2Subs, SUBSHAPES_OF_SHAPE2);
141 myRestrictGroupBox->setEnabled(!CORBA::is_nil(myMainObj));
142 allSubs->setChecked(true);
144 myShowOnlyBtn = new QPushButton(tr("SHOW_ONLY_SELECTED"), GroupMedium);
145 myHideSelBtn = new QPushButton(tr("HIDE_SELECTED"), GroupMedium);
146 myShowAllBtn = new QPushButton(tr("SHOW_ALL_SUB_SHAPES"), GroupMedium);
148 mySelAllBtn = new QPushButton(tr("SELECT_ALL"), GroupMedium);
149 myAddBtn = new QPushButton(tr("ADD"), GroupMedium);
150 myRemBtn = new QPushButton(tr("REMOVE"), GroupMedium);
152 myIdList = new QListWidget(GroupMedium);
154 myIdList->setSelectionMode(QAbstractItemView::ExtendedSelection);
155 myIdList->setFlow(QListView::TopToBottom);
156 myIdList->setWrapping(true);
158 aMedLayout->addWidget(aMainLabel, 0, 0);
159 aMedLayout->addWidget(mySelBtn, 0, 1);
160 aMedLayout->addWidget(myMainName, 0, 2, 1, 2);
161 aMedLayout->addWidget(myRestrictGroupBox, 1, 0, 4, 3);
163 aMedLayout->addWidget(myShowOnlyBtn, 1, 3);
164 aMedLayout->addWidget(myHideSelBtn, 2, 3);
165 aMedLayout->addWidget(myShowAllBtn, 3, 3);
167 aMedLayout->addWidget(myIdList, 5, 0, 4, 3);
168 aMedLayout->addWidget(mySelAllBtn, 5, 3);
169 aMedLayout->addWidget(myAddBtn, 6, 3);
170 aMedLayout->addWidget(myRemBtn, 7, 3);
172 aMedLayout->setColumnStretch(2, 5);
173 aMedLayout->setRowStretch(5, 5);
174 aMedLayout->setRowStretch(8, 5);
176 QVBoxLayout* layout = new QVBoxLayout(centralWidget());
177 layout->setMargin(0); layout->setSpacing(6);
178 layout->addWidget(GroupMedium);
180 setHelpFileName("work_with_groups_page.html");
185 GroupGUI_GroupDlg::~GroupGUI_GroupDlg()
187 if (myIsHiddenMain) {
188 GEOM_Displayer* aDisplayer = getDisplayer();
189 aDisplayer->Display(myMainObj);
190 myIsHiddenMain = false;
194 //=================================================================================
197 //=================================================================================
198 void GroupGUI_GroupDlg::Init()
200 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
202 //unset shape type to avoid preparation of selection before exact user shape type selection
203 unsetConstructorId();
204 myIsShapeType = false;
206 if (myMode == CreateGroup) {
207 initName(tr("GROUP_PREFIX"));
209 // Get ready for main shape selection
210 myEditCurrentArgument = myMainName;
212 connect(this, SIGNAL(constructorsClicked(int)), this, SLOT(ConstructorsClicked(int)));
213 connect(mySelBtn, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
214 connect(mySelBtn2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
216 else if (myMode == EditGroup) {
217 SALOME_ListIO aSelList;
218 aSelMgr->selectedObjects(aSelList);
220 if (aSelList.Extent()) {
221 GEOM::GEOM_Object_var anObj =
222 GEOMBase::ConvertIOinGEOMObject(aSelList.First());
224 if (!CORBA::is_nil(anObj) && anObj->GetType() == GEOM_GROUP) {
227 mainFrame()->ResultName->setText(GEOMBase::GetName(myGroup));
229 GEOM::GEOM_IGroupOperations_var anOper = GEOM::GEOM_IGroupOperations::_narrow(getOperation());
230 myMainObj = anOper->GetMainShape(myGroup);
231 if (!CORBA::is_nil(myMainObj))
232 myMainName->setText(GEOMBase::GetName(myMainObj));
234 setShapeType((TopAbs_ShapeEnum)anOper->GetType(myGroup));
236 GEOM::ListOfLong_var aCurrList = anOper->GetObjects(myGroup);
237 for (int i = 0, n = aCurrList->length(); i < n; i++)
238 myIdList->addItem(new QListWidgetItem(QString("%1").arg(aCurrList[i])));
240 myEditCurrentArgument = 0;
242 connect(mySelBtn2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
246 connect(aSelMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
248 connect(buttonOk(), SIGNAL(clicked()), this, SLOT(ClickOnOk()));
249 connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
251 connect(myRestrictGroup, SIGNAL(buttonClicked(int)), this, SLOT(SetEditCurrentArgument()));
252 connect(mySelAllBtn, SIGNAL(clicked()), this, SLOT(selectAllSubShapes()));
253 connect(myAddBtn, SIGNAL(clicked()), this, SLOT(add()));
254 connect(myRemBtn, SIGNAL(clicked()), this, SLOT(remove()));
255 connect(myShowOnlyBtn, SIGNAL(clicked()), this, SLOT(showOnlySelected()));
256 connect(myHideSelBtn, SIGNAL(clicked()), this, SLOT(showOnlySelected()));
257 connect(myShowAllBtn, SIGNAL(clicked()), this, SLOT(showOnlySelected()));
258 connect(myIdList, SIGNAL(itemSelectionChanged()), this, SLOT(selectionChanged()));
260 setInPlaceObj(GEOM::GEOM_Object::_nil());
262 myBusy = true; // just activate but do not select in the list
267 //=================================================================================
268 // function : enterEvent()
270 //=================================================================================
271 void GroupGUI_GroupDlg::enterEvent(QEvent* e)
273 if (!buttonCancel()->isEnabled())
274 ActivateThisDialog();
277 //=================================================================================
278 //function : closeEvent
279 //purpose : remove temporary geom object
280 //=================================================================================
281 void GroupGUI_GroupDlg::closeEvent(QCloseEvent* e)
283 setInPlaceObj(GEOM::GEOM_Object::_nil());
286 GEOMBase_Skeleton::closeEvent(e);
289 //=================================================================================
290 // function : ClickOnOk()
292 //=================================================================================
293 void GroupGUI_GroupDlg::ClickOnOk()
295 setIsApplyAndClose(true);
300 //=================================================================================
301 // function : ClickOnApply()
303 //=================================================================================
304 bool GroupGUI_GroupDlg::ClickOnApply()
306 if (!onAccept(myMode == CreateGroup, true))
309 if (myMode == CreateGroup)
313 ConstructorsClicked(getConstructorId());
321 //=================================================================================
322 // function : ActivateThisDialog()
324 //=================================================================================
325 void GroupGUI_GroupDlg::ActivateThisDialog()
327 GEOMBase_Skeleton::ActivateThisDialog();
329 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
330 this, SLOT(SelectionIntoArgument()));
335 //=================================================================================
336 // function : SetEditCurrentArgument()
338 //=================================================================================
339 void GroupGUI_GroupDlg::SetEditCurrentArgument()
341 QPushButton* send = (QPushButton*)sender();
343 if (send == mySelBtn) {
344 myEditCurrentArgument = myMainName;
345 myShape2Name->setText("");
347 else if (send == mySelBtn2 || sender() == myRestrictGroup) {
348 setInPlaceObj(GEOM::GEOM_Object::_nil());
349 myShape2Name->setText("");
350 if (subSelectionWay() != ALL_SUBSHAPES) {
351 myEditCurrentArgument = myShape2Name;
354 myEditCurrentArgument = 0;
363 //=================================================================================
364 // function : onGetInPlace()
366 //=================================================================================
367 void GroupGUI_GroupDlg::onGetInPlace()
369 setInPlaceObj(GEOM::GEOM_Object::_nil());
370 myEditCurrentArgument->setText("");
372 bool isBlocked = myIdList->signalsBlocked();
373 myIdList->blockSignals(true);
374 myIdList->clearSelection();
375 myIdList->blockSignals(isBlocked);
377 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
378 SALOME_ListIO aSelList;
379 aSelMgr->selectedObjects(aSelList);
381 if (aSelList.Extent() != 1)
384 GEOM::GEOM_Object_var anObj =
385 GEOMBase::ConvertIOinGEOMObject(aSelList.First());
386 if (GEOMBase::IsShape(anObj)) {
387 if (!anObj->_is_equivalent(myMainObj) && !anObj->_is_equivalent(myGroup)) {
388 SUIT_OverrideCursor wc;
389 myEditCurrentArgument->setText(GEOMBase::GetName(anObj));
390 GEOM::GEOM_IShapesOperations_var aShapesOp =
391 getGeomEngine()->GetIShapesOperations(getStudyId());
392 if (subSelectionWay() == GET_IN_PLACE) {
393 GEOM::GEOM_Object_var aGetInPlaceObj = aShapesOp->GetInPlace(myMainObj, anObj);
394 setInPlaceObj(aGetInPlaceObj);
397 bool isVisible = true;
398 if (SALOME_View* view = GEOM_Displayer::GetActiveView())
399 isVisible = view->isVisible(aSelList.First());
400 setInPlaceObj(anObj, isVisible);
402 myEditCurrentArgument = 0;
403 //myBusy = true; // just activate but do not select in the list
410 //=================================================================================
411 //function : setInPlaceObj
412 //purpose : temporarily add an object to study and remove old InPlaceObj
413 //=================================================================================
414 void GroupGUI_GroupDlg::setInPlaceObj(GEOM::GEOM_Object_var theObj, const bool isVisible)
416 if (!myInPlaceObj->_is_equivalent(theObj))
418 myInPlaceObj = theObj;
421 // build map of indices
422 myMain2InPlaceIndices.Clear();
423 if (!myInPlaceObj->_is_nil()) {
424 GEOM::GEOM_IShapesOperations_var aShapesOp = getGeomEngine()->GetIShapesOperations(getStudyId());
425 GEOM::GEOM_ILocalOperations_var aLocOp = getGeomEngine()->GetILocalOperations(getStudyId());
427 GEOM::ListOfGO_var aSubObjects = aShapesOp->MakeExplode(myInPlaceObj, getShapeType(), false);
428 for (int i = 0; i < aSubObjects->length(); i++)
430 GEOM::GEOM_Object_var aSS = aShapesOp->GetSame(myMainObj, aSubObjects[i]);
431 if (!CORBA::is_nil(aSS)) {
432 CORBA::Long aMainIndex = aLocOp->GetSubShapeIndex(myMainObj, aSS);
433 CORBA::Long aPlaceIndex = aLocOp->GetSubShapeIndex(myInPlaceObj, aSubObjects[i]);
434 if (aMainIndex >= 0 && aPlaceIndex > 0)
435 myMain2InPlaceIndices.Bind(aMainIndex, aPlaceIndex);
439 myInPlaceObjSelectState = subSelectionWay();
440 if (myInPlaceObjSelectState == SUBSHAPES_OF_SHAPE2 && !isVisible)
441 myInPlaceObjSelectState = SUBSHAPES_OF_INVISIBLE_SHAPE2;
444 //=================================================================================
445 // function : SelectionIntoArgument()
446 // purpose : Called when selection has changed
447 //=================================================================================
448 void GroupGUI_GroupDlg::SelectionIntoArgument()
450 if (subSelectionWay() != ALL_SUBSHAPES && myEditCurrentArgument == myShape2Name) {
455 if (myEditCurrentArgument == myMainName) { // Selection of a main shape is active
456 myEditCurrentArgument->setText("");
459 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
460 SALOME_ListIO aSelList;
461 aSelMgr->selectedObjects(aSelList);
462 int nbSel = aSelList.Extent();
465 GEOM::GEOM_Object_var anObj =
466 GEOMBase::ConvertIOinGEOMObject(aSelList.First());
468 if (GEOMBase::IsShape(anObj)) {
469 if (myIsHiddenMain) {
470 GEOM_Displayer* aDisplayer = getDisplayer();
471 aDisplayer->Display(myMainObj);
472 myIsHiddenMain = false;
475 myEditCurrentArgument->setText(GEOMBase::GetName(anObj));
476 // activate subshapes selection by default
477 myEditCurrentArgument = 0;
483 if (myIsHiddenMain) {
484 GEOM_Displayer* aDisplayer = getDisplayer();
485 aDisplayer->Display(myMainObj);
486 myIsHiddenMain = false;
488 myMainObj = GEOM::GEOM_Object::_nil();
491 else { // an attempt to synchronize list box selection with 3d viewer
492 if (myBusy || myMainObj->_is_nil()) {
496 bool isBlocked = myIdList->signalsBlocked();
497 myIdList->blockSignals(true);
498 myIdList->clearSelection();
500 TColStd_IndexedMapOfInteger aMapIndex;
501 int nbSel = getSelectedSubshapes(aMapIndex);
505 for (int i = 0, n = myIdList->count(); i < n; i++)
506 aMap.insert(myIdList->item(i)->text().toInt(), i);
508 bool highlight = false;
509 for (int ii = 1, nn = aMapIndex.Extent(); ii <= nn; ii++) {
510 if (aMap.contains(aMapIndex(ii))) {
511 myIdList->item(aMap[aMapIndex(ii)])->setSelected(true);
516 highlightSubShapes();
518 myIdList->blockSignals(isBlocked);
524 //=================================================================================
525 // function : ConstructorsClicked()
526 // purpose : Radio button management
527 //=================================================================================
528 void GroupGUI_GroupDlg::ConstructorsClicked(int constructorId)
530 if (getConstructorId() != constructorId)
531 setConstructorId(constructorId);
533 myIsShapeType = true;
535 myEditCurrentArgument = 0;
537 setInPlaceObj(myInPlaceObj); // to rebuild myMain2InPlaceIndices
542 //=================================================================================
543 // function : selectAllSubShapes
545 //=================================================================================
546 void GroupGUI_GroupDlg::selectAllSubShapes()
548 if (CORBA::is_nil(myMainObj) || !myIsShapeType)
551 GEOM::ListOfLong_var aSubShapes;
552 GEOM::GEOM_IShapesOperations_var aShOp = getGeomEngine()->GetIShapesOperations(getStudyId());
553 aSubShapes = aShOp->SubShapeAllIDs(myMainObj, getShapeType(), false);
554 if (aSubShapes->length() > 0) {
555 if (subSelectionWay() == ALL_SUBSHAPES)
557 myIdList->clear(); // for sorted final list?
559 if (!aShOp->IsDone())
564 aSubShapes = new GEOM::ListOfLong();
565 aSubShapes->length(myMain2InPlaceIndices.Extent());
566 TColStd_DataMapIteratorOfDataMapOfIntegerInteger m2ip (myMain2InPlaceIndices);
567 for (int i = 0; m2ip.More(); i++, m2ip.Next())
568 aSubShapes[i] = m2ip.Key();
571 bool isBlocked = myIdList->signalsBlocked();
572 myIdList->blockSignals(true);
574 for (int i = 0, n = aSubShapes->length(); i < n; i++) {
575 CORBA::Long anIndex = aSubShapes[i];
579 QListWidgetItem* anItem = 0;
580 QString text = QString("%1").arg(anIndex);
581 if (!myInPlaceObj->_is_nil()) {
582 QList<QListWidgetItem*> found = myIdList->findItems(text, Qt::MatchExactly);
583 if (found.count()) anItem = found[0];
586 anItem = new QListWidgetItem(text);
587 myIdList->addItem(anItem);
589 anItem->setSelected(true);
592 myIdList->blockSignals(isBlocked);
593 highlightSubShapes();
597 //=================================================================================
598 // function : showOnlySelected
600 //=================================================================================
601 void GroupGUI_GroupDlg::showOnlySelected()
603 if (CORBA::is_nil(myMainObj) || !myIsShapeType)
606 QPushButton* send = (QPushButton*)sender();
607 if (send == myShowAllBtn) {
612 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
613 SALOME_ListIO aSelList;
614 aSelMgr->selectedObjects(aSelList);
616 GEOM_Displayer* aDisplayer = getDisplayer();
618 if (send == myHideSelBtn) {
619 aDisplayer->Erase(aSelList, false, true);
622 aDisplayer->EraseAll();
623 aDisplayer->Display(aSelList, true);
627 //=================================================================================
628 // function : getSelectedSubshapes
630 //=================================================================================
631 int GroupGUI_GroupDlg::getSelectedSubshapes (TColStd_IndexedMapOfInteger& theMapIndex)
635 SalomeApp_Application* app = myGeomGUI->getApp();
636 if (!app || myMainObj->_is_nil())
639 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
640 SALOME_ListIO aSelList;
641 aSelMgr->selectedObjects(aSelList);
643 // try to find out and process the global selection
644 // (of not published objects and of published sub-shapes)
646 SALOME_ListIteratorOfListIO anIter (aSelList);
647 for (int i = 0; anIter.More(); anIter.Next(), i++)
649 Handle(SALOME_InteractiveObject) anIObj = anIter.Value();
650 QString anEntry = anIObj->getEntry();
652 int index = anEntry.lastIndexOf(str);
653 if (index > 0) // selection among special preview
655 anEntry.remove(0, index+1);
656 int anIndex = anEntry.toInt();
658 theMapIndex.Add(anIndex);
660 else // selection among published shapes
662 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>(app->activeStudy());
663 if (!appStudy) return 0;
664 _PTR(Study) aStudy = appStudy->studyDS();
666 _PTR(SObject) aSObj (aStudy->FindObjectID(anEntry.toLatin1().constData()));
667 GEOM::GEOM_Object_var aGeomObj =
668 GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aSObj));
670 if (GEOMBase::GetShape(aGeomObj, aShape)) {
671 if (aGeomObj->GetType() == GEOM_GROUP || aShape.ShapeType() == getShapeType()) {
672 TopTools_IndexedMapOfShape aMainMap;
673 TopoDS_Shape aMainShape = GEOM_Client::get_client().GetShape(GeometryGUI::GetGeomGen(), myMainObj);
674 TopExp::MapShapes(aMainShape, aMainMap);
676 TopExp_Explorer anExp (aShape, getShapeType());
677 for (; anExp.More(); anExp.Next()) {
678 TopoDS_Shape aSubShape = anExp.Current();
679 int anIndex = aMainMap.FindIndex(aSubShape);
681 if (subSelectionWay() != ALL_SUBSHAPES &&
682 !myMain2InPlaceIndices.IsBound(anIndex))
684 theMapIndex.Add(anIndex);
693 return theMapIndex.Extent();
696 //=================================================================================
699 //=================================================================================
700 void GroupGUI_GroupDlg::add()
702 TColStd_IndexedMapOfInteger aMapIndex;
703 int nbSel = getSelectedSubshapes(aMapIndex);
705 TColStd_MapOfInteger aMap;
706 for (int i = 0, n = myIdList->count(); i < n; i++)
707 aMap.Add(myIdList->item(i)->text().toInt());
710 bool isBlocked = myIdList->signalsBlocked();
711 myIdList->blockSignals(true);
713 for (int i = 1, n = aMapIndex.Extent(); i <= n; i++) {
714 if (aMap.Contains(aMapIndex(i)))
717 QListWidgetItem* anItem = new QListWidgetItem(QString("%1").arg(aMapIndex(i)));
718 myIdList->addItem(anItem);
719 anItem->setSelected(true);
722 myIdList->blockSignals(isBlocked);
728 //=================================================================================
731 //=================================================================================
732 void GroupGUI_GroupDlg::remove()
734 bool isBlocked = myIdList->signalsBlocked();
735 myIdList->blockSignals(true);
737 QListIterator<QListWidgetItem*> it (myIdList->selectedItems());
741 myIdList->blockSignals(isBlocked);
743 highlightSubShapes();
746 //=================================================================================
747 //function : subSelectionWay
749 //=================================================================================
750 int GroupGUI_GroupDlg::subSelectionWay() const
752 return myRestrictGroup->checkedId();
755 //=================================================================================
756 // function : getShapeType()
758 //=================================================================================
759 TopAbs_ShapeEnum GroupGUI_GroupDlg::getShapeType() const
761 switch (getConstructorId()) {
762 case 0: return TopAbs_VERTEX;
763 case 1: return TopAbs_EDGE;
764 case 2: return TopAbs_FACE;
765 case 3: return TopAbs_SOLID;
766 default: return TopAbs_SHAPE;
770 //=================================================================================
771 // function : setShapeType()
773 //=================================================================================
774 void GroupGUI_GroupDlg::setShapeType(const TopAbs_ShapeEnum theType)
778 case TopAbs_VERTEX: anId = 0; break;
779 case TopAbs_EDGE: anId = 1; break;
780 case TopAbs_FACE: anId = 2; break;
781 case TopAbs_SOLID: anId = 3; break;
783 setConstructorId(anId);
786 myIsShapeType = true;
787 // workaround to avoid set checked button 0
788 setConstructorId(anId);
792 //=================================================================================
793 // function : activateSelection
794 // purpose : Activate selection in accordance with myEditCurrentArgument
795 //=================================================================================
796 void GroupGUI_GroupDlg::activateSelection()
801 if (!myMainObj->_is_nil() &&
802 !myEditCurrentArgument &&
803 myIsShapeType) // check if shape type is already choosen by user
805 GEOM_Displayer* aDisplayer = getDisplayer();
806 SALOME_View* view = GEOM_Displayer::GetActiveView();
808 CORBA::String_var aMainEntry = myMainObj->GetStudyEntry();
809 Handle(SALOME_InteractiveObject) io = new SALOME_InteractiveObject (aMainEntry.in(), "GEOM", "TEMP_IO");
810 if (view->isVisible(io)) {
811 aDisplayer->Erase(myMainObj, false, false);
812 myIsHiddenMain = true;
816 int prevDisplayMode = aDisplayer->SetDisplayMode(0);
818 SUIT_ViewWindow* aViewWindow = 0;
819 SUIT_Study* activeStudy = SUIT_Session::session()->activeApplication()->activeStudy();
821 aViewWindow = SUIT_Session::session()->activeApplication()->desktop()->activeWindow();
822 if (aViewWindow == 0) return;
824 SUIT_ViewManager* aViewManager = aViewWindow->getViewManager();
825 if (aViewManager->getType() != OCCViewer_Viewer::Type() &&
826 aViewManager->getType() != SVTK_Viewer::Type())
829 SUIT_ViewModel* aViewModel = aViewManager->getViewModel();
830 SALOME_View* aView = dynamic_cast<SALOME_View*>(aViewModel);
831 if (aView == 0) return;
833 TopoDS_Shape aMainShape = GEOM_Client::get_client().GetShape(GeometryGUI::GetGeomGen(), myMainObj);
834 TopoDS_Shape aRestrictionShape;
836 if (subSelectionWay() == ALL_SUBSHAPES) {
837 aRestrictionShape = aMainShape;
839 TopTools_IndexedMapOfShape aSubShapesMap;
840 TopExp::MapShapes(aMainShape, aSubShapesMap);
841 CORBA::String_var aMainEntry = myMainObj->GetStudyEntry();
842 QString anEntryBase = aMainEntry.in();
844 TopExp_Explorer anExp (aRestrictionShape, getShapeType());
845 for (; anExp.More(); anExp.Next()) {
846 TopoDS_Shape aSubShape = anExp.Current();
847 int index = aSubShapesMap.FindIndex(aSubShape);
848 QString anEntry = anEntryBase + QString("_%1").arg(index);
850 SALOME_Prs* aPrs = aDisplayer->buildSubshapePresentation(aSubShape, anEntry, aView);
852 displayPreview(aPrs, true, false); // append, do not update
856 else if (!myInPlaceObj->_is_nil()) {
857 TopTools_IndexedMapOfShape aSubShapesMap;
858 TopExp::MapShapes(aMainShape, aSubShapesMap);
859 CORBA::String_var aMainEntry = myMainObj->GetStudyEntry();
860 QString anEntryBase = aMainEntry.in();
862 TColStd_DataMapIteratorOfDataMapOfIntegerInteger aM2IPit (myMain2InPlaceIndices);
863 for (; aM2IPit.More(); aM2IPit.Next()) {
864 int index = aM2IPit.Key();
865 TopoDS_Shape aSubShape = aSubShapesMap.FindKey(index);
866 QString anEntry = anEntryBase + QString("_%1").arg(index);
868 SALOME_Prs* aPrs = aDisplayer->buildSubshapePresentation(aSubShape, anEntry, aView);
870 displayPreview(aPrs, true, false); // append, do not update
876 aDisplayer->UpdateViewer();
877 aDisplayer->SetDisplayMode(prevDisplayMode);
880 globalSelection(GEOM_ALLSHAPES);
882 SelectionIntoArgument();
885 //=================================================================================
886 // function : updateState
888 //=================================================================================
889 void GroupGUI_GroupDlg::updateState (bool isAdd)
891 myAddBtn->setEnabled(!myEditCurrentArgument && !CORBA::is_nil(myMainObj) && isAdd);
892 //myShowOnlyBtn->setEnabled(!myEditCurrentArgument && !CORBA::is_nil(myMainObj) && isAdd);
894 bool hasSel = myIdList->selectedItems().count() > 0;
896 myRemBtn->setEnabled(hasSel);
897 myRestrictGroupBox->setEnabled(!CORBA::is_nil(myMainObj));
898 mySelAllBtn->setEnabled(!CORBA::is_nil(myMainObj));
900 mySelBtn2->setEnabled(subSelectionWay() != ALL_SUBSHAPES);
901 myShape2Name->setEnabled(subSelectionWay() != ALL_SUBSHAPES);
902 if (subSelectionWay() == ALL_SUBSHAPES)
903 setInPlaceObj(GEOM::GEOM_Object::_nil());
906 //=================================================================================
907 // function : selectionChanged
909 //=================================================================================
910 void GroupGUI_GroupDlg::selectionChanged()
912 highlightSubShapes();
915 //=================================================================================
916 // function : highlightSubShapes
918 //=================================================================================
919 void GroupGUI_GroupDlg::highlightSubShapes()
921 if (CORBA::is_nil(myMainObj))
924 TColStd_MapOfInteger anIds;
928 int ii = 0, nn = myIdList->count();
929 for (; ii < nn; ii++)
931 if (myIdList->item(ii)->isSelected()) {
932 int id = myIdList->item(ii)->text().toInt();
933 if (subSelectionWay() != ALL_SUBSHAPES &&
934 !myMain2InPlaceIndices.IsBound(id)) {
935 //myIdList->item(ii)->setSelected(false);
942 SalomeApp_Application* app = myGeomGUI->getApp();
943 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
944 aSelMgr->clearSelected();
946 SUIT_ViewWindow* aViewWindow = 0;
947 SUIT_Study* activeStudy = app->activeStudy();
949 aViewWindow = app->desktop()->activeWindow();
950 if (aViewWindow == 0) return;
952 SUIT_ViewManager* aViewManager = aViewWindow->getViewManager();
953 if (aViewManager->getType() != OCCViewer_Viewer::Type() &&
954 aViewManager->getType() != SVTK_Viewer::Type())
957 SUIT_ViewModel* aViewModel = aViewManager->getViewModel();
958 SALOME_View* aView = dynamic_cast<SALOME_View*>(aViewModel);
959 if (aView == 0) return;
961 // TODO: use here GEOMBase_Helper::myPreview instead of ic->DisplayedObjects()
963 OCCViewer_Viewer* v3d = ((OCCViewer_ViewManager*)aViewManager)->getOCCViewer();
964 Handle(AIS_InteractiveContext) ic = v3d->getAISContext();
965 AIS_ListOfInteractive List;
966 ic->DisplayedObjects(List);
968 SALOME_ListIO aSelList;
970 // To highlight the selected subshape in Object Browser, if it's already pudlished under the main shape
971 GEOM::GEOM_ILocalOperations_var aLocOp = getGeomEngine()->GetILocalOperations(getStudyId());
972 QMap<int, QString> childsMap;
973 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>(app->activeStudy());
975 _PTR(Study) aStudy = appStudy->studyDS();
976 CORBA::String_var aMainEntry = myMainObj->GetStudyEntry();
977 QString anEntry = aMainEntry.in();
978 _PTR(SObject) aSObj (aStudy->FindObjectID(anEntry.toLatin1().constData()));
979 _PTR(ChildIterator) anIt (aStudy->NewChildIterator(aSObj));
980 for (anIt->InitEx(true); anIt->More(); anIt->Next()) {
981 GEOM::GEOM_Object_var aChild = GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(anIt->Value()));
982 if (!CORBA::is_nil(aChild)) {
983 int index = aLocOp->GetSubShapeIndex(myMainObj, aChild);
984 CORBA::String_var aChildEntry = aChild->GetStudyEntry();
985 QString anEntry = aChildEntry.in();
986 childsMap.insert(index, anEntry);
991 AIS_ListIteratorOfListOfInteractive ite (List);
992 for (; ite.More(); ite.Next()) {
993 if (ite.Value()->IsInstance(STANDARD_TYPE(GEOM_AISShape))) {
994 Handle(GEOM_AISShape) aSh = Handle(GEOM_AISShape)::DownCast(ite.Value());
996 Handle(SALOME_InteractiveObject) anIO = aSh->getIO();
997 QString anEntry = anIO->getEntry();
998 int index = anEntry.lastIndexOf("_");
999 anEntry.remove(0, index+1);
1000 int anIndex = anEntry.toInt();
1001 if (anIds.Contains(anIndex)) {
1002 aSelList.Append(anIO);
1003 if (childsMap.contains (anIndex)) {
1004 Handle(SALOME_InteractiveObject) tmpIO = new SALOME_InteractiveObject(childsMap.value(anIndex).toLatin1().constData(), "GEOM", "TEMP_IO");
1005 aSelList.Append(tmpIO);
1011 aSelMgr->setSelectedObjects(aSelList);
1016 updateState(aSelList.Extent() > 0);
1018 myAddBtn->setEnabled(true);
1019 myAddBtn->setEnabled(true);
1020 myRemBtn->setEnabled(true);
1024 //=================================================================================
1025 // function : createOperation
1027 //=================================================================================
1028 GEOM::GEOM_IOperations_ptr GroupGUI_GroupDlg::createOperation()
1030 return getGeomEngine()->GetIGroupOperations(getStudyId());
1033 #define RETURN_WITH_MSG(a, b) \
1035 theMessage += (b); \
1039 //=================================================================================
1040 // function : isValid()
1041 // purpose : Verify validity of input data
1042 //=================================================================================
1043 bool GroupGUI_GroupDlg::isValid(QString& theMessage)
1045 SalomeApp_Study* study = getStudy();
1047 RETURN_WITH_MSG (!study->studyDS()->GetProperties()->IsLocked(), tr("GEOM_STUDY_LOCKED"))
1049 if (myMode == CreateGroup) {
1050 RETURN_WITH_MSG(!CORBA::is_nil(myMainObj), tr("NO_MAIN_OBJ"))
1053 RETURN_WITH_MSG(!CORBA::is_nil(myMainObj), tr("NO_GROUP"))
1056 QString aName (getNewObjectName());
1057 RETURN_WITH_MSG (!aName.trimmed().isEmpty(), tr("EMPTY_NAME"))
1059 RETURN_WITH_MSG (myIdList->count(), tr("EMPTY_LIST"))
1063 //=================================================================================
1064 // function : execute
1066 //=================================================================================
1067 bool GroupGUI_GroupDlg::execute(ObjectList& objects)
1069 GEOM::GEOM_IGroupOperations_var anOper = GEOM::GEOM_IGroupOperations::_narrow(getOperation());
1071 GEOM::GEOM_Object_var aGroup;
1072 if (myMode == CreateGroup)
1073 aGroup = anOper->CreateGroup(myMainObj, getShapeType());
1074 else if (myMode == EditGroup)
1077 if (CORBA::is_nil(aGroup) || (myMode == CreateGroup && !anOper->IsDone()))
1080 GEOM::ListOfLong_var aCurrList = anOper->GetObjects(aGroup);
1081 if (!anOper->IsDone())
1084 if (aCurrList->length() > 0)
1086 anOper->DifferenceIDs(aGroup, aCurrList);
1087 if (!anOper->IsDone())
1091 int ii, nn = myIdList->count();
1094 GEOM::ListOfLong_var aNewList = new GEOM::ListOfLong;
1095 aNewList->length(nn);
1096 for (ii = 0; ii < nn; ii++) {
1097 aNewList[ii] = myIdList->item(ii)->text().toInt();
1099 anOper->UnionIDs(aGroup, aNewList);
1100 if (!anOper->IsDone())
1104 SalomeApp_Study* study = getStudy();
1106 QString objIOR = GEOMBase::GetIORFromObject(aGroup);
1108 _PTR(SObject) SO (study->studyDS()->FindObjectIOR(objIOR.toLatin1().constData()));
1110 _PTR(StudyBuilder) aBuilder (study->studyDS()->NewBuilder());
1111 aBuilder->SetName(SO, getNewObjectName().toLatin1().constData());
1116 objects.push_back(aGroup._retn());
1121 //================================================================
1122 // Function : getFather
1123 // Purpose : Get father object for object to be added in study
1124 // (called with addInStudy method)
1125 //================================================================
1126 GEOM::GEOM_Object_ptr GroupGUI_GroupDlg::getFather(GEOM::GEOM_Object_ptr theObj)
1128 GEOM::GEOM_Object_var aFatherObj;
1129 if (theObj->GetType() == GEOM_GROUP) {
1130 GEOM::GEOM_IGroupOperations_var anOper = GEOM::GEOM_IGroupOperations::_narrow(getOperation());
1131 aFatherObj = anOper->GetMainShape(theObj);
1133 return aFatherObj._retn();