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
476 if ( myBusy || myMainObj->_is_nil() ) {
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();
620 if ( !app || myMainObj->_is_nil() )
623 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
624 SALOME_ListIO aSelList;
625 aSelMgr->selectedObjects(aSelList);
627 // try to find out and process the global selection
628 // (of not published objects and of published sub-shapes)
630 SALOME_ListIteratorOfListIO anIter (aSelList);
631 for (int i = 0; anIter.More(); anIter.Next(), i++)
633 Handle(SALOME_InteractiveObject) anIObj = anIter.Value();
634 QString anEntry = anIObj->getEntry();
636 int index = anEntry.lastIndexOf(str);
637 if (index > 0) // selection among special preview
639 anEntry.remove(0, index+1);
640 int anIndex = anEntry.toInt();
642 theMapIndex.Add(anIndex);
644 else // selection among published shapes
646 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>(app->activeStudy());
647 if (!appStudy) return 0;
648 _PTR(Study) aStudy = appStudy->studyDS();
650 _PTR(SObject) aSObj (aStudy->FindObjectID(anEntry.toLatin1().constData()));
651 GEOM::GEOM_Object_var aGeomObj =
652 GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aSObj));
654 if (GEOMBase::GetShape(aGeomObj, aShape)) {
655 if (aGeomObj->GetType() == GEOM_GROUP || aShape.ShapeType() == getShapeType()) {
656 TopTools_IndexedMapOfShape aMainMap;
657 TopoDS_Shape aMainShape = GEOM_Client::get_client().GetShape(GeometryGUI::GetGeomGen(), myMainObj);
658 TopExp::MapShapes(aMainShape, aMainMap);
660 TopExp_Explorer anExp (aShape, getShapeType());
661 for (; anExp.More(); anExp.Next()) {
662 TopoDS_Shape aSubShape = anExp.Current();
663 int anIndex = aMainMap.FindIndex(aSubShape);
665 if (subSelectionWay() != ALL_SUBSHAPES &&
666 !myMain2InPlaceIndices.IsBound(anIndex))
668 theMapIndex.Add(anIndex);
677 return theMapIndex.Extent();
680 //=================================================================================
683 //=================================================================================
684 void GroupGUI_GroupDlg::add()
686 TColStd_IndexedMapOfInteger aMapIndex;
687 int nbSel = getSelectedSubshapes(aMapIndex);
689 TColStd_MapOfInteger aMap;
690 for (int i = 0, n = myIdList->count(); i < n; i++)
691 aMap.Add(myIdList->item(i)->text().toInt());
694 bool isBlocked = myIdList->signalsBlocked();
695 myIdList->blockSignals(true);
697 for (int i = 1, n = aMapIndex.Extent(); i <= n; i++) {
698 if (aMap.Contains(aMapIndex(i)))
701 QListWidgetItem* anItem = new QListWidgetItem(QString("%1").arg(aMapIndex(i)));
702 myIdList->addItem(anItem);
703 anItem->setSelected(true);
706 myIdList->blockSignals(isBlocked);
712 //=================================================================================
715 //=================================================================================
716 void GroupGUI_GroupDlg::remove()
718 bool isBlocked = myIdList->signalsBlocked();
719 myIdList->blockSignals(true);
721 QListIterator<QListWidgetItem*> it (myIdList->selectedItems());
725 myIdList->blockSignals(isBlocked);
727 highlightSubShapes();
730 //=================================================================================
731 //function : subSelectionWay
733 //=================================================================================
734 int GroupGUI_GroupDlg::subSelectionWay() const
736 return myRestrictGroup->checkedId();
739 //=================================================================================
740 // function : getShapeType()
742 //=================================================================================
743 TopAbs_ShapeEnum GroupGUI_GroupDlg::getShapeType() const
745 switch (getConstructorId()) {
746 case 0: return TopAbs_VERTEX;
747 case 1: return TopAbs_EDGE;
748 case 2: return TopAbs_FACE;
749 case 3: return TopAbs_SOLID;
750 default: return TopAbs_SHAPE;
754 //=================================================================================
755 // function : setShapeType()
757 //=================================================================================
758 void GroupGUI_GroupDlg::setShapeType(const TopAbs_ShapeEnum theType)
762 case TopAbs_VERTEX: anId = 0; break;
763 case TopAbs_EDGE: anId = 1; break;
764 case TopAbs_FACE: anId = 2; break;
765 case TopAbs_SOLID: anId = 3; break;
767 setConstructorId(anId);
770 myIsShapeType = true;
771 // workaround to avoid set checked button 0
772 setConstructorId(anId);
776 //=================================================================================
777 // function : activateSelection
778 // purpose : Activate selection in accordance with myEditCurrentArgument
779 //=================================================================================
780 void GroupGUI_GroupDlg::activateSelection()
785 if (!myMainObj->_is_nil() &&
786 !myEditCurrentArgument &&
787 myIsShapeType) // check if shape type is already choosen by user
789 GEOM_Displayer* aDisplayer = getDisplayer();
790 int prevDisplayMode = aDisplayer->SetDisplayMode(0);
792 SUIT_ViewWindow* aViewWindow = 0;
793 SUIT_Study* activeStudy = SUIT_Session::session()->activeApplication()->activeStudy();
795 aViewWindow = SUIT_Session::session()->activeApplication()->desktop()->activeWindow();
796 if (aViewWindow == 0) return;
798 SUIT_ViewManager* aViewManager = aViewWindow->getViewManager();
799 if (aViewManager->getType() != OCCViewer_Viewer::Type() &&
800 aViewManager->getType() != SVTK_Viewer::Type())
803 SUIT_ViewModel* aViewModel = aViewManager->getViewModel();
804 SALOME_View* aView = dynamic_cast<SALOME_View*>(aViewModel);
805 if (aView == 0) return;
807 TopoDS_Shape aMainShape = GEOM_Client::get_client().GetShape(GeometryGUI::GetGeomGen(), myMainObj);
808 TopoDS_Shape aRestrictionShape;
809 if (subSelectionWay() == ALL_SUBSHAPES)
810 aRestrictionShape = aMainShape;
811 else if (!myInPlaceObj->_is_nil())
812 aRestrictionShape = GEOM_Client::get_client().GetShape(GeometryGUI::GetGeomGen(), myInPlaceObj);
815 TopTools_IndexedMapOfShape aSubShapesMap;
816 TopExp::MapShapes(aMainShape, aSubShapesMap);
817 CORBA::String_var aMainEntry = myMainObj->GetStudyEntry();
818 QString anEntryBase = aMainEntry.in();
820 TopExp_Explorer anExp (aRestrictionShape, getShapeType());
821 for (; anExp.More(); anExp.Next())
823 TopoDS_Shape aSubShape = anExp.Current();
824 int index = aSubShapesMap.FindIndex(aSubShape);
825 QString anEntry = anEntryBase + QString("_%1").arg(index);
827 SALOME_Prs* aPrs = aDisplayer->buildSubshapePresentation(aSubShape, anEntry, aView);
829 displayPreview(aPrs, true, false); // append, do not update
832 aDisplayer->UpdateViewer();
833 aDisplayer->SetDisplayMode(prevDisplayMode);
836 globalSelection(GEOM_ALLSHAPES);
838 SelectionIntoArgument();
841 //=================================================================================
842 // function : updateState
844 //=================================================================================
845 void GroupGUI_GroupDlg::updateState (bool isAdd)
847 myAddBtn->setEnabled(!myEditCurrentArgument && !CORBA::is_nil(myMainObj) && isAdd);
848 //myShowOnlyBtn->setEnabled(!myEditCurrentArgument && !CORBA::is_nil(myMainObj) && isAdd);
850 bool hasSel = myIdList->selectedItems().count() > 0;
852 myRemBtn->setEnabled(hasSel);
853 myRestrictGroupBox->setEnabled(!CORBA::is_nil(myMainObj));
854 mySelAllBtn->setEnabled(!CORBA::is_nil(myMainObj));
856 mySelBtn2->setEnabled( subSelectionWay() != ALL_SUBSHAPES);
857 myShape2Name->setEnabled(subSelectionWay() != ALL_SUBSHAPES);
858 if (subSelectionWay() == ALL_SUBSHAPES)
859 setInPlaceObj(GEOM::GEOM_Object::_nil());
862 //=================================================================================
863 // function : selectionChanged
865 //=================================================================================
866 void GroupGUI_GroupDlg::selectionChanged()
868 highlightSubShapes();
871 //=================================================================================
872 // function : highlightSubShapes
874 //=================================================================================
875 void GroupGUI_GroupDlg::highlightSubShapes()
877 if (CORBA::is_nil(myMainObj))
880 TColStd_MapOfInteger anIds;
884 int ii = 0, nn = myIdList->count();
885 for (; ii < nn; ii++)
887 if (myIdList->item(ii)->isSelected()) {
888 int id = myIdList->item(ii)->text().toInt();
889 if (subSelectionWay() != ALL_SUBSHAPES &&
890 !myMain2InPlaceIndices.IsBound(id)) {
891 myIdList->item(ii)->setSelected(false);
898 SalomeApp_Application* app = myGeomGUI->getApp();
899 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
900 aSelMgr->clearSelected();
902 SUIT_ViewWindow* aViewWindow = 0;
903 SUIT_Study* activeStudy = app->activeStudy();
905 aViewWindow = app->desktop()->activeWindow();
906 if (aViewWindow == 0) return;
908 SUIT_ViewManager* aViewManager = aViewWindow->getViewManager();
909 if (aViewManager->getType() != OCCViewer_Viewer::Type() &&
910 aViewManager->getType() != SVTK_Viewer::Type())
913 SUIT_ViewModel* aViewModel = aViewManager->getViewModel();
914 SALOME_View* aView = dynamic_cast<SALOME_View*>(aViewModel);
915 if (aView == 0) return;
917 // TODO: use here GEOMBase_Helper::myPreview instead of ic->DisplayedObjects()
919 OCCViewer_Viewer* v3d = ((OCCViewer_ViewManager*)aViewManager)->getOCCViewer();
920 Handle(AIS_InteractiveContext) ic = v3d->getAISContext();
921 AIS_ListOfInteractive List;
922 ic->DisplayedObjects(List);
924 SALOME_ListIO aSelList;
926 // To highlight the selected subshape in Object Browser, if it's already pudlished under the main shape
927 GEOM::GEOM_ILocalOperations_var aLocOp = getGeomEngine()->GetILocalOperations(getStudyId());
928 QMap<int, QString> childsMap;
929 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>(app->activeStudy());
931 _PTR(Study) aStudy = appStudy->studyDS();
932 CORBA::String_var aMainEntry = myMainObj->GetStudyEntry();
933 QString anEntry = aMainEntry.in();
934 _PTR(SObject) aSObj (aStudy->FindObjectID(anEntry.toLatin1().constData()));
935 _PTR(ChildIterator) anIt ( aStudy->NewChildIterator( aSObj ) );
936 for ( anIt->InitEx( true ); anIt->More(); anIt->Next() ) {
937 GEOM::GEOM_Object_var aChild = GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(anIt->Value()));
938 if ( !CORBA::is_nil( aChild ) ) {
939 int index = aLocOp->GetSubShapeIndex(myMainObj, aChild);
940 CORBA::String_var aChildEntry = aChild->GetStudyEntry();
941 QString anEntry = aChildEntry.in();
942 childsMap.insert(index, anEntry);
947 AIS_ListIteratorOfListOfInteractive ite (List);
948 for (; ite.More(); ite.Next()) {
949 if (ite.Value()->IsInstance(STANDARD_TYPE(GEOM_AISShape))) {
950 Handle(GEOM_AISShape) aSh = Handle(GEOM_AISShape)::DownCast(ite.Value());
952 Handle(SALOME_InteractiveObject) anIO = aSh->getIO();
953 QString anEntry = anIO->getEntry();
954 int index = anEntry.lastIndexOf("_");
955 anEntry.remove(0, index+1);
956 int anIndex = anEntry.toInt();
957 if ( anIds.Contains(anIndex) ) {
958 aSelList.Append(anIO);
959 if ( childsMap.contains ( anIndex )) {
960 Handle(SALOME_InteractiveObject) tmpIO = new SALOME_InteractiveObject( childsMap.value(anIndex).toLatin1().constData(), "GEOM", "TEMP_IO" );
961 aSelList.Append(tmpIO);
967 aSelMgr->setSelectedObjects(aSelList);
972 updateState(aSelList.Extent() > 0);
974 myAddBtn->setEnabled(true);
975 myAddBtn->setEnabled(true);
976 myRemBtn->setEnabled(true);
980 //=================================================================================
981 // function : createOperation
983 //=================================================================================
984 GEOM::GEOM_IOperations_ptr GroupGUI_GroupDlg::createOperation()
986 return getGeomEngine()->GetIGroupOperations(getStudyId());
989 #define RETURN_WITH_MSG(a, b) \
995 //=================================================================================
996 // function : isValid()
997 // purpose : Verify validity of input data
998 //=================================================================================
999 bool GroupGUI_GroupDlg::isValid(QString& theMessage)
1001 SalomeApp_Study* study = getStudy();
1003 RETURN_WITH_MSG (!study->studyDS()->GetProperties()->IsLocked(), tr("GEOM_STUDY_LOCKED"))
1005 if (myMode == CreateGroup) {
1006 RETURN_WITH_MSG(!CORBA::is_nil(myMainObj), tr("NO_MAIN_OBJ"))
1009 RETURN_WITH_MSG(!CORBA::is_nil(myMainObj), tr("NO_GROUP"))
1012 QString aName (getNewObjectName());
1013 RETURN_WITH_MSG (!aName.trimmed().isEmpty(), tr("EMPTY_NAME"))
1015 RETURN_WITH_MSG (myIdList->count(), tr("EMPTY_LIST"))
1019 //=================================================================================
1020 // function : execute
1022 //=================================================================================
1023 bool GroupGUI_GroupDlg::execute(ObjectList& objects)
1025 GEOM::GEOM_IGroupOperations_var anOper = GEOM::GEOM_IGroupOperations::_narrow(getOperation());
1027 GEOM::GEOM_Object_var aGroup;
1028 if (myMode == CreateGroup)
1029 aGroup = anOper->CreateGroup(myMainObj, getShapeType());
1030 else if (myMode == EditGroup)
1033 if (CORBA::is_nil(aGroup) || (myMode == CreateGroup && !anOper->IsDone()))
1036 GEOM::ListOfLong_var aCurrList = anOper->GetObjects(aGroup);
1037 if (!anOper->IsDone())
1040 if (aCurrList->length() > 0)
1042 anOper->DifferenceIDs(aGroup, aCurrList);
1043 if (!anOper->IsDone())
1047 int ii, nn = myIdList->count();
1050 GEOM::ListOfLong_var aNewList = new GEOM::ListOfLong;
1051 aNewList->length(nn);
1052 for (ii = 0; ii < nn; ii++) {
1053 aNewList[ii] = myIdList->item(ii)->text().toInt();
1055 anOper->UnionIDs(aGroup, aNewList);
1056 if (!anOper->IsDone())
1060 SalomeApp_Study* study = getStudy();
1062 QString objIOR = GEOMBase::GetIORFromObject(aGroup);
1064 _PTR(SObject) SO (study->studyDS()->FindObjectIOR(objIOR.toLatin1().constData()));
1066 _PTR(StudyBuilder) aBuilder (study->studyDS()->NewBuilder());
1067 aBuilder->SetName(SO, getNewObjectName().toLatin1().constData());
1072 objects.push_back(aGroup._retn());
1077 //================================================================
1078 // Function : getFather
1079 // Purpose : Get father object for object to be added in study
1080 // ( called with addInStudy method )
1081 //================================================================
1082 GEOM::GEOM_Object_ptr GroupGUI_GroupDlg::getFather(GEOM::GEOM_Object_ptr theObj)
1084 GEOM::GEOM_Object_var aFatherObj;
1085 if (theObj->GetType() == GEOM_GROUP) {
1086 GEOM::GEOM_IGroupOperations_var anOper = GEOM::GEOM_IGroupOperations::_narrow(getOperation());
1087 aFatherObj = anOper->GetMainShape(theObj);
1089 return aFatherObj._retn();