1 // GEOM GEOMGUI : GUI for Geometry component
3 // Copyright (C) 2004 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
24 // File : GroupGUI_GroupDlg.cxx
25 // Author : Sergey ANIKIN
29 #include "GroupGUI_GroupDlg.h"
31 #include "LightApp_SelectionMgr.h"
32 #include "SUIT_Desktop.h"
33 #include "SUIT_OverrideCursor.h"
34 #include "SUIT_Session.h"
35 #include "SalomeApp_Application.h"
36 #include "SalomeApp_Study.h"
39 #include "GEOMImpl_Types.hxx"
40 #include "GEOM_Displayer.h"
44 #include <qlineedit.h>
47 #include <TColStd_IndexedMapOfInteger.hxx>
48 #include <TColStd_MapOfInteger.hxx>
49 #include <TColStd_DataMapIteratorOfDataMapOfIntegerInteger.hxx>
53 enum { ALL_SUBSHAPES = 0, GET_IN_PLACE, SUBSHAPES_OF_SHAPE2 };
55 GroupGUI_GroupDlg::GroupGUI_GroupDlg(Mode mode, GeometryGUI* theGeometryGUI, QWidget* parent)
56 :GEOMBase_Skeleton( theGeometryGUI, parent, "GroupGUI_GroupDlg", false,
57 WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu),
61 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
63 QPixmap image0 (resMgr->loadPixmap("GEOM", tr("ICON_OBJBROWSER_VERTEX")));
64 QPixmap image1 (resMgr->loadPixmap("GEOM", tr("ICON_OBJBROWSER_EDGE")));
65 QPixmap image2 (resMgr->loadPixmap("GEOM", tr("ICON_OBJBROWSER_FACE")));
66 QPixmap image3 (resMgr->loadPixmap("GEOM", tr("ICON_OBJBROWSER_SOLID")));
67 QPixmap iconSelect (resMgr->loadPixmap("GEOM", tr("ICON_SELECT")));
69 setCaption( myMode == CreateGroup ? tr( "CREATE_GROUP_TITLE" ) : tr( "EDIT_GROUP_TITLE" ) );
71 // Shape type button group
72 GroupConstructors->setEnabled( myMode == CreateGroup );
73 GroupConstructors->setTitle( tr( "SHAPE_TYPE" ) );
74 RadioButton1->setPixmap( image0 );
75 RadioButton2->setPixmap( image1 );
76 RadioButton3->setPixmap( image2 );
77 RadioButton4->setPixmap( image3 );
81 GroupBoxName->setTitle( tr( "GROUP_NAME" ) );
83 // Main shape and sub-shapes
84 QGroupBox* GroupMedium = new QGroupBox( 1, Qt::Vertical, tr( "MAIN_SUB_SHAPES" ), this );
85 GroupMedium->setInsideMargin( 10 );
86 Layout1->addWidget( GroupMedium, 2, 0 );
88 QWidget* aFrame = new QWidget( GroupMedium );
89 QGridLayout* aMedLayout = new QGridLayout( aFrame, 6, 4, 0, 6 );
91 QLabel* aMainLabel = new QLabel( tr( "MAIN_SHAPE" ), aFrame );
93 mySelBtn = new QPushButton( aFrame );
94 mySelBtn->setPixmap( iconSelect );
95 mySelBtn->setEnabled( myMode == CreateGroup );
97 myMainName = new QLineEdit( aFrame );
98 myMainName->setReadOnly( true );
99 myMainName->setEnabled( myMode == CreateGroup );
101 QLabel* aSecondLabel = new QLabel( tr( "SECOND_SHAPE" ), aFrame );
103 mySelBtn2 = new QPushButton( aFrame );
104 mySelBtn2->setPixmap( iconSelect );
105 mySelBtn2->setEnabled( false );
107 myShape2Name = new QLineEdit( aFrame );
108 myShape2Name->setReadOnly( true );
109 myShape2Name->setEnabled( false );
111 //mySelSubBtn = new QRadioButton ( tr( "SELECT_SUB_SHAPES" ), aFrame );
112 //myPlaceCheckBox = new QCheckBox ( tr( "GET_IN_PLACE" ), aFrame );
113 mySelectionWayGroup = new QButtonGroup(1, Qt::Horizontal, tr("SHAPE_SEL_RESTR"),aFrame);
114 mySelectionWayGroup->setExclusive(true);
115 QRadioButton* allSubs = new QRadioButton(tr("NO_RESTR") ,mySelectionWayGroup);
116 QRadioButton* inPlaceSubs = new QRadioButton(tr("GEOM_PARTS_OF_SHAPE2"),mySelectionWayGroup);
117 QRadioButton* shape2Subs = new QRadioButton(tr("SUBSHAPES_OF_SHAPE2") ,mySelectionWayGroup);
118 mySelectionWayGroup->insert(allSubs , ALL_SUBSHAPES);
119 mySelectionWayGroup->insert(inPlaceSubs, GET_IN_PLACE);
120 mySelectionWayGroup->insert(shape2Subs , SUBSHAPES_OF_SHAPE2);
121 mySelectionWayGroup->setButton( ALL_SUBSHAPES );
123 mySelAllBtn = new QPushButton( tr( "SELECT_ALL" ), aFrame );
124 myAddBtn = new QPushButton( tr( "ADD" ), aFrame );
125 myRemBtn = new QPushButton( tr( "REMOVE" ), aFrame );
126 myIdList = new QListBox( aFrame );
128 myIdList->setSelectionMode( QListBox::Extended );
129 myIdList->setRowMode( QListBox::FitToWidth );
131 aMedLayout->addWidget( aMainLabel, 0, 0 );
132 aMedLayout->addWidget( mySelBtn, 0, 1 );
133 aMedLayout->addMultiCellWidget( myMainName, 0, 0, 2, 3 );
135 aMedLayout->addWidget( aSecondLabel, 1, 0 );
136 aMedLayout->addWidget( mySelBtn2, 1, 1 );
137 aMedLayout->addMultiCellWidget( myShape2Name, 1, 1, 2, 3 );
140 //aMedLayout->addMultiCellWidget( mySelSubBtn, 2, 2, 0, 1 );
141 //aMedLayout->addWidget( myPlaceCheckBox, 2, 2 );
142 //aMedLayout->addMultiCellWidget( myPlaceCheckBox, 2, 2, 0, 2 );
143 aMedLayout->addMultiCellWidget( mySelectionWayGroup, 2, 4, 0, 2 );
144 aMedLayout->addWidget( mySelAllBtn, 2, 3 );
145 aMedLayout->addWidget( myAddBtn, 3, 3 );
146 aMedLayout->addWidget( myRemBtn, 4, 3 );
147 aMedLayout->addMultiCellWidget( myIdList, 5, 5, 0, 3 );
148 aMedLayout->setRowStretch( 5, 1 );
151 setHelpFileName("work_with_groups_page.html");
156 GroupGUI_GroupDlg::~GroupGUI_GroupDlg()
161 //=================================================================================
164 //=================================================================================
165 void GroupGUI_GroupDlg::Init()
167 // san -- TODO: clear selected sub-shapes...
168 //mySelSubBtn->setChecked( true );
169 if ( myMode == CreateGroup ) {
170 initName( tr( "GROUP_PREFIX" ) );
172 // Get ready for main shape selection
173 myEditCurrentArgument = myMainName;
175 connect( GroupConstructors, SIGNAL( clicked( int ) ), this, SLOT( ConstructorsClicked( int ) ) );
176 connect( mySelBtn, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
177 connect( mySelBtn2, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
179 else if ( myMode == EditGroup && IObjectCount() ) {
180 Standard_Boolean aResult = Standard_False;
181 GEOM::GEOM_Object_var anObj =
182 GEOMBase::ConvertIOinGEOMObject( firstIObject(), aResult );
184 if ( aResult && !CORBA::is_nil( anObj ) && anObj->GetType() == GEOM_GROUP ) {
187 ResultName->setText( GEOMBase::GetName( myGroup ) );
189 GEOM::GEOM_IGroupOperations_var anOp = GEOM::GEOM_IGroupOperations::_narrow( getOperation() );
190 myMainObj = anOp->GetMainShape( myGroup );
191 if ( !CORBA::is_nil( myMainObj ) )
192 myMainName->setText( GEOMBase::GetName( myMainObj ) );
194 setShapeType( (TopAbs_ShapeEnum)anOp->GetType( myGroup ) );
196 GEOM::ListOfLong_var aCurrList = anOp->GetObjects( myGroup );
197 QListBoxItem* anItem;
198 for ( int i = 0, n = aCurrList->length(); i < n; i++ ) {
199 anItem = new QListBoxText( QString( "%1" ).arg(aCurrList[i] ) );
200 myIdList->insertItem( anItem );
203 myEditCurrentArgument = 0;
205 connect( mySelBtn2, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
208 LightApp_SelectionMgr* aSelMgr =
209 ((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr();
211 connect( aSelMgr, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
213 connect( buttonOk , SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
214 connect( buttonApply, SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
216 //connect( mySelSubBtn, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
217 //connect( myPlaceCheckBox, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
218 connect( mySelectionWayGroup,SIGNAL(clicked(int)),this,SLOT(SetEditCurrentArgument()));
219 connect( mySelAllBtn, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
220 connect( myAddBtn, SIGNAL( clicked() ), this, SLOT( add() ) );
221 connect( myRemBtn, SIGNAL( clicked() ), this, SLOT( remove() ) );
222 connect( myIdList, SIGNAL( selectionChanged() ), this, SLOT( selectionChanged() ) );
224 setInPlaceObj( GEOM::GEOM_Object::_nil() );
226 myBusy = true; // just activate but do not select in the list
229 // activate subshapes selection if Main Shape is Selected
230 // if ( !CORBA::is_nil( myMainObj ) ) {
231 // myEditCurrentArgument = 0;
232 // activateSelection();
237 //=================================================================================
238 // function : enterEvent()
240 //=================================================================================
241 void GroupGUI_GroupDlg::enterEvent( QEvent* e )
243 if ( !buttonCancel->isEnabled() )
244 this->ActivateThisDialog();
247 //=======================================================================
248 //function : closeEvent
249 //purpose : remove temporary geom object
250 //=======================================================================
252 void GroupGUI_GroupDlg::closeEvent(QCloseEvent* e)
254 setInPlaceObj( GEOM::GEOM_Object::_nil() );
256 GEOMBase_Skeleton::closeEvent(e);
259 //=================================================================================
260 // function : ClickOnOk()
262 //=================================================================================
263 void GroupGUI_GroupDlg::ClickOnOk()
265 if ( ClickOnApply() )
269 //=================================================================================
270 // function : ClickOnApply()
272 //=================================================================================
273 bool GroupGUI_GroupDlg::ClickOnApply()
275 if ( !onAccept( myMode == CreateGroup, true ) )
278 if ( myMode == CreateGroup )
288 //=================================================================================
289 // function : ActivateThisDialog()
291 //=================================================================================
292 void GroupGUI_GroupDlg::ActivateThisDialog()
294 GEOMBase_Skeleton::ActivateThisDialog();
296 connect( ((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
297 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
302 //=================================================================================
303 // function : LineEditReturnPressed()
305 //=================================================================================
306 void GroupGUI_GroupDlg::LineEditReturnPressed()
308 QLineEdit* send = ( QLineEdit* )sender();
310 if ( send == myMainName && !myEditCurrentArgument ) {
311 myEditCurrentArgument = myMainName;
315 GEOMBase_Skeleton::LineEditReturnPressed();
320 //=================================================================================
321 // function : SetEditCurrentArgument()
323 //=================================================================================
324 void GroupGUI_GroupDlg::SetEditCurrentArgument()
326 QPushButton* send = (QPushButton*)sender();
328 if ( send == mySelBtn ) {
329 myEditCurrentArgument = myMainName;
330 myShape2Name->setText( "" );
332 else if ( /*(QRadioButton*)sender() == mySelSubBtn ||*/ send == mySelAllBtn )
333 myEditCurrentArgument = 0;
334 else if ( send == mySelBtn2 || sender() == mySelectionWayGroup ) {
335 setInPlaceObj( GEOM::GEOM_Object::_nil() );
336 //if ( myPlaceCheckBox->isChecked() )
337 myShape2Name->setText( "" );
338 if ( subSelectionWay() != ALL_SUBSHAPES )
340 myEditCurrentArgument = myShape2Name;
343 //myEditCurrentArgument = myMainName;
344 myEditCurrentArgument = 0;
350 if ( send == mySelAllBtn ) {
351 // myShape2Name->setText( "" );
352 // myPlaceCheckBox->setChecked( false );
353 // mySelBtn2->setEnabled( false );
354 // myShape2Name->setEnabled( false );
355 selectAllSubShapes();
361 //=================================================================================
362 // function : onGetInPlace()
364 //=================================================================================
365 void GroupGUI_GroupDlg::onGetInPlace()
367 setInPlaceObj( GEOM::GEOM_Object::_nil() );
368 myEditCurrentArgument->setText( "" );
370 bool isBlocked = myIdList->signalsBlocked();
371 myIdList->blockSignals( true );
372 myIdList->clearSelection();
373 myIdList->blockSignals( isBlocked );
375 if (IObjectCount() != 1 )
378 Standard_Boolean aResult = Standard_False;
379 GEOM::GEOM_Object_var anObj =
380 GEOMBase::ConvertIOinGEOMObject( firstIObject(), aResult );
381 if ( aResult && !anObj->_is_nil() && GEOMBase::IsShape( anObj ) ) {
382 if ( !anObj->_is_equivalent(myMainObj) && !anObj->_is_equivalent( myGroup )) {
383 SUIT_OverrideCursor wc;
384 myEditCurrentArgument->setText( GEOMBase::GetName( anObj ) );
385 GEOM::GEOM_IShapesOperations_var aShapesOp =
386 getGeomEngine()->GetIShapesOperations( getStudyId() );
387 if ( subSelectionWay() == GET_IN_PLACE ) {
388 GEOM::GEOM_Object_var aGetInPlaceObj = aShapesOp->GetInPlace(myMainObj, anObj);
389 setInPlaceObj( aGetInPlaceObj );
392 setInPlaceObj( anObj );
394 myEditCurrentArgument = 0;
395 //myBusy = true; // just activate but do not select in the list
402 //=======================================================================
403 //function : setInPlaceObj
404 //purpose : temporarily add an object to study and remove old InPlaceObj
405 //=======================================================================
407 void GroupGUI_GroupDlg::setInPlaceObj( GEOM::GEOM_Object_var theObj )
409 if ( ! myInPlaceObj->_is_equivalent( theObj ) )
411 const char* tmpName = "__InPlaceObj__";
412 // remove old InPlaceObj
413 if ( !myInPlaceObj->_is_nil() ) {
414 if ( myInPlaceObjSelectWay == GET_IN_PLACE ) { // hide temporary object
415 GEOM_Displayer aDisplayer(getStudy());
416 aDisplayer.Erase( myInPlaceObj, true );
418 if (_PTR(SObject) SO = getStudy()->studyDS()->FindObject( tmpName )) {
419 getStudy()->studyDS()->NewBuilder()->RemoveObjectWithChildren( SO );
420 getGeomEngine()->RemoveObject(myInPlaceObj);
423 // publish InPlaceObj to enable localSelection(InPlaceObj)
424 if ( !theObj->_is_nil() && subSelectionWay() == GET_IN_PLACE ) {
425 SALOMEDS::Study_var aStudyDS = GeometryGUI::ClientStudyToStudy(getStudy()->studyDS());
426 SALOMEDS::SObject_var aSO =
427 getGeomEngine()->AddInStudy(aStudyDS, theObj, tmpName, myMainObj);
429 myInPlaceObj = theObj;
431 // build map of indices
432 myMain2InPlaceIndices.Clear();
433 if ( !myInPlaceObj->_is_nil() ) {
434 GEOM::GEOM_IShapesOperations_var aShapesOp = getGeomEngine()->GetIShapesOperations( getStudyId() );
435 GEOM::GEOM_ILocalOperations_var aLocOp = getGeomEngine()->GetILocalOperations( getStudyId() );
437 GEOM::ListOfGO_var aSubObjects = aShapesOp->MakeExplode( myInPlaceObj, getShapeType(), false);
438 for (int i = 0; i < aSubObjects->length(); i++)
440 CORBA::Long aMainIndex = aLocOp->GetSubShapeIndex( myMainObj, aSubObjects[i] );
441 CORBA::Long aPlaceIndex = aLocOp->GetSubShapeIndex( myInPlaceObj, aSubObjects[i] );
442 if ( aMainIndex >= 0 && aPlaceIndex > 0)
443 myMain2InPlaceIndices.Bind( aMainIndex, aPlaceIndex );
446 myInPlaceObjSelectWay = subSelectionWay();
449 //=================================================================================
450 // function : SelectionIntoArgument()
451 // purpose : Called when selection has changed
452 //=================================================================================
453 void GroupGUI_GroupDlg::SelectionIntoArgument()
455 // if (myPlaceCheckBox->isChecked() && myEditCurrentArgument == myShape2Name )
456 if (subSelectionWay() != ALL_SUBSHAPES && myEditCurrentArgument == myShape2Name ) {
461 if ( myEditCurrentArgument == myMainName) { // Selection of a main shape is active
462 myEditCurrentArgument->setText( "" );
465 if ( IObjectCount() == 1 ) {
466 Standard_Boolean aResult = Standard_False;
467 GEOM::GEOM_Object_var anObj =
468 GEOMBase::ConvertIOinGEOMObject( firstIObject(), aResult );
470 if ( aResult && !anObj->_is_nil() && GEOMBase::IsShape( anObj ) ) {
472 myEditCurrentArgument->setText( GEOMBase::GetName( anObj ) );
473 // activate subshapes selection by default
474 myEditCurrentArgument = 0;
481 myMainObj = GEOM::GEOM_Object::_nil();
483 else { // an attempt to synchronize list box selection with 3d viewer
488 bool isBlocked = myIdList->signalsBlocked();
489 myIdList->blockSignals( true );
490 myIdList->clearSelection();
492 TColStd_IndexedMapOfInteger aMapIndex;
494 SALOME_ListIO aSelIOs;
495 SalomeApp_Application* app = myGeomGUI->getApp();
497 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
499 QMap<QString, TColStd_IndexedMapOfInteger> aMap;
500 aSelMgr->selectedSubOwners(aMap);
501 if (aMap.size() == 1)
502 aMapIndex = aMap.begin().data();
505 bool subselected = aMapIndex.Extent();
507 // convert inPlace indices to main indices
508 //if ( subselected && myPlaceCheckBox->isChecked() )
509 if ( subselected && subSelectionWay() != ALL_SUBSHAPES )
511 TColStd_IndexedMapOfInteger aMapIndex2;
513 TColStd_DataMapIteratorOfDataMapOfIntegerInteger m2ip( myMain2InPlaceIndices );
514 for ( ; m2ip.More(); m2ip.Next() ) {
515 int inPlaceId = m2ip.Value();
516 if ( aMapIndex.Contains( inPlaceId )) {
517 aMapIndex2.Add( m2ip.Key() );
520 aMapIndex = aMapIndex2;
523 // try to find out and process the object browser selection
524 if ( !subselected ) {
525 globalSelection( GEOM_ALLSHAPES );
527 GEOM::ListOfGO anObjects;
528 GEOMBase::ConvertListOfIOInListOfGO(selectedIO(), anObjects);
530 GEOM::GEOM_ILocalOperations_var aLocOp = getGeomEngine()->GetILocalOperations( getStudyId() );
531 GEOM::GEOM_IShapesOperations_var aShapesOp = getGeomEngine()->GetIShapesOperations( getStudyId() );
533 for (int i = 0; i < anObjects.length(); i++)
535 GEOM::GEOM_Object_var aGeomObj = anObjects[i];
536 GEOM::ListOfGO_var aSubObjects = new GEOM::ListOfGO();
538 if ( GEOMBase::GetShape(aGeomObj, aShape, getShapeType()) )
540 aSubObjects->length(1);
541 aSubObjects[0] = aGeomObj;
543 else if (aGeomObj->GetType() == GEOM_GROUP)
544 aSubObjects = aShapesOp->MakeExplode( aGeomObj, getShapeType(), false);
548 for (int i = 0; i < aSubObjects->length(); i++)
551 if ( GEOMBase::GetShape(aSubObjects[i], aShape, getShapeType()) )
554 anIndex = aLocOp->GetSubShapeIndex( myMainObj, aSubObjects[i] );
555 if ( anIndex >= 0 ) {
556 //if ( myPlaceCheckBox->isChecked() && ! myMain2InPlaceIndices.IsBound( anIndex ))
557 if ( subSelectionWay() != ALL_SUBSHAPES &&
558 ! myMain2InPlaceIndices.IsBound( anIndex ))
560 aMapIndex.Add( anIndex );
565 if ( !myMainObj->_is_nil() /*&& mySelSubBtn->isChecked()*/)
566 if ( subSelectionWay() == ALL_SUBSHAPES )
567 localSelection( myMainObj, getShapeType() );
568 else if ( !myInPlaceObj->_is_nil() )
569 localSelection( myInPlaceObj, getShapeType() );
572 if (aMapIndex.Extent() >= 1) {
574 for ( int i = 0, n = myIdList->count(); i < n; i++ )
575 aMap.insert( myIdList->item( i )->text().toInt(), i );
577 for ( int ii = 1, nn = aMapIndex.Extent(); ii <= nn; ii++ ) {
578 if ( aMap.contains( aMapIndex( ii ) ) )
579 myIdList->setSelected( aMap[aMapIndex( ii )], true );
582 myIdList->blockSignals( isBlocked );
588 //=================================================================================
589 // function : ConstructorsClicked()
590 // purpose : Radio button management
591 //=================================================================================
592 void GroupGUI_GroupDlg::ConstructorsClicked( int constructorId )
597 setInPlaceObj( myInPlaceObj ); // to rebuild myMain2InPlaceIndices
600 //=================================================================================
601 // function : selectAllSubShapes
603 //=================================================================================
604 void GroupGUI_GroupDlg::selectAllSubShapes()
606 if ( CORBA::is_nil( myMainObj ) )
609 GEOM::ListOfLong_var aSubShapes;
610 // if ( !myPlaceCheckBox->isChecked() )
611 if ( subSelectionWay() == ALL_SUBSHAPES )
614 GEOM::GEOM_IShapesOperations_var aShOp = getGeomEngine()->GetIShapesOperations( getStudyId() );
615 aSubShapes = aShOp->SubShapeAllIDs(myMainObj, getShapeType(), false);
617 if ( !aShOp->IsDone() )
622 aSubShapes = new GEOM::ListOfLong();
623 aSubShapes->length( myMain2InPlaceIndices.Extent() );
624 TColStd_DataMapIteratorOfDataMapOfIntegerInteger m2ip( myMain2InPlaceIndices );
625 for ( int i = 0; m2ip.More(); i++, m2ip.Next() )
626 aSubShapes[ i ] = m2ip.Key();
628 bool isBlocked = myIdList->signalsBlocked();
629 myIdList->blockSignals( true );
631 QListBoxItem* anItem;
632 for ( int i = 0, n = aSubShapes->length(); i < n; i++ ) {
633 CORBA::Long anIndex = aSubShapes[i];
637 QString text = QString( "%1" ).arg( anIndex );
638 if ( !myInPlaceObj->_is_nil() )
639 anItem = myIdList->findItem( text, Qt::ExactMatch);
641 anItem = new QListBoxText( text );
642 myIdList->insertItem( anItem );
644 myIdList->setSelected( anItem, true );
647 myIdList->blockSignals( isBlocked );
648 highlightSubShapes();
651 //=================================================================================
654 //=================================================================================
655 void GroupGUI_GroupDlg::add()
657 TColStd_MapOfInteger aMap;
658 for ( int i = 0, n = myIdList->count(); i < n; i++ )
659 aMap.Add( myIdList->item( i )->text().toInt() );
661 TColStd_IndexedMapOfInteger aMapIndex;
663 SALOME_ListIO aSelIOs;
664 SalomeApp_Application* app = myGeomGUI->getApp();
666 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
668 QMap<QString, TColStd_IndexedMapOfInteger> aMap;
669 aSelMgr->selectedSubOwners(aMap);
670 if (aMap.size() == 1)
671 aMapIndex = aMap.begin().data();
674 GEOM::ListOfGO anObjects;
675 // get selected sub-shapes of myInPlaceObj
676 if ( aMapIndex.Extent() > 0 && !myInPlaceObj->_is_nil() )
678 GEOM::GEOM_IShapesOperations_var aShapesOp = getGeomEngine()->GetIShapesOperations( getStudyId() );
680 anObjects.length( aMapIndex.Extent() );
681 for ( int i = 1; i <= aMapIndex.Extent(); i++ )
682 anObjects[ i-1 ] = aShapesOp->GetSubShape( myInPlaceObj, aMapIndex( i ));
687 // try to find out and process the object browser selection or InPlace sub-shapes
688 if ( !aMapIndex.Extent() )
690 if ( anObjects.length() == 0 )
691 GEOMBase::ConvertListOfIOInListOfGO(aSelIOs, anObjects);
693 GEOM::GEOM_ILocalOperations_var aLocOp = getGeomEngine()->GetILocalOperations( getStudyId() );
694 GEOM::GEOM_IShapesOperations_var aShapesOp = getGeomEngine()->GetIShapesOperations( getStudyId() );
696 for (int i = 0; i < anObjects.length(); i++)
698 GEOM::GEOM_Object_var aGeomObj = anObjects[i];
699 GEOM::ListOfGO_var aSubObjects = new GEOM::ListOfGO();
701 if ( GEOMBase::GetShape(aGeomObj, aShape, getShapeType()) )
703 aSubObjects->length(1);
704 aSubObjects[0] = aGeomObj;
706 else if (aGeomObj->GetType() == GEOM_GROUP)
707 aSubObjects = aShapesOp->MakeExplode( aGeomObj, getShapeType(), false);
711 for (int i = 0; i < aSubObjects->length(); i++)
714 if ( GEOMBase::GetShape(aSubObjects[i], aShape, getShapeType()) )
717 anIndex = aLocOp->GetSubShapeIndex( myMainObj, aSubObjects[i] );
719 aMapIndex.Add( anIndex );
725 if ( aMapIndex.Extent() >= 1 ) {
726 QListBoxItem* anItem;
727 bool isBlocked = myIdList->signalsBlocked();
728 myIdList->blockSignals( true );
730 for ( int i = 1, n = aMapIndex.Extent(); i <= n; i++ ) {
731 if ( aMap.Contains( aMapIndex( i ) ) )
734 anItem = new QListBoxText( QString( "%1" ).arg( aMapIndex( i ) ) );
735 myIdList->insertItem( anItem );
736 myIdList->setSelected( anItem, true );
739 myIdList->blockSignals( isBlocked );
745 //=================================================================================
748 //=================================================================================
749 void GroupGUI_GroupDlg::remove()
751 bool isBlocked = myIdList->signalsBlocked();
752 myIdList->blockSignals( true );
754 for ( int i = myIdList->count() - 1; i >= 0; i-- ) {
755 if ( myIdList->isSelected( i ) )
756 myIdList->removeItem( i );
759 myIdList->blockSignals( isBlocked );
761 highlightSubShapes();
765 //=================================================================================
766 // function : getConstructorId()
768 //=================================================================================
769 int GroupGUI_GroupDlg::getConstructorId() const
771 return GroupConstructors->id( GroupConstructors->selected() );
774 //=======================================================================
775 //function : subSelectionWay
777 //=======================================================================
779 int GroupGUI_GroupDlg::subSelectionWay() const
781 return mySelectionWayGroup->id( mySelectionWayGroup->selected() );
784 //=================================================================================
785 // function : getShapeType()
787 //=================================================================================
788 TopAbs_ShapeEnum GroupGUI_GroupDlg::getShapeType() const
790 switch ( getConstructorId() ) {
791 case 0: return TopAbs_VERTEX;
792 case 1: return TopAbs_EDGE;
793 case 2: return TopAbs_FACE;
794 case 3: return TopAbs_SOLID;
795 default: return TopAbs_SHAPE;
799 //=================================================================================
800 // function : setShapeType()
802 //=================================================================================
803 void GroupGUI_GroupDlg::setShapeType( const TopAbs_ShapeEnum theType )
807 case TopAbs_VERTEX: anId = 0; break;
808 case TopAbs_EDGE: anId = 1; break;
809 case TopAbs_FACE: anId = 2; break;
810 case TopAbs_SOLID: anId = 3; break;
812 GroupConstructors->setButton( anId );
816 //=================================================================================
817 // function : activateSelection
818 // purpose : Activate selection in accordance with myEditCurrentArgument
819 //=================================================================================
820 void GroupGUI_GroupDlg::activateSelection()
822 globalSelection( GEOM_ALLSHAPES );
825 if ( !myMainObj->_is_nil() && !myEditCurrentArgument/* && mySelSubBtn->isChecked()*/) {
826 // if ( !myPlaceCheckBox->isChecked() )
827 if ( subSelectionWay() == ALL_SUBSHAPES )
828 localSelection( myMainObj, getShapeType() );
829 else if ( !myInPlaceObj->_is_nil() )
830 localSelection( myInPlaceObj, getShapeType() );
833 SelectionIntoArgument();
836 //=================================================================================
837 // function : updateState
839 //=================================================================================
840 void GroupGUI_GroupDlg::updateState()
844 TColStd_IndexedMapOfInteger aMapIndex;
846 SALOME_ListIO aSelIOs;
847 SalomeApp_Application* app = myGeomGUI->getApp();
849 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
851 QMap<QString, TColStd_IndexedMapOfInteger> aMap;
852 aSelMgr->selectedSubOwners(aMap);
853 if (aMap.size() == 1)
854 aMapIndex = aMap.begin().data();
858 // try to find out and process the object browser selection
859 if ( !aMapIndex.Extent() && !CORBA::is_nil( myMainObj ) ) {
860 GEOM::ListOfGO anObjects;
861 //GEOMBase::ConvertListOfIOInListOfGO(selectedIO(), anObjects);
862 GEOMBase::ConvertListOfIOInListOfGO(aSelIOs, anObjects);
864 GEOM::GEOM_ILocalOperations_var aLocOp = getGeomEngine()->GetILocalOperations( getStudyId() );
865 GEOM::GEOM_IShapesOperations_var aShapesOp = getGeomEngine()->GetIShapesOperations( getStudyId() );
869 for (int i = 0; i < anObjects.length(); i++)
871 GEOM::GEOM_Object_var aGeomObj = anObjects[i];
872 GEOM::ListOfGO_var aSubObjects = new GEOM::ListOfGO();
874 if ( GEOMBase::GetShape(aGeomObj, aShape, getShapeType()) ) {
875 aSubObjects->length(1);
876 aSubObjects[0] = aGeomObj;
878 else if (aGeomObj->GetType() == GEOM_GROUP) {
879 aSubObjects = aShapesOp->MakeExplode( aGeomObj, getShapeType(), false);
886 for (int i = 0; i < aSubObjects->length(); i++)
890 if ( GEOMBase::GetShape(aSubObjects[i], aShape, getShapeType()) )
893 anIndex = aLocOp->GetSubShapeIndex( myMainObj, aSubObjects[i] );
895 aMapIndex.Add( anIndex );
914 isAdd = aMapIndex.Extent() > 0;
916 myAddBtn->setEnabled( !myEditCurrentArgument && !CORBA::is_nil( myMainObj ) && isAdd );
918 for ( int ii = 0, nn = myIdList->count(); !hasSel && ii < nn; ii++ )
919 hasSel = myIdList->isSelected( ii );
920 myRemBtn->setEnabled( hasSel );
921 //mySelSubBtn->setEnabled( !CORBA::is_nil( myMainObj ) );
922 //myPlaceCheckBox->setEnabled( !CORBA::is_nil( myMainObj ) );
923 mySelectionWayGroup->setEnabled( !CORBA::is_nil( myMainObj ) );
924 mySelAllBtn->setEnabled( !CORBA::is_nil( myMainObj ) );
925 // mySelBtn2->setEnabled( myPlaceCheckBox->isChecked() );
926 // myShape2Name->setEnabled( myPlaceCheckBox->isChecked() );
927 mySelBtn2->setEnabled( subSelectionWay() != ALL_SUBSHAPES );
928 myShape2Name->setEnabled( subSelectionWay() != ALL_SUBSHAPES );
929 // if ( !myPlaceCheckBox->isChecked() )
930 if ( subSelectionWay() == ALL_SUBSHAPES )
931 setInPlaceObj( GEOM::GEOM_Object::_nil() );
934 //=================================================================================
935 // function : selectionChanged
937 //=================================================================================
938 void GroupGUI_GroupDlg::selectionChanged()
940 highlightSubShapes();
943 //=================================================================================
944 // function : highlightSubShapes
946 //=================================================================================
947 void GroupGUI_GroupDlg::highlightSubShapes()
949 if ( CORBA::is_nil( myMainObj ) )
952 Standard_Boolean isOk;
955 if ( myInPlaceObj->_is_nil() )
956 objIOR = GEOMBase::GetIORFromObject( myMainObj );
958 objIOR = GEOMBase::GetIORFromObject( myInPlaceObj );
960 Handle(GEOM_AISShape) aSh = GEOMBase::ConvertIORinGEOMAISShape( objIOR, isOk, true );
962 if ( !isOk || aSh.IsNull() )
965 TColStd_MapOfInteger anIds;
969 int ii = 0, nn = myIdList->count();
970 for ( ; ii < nn; ii++ )
971 if ( myIdList->isSelected( ii ) ) {
972 int id = myIdList->item( ii )->text().toInt();
973 // if ( myPlaceCheckBox->isChecked() )
974 if ( subSelectionWay() != ALL_SUBSHAPES )
976 if (myMain2InPlaceIndices.IsBound( id ))
977 id = myMain2InPlaceIndices( id );
979 myIdList->setSelected( ii, false );
986 SalomeApp_Application* app = myGeomGUI->getApp();
987 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
988 aSelMgr->clearSelected();
990 aSelMgr->AddOrRemoveIndex(aSh->getIO(), anIds, false);
997 myAddBtn->setEnabled( true );
998 myRemBtn->setEnabled( true );
1002 //=================================================================================
1003 // function : createOperation
1005 //=================================================================================
1006 GEOM::GEOM_IOperations_ptr GroupGUI_GroupDlg::createOperation()
1008 return getGeomEngine()->GetIGroupOperations( getStudyId() );
1011 #define RETURN_WITH_MSG(a, b) \
1013 theMessage += (b); \
1017 //=================================================================================
1018 // function : isValid()
1019 // purpose : Verify validity of input data
1020 //=================================================================================
1021 bool GroupGUI_GroupDlg::isValid( QString& theMessage )
1023 SalomeApp_Study* study = getStudy();
1025 RETURN_WITH_MSG ( !study->studyDS()->GetProperties()->IsLocked(), tr( "GEOM_STUDY_LOCKED" ) )
1027 if ( myMode == CreateGroup ) {
1028 RETURN_WITH_MSG( !CORBA::is_nil( myMainObj ), tr( "NO_MAIN_OBJ" ) )
1031 RETURN_WITH_MSG( !CORBA::is_nil( myMainObj ), tr( "NO_GROUP" ) )
1034 QString aName (getNewObjectName());
1035 RETURN_WITH_MSG ( !aName.stripWhiteSpace().isEmpty(), tr( "EMPTY_NAME" ) )
1037 RETURN_WITH_MSG ( myIdList->count(), tr( "EMPTY_LIST" ) )
1041 //=================================================================================
1042 // function : execute
1044 //=================================================================================
1045 bool GroupGUI_GroupDlg::execute( ObjectList& objects )
1047 setInPlaceObj( GEOM::GEOM_Object::_nil() );
1049 GEOM::GEOM_IGroupOperations_var anOp = GEOM::GEOM_IGroupOperations::_narrow(getOperation());
1051 GEOM::GEOM_Object_var aGroup;
1052 if (myMode == CreateGroup)
1053 aGroup = anOp->CreateGroup(myMainObj, getShapeType());
1054 else if (myMode == EditGroup)
1057 if (CORBA::is_nil(aGroup) || (myMode == CreateGroup && !anOp->IsDone()))
1060 GEOM::ListOfLong_var aCurrList = anOp->GetObjects(aGroup);
1061 if (!anOp->IsDone())
1064 if (aCurrList->length() > 0)
1066 anOp->DifferenceIDs(aGroup, aCurrList);
1067 if (!anOp->IsDone())
1071 int ii, nn = myIdList->count();
1074 GEOM::ListOfLong_var aNewList = new GEOM::ListOfLong;
1075 aNewList->length(nn);
1076 for (ii = 0; ii < nn; ii++) {
1077 aNewList[ii] = myIdList->item(ii)->text().toInt();
1079 anOp->UnionIDs(aGroup, aNewList);
1080 if (!anOp->IsDone())
1084 SalomeApp_Study* study = getStudy();
1086 char* objIOR = GEOMBase::GetIORFromObject( aGroup );
1087 string IOR( objIOR );
1090 _PTR(SObject) SO ( study->studyDS()->FindObjectIOR( IOR ) );
1092 _PTR(StudyBuilder) aBuilder (study->studyDS()->NewBuilder());
1093 aBuilder->SetName( SO, getNewObjectName() );
1098 objects.push_back( aGroup._retn() );
1103 //================================================================
1104 // Function : getFather
1105 // Purpose : Get father object for object to be added in study
1106 // ( called with addInStudy method )
1107 //================================================================
1108 GEOM::GEOM_Object_ptr GroupGUI_GroupDlg::getFather( GEOM::GEOM_Object_ptr theObj )
1110 GEOM::GEOM_Object_var aFatherObj;
1111 if ( theObj->GetType() == GEOM_GROUP ) {
1112 GEOM::GEOM_IGroupOperations_var anOp = GEOM::GEOM_IGroupOperations::_narrow( getOperation() );
1113 aFatherObj = anOp->GetMainShape( theObj );
1115 return aFatherObj._retn();