1 // Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // GEOM GEOMGUI : GUI for Geometry component
23 // File : GroupGUI_GroupDlg.cxx
24 // Author : Sergey ANIKIN, Open CASCADE S.A.S. (sergey.anikin@opencascade.com)
26 #include "GroupGUI_GroupDlg.h"
30 #include <GeometryGUI.h>
31 #include <GEOM_Displayer.h>
33 #include <SalomeApp_Application.h>
34 #include <SalomeApp_Study.h>
35 #include <SalomeApp_Tools.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_Desktop.h>
46 #include <SUIT_MessageBox.h>
47 #include <SUIT_OverrideCursor.h>
48 #include <SUIT_ResourceMgr.h>
49 #include <SUIT_Session.h>
50 #include <SUIT_ViewWindow.h>
51 #include <SUIT_ViewManager.h>
54 #include <QListWidget>
58 #include <AIS_ListOfInteractive.hxx>
59 #include <AIS_ListIteratorOfListOfInteractive.hxx>
62 #include <TopExp_Explorer.hxx>
63 #include <TopTools_IndexedMapOfShape.hxx>
64 #include <TColStd_IndexedMapOfInteger.hxx>
65 #include <TColStd_MapOfInteger.hxx>
66 #include <TColStd_DataMapIteratorOfDataMapOfIntegerInteger.hxx>
68 #include <GEOMImpl_Types.hxx>
70 #define GROUP_IDLST_COLOR Qt::blue // Specific color for the IDs of subShapes in the dialog box
71 #define GROUP_NEWIDLST_COLOR Qt::red // Specific color for the new IDs of subShapes in the dialog box
73 enum { ALL_SUBSHAPES = 0, GET_IN_PLACE, SUBSHAPES_OF_SHAPE2, SUBSHAPES_OF_INVISIBLE_SHAPE2 };
75 GroupGUI_GroupDlg::GroupGUI_GroupDlg (Mode mode, GeometryGUI* theGeometryGUI, QWidget* parent)
76 : GEOMBase_Skeleton(theGeometryGUI, parent, false),
82 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
84 QPixmap image0 (resMgr->loadPixmap("GEOM", tr("ICON_OBJBROWSER_VERTEX")));
85 QPixmap image1 (resMgr->loadPixmap("GEOM", tr("ICON_OBJBROWSER_EDGE")));
86 QPixmap image2 (resMgr->loadPixmap("GEOM", tr("ICON_OBJBROWSER_FACE")));
87 QPixmap image3 (resMgr->loadPixmap("GEOM", tr("ICON_OBJBROWSER_SOLID")));
88 QPixmap iconSelect (resMgr->loadPixmap("GEOM", tr("ICON_SELECT")));
90 setWindowTitle(myMode == CreateGroup ? tr("CREATE_GROUP_TITLE") : tr("EDIT_GROUP_TITLE"));
92 // Shape type button group
93 mainFrame()->GroupConstructors->setEnabled(myMode == CreateGroup);
94 mainFrame()->GroupConstructors->setTitle(tr("SHAPE_TYPE"));
95 mainFrame()->RadioButton1->setIcon(image0);
96 mainFrame()->RadioButton2->setIcon(image1);
97 mainFrame()->RadioButton3->setIcon(image2);
98 mainFrame()->RadioButton4->setIcon(image3);
99 mainFrame()->RadioButton4->show();
102 mainFrame()->GroupBoxName->setTitle(tr("GROUP_NAME"));
104 // Main shape and sub-shapes
105 QGroupBox* GroupMedium = new QGroupBox(tr("MAIN_SUB_SHAPES"), centralWidget());
106 QGridLayout* aMedLayout = new QGridLayout(GroupMedium);
107 aMedLayout->setMargin(9);
108 aMedLayout->setSpacing(6);
110 QLabel* aMainLabel = new QLabel(tr("MAIN_SHAPE"), GroupMedium);
112 mySelBtn = new QPushButton(GroupMedium);
113 mySelBtn->setIcon(iconSelect);
114 mySelBtn->setEnabled(myMode == CreateGroup);
116 myMainName = new QLineEdit(GroupMedium);
117 myMainName->setReadOnly(true);
118 myMainName->setEnabled(myMode == CreateGroup);
120 myRestrictGroupBox = new QGroupBox(tr("SHAPE_SEL_RESTR"), GroupMedium);
121 myRestrictGroup = new QButtonGroup(myRestrictGroupBox);
122 QRadioButton* allSubs = new QRadioButton(tr("NO_RESTR") , myRestrictGroupBox);
123 QRadioButton* inPlaceSubs = new QRadioButton(tr("GEOM_PARTS_OF_SHAPE2"), myRestrictGroupBox);
124 QRadioButton* shape2Subs = new QRadioButton(tr("SUBSHAPES_OF_SHAPE2") , myRestrictGroupBox);
125 QGridLayout* aRestrictLayout = new QGridLayout(myRestrictGroupBox);
127 QLabel* aSecondLabel = new QLabel(tr("SECOND_SHAPE"), myRestrictGroupBox);
128 mySelBtn2 = new QPushButton(myRestrictGroupBox);
129 mySelBtn2->setIcon(iconSelect);
130 mySelBtn2->setEnabled(false);
131 myShape2Name = new QLineEdit(myRestrictGroupBox);
132 myShape2Name->setReadOnly(true);
133 myShape2Name->setEnabled(false);
135 aRestrictLayout->setMargin(9);
136 aRestrictLayout->setSpacing(6);
137 aRestrictLayout->addWidget(allSubs, 0, 0, 1, 3);
138 aRestrictLayout->addWidget(inPlaceSubs, 1, 0, 1, 3);
139 aRestrictLayout->addWidget(shape2Subs, 2, 0, 1, 3);
140 aRestrictLayout->addWidget(aSecondLabel, 3, 0);
141 aRestrictLayout->addWidget(mySelBtn2, 3, 1);
142 aRestrictLayout->addWidget(myShape2Name, 3, 2);
143 myRestrictGroup->addButton(allSubs, ALL_SUBSHAPES);
144 myRestrictGroup->addButton(inPlaceSubs, GET_IN_PLACE);
145 myRestrictGroup->addButton(shape2Subs, SUBSHAPES_OF_SHAPE2);
146 myRestrictGroupBox->setEnabled(!CORBA::is_nil(myMainObj));
147 allSubs->setChecked(true);
149 myShowOnlyBtn = new QPushButton(tr("SHOW_ONLY_SELECTED"), GroupMedium);
150 myHideSelBtn = new QPushButton(tr("HIDE_SELECTED"), GroupMedium);
151 myShowAllBtn = new QPushButton(tr("SHOW_ALL_SUB_SHAPES"), GroupMedium);
153 mySelAllBtn = new QPushButton(tr("SELECT_ALL"), GroupMedium);
154 myAddBtn = new QPushButton(tr("ADD"), GroupMedium);
155 myRemBtn = new QPushButton(tr("REMOVE"), GroupMedium);
157 myIdList = new QListWidget(GroupMedium);
159 myIdList->setSelectionMode(QAbstractItemView::ExtendedSelection);
160 myIdList->setFlow(QListView::TopToBottom);
161 myIdList->setWrapping(true);
163 aMedLayout->addWidget(aMainLabel, 0, 0);
164 aMedLayout->addWidget(mySelBtn, 0, 1);
165 aMedLayout->addWidget(myMainName, 0, 2, 1, 2);
166 aMedLayout->addWidget(myRestrictGroupBox, 1, 0, 4, 3);
168 aMedLayout->addWidget(myShowOnlyBtn, 1, 3);
169 aMedLayout->addWidget(myHideSelBtn, 2, 3);
170 aMedLayout->addWidget(myShowAllBtn, 3, 3);
172 aMedLayout->addWidget(myIdList, 5, 0, 4, 3);
173 aMedLayout->addWidget(mySelAllBtn, 5, 3);
174 aMedLayout->addWidget(myAddBtn, 6, 3);
175 aMedLayout->addWidget(myRemBtn, 7, 3);
177 aMedLayout->setColumnStretch(2, 5);
178 aMedLayout->setRowStretch(5, 5);
179 aMedLayout->setRowStretch(8, 5);
181 QVBoxLayout* layout = new QVBoxLayout(centralWidget());
182 layout->setMargin(0); layout->setSpacing(6);
183 layout->addWidget(GroupMedium);
185 setHelpFileName("work_with_groups_page.html");
191 GroupGUI_GroupDlg::~GroupGUI_GroupDlg()
193 GEOM_Displayer* aDisplayer = getDisplayer();
194 if (myIsHiddenMain) {
195 aDisplayer->Display(myMainObj);
196 myIsHiddenMain = false;
198 aDisplayer->Display(myGroup);
202 //=================================================================================
205 //=================================================================================
206 void GroupGUI_GroupDlg::Init()
209 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
211 //unset shape type to avoid preparation of selection before exact user shape type selection
212 unsetConstructorId();
213 myIsShapeType = false;
215 if (myMode == CreateGroup) {
216 initName(tr("GROUP_PREFIX"));
218 // Get ready for main shape selection
219 myEditCurrentArgument = myMainName;
221 connect(this, SIGNAL(constructorsClicked(int)), this, SLOT(ConstructorsClicked(int)));
222 connect(mySelBtn, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
223 connect(mySelBtn2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
225 else if (myMode == EditGroup) {
226 SALOME_ListIO aSelList;
227 aSelMgr->selectedObjects(aSelList);
229 if (aSelList.Extent()) {
230 GEOM::GEOM_Object_var anObj =
231 GEOMBase::ConvertIOinGEOMObject(aSelList.First());
233 if (!CORBA::is_nil(anObj) && anObj->GetType() == GEOM_GROUP) {
236 mainFrame()->ResultName->setText(GEOMBase::GetName(myGroup));
238 GEOM::GEOM_IGroupOperations_var anOper = GEOM::GEOM_IGroupOperations::_narrow(getOperation());
239 myMainObj = anOper->GetMainShape(myGroup);
240 if (!CORBA::is_nil(myMainObj))
241 myMainName->setText(GEOMBase::GetName(myMainObj));
243 setShapeType((TopAbs_ShapeEnum)anOper->GetType(myGroup));
245 GEOM::ListOfLong_var aCurrList = anOper->GetObjects(myGroup);
246 for (int i = 0, n = aCurrList->length(); i < n; i++) {
247 QListWidgetItem* itm = new QListWidgetItem( QString( "%1" ).arg( aCurrList[ i ] ) );
248 myGroupIdList.append( aCurrList[ i ] );
249 itm->setTextColor( QColor( GROUP_IDLST_COLOR ) );
250 myIdList->addItem( itm );
252 myEditCurrentArgument = 0;
254 connect(mySelBtn2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
258 connect(aSelMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
260 connect(buttonOk(), SIGNAL(clicked()), this, SLOT(ClickOnOk()));
261 connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
263 connect(myRestrictGroup, SIGNAL(buttonClicked(int)), this, SLOT(SetEditCurrentArgument()));
264 connect(mySelAllBtn, SIGNAL(clicked()), this, SLOT(selectAllSubShapes()));
265 connect(myAddBtn, SIGNAL(clicked()), this, SLOT(add()));
266 connect(myRemBtn, SIGNAL(clicked()), this, SLOT(remove()));
267 connect(myShowOnlyBtn, SIGNAL(clicked()), this, SLOT(showOnlySelected()));
268 connect(myHideSelBtn, SIGNAL(clicked()), this, SLOT(showOnlySelected()));
269 connect(myShowAllBtn, SIGNAL(clicked()), this, SLOT(showOnlySelected()));
270 connect(myIdList, SIGNAL(itemSelectionChanged()), this, SLOT(selectionChanged()));
272 setInPlaceObj(GEOM::GEOM_Object::_nil());
274 myBusy = true; // just activate but do not select in the list
279 //=================================================================================
280 // function : enterEvent()
282 //=================================================================================
283 void GroupGUI_GroupDlg::enterEvent(QEvent* e)
285 if (!buttonCancel()->isEnabled())
286 ActivateThisDialog();
289 //=================================================================================
290 //function : closeEvent
291 //purpose : remove temporary geom object
292 //=================================================================================
293 void GroupGUI_GroupDlg::closeEvent(QCloseEvent* e)
295 setInPlaceObj(GEOM::GEOM_Object::_nil());
298 GEOMBase_Skeleton::closeEvent(e);
301 //=================================================================================
302 // function : ClickOnOk()
304 //=================================================================================
305 void GroupGUI_GroupDlg::ClickOnOk()
307 setIsApplyAndClose(true);
310 setIsApplyAndClose(false);
313 //=================================================================================
314 // function : ClickOnApply()
316 //=================================================================================
317 bool GroupGUI_GroupDlg::ClickOnApply()
319 if(!isApplyAndClose()) {
320 setIsDisableBrowsing( true );
321 setIsDisplayResult( false );
324 if (!onAccept(myMode == CreateGroup, true, isApplyAndClose()))
327 if(!isApplyAndClose()) {
328 setIsDisableBrowsing( false );
329 setIsDisplayResult( true );
332 if (myMode == CreateGroup)
336 ConstructorsClicked(getConstructorId());
340 int n = myIdList->count();
341 myGroupIdList.clear();
344 for (int i = 0; i < n; i++) {
345 QListWidgetItem* anItem = myIdList->item( i );
346 myGroupIdList.append( anItem->text().toInt() );
347 anItem->setTextColor( GROUP_IDLST_COLOR );
355 //=================================================================================
356 // function : ActivateThisDialog()
358 //=================================================================================
359 void GroupGUI_GroupDlg::ActivateThisDialog()
361 GEOMBase_Skeleton::ActivateThisDialog();
363 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
364 this, SLOT(SelectionIntoArgument()));
369 //=================================================================================
370 // function : SetEditCurrentArgument()
372 //=================================================================================
373 void GroupGUI_GroupDlg::SetEditCurrentArgument()
375 QPushButton* send = (QPushButton*)sender();
377 if (send == mySelBtn) {
378 myEditCurrentArgument = myMainName;
379 myShape2Name->setText("");
381 else if (send == mySelBtn2 || sender() == myRestrictGroup) {
382 setInPlaceObj(GEOM::GEOM_Object::_nil());
383 myShape2Name->setText("");
384 if (subSelectionWay() != ALL_SUBSHAPES) {
385 myEditCurrentArgument = myShape2Name;
388 myEditCurrentArgument = 0;
397 //=================================================================================
398 // function : onGetInPlace()
400 //=================================================================================
401 void GroupGUI_GroupDlg::onGetInPlace()
403 setInPlaceObj(GEOM::GEOM_Object::_nil());
404 myEditCurrentArgument->setText("");
406 bool isBlocked = myIdList->signalsBlocked();
407 myIdList->blockSignals(true);
408 myIdList->clearSelection();
409 myIdList->blockSignals(isBlocked);
411 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
412 SALOME_ListIO aSelList;
413 aSelMgr->selectedObjects(aSelList);
415 if (aSelList.Extent() != 1)
418 GEOM::GEOM_Object_var anObj =
419 GEOMBase::ConvertIOinGEOMObject(aSelList.First());
420 if (GEOMBase::IsShape(anObj)) {
421 if (!anObj->_is_equivalent(myMainObj) && !anObj->_is_equivalent(myGroup)) {
422 SUIT_OverrideCursor wc;
423 myEditCurrentArgument->setText(GEOMBase::GetName(anObj));
424 GEOM::GEOM_IShapesOperations_var aShapesOp =
425 getGeomEngine()->GetIShapesOperations(getStudyId());
426 if (subSelectionWay() == GET_IN_PLACE) {
427 GEOM::GEOM_Object_var aGetInPlaceObj = aShapesOp->GetInPlace(myMainObj, anObj);
428 setInPlaceObj(aGetInPlaceObj);
431 bool isVisible = true;
432 if (SALOME_View* view = GEOM_Displayer::GetActiveView())
433 isVisible = view->isVisible(aSelList.First());
434 setInPlaceObj(anObj, isVisible);
436 myEditCurrentArgument = 0;
437 //myBusy = true; // just activate but do not select in the list
444 //=================================================================================
445 //function : setInPlaceObj
446 //purpose : temporarily add an object to study and remove old InPlaceObj
447 //=================================================================================
448 void GroupGUI_GroupDlg::setInPlaceObj(GEOM::GEOM_Object_var theObj, const bool isVisible)
450 if (!myInPlaceObj->_is_equivalent(theObj))
452 myInPlaceObj = theObj;
455 // build map of indices
456 myMain2InPlaceIndices.Clear();
457 if (!myInPlaceObj->_is_nil()) {
458 GEOM::GEOM_IShapesOperations_var aShapesOp = getGeomEngine()->GetIShapesOperations(getStudyId());
459 GEOM::GEOM_ILocalOperations_var aLocOp = getGeomEngine()->GetILocalOperations(getStudyId());
461 GEOM::ListOfGO_var aSubObjects = aShapesOp->MakeExplode(myInPlaceObj, getShapeType(), false);
462 for ( int i = 0; i < aSubObjects->length(); i++ )
464 GEOM::ListOfLong_var aCurrList = aShapesOp->GetSameIDs( myMainObj, aSubObjects[i] );
465 if( aCurrList->length() > 1 ) {
466 //rnv : To Fix the 21561: EDF 2184 GEOM: Group with second shape restriction.
467 // In case if GetSameIDs(...) method return more then one ID use
468 // GetSharedShapes(...) method to get sub-shapes of the second shape.
469 GEOM::ListOfGO_var aSubObjects2 = aShapesOp->GetSharedShapes( myMainObj, aSubObjects[i], getShapeType() );
470 for( int j = 0; j < aSubObjects2->length(); j++ ) {
471 CORBA::Long aMainIndex = aLocOp->GetSubShapeIndex( myMainObj, aSubObjects2[j] );
472 CORBA::Long aPlaceIndex = aLocOp->GetSubShapeIndex( myInPlaceObj, aSubObjects[i]);
473 if ( aMainIndex >= 0 && aPlaceIndex > 0 ) {
474 myMain2InPlaceIndices.Bind( aMainIndex, aPlaceIndex );
477 } else if(aCurrList->length() > 0 ) {
478 CORBA::Long aMainIndex = aCurrList[0];
479 CORBA::Long aPlaceIndex = aLocOp->GetSubShapeIndex( myInPlaceObj, aSubObjects[i] );
480 if ( aMainIndex >= 0 && aPlaceIndex > 0) {
481 myMain2InPlaceIndices.Bind( aMainIndex, aPlaceIndex );
486 myInPlaceObjSelectState = subSelectionWay();
487 if (myInPlaceObjSelectState == SUBSHAPES_OF_SHAPE2 && !isVisible)
488 myInPlaceObjSelectState = SUBSHAPES_OF_INVISIBLE_SHAPE2;
491 //=================================================================================
492 // function : SelectionIntoArgument()
493 // purpose : Called when selection has changed
494 //=================================================================================
495 void GroupGUI_GroupDlg::SelectionIntoArgument()
497 if (subSelectionWay() != ALL_SUBSHAPES && myEditCurrentArgument == myShape2Name) {
502 if (myEditCurrentArgument == myMainName) { // Selection of a main shape is active
503 myEditCurrentArgument->setText("");
506 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
507 SALOME_ListIO aSelList;
508 aSelMgr->selectedObjects(aSelList);
509 int nbSel = aSelList.Extent();
512 GEOM::GEOM_Object_var anObj =
513 GEOMBase::ConvertIOinGEOMObject(aSelList.First());
515 if (GEOMBase::IsShape(anObj)) {
516 if (myIsHiddenMain) {
517 GEOM_Displayer* aDisplayer = getDisplayer();
518 aDisplayer->Display(myMainObj);
519 myIsHiddenMain = false;
522 myEditCurrentArgument->setText(GEOMBase::GetName(anObj));
523 // activate sub-shapes selection by default
524 myEditCurrentArgument = 0;
530 if (myIsHiddenMain) {
531 GEOM_Displayer* aDisplayer = getDisplayer();
532 aDisplayer->Display(myMainObj);
533 myIsHiddenMain = false;
535 myMainObj = GEOM::GEOM_Object::_nil();
538 else { // an attempt to synchronize list box selection with 3d viewer
539 if (myBusy || myMainObj->_is_nil()) {
543 bool isBlocked = myIdList->signalsBlocked();
544 myIdList->blockSignals(true);
545 myIdList->clearSelection();
547 TColStd_IndexedMapOfInteger aMapIndex;
548 int nbSel = getSelectedSubshapes(aMapIndex);
552 for (int i = 0, n = myIdList->count(); i < n; i++)
553 aMap.insert(myIdList->item(i)->text().toInt(), i);
555 bool highlight = false;
556 for (int ii = 1, nn = aMapIndex.Extent(); ii <= nn; ii++) {
557 if (aMap.contains(aMapIndex(ii))) {
558 myIdList->item(aMap[aMapIndex(ii)])->setSelected(true);
563 highlightSubShapes();
565 myIdList->blockSignals(isBlocked);
571 //=================================================================================
572 // function : ConstructorsClicked()
573 // purpose : Radio button management
574 //=================================================================================
575 void GroupGUI_GroupDlg::ConstructorsClicked(int constructorId)
577 if (getConstructorId() != constructorId)
578 setConstructorId(constructorId);
580 myIsShapeType = true;
582 myEditCurrentArgument = 0;
584 setInPlaceObj(myInPlaceObj); // to rebuild myMain2InPlaceIndices
589 //=================================================================================
590 // function : selectAllSubShapes
592 //=================================================================================
593 void GroupGUI_GroupDlg::selectAllSubShapes()
595 if (CORBA::is_nil(myMainObj) || !myIsShapeType)
598 GEOM::ListOfLong_var aSubShapes;
599 GEOM::GEOM_IShapesOperations_var aShOp = getGeomEngine()->GetIShapesOperations(getStudyId());
600 aSubShapes = aShOp->SubShapeAllIDs(myMainObj, getShapeType(), false);
601 if (aSubShapes->length() > 0) {
602 if (subSelectionWay() == ALL_SUBSHAPES)
604 // myIdList->clear(); // for sorted final list?
606 if (!aShOp->IsDone())
611 aSubShapes = new GEOM::ListOfLong();
612 aSubShapes->length(myMain2InPlaceIndices.Extent());
613 TColStd_DataMapIteratorOfDataMapOfIntegerInteger m2ip (myMain2InPlaceIndices);
614 for (int i = 0; m2ip.More(); i++, m2ip.Next())
615 aSubShapes[i] = m2ip.Key();
618 bool isBlocked = myIdList->signalsBlocked();
619 myIdList->blockSignals(true);
621 for (int i = 0, n = aSubShapes->length(); i < n; i++) {
622 CORBA::Long anIndex = aSubShapes[i];
626 QListWidgetItem* anItem = 0;
627 QString text = QString("%1").arg(anIndex);
628 // if (!myInPlaceObj->_is_nil()) {
629 QList<QListWidgetItem*> found = myIdList->findItems(text, Qt::MatchExactly);
630 if (found.count()) anItem = found[0];
633 anItem = new QListWidgetItem(text);
634 anItem->setTextColor( myGroupIdList.contains(anIndex) ? QColor( GROUP_IDLST_COLOR ) : QColor( GROUP_NEWIDLST_COLOR ) );
635 myIdList->addItem(anItem);
637 anItem->setSelected(true);
640 myIdList->blockSignals(isBlocked);
641 highlightSubShapes();
645 //=================================================================================
646 // function : showOnlySelected
648 //=================================================================================
649 void GroupGUI_GroupDlg::showOnlySelected()
651 if (CORBA::is_nil(myMainObj) || !myIsShapeType)
654 QPushButton* send = (QPushButton*)sender();
655 if (send == myShowAllBtn) {
660 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
661 SALOME_ListIO aSelList;
662 aSelMgr->selectedObjects(aSelList);
664 GEOM_Displayer* aDisplayer = getDisplayer();
666 if (send == myHideSelBtn) {
667 aDisplayer->Erase(aSelList, /*forced=*/false, /*updateViewer=*/true);
670 // Mantis issue 0021421: do not hide main shape, if explode on VERTEX
671 SALOME_View* view = GEOM_Displayer::GetActiveView();
673 CORBA::String_var aMainEntry = myMainObj->GetStudyEntry();
674 Handle(SALOME_InteractiveObject) io =
675 new SALOME_InteractiveObject (aMainEntry.in(), "GEOM", "TEMP_IO");
676 if (view->isVisible(io)) myIsHiddenMain = true;
679 aDisplayer->EraseAll(/*forced = false, updateViewer = true*/);
680 aDisplayer->Display(aSelList, true);
682 // Mantis issue 0021421: do not hide main shape, if explode on VERTEX
683 if (getShapeType() == TopAbs_VERTEX && myIsHiddenMain) {
684 aDisplayer->Display(myMainObj);
687 // for the case when selected ids were not displayed in the viewer: Mantis issue 0021367
688 highlightSubShapes();
692 //=================================================================================
693 // function : getSelectedSubshapes
695 //=================================================================================
696 int GroupGUI_GroupDlg::getSelectedSubshapes (TColStd_IndexedMapOfInteger& theMapIndex)
700 SalomeApp_Application* app = myGeomGUI->getApp();
701 if (!app || myMainObj->_is_nil())
704 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
705 SALOME_ListIO aSelList;
706 aSelMgr->selectedObjects(aSelList);
708 // try to find out and process the global selection
709 // (of not published objects and of published sub-shapes)
711 SALOME_ListIteratorOfListIO anIter (aSelList);
712 for (int i = 0; anIter.More(); anIter.Next(), i++)
714 Handle(SALOME_InteractiveObject) anIObj = anIter.Value();
715 QString anEntry = anIObj->getEntry();
717 int index = anEntry.lastIndexOf(str);
718 if (index > 0) // selection among special preview
720 anEntry.remove(0, index+1);
721 int anIndex = anEntry.toInt();
723 theMapIndex.Add(anIndex);
725 else // selection among published shapes
727 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>(app->activeStudy());
728 if (!appStudy) return 0;
729 _PTR(Study) aStudy = appStudy->studyDS();
731 _PTR(SObject) aSObj (aStudy->FindObjectID(anEntry.toLatin1().constData()));
732 GEOM::GEOM_Object_var aGeomObj =
733 GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aSObj));
735 if (GEOMBase::GetShape(aGeomObj, aShape)) {
736 if (aGeomObj->GetType() == GEOM_GROUP || aShape.ShapeType() == getShapeType()) {
737 TopTools_IndexedMapOfShape aMainMap;
738 TopoDS_Shape aMainShape = GEOM_Client::get_client().GetShape(GeometryGUI::GetGeomGen(), myMainObj);
739 TopExp::MapShapes(aMainShape, aMainMap);
741 TopExp_Explorer anExp (aShape, getShapeType());
742 for (; anExp.More(); anExp.Next()) {
743 TopoDS_Shape aSubShape = anExp.Current();
744 int anIndex = aMainMap.FindIndex(aSubShape);
746 SUIT_MessageBox::warning(app->desktop(), QObject::tr("WRN_WARNING"),
747 tr("WRN_NOT_SUBSHAPE"));
750 if (subSelectionWay() != ALL_SUBSHAPES &&
751 !myMain2InPlaceIndices.IsBound(anIndex))
753 theMapIndex.Add(anIndex);
762 return theMapIndex.Extent();
765 //=================================================================================
768 //=================================================================================
769 void GroupGUI_GroupDlg::add()
771 TColStd_IndexedMapOfInteger aMapIndex;
772 int nbSel = getSelectedSubshapes(aMapIndex);
774 TColStd_MapOfInteger aMap;
775 for (int i = 0, n = myIdList->count(); i < n; i++)
776 aMap.Add(myIdList->item(i)->text().toInt());
779 bool isBlocked = myIdList->signalsBlocked();
780 myIdList->blockSignals(true);
782 for (int i = 1, n = aMapIndex.Extent(); i <= n; i++) {
783 if (aMap.Contains(aMapIndex(i)))
786 QListWidgetItem* anItem = new QListWidgetItem(QString("%1").arg(aMapIndex(i)));
787 anItem->setTextColor( myGroupIdList.contains( aMapIndex( i ) ) ? QColor( GROUP_IDLST_COLOR ) : QColor( GROUP_NEWIDLST_COLOR ) );
788 myIdList->addItem(anItem);
789 anItem->setSelected(true);
792 myIdList->blockSignals(isBlocked);
798 //=================================================================================
801 //=================================================================================
802 void GroupGUI_GroupDlg::remove()
804 bool isBlocked = myIdList->signalsBlocked();
805 myIdList->blockSignals(true);
807 QListIterator<QListWidgetItem*> it (myIdList->selectedItems());
811 myIdList->blockSignals(isBlocked);
813 highlightSubShapes();
816 //=================================================================================
817 //function : subSelectionWay
819 //=================================================================================
820 int GroupGUI_GroupDlg::subSelectionWay() const
822 return myRestrictGroup->checkedId();
825 //=================================================================================
826 // function : getShapeType()
828 //=================================================================================
829 TopAbs_ShapeEnum GroupGUI_GroupDlg::getShapeType() const
831 switch (getConstructorId()) {
832 case 0: return TopAbs_VERTEX;
833 case 1: return TopAbs_EDGE;
834 case 2: return TopAbs_FACE;
835 case 3: return TopAbs_SOLID;
836 default: return TopAbs_SHAPE;
840 //=================================================================================
841 // function : setShapeType()
843 //=================================================================================
844 void GroupGUI_GroupDlg::setShapeType(const TopAbs_ShapeEnum theType)
848 case TopAbs_VERTEX: anId = 0; break;
849 case TopAbs_EDGE: anId = 1; break;
850 case TopAbs_FACE: anId = 2; break;
851 case TopAbs_SOLID: anId = 3; break;
853 setConstructorId(anId);
856 myIsShapeType = true;
857 // workaround to avoid set checked button 0
858 setConstructorId(anId);
862 //=================================================================================
863 // function : activateSelection
864 // purpose : Activate selection in accordance with myEditCurrentArgument
865 //=================================================================================
866 void GroupGUI_GroupDlg::activateSelection()
868 bool isApply = ((QPushButton*)sender() == buttonApply());
869 if(!isApplyAndClose())
873 if (!myMainObj->_is_nil() &&
874 !myEditCurrentArgument &&
875 myIsShapeType) // check if shape type is already choosen by user
877 GEOM_Displayer* aDisplayer = getDisplayer();
879 //display mode for main shape
880 if ( myDmMode == -1 ) {
881 SALOME_View* view = GEOM_Displayer::GetActiveView();
883 CORBA::String_var aMainEntry = myMainObj->GetStudyEntry();
884 Handle(SALOME_InteractiveObject) io =
885 new SALOME_InteractiveObject (aMainEntry.in(), "GEOM", "TEMP_IO");
886 if ( view->isVisible( io ) ) {
887 Handle(GEOM_AISShape) aSh = GEOMBase::ConvertIOinGEOMAISShape( io, true );
889 myDmMode = aSh->isTopLevel() ? aSh->prevDisplayMode() : aSh->DisplayMode();
891 // Hide main shape, if explode on VERTEX
892 if(getShapeType() != TopAbs_VERTEX) {
893 aDisplayer->Erase(myMainObj, false, false);
894 myIsHiddenMain = true;
898 myDmMode = SUIT_Session::session()->resourceMgr()->integerValue( "Geometry", "display_mode" );
901 aDisplayer->SetDisplayMode(myDmMode);
903 // Mantis issue 0021421: do not hide main shape, if explode on VERTEX
904 if (getShapeType() == TopAbs_VERTEX) {
906 aDisplayer->Display(myMainObj);
908 aDisplayer->Erase(myGroup, false, false);
910 QColor aColor = SUIT_Session::session()->resourceMgr()->colorValue( "Geometry", "editgroup_color" );
911 Quantity_NameOfColor aCol = SalomeApp_Tools::color( aColor ).Name();
913 if(!isApplyAndClose()) {
914 SUIT_ViewWindow* aViewWindow = 0;
915 SUIT_Study* activeStudy = SUIT_Session::session()->activeApplication()->activeStudy();
917 aViewWindow = SUIT_Session::session()->activeApplication()->desktop()->activeWindow();
918 if (aViewWindow == 0) return;
920 SUIT_ViewManager* aViewManager = aViewWindow->getViewManager();
921 if (aViewManager->getType() != OCCViewer_Viewer::Type() &&
922 aViewManager->getType() != SVTK_Viewer::Type())
925 SUIT_ViewModel* aViewModel = aViewManager->getViewModel();
926 SALOME_View* aView = dynamic_cast<SALOME_View*>(aViewModel);
927 if (aView == 0) return;
929 TopoDS_Shape aMainShape = GEOM_Client::get_client().GetShape(GeometryGUI::GetGeomGen(), myMainObj);
930 TopoDS_Shape aRestrictionShape;
932 if (subSelectionWay() == ALL_SUBSHAPES) {
933 aRestrictionShape = aMainShape;
935 TopTools_IndexedMapOfShape aSubShapesMap;
936 TopExp::MapShapes(aMainShape, aSubShapesMap);
937 CORBA::String_var aMainEntry = myMainObj->GetStudyEntry();
938 QString anEntryBase = aMainEntry.in();
940 TopExp_Explorer anExp (aRestrictionShape, getShapeType());
941 for (; anExp.More(); anExp.Next()) {
942 TopoDS_Shape aSubShape = anExp.Current();
943 int index = aSubShapesMap.FindIndex(aSubShape);
944 QString anEntry = QString( "TEMP_" ) + anEntryBase + QString("_%1").arg(index);
945 Handle(SALOME_InteractiveObject) io =
946 new SALOME_InteractiveObject(anEntry.toAscii(), "GEOM", "TEMP_IO");
947 if ( myGroupIdList.contains( index ) ) {
948 aDisplayer->SetColor( aCol );
951 aDisplayer->UnsetColor();
953 SALOME_Prs* aPrs = aDisplayer->buildSubshapePresentation(aSubShape, anEntry, aView);
955 displayPreview(aPrs, true, false); // append, do not update
956 // TODO: map or delete Prs
960 else if (!myInPlaceObj->_is_nil()) {
961 TopTools_IndexedMapOfShape aSubShapesMap;
962 TopExp::MapShapes(aMainShape, aSubShapesMap);
963 CORBA::String_var aMainEntry = myMainObj->GetStudyEntry();
964 QString anEntryBase = aMainEntry.in();
966 TColStd_DataMapIteratorOfDataMapOfIntegerInteger aM2IPit (myMain2InPlaceIndices);
967 for (; aM2IPit.More(); aM2IPit.Next()) {
968 int index = aM2IPit.Key();
969 TopoDS_Shape aSubShape = aSubShapesMap.FindKey(index);
970 QString anEntry = QString( "TEMP_" ) + anEntryBase + QString("_%1").arg(index);
972 if ( myGroupIdList.contains( index ) ) {
973 aDisplayer->SetColor( aCol );
976 aDisplayer->UnsetColor();
979 SALOME_Prs* aPrs = aDisplayer->buildSubshapePresentation(aSubShape, anEntry, aView);
981 displayPreview(aPrs, true, false); // append, do not update
986 aDisplayer->UnsetDisplayMode();
987 aDisplayer->UnsetColor();
988 aDisplayer->UpdateViewer();
992 globalSelection(GEOM_ALLSHAPES);
994 SelectionIntoArgument();
997 //=================================================================================
998 // function : updateState
1000 //=================================================================================
1001 void GroupGUI_GroupDlg::updateState (bool isAdd)
1003 myAddBtn->setEnabled(!myEditCurrentArgument && !CORBA::is_nil(myMainObj) && isAdd);
1004 //myShowOnlyBtn->setEnabled(!myEditCurrentArgument && !CORBA::is_nil(myMainObj) && isAdd);
1006 bool hasSel = myIdList->selectedItems().count() > 0;
1008 myRemBtn->setEnabled(hasSel);
1009 myRestrictGroupBox->setEnabled(!CORBA::is_nil(myMainObj));
1010 mySelAllBtn->setEnabled(!CORBA::is_nil(myMainObj));
1012 mySelBtn2->setEnabled(subSelectionWay() != ALL_SUBSHAPES);
1013 myShape2Name->setEnabled(subSelectionWay() != ALL_SUBSHAPES);
1014 if (subSelectionWay() == ALL_SUBSHAPES)
1015 setInPlaceObj(GEOM::GEOM_Object::_nil());
1018 //=================================================================================
1019 // function : selectionChanged
1021 //=================================================================================
1022 void GroupGUI_GroupDlg::selectionChanged()
1024 highlightSubShapes();
1027 //=================================================================================
1028 // function : highlightSubShapes
1030 //=================================================================================
1031 void GroupGUI_GroupDlg::highlightSubShapes()
1033 if (CORBA::is_nil(myMainObj))
1036 TColStd_MapOfInteger anIds;
1040 int ii = 0, nn = myIdList->count();
1041 for (; ii < nn; ii++)
1043 if (myIdList->item(ii)->isSelected()) {
1044 int id = myIdList->item(ii)->text().toInt();
1045 if (subSelectionWay() != ALL_SUBSHAPES &&
1046 !myMain2InPlaceIndices.IsBound(id)) {
1047 //myIdList->item(ii)->setSelected(false);
1054 SalomeApp_Application* app = myGeomGUI->getApp();
1055 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
1056 aSelMgr->clearSelected();
1058 SUIT_ViewWindow* aViewWindow = 0;
1059 SUIT_Study* activeStudy = app->activeStudy();
1061 aViewWindow = app->desktop()->activeWindow();
1062 if (aViewWindow == 0) return;
1064 SUIT_ViewManager* aViewManager = aViewWindow->getViewManager();
1065 if (aViewManager->getType() != OCCViewer_Viewer::Type() &&
1066 aViewManager->getType() != SVTK_Viewer::Type())
1069 SUIT_ViewModel* aViewModel = aViewManager->getViewModel();
1070 SALOME_View* aView = dynamic_cast<SALOME_View*>(aViewModel);
1071 if (aView == 0) return;
1073 // TODO??: use here GEOMBase_Helper::myPreview instead of ic->DisplayedObjects()
1075 OCCViewer_Viewer* v3d = ((OCCViewer_ViewManager*)aViewManager)->getOCCViewer();
1076 Handle(AIS_InteractiveContext) ic = v3d->getAISContext();
1077 AIS_ListOfInteractive List;
1078 //ic->DisplayedObjects(List);
1079 ic->ObjectsInside(List); // Mantis issue 0021367
1081 SALOME_ListIO aSelList;
1083 // To highlight the selected sub-shape in Object Browser, if it's already published under the main shape
1084 GEOM::GEOM_ILocalOperations_var aLocOp = getGeomEngine()->GetILocalOperations(getStudyId());
1085 QMap<int, QString> childsMap;
1086 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>(app->activeStudy());
1088 _PTR(Study) aStudy = appStudy->studyDS();
1089 CORBA::String_var aMainEntry = myMainObj->GetStudyEntry();
1090 QString anEntry = aMainEntry.in();
1091 _PTR(SObject) aSObj (aStudy->FindObjectID(anEntry.toLatin1().constData()));
1092 _PTR(ChildIterator) anIt (aStudy->NewChildIterator(aSObj));
1093 for (anIt->InitEx(true); anIt->More(); anIt->Next()) {
1094 GEOM::GEOM_Object_var aChild = GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(anIt->Value()));
1095 if (!CORBA::is_nil(aChild)) {
1096 int index = aLocOp->GetSubShapeIndex(myMainObj, aChild);
1097 CORBA::String_var aChildEntry = aChild->GetStudyEntry();
1098 QString anEntry = aChildEntry.in();
1099 childsMap.insert(index, anEntry);
1104 AIS_ListIteratorOfListOfInteractive ite (List);
1105 for (; ite.More(); ite.Next()) {
1106 if (ite.Value()->IsInstance(STANDARD_TYPE(GEOM_AISShape))) {
1107 Handle(GEOM_AISShape) aSh = Handle(GEOM_AISShape)::DownCast(ite.Value());
1109 Handle(SALOME_InteractiveObject) anIO = aSh->getIO();
1110 QString anEntry = anIO->getEntry();
1111 int index = anEntry.lastIndexOf("_");
1112 anEntry.remove(0, index+1);
1113 int anIndex = anEntry.toInt();
1114 if (anIds.Contains(anIndex)) {
1115 aSelList.Append(anIO);
1116 if (childsMap.contains (anIndex)) {
1117 Handle(SALOME_InteractiveObject) tmpIO = new SALOME_InteractiveObject(childsMap.value(anIndex).toLatin1().constData(), "GEOM", "TEMP_IO");
1118 aSelList.Append(tmpIO);
1124 aSelMgr->setSelectedObjects(aSelList);
1129 updateState(aSelList.Extent() > 0);
1131 myAddBtn->setEnabled(true);
1132 myAddBtn->setEnabled(true);
1133 myRemBtn->setEnabled(true);
1137 //=================================================================================
1138 // function : createOperation
1140 //=================================================================================
1141 GEOM::GEOM_IOperations_ptr GroupGUI_GroupDlg::createOperation()
1143 return getGeomEngine()->GetIGroupOperations(getStudyId());
1146 #define RETURN_WITH_MSG(a, b) \
1148 theMessage += (b); \
1152 //=================================================================================
1153 // function : isValid()
1154 // purpose : Verify validity of input data
1155 //=================================================================================
1156 bool GroupGUI_GroupDlg::isValid(QString& theMessage)
1158 SalomeApp_Study* study = getStudy();
1160 RETURN_WITH_MSG (!study->studyDS()->GetProperties()->IsLocked(), tr("GEOM_STUDY_LOCKED"))
1162 if (myMode == CreateGroup) {
1163 RETURN_WITH_MSG(!CORBA::is_nil(myMainObj), tr("NO_MAIN_OBJ"))
1166 RETURN_WITH_MSG(!CORBA::is_nil(myMainObj), tr("NO_GROUP"))
1169 QString aName (getNewObjectName());
1170 RETURN_WITH_MSG (!aName.trimmed().isEmpty(), tr("EMPTY_NAME"))
1172 RETURN_WITH_MSG (myIdList->count(), tr("EMPTY_LIST"))
1176 //=================================================================================
1177 // function : execute
1179 //=================================================================================
1180 bool GroupGUI_GroupDlg::execute(ObjectList& objects)
1182 GEOM::GEOM_IGroupOperations_var anOper = GEOM::GEOM_IGroupOperations::_narrow(getOperation());
1184 GEOM::GEOM_Object_var aGroup;
1185 if (myMode == CreateGroup)
1186 aGroup = anOper->CreateGroup(myMainObj, getShapeType());
1187 else if (myMode == EditGroup)
1190 if (CORBA::is_nil(aGroup) || (myMode == CreateGroup && !anOper->IsDone()))
1193 GEOM::ListOfLong_var aCurrList = anOper->GetObjects(aGroup);
1194 if (!anOper->IsDone())
1197 if (aCurrList->length() > 0)
1199 anOper->DifferenceIDs(aGroup, aCurrList);
1200 if (!anOper->IsDone())
1204 int ii, nn = myIdList->count();
1207 GEOM::ListOfLong_var aNewList = new GEOM::ListOfLong;
1208 aNewList->length(nn);
1209 for (ii = 0; ii < nn; ii++) {
1210 aNewList[ii] = myIdList->item(ii)->text().toInt();
1212 anOper->UnionIDs(aGroup, aNewList);
1213 if (!anOper->IsDone())
1217 SalomeApp_Study* study = getStudy();
1219 QString objIOR = GEOMBase::GetIORFromObject(aGroup);
1221 _PTR(SObject) SO (study->studyDS()->FindObjectIOR(objIOR.toLatin1().constData()));
1223 _PTR(StudyBuilder) aBuilder (study->studyDS()->NewBuilder());
1224 aBuilder->SetName(SO, getNewObjectName().toLatin1().constData());
1229 objects.push_back(aGroup._retn());
1234 //================================================================
1235 // Function : getFather
1236 // Purpose : Get father object for object to be added in study
1237 // (called with addInStudy method)
1238 //================================================================
1239 GEOM::GEOM_Object_ptr GroupGUI_GroupDlg::getFather(GEOM::GEOM_Object_ptr theObj)
1241 GEOM::GEOM_Object_var aFatherObj;
1242 if (theObj->GetType() == GEOM_GROUP) {
1243 GEOM::GEOM_IGroupOperations_var anOper = GEOM::GEOM_IGroupOperations::_narrow(getOperation());
1244 aFatherObj = anOper->GetMainShape(theObj);
1246 return aFatherObj._retn();