1 // Copyright (C) 2007-2021 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, or (at your option) any later version.
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>
33 #include <GEOMUtils.hxx>
34 #ifndef DISABLE_PLOT2DVIEWER
35 #include <MeasureGUI_ShapeStatisticsDlg.h>
38 #include <SalomeApp_Application.h>
39 #include <SalomeApp_Study.h>
40 #include <SalomeApp_Tools.h>
42 #include <LightApp_SelectionMgr.h>
43 #include "utilities.h"
45 #include <OCCViewer_ViewModel.h>
46 #include <OCCViewer_ViewManager.h>
47 #include <SVTK_ViewModel.h>
48 #include <SALOME_Prs.h>
49 #include <SALOME_ListIO.hxx>
50 #include "utilities.h"
52 #include <SUIT_Desktop.h>
53 #include <SUIT_MessageBox.h>
54 #include <SUIT_OverrideCursor.h>
55 #include <SUIT_ResourceMgr.h>
56 #include <SUIT_Session.h>
57 #include <SUIT_ViewWindow.h>
58 #include <SUIT_ViewManager.h>
61 #include <QListWidget>
64 #include <QButtonGroup>
66 #include <AIS_ListOfInteractive.hxx>
67 #include <AIS_ListIteratorOfListOfInteractive.hxx>
70 #include <TopExp_Explorer.hxx>
71 #include <TopTools_IndexedMapOfShape.hxx>
72 #include <TColStd_IndexedMapOfInteger.hxx>
73 #include <TColStd_MapOfInteger.hxx>
74 #include <TColStd_DataMapIteratorOfDataMapOfIntegerInteger.hxx>
76 #include <GEOMImpl_Types.hxx>
78 #define GROUP_IDLST_COLOR Qt::blue // Specific color for the IDs of subShapes in the dialog box
79 #define GROUP_NEWIDLST_COLOR Qt::red // Specific color for the new IDs of subShapes in the dialog box
82 enum { ALL_SUBSHAPES = 0, GET_IN_PLACE, SUBSHAPES_OF_SHAPE2, SUBSHAPES_OF_INVISIBLE_SHAPE2 };
83 enum { Filter_LT, Filter_LE, Filter_GT, Filter_GE };
86 GroupGUI_GroupDlg::GroupGUI_GroupDlg (Mode mode, GeometryGUI* theGeometryGUI, QWidget* parent)
87 : GEOMBase_Skeleton(theGeometryGUI, parent, false),
91 myIsHiddenMain(false),
92 myWasHiddenMain(true),
95 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
97 QPixmap image0 (resMgr->loadPixmap("GEOM", tr("ICON_OBJBROWSER_VERTEX")));
98 QPixmap image1 (resMgr->loadPixmap("GEOM", tr("ICON_OBJBROWSER_EDGE")));
99 QPixmap image2 (resMgr->loadPixmap("GEOM", tr("ICON_OBJBROWSER_FACE")));
100 QPixmap image3 (resMgr->loadPixmap("GEOM", tr("ICON_OBJBROWSER_SOLID")));
101 QPixmap iconSelect (resMgr->loadPixmap("GEOM", tr("ICON_SELECT")));
103 setWindowTitle(myMode == CreateGroup ? tr("CREATE_GROUP_TITLE") : tr("EDIT_GROUP_TITLE"));
105 // Shape type button group
106 mainFrame()->GroupConstructors->setEnabled(myMode == CreateGroup);
107 mainFrame()->GroupConstructors->setTitle(tr("SHAPE_TYPE"));
108 mainFrame()->RadioButton1->setIcon(image0);
109 mainFrame()->RadioButton2->setIcon(image1);
110 mainFrame()->RadioButton3->setIcon(image2);
111 mainFrame()->RadioButton4->setIcon(image3);
112 mainFrame()->RadioButton4->show();
115 mainFrame()->GroupBoxName->setTitle(tr("GROUP_NAME"));
117 // Main shape and sub-shapes
118 QGroupBox* GroupMedium = new QGroupBox(tr("MAIN_SUB_SHAPES"), centralWidget());
119 QGridLayout* aMedLayout = new QGridLayout(GroupMedium);
120 aMedLayout->setMargin(9);
121 aMedLayout->setSpacing(6);
123 QLabel* aMainLabel = new QLabel(tr("MAIN_SHAPE"), GroupMedium);
125 mySelBtn = new QPushButton(GroupMedium);
126 mySelBtn->setIcon(iconSelect);
127 mySelBtn->setEnabled(myMode == CreateGroup);
129 myMainName = new QLineEdit(GroupMedium);
130 myMainName->setReadOnly(true);
131 myMainName->setEnabled(myMode == CreateGroup);
133 myRestrictGroupBox = new QGroupBox(tr("SHAPE_SEL_RESTR"), GroupMedium);
134 myRestrictGroup = new QButtonGroup(myRestrictGroupBox);
135 QRadioButton* allSubs = new QRadioButton(tr("NO_RESTR") , myRestrictGroupBox);
136 QRadioButton* inPlaceSubs = new QRadioButton(tr("GEOM_PARTS_OF_SHAPE2"), myRestrictGroupBox);
137 QRadioButton* shape2Subs = new QRadioButton(tr("SUBSHAPES_OF_SHAPE2") , myRestrictGroupBox);
138 QGridLayout* aRestrictLayout = new QGridLayout(myRestrictGroupBox);
140 QLabel* aSecondLabel = new QLabel(tr("SECOND_SHAPE"), myRestrictGroupBox);
141 mySelBtn2 = new QPushButton(myRestrictGroupBox);
142 mySelBtn2->setIcon(iconSelect);
143 mySelBtn2->setEnabled(false);
144 myShape2Name = new QLineEdit(myRestrictGroupBox);
145 myShape2Name->setReadOnly(true);
146 myShape2Name->setEnabled(false);
148 aRestrictLayout->setMargin(9);
149 aRestrictLayout->setSpacing(6);
150 aRestrictLayout->addWidget(allSubs, 0, 0, 1, 3);
151 aRestrictLayout->addWidget(inPlaceSubs, 1, 0, 1, 3);
152 aRestrictLayout->addWidget(shape2Subs, 2, 0, 1, 3);
153 aRestrictLayout->addWidget(aSecondLabel, 3, 0);
154 aRestrictLayout->addWidget(mySelBtn2, 3, 1);
155 aRestrictLayout->addWidget(myShape2Name, 3, 2);
156 myRestrictGroup->addButton(allSubs, ALL_SUBSHAPES);
157 myRestrictGroup->addButton(inPlaceSubs, GET_IN_PLACE);
158 myRestrictGroup->addButton(shape2Subs, SUBSHAPES_OF_SHAPE2);
159 myRestrictGroupBox->setEnabled(!CORBA::is_nil(myMainObj));
160 allSubs->setChecked(true);
162 myShowOnlyBtn = new QPushButton(tr("SHOW_ONLY_SELECTED"), GroupMedium);
163 myHideSelBtn = new QPushButton(tr("HIDE_SELECTED"), GroupMedium);
164 myShowAllBtn = new QPushButton(tr("SHOW_ALL_SUB_SHAPES"), GroupMedium);
166 mySelAllBtn = new QPushButton(tr("SELECT_ALL"), GroupMedium);
167 myAddBtn = new QPushButton(tr("ADD"), GroupMedium);
168 myRemBtn = new QPushButton(tr("REMOVE"), GroupMedium);
170 myIdList = new QListWidget(GroupMedium);
172 myIdList->setSelectionMode(QAbstractItemView::ExtendedSelection);
173 myIdList->setFlow(QListView::TopToBottom);
174 myIdList->setWrapping(true);
176 aMedLayout->addWidget(aMainLabel, 0, 0);
177 aMedLayout->addWidget(mySelBtn, 0, 1);
178 aMedLayout->addWidget(myMainName, 0, 2, 1, 2);
179 aMedLayout->addWidget(myRestrictGroupBox, 1, 0, 4, 3);
181 aMedLayout->addWidget(myShowOnlyBtn, 1, 3);
182 aMedLayout->addWidget(myHideSelBtn, 2, 3);
183 aMedLayout->addWidget(myShowAllBtn, 3, 3);
185 aMedLayout->addWidget(myIdList, 5, 0, 4, 3);
186 aMedLayout->addWidget(mySelAllBtn, 5, 3);
187 aMedLayout->addWidget(myAddBtn, 6, 3);
188 aMedLayout->addWidget(myRemBtn, 7, 3);
190 aMedLayout->setColumnStretch(2, 5);
191 aMedLayout->setRowStretch(5, 5);
192 aMedLayout->setRowStretch(8, 5);
196 myFilterGrp = new QGroupBox(tr("GEOM_FILTER"), centralWidget());
197 myLessFilterCheck = new QCheckBox(myFilterGrp);
198 myLessFilterCombo = new QComboBox(myFilterGrp);
199 myLessFilterCombo->addItem( tr("GEOM_LESS_THAN"), Filter_LT );
200 myLessFilterCombo->addItem( tr("GEOM_LESSOREQUAL_THAN"), Filter_LE );
201 myGreaterFilterCheck = new QCheckBox(myFilterGrp);
202 myGreaterFilterCombo = new QComboBox(myFilterGrp);
203 myGreaterFilterCombo->addItem( tr("GEOM_GREAT_THAN"), Filter_GT );
204 myGreaterFilterCombo->addItem( tr("GEOM_GREATOREQUAL_THAN"), Filter_GE );
205 myLessFilterSpin = new SalomeApp_DoubleSpinBox(myFilterGrp);
206 myGreaterFilterSpin = new SalomeApp_DoubleSpinBox(myFilterGrp);
207 myApplyFilterButton = new QPushButton(tr("GEOM_BUT_APPLY"), myFilterGrp);
208 #ifndef DISABLE_PLOT2DVIEWER
209 myPlotDistributionButton = new QPushButton(tr("GEOM_PLOT_DISTRIBUTION"), myFilterGrp);
212 QGridLayout* filterLayout = new QGridLayout(myFilterGrp);
213 filterLayout->addWidget(myLessFilterCheck, 0, 0);
214 filterLayout->addWidget(myLessFilterCombo, 0, 1);
215 filterLayout->addWidget(myLessFilterSpin, 0, 2);
216 filterLayout->addWidget(myGreaterFilterCheck, 1, 0);
217 filterLayout->addWidget(myGreaterFilterCombo, 1, 1);
218 filterLayout->addWidget(myGreaterFilterSpin, 1, 2);
219 filterLayout->addWidget(myApplyFilterButton, 0, 3);
220 #ifndef DISABLE_PLOT2DVIEWER
221 filterLayout->addWidget(myPlotDistributionButton, 1, 3);
224 QVBoxLayout* layout = new QVBoxLayout(centralWidget());
225 layout->setMargin(0); layout->setSpacing(6);
226 layout->addWidget(GroupMedium);
227 layout->addWidget(myFilterGrp);
229 setHelpFileName("work_with_groups_page.html");
235 GroupGUI_GroupDlg::~GroupGUI_GroupDlg()
237 GEOM_Displayer* aDisplayer = getDisplayer();
238 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
239 bool isHideObjects = resMgr->booleanValue( "Geometry", "hide_input_object", true);
240 if (myWasHiddenMain || ( isHideObjects && myIsAccept ) ) {
241 myIsHiddenMain = true;
244 aDisplayer->Display(myMainObj);
245 myIsHiddenMain = false;
247 aDisplayer->Display(myGroup);
251 //=================================================================================
254 //=================================================================================
255 void GroupGUI_GroupDlg::Init()
257 // Get setting of step value from file configuration
258 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
259 double step = resMgr->doubleValue("Geometry", "SettingsGeomStep", 100);
261 // min, max, step and decimals for spin boxes
262 initSpinBox(myLessFilterSpin, 0., COORD_MAX, step, "length_precision" );
263 initSpinBox(myGreaterFilterSpin, 0., COORD_MAX, step, "length_precision" );
264 myLessFilterSpin->setValue( 0. );
265 myGreaterFilterSpin->setValue( 0. );
268 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
270 //unset shape type to avoid preparation of selection before exact user shape type selection
271 unsetConstructorId();
272 myIsShapeType = false;
274 if (myMode == CreateGroup) {
275 initName(tr("GROUP_PREFIX"));
277 // Get ready for main shape selection
278 myEditCurrentArgument = myMainName;
280 connect(this, SIGNAL(constructorsClicked(int)), this, SLOT(ConstructorsClicked(int)));
281 connect(mySelBtn, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
282 connect(mySelBtn2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
284 else if (myMode == EditGroup) {
285 SALOME_ListIO aSelList;
286 aSelMgr->selectedObjects(aSelList);
288 if (aSelList.Extent()) {
289 GEOM::GEOM_Object_var anObj =
290 GEOMBase::ConvertIOinGEOMObject(aSelList.First());
292 if (!CORBA::is_nil(anObj) && anObj->GetType() == GEOM_GROUP) {
295 mainFrame()->ResultName->setText(GEOMBase::GetName(myGroup));
297 GEOM::GEOM_IGroupOperations_var anOper = GEOM::GEOM_IGroupOperations::_narrow(getOperation());
298 myMainObj = anOper->GetMainShape(myGroup);
299 if (!CORBA::is_nil(myMainObj)) {
300 myMainName->setText(GEOMBase::GetName(myMainObj));
301 SALOME_View* view = GEOM_Displayer::GetActiveView();
303 CORBA::String_var aMainEntry = myMainObj->GetStudyEntry();
304 Handle(SALOME_InteractiveObject) io =
305 new SALOME_InteractiveObject (aMainEntry.in(), "GEOM", "TEMP_IO");
306 if (view->isVisible(io)) myWasHiddenMain = false;
310 setShapeType((TopAbs_ShapeEnum)anOper->GetType(myGroup));
312 GEOM::ListOfLong_var aCurrList = anOper->GetObjects(myGroup);
313 for (int i = 0, n = aCurrList->length(); i < n; i++) {
314 QListWidgetItem* itm = new QListWidgetItem( QString( "%1" ).arg( aCurrList[ i ] ) );
315 myGroupIdList.append( aCurrList[ i ] );
316 itm->setTextColor( QColor( GROUP_IDLST_COLOR ) );
317 myIdList->addItem( itm );
319 myEditCurrentArgument = 0;
321 connect(mySelBtn2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
325 connect(aSelMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
327 connect(buttonOk(), SIGNAL(clicked()), this, SLOT(ClickOnOk()));
328 connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
330 connect(myRestrictGroup, SIGNAL(buttonClicked(int)), this, SLOT(SetEditCurrentArgument()));
331 connect(mySelAllBtn, SIGNAL(clicked()), this, SLOT(selectAllSubShapes()));
332 connect(myAddBtn, SIGNAL(clicked()), this, SLOT(add()));
333 connect(myRemBtn, SIGNAL(clicked()), this, SLOT(remove()));
334 connect(myShowOnlyBtn, SIGNAL(clicked()), this, SLOT(showOnlySelected()));
335 connect(myHideSelBtn, SIGNAL(clicked()), this, SLOT(showOnlySelected()));
336 connect(myShowAllBtn, SIGNAL(clicked()), this, SLOT(showOnlySelected()));
337 connect(myIdList, SIGNAL(itemSelectionChanged()), this, SLOT(selectionChanged()));
339 connect(myApplyFilterButton, SIGNAL(clicked()), this, SLOT(ClickOnOkFilter()));
340 #ifndef DISABLE_PLOT2DVIEWER
341 connect(myPlotDistributionButton, SIGNAL(clicked()), this, SLOT(ClickOnPlot()));
343 connect(myLessFilterCheck, SIGNAL(stateChanged(int)), this, SLOT(MeasureToggled()));
344 connect(myGreaterFilterCheck, SIGNAL(stateChanged(int)), this, SLOT(MeasureToggled()));
346 setInPlaceObj(GEOM::GEOM_Object::_nil());
348 myBusy = true; // just activate but do not select in the list
354 //=================================================================================
355 // function : enterEvent()
357 //=================================================================================
358 void GroupGUI_GroupDlg::enterEvent(QEvent*)
360 if (!buttonCancel()->isEnabled())
361 ActivateThisDialog();
364 //=================================================================================
365 //function : closeEvent
366 //purpose : remove temporary geom object
367 //=================================================================================
368 void GroupGUI_GroupDlg::closeEvent(QCloseEvent* e)
370 setInPlaceObj(GEOM::GEOM_Object::_nil());
373 GEOMBase_Skeleton::closeEvent(e);
376 //=================================================================================
377 // function : ClickOnOk()
379 //=================================================================================
380 void GroupGUI_GroupDlg::ClickOnOk()
382 setIsApplyAndClose(true);
385 setIsApplyAndClose(false);
386 getDisplayer()->UnsetDisplayMode();
389 //=================================================================================
390 // function : ClickOnApply()
392 //=================================================================================
393 bool GroupGUI_GroupDlg::ClickOnApply()
395 if(!isApplyAndClose()) {
396 setIsDisableBrowsing( true );
397 setIsDisplayResult( false );
400 myIsAccept = onAccept(myMode == CreateGroup, true, isApplyAndClose());
404 if(!isApplyAndClose()) {
405 setIsDisableBrowsing( false );
406 setIsDisplayResult( true );
409 if (myMode == CreateGroup)
413 ConstructorsClicked(getConstructorId());
417 int n = myIdList->count();
418 myGroupIdList.clear();
421 for (int i = 0; i < n; i++) {
422 QListWidgetItem* anItem = myIdList->item( i );
423 myGroupIdList.append( anItem->text().toInt() );
424 anItem->setTextColor( GROUP_IDLST_COLOR );
432 //=================================================================================
433 // function : ActivateThisDialog()
435 //=================================================================================
436 void GroupGUI_GroupDlg::ActivateThisDialog()
438 GEOMBase_Skeleton::ActivateThisDialog();
440 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
441 this, SLOT(SelectionIntoArgument()));
446 //=================================================================================
447 // function : SetEditCurrentArgument()
449 //=================================================================================
450 void GroupGUI_GroupDlg::SetEditCurrentArgument()
452 QPushButton* send = qobject_cast<QPushButton*>( sender() );
454 if (send == mySelBtn) {
455 myEditCurrentArgument = myMainName;
456 myShape2Name->setText("");
457 mySelBtn->setDown(true);
458 mySelBtn2->setDown(false);
460 else if (send == mySelBtn2 || sender() == myRestrictGroup) {
461 setInPlaceObj(GEOM::GEOM_Object::_nil());
462 myShape2Name->setText("");
463 if ( send == mySelBtn2 ) {
464 mySelBtn2->setDown(true);
465 mySelBtn->setDown(false);
467 if (subSelectionWay() != ALL_SUBSHAPES) {
468 myEditCurrentArgument = myShape2Name;
471 myEditCurrentArgument = 0;
475 // activateSelection();
476 if(myEditCurrentArgument) {
477 myEditCurrentArgument->setFocus();
485 //=================================================================================
486 // function : onGetInPlace()
488 //=================================================================================
489 void GroupGUI_GroupDlg::onGetInPlace()
491 setInPlaceObj(GEOM::GEOM_Object::_nil());
492 myEditCurrentArgument->setText("");
494 bool isBlocked = myIdList->signalsBlocked();
495 myIdList->blockSignals(true);
496 myIdList->clearSelection();
497 myIdList->blockSignals(isBlocked);
499 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
500 SALOME_ListIO aSelList;
501 aSelMgr->selectedObjects(aSelList);
503 if (aSelList.Extent() != 1)
506 GEOM::GEOM_Object_var anObj =
507 GEOMBase::ConvertIOinGEOMObject(aSelList.First());
508 if (GEOMBase::IsShape(anObj)) {
509 if (!anObj->_is_equivalent(myMainObj) && !anObj->_is_equivalent(myGroup)) {
510 SUIT_OverrideCursor wc;
511 myEditCurrentArgument->setText(GEOMBase::GetName(anObj));
512 GEOM::GEOM_IShapesOperations_var aShapesOp =
513 getGeomEngine()->GetIShapesOperations();
514 if (subSelectionWay() == GET_IN_PLACE) {
515 GEOM::GEOM_Object_var aGetInPlaceObj = aShapesOp->GetInPlace(myMainObj, anObj);
516 setInPlaceObj(aGetInPlaceObj);
519 bool isVisible = true;
520 if (SALOME_View* view = GEOM_Displayer::GetActiveView())
521 isVisible = view->isVisible(aSelList.First());
522 setInPlaceObj(anObj, isVisible);
524 myEditCurrentArgument = 0;
525 //myBusy = true; // just activate but do not select in the list
532 //=================================================================================
533 //function : setInPlaceObj
534 //purpose : temporarily add an object to study and remove old InPlaceObj
535 //=================================================================================
536 void GroupGUI_GroupDlg::setInPlaceObj(GEOM::GEOM_Object_var theObj, const bool isVisible)
538 if (!myInPlaceObj->_is_equivalent(theObj))
540 myInPlaceObj = theObj;
543 // build map of indices
544 myMain2InPlaceIndices.Clear();
545 if (!myInPlaceObj->_is_nil()) {
546 GEOM::GEOM_IShapesOperations_var aShapesOp = getGeomEngine()->GetIShapesOperations();
547 GEOM::GEOM_ILocalOperations_var aLocOp = getGeomEngine()->GetILocalOperations();
549 GEOM::ListOfGO_var aSubObjects = aShapesOp->MakeExplode(myInPlaceObj, getShapeType(), false);
550 for ( int i = 0; i < (int)aSubObjects->length(); i++ )
552 GEOM::ListOfLong_var aCurrList = aShapesOp->GetSameIDs( myMainObj, aSubObjects[i] );
553 if( aCurrList->length() > 1 ) {
554 //rnv : To Fix the 21561: EDF 2184 GEOM: Group with second shape restriction.
555 // In case if GetSameIDs(...) method return more then one ID use
556 // GetSharedShapes(...) method to get sub-shapes of the second shape.
557 GEOM::ListOfGO_var aSubObjects2 = aShapesOp->GetSharedShapes( myMainObj, aSubObjects[i], getShapeType() );
558 for( int j = 0; j < (int)aSubObjects2->length(); j++ ) {
559 CORBA::Long aMainIndex = aLocOp->GetSubShapeIndex( myMainObj, aSubObjects2[j] );
560 CORBA::Long aPlaceIndex = aLocOp->GetSubShapeIndex( myInPlaceObj, aSubObjects[i]);
561 if ( aMainIndex >= 0 && aPlaceIndex > 0 ) {
562 myMain2InPlaceIndices.Bind( aMainIndex, aPlaceIndex );
565 } else if(aCurrList->length() > 0 ) {
566 CORBA::Long aMainIndex = aCurrList[0];
567 CORBA::Long aPlaceIndex = aLocOp->GetSubShapeIndex( myInPlaceObj, aSubObjects[i] );
568 if ( aMainIndex >= 0 && aPlaceIndex > 0) {
569 myMain2InPlaceIndices.Bind( aMainIndex, aPlaceIndex );
574 myInPlaceObjSelectState = subSelectionWay();
575 if (myInPlaceObjSelectState == SUBSHAPES_OF_SHAPE2 && !isVisible)
576 myInPlaceObjSelectState = SUBSHAPES_OF_INVISIBLE_SHAPE2;
579 //=================================================================================
580 // function : SelectionIntoArgument()
581 // purpose : Called when selection has changed
582 //=================================================================================
583 void GroupGUI_GroupDlg::SelectionIntoArgument()
585 if (subSelectionWay() != ALL_SUBSHAPES && myEditCurrentArgument == myShape2Name) {
587 if( !myInPlaceObj->_is_nil() ) {
588 mySelBtn2->setDown(false);
593 if (myEditCurrentArgument == myMainName) { // Selection of a main shape is active
594 myEditCurrentArgument->setText("");
597 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
598 SALOME_ListIO aSelList;
599 aSelMgr->selectedObjects(aSelList);
600 int nbSel = aSelList.Extent();
603 GEOM::GEOM_Object_var anObj =
604 GEOMBase::ConvertIOinGEOMObject(aSelList.First());
606 if (GEOMBase::IsShape(anObj)) {
607 if (myIsHiddenMain) {
608 GEOM_Displayer* aDisplayer = getDisplayer();
609 aDisplayer->Display(myMainObj);
610 myIsHiddenMain = false;
613 if (!CORBA::is_nil(myMainObj)) {
614 mySelBtn->setDown(false);
615 SALOME_View* view = GEOM_Displayer::GetActiveView();
617 CORBA::String_var aMainEntry = myMainObj->GetStudyEntry();
618 Handle(SALOME_InteractiveObject) io =
619 new SALOME_InteractiveObject (aMainEntry.in(), "GEOM", "TEMP_IO");
620 if (view->isVisible(io)) myWasHiddenMain = false;
623 myEditCurrentArgument->setText(GEOMBase::GetName(anObj));
624 // activate sub-shapes selection by default
625 myEditCurrentArgument = 0;
631 if (myIsHiddenMain) {
632 GEOM_Displayer* aDisplayer = getDisplayer();
633 aDisplayer->Display(myMainObj);
634 myIsHiddenMain = false;
636 myMainObj = GEOM::GEOM_Object::_nil();
639 else { // an attempt to synchronize list box selection with 3d viewer
640 if (myBusy || myMainObj->_is_nil()) {
644 bool isBlocked = myIdList->signalsBlocked();
645 myIdList->blockSignals(true);
646 myIdList->clearSelection();
648 TColStd_IndexedMapOfInteger aMapIndex;
649 int nbSel = getSelectedSubshapes(aMapIndex);
653 for (int i = 0, n = myIdList->count(); i < n; i++)
654 aMap.insert(myIdList->item(i)->text().toInt(), i);
656 bool highlight = false;
657 for (int ii = 1, nn = aMapIndex.Extent(); ii <= nn; ii++) {
658 if (aMap.contains(aMapIndex(ii))) {
659 myIdList->item(aMap[aMapIndex(ii)])->setSelected(true);
664 highlightSubShapes();
666 myIdList->blockSignals(isBlocked);
672 //=================================================================================
673 // function : ConstructorsClicked()
674 // purpose : Radio button management
675 //=================================================================================
676 void GroupGUI_GroupDlg::ConstructorsClicked(int constructorId)
678 if (getConstructorId() != constructorId)
679 setConstructorId(constructorId);
681 myIsShapeType = true;
683 myEditCurrentArgument = 0;
685 setInPlaceObj(myInPlaceObj); // to rebuild myMain2InPlaceIndices
690 //=================================================================================
691 // function : selectAllSubShapes
693 //=================================================================================
694 void GroupGUI_GroupDlg::selectAllSubShapes()
696 if (CORBA::is_nil(myMainObj) || !myIsShapeType)
699 GEOM::ListOfLong_var aSubShapes;
700 GEOM::GEOM_IShapesOperations_var aShOp = getGeomEngine()->GetIShapesOperations();
701 aSubShapes = aShOp->SubShapeAllIDs(myMainObj, getShapeType(), false);
702 if (aSubShapes->length() > 0) {
703 if (subSelectionWay() == ALL_SUBSHAPES)
705 // myIdList->clear(); // for sorted final list?
707 if (!aShOp->IsDone())
712 aSubShapes = new GEOM::ListOfLong();
713 aSubShapes->length(myMain2InPlaceIndices.Extent());
714 TColStd_DataMapIteratorOfDataMapOfIntegerInteger m2ip (myMain2InPlaceIndices);
715 for (int i = 0; m2ip.More(); i++, m2ip.Next())
716 aSubShapes[i] = m2ip.Key();
719 bool isBlocked = myIdList->signalsBlocked();
720 myIdList->blockSignals(true);
722 for (int i = 0, n = aSubShapes->length(); i < n; i++) {
723 CORBA::Long anIndex = aSubShapes[i];
727 QListWidgetItem* anItem = 0;
728 QString text = QString("%1").arg(anIndex);
729 // if (!myInPlaceObj->_is_nil()) {
730 QList<QListWidgetItem*> found = myIdList->findItems(text, Qt::MatchExactly);
731 if (found.count()) anItem = found[0];
734 anItem = new QListWidgetItem(text);
735 anItem->setTextColor( myGroupIdList.contains(anIndex) ? QColor( GROUP_IDLST_COLOR ) : QColor( GROUP_NEWIDLST_COLOR ) );
736 myIdList->addItem(anItem);
738 anItem->setSelected(true);
741 myIdList->blockSignals(isBlocked);
742 highlightSubShapes();
746 //=================================================================================
747 // function : showOnlySelected
749 //=================================================================================
750 void GroupGUI_GroupDlg::showOnlySelected()
752 if (CORBA::is_nil(myMainObj) || !myIsShapeType)
755 QPushButton* send = (QPushButton*)sender();
756 if (send == myShowAllBtn) {
761 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
762 SALOME_ListIO aSelList;
763 aSelMgr->selectedObjects(aSelList);
765 GEOM_Displayer* aDisplayer = getDisplayer();
767 if (send == myHideSelBtn) {
768 aDisplayer->Erase(aSelList, /*forced=*/false, /*updateViewer=*/true);
771 // Mantis issue 0021421: do not hide main shape, if explode on VERTEX
772 SALOME_View* view = GEOM_Displayer::GetActiveView();
774 CORBA::String_var aMainEntry = myMainObj->GetStudyEntry();
775 Handle(SALOME_InteractiveObject) io =
776 new SALOME_InteractiveObject (aMainEntry.in(), "GEOM", "TEMP_IO");
777 if (view->isVisible(io)) myIsHiddenMain = true;
779 //keep the selected entry and IO in the map for checking
780 std::map<QString, Handle(SALOME_InteractiveObject)> aSelEntriesMap;
781 SALOME_ListIteratorOfListIO aSelIt(aSelList);
782 for ( ; aSelIt.More(); aSelIt.Next() ) {
783 Handle(SALOME_InteractiveObject) anSelIO = aSelIt.Value();
784 aSelEntriesMap[anSelIO->getEntry()] = anSelIO;
786 //get the displayed sub-shapes
787 SALOME_ListIO displayed;
788 view->GetVisible(displayed);
789 // Erase all, except the selected sub-shapes
790 std::map<QString, Handle(SALOME_InteractiveObject)>::iterator
791 aSelDispIter = aSelEntriesMap.end();
792 SALOME_ListIteratorOfListIO aDispIt( displayed );
793 for ( ; aDispIt.More(); aDispIt.Next() ) {
794 Handle(SALOME_InteractiveObject) anIO = aDispIt.Value();
795 aSelDispIter = aSelEntriesMap.find( anIO->getEntry() );
796 if ( aSelDispIter != aSelEntriesMap.end() ) {
797 //sub-shape is selected, so erase it's record from map to keep in it not displayed, but selected sub-shapes only
798 aSelEntriesMap.erase(aSelDispIter);
800 //sub-shape is not in the map of selected, then erase it from view
801 aDisplayer->Erase( anIO, /*forced = */false, /*updateViewer = */false );
805 if ( !aSelEntriesMap.empty() ) {
806 // Build a presentation of the selected, but not displayed sub-shapes
807 TopoDS_Shape aMainShape = GEOM_Client::get_client().GetShape(GeometryGUI::GetGeomGen(), myMainObj);
808 TopTools_IndexedMapOfShape aSubShapesMap;
809 TopExp::MapShapes(aMainShape, aSubShapesMap);
810 QString anEntryBase = aMainEntry.in();
812 TopExp_Explorer anExp (aMainShape, getShapeType());
813 for (; anExp.More(); anExp.Next()) {
814 TopoDS_Shape aSubShape = anExp.Current();
815 int index = aSubShapesMap.FindIndex(aSubShape);
816 QString anEntry = QString( "TEMP_" ) + anEntryBase + QString("_%1").arg(index);
817 if ( aSelEntriesMap.find( anEntry ) == aSelEntriesMap.end() ) {
818 //skip not selected sub-shapes
821 SALOME_Prs* aPrs = aDisplayer->buildSubshapePresentation(aSubShape, anEntry, view);
823 displayPreview(aPrs, true, false); // append, do not update
827 aDisplayer->UpdateViewer();
830 // Mantis issue 0021421: do not hide main shape, if explode on VERTEX
831 if (getShapeType() == TopAbs_VERTEX && myIsHiddenMain) {
832 aDisplayer->Display(myMainObj);
835 // for the case when selected ids were not displayed in the viewer: Mantis issue 0021367
836 highlightSubShapes();
840 //=================================================================================
841 // function : getSelectedSubshapes
843 //=================================================================================
844 int GroupGUI_GroupDlg::getSelectedSubshapes (TColStd_IndexedMapOfInteger& theMapIndex)
848 SalomeApp_Application* app = myGeomGUI->getApp();
849 if (!app || myMainObj->_is_nil())
852 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
853 SALOME_ListIO aSelList;
854 aSelMgr->selectedObjects(aSelList);
856 // try to find out and process the global selection
857 // (of not published objects and of published sub-shapes)
859 SALOME_ListIteratorOfListIO anIter (aSelList);
860 for (int i = 0; anIter.More(); anIter.Next(), i++)
862 Handle(SALOME_InteractiveObject) anIObj = anIter.Value();
863 QString anEntry = anIObj->getEntry();
865 int index = anEntry.lastIndexOf(str);
866 if (index > 0) // selection among special preview
868 anEntry.remove(0, index+1);
869 int anIndex = anEntry.toInt();
871 theMapIndex.Add(anIndex);
873 else // selection among published shapes
875 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>(app->activeStudy());
876 if (!appStudy) return 0;
877 _PTR(Study) aStudy = appStudy->studyDS();
879 _PTR(SObject) aSObj (aStudy->FindObjectID(anEntry.toUtf8().constData()));
880 if ( ! GeometryGUI::IsInGeomComponent( aSObj )) continue;
881 GEOM::GEOM_Object_var aGeomObj =
882 GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aSObj));
884 if (GEOMBase::GetShape(aGeomObj, aShape)) {
885 if (aGeomObj->GetType() == GEOM_GROUP || aShape.ShapeType() == getShapeType()) {
886 if (subSelectionWay() != ALL_SUBSHAPES &&
887 GEOMBase::GetName(aGeomObj) == myShape2Name->text()) {
888 // Skip selected in place object.
892 TopTools_IndexedMapOfShape aMainMap;
893 TopoDS_Shape aMainShape = GEOM_Client::get_client().GetShape(GeometryGUI::GetGeomGen(), myMainObj);
894 TopExp::MapShapes(aMainShape, aMainMap);
896 TopExp_Explorer anExp (aShape, getShapeType());
897 bool isShowWarning = true;
898 for (; anExp.More(); anExp.Next()) {
899 TopoDS_Shape aSubShape = anExp.Current();
900 int anIndex = aMainMap.FindIndex(aSubShape);
903 SUIT_MessageBox::warning(app->desktop(), QObject::tr("WRN_WARNING"),
904 tr("WRN_NOT_SUBSHAPE"));
905 isShowWarning = false;
909 if (subSelectionWay() != ALL_SUBSHAPES &&
910 !myMain2InPlaceIndices.IsBound(anIndex))
912 theMapIndex.Add(anIndex);
921 return theMapIndex.Extent();
924 //=================================================================================
927 //=================================================================================
928 void GroupGUI_GroupDlg::add()
930 TColStd_IndexedMapOfInteger aMapIndex;
931 int nbSel = getSelectedSubshapes(aMapIndex);
933 TColStd_MapOfInteger aMap;
934 for (int i = 0, n = myIdList->count(); i < n; i++)
935 aMap.Add(myIdList->item(i)->text().toInt());
938 bool isBlocked = myIdList->signalsBlocked();
939 myIdList->blockSignals(true);
941 for (int i = 1, n = aMapIndex.Extent(); i <= n; i++) {
942 if (aMap.Contains(aMapIndex(i)))
945 QListWidgetItem* anItem = new QListWidgetItem(QString("%1").arg(aMapIndex(i)));
946 anItem->setTextColor( myGroupIdList.contains( aMapIndex( i ) ) ? QColor( GROUP_IDLST_COLOR ) : QColor( GROUP_NEWIDLST_COLOR ) );
947 myIdList->addItem(anItem);
948 anItem->setSelected(true);
951 myIdList->blockSignals(isBlocked);
957 //=================================================================================
960 //=================================================================================
961 void GroupGUI_GroupDlg::remove()
963 bool isBlocked = myIdList->signalsBlocked();
964 myIdList->blockSignals(true);
966 QListIterator<QListWidgetItem*> it (myIdList->selectedItems());
970 myIdList->blockSignals(isBlocked);
972 highlightSubShapes();
975 //=================================================================================
976 //function : subSelectionWay
978 //=================================================================================
979 int GroupGUI_GroupDlg::subSelectionWay() const
981 return myRestrictGroup->checkedId();
984 //=================================================================================
985 // function : getShapeType()
987 //=================================================================================
988 TopAbs_ShapeEnum GroupGUI_GroupDlg::getShapeType() const
990 switch (getConstructorId()) {
991 case 0: return TopAbs_VERTEX;
992 case 1: return TopAbs_EDGE;
993 case 2: return TopAbs_FACE;
994 case 3: return TopAbs_SOLID;
995 default: return TopAbs_SHAPE;
999 //=================================================================================
1000 // function : setShapeType()
1002 //=================================================================================
1003 void GroupGUI_GroupDlg::setShapeType(const TopAbs_ShapeEnum theType)
1007 case TopAbs_VERTEX: anId = 0; break;
1008 case TopAbs_EDGE: anId = 1; break;
1009 case TopAbs_FACE: anId = 2; break;
1010 case TopAbs_SOLID: anId = 3; break;
1013 setConstructorId(anId);
1016 myIsShapeType = true;
1017 // workaround to avoid set checked button 0
1018 setConstructorId(anId);
1022 //=================================================================================
1023 // function : activateSelection
1024 // purpose : Activate selection in accordance with myEditCurrentArgument
1025 //=================================================================================
1026 void GroupGUI_GroupDlg::activateSelection()
1028 //bool isApply = ((QPushButton*)sender() == buttonApply());
1029 if(!isApplyAndClose())
1030 erasePreview(false);
1033 if (!myMainObj->_is_nil() &&
1034 !myEditCurrentArgument &&
1035 myIsShapeType) // check if shape type is already chosen by user
1037 GEOM_Displayer* aDisplayer = getDisplayer();
1039 //display mode for main shape
1040 if ( myDmMode == -1 ) {
1041 SALOME_View* view = GEOM_Displayer::GetActiveView();
1043 CORBA::String_var aMainEntry = myMainObj->GetStudyEntry();
1044 Handle(SALOME_InteractiveObject) io =
1045 new SALOME_InteractiveObject (aMainEntry.in(), "GEOM", "TEMP_IO");
1046 if ( view->isVisible( io ) ) {
1047 Handle(GEOM_AISShape) aSh = GEOMBase::ConvertIOinGEOMAISShape( io, true );
1049 myDmMode = aSh->isTopLevel() ? aSh->prevDisplayMode() : aSh->DisplayMode();
1053 myDmMode = SUIT_Session::session()->resourceMgr()->integerValue( "Geometry", "display_mode" );
1056 aDisplayer->SetDisplayMode(myDmMode);
1058 // Mantis issue 0021421: do not hide main shape, if explode on VERTEX
1059 if(getShapeType() != TopAbs_VERTEX) {
1060 aDisplayer->Erase(myMainObj, false, false);
1061 myIsHiddenMain = true;
1064 aDisplayer->Display(myMainObj);
1066 aDisplayer->Erase(myGroup, false, false);
1068 QColor aColor = SUIT_Session::session()->resourceMgr()->colorValue( "Geometry", "editgroup_color" );
1069 Quantity_NameOfColor aCol = SalomeApp_Tools::color( aColor ).Name();
1071 if(!isApplyAndClose()) {
1072 SUIT_ViewWindow* aViewWindow = 0;
1073 SUIT_Study* activeStudy = SUIT_Session::session()->activeApplication()->activeStudy();
1075 aViewWindow = SUIT_Session::session()->activeApplication()->desktop()->activeWindow();
1076 if (aViewWindow == 0) return;
1078 SUIT_ViewManager* aViewManager = aViewWindow->getViewManager();
1079 if (aViewManager->getType() != OCCViewer_Viewer::Type() &&
1080 aViewManager->getType() != SVTK_Viewer::Type())
1083 SUIT_ViewModel* aViewModel = aViewManager->getViewModel();
1084 SALOME_View* aView = dynamic_cast<SALOME_View*>(aViewModel);
1085 if (aView == 0) return;
1087 TopoDS_Shape aMainShape = GEOM_Client::get_client().GetShape(GeometryGUI::GetGeomGen(), myMainObj);
1088 TopoDS_Shape aRestrictionShape;
1090 if (subSelectionWay() == ALL_SUBSHAPES) {
1091 aRestrictionShape = aMainShape;
1093 TopTools_IndexedMapOfShape aSubShapesMap;
1094 TopExp::MapShapes(aMainShape, aSubShapesMap);
1095 CORBA::String_var aMainEntry = myMainObj->GetStudyEntry();
1096 QString anEntryBase = aMainEntry.in();
1098 TopExp_Explorer anExp (aRestrictionShape, getShapeType());
1099 for (; anExp.More(); anExp.Next()) {
1100 TopoDS_Shape aSubShape = anExp.Current();
1101 int index = aSubShapesMap.FindIndex(aSubShape);
1102 QString anEntry = QString( "TEMP_" ) + anEntryBase + QString("_%1").arg(index);
1103 Handle(SALOME_InteractiveObject) io =
1104 new SALOME_InteractiveObject(anEntry.toUtf8(), "GEOM", "TEMP_IO");
1105 if ( myGroupIdList.contains( index ) ) {
1106 aDisplayer->SetColor( aCol );
1109 aDisplayer->UnsetColor();
1111 SALOME_Prs* aPrs = aDisplayer->buildSubshapePresentation(aSubShape, anEntry, aView);
1113 displayPreview(aPrs, true, false); // append, do not update
1114 // TODO: map or delete Prs
1118 else if (!myInPlaceObj->_is_nil()) {
1119 TopTools_IndexedMapOfShape aSubShapesMap;
1120 TopExp::MapShapes(aMainShape, aSubShapesMap);
1121 CORBA::String_var aMainEntry = myMainObj->GetStudyEntry();
1122 QString anEntryBase = aMainEntry.in();
1124 TColStd_DataMapIteratorOfDataMapOfIntegerInteger aM2IPit (myMain2InPlaceIndices);
1125 for (; aM2IPit.More(); aM2IPit.Next()) {
1126 int index = aM2IPit.Key();
1127 TopoDS_Shape aSubShape = aSubShapesMap.FindKey(index);
1128 QString anEntry = QString( "TEMP_" ) + anEntryBase + QString("_%1").arg(index);
1130 if ( myGroupIdList.contains( index ) ) {
1131 aDisplayer->SetColor( aCol );
1134 aDisplayer->UnsetColor();
1137 SALOME_Prs* aPrs = aDisplayer->buildSubshapePresentation(aSubShape, anEntry, aView);
1139 displayPreview(aPrs, true, false); // append, do not update
1143 aDisplayer->UnsetDisplayMode();
1144 aDisplayer->UnsetColor();
1145 aDisplayer->UpdateViewer();
1149 globalSelection(GEOM_ALLSHAPES);
1151 SelectionIntoArgument();
1154 //=================================================================================
1155 // function : updateState
1157 //=================================================================================
1158 void GroupGUI_GroupDlg::updateState (bool isAdd)
1160 myAddBtn->setEnabled(!myEditCurrentArgument && !CORBA::is_nil(myMainObj) && isAdd);
1161 //myShowOnlyBtn->setEnabled(!myEditCurrentArgument && !CORBA::is_nil(myMainObj) && isAdd);
1163 bool hasSel = myIdList->selectedItems().count() > 0;
1165 myRemBtn->setEnabled(hasSel);
1166 myRestrictGroupBox->setEnabled(!CORBA::is_nil(myMainObj));
1167 mySelAllBtn->setEnabled(!CORBA::is_nil(myMainObj));
1169 mySelBtn2->setEnabled(subSelectionWay() != ALL_SUBSHAPES);
1170 myShape2Name->setEnabled(subSelectionWay() != ALL_SUBSHAPES);
1171 myFilterGrp->setEnabled(!CORBA::is_nil(myMainObj) &&
1172 subSelectionWay() == ALL_SUBSHAPES &&
1174 getShapeType() != TopAbs_VERTEX);
1175 // manage of 'Plot' button access
1176 GEOM::GEOM_IShapesOperations_var aShOp = getGeomEngine()->GetIShapesOperations();
1177 GEOM::ListOfLong_var aSubShapes = aShOp->SubShapeAllIDs( myMainObj, getShapeType(), false );
1178 bool hasCurrentEntities = aSubShapes->length() > 0;
1179 #ifndef DISABLE_PLOT2DVIEWER
1180 myPlotDistributionButton->setEnabled( myFilterGrp->isEnabled() &&
1182 ( getShapeType() == TopAbs_EDGE ||
1183 getShapeType() == TopAbs_FACE ||
1184 getShapeType() == TopAbs_SOLID ) &&
1185 hasCurrentEntities );
1187 if (subSelectionWay() == ALL_SUBSHAPES)
1188 setInPlaceObj(GEOM::GEOM_Object::_nil());
1191 //=================================================================================
1192 // function : selectionChanged
1194 //=================================================================================
1195 void GroupGUI_GroupDlg::selectionChanged()
1197 highlightSubShapes();
1200 //=================================================================================
1201 // function : highlightSubShapes
1203 //=================================================================================
1204 void GroupGUI_GroupDlg::highlightSubShapes()
1206 if (CORBA::is_nil(myMainObj))
1209 TColStd_MapOfInteger anIds;
1213 int ii = 0, nn = myIdList->count();
1214 for (; ii < nn; ii++)
1216 if (myIdList->item(ii)->isSelected()) {
1217 int id = myIdList->item(ii)->text().toInt();
1218 if (subSelectionWay() != ALL_SUBSHAPES &&
1219 !myMain2InPlaceIndices.IsBound(id)) {
1220 //myIdList->item(ii)->setSelected(false);
1227 SalomeApp_Application* app = myGeomGUI->getApp();
1228 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
1229 aSelMgr->clearSelected();
1231 SUIT_ViewWindow* aViewWindow = 0;
1232 SUIT_Study* activeStudy = app->activeStudy();
1234 aViewWindow = app->desktop()->activeWindow();
1235 if (aViewWindow == 0) return;
1237 SUIT_ViewManager* aViewManager = aViewWindow->getViewManager();
1238 if (aViewManager->getType() != OCCViewer_Viewer::Type() &&
1239 aViewManager->getType() != SVTK_Viewer::Type())
1242 SUIT_ViewModel* aViewModel = aViewManager->getViewModel();
1243 SALOME_View* aView = dynamic_cast<SALOME_View*>(aViewModel);
1244 if (aView == 0) return;
1246 // TODO??: use here GEOMBase_Helper::myPreview instead of ic->DisplayedObjects()
1248 OCCViewer_Viewer* v3d = ((OCCViewer_ViewManager*)aViewManager)->getOCCViewer();
1249 Handle(AIS_InteractiveContext) ic = v3d->getAISContext();
1250 AIS_ListOfInteractive List;
1251 //ic->DisplayedObjects(List);
1252 ic->ObjectsInside(List); // Mantis issue 0021367
1254 SALOME_ListIO aSelList;
1256 // To highlight the selected sub-shape in Object Browser, if it's already published under the main shape
1257 GEOM::GEOM_ILocalOperations_var aLocOp = getGeomEngine()->GetILocalOperations();
1258 QMap<int, QString> childsMap;
1259 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>(app->activeStudy());
1261 _PTR(Study) aStudy = appStudy->studyDS();
1262 CORBA::String_var aMainEntry = myMainObj->GetStudyEntry();
1263 QString anEntry = aMainEntry.in();
1264 _PTR(SObject) aSObj (aStudy->FindObjectID(anEntry.toUtf8().constData()));
1265 _PTR(ChildIterator) anIt (aStudy->NewChildIterator(aSObj));
1266 for (anIt->InitEx(true); anIt->More(); anIt->Next()) {
1267 GEOM::GEOM_Object_var aChild = GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(anIt->Value()));
1268 if (!CORBA::is_nil(aChild)) {
1269 int index = aLocOp->GetSubShapeIndex(myMainObj, aChild);
1270 CORBA::String_var aChildEntry = aChild->GetStudyEntry();
1271 QString anEntry = aChildEntry.in();
1272 childsMap.insert(index, anEntry);
1277 AIS_ListIteratorOfListOfInteractive ite (List);
1278 for (; ite.More(); ite.Next()) {
1279 if (ite.Value()->IsInstance(STANDARD_TYPE(GEOM_AISShape))) {
1280 Handle(GEOM_AISShape) aSh = Handle(GEOM_AISShape)::DownCast(ite.Value());
1282 Handle(SALOME_InteractiveObject) anIO = aSh->getIO();
1283 QString anEntry = anIO->getEntry();
1284 int index = anEntry.lastIndexOf("_");
1285 anEntry.remove(0, index+1);
1286 int anIndex = anEntry.toInt();
1287 if (anIds.Contains(anIndex)) {
1288 aSelList.Append(anIO);
1289 if (childsMap.contains (anIndex)) {
1290 Handle(SALOME_InteractiveObject) tmpIO = new SALOME_InteractiveObject(childsMap.value(anIndex).toUtf8().constData(), "GEOM", "TEMP_IO");
1291 aSelList.Append(tmpIO);
1297 aSelMgr->setSelectedObjects(aSelList);
1302 updateState(aSelList.Extent() > 0);
1304 myAddBtn->setEnabled(true);
1305 myAddBtn->setEnabled(true);
1306 myRemBtn->setEnabled(true);
1310 //=================================================================================
1311 // function : createOperation
1313 //=================================================================================
1314 GEOM::GEOM_IOperations_ptr GroupGUI_GroupDlg::createOperation()
1316 return getGeomEngine()->GetIGroupOperations();
1319 #define RETURN_WITH_MSG(a, b) \
1321 theMessage += (b); \
1325 //=================================================================================
1326 // function : isValid()
1327 // purpose : Verify validity of input data
1328 //=================================================================================
1329 bool GroupGUI_GroupDlg::isValid(QString& theMessage)
1331 SalomeApp_Study* study = getStudy();
1333 RETURN_WITH_MSG (!study->studyDS()->GetProperties()->IsLocked(), tr("GEOM_STUDY_LOCKED"))
1335 if (myMode == CreateGroup) {
1336 RETURN_WITH_MSG(!CORBA::is_nil(myMainObj), tr("NO_MAIN_OBJ"))
1339 RETURN_WITH_MSG(!CORBA::is_nil(myMainObj), tr("NO_GROUP"))
1342 QString aName (getNewObjectName());
1343 RETURN_WITH_MSG (!aName.trimmed().isEmpty(), tr("EMPTY_NAME"))
1345 RETURN_WITH_MSG (myIdList->count(), tr("EMPTY_LIST"))
1349 //=================================================================================
1350 // function : execute
1352 //=================================================================================
1353 bool GroupGUI_GroupDlg::execute(ObjectList& objects)
1355 GEOM::GEOM_IGroupOperations_var anOper = GEOM::GEOM_IGroupOperations::_narrow(getOperation());
1357 GEOM::GEOM_Object_var aGroup;
1358 if (myMode == CreateGroup)
1359 aGroup = anOper->CreateGroup(myMainObj, getShapeType());
1360 else if (myMode == EditGroup)
1363 if (CORBA::is_nil(aGroup) || (myMode == CreateGroup && !anOper->IsDone()))
1366 GEOM::ListOfLong_var aCurrList = anOper->GetObjects(aGroup);
1367 if (!anOper->IsDone())
1370 if (aCurrList->length() > 0)
1372 anOper->DifferenceIDs(aGroup, aCurrList);
1373 if (!anOper->IsDone())
1377 int ii, nn = myIdList->count();
1380 GEOM::ListOfLong_var aNewList = new GEOM::ListOfLong;
1381 aNewList->length(nn);
1382 for (ii = 0; ii < nn; ii++) {
1383 aNewList[ii] = myIdList->item(ii)->text().toInt();
1385 anOper->UnionIDs(aGroup, aNewList);
1386 if (!anOper->IsDone())
1390 SalomeApp_Study* study = getStudy();
1392 QString objIOR = GEOMBase::GetIORFromObject(aGroup);
1394 _PTR(SObject) SO (study->studyDS()->FindObjectIOR(objIOR.toLatin1().constData()));
1396 _PTR(StudyBuilder) aBuilder (study->studyDS()->NewBuilder());
1397 aBuilder->SetName(SO, getNewObjectName().toUtf8().constData());
1402 objects.push_back(aGroup._retn());
1407 //================================================================
1408 // Function : getFather
1409 // Purpose : Get father object for object to be added in study
1410 // (called with addInStudy method)
1411 //================================================================
1412 GEOM::GEOM_Object_ptr GroupGUI_GroupDlg::getFather(GEOM::GEOM_Object_ptr theObj)
1414 GEOM::GEOM_Object_var aFatherObj;
1415 if (theObj->GetType() == GEOM_GROUP) {
1416 GEOM::GEOM_IGroupOperations_var anOper = GEOM::GEOM_IGroupOperations::_narrow(getOperation());
1417 aFatherObj = anOper->GetMainShape(theObj);
1419 return aFatherObj._retn();
1422 void GroupGUI_GroupDlg::ClickOnOkFilter()
1424 if (CORBA::is_nil(myMainObj) || subSelectionWay() != ALL_SUBSHAPES || !myIsShapeType || getShapeType() == TopAbs_VERTEX)
1427 TopoDS_Shape aMainShape = GEOM_Client::get_client().GetShape(GeometryGUI::GetGeomGen(), myMainObj);
1428 TopTools_IndexedMapOfShape aSubShapesMap;
1429 TopExp::MapShapes(aMainShape, aSubShapesMap);
1430 //SALOME_View* view = GEOM_Displayer::GetActiveView();
1431 getDisplayer()->Erase(myMainObj, false, false);
1432 CORBA::String_var aMainEntry = myMainObj->GetStudyEntry();
1433 QString anEntryBase = aMainEntry.in();
1435 SALOME_ListIO toSelect;
1437 TopExp_Explorer anExp (aMainShape, (TopAbs_ShapeEnum)getShapeType());
1438 for (; anExp.More(); anExp.Next())
1440 TopoDS_Shape aSubShape = anExp.Current();
1441 int index = aSubShapesMap.FindIndex(aSubShape);
1442 QString anEntry = QString( "TEMP_" ) + anEntryBase + QString("_%1").arg(index);
1443 if ( !getDisplayer()->IsDisplayed( anEntry ) )
1446 double factor = GEOMUtils::ShapeToDouble(aSubShape).second;
1447 double v1 = myLessFilterSpin->value();
1448 double v2 = myGreaterFilterSpin->value();
1449 bool isLess = myLessFilterCombo->itemData(myLessFilterCombo->currentIndex()).toInt() == Filter_LT ? factor < v1 : factor <= v1;
1450 bool isGreater = myGreaterFilterCombo->itemData(myGreaterFilterCombo->currentIndex()).toInt() == Filter_GT ? factor > v2 : factor >= v2;
1451 if ( ( myLessFilterCheck->isChecked() && myGreaterFilterCheck->isChecked() && isLess && isGreater ) ||
1452 ( myLessFilterCheck->isChecked() && !myGreaterFilterCheck->isChecked() && isLess ) ||
1453 ( myGreaterFilterCheck->isChecked() && !myLessFilterCheck->isChecked() && isGreater ) ) {
1454 Handle(SALOME_InteractiveObject) io = new SALOME_InteractiveObject();
1455 io->setEntry( anEntry.toUtf8().constData() );
1456 toSelect.Append(io);
1459 if ( toSelect.Extent() > 0 ) {
1460 myGeomGUI->getApp()->selectionMgr()->setSelectedObjects(toSelect);
1461 SUIT_MessageBox::information( this,
1463 tr( "GEOM_SOME_SHAPES_SELECTED").arg( toSelect.Extent() ),
1467 SUIT_MessageBox::information( this,
1469 tr( "GEOM_NO_SHAPES_SELECTED" ),
1475 #ifndef DISABLE_PLOT2DVIEWER
1476 //=================================================================================
1477 // function : ClickOnPlot()
1478 // purpose : opens "Shape Statistics" dialog box in order to plot sub-shapes distribution.
1479 //=================================================================================
1480 void GroupGUI_GroupDlg::ClickOnPlot()
1482 TopoDS_Shape aMainShape = GEOM_Client::get_client().GetShape(GeometryGUI::GetGeomGen(), myMainObj);
1483 QDialog* dlg = new MeasureGUI_ShapeStatisticsDlg( this, aMainShape, getShapeType() );
1490 void GroupGUI_GroupDlg::MeasureToggled()
1492 myLessFilterSpin->setEnabled(myLessFilterCheck->isChecked());
1493 myLessFilterCombo->setEnabled(myLessFilterCheck->isChecked());
1494 myGreaterFilterSpin->setEnabled(myGreaterFilterCheck->isChecked());
1495 myGreaterFilterCombo->setEnabled(myGreaterFilterCheck->isChecked());
1496 myApplyFilterButton->setEnabled(myLessFilterCheck->isChecked() || myGreaterFilterCheck->isChecked());
1499 //=================================================================================
1500 // function : getSourceObjects
1501 // purpose : virtual method to get source objects
1502 //=================================================================================
1503 QList<GEOM::GeomObjPtr> GroupGUI_GroupDlg::getSourceObjects()
1505 QList<GEOM::GeomObjPtr> res;
1506 GEOM::GeomObjPtr aGeomObjPtr1(myMainObj), aGeomObjPtr2(myInPlaceObj);
1507 res << aGeomObjPtr1 << aGeomObjPtr2;