1 // Copyright (C) 2007-2016 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>
65 #include <AIS_ListOfInteractive.hxx>
66 #include <AIS_ListIteratorOfListOfInteractive.hxx>
69 #include <TopExp_Explorer.hxx>
70 #include <TopTools_IndexedMapOfShape.hxx>
71 #include <TColStd_IndexedMapOfInteger.hxx>
72 #include <TColStd_MapOfInteger.hxx>
73 #include <TColStd_DataMapIteratorOfDataMapOfIntegerInteger.hxx>
75 #include <GEOMImpl_Types.hxx>
77 #define GROUP_IDLST_COLOR Qt::blue // Specific color for the IDs of subShapes in the dialog box
78 #define GROUP_NEWIDLST_COLOR Qt::red // Specific color for the new IDs of subShapes in the dialog box
81 enum { ALL_SUBSHAPES = 0, GET_IN_PLACE, SUBSHAPES_OF_SHAPE2, SUBSHAPES_OF_INVISIBLE_SHAPE2 };
82 enum { Filter_LT, Filter_LE, Filter_GT, Filter_GE };
85 GroupGUI_GroupDlg::GroupGUI_GroupDlg (Mode mode, GeometryGUI* theGeometryGUI, QWidget* parent)
86 : GEOMBase_Skeleton(theGeometryGUI, parent, false),
90 myIsHiddenMain(false),
91 myWasHiddenMain(true),
94 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
96 QPixmap image0 (resMgr->loadPixmap("GEOM", tr("ICON_OBJBROWSER_VERTEX")));
97 QPixmap image1 (resMgr->loadPixmap("GEOM", tr("ICON_OBJBROWSER_EDGE")));
98 QPixmap image2 (resMgr->loadPixmap("GEOM", tr("ICON_OBJBROWSER_FACE")));
99 QPixmap image3 (resMgr->loadPixmap("GEOM", tr("ICON_OBJBROWSER_SOLID")));
100 QPixmap iconSelect (resMgr->loadPixmap("GEOM", tr("ICON_SELECT")));
102 setWindowTitle(myMode == CreateGroup ? tr("CREATE_GROUP_TITLE") : tr("EDIT_GROUP_TITLE"));
104 // Shape type button group
105 mainFrame()->GroupConstructors->setEnabled(myMode == CreateGroup);
106 mainFrame()->GroupConstructors->setTitle(tr("SHAPE_TYPE"));
107 mainFrame()->RadioButton1->setIcon(image0);
108 mainFrame()->RadioButton2->setIcon(image1);
109 mainFrame()->RadioButton3->setIcon(image2);
110 mainFrame()->RadioButton4->setIcon(image3);
111 mainFrame()->RadioButton4->show();
114 mainFrame()->GroupBoxName->setTitle(tr("GROUP_NAME"));
116 // Main shape and sub-shapes
117 QGroupBox* GroupMedium = new QGroupBox(tr("MAIN_SUB_SHAPES"), centralWidget());
118 QGridLayout* aMedLayout = new QGridLayout(GroupMedium);
119 aMedLayout->setMargin(9);
120 aMedLayout->setSpacing(6);
122 QLabel* aMainLabel = new QLabel(tr("MAIN_SHAPE"), GroupMedium);
124 mySelBtn = new QPushButton(GroupMedium);
125 mySelBtn->setIcon(iconSelect);
126 mySelBtn->setEnabled(myMode == CreateGroup);
128 myMainName = new QLineEdit(GroupMedium);
129 myMainName->setReadOnly(true);
130 myMainName->setEnabled(myMode == CreateGroup);
132 myRestrictGroupBox = new QGroupBox(tr("SHAPE_SEL_RESTR"), GroupMedium);
133 myRestrictGroup = new QButtonGroup(myRestrictGroupBox);
134 QRadioButton* allSubs = new QRadioButton(tr("NO_RESTR") , myRestrictGroupBox);
135 QRadioButton* inPlaceSubs = new QRadioButton(tr("GEOM_PARTS_OF_SHAPE2"), myRestrictGroupBox);
136 QRadioButton* shape2Subs = new QRadioButton(tr("SUBSHAPES_OF_SHAPE2") , myRestrictGroupBox);
137 QGridLayout* aRestrictLayout = new QGridLayout(myRestrictGroupBox);
139 QLabel* aSecondLabel = new QLabel(tr("SECOND_SHAPE"), myRestrictGroupBox);
140 mySelBtn2 = new QPushButton(myRestrictGroupBox);
141 mySelBtn2->setIcon(iconSelect);
142 mySelBtn2->setEnabled(false);
143 myShape2Name = new QLineEdit(myRestrictGroupBox);
144 myShape2Name->setReadOnly(true);
145 myShape2Name->setEnabled(false);
147 aRestrictLayout->setMargin(9);
148 aRestrictLayout->setSpacing(6);
149 aRestrictLayout->addWidget(allSubs, 0, 0, 1, 3);
150 aRestrictLayout->addWidget(inPlaceSubs, 1, 0, 1, 3);
151 aRestrictLayout->addWidget(shape2Subs, 2, 0, 1, 3);
152 aRestrictLayout->addWidget(aSecondLabel, 3, 0);
153 aRestrictLayout->addWidget(mySelBtn2, 3, 1);
154 aRestrictLayout->addWidget(myShape2Name, 3, 2);
155 myRestrictGroup->addButton(allSubs, ALL_SUBSHAPES);
156 myRestrictGroup->addButton(inPlaceSubs, GET_IN_PLACE);
157 myRestrictGroup->addButton(shape2Subs, SUBSHAPES_OF_SHAPE2);
158 myRestrictGroupBox->setEnabled(!CORBA::is_nil(myMainObj));
159 allSubs->setChecked(true);
161 myShowOnlyBtn = new QPushButton(tr("SHOW_ONLY_SELECTED"), GroupMedium);
162 myHideSelBtn = new QPushButton(tr("HIDE_SELECTED"), GroupMedium);
163 myShowAllBtn = new QPushButton(tr("SHOW_ALL_SUB_SHAPES"), GroupMedium);
165 mySelAllBtn = new QPushButton(tr("SELECT_ALL"), GroupMedium);
166 myAddBtn = new QPushButton(tr("ADD"), GroupMedium);
167 myRemBtn = new QPushButton(tr("REMOVE"), GroupMedium);
169 myIdList = new QListWidget(GroupMedium);
171 myIdList->setSelectionMode(QAbstractItemView::ExtendedSelection);
172 myIdList->setFlow(QListView::TopToBottom);
173 myIdList->setWrapping(true);
175 aMedLayout->addWidget(aMainLabel, 0, 0);
176 aMedLayout->addWidget(mySelBtn, 0, 1);
177 aMedLayout->addWidget(myMainName, 0, 2, 1, 2);
178 aMedLayout->addWidget(myRestrictGroupBox, 1, 0, 4, 3);
180 aMedLayout->addWidget(myShowOnlyBtn, 1, 3);
181 aMedLayout->addWidget(myHideSelBtn, 2, 3);
182 aMedLayout->addWidget(myShowAllBtn, 3, 3);
184 aMedLayout->addWidget(myIdList, 5, 0, 4, 3);
185 aMedLayout->addWidget(mySelAllBtn, 5, 3);
186 aMedLayout->addWidget(myAddBtn, 6, 3);
187 aMedLayout->addWidget(myRemBtn, 7, 3);
189 aMedLayout->setColumnStretch(2, 5);
190 aMedLayout->setRowStretch(5, 5);
191 aMedLayout->setRowStretch(8, 5);
195 myFilterGrp = new QGroupBox(tr("GEOM_FILTER"), centralWidget());
196 myLessFilterCheck = new QCheckBox(myFilterGrp);
197 myLessFilterCombo = new QComboBox(myFilterGrp);
198 myLessFilterCombo->addItem( tr("GEOM_LESS_THAN"), Filter_LT );
199 myLessFilterCombo->addItem( tr("GEOM_LESSOREQUAL_THAN"), Filter_LE );
200 myGreaterFilterCheck = new QCheckBox(myFilterGrp);
201 myGreaterFilterCombo = new QComboBox(myFilterGrp);
202 myGreaterFilterCombo->addItem( tr("GEOM_GREAT_THAN"), Filter_GT );
203 myGreaterFilterCombo->addItem( tr("GEOM_GREATOREQUAL_THAN"), Filter_GE );
204 myLessFilterSpin = new SalomeApp_DoubleSpinBox(myFilterGrp);
205 myGreaterFilterSpin = new SalomeApp_DoubleSpinBox(myFilterGrp);
206 myApplyFilterButton = new QPushButton(tr("GEOM_BUT_APPLY"), myFilterGrp);
207 #ifndef DISABLE_PLOT2DVIEWER
208 myPlotDistributionButton = new QPushButton(tr("GEOM_PLOT_DISTRIBUTION"), myFilterGrp);
211 QGridLayout* filterLayout = new QGridLayout(myFilterGrp);
212 filterLayout->addWidget(myLessFilterCheck, 0, 0);
213 filterLayout->addWidget(myLessFilterCombo, 0, 1);
214 filterLayout->addWidget(myLessFilterSpin, 0, 2);
215 filterLayout->addWidget(myGreaterFilterCheck, 1, 0);
216 filterLayout->addWidget(myGreaterFilterCombo, 1, 1);
217 filterLayout->addWidget(myGreaterFilterSpin, 1, 2);
218 filterLayout->addWidget(myApplyFilterButton, 0, 3);
219 #ifndef DISABLE_PLOT2DVIEWER
220 filterLayout->addWidget(myPlotDistributionButton, 1, 3);
223 QVBoxLayout* layout = new QVBoxLayout(centralWidget());
224 layout->setMargin(0); layout->setSpacing(6);
225 layout->addWidget(GroupMedium);
226 layout->addWidget(myFilterGrp);
228 setHelpFileName("work_with_groups_page.html");
234 GroupGUI_GroupDlg::~GroupGUI_GroupDlg()
236 GEOM_Displayer* aDisplayer = getDisplayer();
237 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
238 bool isHideObjects = resMgr->booleanValue( "Geometry", "hide_input_object", true);
239 if (myWasHiddenMain || ( isHideObjects && myIsAccept ) ) {
240 myIsHiddenMain = true;
243 aDisplayer->Display(myMainObj);
244 myIsHiddenMain = false;
246 aDisplayer->Display(myGroup);
250 //=================================================================================
253 //=================================================================================
254 void GroupGUI_GroupDlg::Init()
256 // Get setting of step value from file configuration
257 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
258 double step = resMgr->doubleValue("Geometry", "SettingsGeomStep", 100);
260 // min, max, step and decimals for spin boxes
261 initSpinBox(myLessFilterSpin, 0., COORD_MAX, step, "length_precision" );
262 initSpinBox(myGreaterFilterSpin, 0., COORD_MAX, step, "length_precision" );
263 myLessFilterSpin->setValue( 0. );
264 myGreaterFilterSpin->setValue( 0. );
267 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
269 //unset shape type to avoid preparation of selection before exact user shape type selection
270 unsetConstructorId();
271 myIsShapeType = false;
273 if (myMode == CreateGroup) {
274 initName(tr("GROUP_PREFIX"));
276 // Get ready for main shape selection
277 myEditCurrentArgument = myMainName;
279 connect(this, SIGNAL(constructorsClicked(int)), this, SLOT(ConstructorsClicked(int)));
280 connect(mySelBtn, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
281 connect(mySelBtn2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
283 else if (myMode == EditGroup) {
284 SALOME_ListIO aSelList;
285 aSelMgr->selectedObjects(aSelList);
287 if (aSelList.Extent()) {
288 GEOM::GEOM_Object_var anObj =
289 GEOMBase::ConvertIOinGEOMObject(aSelList.First());
291 if (!CORBA::is_nil(anObj) && anObj->GetType() == GEOM_GROUP) {
294 mainFrame()->ResultName->setText(GEOMBase::GetName(myGroup));
296 GEOM::GEOM_IGroupOperations_var anOper = GEOM::GEOM_IGroupOperations::_narrow(getOperation());
297 myMainObj = anOper->GetMainShape(myGroup);
298 if (!CORBA::is_nil(myMainObj)) {
299 myMainName->setText(GEOMBase::GetName(myMainObj));
300 SALOME_View* view = GEOM_Displayer::GetActiveView();
302 CORBA::String_var aMainEntry = myMainObj->GetStudyEntry();
303 Handle(SALOME_InteractiveObject) io =
304 new SALOME_InteractiveObject (aMainEntry.in(), "GEOM", "TEMP_IO");
305 if (view->isVisible(io)) myWasHiddenMain = false;
309 setShapeType((TopAbs_ShapeEnum)anOper->GetType(myGroup));
311 GEOM::ListOfLong_var aCurrList = anOper->GetObjects(myGroup);
312 for (int i = 0, n = aCurrList->length(); i < n; i++) {
313 QListWidgetItem* itm = new QListWidgetItem( QString( "%1" ).arg( aCurrList[ i ] ) );
314 myGroupIdList.append( aCurrList[ i ] );
315 itm->setTextColor( QColor( GROUP_IDLST_COLOR ) );
316 myIdList->addItem( itm );
318 myEditCurrentArgument = 0;
320 connect(mySelBtn2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
324 connect(aSelMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
326 connect(buttonOk(), SIGNAL(clicked()), this, SLOT(ClickOnOk()));
327 connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
329 connect(myRestrictGroup, SIGNAL(buttonClicked(int)), this, SLOT(SetEditCurrentArgument()));
330 connect(mySelAllBtn, SIGNAL(clicked()), this, SLOT(selectAllSubShapes()));
331 connect(myAddBtn, SIGNAL(clicked()), this, SLOT(add()));
332 connect(myRemBtn, SIGNAL(clicked()), this, SLOT(remove()));
333 connect(myShowOnlyBtn, SIGNAL(clicked()), this, SLOT(showOnlySelected()));
334 connect(myHideSelBtn, SIGNAL(clicked()), this, SLOT(showOnlySelected()));
335 connect(myShowAllBtn, SIGNAL(clicked()), this, SLOT(showOnlySelected()));
336 connect(myIdList, SIGNAL(itemSelectionChanged()), this, SLOT(selectionChanged()));
338 connect(myApplyFilterButton, SIGNAL(clicked()), this, SLOT(ClickOnOkFilter()));
339 #ifndef DISABLE_PLOT2DVIEWER
340 connect(myPlotDistributionButton, SIGNAL(clicked()), this, SLOT(ClickOnPlot()));
342 connect(myLessFilterCheck, SIGNAL(stateChanged(int)), this, SLOT(MeasureToggled()));
343 connect(myGreaterFilterCheck, SIGNAL(stateChanged(int)), this, SLOT(MeasureToggled()));
345 setInPlaceObj(GEOM::GEOM_Object::_nil());
347 myBusy = true; // just activate but do not select in the list
353 //=================================================================================
354 // function : enterEvent()
356 //=================================================================================
357 void GroupGUI_GroupDlg::enterEvent(QEvent* e)
359 if (!buttonCancel()->isEnabled())
360 ActivateThisDialog();
363 //=================================================================================
364 //function : closeEvent
365 //purpose : remove temporary geom object
366 //=================================================================================
367 void GroupGUI_GroupDlg::closeEvent(QCloseEvent* e)
369 setInPlaceObj(GEOM::GEOM_Object::_nil());
372 GEOMBase_Skeleton::closeEvent(e);
375 //=================================================================================
376 // function : ClickOnOk()
378 //=================================================================================
379 void GroupGUI_GroupDlg::ClickOnOk()
381 setIsApplyAndClose(true);
384 setIsApplyAndClose(false);
385 getDisplayer()->UnsetDisplayMode();
388 //=================================================================================
389 // function : ClickOnApply()
391 //=================================================================================
392 bool GroupGUI_GroupDlg::ClickOnApply()
394 if(!isApplyAndClose()) {
395 setIsDisableBrowsing( true );
396 setIsDisplayResult( false );
399 myIsAccept = onAccept(myMode == CreateGroup, true, isApplyAndClose());
403 if(!isApplyAndClose()) {
404 setIsDisableBrowsing( false );
405 setIsDisplayResult( true );
408 if (myMode == CreateGroup)
412 ConstructorsClicked(getConstructorId());
416 int n = myIdList->count();
417 myGroupIdList.clear();
420 for (int i = 0; i < n; i++) {
421 QListWidgetItem* anItem = myIdList->item( i );
422 myGroupIdList.append( anItem->text().toInt() );
423 anItem->setTextColor( GROUP_IDLST_COLOR );
431 //=================================================================================
432 // function : ActivateThisDialog()
434 //=================================================================================
435 void GroupGUI_GroupDlg::ActivateThisDialog()
437 GEOMBase_Skeleton::ActivateThisDialog();
439 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
440 this, SLOT(SelectionIntoArgument()));
445 //=================================================================================
446 // function : SetEditCurrentArgument()
448 //=================================================================================
449 void GroupGUI_GroupDlg::SetEditCurrentArgument()
451 QPushButton* send = qobject_cast<QPushButton*>( sender() );
453 if (send == mySelBtn) {
454 myEditCurrentArgument = myMainName;
455 myShape2Name->setText("");
456 mySelBtn->setDown(true);
457 mySelBtn2->setDown(false);
459 else if (send == mySelBtn2 || sender() == myRestrictGroup) {
460 setInPlaceObj(GEOM::GEOM_Object::_nil());
461 myShape2Name->setText("");
462 if ( send == mySelBtn2 ) {
463 mySelBtn2->setDown(true);
464 mySelBtn->setDown(false);
466 if (subSelectionWay() != ALL_SUBSHAPES) {
467 myEditCurrentArgument = myShape2Name;
470 myEditCurrentArgument = 0;
474 // activateSelection();
475 if(myEditCurrentArgument) {
476 myEditCurrentArgument->setFocus();
484 //=================================================================================
485 // function : onGetInPlace()
487 //=================================================================================
488 void GroupGUI_GroupDlg::onGetInPlace()
490 setInPlaceObj(GEOM::GEOM_Object::_nil());
491 myEditCurrentArgument->setText("");
493 bool isBlocked = myIdList->signalsBlocked();
494 myIdList->blockSignals(true);
495 myIdList->clearSelection();
496 myIdList->blockSignals(isBlocked);
498 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
499 SALOME_ListIO aSelList;
500 aSelMgr->selectedObjects(aSelList);
502 if (aSelList.Extent() != 1)
505 GEOM::GEOM_Object_var anObj =
506 GEOMBase::ConvertIOinGEOMObject(aSelList.First());
507 if (GEOMBase::IsShape(anObj)) {
508 if (!anObj->_is_equivalent(myMainObj) && !anObj->_is_equivalent(myGroup)) {
509 SUIT_OverrideCursor wc;
510 myEditCurrentArgument->setText(GEOMBase::GetName(anObj));
511 GEOM::GEOM_IShapesOperations_var aShapesOp =
512 getGeomEngine()->GetIShapesOperations(getStudyId());
513 if (subSelectionWay() == GET_IN_PLACE) {
514 GEOM::GEOM_Object_var aGetInPlaceObj = aShapesOp->GetInPlace(myMainObj, anObj);
515 setInPlaceObj(aGetInPlaceObj);
518 bool isVisible = true;
519 if (SALOME_View* view = GEOM_Displayer::GetActiveView())
520 isVisible = view->isVisible(aSelList.First());
521 setInPlaceObj(anObj, isVisible);
523 myEditCurrentArgument = 0;
524 //myBusy = true; // just activate but do not select in the list
531 //=================================================================================
532 //function : setInPlaceObj
533 //purpose : temporarily add an object to study and remove old InPlaceObj
534 //=================================================================================
535 void GroupGUI_GroupDlg::setInPlaceObj(GEOM::GEOM_Object_var theObj, const bool isVisible)
537 if (!myInPlaceObj->_is_equivalent(theObj))
539 myInPlaceObj = theObj;
542 // build map of indices
543 myMain2InPlaceIndices.Clear();
544 if (!myInPlaceObj->_is_nil()) {
545 GEOM::GEOM_IShapesOperations_var aShapesOp = getGeomEngine()->GetIShapesOperations(getStudyId());
546 GEOM::GEOM_ILocalOperations_var aLocOp = getGeomEngine()->GetILocalOperations(getStudyId());
548 GEOM::ListOfGO_var aSubObjects = aShapesOp->MakeExplode(myInPlaceObj, getShapeType(), false);
549 for ( int i = 0; i < aSubObjects->length(); i++ )
551 GEOM::ListOfLong_var aCurrList = aShapesOp->GetSameIDs( myMainObj, aSubObjects[i] );
552 if( aCurrList->length() > 1 ) {
553 //rnv : To Fix the 21561: EDF 2184 GEOM: Group with second shape restriction.
554 // In case if GetSameIDs(...) method return more then one ID use
555 // GetSharedShapes(...) method to get sub-shapes of the second shape.
556 GEOM::ListOfGO_var aSubObjects2 = aShapesOp->GetSharedShapes( myMainObj, aSubObjects[i], getShapeType() );
557 for( int j = 0; j < aSubObjects2->length(); j++ ) {
558 CORBA::Long aMainIndex = aLocOp->GetSubShapeIndex( myMainObj, aSubObjects2[j] );
559 CORBA::Long aPlaceIndex = aLocOp->GetSubShapeIndex( myInPlaceObj, aSubObjects[i]);
560 if ( aMainIndex >= 0 && aPlaceIndex > 0 ) {
561 myMain2InPlaceIndices.Bind( aMainIndex, aPlaceIndex );
564 } else if(aCurrList->length() > 0 ) {
565 CORBA::Long aMainIndex = aCurrList[0];
566 CORBA::Long aPlaceIndex = aLocOp->GetSubShapeIndex( myInPlaceObj, aSubObjects[i] );
567 if ( aMainIndex >= 0 && aPlaceIndex > 0) {
568 myMain2InPlaceIndices.Bind( aMainIndex, aPlaceIndex );
573 myInPlaceObjSelectState = subSelectionWay();
574 if (myInPlaceObjSelectState == SUBSHAPES_OF_SHAPE2 && !isVisible)
575 myInPlaceObjSelectState = SUBSHAPES_OF_INVISIBLE_SHAPE2;
578 //=================================================================================
579 // function : SelectionIntoArgument()
580 // purpose : Called when selection has changed
581 //=================================================================================
582 void GroupGUI_GroupDlg::SelectionIntoArgument()
584 if (subSelectionWay() != ALL_SUBSHAPES && myEditCurrentArgument == myShape2Name) {
586 if( !myInPlaceObj->_is_nil() ) {
587 mySelBtn2->setDown(false);
592 if (myEditCurrentArgument == myMainName) { // Selection of a main shape is active
593 myEditCurrentArgument->setText("");
596 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
597 SALOME_ListIO aSelList;
598 aSelMgr->selectedObjects(aSelList);
599 int nbSel = aSelList.Extent();
602 GEOM::GEOM_Object_var anObj =
603 GEOMBase::ConvertIOinGEOMObject(aSelList.First());
605 if (GEOMBase::IsShape(anObj)) {
606 if (myIsHiddenMain) {
607 GEOM_Displayer* aDisplayer = getDisplayer();
608 aDisplayer->Display(myMainObj);
609 myIsHiddenMain = false;
612 if (!CORBA::is_nil(myMainObj)) {
613 mySelBtn->setDown(false);
614 SALOME_View* view = GEOM_Displayer::GetActiveView();
616 CORBA::String_var aMainEntry = myMainObj->GetStudyEntry();
617 Handle(SALOME_InteractiveObject) io =
618 new SALOME_InteractiveObject (aMainEntry.in(), "GEOM", "TEMP_IO");
619 if (view->isVisible(io)) myWasHiddenMain = false;
622 myEditCurrentArgument->setText(GEOMBase::GetName(anObj));
623 // activate sub-shapes selection by default
624 myEditCurrentArgument = 0;
630 if (myIsHiddenMain) {
631 GEOM_Displayer* aDisplayer = getDisplayer();
632 aDisplayer->Display(myMainObj);
633 myIsHiddenMain = false;
635 myMainObj = GEOM::GEOM_Object::_nil();
638 else { // an attempt to synchronize list box selection with 3d viewer
639 if (myBusy || myMainObj->_is_nil()) {
643 bool isBlocked = myIdList->signalsBlocked();
644 myIdList->blockSignals(true);
645 myIdList->clearSelection();
647 TColStd_IndexedMapOfInteger aMapIndex;
648 int nbSel = getSelectedSubshapes(aMapIndex);
652 for (int i = 0, n = myIdList->count(); i < n; i++)
653 aMap.insert(myIdList->item(i)->text().toInt(), i);
655 bool highlight = false;
656 for (int ii = 1, nn = aMapIndex.Extent(); ii <= nn; ii++) {
657 if (aMap.contains(aMapIndex(ii))) {
658 myIdList->item(aMap[aMapIndex(ii)])->setSelected(true);
663 highlightSubShapes();
665 myIdList->blockSignals(isBlocked);
671 //=================================================================================
672 // function : ConstructorsClicked()
673 // purpose : Radio button management
674 //=================================================================================
675 void GroupGUI_GroupDlg::ConstructorsClicked(int constructorId)
677 if (getConstructorId() != constructorId)
678 setConstructorId(constructorId);
680 myIsShapeType = true;
682 myEditCurrentArgument = 0;
684 setInPlaceObj(myInPlaceObj); // to rebuild myMain2InPlaceIndices
689 //=================================================================================
690 // function : selectAllSubShapes
692 //=================================================================================
693 void GroupGUI_GroupDlg::selectAllSubShapes()
695 if (CORBA::is_nil(myMainObj) || !myIsShapeType)
698 GEOM::ListOfLong_var aSubShapes;
699 GEOM::GEOM_IShapesOperations_var aShOp = getGeomEngine()->GetIShapesOperations(getStudyId());
700 aSubShapes = aShOp->SubShapeAllIDs(myMainObj, getShapeType(), false);
701 if (aSubShapes->length() > 0) {
702 if (subSelectionWay() == ALL_SUBSHAPES)
704 // myIdList->clear(); // for sorted final list?
706 if (!aShOp->IsDone())
711 aSubShapes = new GEOM::ListOfLong();
712 aSubShapes->length(myMain2InPlaceIndices.Extent());
713 TColStd_DataMapIteratorOfDataMapOfIntegerInteger m2ip (myMain2InPlaceIndices);
714 for (int i = 0; m2ip.More(); i++, m2ip.Next())
715 aSubShapes[i] = m2ip.Key();
718 bool isBlocked = myIdList->signalsBlocked();
719 myIdList->blockSignals(true);
721 for (int i = 0, n = aSubShapes->length(); i < n; i++) {
722 CORBA::Long anIndex = aSubShapes[i];
726 QListWidgetItem* anItem = 0;
727 QString text = QString("%1").arg(anIndex);
728 // if (!myInPlaceObj->_is_nil()) {
729 QList<QListWidgetItem*> found = myIdList->findItems(text, Qt::MatchExactly);
730 if (found.count()) anItem = found[0];
733 anItem = new QListWidgetItem(text);
734 anItem->setTextColor( myGroupIdList.contains(anIndex) ? QColor( GROUP_IDLST_COLOR ) : QColor( GROUP_NEWIDLST_COLOR ) );
735 myIdList->addItem(anItem);
737 anItem->setSelected(true);
740 myIdList->blockSignals(isBlocked);
741 highlightSubShapes();
745 //=================================================================================
746 // function : showOnlySelected
748 //=================================================================================
749 void GroupGUI_GroupDlg::showOnlySelected()
751 if (CORBA::is_nil(myMainObj) || !myIsShapeType)
754 QPushButton* send = (QPushButton*)sender();
755 if (send == myShowAllBtn) {
760 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
761 SALOME_ListIO aSelList;
762 aSelMgr->selectedObjects(aSelList);
764 GEOM_Displayer* aDisplayer = getDisplayer();
766 if (send == myHideSelBtn) {
767 aDisplayer->Erase(aSelList, /*forced=*/false, /*updateViewer=*/true);
770 // Mantis issue 0021421: do not hide main shape, if explode on VERTEX
771 SALOME_View* view = GEOM_Displayer::GetActiveView();
773 CORBA::String_var aMainEntry = myMainObj->GetStudyEntry();
774 Handle(SALOME_InteractiveObject) io =
775 new SALOME_InteractiveObject (aMainEntry.in(), "GEOM", "TEMP_IO");
776 if (view->isVisible(io)) myIsHiddenMain = true;
778 //keep the selected entry and IO in the map for checking
779 std::map<QString, Handle(SALOME_InteractiveObject)> aSelEntriesMap;
780 SALOME_ListIteratorOfListIO aSelIt(aSelList);
781 for ( ; aSelIt.More(); aSelIt.Next() ) {
782 Handle(SALOME_InteractiveObject) anSelIO = aSelIt.Value();
783 aSelEntriesMap[anSelIO->getEntry()] = anSelIO;
785 //get the displayed sub-shapes
786 SALOME_ListIO displayed;
787 view->GetVisible(displayed);
788 // Erase all, except the selected sub-shapes
789 std::map<QString, Handle(SALOME_InteractiveObject)>::iterator
790 aSelDispIter = aSelEntriesMap.end();
791 SALOME_ListIteratorOfListIO aDispIt( displayed );
792 for ( ; aDispIt.More(); aDispIt.Next() ) {
793 Handle(SALOME_InteractiveObject) anIO = aDispIt.Value();
794 aSelDispIter = aSelEntriesMap.find( anIO->getEntry() );
795 if ( aSelDispIter != aSelEntriesMap.end() ) {
796 //sub-shape is selected, so erase it's record from map to keep in it not displayed, but selected sub-shapes only
797 aSelEntriesMap.erase(aSelDispIter);
799 //sub-shape is not in the map of selected, then erase it from view
800 aDisplayer->Erase( anIO, /*forced = */false, /*updateViewer = */false );
804 if ( !aSelEntriesMap.empty() ) {
805 // Build a presentation of the selected, but not displayed sub-shapes
806 TopoDS_Shape aMainShape = GEOM_Client::get_client().GetShape(GeometryGUI::GetGeomGen(), myMainObj);
807 TopTools_IndexedMapOfShape aSubShapesMap;
808 TopExp::MapShapes(aMainShape, aSubShapesMap);
809 QString anEntryBase = aMainEntry.in();
811 TopExp_Explorer anExp (aMainShape, getShapeType());
812 for (; anExp.More(); anExp.Next()) {
813 TopoDS_Shape aSubShape = anExp.Current();
814 int index = aSubShapesMap.FindIndex(aSubShape);
815 QString anEntry = QString( "TEMP_" ) + anEntryBase + QString("_%1").arg(index);
816 if ( aSelEntriesMap.find( anEntry ) == aSelEntriesMap.end() ) {
817 //skip not selected sub-shapes
820 SALOME_Prs* aPrs = aDisplayer->buildSubshapePresentation(aSubShape, anEntry, view);
822 displayPreview(aPrs, true, false); // append, do not update
826 aDisplayer->UpdateViewer();
829 // Mantis issue 0021421: do not hide main shape, if explode on VERTEX
830 if (getShapeType() == TopAbs_VERTEX && myIsHiddenMain) {
831 aDisplayer->Display(myMainObj);
834 // for the case when selected ids were not displayed in the viewer: Mantis issue 0021367
835 highlightSubShapes();
839 //=================================================================================
840 // function : getSelectedSubshapes
842 //=================================================================================
843 int GroupGUI_GroupDlg::getSelectedSubshapes (TColStd_IndexedMapOfInteger& theMapIndex)
847 SalomeApp_Application* app = myGeomGUI->getApp();
848 if (!app || myMainObj->_is_nil())
851 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
852 SALOME_ListIO aSelList;
853 aSelMgr->selectedObjects(aSelList);
855 // try to find out and process the global selection
856 // (of not published objects and of published sub-shapes)
858 SALOME_ListIteratorOfListIO anIter (aSelList);
859 for (int i = 0; anIter.More(); anIter.Next(), i++)
861 Handle(SALOME_InteractiveObject) anIObj = anIter.Value();
862 QString anEntry = anIObj->getEntry();
864 int index = anEntry.lastIndexOf(str);
865 if (index > 0) // selection among special preview
867 anEntry.remove(0, index+1);
868 int anIndex = anEntry.toInt();
870 theMapIndex.Add(anIndex);
872 else // selection among published shapes
874 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>(app->activeStudy());
875 if (!appStudy) return 0;
876 _PTR(Study) aStudy = appStudy->studyDS();
878 _PTR(SObject) aSObj (aStudy->FindObjectID(anEntry.toLatin1().constData()));
879 GEOM::GEOM_Object_var aGeomObj =
880 GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aSObj));
882 if (GEOMBase::GetShape(aGeomObj, aShape)) {
883 if (aGeomObj->GetType() == GEOM_GROUP || aShape.ShapeType() == getShapeType()) {
884 if (subSelectionWay() != ALL_SUBSHAPES &&
885 GEOMBase::GetName(aGeomObj) == myShape2Name->text()) {
886 // Skip selected in place object.
890 TopTools_IndexedMapOfShape aMainMap;
891 TopoDS_Shape aMainShape = GEOM_Client::get_client().GetShape(GeometryGUI::GetGeomGen(), myMainObj);
892 TopExp::MapShapes(aMainShape, aMainMap);
894 TopExp_Explorer anExp (aShape, getShapeType());
895 bool isShowWarning = true;
896 for (; anExp.More(); anExp.Next()) {
897 TopoDS_Shape aSubShape = anExp.Current();
898 int anIndex = aMainMap.FindIndex(aSubShape);
901 SUIT_MessageBox::warning(app->desktop(), QObject::tr("WRN_WARNING"),
902 tr("WRN_NOT_SUBSHAPE"));
903 isShowWarning = false;
907 if (subSelectionWay() != ALL_SUBSHAPES &&
908 !myMain2InPlaceIndices.IsBound(anIndex))
910 theMapIndex.Add(anIndex);
919 return theMapIndex.Extent();
922 //=================================================================================
925 //=================================================================================
926 void GroupGUI_GroupDlg::add()
928 TColStd_IndexedMapOfInteger aMapIndex;
929 int nbSel = getSelectedSubshapes(aMapIndex);
931 TColStd_MapOfInteger aMap;
932 for (int i = 0, n = myIdList->count(); i < n; i++)
933 aMap.Add(myIdList->item(i)->text().toInt());
936 bool isBlocked = myIdList->signalsBlocked();
937 myIdList->blockSignals(true);
939 for (int i = 1, n = aMapIndex.Extent(); i <= n; i++) {
940 if (aMap.Contains(aMapIndex(i)))
943 QListWidgetItem* anItem = new QListWidgetItem(QString("%1").arg(aMapIndex(i)));
944 anItem->setTextColor( myGroupIdList.contains( aMapIndex( i ) ) ? QColor( GROUP_IDLST_COLOR ) : QColor( GROUP_NEWIDLST_COLOR ) );
945 myIdList->addItem(anItem);
946 anItem->setSelected(true);
949 myIdList->blockSignals(isBlocked);
955 //=================================================================================
958 //=================================================================================
959 void GroupGUI_GroupDlg::remove()
961 bool isBlocked = myIdList->signalsBlocked();
962 myIdList->blockSignals(true);
964 QListIterator<QListWidgetItem*> it (myIdList->selectedItems());
968 myIdList->blockSignals(isBlocked);
970 highlightSubShapes();
973 //=================================================================================
974 //function : subSelectionWay
976 //=================================================================================
977 int GroupGUI_GroupDlg::subSelectionWay() const
979 return myRestrictGroup->checkedId();
982 //=================================================================================
983 // function : getShapeType()
985 //=================================================================================
986 TopAbs_ShapeEnum GroupGUI_GroupDlg::getShapeType() const
988 switch (getConstructorId()) {
989 case 0: return TopAbs_VERTEX;
990 case 1: return TopAbs_EDGE;
991 case 2: return TopAbs_FACE;
992 case 3: return TopAbs_SOLID;
993 default: return TopAbs_SHAPE;
997 //=================================================================================
998 // function : setShapeType()
1000 //=================================================================================
1001 void GroupGUI_GroupDlg::setShapeType(const TopAbs_ShapeEnum theType)
1005 case TopAbs_VERTEX: anId = 0; break;
1006 case TopAbs_EDGE: anId = 1; break;
1007 case TopAbs_FACE: anId = 2; break;
1008 case TopAbs_SOLID: anId = 3; break;
1010 setConstructorId(anId);
1013 myIsShapeType = true;
1014 // workaround to avoid set checked button 0
1015 setConstructorId(anId);
1019 //=================================================================================
1020 // function : activateSelection
1021 // purpose : Activate selection in accordance with myEditCurrentArgument
1022 //=================================================================================
1023 void GroupGUI_GroupDlg::activateSelection()
1025 bool isApply = ((QPushButton*)sender() == buttonApply());
1026 if(!isApplyAndClose())
1027 erasePreview(false);
1030 if (!myMainObj->_is_nil() &&
1031 !myEditCurrentArgument &&
1032 myIsShapeType) // check if shape type is already choosen by user
1034 GEOM_Displayer* aDisplayer = getDisplayer();
1036 //display mode for main shape
1037 if ( myDmMode == -1 ) {
1038 SALOME_View* view = GEOM_Displayer::GetActiveView();
1040 CORBA::String_var aMainEntry = myMainObj->GetStudyEntry();
1041 Handle(SALOME_InteractiveObject) io =
1042 new SALOME_InteractiveObject (aMainEntry.in(), "GEOM", "TEMP_IO");
1043 if ( view->isVisible( io ) ) {
1044 Handle(GEOM_AISShape) aSh = GEOMBase::ConvertIOinGEOMAISShape( io, true );
1046 myDmMode = aSh->isTopLevel() ? aSh->prevDisplayMode() : aSh->DisplayMode();
1050 myDmMode = SUIT_Session::session()->resourceMgr()->integerValue( "Geometry", "display_mode" );
1053 aDisplayer->SetDisplayMode(myDmMode);
1055 // Mantis issue 0021421: do not hide main shape, if explode on VERTEX
1056 if(getShapeType() != TopAbs_VERTEX) {
1057 aDisplayer->Erase(myMainObj, false, false);
1058 myIsHiddenMain = true;
1061 aDisplayer->Display(myMainObj);
1063 aDisplayer->Erase(myGroup, false, false);
1065 QColor aColor = SUIT_Session::session()->resourceMgr()->colorValue( "Geometry", "editgroup_color" );
1066 Quantity_NameOfColor aCol = SalomeApp_Tools::color( aColor ).Name();
1068 if(!isApplyAndClose()) {
1069 SUIT_ViewWindow* aViewWindow = 0;
1070 SUIT_Study* activeStudy = SUIT_Session::session()->activeApplication()->activeStudy();
1072 aViewWindow = SUIT_Session::session()->activeApplication()->desktop()->activeWindow();
1073 if (aViewWindow == 0) return;
1075 SUIT_ViewManager* aViewManager = aViewWindow->getViewManager();
1076 if (aViewManager->getType() != OCCViewer_Viewer::Type() &&
1077 aViewManager->getType() != SVTK_Viewer::Type())
1080 SUIT_ViewModel* aViewModel = aViewManager->getViewModel();
1081 SALOME_View* aView = dynamic_cast<SALOME_View*>(aViewModel);
1082 if (aView == 0) return;
1084 TopoDS_Shape aMainShape = GEOM_Client::get_client().GetShape(GeometryGUI::GetGeomGen(), myMainObj);
1085 TopoDS_Shape aRestrictionShape;
1087 if (subSelectionWay() == ALL_SUBSHAPES) {
1088 aRestrictionShape = aMainShape;
1090 TopTools_IndexedMapOfShape aSubShapesMap;
1091 TopExp::MapShapes(aMainShape, aSubShapesMap);
1092 CORBA::String_var aMainEntry = myMainObj->GetStudyEntry();
1093 QString anEntryBase = aMainEntry.in();
1095 TopExp_Explorer anExp (aRestrictionShape, getShapeType());
1096 for (; anExp.More(); anExp.Next()) {
1097 TopoDS_Shape aSubShape = anExp.Current();
1098 int index = aSubShapesMap.FindIndex(aSubShape);
1099 QString anEntry = QString( "TEMP_" ) + anEntryBase + QString("_%1").arg(index);
1100 Handle(SALOME_InteractiveObject) io =
1101 new SALOME_InteractiveObject(anEntry.toLatin1(), "GEOM", "TEMP_IO");
1102 if ( myGroupIdList.contains( index ) ) {
1103 aDisplayer->SetColor( aCol );
1106 aDisplayer->UnsetColor();
1108 SALOME_Prs* aPrs = aDisplayer->buildSubshapePresentation(aSubShape, anEntry, aView);
1110 displayPreview(aPrs, true, false); // append, do not update
1111 // TODO: map or delete Prs
1115 else if (!myInPlaceObj->_is_nil()) {
1116 TopTools_IndexedMapOfShape aSubShapesMap;
1117 TopExp::MapShapes(aMainShape, aSubShapesMap);
1118 CORBA::String_var aMainEntry = myMainObj->GetStudyEntry();
1119 QString anEntryBase = aMainEntry.in();
1121 TColStd_DataMapIteratorOfDataMapOfIntegerInteger aM2IPit (myMain2InPlaceIndices);
1122 for (; aM2IPit.More(); aM2IPit.Next()) {
1123 int index = aM2IPit.Key();
1124 TopoDS_Shape aSubShape = aSubShapesMap.FindKey(index);
1125 QString anEntry = QString( "TEMP_" ) + anEntryBase + QString("_%1").arg(index);
1127 if ( myGroupIdList.contains( index ) ) {
1128 aDisplayer->SetColor( aCol );
1131 aDisplayer->UnsetColor();
1134 SALOME_Prs* aPrs = aDisplayer->buildSubshapePresentation(aSubShape, anEntry, aView);
1136 displayPreview(aPrs, true, false); // append, do not update
1141 aDisplayer->UnsetDisplayMode();
1142 aDisplayer->UnsetColor();
1143 aDisplayer->UpdateViewer();
1147 globalSelection(GEOM_ALLSHAPES);
1149 SelectionIntoArgument();
1152 //=================================================================================
1153 // function : updateState
1155 //=================================================================================
1156 void GroupGUI_GroupDlg::updateState (bool isAdd)
1158 myAddBtn->setEnabled(!myEditCurrentArgument && !CORBA::is_nil(myMainObj) && isAdd);
1159 //myShowOnlyBtn->setEnabled(!myEditCurrentArgument && !CORBA::is_nil(myMainObj) && isAdd);
1161 bool hasSel = myIdList->selectedItems().count() > 0;
1163 myRemBtn->setEnabled(hasSel);
1164 myRestrictGroupBox->setEnabled(!CORBA::is_nil(myMainObj));
1165 mySelAllBtn->setEnabled(!CORBA::is_nil(myMainObj));
1167 mySelBtn2->setEnabled(subSelectionWay() != ALL_SUBSHAPES);
1168 myShape2Name->setEnabled(subSelectionWay() != ALL_SUBSHAPES);
1169 myFilterGrp->setEnabled(!CORBA::is_nil(myMainObj) &&
1170 subSelectionWay() == ALL_SUBSHAPES &&
1172 getShapeType() != TopAbs_VERTEX);
1173 // manage of 'Plot' button access
1174 GEOM::GEOM_IShapesOperations_var aShOp = getGeomEngine()->GetIShapesOperations( getStudyId() );
1175 GEOM::ListOfLong_var aSubShapes = aShOp->SubShapeAllIDs( myMainObj, getShapeType(), false );
1176 bool hasCurrentEntities = aSubShapes->length() > 0;
1177 #ifndef DISABLE_PLOT2DVIEWER
1178 myPlotDistributionButton->setEnabled( myFilterGrp->isEnabled() &&
1180 ( getShapeType() == TopAbs_EDGE ||
1181 getShapeType() == TopAbs_FACE ||
1182 getShapeType() == TopAbs_SOLID ) &&
1183 hasCurrentEntities );
1185 if (subSelectionWay() == ALL_SUBSHAPES)
1186 setInPlaceObj(GEOM::GEOM_Object::_nil());
1189 //=================================================================================
1190 // function : selectionChanged
1192 //=================================================================================
1193 void GroupGUI_GroupDlg::selectionChanged()
1195 highlightSubShapes();
1198 //=================================================================================
1199 // function : highlightSubShapes
1201 //=================================================================================
1202 void GroupGUI_GroupDlg::highlightSubShapes()
1204 if (CORBA::is_nil(myMainObj))
1207 TColStd_MapOfInteger anIds;
1211 int ii = 0, nn = myIdList->count();
1212 for (; ii < nn; ii++)
1214 if (myIdList->item(ii)->isSelected()) {
1215 int id = myIdList->item(ii)->text().toInt();
1216 if (subSelectionWay() != ALL_SUBSHAPES &&
1217 !myMain2InPlaceIndices.IsBound(id)) {
1218 //myIdList->item(ii)->setSelected(false);
1225 SalomeApp_Application* app = myGeomGUI->getApp();
1226 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
1227 aSelMgr->clearSelected();
1229 SUIT_ViewWindow* aViewWindow = 0;
1230 SUIT_Study* activeStudy = app->activeStudy();
1232 aViewWindow = app->desktop()->activeWindow();
1233 if (aViewWindow == 0) return;
1235 SUIT_ViewManager* aViewManager = aViewWindow->getViewManager();
1236 if (aViewManager->getType() != OCCViewer_Viewer::Type() &&
1237 aViewManager->getType() != SVTK_Viewer::Type())
1240 SUIT_ViewModel* aViewModel = aViewManager->getViewModel();
1241 SALOME_View* aView = dynamic_cast<SALOME_View*>(aViewModel);
1242 if (aView == 0) return;
1244 // TODO??: use here GEOMBase_Helper::myPreview instead of ic->DisplayedObjects()
1246 OCCViewer_Viewer* v3d = ((OCCViewer_ViewManager*)aViewManager)->getOCCViewer();
1247 Handle(AIS_InteractiveContext) ic = v3d->getAISContext();
1248 AIS_ListOfInteractive List;
1249 //ic->DisplayedObjects(List);
1250 ic->ObjectsInside(List); // Mantis issue 0021367
1252 SALOME_ListIO aSelList;
1254 // To highlight the selected sub-shape in Object Browser, if it's already published under the main shape
1255 GEOM::GEOM_ILocalOperations_var aLocOp = getGeomEngine()->GetILocalOperations(getStudyId());
1256 QMap<int, QString> childsMap;
1257 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>(app->activeStudy());
1259 _PTR(Study) aStudy = appStudy->studyDS();
1260 CORBA::String_var aMainEntry = myMainObj->GetStudyEntry();
1261 QString anEntry = aMainEntry.in();
1262 _PTR(SObject) aSObj (aStudy->FindObjectID(anEntry.toLatin1().constData()));
1263 _PTR(ChildIterator) anIt (aStudy->NewChildIterator(aSObj));
1264 for (anIt->InitEx(true); anIt->More(); anIt->Next()) {
1265 GEOM::GEOM_Object_var aChild = GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(anIt->Value()));
1266 if (!CORBA::is_nil(aChild)) {
1267 int index = aLocOp->GetSubShapeIndex(myMainObj, aChild);
1268 CORBA::String_var aChildEntry = aChild->GetStudyEntry();
1269 QString anEntry = aChildEntry.in();
1270 childsMap.insert(index, anEntry);
1275 AIS_ListIteratorOfListOfInteractive ite (List);
1276 for (; ite.More(); ite.Next()) {
1277 if (ite.Value()->IsInstance(STANDARD_TYPE(GEOM_AISShape))) {
1278 Handle(GEOM_AISShape) aSh = Handle(GEOM_AISShape)::DownCast(ite.Value());
1280 Handle(SALOME_InteractiveObject) anIO = aSh->getIO();
1281 QString anEntry = anIO->getEntry();
1282 int index = anEntry.lastIndexOf("_");
1283 anEntry.remove(0, index+1);
1284 int anIndex = anEntry.toInt();
1285 if (anIds.Contains(anIndex)) {
1286 aSelList.Append(anIO);
1287 if (childsMap.contains (anIndex)) {
1288 Handle(SALOME_InteractiveObject) tmpIO = new SALOME_InteractiveObject(childsMap.value(anIndex).toLatin1().constData(), "GEOM", "TEMP_IO");
1289 aSelList.Append(tmpIO);
1295 aSelMgr->setSelectedObjects(aSelList);
1300 updateState(aSelList.Extent() > 0);
1302 myAddBtn->setEnabled(true);
1303 myAddBtn->setEnabled(true);
1304 myRemBtn->setEnabled(true);
1308 //=================================================================================
1309 // function : createOperation
1311 //=================================================================================
1312 GEOM::GEOM_IOperations_ptr GroupGUI_GroupDlg::createOperation()
1314 return getGeomEngine()->GetIGroupOperations(getStudyId());
1317 #define RETURN_WITH_MSG(a, b) \
1319 theMessage += (b); \
1323 //=================================================================================
1324 // function : isValid()
1325 // purpose : Verify validity of input data
1326 //=================================================================================
1327 bool GroupGUI_GroupDlg::isValid(QString& theMessage)
1329 SalomeApp_Study* study = getStudy();
1331 RETURN_WITH_MSG (!study->studyDS()->GetProperties()->IsLocked(), tr("GEOM_STUDY_LOCKED"))
1333 if (myMode == CreateGroup) {
1334 RETURN_WITH_MSG(!CORBA::is_nil(myMainObj), tr("NO_MAIN_OBJ"))
1337 RETURN_WITH_MSG(!CORBA::is_nil(myMainObj), tr("NO_GROUP"))
1340 QString aName (getNewObjectName());
1341 RETURN_WITH_MSG (!aName.trimmed().isEmpty(), tr("EMPTY_NAME"))
1343 RETURN_WITH_MSG (myIdList->count(), tr("EMPTY_LIST"))
1347 //=================================================================================
1348 // function : execute
1350 //=================================================================================
1351 bool GroupGUI_GroupDlg::execute(ObjectList& objects)
1353 GEOM::GEOM_IGroupOperations_var anOper = GEOM::GEOM_IGroupOperations::_narrow(getOperation());
1355 GEOM::GEOM_Object_var aGroup;
1356 if (myMode == CreateGroup)
1357 aGroup = anOper->CreateGroup(myMainObj, getShapeType());
1358 else if (myMode == EditGroup)
1361 if (CORBA::is_nil(aGroup) || (myMode == CreateGroup && !anOper->IsDone()))
1364 GEOM::ListOfLong_var aCurrList = anOper->GetObjects(aGroup);
1365 if (!anOper->IsDone())
1368 if (aCurrList->length() > 0)
1370 anOper->DifferenceIDs(aGroup, aCurrList);
1371 if (!anOper->IsDone())
1375 int ii, nn = myIdList->count();
1378 GEOM::ListOfLong_var aNewList = new GEOM::ListOfLong;
1379 aNewList->length(nn);
1380 for (ii = 0; ii < nn; ii++) {
1381 aNewList[ii] = myIdList->item(ii)->text().toInt();
1383 anOper->UnionIDs(aGroup, aNewList);
1384 if (!anOper->IsDone())
1388 SalomeApp_Study* study = getStudy();
1390 QString objIOR = GEOMBase::GetIORFromObject(aGroup);
1392 _PTR(SObject) SO (study->studyDS()->FindObjectIOR(objIOR.toLatin1().constData()));
1394 _PTR(StudyBuilder) aBuilder (study->studyDS()->NewBuilder());
1395 aBuilder->SetName(SO, getNewObjectName().toLatin1().constData());
1400 objects.push_back(aGroup._retn());
1405 //================================================================
1406 // Function : getFather
1407 // Purpose : Get father object for object to be added in study
1408 // (called with addInStudy method)
1409 //================================================================
1410 GEOM::GEOM_Object_ptr GroupGUI_GroupDlg::getFather(GEOM::GEOM_Object_ptr theObj)
1412 GEOM::GEOM_Object_var aFatherObj;
1413 if (theObj->GetType() == GEOM_GROUP) {
1414 GEOM::GEOM_IGroupOperations_var anOper = GEOM::GEOM_IGroupOperations::_narrow(getOperation());
1415 aFatherObj = anOper->GetMainShape(theObj);
1417 return aFatherObj._retn();
1420 void GroupGUI_GroupDlg::ClickOnOkFilter()
1422 if (CORBA::is_nil(myMainObj) || subSelectionWay() != ALL_SUBSHAPES || !myIsShapeType || getShapeType() == TopAbs_VERTEX)
1425 TopoDS_Shape aMainShape = GEOM_Client::get_client().GetShape(GeometryGUI::GetGeomGen(), myMainObj);
1426 TopTools_IndexedMapOfShape aSubShapesMap;
1427 TopExp::MapShapes(aMainShape, aSubShapesMap);
1428 SALOME_View* view = GEOM_Displayer::GetActiveView();
1429 getDisplayer()->Erase(myMainObj, false, false);
1430 CORBA::String_var aMainEntry = myMainObj->GetStudyEntry();
1431 QString anEntryBase = aMainEntry.in();
1433 SALOME_ListIO toSelect;
1435 TopExp_Explorer anExp (aMainShape, (TopAbs_ShapeEnum)getShapeType());
1436 for (; anExp.More(); anExp.Next())
1438 TopoDS_Shape aSubShape = anExp.Current();
1439 int index = aSubShapesMap.FindIndex(aSubShape);
1440 QString anEntry = QString( "TEMP_" ) + anEntryBase + QString("_%1").arg(index);
1441 if ( !getDisplayer()->IsDisplayed( anEntry ) )
1444 double factor = GEOMUtils::ShapeToDouble(aSubShape).second;
1445 double v1 = myLessFilterSpin->value();
1446 double v2 = myGreaterFilterSpin->value();
1447 bool isLess = myLessFilterCombo->itemData(myLessFilterCombo->currentIndex()).toInt() == Filter_LT ? factor < v1 : factor <= v1;
1448 bool isGreater = myGreaterFilterCombo->itemData(myGreaterFilterCombo->currentIndex()).toInt() == Filter_GT ? factor > v2 : factor >= v2;
1449 if ( ( myLessFilterCheck->isChecked() && myGreaterFilterCheck->isChecked() && isLess && isGreater ) ||
1450 ( myLessFilterCheck->isChecked() && !myGreaterFilterCheck->isChecked() && isLess ) ||
1451 ( myGreaterFilterCheck->isChecked() && !myLessFilterCheck->isChecked() && isGreater ) ) {
1452 Handle(SALOME_InteractiveObject) io = new SALOME_InteractiveObject();
1453 io->setEntry( anEntry.toLatin1().constData() );
1454 toSelect.Append(io);
1457 if ( toSelect.Extent() > 0 ) {
1458 myGeomGUI->getApp()->selectionMgr()->setSelectedObjects(toSelect);
1459 SUIT_MessageBox::information( this,
1461 tr( "GEOM_SOME_SHAPES_SELECTED").arg( toSelect.Extent() ),
1465 SUIT_MessageBox::information( this,
1467 tr( "GEOM_NO_SHAPES_SELECTED" ),
1473 #ifndef DISABLE_PLOT2DVIEWER
1474 //=================================================================================
1475 // function : ClickOnPlot()
1476 // purpose : opens "Shape Statistics" dialog box in order to plot sub-shapes distribution.
1477 //=================================================================================
1478 void GroupGUI_GroupDlg::ClickOnPlot()
1480 TopoDS_Shape aMainShape = GEOM_Client::get_client().GetShape(GeometryGUI::GetGeomGen(), myMainObj);
1481 QDialog* dlg = new MeasureGUI_ShapeStatisticsDlg( this, aMainShape, getShapeType() );
1488 void GroupGUI_GroupDlg::MeasureToggled()
1490 myLessFilterSpin->setEnabled(myLessFilterCheck->isChecked());
1491 myLessFilterCombo->setEnabled(myLessFilterCheck->isChecked());
1492 myGreaterFilterSpin->setEnabled(myGreaterFilterCheck->isChecked());
1493 myGreaterFilterCombo->setEnabled(myGreaterFilterCheck->isChecked());
1494 myApplyFilterButton->setEnabled(myLessFilterCheck->isChecked() || myGreaterFilterCheck->isChecked());
1497 //=================================================================================
1498 // function : getSourceObjects
1499 // purpose : virtual method to get source objects
1500 //=================================================================================
1501 QList<GEOM::GeomObjPtr> GroupGUI_GroupDlg::getSourceObjects()
1503 QList<GEOM::GeomObjPtr> res;
1504 GEOM::GeomObjPtr aGeomObjPtr1(myMainObj), aGeomObjPtr2(myInPlaceObj);
1505 res << aGeomObjPtr1 << aGeomObjPtr2;