1 // Copyright (C) 2007-2010 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
23 // GEOM GEOMGUI : GUI for Geometry component
24 // File : GroupGUI_GroupDlg.cxx
25 // Author : Sergey ANIKIN, Open CASCADE S.A.S. (sergey.anikin@opencascade.com)
27 #include "GroupGUI_GroupDlg.h"
31 #include <GeometryGUI.h>
32 #include <GEOM_Displayer.h>
34 #include <SalomeApp_Application.h>
35 #include <SalomeApp_Study.h>
37 #include <LightApp_SelectionMgr.h>
39 #include <OCCViewer_ViewModel.h>
40 #include <OCCViewer_ViewManager.h>
41 #include <SVTK_ViewModel.h>
42 #include <SALOME_Prs.h>
43 #include <SALOME_ListIteratorOfListIO.hxx>
45 #include <SUIT_ResourceMgr.h>
46 #include <SUIT_Desktop.h>
47 #include <SUIT_OverrideCursor.h>
48 #include <SUIT_Session.h>
49 #include <SUIT_ViewWindow.h>
50 #include <SUIT_ViewManager.h>
53 #include <QListWidget>
57 #include <AIS_ListOfInteractive.hxx>
58 #include <AIS_ListIteratorOfListOfInteractive.hxx>
61 #include <TopExp_Explorer.hxx>
62 #include <TopTools_IndexedMapOfShape.hxx>
63 #include <TColStd_IndexedMapOfInteger.hxx>
64 #include <TColStd_MapOfInteger.hxx>
65 #include <TColStd_DataMapIteratorOfDataMapOfIntegerInteger.hxx>
67 #include <GEOMImpl_Types.hxx>
69 enum { ALL_SUBSHAPES = 0, GET_IN_PLACE, SUBSHAPES_OF_SHAPE2, SUBSHAPES_OF_INVISIBLE_SHAPE2 };
71 GroupGUI_GroupDlg::GroupGUI_GroupDlg (Mode mode, GeometryGUI* theGeometryGUI, QWidget* parent)
72 : 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()
189 //=================================================================================
192 //=================================================================================
193 void GroupGUI_GroupDlg::Init()
195 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
197 //unset shape type to avoid preparation of selection before exact user shape type selection
198 unsetConstructorId();
199 myIsShapeType = false;
201 if (myMode == CreateGroup) {
202 initName(tr("GROUP_PREFIX"));
204 // Get ready for main shape selection
205 myEditCurrentArgument = myMainName;
207 connect(this, SIGNAL(constructorsClicked(int)), this, SLOT(ConstructorsClicked(int)));
208 connect(mySelBtn, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
209 connect(mySelBtn2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
211 else if (myMode == EditGroup) {
212 SALOME_ListIO aSelList;
213 aSelMgr->selectedObjects(aSelList);
215 if (aSelList.Extent()) {
216 GEOM::GEOM_Object_var anObj =
217 GEOMBase::ConvertIOinGEOMObject( aSelList.First() );
219 if ( !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 GEOM::GEOM_Object_var anObj =
379 GEOMBase::ConvertIOinGEOMObject( aSelList.First() );
380 if ( GEOMBase::IsShape(anObj) ) {
381 if (!anObj->_is_equivalent(myMainObj) && !anObj->_is_equivalent(myGroup)) {
382 SUIT_OverrideCursor wc;
383 myEditCurrentArgument->setText(GEOMBase::GetName(anObj));
384 GEOM::GEOM_IShapesOperations_var aShapesOp =
385 getGeomEngine()->GetIShapesOperations(getStudyId());
386 if (subSelectionWay() == GET_IN_PLACE) {
387 GEOM::GEOM_Object_var aGetInPlaceObj = aShapesOp->GetInPlace(myMainObj, anObj);
388 setInPlaceObj(aGetInPlaceObj);
391 bool isVisible = true;
392 if (SALOME_View* view = GEOM_Displayer::GetActiveView())
393 isVisible = view->isVisible(aSelList.First());
394 setInPlaceObj(anObj, isVisible);
396 myEditCurrentArgument = 0;
397 //myBusy = true; // just activate but do not select in the list
404 //=================================================================================
405 //function : setInPlaceObj
406 //purpose : temporarily add an object to study and remove old InPlaceObj
407 //=================================================================================
408 void GroupGUI_GroupDlg::setInPlaceObj(GEOM::GEOM_Object_var theObj, const bool isVisible)
410 if (!myInPlaceObj->_is_equivalent(theObj))
412 myInPlaceObj = theObj;
415 // build map of indices
416 myMain2InPlaceIndices.Clear();
417 if (!myInPlaceObj->_is_nil()) {
418 GEOM::GEOM_IShapesOperations_var aShapesOp = getGeomEngine()->GetIShapesOperations(getStudyId());
419 GEOM::GEOM_ILocalOperations_var aLocOp = getGeomEngine()->GetILocalOperations(getStudyId());
421 GEOM::ListOfGO_var aSubObjects = aShapesOp->MakeExplode(myInPlaceObj, getShapeType(), false);
422 for (int i = 0; i < aSubObjects->length(); i++)
424 CORBA::Long aMainIndex = aLocOp->GetSubShapeIndex(myMainObj, aSubObjects[i]);
425 CORBA::Long aPlaceIndex = aLocOp->GetSubShapeIndex(myInPlaceObj, aSubObjects[i]);
426 if (aMainIndex >= 0 && aPlaceIndex > 0)
427 myMain2InPlaceIndices.Bind(aMainIndex, aPlaceIndex);
430 myInPlaceObjSelectState = subSelectionWay();
431 if (myInPlaceObjSelectState == SUBSHAPES_OF_SHAPE2 && !isVisible)
432 myInPlaceObjSelectState = SUBSHAPES_OF_INVISIBLE_SHAPE2;
435 //=================================================================================
436 // function : SelectionIntoArgument()
437 // purpose : Called when selection has changed
438 //=================================================================================
439 void GroupGUI_GroupDlg::SelectionIntoArgument()
441 if (subSelectionWay() != ALL_SUBSHAPES && myEditCurrentArgument == myShape2Name) {
446 if (myEditCurrentArgument == myMainName) { // Selection of a main shape is active
447 myEditCurrentArgument->setText("");
450 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
451 SALOME_ListIO aSelList;
452 aSelMgr->selectedObjects(aSelList);
453 int nbSel = aSelList.Extent();
456 GEOM::GEOM_Object_var anObj =
457 GEOMBase::ConvertIOinGEOMObject( aSelList.First() );
459 if ( GEOMBase::IsShape(anObj) ) {
461 myEditCurrentArgument->setText(GEOMBase::GetName(anObj));
462 // activate subshapes selection by default
463 myEditCurrentArgument = 0;
469 myMainObj = GEOM::GEOM_Object::_nil();
472 else { // an attempt to synchronize list box selection with 3d viewer
473 if ( myBusy || myMainObj->_is_nil() ) {
477 bool isBlocked = myIdList->signalsBlocked();
478 myIdList->blockSignals(true);
479 myIdList->clearSelection();
481 TColStd_IndexedMapOfInteger aMapIndex;
482 int nbSel = getSelectedSubshapes(aMapIndex);
486 for (int i = 0, n = myIdList->count(); i < n; i++)
487 aMap.insert(myIdList->item(i)->text().toInt(), i);
489 bool highlight = false;
490 for (int ii = 1, nn = aMapIndex.Extent(); ii <= nn; ii++) {
491 if (aMap.contains(aMapIndex(ii))) {
492 myIdList->item(aMap[aMapIndex(ii)])->setSelected(true);
497 highlightSubShapes();
499 myIdList->blockSignals(isBlocked);
505 //=================================================================================
506 // function : ConstructorsClicked()
507 // purpose : Radio button management
508 //=================================================================================
509 void GroupGUI_GroupDlg::ConstructorsClicked(int constructorId)
511 if (getConstructorId() != constructorId)
512 setConstructorId(constructorId);
514 myIsShapeType = true;
516 myEditCurrentArgument = 0;
518 setInPlaceObj(myInPlaceObj); // to rebuild myMain2InPlaceIndices
523 //=================================================================================
524 // function : selectAllSubShapes
526 //=================================================================================
527 void GroupGUI_GroupDlg::selectAllSubShapes()
529 if (CORBA::is_nil(myMainObj) || !myIsShapeType)
532 GEOM::ListOfLong_var aSubShapes;
533 GEOM::GEOM_IShapesOperations_var aShOp = getGeomEngine()->GetIShapesOperations(getStudyId());
534 aSubShapes = aShOp->SubShapeAllIDs(myMainObj, getShapeType(), false);
535 if (aSubShapes->length() > 0) {
536 if (subSelectionWay() == ALL_SUBSHAPES)
538 myIdList->clear(); // for sorted final list?
540 if (!aShOp->IsDone())
545 aSubShapes = new GEOM::ListOfLong();
546 aSubShapes->length(myMain2InPlaceIndices.Extent());
547 TColStd_DataMapIteratorOfDataMapOfIntegerInteger m2ip (myMain2InPlaceIndices);
548 for (int i = 0; m2ip.More(); i++, m2ip.Next())
549 aSubShapes[i] = m2ip.Key();
552 bool isBlocked = myIdList->signalsBlocked();
553 myIdList->blockSignals(true);
555 for (int i = 0, n = aSubShapes->length(); i < n; i++) {
556 CORBA::Long anIndex = aSubShapes[i];
560 QListWidgetItem* anItem = 0;
561 QString text = QString("%1").arg(anIndex);
562 if (!myInPlaceObj->_is_nil()) {
563 QList<QListWidgetItem*> found = myIdList->findItems(text, Qt::MatchExactly);
564 if (found.count()) anItem = found[0];
567 anItem = new QListWidgetItem(text);
568 myIdList->addItem(anItem);
570 anItem->setSelected(true);
573 myIdList->blockSignals(isBlocked);
574 highlightSubShapes();
578 //=================================================================================
579 // function : showOnlySelected
581 //=================================================================================
582 void GroupGUI_GroupDlg::showOnlySelected()
584 if (CORBA::is_nil(myMainObj) || !myIsShapeType)
587 QPushButton* send = (QPushButton*)sender();
588 if (send == myShowAllBtn) {
593 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
594 SALOME_ListIO aSelList;
595 aSelMgr->selectedObjects(aSelList);
597 GEOM_Displayer* aDisplayer = getDisplayer();
599 if (send == myHideSelBtn) {
600 aDisplayer->Erase(aSelList, false, true);
603 aDisplayer->EraseAll();
604 aDisplayer->Display(aSelList, true);
608 //=================================================================================
609 // function : getSelectedSubshapes
611 //=================================================================================
612 int GroupGUI_GroupDlg::getSelectedSubshapes (TColStd_IndexedMapOfInteger& theMapIndex)
616 SalomeApp_Application* app = myGeomGUI->getApp();
617 if ( !app || myMainObj->_is_nil() )
620 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
621 SALOME_ListIO aSelList;
622 aSelMgr->selectedObjects(aSelList);
624 // try to find out and process the global selection
625 // (of not published objects and of published sub-shapes)
627 SALOME_ListIteratorOfListIO anIter (aSelList);
628 for (int i = 0; anIter.More(); anIter.Next(), i++)
630 Handle(SALOME_InteractiveObject) anIObj = anIter.Value();
631 QString anEntry = anIObj->getEntry();
633 int index = anEntry.lastIndexOf(str);
634 if (index > 0) // selection among special preview
636 anEntry.remove(0, index+1);
637 int anIndex = anEntry.toInt();
639 theMapIndex.Add(anIndex);
641 else // selection among published shapes
643 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>(app->activeStudy());
644 if (!appStudy) return 0;
645 _PTR(Study) aStudy = appStudy->studyDS();
647 _PTR(SObject) aSObj (aStudy->FindObjectID(anEntry.toLatin1().constData()));
648 GEOM::GEOM_Object_var aGeomObj =
649 GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aSObj));
651 if (GEOMBase::GetShape(aGeomObj, aShape)) {
652 if (aGeomObj->GetType() == GEOM_GROUP || aShape.ShapeType() == getShapeType()) {
653 TopTools_IndexedMapOfShape aMainMap;
654 TopoDS_Shape aMainShape = GEOM_Client::get_client().GetShape(GeometryGUI::GetGeomGen(), myMainObj);
655 TopExp::MapShapes(aMainShape, aMainMap);
657 TopExp_Explorer anExp (aShape, getShapeType());
658 for (; anExp.More(); anExp.Next()) {
659 TopoDS_Shape aSubShape = anExp.Current();
660 int anIndex = aMainMap.FindIndex(aSubShape);
662 if (subSelectionWay() != ALL_SUBSHAPES &&
663 !myMain2InPlaceIndices.IsBound(anIndex))
665 theMapIndex.Add(anIndex);
674 return theMapIndex.Extent();
677 //=================================================================================
680 //=================================================================================
681 void GroupGUI_GroupDlg::add()
683 TColStd_IndexedMapOfInteger aMapIndex;
684 int nbSel = getSelectedSubshapes(aMapIndex);
686 TColStd_MapOfInteger aMap;
687 for (int i = 0, n = myIdList->count(); i < n; i++)
688 aMap.Add(myIdList->item(i)->text().toInt());
691 bool isBlocked = myIdList->signalsBlocked();
692 myIdList->blockSignals(true);
694 for (int i = 1, n = aMapIndex.Extent(); i <= n; i++) {
695 if (aMap.Contains(aMapIndex(i)))
698 QListWidgetItem* anItem = new QListWidgetItem(QString("%1").arg(aMapIndex(i)));
699 myIdList->addItem(anItem);
700 anItem->setSelected(true);
703 myIdList->blockSignals(isBlocked);
709 //=================================================================================
712 //=================================================================================
713 void GroupGUI_GroupDlg::remove()
715 bool isBlocked = myIdList->signalsBlocked();
716 myIdList->blockSignals(true);
718 QListIterator<QListWidgetItem*> it (myIdList->selectedItems());
722 myIdList->blockSignals(isBlocked);
724 highlightSubShapes();
727 //=================================================================================
728 //function : subSelectionWay
730 //=================================================================================
731 int GroupGUI_GroupDlg::subSelectionWay() const
733 return myRestrictGroup->checkedId();
736 //=================================================================================
737 // function : getShapeType()
739 //=================================================================================
740 TopAbs_ShapeEnum GroupGUI_GroupDlg::getShapeType() const
742 switch (getConstructorId()) {
743 case 0: return TopAbs_VERTEX;
744 case 1: return TopAbs_EDGE;
745 case 2: return TopAbs_FACE;
746 case 3: return TopAbs_SOLID;
747 default: return TopAbs_SHAPE;
751 //=================================================================================
752 // function : setShapeType()
754 //=================================================================================
755 void GroupGUI_GroupDlg::setShapeType(const TopAbs_ShapeEnum theType)
759 case TopAbs_VERTEX: anId = 0; break;
760 case TopAbs_EDGE: anId = 1; break;
761 case TopAbs_FACE: anId = 2; break;
762 case TopAbs_SOLID: anId = 3; break;
764 setConstructorId(anId);
767 myIsShapeType = true;
768 // workaround to avoid set checked button 0
769 setConstructorId(anId);
773 //=================================================================================
774 // function : activateSelection
775 // purpose : Activate selection in accordance with myEditCurrentArgument
776 //=================================================================================
777 void GroupGUI_GroupDlg::activateSelection()
782 if (!myMainObj->_is_nil() &&
783 !myEditCurrentArgument &&
784 myIsShapeType) // check if shape type is already choosen by user
786 GEOM_Displayer* aDisplayer = getDisplayer();
787 int prevDisplayMode = aDisplayer->SetDisplayMode(0);
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::get_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::get_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();
830 aDisplayer->SetDisplayMode(prevDisplayMode);
833 globalSelection(GEOM_ALLSHAPES);
835 SelectionIntoArgument();
838 //=================================================================================
839 // function : updateState
841 //=================================================================================
842 void GroupGUI_GroupDlg::updateState (bool isAdd)
844 myAddBtn->setEnabled(!myEditCurrentArgument && !CORBA::is_nil(myMainObj) && isAdd);
845 //myShowOnlyBtn->setEnabled(!myEditCurrentArgument && !CORBA::is_nil(myMainObj) && isAdd);
847 bool hasSel = myIdList->selectedItems().count() > 0;
849 myRemBtn->setEnabled(hasSel);
850 myRestrictGroupBox->setEnabled(!CORBA::is_nil(myMainObj));
851 mySelAllBtn->setEnabled(!CORBA::is_nil(myMainObj));
853 mySelBtn2->setEnabled( subSelectionWay() != ALL_SUBSHAPES);
854 myShape2Name->setEnabled(subSelectionWay() != ALL_SUBSHAPES);
855 if (subSelectionWay() == ALL_SUBSHAPES)
856 setInPlaceObj(GEOM::GEOM_Object::_nil());
859 //=================================================================================
860 // function : selectionChanged
862 //=================================================================================
863 void GroupGUI_GroupDlg::selectionChanged()
865 highlightSubShapes();
868 //=================================================================================
869 // function : highlightSubShapes
871 //=================================================================================
872 void GroupGUI_GroupDlg::highlightSubShapes()
874 if (CORBA::is_nil(myMainObj))
877 TColStd_MapOfInteger anIds;
881 int ii = 0, nn = myIdList->count();
882 for (; ii < nn; ii++)
884 if (myIdList->item(ii)->isSelected()) {
885 int id = myIdList->item(ii)->text().toInt();
886 if (subSelectionWay() != ALL_SUBSHAPES &&
887 !myMain2InPlaceIndices.IsBound(id)) {
888 myIdList->item(ii)->setSelected(false);
895 SalomeApp_Application* app = myGeomGUI->getApp();
896 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
897 aSelMgr->clearSelected();
899 SUIT_ViewWindow* aViewWindow = 0;
900 SUIT_Study* activeStudy = app->activeStudy();
902 aViewWindow = app->desktop()->activeWindow();
903 if (aViewWindow == 0) return;
905 SUIT_ViewManager* aViewManager = aViewWindow->getViewManager();
906 if (aViewManager->getType() != OCCViewer_Viewer::Type() &&
907 aViewManager->getType() != SVTK_Viewer::Type())
910 SUIT_ViewModel* aViewModel = aViewManager->getViewModel();
911 SALOME_View* aView = dynamic_cast<SALOME_View*>(aViewModel);
912 if (aView == 0) return;
914 // TODO: use here GEOMBase_Helper::myPreview instead of ic->DisplayedObjects()
916 OCCViewer_Viewer* v3d = ((OCCViewer_ViewManager*)aViewManager)->getOCCViewer();
917 Handle(AIS_InteractiveContext) ic = v3d->getAISContext();
918 AIS_ListOfInteractive List;
919 ic->DisplayedObjects(List);
921 SALOME_ListIO aSelList;
923 // To highlight the selected subshape in Object Browser, if it's already pudlished under the main shape
924 GEOM::GEOM_ILocalOperations_var aLocOp = getGeomEngine()->GetILocalOperations(getStudyId());
925 QMap<int, QString> childsMap;
926 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>(app->activeStudy());
928 _PTR(Study) aStudy = appStudy->studyDS();
929 CORBA::String_var aMainEntry = myMainObj->GetStudyEntry();
930 QString anEntry = aMainEntry.in();
931 _PTR(SObject) aSObj (aStudy->FindObjectID(anEntry.toLatin1().constData()));
932 _PTR(ChildIterator) anIt ( aStudy->NewChildIterator( aSObj ) );
933 for ( anIt->InitEx( true ); anIt->More(); anIt->Next() ) {
934 GEOM::GEOM_Object_var aChild = GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(anIt->Value()));
935 if ( !CORBA::is_nil( aChild ) ) {
936 int index = aLocOp->GetSubShapeIndex(myMainObj, aChild);
937 CORBA::String_var aChildEntry = aChild->GetStudyEntry();
938 QString anEntry = aChildEntry.in();
939 childsMap.insert(index, anEntry);
944 AIS_ListIteratorOfListOfInteractive ite (List);
945 for (; ite.More(); ite.Next()) {
946 if (ite.Value()->IsInstance(STANDARD_TYPE(GEOM_AISShape))) {
947 Handle(GEOM_AISShape) aSh = Handle(GEOM_AISShape)::DownCast(ite.Value());
949 Handle(SALOME_InteractiveObject) anIO = aSh->getIO();
950 QString anEntry = anIO->getEntry();
951 int index = anEntry.lastIndexOf("_");
952 anEntry.remove(0, index+1);
953 int anIndex = anEntry.toInt();
954 if ( anIds.Contains(anIndex) ) {
955 aSelList.Append(anIO);
956 if ( childsMap.contains ( anIndex )) {
957 Handle(SALOME_InteractiveObject) tmpIO = new SALOME_InteractiveObject( childsMap.value(anIndex).toLatin1().constData(), "GEOM", "TEMP_IO" );
958 aSelList.Append(tmpIO);
964 aSelMgr->setSelectedObjects(aSelList);
969 updateState(aSelList.Extent() > 0);
971 myAddBtn->setEnabled(true);
972 myAddBtn->setEnabled(true);
973 myRemBtn->setEnabled(true);
977 //=================================================================================
978 // function : createOperation
980 //=================================================================================
981 GEOM::GEOM_IOperations_ptr GroupGUI_GroupDlg::createOperation()
983 return getGeomEngine()->GetIGroupOperations(getStudyId());
986 #define RETURN_WITH_MSG(a, b) \
992 //=================================================================================
993 // function : isValid()
994 // purpose : Verify validity of input data
995 //=================================================================================
996 bool GroupGUI_GroupDlg::isValid(QString& theMessage)
998 SalomeApp_Study* study = getStudy();
1000 RETURN_WITH_MSG (!study->studyDS()->GetProperties()->IsLocked(), tr("GEOM_STUDY_LOCKED"))
1002 if (myMode == CreateGroup) {
1003 RETURN_WITH_MSG(!CORBA::is_nil(myMainObj), tr("NO_MAIN_OBJ"))
1006 RETURN_WITH_MSG(!CORBA::is_nil(myMainObj), tr("NO_GROUP"))
1009 QString aName (getNewObjectName());
1010 RETURN_WITH_MSG (!aName.trimmed().isEmpty(), tr("EMPTY_NAME"))
1012 RETURN_WITH_MSG (myIdList->count(), tr("EMPTY_LIST"))
1016 //=================================================================================
1017 // function : execute
1019 //=================================================================================
1020 bool GroupGUI_GroupDlg::execute(ObjectList& objects)
1022 GEOM::GEOM_IGroupOperations_var anOper = GEOM::GEOM_IGroupOperations::_narrow(getOperation());
1024 GEOM::GEOM_Object_var aGroup;
1025 if (myMode == CreateGroup)
1026 aGroup = anOper->CreateGroup(myMainObj, getShapeType());
1027 else if (myMode == EditGroup)
1030 if (CORBA::is_nil(aGroup) || (myMode == CreateGroup && !anOper->IsDone()))
1033 GEOM::ListOfLong_var aCurrList = anOper->GetObjects(aGroup);
1034 if (!anOper->IsDone())
1037 if (aCurrList->length() > 0)
1039 anOper->DifferenceIDs(aGroup, aCurrList);
1040 if (!anOper->IsDone())
1044 int ii, nn = myIdList->count();
1047 GEOM::ListOfLong_var aNewList = new GEOM::ListOfLong;
1048 aNewList->length(nn);
1049 for (ii = 0; ii < nn; ii++) {
1050 aNewList[ii] = myIdList->item(ii)->text().toInt();
1052 anOper->UnionIDs(aGroup, aNewList);
1053 if (!anOper->IsDone())
1057 SalomeApp_Study* study = getStudy();
1059 QString objIOR = GEOMBase::GetIORFromObject(aGroup);
1061 _PTR(SObject) SO (study->studyDS()->FindObjectIOR(objIOR.toLatin1().constData()));
1063 _PTR(StudyBuilder) aBuilder (study->studyDS()->NewBuilder());
1064 aBuilder->SetName(SO, getNewObjectName().toLatin1().constData());
1069 objects.push_back(aGroup._retn());
1074 //================================================================
1075 // Function : getFather
1076 // Purpose : Get father object for object to be added in study
1077 // ( called with addInStudy method )
1078 //================================================================
1079 GEOM::GEOM_Object_ptr GroupGUI_GroupDlg::getFather(GEOM::GEOM_Object_ptr theObj)
1081 GEOM::GEOM_Object_var aFatherObj;
1082 if (theObj->GetType() == GEOM_GROUP) {
1083 GEOM::GEOM_IGroupOperations_var anOper = GEOM::GEOM_IGroupOperations::_narrow(getOperation());
1084 aFatherObj = anOper->GetMainShape(theObj);
1086 return aFatherObj._retn();