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");
186 GroupGUI_GroupDlg::~GroupGUI_GroupDlg()
188 if (myIsHiddenMain) {
189 GEOM_Displayer* aDisplayer = getDisplayer();
190 aDisplayer->Display(myMainObj);
191 myIsHiddenMain = false;
195 //=================================================================================
198 //=================================================================================
199 void GroupGUI_GroupDlg::Init()
201 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
203 //unset shape type to avoid preparation of selection before exact user shape type selection
204 unsetConstructorId();
205 myIsShapeType = false;
207 if (myMode == CreateGroup) {
208 initName(tr("GROUP_PREFIX"));
210 // Get ready for main shape selection
211 myEditCurrentArgument = myMainName;
213 connect(this, SIGNAL(constructorsClicked(int)), this, SLOT(ConstructorsClicked(int)));
214 connect(mySelBtn, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
215 connect(mySelBtn2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
217 else if (myMode == EditGroup) {
218 SALOME_ListIO aSelList;
219 aSelMgr->selectedObjects(aSelList);
221 if (aSelList.Extent()) {
222 GEOM::GEOM_Object_var anObj =
223 GEOMBase::ConvertIOinGEOMObject(aSelList.First());
225 if (!CORBA::is_nil(anObj) && anObj->GetType() == GEOM_GROUP) {
228 mainFrame()->ResultName->setText(GEOMBase::GetName(myGroup));
230 GEOM::GEOM_IGroupOperations_var anOper = GEOM::GEOM_IGroupOperations::_narrow(getOperation());
231 myMainObj = anOper->GetMainShape(myGroup);
232 if (!CORBA::is_nil(myMainObj))
233 myMainName->setText(GEOMBase::GetName(myMainObj));
235 setShapeType((TopAbs_ShapeEnum)anOper->GetType(myGroup));
237 GEOM::ListOfLong_var aCurrList = anOper->GetObjects(myGroup);
238 for (int i = 0, n = aCurrList->length(); i < n; i++)
239 myIdList->addItem(new QListWidgetItem(QString("%1").arg(aCurrList[i])));
241 myEditCurrentArgument = 0;
243 connect(mySelBtn2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
247 connect(aSelMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
249 connect(buttonOk(), SIGNAL(clicked()), this, SLOT(ClickOnOk()));
250 connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
252 connect(myRestrictGroup, SIGNAL(buttonClicked(int)), this, SLOT(SetEditCurrentArgument()));
253 connect(mySelAllBtn, SIGNAL(clicked()), this, SLOT(selectAllSubShapes()));
254 connect(myAddBtn, SIGNAL(clicked()), this, SLOT(add()));
255 connect(myRemBtn, SIGNAL(clicked()), this, SLOT(remove()));
256 connect(myShowOnlyBtn, SIGNAL(clicked()), this, SLOT(showOnlySelected()));
257 connect(myHideSelBtn, SIGNAL(clicked()), this, SLOT(showOnlySelected()));
258 connect(myShowAllBtn, SIGNAL(clicked()), this, SLOT(showOnlySelected()));
259 connect(myIdList, SIGNAL(itemSelectionChanged()), this, SLOT(selectionChanged()));
261 setInPlaceObj(GEOM::GEOM_Object::_nil());
263 myBusy = true; // just activate but do not select in the list
268 //=================================================================================
269 // function : enterEvent()
271 //=================================================================================
272 void GroupGUI_GroupDlg::enterEvent(QEvent* e)
274 if (!buttonCancel()->isEnabled())
275 ActivateThisDialog();
278 //=================================================================================
279 //function : closeEvent
280 //purpose : remove temporary geom object
281 //=================================================================================
282 void GroupGUI_GroupDlg::closeEvent(QCloseEvent* e)
284 setInPlaceObj(GEOM::GEOM_Object::_nil());
287 GEOMBase_Skeleton::closeEvent(e);
290 //=================================================================================
291 // function : ClickOnOk()
293 //=================================================================================
294 void GroupGUI_GroupDlg::ClickOnOk()
296 setIsApplyAndClose(true);
301 //=================================================================================
302 // function : ClickOnApply()
304 //=================================================================================
305 bool GroupGUI_GroupDlg::ClickOnApply()
307 if (!onAccept(myMode == CreateGroup, true))
310 if (myMode == CreateGroup)
314 ConstructorsClicked(getConstructorId());
322 //=================================================================================
323 // function : ActivateThisDialog()
325 //=================================================================================
326 void GroupGUI_GroupDlg::ActivateThisDialog()
328 GEOMBase_Skeleton::ActivateThisDialog();
330 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
331 this, SLOT(SelectionIntoArgument()));
336 //=================================================================================
337 // function : SetEditCurrentArgument()
339 //=================================================================================
340 void GroupGUI_GroupDlg::SetEditCurrentArgument()
342 QPushButton* send = (QPushButton*)sender();
344 if (send == mySelBtn) {
345 myEditCurrentArgument = myMainName;
346 myShape2Name->setText("");
348 else if (send == mySelBtn2 || sender() == myRestrictGroup) {
349 setInPlaceObj(GEOM::GEOM_Object::_nil());
350 myShape2Name->setText("");
351 if (subSelectionWay() != ALL_SUBSHAPES) {
352 myEditCurrentArgument = myShape2Name;
355 myEditCurrentArgument = 0;
364 //=================================================================================
365 // function : onGetInPlace()
367 //=================================================================================
368 void GroupGUI_GroupDlg::onGetInPlace()
370 setInPlaceObj(GEOM::GEOM_Object::_nil());
371 myEditCurrentArgument->setText("");
373 bool isBlocked = myIdList->signalsBlocked();
374 myIdList->blockSignals(true);
375 myIdList->clearSelection();
376 myIdList->blockSignals(isBlocked);
378 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
379 SALOME_ListIO aSelList;
380 aSelMgr->selectedObjects(aSelList);
382 if (aSelList.Extent() != 1)
385 GEOM::GEOM_Object_var anObj =
386 GEOMBase::ConvertIOinGEOMObject(aSelList.First());
387 if (GEOMBase::IsShape(anObj)) {
388 if (!anObj->_is_equivalent(myMainObj) && !anObj->_is_equivalent(myGroup)) {
389 SUIT_OverrideCursor wc;
390 myEditCurrentArgument->setText(GEOMBase::GetName(anObj));
391 GEOM::GEOM_IShapesOperations_var aShapesOp =
392 getGeomEngine()->GetIShapesOperations(getStudyId());
393 if (subSelectionWay() == GET_IN_PLACE) {
394 GEOM::GEOM_Object_var aGetInPlaceObj = aShapesOp->GetInPlace(myMainObj, anObj);
395 setInPlaceObj(aGetInPlaceObj);
398 bool isVisible = true;
399 if (SALOME_View* view = GEOM_Displayer::GetActiveView())
400 isVisible = view->isVisible(aSelList.First());
401 setInPlaceObj(anObj, isVisible);
403 myEditCurrentArgument = 0;
404 //myBusy = true; // just activate but do not select in the list
411 //=================================================================================
412 //function : setInPlaceObj
413 //purpose : temporarily add an object to study and remove old InPlaceObj
414 //=================================================================================
415 void GroupGUI_GroupDlg::setInPlaceObj(GEOM::GEOM_Object_var theObj, const bool isVisible)
417 if (!myInPlaceObj->_is_equivalent(theObj))
419 myInPlaceObj = theObj;
422 // build map of indices
423 myMain2InPlaceIndices.Clear();
424 if (!myInPlaceObj->_is_nil()) {
425 GEOM::GEOM_IShapesOperations_var aShapesOp = getGeomEngine()->GetIShapesOperations(getStudyId());
426 GEOM::GEOM_ILocalOperations_var aLocOp = getGeomEngine()->GetILocalOperations(getStudyId());
428 GEOM::ListOfGO_var aSubObjects = aShapesOp->MakeExplode(myInPlaceObj, getShapeType(), false);
429 for (int i = 0; i < aSubObjects->length(); i++)
431 GEOM::GEOM_Object_var aSS = aShapesOp->GetSame(myMainObj, aSubObjects[i]);
432 if (!CORBA::is_nil(aSS)) {
433 CORBA::Long aMainIndex = aLocOp->GetSubShapeIndex(myMainObj, aSS);
434 CORBA::Long aPlaceIndex = aLocOp->GetSubShapeIndex(myInPlaceObj, aSubObjects[i]);
435 if (aMainIndex >= 0 && aPlaceIndex > 0)
436 myMain2InPlaceIndices.Bind(aMainIndex, aPlaceIndex);
440 myInPlaceObjSelectState = subSelectionWay();
441 if (myInPlaceObjSelectState == SUBSHAPES_OF_SHAPE2 && !isVisible)
442 myInPlaceObjSelectState = SUBSHAPES_OF_INVISIBLE_SHAPE2;
445 //=================================================================================
446 // function : SelectionIntoArgument()
447 // purpose : Called when selection has changed
448 //=================================================================================
449 void GroupGUI_GroupDlg::SelectionIntoArgument()
451 if (subSelectionWay() != ALL_SUBSHAPES && myEditCurrentArgument == myShape2Name) {
456 if (myEditCurrentArgument == myMainName) { // Selection of a main shape is active
457 myEditCurrentArgument->setText("");
460 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
461 SALOME_ListIO aSelList;
462 aSelMgr->selectedObjects(aSelList);
463 int nbSel = aSelList.Extent();
466 GEOM::GEOM_Object_var anObj =
467 GEOMBase::ConvertIOinGEOMObject(aSelList.First());
469 if (GEOMBase::IsShape(anObj)) {
470 if (myIsHiddenMain) {
471 GEOM_Displayer* aDisplayer = getDisplayer();
472 aDisplayer->Display(myMainObj);
473 myIsHiddenMain = false;
476 myEditCurrentArgument->setText(GEOMBase::GetName(anObj));
477 // activate subshapes selection by default
478 myEditCurrentArgument = 0;
484 if (myIsHiddenMain) {
485 GEOM_Displayer* aDisplayer = getDisplayer();
486 aDisplayer->Display(myMainObj);
487 myIsHiddenMain = false;
489 myMainObj = GEOM::GEOM_Object::_nil();
492 else { // an attempt to synchronize list box selection with 3d viewer
493 if (myBusy || myMainObj->_is_nil()) {
497 bool isBlocked = myIdList->signalsBlocked();
498 myIdList->blockSignals(true);
499 myIdList->clearSelection();
501 TColStd_IndexedMapOfInteger aMapIndex;
502 int nbSel = getSelectedSubshapes(aMapIndex);
506 for (int i = 0, n = myIdList->count(); i < n; i++)
507 aMap.insert(myIdList->item(i)->text().toInt(), i);
509 bool highlight = false;
510 for (int ii = 1, nn = aMapIndex.Extent(); ii <= nn; ii++) {
511 if (aMap.contains(aMapIndex(ii))) {
512 myIdList->item(aMap[aMapIndex(ii)])->setSelected(true);
517 highlightSubShapes();
519 myIdList->blockSignals(isBlocked);
525 //=================================================================================
526 // function : ConstructorsClicked()
527 // purpose : Radio button management
528 //=================================================================================
529 void GroupGUI_GroupDlg::ConstructorsClicked(int constructorId)
531 if (getConstructorId() != constructorId)
532 setConstructorId(constructorId);
534 myIsShapeType = true;
536 myEditCurrentArgument = 0;
538 setInPlaceObj(myInPlaceObj); // to rebuild myMain2InPlaceIndices
543 //=================================================================================
544 // function : selectAllSubShapes
546 //=================================================================================
547 void GroupGUI_GroupDlg::selectAllSubShapes()
549 if (CORBA::is_nil(myMainObj) || !myIsShapeType)
552 GEOM::ListOfLong_var aSubShapes;
553 GEOM::GEOM_IShapesOperations_var aShOp = getGeomEngine()->GetIShapesOperations(getStudyId());
554 aSubShapes = aShOp->SubShapeAllIDs(myMainObj, getShapeType(), false);
555 if (aSubShapes->length() > 0) {
556 if (subSelectionWay() == ALL_SUBSHAPES)
558 myIdList->clear(); // for sorted final list?
560 if (!aShOp->IsDone())
565 aSubShapes = new GEOM::ListOfLong();
566 aSubShapes->length(myMain2InPlaceIndices.Extent());
567 TColStd_DataMapIteratorOfDataMapOfIntegerInteger m2ip (myMain2InPlaceIndices);
568 for (int i = 0; m2ip.More(); i++, m2ip.Next())
569 aSubShapes[i] = m2ip.Key();
572 bool isBlocked = myIdList->signalsBlocked();
573 myIdList->blockSignals(true);
575 for (int i = 0, n = aSubShapes->length(); i < n; i++) {
576 CORBA::Long anIndex = aSubShapes[i];
580 QListWidgetItem* anItem = 0;
581 QString text = QString("%1").arg(anIndex);
582 if (!myInPlaceObj->_is_nil()) {
583 QList<QListWidgetItem*> found = myIdList->findItems(text, Qt::MatchExactly);
584 if (found.count()) anItem = found[0];
587 anItem = new QListWidgetItem(text);
588 myIdList->addItem(anItem);
590 anItem->setSelected(true);
593 myIdList->blockSignals(isBlocked);
594 highlightSubShapes();
598 //=================================================================================
599 // function : showOnlySelected
601 //=================================================================================
602 void GroupGUI_GroupDlg::showOnlySelected()
604 if (CORBA::is_nil(myMainObj) || !myIsShapeType)
607 QPushButton* send = (QPushButton*)sender();
608 if (send == myShowAllBtn) {
613 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
614 SALOME_ListIO aSelList;
615 aSelMgr->selectedObjects(aSelList);
617 GEOM_Displayer* aDisplayer = getDisplayer();
619 if (send == myHideSelBtn) {
620 aDisplayer->Erase(aSelList, false, true);
623 aDisplayer->EraseAll();
624 aDisplayer->Display(aSelList, true);
628 //=================================================================================
629 // function : getSelectedSubshapes
631 //=================================================================================
632 int GroupGUI_GroupDlg::getSelectedSubshapes (TColStd_IndexedMapOfInteger& theMapIndex)
636 SalomeApp_Application* app = myGeomGUI->getApp();
637 if (!app || myMainObj->_is_nil())
640 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
641 SALOME_ListIO aSelList;
642 aSelMgr->selectedObjects(aSelList);
644 // try to find out and process the global selection
645 // (of not published objects and of published sub-shapes)
647 SALOME_ListIteratorOfListIO anIter (aSelList);
648 for (int i = 0; anIter.More(); anIter.Next(), i++)
650 Handle(SALOME_InteractiveObject) anIObj = anIter.Value();
651 QString anEntry = anIObj->getEntry();
653 int index = anEntry.lastIndexOf(str);
654 if (index > 0) // selection among special preview
656 anEntry.remove(0, index+1);
657 int anIndex = anEntry.toInt();
659 theMapIndex.Add(anIndex);
661 else // selection among published shapes
663 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>(app->activeStudy());
664 if (!appStudy) return 0;
665 _PTR(Study) aStudy = appStudy->studyDS();
667 _PTR(SObject) aSObj (aStudy->FindObjectID(anEntry.toLatin1().constData()));
668 GEOM::GEOM_Object_var aGeomObj =
669 GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aSObj));
671 if (GEOMBase::GetShape(aGeomObj, aShape)) {
672 if (aGeomObj->GetType() == GEOM_GROUP || aShape.ShapeType() == getShapeType()) {
673 TopTools_IndexedMapOfShape aMainMap;
674 TopoDS_Shape aMainShape = GEOM_Client::get_client().GetShape(GeometryGUI::GetGeomGen(), myMainObj);
675 TopExp::MapShapes(aMainShape, aMainMap);
677 TopExp_Explorer anExp (aShape, getShapeType());
678 for (; anExp.More(); anExp.Next()) {
679 TopoDS_Shape aSubShape = anExp.Current();
680 int anIndex = aMainMap.FindIndex(aSubShape);
682 if (subSelectionWay() != ALL_SUBSHAPES &&
683 !myMain2InPlaceIndices.IsBound(anIndex))
685 theMapIndex.Add(anIndex);
694 return theMapIndex.Extent();
697 //=================================================================================
700 //=================================================================================
701 void GroupGUI_GroupDlg::add()
703 TColStd_IndexedMapOfInteger aMapIndex;
704 int nbSel = getSelectedSubshapes(aMapIndex);
706 TColStd_MapOfInteger aMap;
707 for (int i = 0, n = myIdList->count(); i < n; i++)
708 aMap.Add(myIdList->item(i)->text().toInt());
711 bool isBlocked = myIdList->signalsBlocked();
712 myIdList->blockSignals(true);
714 for (int i = 1, n = aMapIndex.Extent(); i <= n; i++) {
715 if (aMap.Contains(aMapIndex(i)))
718 QListWidgetItem* anItem = new QListWidgetItem(QString("%1").arg(aMapIndex(i)));
719 myIdList->addItem(anItem);
720 anItem->setSelected(true);
723 myIdList->blockSignals(isBlocked);
729 //=================================================================================
732 //=================================================================================
733 void GroupGUI_GroupDlg::remove()
735 bool isBlocked = myIdList->signalsBlocked();
736 myIdList->blockSignals(true);
738 QListIterator<QListWidgetItem*> it (myIdList->selectedItems());
742 myIdList->blockSignals(isBlocked);
744 highlightSubShapes();
747 //=================================================================================
748 //function : subSelectionWay
750 //=================================================================================
751 int GroupGUI_GroupDlg::subSelectionWay() const
753 return myRestrictGroup->checkedId();
756 //=================================================================================
757 // function : getShapeType()
759 //=================================================================================
760 TopAbs_ShapeEnum GroupGUI_GroupDlg::getShapeType() const
762 switch (getConstructorId()) {
763 case 0: return TopAbs_VERTEX;
764 case 1: return TopAbs_EDGE;
765 case 2: return TopAbs_FACE;
766 case 3: return TopAbs_SOLID;
767 default: return TopAbs_SHAPE;
771 //=================================================================================
772 // function : setShapeType()
774 //=================================================================================
775 void GroupGUI_GroupDlg::setShapeType(const TopAbs_ShapeEnum theType)
779 case TopAbs_VERTEX: anId = 0; break;
780 case TopAbs_EDGE: anId = 1; break;
781 case TopAbs_FACE: anId = 2; break;
782 case TopAbs_SOLID: anId = 3; break;
784 setConstructorId(anId);
787 myIsShapeType = true;
788 // workaround to avoid set checked button 0
789 setConstructorId(anId);
793 //=================================================================================
794 // function : activateSelection
795 // purpose : Activate selection in accordance with myEditCurrentArgument
796 //=================================================================================
797 void GroupGUI_GroupDlg::activateSelection()
802 if (!myMainObj->_is_nil() &&
803 !myEditCurrentArgument &&
804 myIsShapeType) // check if shape type is already choosen by user
806 GEOM_Displayer* aDisplayer = getDisplayer();
807 SALOME_View* view = GEOM_Displayer::GetActiveView();
809 CORBA::String_var aMainEntry = myMainObj->GetStudyEntry();
810 Handle(SALOME_InteractiveObject) io = new SALOME_InteractiveObject (aMainEntry.in(), "GEOM", "TEMP_IO");
811 if (view->isVisible(io)) {
812 aDisplayer->Erase(myMainObj, false, false);
813 myIsHiddenMain = true;
817 int prevDisplayMode = aDisplayer->SetDisplayMode(0);
819 SUIT_ViewWindow* aViewWindow = 0;
820 SUIT_Study* activeStudy = SUIT_Session::session()->activeApplication()->activeStudy();
822 aViewWindow = SUIT_Session::session()->activeApplication()->desktop()->activeWindow();
823 if (aViewWindow == 0) return;
825 SUIT_ViewManager* aViewManager = aViewWindow->getViewManager();
826 if (aViewManager->getType() != OCCViewer_Viewer::Type() &&
827 aViewManager->getType() != SVTK_Viewer::Type())
830 SUIT_ViewModel* aViewModel = aViewManager->getViewModel();
831 SALOME_View* aView = dynamic_cast<SALOME_View*>(aViewModel);
832 if (aView == 0) return;
834 TopoDS_Shape aMainShape = GEOM_Client::get_client().GetShape(GeometryGUI::GetGeomGen(), myMainObj);
835 TopoDS_Shape aRestrictionShape;
837 if (subSelectionWay() == ALL_SUBSHAPES) {
838 aRestrictionShape = aMainShape;
840 TopTools_IndexedMapOfShape aSubShapesMap;
841 TopExp::MapShapes(aMainShape, aSubShapesMap);
842 CORBA::String_var aMainEntry = myMainObj->GetStudyEntry();
843 QString anEntryBase = aMainEntry.in();
845 TopExp_Explorer anExp (aRestrictionShape, getShapeType());
846 for (; anExp.More(); anExp.Next()) {
847 TopoDS_Shape aSubShape = anExp.Current();
848 int index = aSubShapesMap.FindIndex(aSubShape);
849 QString anEntry = anEntryBase + QString("_%1").arg(index);
851 SALOME_Prs* aPrs = aDisplayer->buildSubshapePresentation(aSubShape, anEntry, aView);
853 displayPreview(aPrs, true, false); // append, do not update
857 else if (!myInPlaceObj->_is_nil()) {
858 TopTools_IndexedMapOfShape aSubShapesMap;
859 TopExp::MapShapes(aMainShape, aSubShapesMap);
860 CORBA::String_var aMainEntry = myMainObj->GetStudyEntry();
861 QString anEntryBase = aMainEntry.in();
863 TColStd_DataMapIteratorOfDataMapOfIntegerInteger aM2IPit (myMain2InPlaceIndices);
864 for (; aM2IPit.More(); aM2IPit.Next()) {
865 int index = aM2IPit.Key();
866 TopoDS_Shape aSubShape = aSubShapesMap.FindKey(index);
867 QString anEntry = anEntryBase + QString("_%1").arg(index);
869 SALOME_Prs* aPrs = aDisplayer->buildSubshapePresentation(aSubShape, anEntry, aView);
871 displayPreview(aPrs, true, false); // append, do not update
877 aDisplayer->UpdateViewer();
878 aDisplayer->SetDisplayMode(prevDisplayMode);
881 globalSelection(GEOM_ALLSHAPES);
883 SelectionIntoArgument();
886 //=================================================================================
887 // function : updateState
889 //=================================================================================
890 void GroupGUI_GroupDlg::updateState (bool isAdd)
892 myAddBtn->setEnabled(!myEditCurrentArgument && !CORBA::is_nil(myMainObj) && isAdd);
893 //myShowOnlyBtn->setEnabled(!myEditCurrentArgument && !CORBA::is_nil(myMainObj) && isAdd);
895 bool hasSel = myIdList->selectedItems().count() > 0;
897 myRemBtn->setEnabled(hasSel);
898 myRestrictGroupBox->setEnabled(!CORBA::is_nil(myMainObj));
899 mySelAllBtn->setEnabled(!CORBA::is_nil(myMainObj));
901 mySelBtn2->setEnabled(subSelectionWay() != ALL_SUBSHAPES);
902 myShape2Name->setEnabled(subSelectionWay() != ALL_SUBSHAPES);
903 if (subSelectionWay() == ALL_SUBSHAPES)
904 setInPlaceObj(GEOM::GEOM_Object::_nil());
907 //=================================================================================
908 // function : selectionChanged
910 //=================================================================================
911 void GroupGUI_GroupDlg::selectionChanged()
913 highlightSubShapes();
916 //=================================================================================
917 // function : highlightSubShapes
919 //=================================================================================
920 void GroupGUI_GroupDlg::highlightSubShapes()
922 if (CORBA::is_nil(myMainObj))
925 TColStd_MapOfInteger anIds;
929 int ii = 0, nn = myIdList->count();
930 for (; ii < nn; ii++)
932 if (myIdList->item(ii)->isSelected()) {
933 int id = myIdList->item(ii)->text().toInt();
934 if (subSelectionWay() != ALL_SUBSHAPES &&
935 !myMain2InPlaceIndices.IsBound(id)) {
936 //myIdList->item(ii)->setSelected(false);
943 SalomeApp_Application* app = myGeomGUI->getApp();
944 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
945 aSelMgr->clearSelected();
947 SUIT_ViewWindow* aViewWindow = 0;
948 SUIT_Study* activeStudy = app->activeStudy();
950 aViewWindow = app->desktop()->activeWindow();
951 if (aViewWindow == 0) return;
953 SUIT_ViewManager* aViewManager = aViewWindow->getViewManager();
954 if (aViewManager->getType() != OCCViewer_Viewer::Type() &&
955 aViewManager->getType() != SVTK_Viewer::Type())
958 SUIT_ViewModel* aViewModel = aViewManager->getViewModel();
959 SALOME_View* aView = dynamic_cast<SALOME_View*>(aViewModel);
960 if (aView == 0) return;
962 // TODO: use here GEOMBase_Helper::myPreview instead of ic->DisplayedObjects()
964 OCCViewer_Viewer* v3d = ((OCCViewer_ViewManager*)aViewManager)->getOCCViewer();
965 Handle(AIS_InteractiveContext) ic = v3d->getAISContext();
966 AIS_ListOfInteractive List;
967 ic->DisplayedObjects(List);
969 SALOME_ListIO aSelList;
971 // To highlight the selected subshape in Object Browser, if it's already pudlished under the main shape
972 GEOM::GEOM_ILocalOperations_var aLocOp = getGeomEngine()->GetILocalOperations(getStudyId());
973 QMap<int, QString> childsMap;
974 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>(app->activeStudy());
976 _PTR(Study) aStudy = appStudy->studyDS();
977 CORBA::String_var aMainEntry = myMainObj->GetStudyEntry();
978 QString anEntry = aMainEntry.in();
979 _PTR(SObject) aSObj (aStudy->FindObjectID(anEntry.toLatin1().constData()));
980 _PTR(ChildIterator) anIt (aStudy->NewChildIterator(aSObj));
981 for (anIt->InitEx(true); anIt->More(); anIt->Next()) {
982 GEOM::GEOM_Object_var aChild = GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(anIt->Value()));
983 if (!CORBA::is_nil(aChild)) {
984 int index = aLocOp->GetSubShapeIndex(myMainObj, aChild);
985 CORBA::String_var aChildEntry = aChild->GetStudyEntry();
986 QString anEntry = aChildEntry.in();
987 childsMap.insert(index, anEntry);
992 AIS_ListIteratorOfListOfInteractive ite (List);
993 for (; ite.More(); ite.Next()) {
994 if (ite.Value()->IsInstance(STANDARD_TYPE(GEOM_AISShape))) {
995 Handle(GEOM_AISShape) aSh = Handle(GEOM_AISShape)::DownCast(ite.Value());
997 Handle(SALOME_InteractiveObject) anIO = aSh->getIO();
998 QString anEntry = anIO->getEntry();
999 int index = anEntry.lastIndexOf("_");
1000 anEntry.remove(0, index+1);
1001 int anIndex = anEntry.toInt();
1002 if (anIds.Contains(anIndex)) {
1003 aSelList.Append(anIO);
1004 if (childsMap.contains (anIndex)) {
1005 Handle(SALOME_InteractiveObject) tmpIO = new SALOME_InteractiveObject(childsMap.value(anIndex).toLatin1().constData(), "GEOM", "TEMP_IO");
1006 aSelList.Append(tmpIO);
1012 aSelMgr->setSelectedObjects(aSelList);
1017 updateState(aSelList.Extent() > 0);
1019 myAddBtn->setEnabled(true);
1020 myAddBtn->setEnabled(true);
1021 myRemBtn->setEnabled(true);
1025 //=================================================================================
1026 // function : createOperation
1028 //=================================================================================
1029 GEOM::GEOM_IOperations_ptr GroupGUI_GroupDlg::createOperation()
1031 return getGeomEngine()->GetIGroupOperations(getStudyId());
1034 #define RETURN_WITH_MSG(a, b) \
1036 theMessage += (b); \
1040 //=================================================================================
1041 // function : isValid()
1042 // purpose : Verify validity of input data
1043 //=================================================================================
1044 bool GroupGUI_GroupDlg::isValid(QString& theMessage)
1046 SalomeApp_Study* study = getStudy();
1048 RETURN_WITH_MSG (!study->studyDS()->GetProperties()->IsLocked(), tr("GEOM_STUDY_LOCKED"))
1050 if (myMode == CreateGroup) {
1051 RETURN_WITH_MSG(!CORBA::is_nil(myMainObj), tr("NO_MAIN_OBJ"))
1054 RETURN_WITH_MSG(!CORBA::is_nil(myMainObj), tr("NO_GROUP"))
1057 QString aName (getNewObjectName());
1058 RETURN_WITH_MSG (!aName.trimmed().isEmpty(), tr("EMPTY_NAME"))
1060 RETURN_WITH_MSG (myIdList->count(), tr("EMPTY_LIST"))
1064 //=================================================================================
1065 // function : execute
1067 //=================================================================================
1068 bool GroupGUI_GroupDlg::execute(ObjectList& objects)
1070 GEOM::GEOM_IGroupOperations_var anOper = GEOM::GEOM_IGroupOperations::_narrow(getOperation());
1072 GEOM::GEOM_Object_var aGroup;
1073 if (myMode == CreateGroup)
1074 aGroup = anOper->CreateGroup(myMainObj, getShapeType());
1075 else if (myMode == EditGroup)
1078 if (CORBA::is_nil(aGroup) || (myMode == CreateGroup && !anOper->IsDone()))
1081 GEOM::ListOfLong_var aCurrList = anOper->GetObjects(aGroup);
1082 if (!anOper->IsDone())
1085 if (aCurrList->length() > 0)
1087 anOper->DifferenceIDs(aGroup, aCurrList);
1088 if (!anOper->IsDone())
1092 int ii, nn = myIdList->count();
1095 GEOM::ListOfLong_var aNewList = new GEOM::ListOfLong;
1096 aNewList->length(nn);
1097 for (ii = 0; ii < nn; ii++) {
1098 aNewList[ii] = myIdList->item(ii)->text().toInt();
1100 anOper->UnionIDs(aGroup, aNewList);
1101 if (!anOper->IsDone())
1105 SalomeApp_Study* study = getStudy();
1107 QString objIOR = GEOMBase::GetIORFromObject(aGroup);
1109 _PTR(SObject) SO (study->studyDS()->FindObjectIOR(objIOR.toLatin1().constData()));
1111 _PTR(StudyBuilder) aBuilder (study->studyDS()->NewBuilder());
1112 aBuilder->SetName(SO, getNewObjectName().toLatin1().constData());
1117 objects.push_back(aGroup._retn());
1122 //================================================================
1123 // Function : getFather
1124 // Purpose : Get father object for object to be added in study
1125 // (called with addInStudy method)
1126 //================================================================
1127 GEOM::GEOM_Object_ptr GroupGUI_GroupDlg::getFather(GEOM::GEOM_Object_ptr theObj)
1129 GEOM::GEOM_Object_var aFatherObj;
1130 if (theObj->GetType() == GEOM_GROUP) {
1131 GEOM::GEOM_IGroupOperations_var anOper = GEOM::GEOM_IGroupOperations::_narrow(getOperation());
1132 aFatherObj = anOper->GetMainShape(theObj);
1134 return aFatherObj._retn();