1 // Copyright (C) 2007-2020 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();
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();
546 GEOM::GEOM_ILocalOperations_var aLocOp = getGeomEngine()->GetILocalOperations();
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();
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.toUtf8().constData()));
879 if ( ! GeometryGUI::IsInGeomComponent( aSObj )) continue;
880 GEOM::GEOM_Object_var aGeomObj =
881 GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aSObj));
883 if (GEOMBase::GetShape(aGeomObj, aShape)) {
884 if (aGeomObj->GetType() == GEOM_GROUP || aShape.ShapeType() == getShapeType()) {
885 if (subSelectionWay() != ALL_SUBSHAPES &&
886 GEOMBase::GetName(aGeomObj) == myShape2Name->text()) {
887 // Skip selected in place object.
891 TopTools_IndexedMapOfShape aMainMap;
892 TopoDS_Shape aMainShape = GEOM_Client::get_client().GetShape(GeometryGUI::GetGeomGen(), myMainObj);
893 TopExp::MapShapes(aMainShape, aMainMap);
895 TopExp_Explorer anExp (aShape, getShapeType());
896 bool isShowWarning = true;
897 for (; anExp.More(); anExp.Next()) {
898 TopoDS_Shape aSubShape = anExp.Current();
899 int anIndex = aMainMap.FindIndex(aSubShape);
902 SUIT_MessageBox::warning(app->desktop(), QObject::tr("WRN_WARNING"),
903 tr("WRN_NOT_SUBSHAPE"));
904 isShowWarning = false;
908 if (subSelectionWay() != ALL_SUBSHAPES &&
909 !myMain2InPlaceIndices.IsBound(anIndex))
911 theMapIndex.Add(anIndex);
920 return theMapIndex.Extent();
923 //=================================================================================
926 //=================================================================================
927 void GroupGUI_GroupDlg::add()
929 TColStd_IndexedMapOfInteger aMapIndex;
930 int nbSel = getSelectedSubshapes(aMapIndex);
932 TColStd_MapOfInteger aMap;
933 for (int i = 0, n = myIdList->count(); i < n; i++)
934 aMap.Add(myIdList->item(i)->text().toInt());
937 bool isBlocked = myIdList->signalsBlocked();
938 myIdList->blockSignals(true);
940 for (int i = 1, n = aMapIndex.Extent(); i <= n; i++) {
941 if (aMap.Contains(aMapIndex(i)))
944 QListWidgetItem* anItem = new QListWidgetItem(QString("%1").arg(aMapIndex(i)));
945 anItem->setTextColor( myGroupIdList.contains( aMapIndex( i ) ) ? QColor( GROUP_IDLST_COLOR ) : QColor( GROUP_NEWIDLST_COLOR ) );
946 myIdList->addItem(anItem);
947 anItem->setSelected(true);
950 myIdList->blockSignals(isBlocked);
956 //=================================================================================
959 //=================================================================================
960 void GroupGUI_GroupDlg::remove()
962 bool isBlocked = myIdList->signalsBlocked();
963 myIdList->blockSignals(true);
965 QListIterator<QListWidgetItem*> it (myIdList->selectedItems());
969 myIdList->blockSignals(isBlocked);
971 highlightSubShapes();
974 //=================================================================================
975 //function : subSelectionWay
977 //=================================================================================
978 int GroupGUI_GroupDlg::subSelectionWay() const
980 return myRestrictGroup->checkedId();
983 //=================================================================================
984 // function : getShapeType()
986 //=================================================================================
987 TopAbs_ShapeEnum GroupGUI_GroupDlg::getShapeType() const
989 switch (getConstructorId()) {
990 case 0: return TopAbs_VERTEX;
991 case 1: return TopAbs_EDGE;
992 case 2: return TopAbs_FACE;
993 case 3: return TopAbs_SOLID;
994 default: return TopAbs_SHAPE;
998 //=================================================================================
999 // function : setShapeType()
1001 //=================================================================================
1002 void GroupGUI_GroupDlg::setShapeType(const TopAbs_ShapeEnum theType)
1006 case TopAbs_VERTEX: anId = 0; break;
1007 case TopAbs_EDGE: anId = 1; break;
1008 case TopAbs_FACE: anId = 2; break;
1009 case TopAbs_SOLID: anId = 3; break;
1011 setConstructorId(anId);
1014 myIsShapeType = true;
1015 // workaround to avoid set checked button 0
1016 setConstructorId(anId);
1020 //=================================================================================
1021 // function : activateSelection
1022 // purpose : Activate selection in accordance with myEditCurrentArgument
1023 //=================================================================================
1024 void GroupGUI_GroupDlg::activateSelection()
1026 bool isApply = ((QPushButton*)sender() == buttonApply());
1027 if(!isApplyAndClose())
1028 erasePreview(false);
1031 if (!myMainObj->_is_nil() &&
1032 !myEditCurrentArgument &&
1033 myIsShapeType) // check if shape type is already chosen by user
1035 GEOM_Displayer* aDisplayer = getDisplayer();
1037 //display mode for main shape
1038 if ( myDmMode == -1 ) {
1039 SALOME_View* view = GEOM_Displayer::GetActiveView();
1041 CORBA::String_var aMainEntry = myMainObj->GetStudyEntry();
1042 Handle(SALOME_InteractiveObject) io =
1043 new SALOME_InteractiveObject (aMainEntry.in(), "GEOM", "TEMP_IO");
1044 if ( view->isVisible( io ) ) {
1045 Handle(GEOM_AISShape) aSh = GEOMBase::ConvertIOinGEOMAISShape( io, true );
1047 myDmMode = aSh->isTopLevel() ? aSh->prevDisplayMode() : aSh->DisplayMode();
1051 myDmMode = SUIT_Session::session()->resourceMgr()->integerValue( "Geometry", "display_mode" );
1054 aDisplayer->SetDisplayMode(myDmMode);
1056 // Mantis issue 0021421: do not hide main shape, if explode on VERTEX
1057 if(getShapeType() != TopAbs_VERTEX) {
1058 aDisplayer->Erase(myMainObj, false, false);
1059 myIsHiddenMain = true;
1062 aDisplayer->Display(myMainObj);
1064 aDisplayer->Erase(myGroup, false, false);
1066 QColor aColor = SUIT_Session::session()->resourceMgr()->colorValue( "Geometry", "editgroup_color" );
1067 Quantity_NameOfColor aCol = SalomeApp_Tools::color( aColor ).Name();
1069 if(!isApplyAndClose()) {
1070 SUIT_ViewWindow* aViewWindow = 0;
1071 SUIT_Study* activeStudy = SUIT_Session::session()->activeApplication()->activeStudy();
1073 aViewWindow = SUIT_Session::session()->activeApplication()->desktop()->activeWindow();
1074 if (aViewWindow == 0) return;
1076 SUIT_ViewManager* aViewManager = aViewWindow->getViewManager();
1077 if (aViewManager->getType() != OCCViewer_Viewer::Type() &&
1078 aViewManager->getType() != SVTK_Viewer::Type())
1081 SUIT_ViewModel* aViewModel = aViewManager->getViewModel();
1082 SALOME_View* aView = dynamic_cast<SALOME_View*>(aViewModel);
1083 if (aView == 0) return;
1085 TopoDS_Shape aMainShape = GEOM_Client::get_client().GetShape(GeometryGUI::GetGeomGen(), myMainObj);
1086 TopoDS_Shape aRestrictionShape;
1088 if (subSelectionWay() == ALL_SUBSHAPES) {
1089 aRestrictionShape = aMainShape;
1091 TopTools_IndexedMapOfShape aSubShapesMap;
1092 TopExp::MapShapes(aMainShape, aSubShapesMap);
1093 CORBA::String_var aMainEntry = myMainObj->GetStudyEntry();
1094 QString anEntryBase = aMainEntry.in();
1096 TopExp_Explorer anExp (aRestrictionShape, getShapeType());
1097 for (; anExp.More(); anExp.Next()) {
1098 TopoDS_Shape aSubShape = anExp.Current();
1099 int index = aSubShapesMap.FindIndex(aSubShape);
1100 QString anEntry = QString( "TEMP_" ) + anEntryBase + QString("_%1").arg(index);
1101 Handle(SALOME_InteractiveObject) io =
1102 new SALOME_InteractiveObject(anEntry.toUtf8(), "GEOM", "TEMP_IO");
1103 if ( myGroupIdList.contains( index ) ) {
1104 aDisplayer->SetColor( aCol );
1107 aDisplayer->UnsetColor();
1109 SALOME_Prs* aPrs = aDisplayer->buildSubshapePresentation(aSubShape, anEntry, aView);
1111 displayPreview(aPrs, true, false); // append, do not update
1112 // TODO: map or delete Prs
1116 else if (!myInPlaceObj->_is_nil()) {
1117 TopTools_IndexedMapOfShape aSubShapesMap;
1118 TopExp::MapShapes(aMainShape, aSubShapesMap);
1119 CORBA::String_var aMainEntry = myMainObj->GetStudyEntry();
1120 QString anEntryBase = aMainEntry.in();
1122 TColStd_DataMapIteratorOfDataMapOfIntegerInteger aM2IPit (myMain2InPlaceIndices);
1123 for (; aM2IPit.More(); aM2IPit.Next()) {
1124 int index = aM2IPit.Key();
1125 TopoDS_Shape aSubShape = aSubShapesMap.FindKey(index);
1126 QString anEntry = QString( "TEMP_" ) + anEntryBase + QString("_%1").arg(index);
1128 if ( myGroupIdList.contains( index ) ) {
1129 aDisplayer->SetColor( aCol );
1132 aDisplayer->UnsetColor();
1135 SALOME_Prs* aPrs = aDisplayer->buildSubshapePresentation(aSubShape, anEntry, aView);
1137 displayPreview(aPrs, true, false); // append, do not update
1142 aDisplayer->UnsetDisplayMode();
1143 aDisplayer->UnsetColor();
1144 aDisplayer->UpdateViewer();
1148 globalSelection(GEOM_ALLSHAPES);
1150 SelectionIntoArgument();
1153 //=================================================================================
1154 // function : updateState
1156 //=================================================================================
1157 void GroupGUI_GroupDlg::updateState (bool isAdd)
1159 myAddBtn->setEnabled(!myEditCurrentArgument && !CORBA::is_nil(myMainObj) && isAdd);
1160 //myShowOnlyBtn->setEnabled(!myEditCurrentArgument && !CORBA::is_nil(myMainObj) && isAdd);
1162 bool hasSel = myIdList->selectedItems().count() > 0;
1164 myRemBtn->setEnabled(hasSel);
1165 myRestrictGroupBox->setEnabled(!CORBA::is_nil(myMainObj));
1166 mySelAllBtn->setEnabled(!CORBA::is_nil(myMainObj));
1168 mySelBtn2->setEnabled(subSelectionWay() != ALL_SUBSHAPES);
1169 myShape2Name->setEnabled(subSelectionWay() != ALL_SUBSHAPES);
1170 myFilterGrp->setEnabled(!CORBA::is_nil(myMainObj) &&
1171 subSelectionWay() == ALL_SUBSHAPES &&
1173 getShapeType() != TopAbs_VERTEX);
1174 // manage of 'Plot' button access
1175 GEOM::GEOM_IShapesOperations_var aShOp = getGeomEngine()->GetIShapesOperations();
1176 GEOM::ListOfLong_var aSubShapes = aShOp->SubShapeAllIDs( myMainObj, getShapeType(), false );
1177 bool hasCurrentEntities = aSubShapes->length() > 0;
1178 #ifndef DISABLE_PLOT2DVIEWER
1179 myPlotDistributionButton->setEnabled( myFilterGrp->isEnabled() &&
1181 ( getShapeType() == TopAbs_EDGE ||
1182 getShapeType() == TopAbs_FACE ||
1183 getShapeType() == TopAbs_SOLID ) &&
1184 hasCurrentEntities );
1186 if (subSelectionWay() == ALL_SUBSHAPES)
1187 setInPlaceObj(GEOM::GEOM_Object::_nil());
1190 //=================================================================================
1191 // function : selectionChanged
1193 //=================================================================================
1194 void GroupGUI_GroupDlg::selectionChanged()
1196 highlightSubShapes();
1199 //=================================================================================
1200 // function : highlightSubShapes
1202 //=================================================================================
1203 void GroupGUI_GroupDlg::highlightSubShapes()
1205 if (CORBA::is_nil(myMainObj))
1208 TColStd_MapOfInteger anIds;
1212 int ii = 0, nn = myIdList->count();
1213 for (; ii < nn; ii++)
1215 if (myIdList->item(ii)->isSelected()) {
1216 int id = myIdList->item(ii)->text().toInt();
1217 if (subSelectionWay() != ALL_SUBSHAPES &&
1218 !myMain2InPlaceIndices.IsBound(id)) {
1219 //myIdList->item(ii)->setSelected(false);
1226 SalomeApp_Application* app = myGeomGUI->getApp();
1227 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
1228 aSelMgr->clearSelected();
1230 SUIT_ViewWindow* aViewWindow = 0;
1231 SUIT_Study* activeStudy = app->activeStudy();
1233 aViewWindow = app->desktop()->activeWindow();
1234 if (aViewWindow == 0) return;
1236 SUIT_ViewManager* aViewManager = aViewWindow->getViewManager();
1237 if (aViewManager->getType() != OCCViewer_Viewer::Type() &&
1238 aViewManager->getType() != SVTK_Viewer::Type())
1241 SUIT_ViewModel* aViewModel = aViewManager->getViewModel();
1242 SALOME_View* aView = dynamic_cast<SALOME_View*>(aViewModel);
1243 if (aView == 0) return;
1245 // TODO??: use here GEOMBase_Helper::myPreview instead of ic->DisplayedObjects()
1247 OCCViewer_Viewer* v3d = ((OCCViewer_ViewManager*)aViewManager)->getOCCViewer();
1248 Handle(AIS_InteractiveContext) ic = v3d->getAISContext();
1249 AIS_ListOfInteractive List;
1250 //ic->DisplayedObjects(List);
1251 ic->ObjectsInside(List); // Mantis issue 0021367
1253 SALOME_ListIO aSelList;
1255 // To highlight the selected sub-shape in Object Browser, if it's already published under the main shape
1256 GEOM::GEOM_ILocalOperations_var aLocOp = getGeomEngine()->GetILocalOperations();
1257 QMap<int, QString> childsMap;
1258 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>(app->activeStudy());
1260 _PTR(Study) aStudy = appStudy->studyDS();
1261 CORBA::String_var aMainEntry = myMainObj->GetStudyEntry();
1262 QString anEntry = aMainEntry.in();
1263 _PTR(SObject) aSObj (aStudy->FindObjectID(anEntry.toUtf8().constData()));
1264 _PTR(ChildIterator) anIt (aStudy->NewChildIterator(aSObj));
1265 for (anIt->InitEx(true); anIt->More(); anIt->Next()) {
1266 GEOM::GEOM_Object_var aChild = GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(anIt->Value()));
1267 if (!CORBA::is_nil(aChild)) {
1268 int index = aLocOp->GetSubShapeIndex(myMainObj, aChild);
1269 CORBA::String_var aChildEntry = aChild->GetStudyEntry();
1270 QString anEntry = aChildEntry.in();
1271 childsMap.insert(index, anEntry);
1276 AIS_ListIteratorOfListOfInteractive ite (List);
1277 for (; ite.More(); ite.Next()) {
1278 if (ite.Value()->IsInstance(STANDARD_TYPE(GEOM_AISShape))) {
1279 Handle(GEOM_AISShape) aSh = Handle(GEOM_AISShape)::DownCast(ite.Value());
1281 Handle(SALOME_InteractiveObject) anIO = aSh->getIO();
1282 QString anEntry = anIO->getEntry();
1283 int index = anEntry.lastIndexOf("_");
1284 anEntry.remove(0, index+1);
1285 int anIndex = anEntry.toInt();
1286 if (anIds.Contains(anIndex)) {
1287 aSelList.Append(anIO);
1288 if (childsMap.contains (anIndex)) {
1289 Handle(SALOME_InteractiveObject) tmpIO = new SALOME_InteractiveObject(childsMap.value(anIndex).toUtf8().constData(), "GEOM", "TEMP_IO");
1290 aSelList.Append(tmpIO);
1296 aSelMgr->setSelectedObjects(aSelList);
1301 updateState(aSelList.Extent() > 0);
1303 myAddBtn->setEnabled(true);
1304 myAddBtn->setEnabled(true);
1305 myRemBtn->setEnabled(true);
1309 //=================================================================================
1310 // function : createOperation
1312 //=================================================================================
1313 GEOM::GEOM_IOperations_ptr GroupGUI_GroupDlg::createOperation()
1315 return getGeomEngine()->GetIGroupOperations();
1318 #define RETURN_WITH_MSG(a, b) \
1320 theMessage += (b); \
1324 //=================================================================================
1325 // function : isValid()
1326 // purpose : Verify validity of input data
1327 //=================================================================================
1328 bool GroupGUI_GroupDlg::isValid(QString& theMessage)
1330 SalomeApp_Study* study = getStudy();
1332 RETURN_WITH_MSG (!study->studyDS()->GetProperties()->IsLocked(), tr("GEOM_STUDY_LOCKED"))
1334 if (myMode == CreateGroup) {
1335 RETURN_WITH_MSG(!CORBA::is_nil(myMainObj), tr("NO_MAIN_OBJ"))
1338 RETURN_WITH_MSG(!CORBA::is_nil(myMainObj), tr("NO_GROUP"))
1341 QString aName (getNewObjectName());
1342 RETURN_WITH_MSG (!aName.trimmed().isEmpty(), tr("EMPTY_NAME"))
1344 RETURN_WITH_MSG (myIdList->count(), tr("EMPTY_LIST"))
1348 //=================================================================================
1349 // function : execute
1351 //=================================================================================
1352 bool GroupGUI_GroupDlg::execute(ObjectList& objects)
1354 GEOM::GEOM_IGroupOperations_var anOper = GEOM::GEOM_IGroupOperations::_narrow(getOperation());
1356 GEOM::GEOM_Object_var aGroup;
1357 if (myMode == CreateGroup)
1358 aGroup = anOper->CreateGroup(myMainObj, getShapeType());
1359 else if (myMode == EditGroup)
1362 if (CORBA::is_nil(aGroup) || (myMode == CreateGroup && !anOper->IsDone()))
1365 GEOM::ListOfLong_var aCurrList = anOper->GetObjects(aGroup);
1366 if (!anOper->IsDone())
1369 if (aCurrList->length() > 0)
1371 anOper->DifferenceIDs(aGroup, aCurrList);
1372 if (!anOper->IsDone())
1376 int ii, nn = myIdList->count();
1379 GEOM::ListOfLong_var aNewList = new GEOM::ListOfLong;
1380 aNewList->length(nn);
1381 for (ii = 0; ii < nn; ii++) {
1382 aNewList[ii] = myIdList->item(ii)->text().toInt();
1384 anOper->UnionIDs(aGroup, aNewList);
1385 if (!anOper->IsDone())
1389 SalomeApp_Study* study = getStudy();
1391 QString objIOR = GEOMBase::GetIORFromObject(aGroup);
1393 _PTR(SObject) SO (study->studyDS()->FindObjectIOR(objIOR.toLatin1().constData()));
1395 _PTR(StudyBuilder) aBuilder (study->studyDS()->NewBuilder());
1396 aBuilder->SetName(SO, getNewObjectName().toUtf8().constData());
1401 objects.push_back(aGroup._retn());
1406 //================================================================
1407 // Function : getFather
1408 // Purpose : Get father object for object to be added in study
1409 // (called with addInStudy method)
1410 //================================================================
1411 GEOM::GEOM_Object_ptr GroupGUI_GroupDlg::getFather(GEOM::GEOM_Object_ptr theObj)
1413 GEOM::GEOM_Object_var aFatherObj;
1414 if (theObj->GetType() == GEOM_GROUP) {
1415 GEOM::GEOM_IGroupOperations_var anOper = GEOM::GEOM_IGroupOperations::_narrow(getOperation());
1416 aFatherObj = anOper->GetMainShape(theObj);
1418 return aFatherObj._retn();
1421 void GroupGUI_GroupDlg::ClickOnOkFilter()
1423 if (CORBA::is_nil(myMainObj) || subSelectionWay() != ALL_SUBSHAPES || !myIsShapeType || getShapeType() == TopAbs_VERTEX)
1426 TopoDS_Shape aMainShape = GEOM_Client::get_client().GetShape(GeometryGUI::GetGeomGen(), myMainObj);
1427 TopTools_IndexedMapOfShape aSubShapesMap;
1428 TopExp::MapShapes(aMainShape, aSubShapesMap);
1429 SALOME_View* view = GEOM_Displayer::GetActiveView();
1430 getDisplayer()->Erase(myMainObj, false, false);
1431 CORBA::String_var aMainEntry = myMainObj->GetStudyEntry();
1432 QString anEntryBase = aMainEntry.in();
1434 SALOME_ListIO toSelect;
1436 TopExp_Explorer anExp (aMainShape, (TopAbs_ShapeEnum)getShapeType());
1437 for (; anExp.More(); anExp.Next())
1439 TopoDS_Shape aSubShape = anExp.Current();
1440 int index = aSubShapesMap.FindIndex(aSubShape);
1441 QString anEntry = QString( "TEMP_" ) + anEntryBase + QString("_%1").arg(index);
1442 if ( !getDisplayer()->IsDisplayed( anEntry ) )
1445 double factor = GEOMUtils::ShapeToDouble(aSubShape).second;
1446 double v1 = myLessFilterSpin->value();
1447 double v2 = myGreaterFilterSpin->value();
1448 bool isLess = myLessFilterCombo->itemData(myLessFilterCombo->currentIndex()).toInt() == Filter_LT ? factor < v1 : factor <= v1;
1449 bool isGreater = myGreaterFilterCombo->itemData(myGreaterFilterCombo->currentIndex()).toInt() == Filter_GT ? factor > v2 : factor >= v2;
1450 if ( ( myLessFilterCheck->isChecked() && myGreaterFilterCheck->isChecked() && isLess && isGreater ) ||
1451 ( myLessFilterCheck->isChecked() && !myGreaterFilterCheck->isChecked() && isLess ) ||
1452 ( myGreaterFilterCheck->isChecked() && !myLessFilterCheck->isChecked() && isGreater ) ) {
1453 Handle(SALOME_InteractiveObject) io = new SALOME_InteractiveObject();
1454 io->setEntry( anEntry.toUtf8().constData() );
1455 toSelect.Append(io);
1458 if ( toSelect.Extent() > 0 ) {
1459 myGeomGUI->getApp()->selectionMgr()->setSelectedObjects(toSelect);
1460 SUIT_MessageBox::information( this,
1462 tr( "GEOM_SOME_SHAPES_SELECTED").arg( toSelect.Extent() ),
1466 SUIT_MessageBox::information( this,
1468 tr( "GEOM_NO_SHAPES_SELECTED" ),
1474 #ifndef DISABLE_PLOT2DVIEWER
1475 //=================================================================================
1476 // function : ClickOnPlot()
1477 // purpose : opens "Shape Statistics" dialog box in order to plot sub-shapes distribution.
1478 //=================================================================================
1479 void GroupGUI_GroupDlg::ClickOnPlot()
1481 TopoDS_Shape aMainShape = GEOM_Client::get_client().GetShape(GeometryGUI::GetGeomGen(), myMainObj);
1482 QDialog* dlg = new MeasureGUI_ShapeStatisticsDlg( this, aMainShape, getShapeType() );
1489 void GroupGUI_GroupDlg::MeasureToggled()
1491 myLessFilterSpin->setEnabled(myLessFilterCheck->isChecked());
1492 myLessFilterCombo->setEnabled(myLessFilterCheck->isChecked());
1493 myGreaterFilterSpin->setEnabled(myGreaterFilterCheck->isChecked());
1494 myGreaterFilterCombo->setEnabled(myGreaterFilterCheck->isChecked());
1495 myApplyFilterButton->setEnabled(myLessFilterCheck->isChecked() || myGreaterFilterCheck->isChecked());
1498 //=================================================================================
1499 // function : getSourceObjects
1500 // purpose : virtual method to get source objects
1501 //=================================================================================
1502 QList<GEOM::GeomObjPtr> GroupGUI_GroupDlg::getSourceObjects()
1504 QList<GEOM::GeomObjPtr> res;
1505 GEOM::GeomObjPtr aGeomObjPtr1(myMainObj), aGeomObjPtr2(myInPlaceObj);
1506 res << aGeomObjPtr1 << aGeomObjPtr2;