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 Standard_Boolean aResult = Standard_False;
217 GEOM::GEOM_Object_var anObj =
218 GEOMBase::ConvertIOinGEOMObject(aSelList.First(), aResult);
220 if (aResult && !CORBA::is_nil(anObj) && anObj->GetType() == GEOM_GROUP) {
223 mainFrame()->ResultName->setText(GEOMBase::GetName(myGroup));
225 GEOM::GEOM_IGroupOperations_var anOper = GEOM::GEOM_IGroupOperations::_narrow(getOperation());
226 myMainObj = anOper->GetMainShape(myGroup);
227 if (!CORBA::is_nil(myMainObj))
228 myMainName->setText(GEOMBase::GetName(myMainObj));
230 setShapeType((TopAbs_ShapeEnum)anOper->GetType(myGroup));
232 GEOM::ListOfLong_var aCurrList = anOper->GetObjects(myGroup);
233 for (int i = 0, n = aCurrList->length(); i < n; i++)
234 myIdList->addItem(new QListWidgetItem(QString("%1").arg(aCurrList[i])));
236 myEditCurrentArgument = 0;
238 connect(mySelBtn2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
242 connect(aSelMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
244 connect(buttonOk(), SIGNAL(clicked()), this, SLOT(ClickOnOk()));
245 connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
247 connect(myRestrictGroup, SIGNAL(buttonClicked(int)), this, SLOT(SetEditCurrentArgument()));
248 connect(mySelAllBtn, SIGNAL(clicked()), this, SLOT(selectAllSubShapes()));
249 connect(myAddBtn, SIGNAL(clicked()), this, SLOT(add()));
250 connect(myRemBtn, SIGNAL(clicked()), this, SLOT(remove()));
251 connect(myShowOnlyBtn, SIGNAL(clicked()), this, SLOT(showOnlySelected()));
252 connect(myHideSelBtn, SIGNAL(clicked()), this, SLOT(showOnlySelected()));
253 connect(myShowAllBtn, SIGNAL(clicked()), this, SLOT(showOnlySelected()));
254 connect(myIdList, SIGNAL(itemSelectionChanged()), this, SLOT(selectionChanged()));
256 setInPlaceObj(GEOM::GEOM_Object::_nil());
258 myBusy = true; // just activate but do not select in the list
263 //=================================================================================
264 // function : enterEvent()
266 //=================================================================================
267 void GroupGUI_GroupDlg::enterEvent(QEvent* e)
269 if (!buttonCancel()->isEnabled())
270 ActivateThisDialog();
273 //=================================================================================
274 //function : closeEvent
275 //purpose : remove temporary geom object
276 //=================================================================================
277 void GroupGUI_GroupDlg::closeEvent(QCloseEvent* e)
279 setInPlaceObj(GEOM::GEOM_Object::_nil());
282 GEOMBase_Skeleton::closeEvent(e);
285 //=================================================================================
286 // function : ClickOnOk()
288 //=================================================================================
289 void GroupGUI_GroupDlg::ClickOnOk()
295 //=================================================================================
296 // function : ClickOnApply()
298 //=================================================================================
299 bool GroupGUI_GroupDlg::ClickOnApply()
301 if (!onAccept(myMode == CreateGroup, true))
304 if (myMode == CreateGroup)
308 ConstructorsClicked(getConstructorId());
316 //=================================================================================
317 // function : ActivateThisDialog()
319 //=================================================================================
320 void GroupGUI_GroupDlg::ActivateThisDialog()
322 GEOMBase_Skeleton::ActivateThisDialog();
324 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
325 this, SLOT(SelectionIntoArgument()));
330 //=================================================================================
331 // function : SetEditCurrentArgument()
333 //=================================================================================
334 void GroupGUI_GroupDlg::SetEditCurrentArgument()
336 QPushButton* send = (QPushButton*)sender();
338 if (send == mySelBtn) {
339 myEditCurrentArgument = myMainName;
340 myShape2Name->setText("");
342 else if (send == mySelBtn2 || sender() == myRestrictGroup) {
343 setInPlaceObj(GEOM::GEOM_Object::_nil());
344 myShape2Name->setText("");
345 if (subSelectionWay() != ALL_SUBSHAPES) {
346 myEditCurrentArgument = myShape2Name;
349 myEditCurrentArgument = 0;
358 //=================================================================================
359 // function : onGetInPlace()
361 //=================================================================================
362 void GroupGUI_GroupDlg::onGetInPlace()
364 setInPlaceObj(GEOM::GEOM_Object::_nil());
365 myEditCurrentArgument->setText("");
367 bool isBlocked = myIdList->signalsBlocked();
368 myIdList->blockSignals(true);
369 myIdList->clearSelection();
370 myIdList->blockSignals(isBlocked);
372 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
373 SALOME_ListIO aSelList;
374 aSelMgr->selectedObjects(aSelList);
376 if (aSelList.Extent() != 1)
379 Standard_Boolean aResult = Standard_False;
380 GEOM::GEOM_Object_var anObj =
381 GEOMBase::ConvertIOinGEOMObject(aSelList.First(), aResult);
382 if (aResult && !anObj->_is_nil() && GEOMBase::IsShape(anObj)) {
383 if (!anObj->_is_equivalent(myMainObj) && !anObj->_is_equivalent(myGroup)) {
384 SUIT_OverrideCursor wc;
385 myEditCurrentArgument->setText(GEOMBase::GetName(anObj));
386 GEOM::GEOM_IShapesOperations_var aShapesOp =
387 getGeomEngine()->GetIShapesOperations(getStudyId());
388 if (subSelectionWay() == GET_IN_PLACE) {
389 GEOM::GEOM_Object_var aGetInPlaceObj = aShapesOp->GetInPlace(myMainObj, anObj);
390 setInPlaceObj(aGetInPlaceObj);
393 bool isVisible = true;
394 if (SALOME_View* view = GEOM_Displayer::GetActiveView())
395 isVisible = view->isVisible(aSelList.First());
396 setInPlaceObj(anObj, isVisible);
398 myEditCurrentArgument = 0;
399 //myBusy = true; // just activate but do not select in the list
406 //=================================================================================
407 //function : setInPlaceObj
408 //purpose : temporarily add an object to study and remove old InPlaceObj
409 //=================================================================================
410 void GroupGUI_GroupDlg::setInPlaceObj(GEOM::GEOM_Object_var theObj, const bool isVisible)
412 if (!myInPlaceObj->_is_equivalent(theObj))
414 myInPlaceObj = theObj;
417 // build map of indices
418 myMain2InPlaceIndices.Clear();
419 if (!myInPlaceObj->_is_nil()) {
420 GEOM::GEOM_IShapesOperations_var aShapesOp = getGeomEngine()->GetIShapesOperations(getStudyId());
421 GEOM::GEOM_ILocalOperations_var aLocOp = getGeomEngine()->GetILocalOperations(getStudyId());
423 GEOM::ListOfGO_var aSubObjects = aShapesOp->MakeExplode(myInPlaceObj, getShapeType(), false);
424 for (int i = 0; i < aSubObjects->length(); i++)
426 CORBA::Long aMainIndex = aLocOp->GetSubShapeIndex(myMainObj, aSubObjects[i]);
427 CORBA::Long aPlaceIndex = aLocOp->GetSubShapeIndex(myInPlaceObj, aSubObjects[i]);
428 if (aMainIndex >= 0 && aPlaceIndex > 0)
429 myMain2InPlaceIndices.Bind(aMainIndex, aPlaceIndex);
432 myInPlaceObjSelectState = subSelectionWay();
433 if (myInPlaceObjSelectState == SUBSHAPES_OF_SHAPE2 && !isVisible)
434 myInPlaceObjSelectState = SUBSHAPES_OF_INVISIBLE_SHAPE2;
437 //=================================================================================
438 // function : SelectionIntoArgument()
439 // purpose : Called when selection has changed
440 //=================================================================================
441 void GroupGUI_GroupDlg::SelectionIntoArgument()
443 if (subSelectionWay() != ALL_SUBSHAPES && myEditCurrentArgument == myShape2Name) {
448 if (myEditCurrentArgument == myMainName) { // Selection of a main shape is active
449 myEditCurrentArgument->setText("");
452 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
453 SALOME_ListIO aSelList;
454 aSelMgr->selectedObjects(aSelList);
455 int nbSel = aSelList.Extent();
458 Standard_Boolean aResult = Standard_False;
459 GEOM::GEOM_Object_var anObj =
460 GEOMBase::ConvertIOinGEOMObject(aSelList.First(), aResult);
462 if (aResult && !anObj->_is_nil() && GEOMBase::IsShape(anObj)) {
464 myEditCurrentArgument->setText(GEOMBase::GetName(anObj));
465 // activate subshapes selection by default
466 myEditCurrentArgument = 0;
472 myMainObj = GEOM::GEOM_Object::_nil();
475 else { // an attempt to synchronize list box selection with 3d viewer
480 bool isBlocked = myIdList->signalsBlocked();
481 myIdList->blockSignals(true);
482 myIdList->clearSelection();
484 TColStd_IndexedMapOfInteger aMapIndex;
485 int nbSel = getSelectedSubshapes(aMapIndex);
489 for (int i = 0, n = myIdList->count(); i < n; i++)
490 aMap.insert(myIdList->item(i)->text().toInt(), i);
492 bool highlight = false;
493 for (int ii = 1, nn = aMapIndex.Extent(); ii <= nn; ii++) {
494 if (aMap.contains(aMapIndex(ii))) {
495 myIdList->item(aMap[aMapIndex(ii)])->setSelected(true);
500 highlightSubShapes();
502 myIdList->blockSignals(isBlocked);
508 //=================================================================================
509 // function : ConstructorsClicked()
510 // purpose : Radio button management
511 //=================================================================================
512 void GroupGUI_GroupDlg::ConstructorsClicked(int constructorId)
514 if (getConstructorId() != constructorId)
515 setConstructorId(constructorId);
517 myIsShapeType = true;
519 myEditCurrentArgument = 0;
521 setInPlaceObj(myInPlaceObj); // to rebuild myMain2InPlaceIndices
526 //=================================================================================
527 // function : selectAllSubShapes
529 //=================================================================================
530 void GroupGUI_GroupDlg::selectAllSubShapes()
532 if (CORBA::is_nil(myMainObj) || !myIsShapeType)
535 GEOM::ListOfLong_var aSubShapes;
536 GEOM::GEOM_IShapesOperations_var aShOp = getGeomEngine()->GetIShapesOperations(getStudyId());
537 aSubShapes = aShOp->SubShapeAllIDs(myMainObj, getShapeType(), false);
538 if (aSubShapes->length() > 0) {
539 if (subSelectionWay() == ALL_SUBSHAPES)
541 myIdList->clear(); // for sorted final list?
543 if (!aShOp->IsDone())
548 aSubShapes = new GEOM::ListOfLong();
549 aSubShapes->length(myMain2InPlaceIndices.Extent());
550 TColStd_DataMapIteratorOfDataMapOfIntegerInteger m2ip (myMain2InPlaceIndices);
551 for (int i = 0; m2ip.More(); i++, m2ip.Next())
552 aSubShapes[i] = m2ip.Key();
555 bool isBlocked = myIdList->signalsBlocked();
556 myIdList->blockSignals(true);
558 for (int i = 0, n = aSubShapes->length(); i < n; i++) {
559 CORBA::Long anIndex = aSubShapes[i];
563 QListWidgetItem* anItem = 0;
564 QString text = QString("%1").arg(anIndex);
565 if (!myInPlaceObj->_is_nil()) {
566 QList<QListWidgetItem*> found = myIdList->findItems(text, Qt::MatchExactly);
567 if (found.count()) anItem = found[0];
570 anItem = new QListWidgetItem(text);
571 myIdList->addItem(anItem);
573 anItem->setSelected(true);
576 myIdList->blockSignals(isBlocked);
577 highlightSubShapes();
581 //=================================================================================
582 // function : showOnlySelected
584 //=================================================================================
585 void GroupGUI_GroupDlg::showOnlySelected()
587 if (CORBA::is_nil(myMainObj) || !myIsShapeType)
590 QPushButton* send = (QPushButton*)sender();
591 if (send == myShowAllBtn) {
596 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
597 SALOME_ListIO aSelList;
598 aSelMgr->selectedObjects(aSelList);
600 GEOM_Displayer* aDisplayer = getDisplayer();
602 if (send == myHideSelBtn) {
603 aDisplayer->Erase(aSelList, false, true);
606 aDisplayer->EraseAll();
607 aDisplayer->Display(aSelList, true);
611 //=================================================================================
612 // function : getSelectedSubshapes
614 //=================================================================================
615 int GroupGUI_GroupDlg::getSelectedSubshapes (TColStd_IndexedMapOfInteger& theMapIndex)
619 SalomeApp_Application* app = myGeomGUI->getApp();
622 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
623 SALOME_ListIO aSelList;
624 aSelMgr->selectedObjects(aSelList);
626 // try to find out and process the global selection
627 // (of not published objects and of published sub-shapes)
629 SALOME_ListIteratorOfListIO anIter (aSelList);
630 for (int i = 0; anIter.More(); anIter.Next(), i++)
632 Handle(SALOME_InteractiveObject) anIObj = anIter.Value();
633 QString anEntry = anIObj->getEntry();
635 int index = anEntry.lastIndexOf(str);
636 if (index > 0) // selection among special preview
638 anEntry.remove(0, index+1);
639 int anIndex = anEntry.toInt();
641 theMapIndex.Add(anIndex);
643 else // selection among published shapes
645 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>(app->activeStudy());
646 if (!appStudy) return 0;
647 _PTR(Study) aStudy = appStudy->studyDS();
649 _PTR(SObject) aSObj (aStudy->FindObjectID(anEntry.toLatin1().constData()));
650 GEOM::GEOM_Object_var aGeomObj =
651 GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aSObj));
653 if (GEOMBase::GetShape(aGeomObj, aShape)) {
654 if (aGeomObj->GetType() == GEOM_GROUP || aShape.ShapeType() == getShapeType()) {
655 TopTools_IndexedMapOfShape aMainMap;
656 TopoDS_Shape aMainShape = GEOM_Client().GetShape(GeometryGUI::GetGeomGen(), myMainObj);
657 TopExp::MapShapes(aMainShape, aMainMap);
659 TopExp_Explorer anExp (aShape, getShapeType());
660 for (; anExp.More(); anExp.Next()) {
661 TopoDS_Shape aSubShape = anExp.Current();
662 int anIndex = aMainMap.FindIndex(aSubShape);
664 if (subSelectionWay() != ALL_SUBSHAPES &&
665 !myMain2InPlaceIndices.IsBound(anIndex))
667 theMapIndex.Add(anIndex);
676 return theMapIndex.Extent();
679 //=================================================================================
682 //=================================================================================
683 void GroupGUI_GroupDlg::add()
685 TColStd_IndexedMapOfInteger aMapIndex;
686 int nbSel = getSelectedSubshapes(aMapIndex);
688 TColStd_MapOfInteger aMap;
689 for (int i = 0, n = myIdList->count(); i < n; i++)
690 aMap.Add(myIdList->item(i)->text().toInt());
693 bool isBlocked = myIdList->signalsBlocked();
694 myIdList->blockSignals(true);
696 for (int i = 1, n = aMapIndex.Extent(); i <= n; i++) {
697 if (aMap.Contains(aMapIndex(i)))
700 QListWidgetItem* anItem = new QListWidgetItem(QString("%1").arg(aMapIndex(i)));
701 myIdList->addItem(anItem);
702 anItem->setSelected(true);
705 myIdList->blockSignals(isBlocked);
711 //=================================================================================
714 //=================================================================================
715 void GroupGUI_GroupDlg::remove()
717 bool isBlocked = myIdList->signalsBlocked();
718 myIdList->blockSignals(true);
720 QListIterator<QListWidgetItem*> it (myIdList->selectedItems());
724 myIdList->blockSignals(isBlocked);
726 highlightSubShapes();
729 //=================================================================================
730 //function : subSelectionWay
732 //=================================================================================
733 int GroupGUI_GroupDlg::subSelectionWay() const
735 return myRestrictGroup->checkedId();
738 //=================================================================================
739 // function : getShapeType()
741 //=================================================================================
742 TopAbs_ShapeEnum GroupGUI_GroupDlg::getShapeType() const
744 switch (getConstructorId()) {
745 case 0: return TopAbs_VERTEX;
746 case 1: return TopAbs_EDGE;
747 case 2: return TopAbs_FACE;
748 case 3: return TopAbs_SOLID;
749 default: return TopAbs_SHAPE;
753 //=================================================================================
754 // function : setShapeType()
756 //=================================================================================
757 void GroupGUI_GroupDlg::setShapeType(const TopAbs_ShapeEnum theType)
761 case TopAbs_VERTEX: anId = 0; break;
762 case TopAbs_EDGE: anId = 1; break;
763 case TopAbs_FACE: anId = 2; break;
764 case TopAbs_SOLID: anId = 3; break;
766 setConstructorId(anId);
769 myIsShapeType = true;
770 // workaround to avoid set checked button 0
771 setConstructorId(anId);
775 //=================================================================================
776 // function : activateSelection
777 // purpose : Activate selection in accordance with myEditCurrentArgument
778 //=================================================================================
779 void GroupGUI_GroupDlg::activateSelection()
784 if (!myMainObj->_is_nil() &&
785 !myEditCurrentArgument &&
786 myIsShapeType) // check if shape type is already choosen by user
788 GEOM_Displayer* aDisplayer = getDisplayer();
790 SUIT_ViewWindow* aViewWindow = 0;
791 SUIT_Study* activeStudy = SUIT_Session::session()->activeApplication()->activeStudy();
793 aViewWindow = SUIT_Session::session()->activeApplication()->desktop()->activeWindow();
794 if (aViewWindow == 0) return;
796 SUIT_ViewManager* aViewManager = aViewWindow->getViewManager();
797 if (aViewManager->getType() != OCCViewer_Viewer::Type() &&
798 aViewManager->getType() != SVTK_Viewer::Type())
801 SUIT_ViewModel* aViewModel = aViewManager->getViewModel();
802 SALOME_View* aView = dynamic_cast<SALOME_View*>(aViewModel);
803 if (aView == 0) return;
805 TopoDS_Shape aMainShape = GEOM_Client().GetShape(GeometryGUI::GetGeomGen(), myMainObj);
806 TopoDS_Shape aRestrictionShape;
807 if (subSelectionWay() == ALL_SUBSHAPES)
808 aRestrictionShape = aMainShape;
809 else if (!myInPlaceObj->_is_nil())
810 aRestrictionShape = GEOM_Client().GetShape(GeometryGUI::GetGeomGen(), myInPlaceObj);
813 TopTools_IndexedMapOfShape aSubShapesMap;
814 TopExp::MapShapes(aMainShape, aSubShapesMap);
815 CORBA::String_var aMainEntry = myMainObj->GetStudyEntry();
816 QString anEntryBase = aMainEntry.in();
818 TopExp_Explorer anExp (aRestrictionShape, getShapeType());
819 for (; anExp.More(); anExp.Next())
821 TopoDS_Shape aSubShape = anExp.Current();
822 int index = aSubShapesMap.FindIndex(aSubShape);
823 QString anEntry = anEntryBase + QString("_%1").arg(index);
825 SALOME_Prs* aPrs = aDisplayer->buildSubshapePresentation(aSubShape, anEntry, aView);
827 displayPreview(aPrs, true, false); // append, do not update
830 aDisplayer->UpdateViewer();
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 char* objIOR = GEOMBase::GetIORFromObject(aGroup);
1060 std::string IOR(objIOR);
1063 _PTR(SObject) SO (study->studyDS()->FindObjectIOR(IOR));
1065 _PTR(StudyBuilder) aBuilder (study->studyDS()->NewBuilder());
1066 aBuilder->SetName(SO, getNewObjectName().toLatin1().constData());
1071 objects.push_back(aGroup._retn());
1076 //================================================================
1077 // Function : getFather
1078 // Purpose : Get father object for object to be added in study
1079 // ( called with addInStudy method )
1080 //================================================================
1081 GEOM::GEOM_Object_ptr GroupGUI_GroupDlg::getFather(GEOM::GEOM_Object_ptr theObj)
1083 GEOM::GEOM_Object_var aFatherObj;
1084 if (theObj->GetType() == GEOM_GROUP) {
1085 GEOM::GEOM_IGroupOperations_var anOper = GEOM::GEOM_IGroupOperations::_narrow(getOperation());
1086 aFatherObj = anOper->GetMainShape(theObj);
1088 return aFatherObj._retn();