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
22 // File : GroupGUI_GroupDlg.cxx
23 // Author : Sergey ANIKIN, Open CASCADE S.A.S. (sergey.anikin@opencascade.com)
26 #include "GroupGUI_GroupDlg.h"
28 #include <LightApp_SelectionMgr.h>
29 #include <SUIT_ResourceMgr.h>
30 #include <SUIT_Desktop.h>
31 #include <SUIT_OverrideCursor.h>
32 #include <SUIT_Session.h>
33 #include <SalomeApp_Application.h>
34 #include <SalomeApp_Study.h>
38 #include <GeometryGUI.h>
39 #include <GEOMImpl_Types.hxx>
40 #include <GEOM_Displayer.h>
43 #include <QListWidget>
47 #include <TColStd_IndexedMapOfInteger.hxx>
48 #include <TColStd_MapOfInteger.hxx>
49 #include <TColStd_DataMapIteratorOfDataMapOfIntegerInteger.hxx>
51 enum { ALL_SUBSHAPES = 0, GET_IN_PLACE, SUBSHAPES_OF_SHAPE2 };
53 GroupGUI_GroupDlg::GroupGUI_GroupDlg( Mode mode, GeometryGUI* theGeometryGUI, QWidget* parent )
54 : GEOMBase_Skeleton( theGeometryGUI, parent, false ),
58 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
60 QPixmap image0 ( resMgr->loadPixmap( "GEOM", tr( "ICON_OBJBROWSER_VERTEX" ) ) );
61 QPixmap image1 ( resMgr->loadPixmap( "GEOM", tr( "ICON_OBJBROWSER_EDGE" ) ) );
62 QPixmap image2 ( resMgr->loadPixmap( "GEOM", tr( "ICON_OBJBROWSER_FACE" ) ) );
63 QPixmap image3 ( resMgr->loadPixmap( "GEOM", tr( "ICON_OBJBROWSER_SOLID" ) ) );
64 QPixmap iconSelect ( resMgr->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
66 setWindowTitle( myMode == CreateGroup ? tr( "CREATE_GROUP_TITLE" ) : tr( "EDIT_GROUP_TITLE" ) );
68 // Shape type button group
69 mainFrame()->GroupConstructors->setEnabled( myMode == CreateGroup );
70 mainFrame()->GroupConstructors->setTitle( tr( "SHAPE_TYPE" ) );
71 mainFrame()->RadioButton1->setIcon( image0 );
72 mainFrame()->RadioButton2->setIcon( image1 );
73 mainFrame()->RadioButton3->setIcon( image2 );
74 mainFrame()->RadioButton4->setIcon( image3 );
75 mainFrame()->RadioButton4->show();
78 mainFrame()->GroupBoxName->setTitle( tr( "GROUP_NAME" ) );
80 // Main shape and sub-shapes
81 QGroupBox* GroupMedium = new QGroupBox( tr( "MAIN_SUB_SHAPES" ), centralWidget() );
82 QGridLayout* aMedLayout = new QGridLayout( GroupMedium );
83 aMedLayout->setMargin( 9 );
84 aMedLayout->setSpacing( 6 );
86 QLabel* aMainLabel = new QLabel( tr( "MAIN_SHAPE" ), GroupMedium );
88 mySelBtn = new QPushButton( GroupMedium );
89 mySelBtn->setIcon( iconSelect );
90 mySelBtn->setEnabled( myMode == CreateGroup );
92 myMainName = new QLineEdit( GroupMedium );
93 myMainName->setReadOnly( true );
94 myMainName->setEnabled( myMode == CreateGroup );
96 QLabel* aSecondLabel = new QLabel( tr( "SECOND_SHAPE" ), GroupMedium );
98 mySelBtn2 = new QPushButton( GroupMedium );
99 mySelBtn2->setIcon( iconSelect );
100 mySelBtn2->setEnabled( false );
102 myShape2Name = new QLineEdit( GroupMedium );
103 myShape2Name->setReadOnly( true );
104 myShape2Name->setEnabled( false );
106 mySelectionWayGroupBox = new QGroupBox( tr("SHAPE_SEL_RESTR"), GroupMedium );
107 mySelectionWayGroup = new QButtonGroup( mySelectionWayGroupBox );
108 QRadioButton* allSubs = new QRadioButton( tr( "NO_RESTR" ) , mySelectionWayGroupBox );
109 QRadioButton* inPlaceSubs = new QRadioButton( tr( "GEOM_PARTS_OF_SHAPE2" ), mySelectionWayGroupBox );
110 QRadioButton* shape2Subs = new QRadioButton( tr( "SUBSHAPES_OF_SHAPE2" ) , mySelectionWayGroupBox );
111 QVBoxLayout* mySelWayLayout = new QVBoxLayout( mySelectionWayGroupBox );
112 mySelWayLayout->setMargin( 9 );
113 mySelWayLayout->setSpacing( 6 );
114 mySelWayLayout->addWidget( allSubs );
115 mySelWayLayout->addWidget( inPlaceSubs );
116 mySelWayLayout->addWidget( shape2Subs );
117 mySelectionWayGroup->addButton( allSubs, ALL_SUBSHAPES );
118 mySelectionWayGroup->addButton( inPlaceSubs, GET_IN_PLACE );
119 mySelectionWayGroup->addButton( shape2Subs, SUBSHAPES_OF_SHAPE2 );
120 allSubs->setChecked( true );
122 mySelAllBtn = new QPushButton( tr( "SELECT_ALL" ), GroupMedium );
123 myAddBtn = new QPushButton( tr( "ADD" ), GroupMedium );
124 myRemBtn = new QPushButton( tr( "REMOVE" ), GroupMedium );
125 myIdList = new QListWidget( GroupMedium );
127 myIdList->setSelectionMode( QAbstractItemView::ExtendedSelection );
128 myIdList->setFlow( QListView::TopToBottom );
129 myIdList->setWrapping( true );
131 aMedLayout->addWidget( aMainLabel, 0, 0 );
132 aMedLayout->addWidget( mySelBtn, 0, 1 );
133 aMedLayout->addWidget( myMainName, 0, 2, 1, 2 );
134 aMedLayout->addWidget( aSecondLabel, 1, 0 );
135 aMedLayout->addWidget( mySelBtn2, 1, 1 );
136 aMedLayout->addWidget( myShape2Name, 1, 2, 1, 2 );
137 aMedLayout->addWidget( mySelectionWayGroupBox, 2, 0, 3, 3 );
138 aMedLayout->addWidget( mySelAllBtn, 2, 3 );
139 aMedLayout->addWidget( myAddBtn, 3, 3 );
140 aMedLayout->addWidget( myRemBtn, 4, 3 );
141 aMedLayout->addWidget( myIdList, 5, 0, 1, 4 );
142 aMedLayout->setRowStretch( 5, 1 );
144 QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
145 layout->setMargin( 0 ); layout->setSpacing( 6 );
146 layout->addWidget( GroupMedium );
148 setHelpFileName( "work_with_groups_page.html" );
153 GroupGUI_GroupDlg::~GroupGUI_GroupDlg()
157 //=================================================================================
160 //=================================================================================
161 void GroupGUI_GroupDlg::Init()
163 // san -- TODO: clear selected sub-shapes...
164 //mySelSubBtn->setChecked( true );
165 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
167 if ( myMode == CreateGroup ) {
168 initName( tr( "GROUP_PREFIX" ) );
170 // Get ready for main shape selection
171 myEditCurrentArgument = myMainName;
173 connect( this, SIGNAL( constructorsClicked( int ) ), this, SLOT( ConstructorsClicked( int ) ) );
174 connect( mySelBtn, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
175 connect( mySelBtn2, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
177 else if (myMode == EditGroup) {
178 SALOME_ListIO aSelList;
179 aSelMgr->selectedObjects(aSelList);
181 if (aSelList.Extent()) {
182 Standard_Boolean aResult = Standard_False;
183 GEOM::GEOM_Object_var anObj =
184 GEOMBase::ConvertIOinGEOMObject(aSelList.First(), aResult);
186 if ( aResult && !CORBA::is_nil( anObj ) && anObj->GetType() == GEOM_GROUP ) {
189 mainFrame()->ResultName->setText( GEOMBase::GetName( myGroup ) );
191 GEOM::GEOM_IGroupOperations_var anOp = GEOM::GEOM_IGroupOperations::_narrow( getOperation() );
192 myMainObj = anOp->GetMainShape( myGroup );
193 if ( !CORBA::is_nil( myMainObj ) )
194 myMainName->setText( GEOMBase::GetName( myMainObj ) );
196 setShapeType( (TopAbs_ShapeEnum)anOp->GetType( myGroup ) );
198 GEOM::ListOfLong_var aCurrList = anOp->GetObjects( myGroup );
199 for ( int i = 0, n = aCurrList->length(); i < n; i++ )
200 myIdList->addItem( new QListWidgetItem( QString( "%1" ).arg( aCurrList[i] ) ) );
202 myEditCurrentArgument = 0;
204 connect( mySelBtn2, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
208 connect( aSelMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()) );
210 connect( buttonOk(), SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
211 connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
213 connect( mySelectionWayGroup, SIGNAL( buttonClicked( int ) ), this, SLOT( SetEditCurrentArgument() ) );
214 connect( mySelAllBtn, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
215 connect( myAddBtn, SIGNAL( clicked() ), this, SLOT( add() ) );
216 connect( myRemBtn, SIGNAL( clicked() ), this, SLOT( remove() ) );
217 connect( myIdList, SIGNAL( selectionChanged() ), this, SLOT( selectionChanged() ) );
219 setInPlaceObj(GEOM::GEOM_Object::_nil());
221 myBusy = true; // just activate but do not select in the list
226 //=================================================================================
227 // function : enterEvent()
229 //=================================================================================
230 void GroupGUI_GroupDlg::enterEvent( QEvent* e )
232 if ( !buttonCancel()->isEnabled() )
233 ActivateThisDialog();
236 //=======================================================================
237 //function : closeEvent
238 //purpose : remove temporary geom object
239 //=======================================================================
241 void GroupGUI_GroupDlg::closeEvent( QCloseEvent* e )
243 setInPlaceObj( GEOM::GEOM_Object::_nil() );
245 GEOMBase_Skeleton::closeEvent( e );
248 //=================================================================================
249 // function : ClickOnOk()
251 //=================================================================================
252 void GroupGUI_GroupDlg::ClickOnOk()
254 if ( ClickOnApply() )
258 //=================================================================================
259 // function : ClickOnApply()
261 //=================================================================================
262 bool GroupGUI_GroupDlg::ClickOnApply()
264 if ( !onAccept( myMode == CreateGroup, true ) )
267 if ( myMode == CreateGroup )
271 ConstructorsClicked( getConstructorId() );
278 //=================================================================================
279 // function : ActivateThisDialog()
281 //=================================================================================
282 void GroupGUI_GroupDlg::ActivateThisDialog()
284 GEOMBase_Skeleton::ActivateThisDialog();
286 connect( ((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
287 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
292 //=================================================================================
293 // function : LineEditReturnPressed()
295 //=================================================================================
296 void GroupGUI_GroupDlg::LineEditReturnPressed()
298 QLineEdit* send = ( QLineEdit* )sender();
300 if ( send == myMainName && !myEditCurrentArgument ) {
301 myEditCurrentArgument = myMainName;
305 GEOMBase_Skeleton::LineEditReturnPressed();
310 //=================================================================================
311 // function : SetEditCurrentArgument()
313 //=================================================================================
314 void GroupGUI_GroupDlg::SetEditCurrentArgument()
316 QPushButton* send = (QPushButton*)sender();
318 if ( send == mySelBtn ) {
319 myEditCurrentArgument = myMainName;
320 myShape2Name->setText( "" );
322 else if ( /*(QRadioButton*)sender() == mySelSubBtn ||*/ send == mySelAllBtn )
323 myEditCurrentArgument = 0;
324 else if ( send == mySelBtn2 || sender() == mySelectionWayGroup ) {
325 setInPlaceObj( GEOM::GEOM_Object::_nil() );
326 //if ( myPlaceCheckBox->isChecked() )
327 myShape2Name->setText( "" );
328 if ( subSelectionWay() != ALL_SUBSHAPES )
330 myEditCurrentArgument = myShape2Name;
333 //myEditCurrentArgument = myMainName;
334 myEditCurrentArgument = 0;
340 if ( send == mySelAllBtn ) {
341 // myShape2Name->setText( "" );
342 // myPlaceCheckBox->setChecked( false );
343 // mySelBtn2->setEnabled( false );
344 // myShape2Name->setEnabled( false );
345 selectAllSubShapes();
351 //=================================================================================
352 // function : onGetInPlace()
354 //=================================================================================
355 void GroupGUI_GroupDlg::onGetInPlace()
357 setInPlaceObj( GEOM::GEOM_Object::_nil() );
358 myEditCurrentArgument->setText( "" );
360 bool isBlocked = myIdList->signalsBlocked();
361 myIdList->blockSignals( true );
362 myIdList->clearSelection();
363 myIdList->blockSignals( isBlocked );
365 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
366 SALOME_ListIO aSelList;
367 aSelMgr->selectedObjects(aSelList);
369 if (aSelList.Extent() != 1)
372 Standard_Boolean aResult = Standard_False;
373 GEOM::GEOM_Object_var anObj =
374 GEOMBase::ConvertIOinGEOMObject(aSelList.First(), aResult);
375 if (aResult && !anObj->_is_nil() && GEOMBase::IsShape(anObj)) {
376 if (!anObj->_is_equivalent(myMainObj) && !anObj->_is_equivalent(myGroup)) {
377 SUIT_OverrideCursor wc;
378 myEditCurrentArgument->setText(GEOMBase::GetName(anObj));
379 GEOM::GEOM_IShapesOperations_var aShapesOp =
380 getGeomEngine()->GetIShapesOperations(getStudyId());
381 if ( subSelectionWay() == GET_IN_PLACE ) {
382 GEOM::GEOM_Object_var aGetInPlaceObj = aShapesOp->GetInPlace(myMainObj, anObj);
383 setInPlaceObj( aGetInPlaceObj );
386 setInPlaceObj( anObj );
388 myEditCurrentArgument = 0;
389 //myBusy = true; // just activate but do not select in the list
396 //=======================================================================
397 //function : setInPlaceObj
398 //purpose : temporarily add an object to study and remove old InPlaceObj
399 //=======================================================================
401 void GroupGUI_GroupDlg::setInPlaceObj( GEOM::GEOM_Object_var theObj )
403 if ( ! myInPlaceObj->_is_equivalent( theObj ) )
405 const char* tmpName = "__InPlaceObj__";
406 // remove old InPlaceObj
407 if ( !myInPlaceObj->_is_nil() ) {
408 if ( myInPlaceObjSelectWay == GET_IN_PLACE ) { // hide temporary object
409 GEOM_Displayer aDisplayer(getStudy());
410 aDisplayer.Erase( myInPlaceObj, true );
412 if (_PTR(SObject) SO = getStudy()->studyDS()->FindObject( tmpName )) {
413 getStudy()->studyDS()->NewBuilder()->RemoveObjectWithChildren( SO );
414 getGeomEngine()->RemoveObject(myInPlaceObj);
417 // publish InPlaceObj to enable localSelection(InPlaceObj)
418 if ( !theObj->_is_nil() && subSelectionWay() == GET_IN_PLACE ) {
419 SALOMEDS::Study_var aStudyDS = GeometryGUI::ClientStudyToStudy(getStudy()->studyDS());
420 SALOMEDS::SObject_var aSO =
421 getGeomEngine()->AddInStudy(aStudyDS, theObj, tmpName, myMainObj);
423 myInPlaceObj = theObj;
425 // build map of indices
426 myMain2InPlaceIndices.Clear();
427 if ( !myInPlaceObj->_is_nil() ) {
428 GEOM::GEOM_IShapesOperations_var aShapesOp = getGeomEngine()->GetIShapesOperations( getStudyId() );
429 GEOM::GEOM_ILocalOperations_var aLocOp = getGeomEngine()->GetILocalOperations( getStudyId() );
431 GEOM::ListOfGO_var aSubObjects = aShapesOp->MakeExplode( myInPlaceObj, getShapeType(), false);
432 for (int i = 0; i < aSubObjects->length(); i++)
434 CORBA::Long aMainIndex = aLocOp->GetSubShapeIndex( myMainObj, aSubObjects[i] );
435 CORBA::Long aPlaceIndex = aLocOp->GetSubShapeIndex( myInPlaceObj, aSubObjects[i] );
436 if ( aMainIndex >= 0 && aPlaceIndex > 0)
437 myMain2InPlaceIndices.Bind( aMainIndex, aPlaceIndex );
440 myInPlaceObjSelectWay = subSelectionWay();
443 //=================================================================================
444 // function : SelectionIntoArgument()
445 // purpose : Called when selection has changed
446 //=================================================================================
447 void GroupGUI_GroupDlg::SelectionIntoArgument()
449 // if (myPlaceCheckBox->isChecked() && myEditCurrentArgument == myShape2Name )
450 if (subSelectionWay() != ALL_SUBSHAPES && myEditCurrentArgument == myShape2Name) {
455 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
456 SALOME_ListIO aSelList;
457 aSelMgr->selectedObjects(aSelList);
459 if (myEditCurrentArgument == myMainName) { // Selection of a main shape is active
460 myEditCurrentArgument->setText("");
463 if (aSelList.Extent() == 1) {
464 Standard_Boolean aResult = Standard_False;
465 GEOM::GEOM_Object_var anObj =
466 GEOMBase::ConvertIOinGEOMObject(aSelList.First(), aResult);
468 if ( aResult && !anObj->_is_nil() && GEOMBase::IsShape( anObj ) ) {
470 myEditCurrentArgument->setText( GEOMBase::GetName( anObj ) );
471 // activate subshapes selection by default
472 myEditCurrentArgument = 0;
479 myMainObj = GEOM::GEOM_Object::_nil();
481 else { // an attempt to synchronize list box selection with 3d viewer
486 bool isBlocked = myIdList->signalsBlocked();
487 myIdList->blockSignals( true );
488 myIdList->clearSelection();
490 TColStd_IndexedMapOfInteger aMapIndex;
492 LightApp_SelectionMgr::MapEntryOfMapOfInteger aMap;
493 aSelMgr->selectedSubOwners( aMap );
494 if ( aMap.Size() == 1 )
495 aMapIndex = LightApp_SelectionMgr::MapEntryOfMapOfInteger::Iterator( aMap ).Value();
496 bool subselected = aMapIndex.Extent();
498 // convert inPlace indices to main indices
499 //if ( subselected && myPlaceCheckBox->isChecked() )
500 if ( subselected && subSelectionWay() != ALL_SUBSHAPES )
502 TColStd_IndexedMapOfInteger aMapIndex2;
504 TColStd_DataMapIteratorOfDataMapOfIntegerInteger m2ip( myMain2InPlaceIndices );
505 for ( ; m2ip.More(); m2ip.Next() ) {
506 int inPlaceId = m2ip.Value();
507 if ( aMapIndex.Contains( inPlaceId )) {
508 aMapIndex2.Add( m2ip.Key() );
511 aMapIndex = aMapIndex2;
514 // try to find out and process the object browser selection
515 if ( !subselected ) {
516 globalSelection( GEOM_ALLSHAPES );
518 GEOM::ListOfGO anObjects;
519 GEOMBase::ConvertListOfIOInListOfGO(aSelList, anObjects);
521 GEOM::GEOM_ILocalOperations_var aLocOp = getGeomEngine()->GetILocalOperations( getStudyId() );
522 GEOM::GEOM_IShapesOperations_var aShapesOp = getGeomEngine()->GetIShapesOperations( getStudyId() );
524 for (int i = 0; i < anObjects.length(); i++)
526 GEOM::GEOM_Object_var aGeomObj = anObjects[i];
527 GEOM::ListOfGO_var aSubObjects = new GEOM::ListOfGO();
529 if ( GEOMBase::GetShape(aGeomObj, aShape, getShapeType()) )
531 aSubObjects->length(1);
532 aSubObjects[0] = aGeomObj;
534 else if (aGeomObj->GetType() == GEOM_GROUP)
535 aSubObjects = aShapesOp->MakeExplode( aGeomObj, getShapeType(), false);
539 for (int i = 0; i < aSubObjects->length(); i++)
542 if ( GEOMBase::GetShape(aSubObjects[i], aShape, getShapeType()) )
545 anIndex = aLocOp->GetSubShapeIndex( myMainObj, aSubObjects[i] );
546 if ( anIndex >= 0 ) {
547 //if ( myPlaceCheckBox->isChecked() && ! myMain2InPlaceIndices.IsBound( anIndex ))
548 if ( subSelectionWay() != ALL_SUBSHAPES &&
549 ! myMain2InPlaceIndices.IsBound( anIndex ))
551 aMapIndex.Add( anIndex );
556 if ( !myMainObj->_is_nil() /*&& mySelSubBtn->isChecked()*/)
557 if ( subSelectionWay() == ALL_SUBSHAPES )
558 localSelection( myMainObj, getShapeType() );
559 else if ( !myInPlaceObj->_is_nil() )
560 localSelection( myInPlaceObj, getShapeType() );
563 if (aMapIndex.Extent() >= 1) {
565 for ( int i = 0, n = myIdList->count(); i < n; i++ )
566 aMap.insert( myIdList->item( i )->text().toInt(), i );
568 for ( int ii = 1, nn = aMapIndex.Extent(); ii <= nn; ii++ ) {
569 if ( aMap.contains( aMapIndex( ii ) ) )
570 myIdList->item( aMap[aMapIndex( ii )])->setSelected( true );
573 myIdList->blockSignals( isBlocked );
579 //=================================================================================
580 // function : ConstructorsClicked()
581 // purpose : Radio button management
582 //=================================================================================
583 void GroupGUI_GroupDlg::ConstructorsClicked( int constructorId )
588 setInPlaceObj( myInPlaceObj ); // to rebuild myMain2InPlaceIndices
591 //=================================================================================
592 // function : selectAllSubShapes
594 //=================================================================================
595 void GroupGUI_GroupDlg::selectAllSubShapes()
597 if ( CORBA::is_nil( myMainObj ) )
600 GEOM::ListOfLong_var aSubShapes;
601 // if ( !myPlaceCheckBox->isChecked() )
602 if ( subSelectionWay() == ALL_SUBSHAPES )
605 GEOM::GEOM_IShapesOperations_var aShOp = getGeomEngine()->GetIShapesOperations( getStudyId() );
606 aSubShapes = aShOp->SubShapeAllIDs(myMainObj, getShapeType(), false);
608 if ( !aShOp->IsDone() )
613 aSubShapes = new GEOM::ListOfLong();
614 aSubShapes->length( myMain2InPlaceIndices.Extent() );
615 TColStd_DataMapIteratorOfDataMapOfIntegerInteger m2ip( myMain2InPlaceIndices );
616 for ( int i = 0; m2ip.More(); i++, m2ip.Next() )
617 aSubShapes[ i ] = m2ip.Key();
619 bool isBlocked = myIdList->signalsBlocked();
620 myIdList->blockSignals( true );
622 for ( int i = 0, n = aSubShapes->length(); i < n; i++ ) {
623 CORBA::Long anIndex = aSubShapes[i];
627 QListWidgetItem* anItem = 0;
628 QString text = QString( "%1" ).arg( anIndex );
629 if ( !myInPlaceObj->_is_nil() ) {
630 QList<QListWidgetItem*> found = myIdList->findItems( text, Qt::MatchExactly );
631 if ( found.count() ) anItem = found[0];
634 anItem = new QListWidgetItem( text );
635 myIdList->addItem( anItem );
637 anItem->setSelected( true );
640 myIdList->blockSignals( isBlocked );
641 highlightSubShapes();
644 //=================================================================================
647 //=================================================================================
648 void GroupGUI_GroupDlg::add()
650 TColStd_MapOfInteger aMap;
651 for ( int i = 0, n = myIdList->count(); i < n; i++ )
652 aMap.Add( myIdList->item( i )->text().toInt() );
654 TColStd_IndexedMapOfInteger aMapIndex;
656 SALOME_ListIO aSelIOs;
657 SalomeApp_Application* app = myGeomGUI->getApp();
659 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
661 LightApp_SelectionMgr::MapEntryOfMapOfInteger aMap;
662 aSelMgr->selectedSubOwners( aMap );
663 if ( aMap.Size() == 1 )
664 aMapIndex = LightApp_SelectionMgr::MapEntryOfMapOfInteger::Iterator( aMap ).Value();
667 GEOM::ListOfGO anObjects;
668 // get selected sub-shapes of myInPlaceObj
669 if ( aMapIndex.Extent() > 0 && !myInPlaceObj->_is_nil() )
671 GEOM::GEOM_IShapesOperations_var aShapesOp = getGeomEngine()->GetIShapesOperations( getStudyId() );
673 anObjects.length( aMapIndex.Extent() );
674 for ( int i = 1; i <= aMapIndex.Extent(); i++ )
675 anObjects[ i-1 ] = aShapesOp->GetSubShape( myInPlaceObj, aMapIndex( i ));
680 // try to find out and process the object browser selection or InPlace sub-shapes
681 if ( !aMapIndex.Extent() )
683 if ( anObjects.length() == 0 )
684 GEOMBase::ConvertListOfIOInListOfGO(aSelIOs, anObjects);
686 GEOM::GEOM_ILocalOperations_var aLocOp = getGeomEngine()->GetILocalOperations( getStudyId() );
687 GEOM::GEOM_IShapesOperations_var aShapesOp = getGeomEngine()->GetIShapesOperations( getStudyId() );
689 for (int i = 0; i < anObjects.length(); i++)
691 GEOM::GEOM_Object_var aGeomObj = anObjects[i];
692 GEOM::ListOfGO_var aSubObjects = new GEOM::ListOfGO();
694 if ( GEOMBase::GetShape(aGeomObj, aShape, getShapeType()) )
696 aSubObjects->length(1);
697 aSubObjects[0] = aGeomObj;
699 else if (aGeomObj->GetType() == GEOM_GROUP)
700 aSubObjects = aShapesOp->MakeExplode( aGeomObj, getShapeType(), false);
704 for (int i = 0; i < aSubObjects->length(); i++)
707 if ( GEOMBase::GetShape(aSubObjects[i], aShape, getShapeType()) )
710 anIndex = aLocOp->GetSubShapeIndex( myMainObj, aSubObjects[i] );
712 aMapIndex.Add( anIndex );
718 if ( aMapIndex.Extent() >= 1 ) {
719 bool isBlocked = myIdList->signalsBlocked();
720 myIdList->blockSignals( true );
722 for ( int i = 1, n = aMapIndex.Extent(); i <= n; i++ ) {
723 if ( aMap.Contains( aMapIndex( i ) ) )
726 QListWidgetItem* anItem = new QListWidgetItem( QString( "%1" ).arg( aMapIndex( i ) ) );
727 myIdList->addItem( anItem );
728 anItem->setSelected( true );
731 myIdList->blockSignals( isBlocked );
737 //=================================================================================
740 //=================================================================================
741 void GroupGUI_GroupDlg::remove()
743 bool isBlocked = myIdList->signalsBlocked();
744 myIdList->blockSignals( true );
746 QListIterator<QListWidgetItem*> it( myIdList->selectedItems() );
747 while ( it.hasNext() )
750 myIdList->blockSignals( isBlocked );
752 highlightSubShapes();
755 //=======================================================================
756 //function : subSelectionWay
758 //=======================================================================
760 int GroupGUI_GroupDlg::subSelectionWay() const
762 return mySelectionWayGroup->checkedId();
765 //=================================================================================
766 // function : getShapeType()
768 //=================================================================================
769 TopAbs_ShapeEnum GroupGUI_GroupDlg::getShapeType() const
771 switch ( getConstructorId() ) {
772 case 0: return TopAbs_VERTEX;
773 case 1: return TopAbs_EDGE;
774 case 2: return TopAbs_FACE;
775 case 3: return TopAbs_SOLID;
776 default: return TopAbs_SHAPE;
780 //=================================================================================
781 // function : setShapeType()
783 //=================================================================================
784 void GroupGUI_GroupDlg::setShapeType( const TopAbs_ShapeEnum theType )
788 case TopAbs_VERTEX: anId = 0; break;
789 case TopAbs_EDGE: anId = 1; break;
790 case TopAbs_FACE: anId = 2; break;
791 case TopAbs_SOLID: anId = 3; break;
793 setConstructorId( anId );
797 //=================================================================================
798 // function : activateSelection
799 // purpose : Activate selection in accordance with myEditCurrentArgument
800 //=================================================================================
801 void GroupGUI_GroupDlg::activateSelection()
803 globalSelection( GEOM_ALLSHAPES );
806 if ( !myMainObj->_is_nil() && !myEditCurrentArgument/* && mySelSubBtn->isChecked()*/) {
807 // if ( !myPlaceCheckBox->isChecked() )
808 if ( subSelectionWay() == ALL_SUBSHAPES )
809 localSelection( myMainObj, getShapeType() );
810 else if ( !myInPlaceObj->_is_nil() )
811 localSelection( myInPlaceObj, getShapeType() );
814 SelectionIntoArgument();
817 //=================================================================================
818 // function : updateState
820 //=================================================================================
821 void GroupGUI_GroupDlg::updateState()
825 TColStd_IndexedMapOfInteger aMapIndex;
827 SALOME_ListIO aSelIOs;
828 SalomeApp_Application* app = myGeomGUI->getApp();
830 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
832 LightApp_SelectionMgr::MapEntryOfMapOfInteger aMap;
833 aSelMgr->selectedSubOwners( aMap );
834 if ( aMap.Size() == 1 )
835 aMapIndex = LightApp_SelectionMgr::MapEntryOfMapOfInteger::Iterator( aMap ).Value();
839 // try to find out and process the object browser selection
840 if ( !aMapIndex.Extent() && !CORBA::is_nil( myMainObj ) ) {
841 GEOM::ListOfGO anObjects;
842 //GEOMBase::ConvertListOfIOInListOfGO(selectedIO(), anObjects);
843 GEOMBase::ConvertListOfIOInListOfGO(aSelIOs, anObjects);
845 GEOM::GEOM_ILocalOperations_var aLocOp = getGeomEngine()->GetILocalOperations( getStudyId() );
846 GEOM::GEOM_IShapesOperations_var aShapesOp = getGeomEngine()->GetIShapesOperations( getStudyId() );
850 for (int i = 0; i < anObjects.length(); i++)
852 GEOM::GEOM_Object_var aGeomObj = anObjects[i];
853 GEOM::ListOfGO_var aSubObjects = new GEOM::ListOfGO();
855 if ( GEOMBase::GetShape(aGeomObj, aShape, getShapeType()) ) {
856 aSubObjects->length(1);
857 aSubObjects[0] = aGeomObj;
859 else if (aGeomObj->GetType() == GEOM_GROUP) {
860 aSubObjects = aShapesOp->MakeExplode( aGeomObj, getShapeType(), false);
867 for (int i = 0; i < aSubObjects->length(); i++)
871 if ( GEOMBase::GetShape(aSubObjects[i], aShape, getShapeType()) )
874 anIndex = aLocOp->GetSubShapeIndex( myMainObj, aSubObjects[i] );
876 aMapIndex.Add( anIndex );
895 isAdd = aMapIndex.Extent() > 0;
897 myAddBtn->setEnabled( !myEditCurrentArgument && !CORBA::is_nil( myMainObj ) && isAdd );
898 bool hasSel = myIdList->selectedItems().count() > 0;
899 myRemBtn->setEnabled( hasSel );
900 //mySelSubBtn->setEnabled( !CORBA::is_nil( myMainObj ) );
901 //myPlaceCheckBox->setEnabled( !CORBA::is_nil( myMainObj ) );
902 mySelectionWayGroupBox->setEnabled( !CORBA::is_nil( myMainObj ) );
903 mySelAllBtn->setEnabled( !CORBA::is_nil( myMainObj ) );
904 // mySelBtn2->setEnabled( myPlaceCheckBox->isChecked() );
905 // myShape2Name->setEnabled( myPlaceCheckBox->isChecked() );
906 mySelBtn2->setEnabled( subSelectionWay() != ALL_SUBSHAPES );
907 myShape2Name->setEnabled( subSelectionWay() != ALL_SUBSHAPES );
908 // if ( !myPlaceCheckBox->isChecked() )
909 if ( subSelectionWay() == ALL_SUBSHAPES )
910 setInPlaceObj( GEOM::GEOM_Object::_nil() );
913 //=================================================================================
914 // function : selectionChanged
916 //=================================================================================
917 void GroupGUI_GroupDlg::selectionChanged()
919 highlightSubShapes();
922 //=================================================================================
923 // function : highlightSubShapes
925 //=================================================================================
926 void GroupGUI_GroupDlg::highlightSubShapes()
928 if ( CORBA::is_nil( myMainObj ) )
931 Standard_Boolean isOk;
934 if ( myInPlaceObj->_is_nil() )
935 objIOR = GEOMBase::GetIORFromObject( myMainObj );
937 objIOR = GEOMBase::GetIORFromObject( myInPlaceObj );
939 Handle(GEOM_AISShape) aSh = GEOMBase::ConvertIORinGEOMAISShape( objIOR, isOk, true );
941 if ( !isOk || aSh.IsNull() )
944 TColStd_MapOfInteger anIds;
948 int ii = 0, nn = myIdList->count();
949 for ( ; ii < nn; ii++ )
951 if ( myIdList->item( ii )->isSelected() ) {
952 int id = myIdList->item( ii )->text().toInt();
953 // if ( myPlaceCheckBox->isChecked() )
954 if ( subSelectionWay() != ALL_SUBSHAPES )
956 if ( myMain2InPlaceIndices.IsBound( id ) )
957 id = myMain2InPlaceIndices( id );
959 myIdList->item( ii )->setSelected( false );
966 SalomeApp_Application* app = myGeomGUI->getApp();
967 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
968 aSelMgr->clearSelected();
970 aSelMgr->AddOrRemoveIndex(aSh->getIO(), anIds, false);
977 myAddBtn->setEnabled( true );
978 myRemBtn->setEnabled( true );
982 //=================================================================================
983 // function : createOperation
985 //=================================================================================
986 GEOM::GEOM_IOperations_ptr GroupGUI_GroupDlg::createOperation()
988 return getGeomEngine()->GetIGroupOperations( getStudyId() );
991 #define RETURN_WITH_MSG(a, b) \
997 //=================================================================================
998 // function : isValid()
999 // purpose : Verify validity of input data
1000 //=================================================================================
1001 bool GroupGUI_GroupDlg::isValid( QString& theMessage )
1003 SalomeApp_Study* study = getStudy();
1005 RETURN_WITH_MSG ( !study->studyDS()->GetProperties()->IsLocked(), tr( "GEOM_STUDY_LOCKED" ) )
1007 if ( myMode == CreateGroup ) {
1008 RETURN_WITH_MSG( !CORBA::is_nil( myMainObj ), tr( "NO_MAIN_OBJ" ) )
1011 RETURN_WITH_MSG( !CORBA::is_nil( myMainObj ), tr( "NO_GROUP" ) )
1014 QString aName (getNewObjectName());
1015 RETURN_WITH_MSG ( !aName.trimmed().isEmpty(), tr( "EMPTY_NAME" ) )
1017 RETURN_WITH_MSG ( myIdList->count(), tr( "EMPTY_LIST" ) )
1021 //=================================================================================
1022 // function : execute
1024 //=================================================================================
1025 bool GroupGUI_GroupDlg::execute( ObjectList& objects )
1027 setInPlaceObj( GEOM::GEOM_Object::_nil() );
1029 GEOM::GEOM_IGroupOperations_var anOp = GEOM::GEOM_IGroupOperations::_narrow(getOperation());
1031 GEOM::GEOM_Object_var aGroup;
1032 if (myMode == CreateGroup)
1033 aGroup = anOp->CreateGroup(myMainObj, getShapeType());
1034 else if (myMode == EditGroup)
1037 if (CORBA::is_nil(aGroup) || (myMode == CreateGroup && !anOp->IsDone()))
1040 GEOM::ListOfLong_var aCurrList = anOp->GetObjects(aGroup);
1041 if (!anOp->IsDone())
1044 if (aCurrList->length() > 0)
1046 anOp->DifferenceIDs(aGroup, aCurrList);
1047 if (!anOp->IsDone())
1051 int ii, nn = myIdList->count();
1054 GEOM::ListOfLong_var aNewList = new GEOM::ListOfLong;
1055 aNewList->length(nn);
1056 for (ii = 0; ii < nn; ii++) {
1057 aNewList[ii] = myIdList->item(ii)->text().toInt();
1059 anOp->UnionIDs(aGroup, aNewList);
1060 if (!anOp->IsDone())
1064 SalomeApp_Study* study = getStudy();
1066 char* objIOR = GEOMBase::GetIORFromObject( aGroup );
1067 std::string IOR( objIOR );
1070 _PTR(SObject) SO ( study->studyDS()->FindObjectIOR( IOR ) );
1072 _PTR(StudyBuilder) aBuilder (study->studyDS()->NewBuilder());
1073 aBuilder->SetName( SO, getNewObjectName().toLatin1().constData() );
1078 objects.push_back( aGroup._retn() );
1083 //================================================================
1084 // Function : getFather
1085 // Purpose : Get father object for object to be added in study
1086 // ( called with addInStudy method )
1087 //================================================================
1088 GEOM::GEOM_Object_ptr GroupGUI_GroupDlg::getFather( GEOM::GEOM_Object_ptr theObj )
1090 GEOM::GEOM_Object_var aFatherObj;
1091 if ( theObj->GetType() == GEOM_GROUP ) {
1092 GEOM::GEOM_IGroupOperations_var anOp = GEOM::GEOM_IGroupOperations::_narrow( getOperation() );
1093 aFatherObj = anOp->GetMainShape( theObj );
1095 return aFatherObj._retn();