1 // Copyright (C) 2007-2012 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),
78 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
80 QPixmap image0 (resMgr->loadPixmap("GEOM", tr("ICON_OBJBROWSER_VERTEX")));
81 QPixmap image1 (resMgr->loadPixmap("GEOM", tr("ICON_OBJBROWSER_EDGE")));
82 QPixmap image2 (resMgr->loadPixmap("GEOM", tr("ICON_OBJBROWSER_FACE")));
83 QPixmap image3 (resMgr->loadPixmap("GEOM", tr("ICON_OBJBROWSER_SOLID")));
84 QPixmap iconSelect (resMgr->loadPixmap("GEOM", tr("ICON_SELECT")));
86 setWindowTitle(myMode == CreateGroup ? tr("CREATE_GROUP_TITLE") : tr("EDIT_GROUP_TITLE"));
88 // Shape type button group
89 mainFrame()->GroupConstructors->setEnabled(myMode == CreateGroup);
90 mainFrame()->GroupConstructors->setTitle(tr("SHAPE_TYPE"));
91 mainFrame()->RadioButton1->setIcon(image0);
92 mainFrame()->RadioButton2->setIcon(image1);
93 mainFrame()->RadioButton3->setIcon(image2);
94 mainFrame()->RadioButton4->setIcon(image3);
95 mainFrame()->RadioButton4->show();
98 mainFrame()->GroupBoxName->setTitle(tr("GROUP_NAME"));
100 // Main shape and sub-shapes
101 QGroupBox* GroupMedium = new QGroupBox(tr("MAIN_SUB_SHAPES"), centralWidget());
102 QGridLayout* aMedLayout = new QGridLayout(GroupMedium);
103 aMedLayout->setMargin(9);
104 aMedLayout->setSpacing(6);
106 QLabel* aMainLabel = new QLabel(tr("MAIN_SHAPE"), GroupMedium);
108 mySelBtn = new QPushButton(GroupMedium);
109 mySelBtn->setIcon(iconSelect);
110 mySelBtn->setEnabled(myMode == CreateGroup);
112 myMainName = new QLineEdit(GroupMedium);
113 myMainName->setReadOnly(true);
114 myMainName->setEnabled(myMode == CreateGroup);
116 myRestrictGroupBox = new QGroupBox(tr("SHAPE_SEL_RESTR"), GroupMedium);
117 myRestrictGroup = new QButtonGroup(myRestrictGroupBox);
118 QRadioButton* allSubs = new QRadioButton(tr("NO_RESTR") , myRestrictGroupBox);
119 QRadioButton* inPlaceSubs = new QRadioButton(tr("GEOM_PARTS_OF_SHAPE2"), myRestrictGroupBox);
120 QRadioButton* shape2Subs = new QRadioButton(tr("SUBSHAPES_OF_SHAPE2") , myRestrictGroupBox);
121 QGridLayout* aRestrictLayout = new QGridLayout(myRestrictGroupBox);
123 QLabel* aSecondLabel = new QLabel(tr("SECOND_SHAPE"), myRestrictGroupBox);
124 mySelBtn2 = new QPushButton(myRestrictGroupBox);
125 mySelBtn2->setIcon(iconSelect);
126 mySelBtn2->setEnabled(false);
127 myShape2Name = new QLineEdit(myRestrictGroupBox);
128 myShape2Name->setReadOnly(true);
129 myShape2Name->setEnabled(false);
131 aRestrictLayout->setMargin(9);
132 aRestrictLayout->setSpacing(6);
133 aRestrictLayout->addWidget(allSubs, 0, 0, 1, 3);
134 aRestrictLayout->addWidget(inPlaceSubs, 1, 0, 1, 3);
135 aRestrictLayout->addWidget(shape2Subs, 2, 0, 1, 3);
136 aRestrictLayout->addWidget(aSecondLabel, 3, 0);
137 aRestrictLayout->addWidget(mySelBtn2, 3, 1);
138 aRestrictLayout->addWidget(myShape2Name, 3, 2);
139 myRestrictGroup->addButton(allSubs, ALL_SUBSHAPES);
140 myRestrictGroup->addButton(inPlaceSubs, GET_IN_PLACE);
141 myRestrictGroup->addButton(shape2Subs, SUBSHAPES_OF_SHAPE2);
142 myRestrictGroupBox->setEnabled(!CORBA::is_nil(myMainObj));
143 allSubs->setChecked(true);
145 myShowOnlyBtn = new QPushButton(tr("SHOW_ONLY_SELECTED"), GroupMedium);
146 myHideSelBtn = new QPushButton(tr("HIDE_SELECTED"), GroupMedium);
147 myShowAllBtn = new QPushButton(tr("SHOW_ALL_SUB_SHAPES"), GroupMedium);
149 mySelAllBtn = new QPushButton(tr("SELECT_ALL"), GroupMedium);
150 myAddBtn = new QPushButton(tr("ADD"), GroupMedium);
151 myRemBtn = new QPushButton(tr("REMOVE"), GroupMedium);
153 myIdList = new QListWidget(GroupMedium);
155 myIdList->setSelectionMode(QAbstractItemView::ExtendedSelection);
156 myIdList->setFlow(QListView::TopToBottom);
157 myIdList->setWrapping(true);
159 aMedLayout->addWidget(aMainLabel, 0, 0);
160 aMedLayout->addWidget(mySelBtn, 0, 1);
161 aMedLayout->addWidget(myMainName, 0, 2, 1, 2);
162 aMedLayout->addWidget(myRestrictGroupBox, 1, 0, 4, 3);
164 aMedLayout->addWidget(myShowOnlyBtn, 1, 3);
165 aMedLayout->addWidget(myHideSelBtn, 2, 3);
166 aMedLayout->addWidget(myShowAllBtn, 3, 3);
168 aMedLayout->addWidget(myIdList, 5, 0, 4, 3);
169 aMedLayout->addWidget(mySelAllBtn, 5, 3);
170 aMedLayout->addWidget(myAddBtn, 6, 3);
171 aMedLayout->addWidget(myRemBtn, 7, 3);
173 aMedLayout->setColumnStretch(2, 5);
174 aMedLayout->setRowStretch(5, 5);
175 aMedLayout->setRowStretch(8, 5);
177 QVBoxLayout* layout = new QVBoxLayout(centralWidget());
178 layout->setMargin(0); layout->setSpacing(6);
179 layout->addWidget(GroupMedium);
181 setHelpFileName("work_with_groups_page.html");
187 GroupGUI_GroupDlg::~GroupGUI_GroupDlg()
189 if (myIsHiddenMain) {
190 GEOM_Displayer* aDisplayer = getDisplayer();
191 aDisplayer->Display(myMainObj);
192 myIsHiddenMain = false;
196 //=================================================================================
199 //=================================================================================
200 void GroupGUI_GroupDlg::Init()
202 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
204 //unset shape type to avoid preparation of selection before exact user shape type selection
205 unsetConstructorId();
206 myIsShapeType = false;
208 if (myMode == CreateGroup) {
209 initName(tr("GROUP_PREFIX"));
211 // Get ready for main shape selection
212 myEditCurrentArgument = myMainName;
214 connect(this, SIGNAL(constructorsClicked(int)), this, SLOT(ConstructorsClicked(int)));
215 connect(mySelBtn, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
216 connect(mySelBtn2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
218 else if (myMode == EditGroup) {
219 SALOME_ListIO aSelList;
220 aSelMgr->selectedObjects(aSelList);
222 if (aSelList.Extent()) {
223 GEOM::GEOM_Object_var anObj =
224 GEOMBase::ConvertIOinGEOMObject(aSelList.First());
226 if (!CORBA::is_nil(anObj) && anObj->GetType() == GEOM_GROUP) {
229 mainFrame()->ResultName->setText(GEOMBase::GetName(myGroup));
231 GEOM::GEOM_IGroupOperations_var anOper = GEOM::GEOM_IGroupOperations::_narrow(getOperation());
232 myMainObj = anOper->GetMainShape(myGroup);
233 if (!CORBA::is_nil(myMainObj))
234 myMainName->setText(GEOMBase::GetName(myMainObj));
236 setShapeType((TopAbs_ShapeEnum)anOper->GetType(myGroup));
238 GEOM::ListOfLong_var aCurrList = anOper->GetObjects(myGroup);
239 for (int i = 0, n = aCurrList->length(); i < n; i++)
240 myIdList->addItem(new QListWidgetItem(QString("%1").arg(aCurrList[i])));
242 myEditCurrentArgument = 0;
244 connect(mySelBtn2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
248 connect(aSelMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
250 connect(buttonOk(), SIGNAL(clicked()), this, SLOT(ClickOnOk()));
251 connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
253 connect(myRestrictGroup, SIGNAL(buttonClicked(int)), this, SLOT(SetEditCurrentArgument()));
254 connect(mySelAllBtn, SIGNAL(clicked()), this, SLOT(selectAllSubShapes()));
255 connect(myAddBtn, SIGNAL(clicked()), this, SLOT(add()));
256 connect(myRemBtn, SIGNAL(clicked()), this, SLOT(remove()));
257 connect(myShowOnlyBtn, SIGNAL(clicked()), this, SLOT(showOnlySelected()));
258 connect(myHideSelBtn, SIGNAL(clicked()), this, SLOT(showOnlySelected()));
259 connect(myShowAllBtn, SIGNAL(clicked()), this, SLOT(showOnlySelected()));
260 connect(myIdList, SIGNAL(itemSelectionChanged()), this, SLOT(selectionChanged()));
262 setInPlaceObj(GEOM::GEOM_Object::_nil());
264 myBusy = true; // just activate but do not select in the list
269 //=================================================================================
270 // function : enterEvent()
272 //=================================================================================
273 void GroupGUI_GroupDlg::enterEvent(QEvent* e)
275 if (!buttonCancel()->isEnabled())
276 ActivateThisDialog();
279 //=================================================================================
280 //function : closeEvent
281 //purpose : remove temporary geom object
282 //=================================================================================
283 void GroupGUI_GroupDlg::closeEvent(QCloseEvent* e)
285 setInPlaceObj(GEOM::GEOM_Object::_nil());
288 GEOMBase_Skeleton::closeEvent(e);
291 //=================================================================================
292 // function : ClickOnOk()
294 //=================================================================================
295 void GroupGUI_GroupDlg::ClickOnOk()
297 setIsApplyAndClose(true);
300 setIsApplyAndClose(false);
303 //=================================================================================
304 // function : ClickOnApply()
306 //=================================================================================
307 bool GroupGUI_GroupDlg::ClickOnApply()
309 if(!isApplyAndClose())
310 setIsDisableBrowsing( true );
312 if (!onAccept(myMode == CreateGroup, true,isApplyAndClose()))
315 if(!isApplyAndClose())
316 setIsDisableBrowsing( false );
318 if (myMode == CreateGroup)
322 ConstructorsClicked(getConstructorId());
330 //=================================================================================
331 // function : ActivateThisDialog()
333 //=================================================================================
334 void GroupGUI_GroupDlg::ActivateThisDialog()
336 GEOMBase_Skeleton::ActivateThisDialog();
338 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
339 this, SLOT(SelectionIntoArgument()));
344 //=================================================================================
345 // function : SetEditCurrentArgument()
347 //=================================================================================
348 void GroupGUI_GroupDlg::SetEditCurrentArgument()
350 QPushButton* send = (QPushButton*)sender();
352 if (send == mySelBtn) {
353 myEditCurrentArgument = myMainName;
354 myShape2Name->setText("");
356 else if (send == mySelBtn2 || sender() == myRestrictGroup) {
357 setInPlaceObj(GEOM::GEOM_Object::_nil());
358 myShape2Name->setText("");
359 if (subSelectionWay() != ALL_SUBSHAPES) {
360 myEditCurrentArgument = myShape2Name;
363 myEditCurrentArgument = 0;
372 //=================================================================================
373 // function : onGetInPlace()
375 //=================================================================================
376 void GroupGUI_GroupDlg::onGetInPlace()
378 setInPlaceObj(GEOM::GEOM_Object::_nil());
379 myEditCurrentArgument->setText("");
381 bool isBlocked = myIdList->signalsBlocked();
382 myIdList->blockSignals(true);
383 myIdList->clearSelection();
384 myIdList->blockSignals(isBlocked);
386 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
387 SALOME_ListIO aSelList;
388 aSelMgr->selectedObjects(aSelList);
390 if (aSelList.Extent() != 1)
393 GEOM::GEOM_Object_var anObj =
394 GEOMBase::ConvertIOinGEOMObject(aSelList.First());
395 if (GEOMBase::IsShape(anObj)) {
396 if (!anObj->_is_equivalent(myMainObj) && !anObj->_is_equivalent(myGroup)) {
397 SUIT_OverrideCursor wc;
398 myEditCurrentArgument->setText(GEOMBase::GetName(anObj));
399 GEOM::GEOM_IShapesOperations_var aShapesOp =
400 getGeomEngine()->GetIShapesOperations(getStudyId());
401 if (subSelectionWay() == GET_IN_PLACE) {
402 GEOM::GEOM_Object_var aGetInPlaceObj = aShapesOp->GetInPlace(myMainObj, anObj);
403 setInPlaceObj(aGetInPlaceObj);
406 bool isVisible = true;
407 if (SALOME_View* view = GEOM_Displayer::GetActiveView())
408 isVisible = view->isVisible(aSelList.First());
409 setInPlaceObj(anObj, isVisible);
411 myEditCurrentArgument = 0;
412 //myBusy = true; // just activate but do not select in the list
419 //=================================================================================
420 //function : setInPlaceObj
421 //purpose : temporarily add an object to study and remove old InPlaceObj
422 //=================================================================================
423 void GroupGUI_GroupDlg::setInPlaceObj(GEOM::GEOM_Object_var theObj, const bool isVisible)
425 if (!myInPlaceObj->_is_equivalent(theObj))
427 myInPlaceObj = theObj;
430 // build map of indices
431 myMain2InPlaceIndices.Clear();
432 if (!myInPlaceObj->_is_nil()) {
433 GEOM::GEOM_IShapesOperations_var aShapesOp = getGeomEngine()->GetIShapesOperations(getStudyId());
434 GEOM::GEOM_ILocalOperations_var aLocOp = getGeomEngine()->GetILocalOperations(getStudyId());
436 GEOM::ListOfGO_var aSubObjects = aShapesOp->MakeExplode(myInPlaceObj, getShapeType(), false);
437 for ( int i = 0; i < aSubObjects->length(); i++ )
439 GEOM::ListOfLong_var aCurrList = aShapesOp->GetSameIDs( myMainObj, aSubObjects[i] );
440 if( aCurrList->length() > 1 ) {
441 //rnv : To Fix the 21561: EDF 2184 GEOM: Group with second shape restriction.
442 // In case if GetSameIDs(...) method return more then one ID use
443 // GetSharedShapes(...) method to get sub-shapes of the second shape.
444 GEOM::ListOfGO_var aSubObjects2 = aShapesOp->GetSharedShapes( myMainObj, aSubObjects[i], getShapeType() );
445 for( int j = 0; j < aSubObjects2->length(); j++ ) {
446 CORBA::Long aMainIndex = aLocOp->GetSubShapeIndex( myMainObj, aSubObjects2[j] );
447 CORBA::Long aPlaceIndex = aLocOp->GetSubShapeIndex( myInPlaceObj, aSubObjects[i]);
448 if ( aMainIndex >= 0 && aPlaceIndex > 0 ) {
449 myMain2InPlaceIndices.Bind( aMainIndex, aPlaceIndex );
452 } else if(aCurrList->length() > 0 ) {
453 CORBA::Long aMainIndex = aCurrList[0];
454 CORBA::Long aPlaceIndex = aLocOp->GetSubShapeIndex( myInPlaceObj, aSubObjects[i] );
455 if ( aMainIndex >= 0 && aPlaceIndex > 0) {
456 myMain2InPlaceIndices.Bind( aMainIndex, aPlaceIndex );
461 myInPlaceObjSelectState = subSelectionWay();
462 if (myInPlaceObjSelectState == SUBSHAPES_OF_SHAPE2 && !isVisible)
463 myInPlaceObjSelectState = SUBSHAPES_OF_INVISIBLE_SHAPE2;
466 //=================================================================================
467 // function : SelectionIntoArgument()
468 // purpose : Called when selection has changed
469 //=================================================================================
470 void GroupGUI_GroupDlg::SelectionIntoArgument()
472 if (subSelectionWay() != ALL_SUBSHAPES && myEditCurrentArgument == myShape2Name) {
477 if (myEditCurrentArgument == myMainName) { // Selection of a main shape is active
478 myEditCurrentArgument->setText("");
481 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
482 SALOME_ListIO aSelList;
483 aSelMgr->selectedObjects(aSelList);
484 int nbSel = aSelList.Extent();
487 GEOM::GEOM_Object_var anObj =
488 GEOMBase::ConvertIOinGEOMObject(aSelList.First());
490 if (GEOMBase::IsShape(anObj)) {
491 if (myIsHiddenMain) {
492 GEOM_Displayer* aDisplayer = getDisplayer();
493 aDisplayer->Display(myMainObj);
494 myIsHiddenMain = false;
497 myEditCurrentArgument->setText(GEOMBase::GetName(anObj));
498 // activate sub-shapes selection by default
499 myEditCurrentArgument = 0;
505 if (myIsHiddenMain) {
506 GEOM_Displayer* aDisplayer = getDisplayer();
507 aDisplayer->Display(myMainObj);
508 myIsHiddenMain = false;
510 myMainObj = GEOM::GEOM_Object::_nil();
513 else { // an attempt to synchronize list box selection with 3d viewer
514 if (myBusy || myMainObj->_is_nil()) {
518 bool isBlocked = myIdList->signalsBlocked();
519 myIdList->blockSignals(true);
520 myIdList->clearSelection();
522 TColStd_IndexedMapOfInteger aMapIndex;
523 int nbSel = getSelectedSubshapes(aMapIndex);
527 for (int i = 0, n = myIdList->count(); i < n; i++)
528 aMap.insert(myIdList->item(i)->text().toInt(), i);
530 bool highlight = false;
531 for (int ii = 1, nn = aMapIndex.Extent(); ii <= nn; ii++) {
532 if (aMap.contains(aMapIndex(ii))) {
533 myIdList->item(aMap[aMapIndex(ii)])->setSelected(true);
538 highlightSubShapes();
540 myIdList->blockSignals(isBlocked);
546 //=================================================================================
547 // function : ConstructorsClicked()
548 // purpose : Radio button management
549 //=================================================================================
550 void GroupGUI_GroupDlg::ConstructorsClicked(int constructorId)
552 if (getConstructorId() != constructorId)
553 setConstructorId(constructorId);
555 myIsShapeType = true;
557 myEditCurrentArgument = 0;
559 setInPlaceObj(myInPlaceObj); // to rebuild myMain2InPlaceIndices
564 //=================================================================================
565 // function : selectAllSubShapes
567 //=================================================================================
568 void GroupGUI_GroupDlg::selectAllSubShapes()
570 if (CORBA::is_nil(myMainObj) || !myIsShapeType)
573 GEOM::ListOfLong_var aSubShapes;
574 GEOM::GEOM_IShapesOperations_var aShOp = getGeomEngine()->GetIShapesOperations(getStudyId());
575 aSubShapes = aShOp->SubShapeAllIDs(myMainObj, getShapeType(), false);
576 if (aSubShapes->length() > 0) {
577 if (subSelectionWay() == ALL_SUBSHAPES)
579 myIdList->clear(); // for sorted final list?
581 if (!aShOp->IsDone())
586 aSubShapes = new GEOM::ListOfLong();
587 aSubShapes->length(myMain2InPlaceIndices.Extent());
588 TColStd_DataMapIteratorOfDataMapOfIntegerInteger m2ip (myMain2InPlaceIndices);
589 for (int i = 0; m2ip.More(); i++, m2ip.Next())
590 aSubShapes[i] = m2ip.Key();
593 bool isBlocked = myIdList->signalsBlocked();
594 myIdList->blockSignals(true);
596 for (int i = 0, n = aSubShapes->length(); i < n; i++) {
597 CORBA::Long anIndex = aSubShapes[i];
601 QListWidgetItem* anItem = 0;
602 QString text = QString("%1").arg(anIndex);
603 if (!myInPlaceObj->_is_nil()) {
604 QList<QListWidgetItem*> found = myIdList->findItems(text, Qt::MatchExactly);
605 if (found.count()) anItem = found[0];
608 anItem = new QListWidgetItem(text);
609 myIdList->addItem(anItem);
611 anItem->setSelected(true);
614 myIdList->blockSignals(isBlocked);
615 highlightSubShapes();
619 //=================================================================================
620 // function : showOnlySelected
622 //=================================================================================
623 void GroupGUI_GroupDlg::showOnlySelected()
625 if (CORBA::is_nil(myMainObj) || !myIsShapeType)
628 QPushButton* send = (QPushButton*)sender();
629 if (send == myShowAllBtn) {
634 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
635 SALOME_ListIO aSelList;
636 aSelMgr->selectedObjects(aSelList);
638 GEOM_Displayer* aDisplayer = getDisplayer();
640 if (send == myHideSelBtn) {
641 aDisplayer->Erase(aSelList, /*forced=*/false, /*updateViewer=*/true);
644 // Mantis issue 0021421: do not hide main shape, if explode on VERTEX
645 SALOME_View* view = GEOM_Displayer::GetActiveView();
647 CORBA::String_var aMainEntry = myMainObj->GetStudyEntry();
648 Handle(SALOME_InteractiveObject) io =
649 new SALOME_InteractiveObject (aMainEntry.in(), "GEOM", "TEMP_IO");
650 if (view->isVisible(io)) myIsHiddenMain = true;
653 aDisplayer->EraseAll(/*forced = false, updateViewer = true*/);
654 aDisplayer->Display(aSelList, true);
656 // Mantis issue 0021421: do not hide main shape, if explode on VERTEX
657 if (getShapeType() == TopAbs_VERTEX && myIsHiddenMain) {
658 aDisplayer->Display(myMainObj);
661 // for the case when selected ids were not displayed in the viewer: Mantis issue 0021367
662 highlightSubShapes();
666 //=================================================================================
667 // function : getSelectedSubshapes
669 //=================================================================================
670 int GroupGUI_GroupDlg::getSelectedSubshapes (TColStd_IndexedMapOfInteger& theMapIndex)
674 SalomeApp_Application* app = myGeomGUI->getApp();
675 if (!app || myMainObj->_is_nil())
678 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
679 SALOME_ListIO aSelList;
680 aSelMgr->selectedObjects(aSelList);
682 // try to find out and process the global selection
683 // (of not published objects and of published sub-shapes)
685 SALOME_ListIteratorOfListIO anIter (aSelList);
686 for (int i = 0; anIter.More(); anIter.Next(), i++)
688 Handle(SALOME_InteractiveObject) anIObj = anIter.Value();
689 QString anEntry = anIObj->getEntry();
691 int index = anEntry.lastIndexOf(str);
692 if (index > 0) // selection among special preview
694 anEntry.remove(0, index+1);
695 int anIndex = anEntry.toInt();
697 theMapIndex.Add(anIndex);
699 else // selection among published shapes
701 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>(app->activeStudy());
702 if (!appStudy) return 0;
703 _PTR(Study) aStudy = appStudy->studyDS();
705 _PTR(SObject) aSObj (aStudy->FindObjectID(anEntry.toLatin1().constData()));
706 GEOM::GEOM_Object_var aGeomObj =
707 GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aSObj));
709 if (GEOMBase::GetShape(aGeomObj, aShape)) {
710 if (aGeomObj->GetType() == GEOM_GROUP || aShape.ShapeType() == getShapeType()) {
711 TopTools_IndexedMapOfShape aMainMap;
712 TopoDS_Shape aMainShape = GEOM_Client::get_client().GetShape(GeometryGUI::GetGeomGen(), myMainObj);
713 TopExp::MapShapes(aMainShape, aMainMap);
715 TopExp_Explorer anExp (aShape, getShapeType());
716 for (; anExp.More(); anExp.Next()) {
717 TopoDS_Shape aSubShape = anExp.Current();
718 int anIndex = aMainMap.FindIndex(aSubShape);
720 if (subSelectionWay() != ALL_SUBSHAPES &&
721 !myMain2InPlaceIndices.IsBound(anIndex))
723 theMapIndex.Add(anIndex);
732 return theMapIndex.Extent();
735 //=================================================================================
738 //=================================================================================
739 void GroupGUI_GroupDlg::add()
741 TColStd_IndexedMapOfInteger aMapIndex;
742 int nbSel = getSelectedSubshapes(aMapIndex);
744 TColStd_MapOfInteger aMap;
745 for (int i = 0, n = myIdList->count(); i < n; i++)
746 aMap.Add(myIdList->item(i)->text().toInt());
749 bool isBlocked = myIdList->signalsBlocked();
750 myIdList->blockSignals(true);
752 for (int i = 1, n = aMapIndex.Extent(); i <= n; i++) {
753 if (aMap.Contains(aMapIndex(i)))
756 QListWidgetItem* anItem = new QListWidgetItem(QString("%1").arg(aMapIndex(i)));
757 myIdList->addItem(anItem);
758 anItem->setSelected(true);
761 myIdList->blockSignals(isBlocked);
767 //=================================================================================
770 //=================================================================================
771 void GroupGUI_GroupDlg::remove()
773 bool isBlocked = myIdList->signalsBlocked();
774 myIdList->blockSignals(true);
776 QListIterator<QListWidgetItem*> it (myIdList->selectedItems());
780 myIdList->blockSignals(isBlocked);
782 highlightSubShapes();
785 //=================================================================================
786 //function : subSelectionWay
788 //=================================================================================
789 int GroupGUI_GroupDlg::subSelectionWay() const
791 return myRestrictGroup->checkedId();
794 //=================================================================================
795 // function : getShapeType()
797 //=================================================================================
798 TopAbs_ShapeEnum GroupGUI_GroupDlg::getShapeType() const
800 switch (getConstructorId()) {
801 case 0: return TopAbs_VERTEX;
802 case 1: return TopAbs_EDGE;
803 case 2: return TopAbs_FACE;
804 case 3: return TopAbs_SOLID;
805 default: return TopAbs_SHAPE;
809 //=================================================================================
810 // function : setShapeType()
812 //=================================================================================
813 void GroupGUI_GroupDlg::setShapeType(const TopAbs_ShapeEnum theType)
817 case TopAbs_VERTEX: anId = 0; break;
818 case TopAbs_EDGE: anId = 1; break;
819 case TopAbs_FACE: anId = 2; break;
820 case TopAbs_SOLID: anId = 3; break;
822 setConstructorId(anId);
825 myIsShapeType = true;
826 // workaround to avoid set checked button 0
827 setConstructorId(anId);
831 //=================================================================================
832 // function : activateSelection
833 // purpose : Activate selection in accordance with myEditCurrentArgument
834 //=================================================================================
835 void GroupGUI_GroupDlg::activateSelection()
837 bool isApply = ((QPushButton*)sender() == buttonApply());
842 if (!myMainObj->_is_nil() &&
843 !myEditCurrentArgument &&
844 myIsShapeType) // check if shape type is already choosen by user
846 GEOM_Displayer* aDisplayer = getDisplayer();
848 // Mantis issue 0021421: do not hide main shape, if explode on VERTEX
849 if (getShapeType() == TopAbs_VERTEX) {
851 aDisplayer->Display(myMainObj);
854 SALOME_View* view = GEOM_Displayer::GetActiveView();
856 CORBA::String_var aMainEntry = myMainObj->GetStudyEntry();
857 Handle(SALOME_InteractiveObject) io =
858 new SALOME_InteractiveObject (aMainEntry.in(), "GEOM", "TEMP_IO");
859 if (view->isVisible(io)) {
860 aDisplayer->Erase(myMainObj, false, false);
861 myIsHiddenMain = true;
866 int prevDisplayMode = aDisplayer->SetDisplayMode(0);
868 SUIT_ViewWindow* aViewWindow = 0;
869 SUIT_Study* activeStudy = SUIT_Session::session()->activeApplication()->activeStudy();
871 aViewWindow = SUIT_Session::session()->activeApplication()->desktop()->activeWindow();
872 if (aViewWindow == 0) return;
874 SUIT_ViewManager* aViewManager = aViewWindow->getViewManager();
875 if (aViewManager->getType() != OCCViewer_Viewer::Type() &&
876 aViewManager->getType() != SVTK_Viewer::Type())
879 SUIT_ViewModel* aViewModel = aViewManager->getViewModel();
880 SALOME_View* aView = dynamic_cast<SALOME_View*>(aViewModel);
881 if (aView == 0) return;
883 TopoDS_Shape aMainShape = GEOM_Client::get_client().GetShape(GeometryGUI::GetGeomGen(), myMainObj);
884 TopoDS_Shape aRestrictionShape;
886 if (subSelectionWay() == ALL_SUBSHAPES) {
887 aRestrictionShape = aMainShape;
889 TopTools_IndexedMapOfShape aSubShapesMap;
890 TopExp::MapShapes(aMainShape, aSubShapesMap);
891 CORBA::String_var aMainEntry = myMainObj->GetStudyEntry();
892 QString anEntryBase = aMainEntry.in();
894 TopExp_Explorer anExp (aRestrictionShape, getShapeType());
895 for (; anExp.More(); anExp.Next()) {
896 TopoDS_Shape aSubShape = anExp.Current();
897 int index = aSubShapesMap.FindIndex(aSubShape);
898 QString anEntry = anEntryBase + QString("_%1").arg(index);
900 SALOME_Prs* aPrs = aDisplayer->buildSubshapePresentation(aSubShape, anEntry, aView);
902 displayPreview(aPrs, true, false); // append, do not update
903 // TODO: map or delete Prs
907 else if (!myInPlaceObj->_is_nil()) {
908 TopTools_IndexedMapOfShape aSubShapesMap;
909 TopExp::MapShapes(aMainShape, aSubShapesMap);
910 CORBA::String_var aMainEntry = myMainObj->GetStudyEntry();
911 QString anEntryBase = aMainEntry.in();
913 TColStd_DataMapIteratorOfDataMapOfIntegerInteger aM2IPit (myMain2InPlaceIndices);
914 for (; aM2IPit.More(); aM2IPit.Next()) {
915 int index = aM2IPit.Key();
916 TopoDS_Shape aSubShape = aSubShapesMap.FindKey(index);
917 QString anEntry = anEntryBase + QString("_%1").arg(index);
919 SALOME_Prs* aPrs = aDisplayer->buildSubshapePresentation(aSubShape, anEntry, aView);
921 displayPreview(aPrs, true, false); // append, do not update
927 aDisplayer->UpdateViewer();
928 aDisplayer->SetDisplayMode(prevDisplayMode);
932 globalSelection(GEOM_ALLSHAPES);
934 SelectionIntoArgument();
937 //=================================================================================
938 // function : updateState
940 //=================================================================================
941 void GroupGUI_GroupDlg::updateState (bool isAdd)
943 myAddBtn->setEnabled(!myEditCurrentArgument && !CORBA::is_nil(myMainObj) && isAdd);
944 //myShowOnlyBtn->setEnabled(!myEditCurrentArgument && !CORBA::is_nil(myMainObj) && isAdd);
946 bool hasSel = myIdList->selectedItems().count() > 0;
948 myRemBtn->setEnabled(hasSel);
949 myRestrictGroupBox->setEnabled(!CORBA::is_nil(myMainObj));
950 mySelAllBtn->setEnabled(!CORBA::is_nil(myMainObj));
952 mySelBtn2->setEnabled(subSelectionWay() != ALL_SUBSHAPES);
953 myShape2Name->setEnabled(subSelectionWay() != ALL_SUBSHAPES);
954 if (subSelectionWay() == ALL_SUBSHAPES)
955 setInPlaceObj(GEOM::GEOM_Object::_nil());
958 //=================================================================================
959 // function : selectionChanged
961 //=================================================================================
962 void GroupGUI_GroupDlg::selectionChanged()
964 highlightSubShapes();
967 //=================================================================================
968 // function : highlightSubShapes
970 //=================================================================================
971 void GroupGUI_GroupDlg::highlightSubShapes()
973 if (CORBA::is_nil(myMainObj))
976 TColStd_MapOfInteger anIds;
980 int ii = 0, nn = myIdList->count();
981 for (; ii < nn; ii++)
983 if (myIdList->item(ii)->isSelected()) {
984 int id = myIdList->item(ii)->text().toInt();
985 if (subSelectionWay() != ALL_SUBSHAPES &&
986 !myMain2InPlaceIndices.IsBound(id)) {
987 //myIdList->item(ii)->setSelected(false);
994 SalomeApp_Application* app = myGeomGUI->getApp();
995 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
996 aSelMgr->clearSelected();
998 SUIT_ViewWindow* aViewWindow = 0;
999 SUIT_Study* activeStudy = app->activeStudy();
1001 aViewWindow = app->desktop()->activeWindow();
1002 if (aViewWindow == 0) return;
1004 SUIT_ViewManager* aViewManager = aViewWindow->getViewManager();
1005 if (aViewManager->getType() != OCCViewer_Viewer::Type() &&
1006 aViewManager->getType() != SVTK_Viewer::Type())
1009 SUIT_ViewModel* aViewModel = aViewManager->getViewModel();
1010 SALOME_View* aView = dynamic_cast<SALOME_View*>(aViewModel);
1011 if (aView == 0) return;
1013 // TODO??: use here GEOMBase_Helper::myPreview instead of ic->DisplayedObjects()
1015 OCCViewer_Viewer* v3d = ((OCCViewer_ViewManager*)aViewManager)->getOCCViewer();
1016 Handle(AIS_InteractiveContext) ic = v3d->getAISContext();
1017 AIS_ListOfInteractive List;
1018 //ic->DisplayedObjects(List);
1019 ic->ObjectsInside(List); // Mantis issue 0021367
1021 SALOME_ListIO aSelList;
1023 // To highlight the selected sub-shape in Object Browser, if it's already published under the main shape
1024 GEOM::GEOM_ILocalOperations_var aLocOp = getGeomEngine()->GetILocalOperations(getStudyId());
1025 QMap<int, QString> childsMap;
1026 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>(app->activeStudy());
1028 _PTR(Study) aStudy = appStudy->studyDS();
1029 CORBA::String_var aMainEntry = myMainObj->GetStudyEntry();
1030 QString anEntry = aMainEntry.in();
1031 _PTR(SObject) aSObj (aStudy->FindObjectID(anEntry.toLatin1().constData()));
1032 _PTR(ChildIterator) anIt (aStudy->NewChildIterator(aSObj));
1033 for (anIt->InitEx(true); anIt->More(); anIt->Next()) {
1034 GEOM::GEOM_Object_var aChild = GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(anIt->Value()));
1035 if (!CORBA::is_nil(aChild)) {
1036 int index = aLocOp->GetSubShapeIndex(myMainObj, aChild);
1037 CORBA::String_var aChildEntry = aChild->GetStudyEntry();
1038 QString anEntry = aChildEntry.in();
1039 childsMap.insert(index, anEntry);
1044 AIS_ListIteratorOfListOfInteractive ite (List);
1045 for (; ite.More(); ite.Next()) {
1046 if (ite.Value()->IsInstance(STANDARD_TYPE(GEOM_AISShape))) {
1047 Handle(GEOM_AISShape) aSh = Handle(GEOM_AISShape)::DownCast(ite.Value());
1049 Handle(SALOME_InteractiveObject) anIO = aSh->getIO();
1050 QString anEntry = anIO->getEntry();
1051 int index = anEntry.lastIndexOf("_");
1052 anEntry.remove(0, index+1);
1053 int anIndex = anEntry.toInt();
1054 if (anIds.Contains(anIndex)) {
1055 aSelList.Append(anIO);
1056 if (childsMap.contains (anIndex)) {
1057 Handle(SALOME_InteractiveObject) tmpIO = new SALOME_InteractiveObject(childsMap.value(anIndex).toLatin1().constData(), "GEOM", "TEMP_IO");
1058 aSelList.Append(tmpIO);
1064 aSelMgr->setSelectedObjects(aSelList);
1069 updateState(aSelList.Extent() > 0);
1071 myAddBtn->setEnabled(true);
1072 myAddBtn->setEnabled(true);
1073 myRemBtn->setEnabled(true);
1077 //=================================================================================
1078 // function : createOperation
1080 //=================================================================================
1081 GEOM::GEOM_IOperations_ptr GroupGUI_GroupDlg::createOperation()
1083 return getGeomEngine()->GetIGroupOperations(getStudyId());
1086 #define RETURN_WITH_MSG(a, b) \
1088 theMessage += (b); \
1092 //=================================================================================
1093 // function : isValid()
1094 // purpose : Verify validity of input data
1095 //=================================================================================
1096 bool GroupGUI_GroupDlg::isValid(QString& theMessage)
1098 SalomeApp_Study* study = getStudy();
1100 RETURN_WITH_MSG (!study->studyDS()->GetProperties()->IsLocked(), tr("GEOM_STUDY_LOCKED"))
1102 if (myMode == CreateGroup) {
1103 RETURN_WITH_MSG(!CORBA::is_nil(myMainObj), tr("NO_MAIN_OBJ"))
1106 RETURN_WITH_MSG(!CORBA::is_nil(myMainObj), tr("NO_GROUP"))
1109 QString aName (getNewObjectName());
1110 RETURN_WITH_MSG (!aName.trimmed().isEmpty(), tr("EMPTY_NAME"))
1112 RETURN_WITH_MSG (myIdList->count(), tr("EMPTY_LIST"))
1116 //=================================================================================
1117 // function : execute
1119 //=================================================================================
1120 bool GroupGUI_GroupDlg::execute(ObjectList& objects)
1122 GEOM::GEOM_IGroupOperations_var anOper = GEOM::GEOM_IGroupOperations::_narrow(getOperation());
1124 GEOM::GEOM_Object_var aGroup;
1125 if (myMode == CreateGroup)
1126 aGroup = anOper->CreateGroup(myMainObj, getShapeType());
1127 else if (myMode == EditGroup)
1130 if (CORBA::is_nil(aGroup) || (myMode == CreateGroup && !anOper->IsDone()))
1133 GEOM::ListOfLong_var aCurrList = anOper->GetObjects(aGroup);
1134 if (!anOper->IsDone())
1137 if (aCurrList->length() > 0)
1139 anOper->DifferenceIDs(aGroup, aCurrList);
1140 if (!anOper->IsDone())
1144 int ii, nn = myIdList->count();
1147 GEOM::ListOfLong_var aNewList = new GEOM::ListOfLong;
1148 aNewList->length(nn);
1149 for (ii = 0; ii < nn; ii++) {
1150 aNewList[ii] = myIdList->item(ii)->text().toInt();
1152 anOper->UnionIDs(aGroup, aNewList);
1153 if (!anOper->IsDone())
1157 SalomeApp_Study* study = getStudy();
1159 QString objIOR = GEOMBase::GetIORFromObject(aGroup);
1161 _PTR(SObject) SO (study->studyDS()->FindObjectIOR(objIOR.toLatin1().constData()));
1163 _PTR(StudyBuilder) aBuilder (study->studyDS()->NewBuilder());
1164 aBuilder->SetName(SO, getNewObjectName().toLatin1().constData());
1169 objects.push_back(aGroup._retn());
1174 //================================================================
1175 // Function : getFather
1176 // Purpose : Get father object for object to be added in study
1177 // (called with addInStudy method)
1178 //================================================================
1179 GEOM::GEOM_Object_ptr GroupGUI_GroupDlg::getFather(GEOM::GEOM_Object_ptr theObj)
1181 GEOM::GEOM_Object_var aFatherObj;
1182 if (theObj->GetType() == GEOM_GROUP) {
1183 GEOM::GEOM_IGroupOperations_var anOper = GEOM::GEOM_IGroupOperations::_narrow(getOperation());
1184 aFatherObj = anOper->GetMainShape(theObj);
1186 return aFatherObj._retn();