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>
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, "GroupGUI_GroupDlg", false,
55 WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu),
59 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
61 QPixmap image0 (resMgr->loadPixmap("GEOM", tr("ICON_OBJBROWSER_VERTEX")));
62 QPixmap image1 (resMgr->loadPixmap("GEOM", tr("ICON_OBJBROWSER_EDGE")));
63 QPixmap image2 (resMgr->loadPixmap("GEOM", tr("ICON_OBJBROWSER_FACE")));
64 QPixmap image3 (resMgr->loadPixmap("GEOM", tr("ICON_OBJBROWSER_SOLID")));
65 QPixmap iconSelect (resMgr->loadPixmap("GEOM", tr("ICON_SELECT")));
67 setCaption( myMode == CreateGroup ? tr( "CREATE_GROUP_TITLE" ) : tr( "EDIT_GROUP_TITLE" ) );
69 // Shape type button group
70 GroupConstructors->setEnabled( myMode == CreateGroup );
71 GroupConstructors->setTitle( tr( "SHAPE_TYPE" ) );
72 RadioButton1->setPixmap( image0 );
73 RadioButton2->setPixmap( image1 );
74 RadioButton3->setPixmap( image2 );
75 RadioButton4->setPixmap( image3 );
79 GroupBoxName->setTitle( tr( "GROUP_NAME" ) );
81 // Main shape and sub-shapes
82 QGroupBox* GroupMedium = new QGroupBox( 1, Qt::Vertical, tr( "MAIN_SUB_SHAPES" ), this );
83 GroupMedium->setInsideMargin( 10 );
84 Layout1->addWidget( GroupMedium, 2, 0 );
86 QWidget* aFrame = new QWidget( GroupMedium );
87 QGridLayout* aMedLayout = new QGridLayout( aFrame, 6, 4, 0, 6 );
89 QLabel* aMainLabel = new QLabel( tr( "MAIN_SHAPE" ), aFrame );
91 mySelBtn = new QPushButton( aFrame );
92 mySelBtn->setPixmap( iconSelect );
93 mySelBtn->setEnabled( myMode == CreateGroup );
95 myMainName = new QLineEdit( aFrame );
96 myMainName->setReadOnly( true );
97 myMainName->setEnabled( myMode == CreateGroup );
99 QLabel* aSecondLabel = new QLabel( tr( "SECOND_SHAPE" ), aFrame );
101 mySelBtn2 = new QPushButton( aFrame );
102 mySelBtn2->setPixmap( iconSelect );
103 mySelBtn2->setEnabled( false );
105 myShape2Name = new QLineEdit( aFrame );
106 myShape2Name->setReadOnly( true );
107 myShape2Name->setEnabled( false );
109 //mySelSubBtn = new QRadioButton ( tr( "SELECT_SUB_SHAPES" ), aFrame );
110 //myPlaceCheckBox = new QCheckBox ( tr( "GET_IN_PLACE" ), aFrame );
111 mySelectionWayGroup = new QButtonGroup(1, Qt::Horizontal, tr("SHAPE_SEL_RESTR"),aFrame);
112 mySelectionWayGroup->setExclusive(true);
113 QRadioButton* allSubs = new QRadioButton(tr("NO_RESTR") ,mySelectionWayGroup);
114 QRadioButton* inPlaceSubs = new QRadioButton(tr("GEOM_PARTS_OF_SHAPE2"),mySelectionWayGroup);
115 QRadioButton* shape2Subs = new QRadioButton(tr("SUBSHAPES_OF_SHAPE2") ,mySelectionWayGroup);
116 mySelectionWayGroup->insert(allSubs , ALL_SUBSHAPES);
117 mySelectionWayGroup->insert(inPlaceSubs, GET_IN_PLACE);
118 mySelectionWayGroup->insert(shape2Subs , SUBSHAPES_OF_SHAPE2);
119 mySelectionWayGroup->setButton( ALL_SUBSHAPES );
121 mySelAllBtn = new QPushButton( tr( "SELECT_ALL" ), aFrame );
122 myAddBtn = new QPushButton( tr( "ADD" ), aFrame );
123 myRemBtn = new QPushButton( tr( "REMOVE" ), aFrame );
124 myIdList = new QListBox( aFrame );
126 myIdList->setSelectionMode( QListBox::Extended );
127 myIdList->setRowMode( QListBox::FitToWidth );
129 aMedLayout->addWidget( aMainLabel, 0, 0 );
130 aMedLayout->addWidget( mySelBtn, 0, 1 );
131 aMedLayout->addMultiCellWidget( myMainName, 0, 0, 2, 3 );
133 aMedLayout->addWidget( aSecondLabel, 1, 0 );
134 aMedLayout->addWidget( mySelBtn2, 1, 1 );
135 aMedLayout->addMultiCellWidget( myShape2Name, 1, 1, 2, 3 );
138 //aMedLayout->addMultiCellWidget( mySelSubBtn, 2, 2, 0, 1 );
139 //aMedLayout->addWidget( myPlaceCheckBox, 2, 2 );
140 //aMedLayout->addMultiCellWidget( myPlaceCheckBox, 2, 2, 0, 2 );
141 aMedLayout->addMultiCellWidget( mySelectionWayGroup, 2, 4, 0, 2 );
142 aMedLayout->addWidget( mySelAllBtn, 2, 3 );
143 aMedLayout->addWidget( myAddBtn, 3, 3 );
144 aMedLayout->addWidget( myRemBtn, 4, 3 );
145 aMedLayout->addMultiCellWidget( myIdList, 5, 5, 0, 3 );
146 aMedLayout->setRowStretch( 5, 1 );
149 setHelpFileName("work_with_groups_page.html");
154 GroupGUI_GroupDlg::~GroupGUI_GroupDlg()
159 //=================================================================================
162 //=================================================================================
163 void GroupGUI_GroupDlg::Init()
165 // san -- TODO: clear selected sub-shapes...
166 //mySelSubBtn->setChecked( true );
167 if ( myMode == CreateGroup ) {
168 initName( tr( "GROUP_PREFIX" ) );
170 // Get ready for main shape selection
171 myEditCurrentArgument = myMainName;
173 connect( GroupConstructors, SIGNAL( clicked( 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 && IObjectCount() ) {
178 Standard_Boolean aResult = Standard_False;
179 GEOM::GEOM_Object_var anObj =
180 GEOMBase::ConvertIOinGEOMObject( firstIObject(), aResult );
182 if ( aResult && !CORBA::is_nil( anObj ) && anObj->GetType() == GEOM_GROUP ) {
185 ResultName->setText( GEOMBase::GetName( myGroup ) );
187 GEOM::GEOM_IGroupOperations_var anOp = GEOM::GEOM_IGroupOperations::_narrow( getOperation() );
188 myMainObj = anOp->GetMainShape( myGroup );
189 if ( !CORBA::is_nil( myMainObj ) )
190 myMainName->setText( GEOMBase::GetName( myMainObj ) );
192 setShapeType( (TopAbs_ShapeEnum)anOp->GetType( myGroup ) );
194 GEOM::ListOfLong_var aCurrList = anOp->GetObjects( myGroup );
195 QListBoxItem* anItem;
196 for ( int i = 0, n = aCurrList->length(); i < n; i++ ) {
197 anItem = new QListBoxText( QString( "%1" ).arg(aCurrList[i] ) );
198 myIdList->insertItem( anItem );
201 myEditCurrentArgument = 0;
203 connect( mySelBtn2, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
206 LightApp_SelectionMgr* aSelMgr =
207 ((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr();
209 connect( aSelMgr, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
211 connect( buttonOk , SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
212 connect( buttonApply, SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
214 //connect( mySelSubBtn, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
215 //connect( myPlaceCheckBox, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
216 connect( mySelectionWayGroup,SIGNAL(clicked(int)),this,SLOT(SetEditCurrentArgument()));
217 connect( mySelAllBtn, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
218 connect( myAddBtn, SIGNAL( clicked() ), this, SLOT( add() ) );
219 connect( myRemBtn, SIGNAL( clicked() ), this, SLOT( remove() ) );
220 connect( myIdList, SIGNAL( selectionChanged() ), this, SLOT( selectionChanged() ) );
222 setInPlaceObj( GEOM::GEOM_Object::_nil() );
224 myBusy = true; // just activate but do not select in the list
227 // activate subshapes selection if Main Shape is Selected
228 // if ( !CORBA::is_nil( myMainObj ) ) {
229 // myEditCurrentArgument = 0;
230 // activateSelection();
235 //=================================================================================
236 // function : enterEvent()
238 //=================================================================================
239 void GroupGUI_GroupDlg::enterEvent( QEvent* e )
241 if ( !buttonCancel->isEnabled() )
242 this->ActivateThisDialog();
245 //=======================================================================
246 //function : closeEvent
247 //purpose : remove temporary geom object
248 //=======================================================================
250 void GroupGUI_GroupDlg::closeEvent(QCloseEvent* e)
252 setInPlaceObj( GEOM::GEOM_Object::_nil() );
254 GEOMBase_Skeleton::closeEvent(e);
257 //=================================================================================
258 // function : ClickOnOk()
260 //=================================================================================
261 void GroupGUI_GroupDlg::ClickOnOk()
263 if ( ClickOnApply() )
267 //=================================================================================
268 // function : ClickOnApply()
270 //=================================================================================
271 bool GroupGUI_GroupDlg::ClickOnApply()
273 if ( !onAccept( myMode == CreateGroup, true ) )
276 if ( myMode == CreateGroup )
286 //=================================================================================
287 // function : ActivateThisDialog()
289 //=================================================================================
290 void GroupGUI_GroupDlg::ActivateThisDialog()
292 GEOMBase_Skeleton::ActivateThisDialog();
294 connect( ((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
295 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
300 //=================================================================================
301 // function : LineEditReturnPressed()
303 //=================================================================================
304 void GroupGUI_GroupDlg::LineEditReturnPressed()
306 QLineEdit* send = ( QLineEdit* )sender();
308 if ( send == myMainName && !myEditCurrentArgument ) {
309 myEditCurrentArgument = myMainName;
313 GEOMBase_Skeleton::LineEditReturnPressed();
318 //=================================================================================
319 // function : SetEditCurrentArgument()
321 //=================================================================================
322 void GroupGUI_GroupDlg::SetEditCurrentArgument()
324 QPushButton* send = (QPushButton*)sender();
326 if ( send == mySelBtn ) {
327 myEditCurrentArgument = myMainName;
328 myShape2Name->setText( "" );
330 else if ( /*(QRadioButton*)sender() == mySelSubBtn ||*/ send == mySelAllBtn )
331 myEditCurrentArgument = 0;
332 else if ( send == mySelBtn2 || sender() == mySelectionWayGroup ) {
333 setInPlaceObj( GEOM::GEOM_Object::_nil() );
334 //if ( myPlaceCheckBox->isChecked() )
335 myShape2Name->setText( "" );
336 if ( subSelectionWay() != ALL_SUBSHAPES )
338 myEditCurrentArgument = myShape2Name;
341 //myEditCurrentArgument = myMainName;
342 myEditCurrentArgument = 0;
348 if ( send == mySelAllBtn ) {
349 // myShape2Name->setText( "" );
350 // myPlaceCheckBox->setChecked( false );
351 // mySelBtn2->setEnabled( false );
352 // myShape2Name->setEnabled( false );
353 selectAllSubShapes();
359 //=================================================================================
360 // function : onGetInPlace()
362 //=================================================================================
363 void GroupGUI_GroupDlg::onGetInPlace()
365 setInPlaceObj( GEOM::GEOM_Object::_nil() );
366 myEditCurrentArgument->setText( "" );
368 bool isBlocked = myIdList->signalsBlocked();
369 myIdList->blockSignals( true );
370 myIdList->clearSelection();
371 myIdList->blockSignals( isBlocked );
373 if (IObjectCount() != 1 )
376 Standard_Boolean aResult = Standard_False;
377 GEOM::GEOM_Object_var anObj =
378 GEOMBase::ConvertIOinGEOMObject( firstIObject(), aResult );
379 if ( aResult && !anObj->_is_nil() && GEOMBase::IsShape( anObj ) ) {
380 if ( !anObj->_is_equivalent(myMainObj) && !anObj->_is_equivalent( myGroup )) {
381 SUIT_OverrideCursor wc;
382 myEditCurrentArgument->setText( GEOMBase::GetName( anObj ) );
383 GEOM::GEOM_IShapesOperations_var aShapesOp =
384 getGeomEngine()->GetIShapesOperations( getStudyId() );
385 if ( subSelectionWay() == GET_IN_PLACE ) {
386 GEOM::GEOM_Object_var aGetInPlaceObj = aShapesOp->GetInPlace(myMainObj, anObj);
387 setInPlaceObj( aGetInPlaceObj );
390 setInPlaceObj( anObj );
392 myEditCurrentArgument = 0;
393 //myBusy = true; // just activate but do not select in the list
400 //=======================================================================
401 //function : setInPlaceObj
402 //purpose : temporarily add an object to study and remove old InPlaceObj
403 //=======================================================================
405 void GroupGUI_GroupDlg::setInPlaceObj( GEOM::GEOM_Object_var theObj )
407 if ( ! myInPlaceObj->_is_equivalent( theObj ) )
409 const char* tmpName = "__InPlaceObj__";
410 // remove old InPlaceObj
411 if ( !myInPlaceObj->_is_nil() ) {
412 if ( myInPlaceObjSelectWay == GET_IN_PLACE ) { // hide temporary object
413 GEOM_Displayer aDisplayer(getStudy());
414 aDisplayer.Erase( myInPlaceObj, true );
416 if (_PTR(SObject) SO = getStudy()->studyDS()->FindObject( tmpName )) {
417 getStudy()->studyDS()->NewBuilder()->RemoveObjectWithChildren( SO );
418 getGeomEngine()->RemoveObject(myInPlaceObj);
421 // publish InPlaceObj to enable localSelection(InPlaceObj)
422 if ( !theObj->_is_nil() && subSelectionWay() == GET_IN_PLACE ) {
423 SALOMEDS::Study_var aStudyDS = GeometryGUI::ClientStudyToStudy(getStudy()->studyDS());
424 SALOMEDS::SObject_var aSO =
425 getGeomEngine()->AddInStudy(aStudyDS, theObj, tmpName, myMainObj);
427 myInPlaceObj = theObj;
429 // build map of indices
430 myMain2InPlaceIndices.Clear();
431 if ( !myInPlaceObj->_is_nil() ) {
432 GEOM::GEOM_IShapesOperations_var aShapesOp = getGeomEngine()->GetIShapesOperations( getStudyId() );
433 GEOM::GEOM_ILocalOperations_var aLocOp = getGeomEngine()->GetILocalOperations( getStudyId() );
435 GEOM::ListOfGO_var aSubObjects = aShapesOp->MakeExplode( myInPlaceObj, getShapeType(), false);
436 for (int i = 0; i < aSubObjects->length(); i++)
438 CORBA::Long aMainIndex = aLocOp->GetSubShapeIndex( myMainObj, aSubObjects[i] );
439 CORBA::Long aPlaceIndex = aLocOp->GetSubShapeIndex( myInPlaceObj, aSubObjects[i] );
440 if ( aMainIndex >= 0 && aPlaceIndex > 0)
441 myMain2InPlaceIndices.Bind( aMainIndex, aPlaceIndex );
444 myInPlaceObjSelectWay = subSelectionWay();
447 //=================================================================================
448 // function : SelectionIntoArgument()
449 // purpose : Called when selection has changed
450 //=================================================================================
451 void GroupGUI_GroupDlg::SelectionIntoArgument()
453 // if (myPlaceCheckBox->isChecked() && myEditCurrentArgument == myShape2Name )
454 if (subSelectionWay() != ALL_SUBSHAPES && myEditCurrentArgument == myShape2Name ) {
459 if ( myEditCurrentArgument == myMainName) { // Selection of a main shape is active
460 myEditCurrentArgument->setText( "" );
463 if ( IObjectCount() == 1 ) {
464 Standard_Boolean aResult = Standard_False;
465 GEOM::GEOM_Object_var anObj =
466 GEOMBase::ConvertIOinGEOMObject( firstIObject(), 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 SALOME_ListIO aSelIOs;
493 SalomeApp_Application* app = myGeomGUI->getApp();
495 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
497 QMap<QString, TColStd_IndexedMapOfInteger> aMap;
498 aSelMgr->selectedSubOwners(aMap);
499 if (aMap.size() == 1)
500 aMapIndex = aMap.begin().data();
503 bool subselected = aMapIndex.Extent();
505 // convert inPlace indices to main indices
506 //if ( subselected && myPlaceCheckBox->isChecked() )
507 if ( subselected && subSelectionWay() != ALL_SUBSHAPES )
509 TColStd_IndexedMapOfInteger aMapIndex2;
511 TColStd_DataMapIteratorOfDataMapOfIntegerInteger m2ip( myMain2InPlaceIndices );
512 for ( ; m2ip.More(); m2ip.Next() ) {
513 int inPlaceId = m2ip.Value();
514 if ( aMapIndex.Contains( inPlaceId )) {
515 aMapIndex2.Add( m2ip.Key() );
518 aMapIndex = aMapIndex2;
521 // try to find out and process the object browser selection
522 if ( !subselected ) {
523 globalSelection( GEOM_ALLSHAPES );
525 GEOM::ListOfGO anObjects;
526 GEOMBase::ConvertListOfIOInListOfGO(selectedIO(), anObjects);
528 GEOM::GEOM_ILocalOperations_var aLocOp = getGeomEngine()->GetILocalOperations( getStudyId() );
529 GEOM::GEOM_IShapesOperations_var aShapesOp = getGeomEngine()->GetIShapesOperations( getStudyId() );
531 for (int i = 0; i < anObjects.length(); i++)
533 GEOM::GEOM_Object_var aGeomObj = anObjects[i];
534 GEOM::ListOfGO_var aSubObjects = new GEOM::ListOfGO();
536 if ( GEOMBase::GetShape(aGeomObj, aShape, getShapeType()) )
538 aSubObjects->length(1);
539 aSubObjects[0] = aGeomObj;
541 else if (aGeomObj->GetType() == GEOM_GROUP)
542 aSubObjects = aShapesOp->MakeExplode( aGeomObj, getShapeType(), false);
546 for (int i = 0; i < aSubObjects->length(); i++)
549 if ( GEOMBase::GetShape(aSubObjects[i], aShape, getShapeType()) )
552 anIndex = aLocOp->GetSubShapeIndex( myMainObj, aSubObjects[i] );
553 if ( anIndex >= 0 ) {
554 //if ( myPlaceCheckBox->isChecked() && ! myMain2InPlaceIndices.IsBound( anIndex ))
555 if ( subSelectionWay() != ALL_SUBSHAPES &&
556 ! myMain2InPlaceIndices.IsBound( anIndex ))
558 aMapIndex.Add( anIndex );
563 if ( !myMainObj->_is_nil() /*&& mySelSubBtn->isChecked()*/)
564 if ( subSelectionWay() == ALL_SUBSHAPES )
565 localSelection( myMainObj, getShapeType() );
566 else if ( !myInPlaceObj->_is_nil() )
567 localSelection( myInPlaceObj, getShapeType() );
570 if (aMapIndex.Extent() >= 1) {
572 for ( int i = 0, n = myIdList->count(); i < n; i++ )
573 aMap.insert( myIdList->item( i )->text().toInt(), i );
575 for ( int ii = 1, nn = aMapIndex.Extent(); ii <= nn; ii++ ) {
576 if ( aMap.contains( aMapIndex( ii ) ) )
577 myIdList->setSelected( aMap[aMapIndex( ii )], true );
580 myIdList->blockSignals( isBlocked );
586 //=================================================================================
587 // function : ConstructorsClicked()
588 // purpose : Radio button management
589 //=================================================================================
590 void GroupGUI_GroupDlg::ConstructorsClicked( int constructorId )
595 setInPlaceObj( myInPlaceObj ); // to rebuild myMain2InPlaceIndices
598 //=================================================================================
599 // function : selectAllSubShapes
601 //=================================================================================
602 void GroupGUI_GroupDlg::selectAllSubShapes()
604 if ( CORBA::is_nil( myMainObj ) )
607 GEOM::ListOfLong_var aSubShapes;
608 // if ( !myPlaceCheckBox->isChecked() )
609 if ( subSelectionWay() == ALL_SUBSHAPES )
612 GEOM::GEOM_IShapesOperations_var aShOp = getGeomEngine()->GetIShapesOperations( getStudyId() );
613 aSubShapes = aShOp->SubShapeAllIDs(myMainObj, getShapeType(), false);
615 if ( !aShOp->IsDone() )
620 aSubShapes = new GEOM::ListOfLong();
621 aSubShapes->length( myMain2InPlaceIndices.Extent() );
622 TColStd_DataMapIteratorOfDataMapOfIntegerInteger m2ip( myMain2InPlaceIndices );
623 for ( int i = 0; m2ip.More(); i++, m2ip.Next() )
624 aSubShapes[ i ] = m2ip.Key();
626 bool isBlocked = myIdList->signalsBlocked();
627 myIdList->blockSignals( true );
629 QListBoxItem* anItem;
630 for ( int i = 0, n = aSubShapes->length(); i < n; i++ ) {
631 CORBA::Long anIndex = aSubShapes[i];
635 QString text = QString( "%1" ).arg( anIndex );
636 if ( !myInPlaceObj->_is_nil() )
637 anItem = myIdList->findItem( text, Qt::ExactMatch);
639 anItem = new QListBoxText( text );
640 myIdList->insertItem( anItem );
642 myIdList->setSelected( anItem, true );
645 myIdList->blockSignals( isBlocked );
646 highlightSubShapes();
649 //=================================================================================
652 //=================================================================================
653 void GroupGUI_GroupDlg::add()
655 TColStd_MapOfInteger aMap;
656 for ( int i = 0, n = myIdList->count(); i < n; i++ )
657 aMap.Add( myIdList->item( i )->text().toInt() );
659 TColStd_IndexedMapOfInteger aMapIndex;
661 SALOME_ListIO aSelIOs;
662 SalomeApp_Application* app = myGeomGUI->getApp();
664 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
666 QMap<QString, TColStd_IndexedMapOfInteger> aMap;
667 aSelMgr->selectedSubOwners(aMap);
668 if (aMap.size() == 1)
669 aMapIndex = aMap.begin().data();
672 GEOM::ListOfGO anObjects;
673 // get selected sub-shapes of myInPlaceObj
674 if ( aMapIndex.Extent() > 0 && !myInPlaceObj->_is_nil() )
676 GEOM::GEOM_IShapesOperations_var aShapesOp = getGeomEngine()->GetIShapesOperations( getStudyId() );
678 anObjects.length( aMapIndex.Extent() );
679 for ( int i = 1; i <= aMapIndex.Extent(); i++ )
680 anObjects[ i-1 ] = aShapesOp->GetSubShape( myInPlaceObj, aMapIndex( i ));
685 // try to find out and process the object browser selection or InPlace sub-shapes
686 if ( !aMapIndex.Extent() )
688 if ( anObjects.length() == 0 )
689 GEOMBase::ConvertListOfIOInListOfGO(aSelIOs, anObjects);
691 GEOM::GEOM_ILocalOperations_var aLocOp = getGeomEngine()->GetILocalOperations( getStudyId() );
692 GEOM::GEOM_IShapesOperations_var aShapesOp = getGeomEngine()->GetIShapesOperations( getStudyId() );
694 for (int i = 0; i < anObjects.length(); i++)
696 GEOM::GEOM_Object_var aGeomObj = anObjects[i];
697 GEOM::ListOfGO_var aSubObjects = new GEOM::ListOfGO();
699 if ( GEOMBase::GetShape(aGeomObj, aShape, getShapeType()) )
701 aSubObjects->length(1);
702 aSubObjects[0] = aGeomObj;
704 else if (aGeomObj->GetType() == GEOM_GROUP)
705 aSubObjects = aShapesOp->MakeExplode( aGeomObj, getShapeType(), false);
709 for (int i = 0; i < aSubObjects->length(); i++)
712 if ( GEOMBase::GetShape(aSubObjects[i], aShape, getShapeType()) )
715 anIndex = aLocOp->GetSubShapeIndex( myMainObj, aSubObjects[i] );
717 aMapIndex.Add( anIndex );
723 if ( aMapIndex.Extent() >= 1 ) {
724 QListBoxItem* anItem;
725 bool isBlocked = myIdList->signalsBlocked();
726 myIdList->blockSignals( true );
728 for ( int i = 1, n = aMapIndex.Extent(); i <= n; i++ ) {
729 if ( aMap.Contains( aMapIndex( i ) ) )
732 anItem = new QListBoxText( QString( "%1" ).arg( aMapIndex( i ) ) );
733 myIdList->insertItem( anItem );
734 myIdList->setSelected( anItem, true );
737 myIdList->blockSignals( isBlocked );
743 //=================================================================================
746 //=================================================================================
747 void GroupGUI_GroupDlg::remove()
749 bool isBlocked = myIdList->signalsBlocked();
750 myIdList->blockSignals( true );
752 for ( int i = myIdList->count() - 1; i >= 0; i-- ) {
753 if ( myIdList->isSelected( i ) )
754 myIdList->removeItem( i );
757 myIdList->blockSignals( isBlocked );
759 highlightSubShapes();
763 //=================================================================================
764 // function : getConstructorId()
766 //=================================================================================
767 int GroupGUI_GroupDlg::getConstructorId() const
769 return GroupConstructors->id( GroupConstructors->selected() );
772 //=======================================================================
773 //function : subSelectionWay
775 //=======================================================================
777 int GroupGUI_GroupDlg::subSelectionWay() const
779 return mySelectionWayGroup->id( mySelectionWayGroup->selected() );
782 //=================================================================================
783 // function : getShapeType()
785 //=================================================================================
786 TopAbs_ShapeEnum GroupGUI_GroupDlg::getShapeType() const
788 switch ( getConstructorId() ) {
789 case 0: return TopAbs_VERTEX;
790 case 1: return TopAbs_EDGE;
791 case 2: return TopAbs_FACE;
792 case 3: return TopAbs_SOLID;
793 default: return TopAbs_SHAPE;
797 //=================================================================================
798 // function : setShapeType()
800 //=================================================================================
801 void GroupGUI_GroupDlg::setShapeType( const TopAbs_ShapeEnum theType )
805 case TopAbs_VERTEX: anId = 0; break;
806 case TopAbs_EDGE: anId = 1; break;
807 case TopAbs_FACE: anId = 2; break;
808 case TopAbs_SOLID: anId = 3; break;
810 GroupConstructors->setButton( anId );
814 //=================================================================================
815 // function : activateSelection
816 // purpose : Activate selection in accordance with myEditCurrentArgument
817 //=================================================================================
818 void GroupGUI_GroupDlg::activateSelection()
820 globalSelection( GEOM_ALLSHAPES );
823 if ( !myMainObj->_is_nil() && !myEditCurrentArgument/* && mySelSubBtn->isChecked()*/) {
824 // if ( !myPlaceCheckBox->isChecked() )
825 if ( subSelectionWay() == ALL_SUBSHAPES )
826 localSelection( myMainObj, getShapeType() );
827 else if ( !myInPlaceObj->_is_nil() )
828 localSelection( myInPlaceObj, getShapeType() );
831 SelectionIntoArgument();
834 //=================================================================================
835 // function : updateState
837 //=================================================================================
838 void GroupGUI_GroupDlg::updateState()
842 TColStd_IndexedMapOfInteger aMapIndex;
844 SALOME_ListIO aSelIOs;
845 SalomeApp_Application* app = myGeomGUI->getApp();
847 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
849 QMap<QString, TColStd_IndexedMapOfInteger> aMap;
850 aSelMgr->selectedSubOwners(aMap);
851 if (aMap.size() == 1)
852 aMapIndex = aMap.begin().data();
856 // try to find out and process the object browser selection
857 if ( !aMapIndex.Extent() && !CORBA::is_nil( myMainObj ) ) {
858 GEOM::ListOfGO anObjects;
859 //GEOMBase::ConvertListOfIOInListOfGO(selectedIO(), anObjects);
860 GEOMBase::ConvertListOfIOInListOfGO(aSelIOs, anObjects);
862 GEOM::GEOM_ILocalOperations_var aLocOp = getGeomEngine()->GetILocalOperations( getStudyId() );
863 GEOM::GEOM_IShapesOperations_var aShapesOp = getGeomEngine()->GetIShapesOperations( getStudyId() );
867 for (int i = 0; i < anObjects.length(); i++)
869 GEOM::GEOM_Object_var aGeomObj = anObjects[i];
870 GEOM::ListOfGO_var aSubObjects = new GEOM::ListOfGO();
872 if ( GEOMBase::GetShape(aGeomObj, aShape, getShapeType()) ) {
873 aSubObjects->length(1);
874 aSubObjects[0] = aGeomObj;
876 else if (aGeomObj->GetType() == GEOM_GROUP) {
877 aSubObjects = aShapesOp->MakeExplode( aGeomObj, getShapeType(), false);
884 for (int i = 0; i < aSubObjects->length(); i++)
888 if ( GEOMBase::GetShape(aSubObjects[i], aShape, getShapeType()) )
891 anIndex = aLocOp->GetSubShapeIndex( myMainObj, aSubObjects[i] );
893 aMapIndex.Add( anIndex );
912 isAdd = aMapIndex.Extent() > 0;
914 myAddBtn->setEnabled( !myEditCurrentArgument && !CORBA::is_nil( myMainObj ) && isAdd );
916 for ( int ii = 0, nn = myIdList->count(); !hasSel && ii < nn; ii++ )
917 hasSel = myIdList->isSelected( ii );
918 myRemBtn->setEnabled( hasSel );
919 //mySelSubBtn->setEnabled( !CORBA::is_nil( myMainObj ) );
920 //myPlaceCheckBox->setEnabled( !CORBA::is_nil( myMainObj ) );
921 mySelectionWayGroup->setEnabled( !CORBA::is_nil( myMainObj ) );
922 mySelAllBtn->setEnabled( !CORBA::is_nil( myMainObj ) );
923 // mySelBtn2->setEnabled( myPlaceCheckBox->isChecked() );
924 // myShape2Name->setEnabled( myPlaceCheckBox->isChecked() );
925 mySelBtn2->setEnabled( subSelectionWay() != ALL_SUBSHAPES );
926 myShape2Name->setEnabled( subSelectionWay() != ALL_SUBSHAPES );
927 // if ( !myPlaceCheckBox->isChecked() )
928 if ( subSelectionWay() == ALL_SUBSHAPES )
929 setInPlaceObj( GEOM::GEOM_Object::_nil() );
932 //=================================================================================
933 // function : selectionChanged
935 //=================================================================================
936 void GroupGUI_GroupDlg::selectionChanged()
938 highlightSubShapes();
941 //=================================================================================
942 // function : highlightSubShapes
944 //=================================================================================
945 void GroupGUI_GroupDlg::highlightSubShapes()
947 if ( CORBA::is_nil( myMainObj ) )
950 Standard_Boolean isOk;
953 if ( myInPlaceObj->_is_nil() )
954 objIOR = GEOMBase::GetIORFromObject( myMainObj );
956 objIOR = GEOMBase::GetIORFromObject( myInPlaceObj );
958 Handle(GEOM_AISShape) aSh = GEOMBase::ConvertIORinGEOMAISShape( objIOR, isOk, true );
960 if ( !isOk || aSh.IsNull() )
963 TColStd_MapOfInteger anIds;
967 int ii = 0, nn = myIdList->count();
968 for ( ; ii < nn; ii++ )
969 if ( myIdList->isSelected( ii ) ) {
970 int id = myIdList->item( ii )->text().toInt();
971 // if ( myPlaceCheckBox->isChecked() )
972 if ( subSelectionWay() != ALL_SUBSHAPES )
974 if (myMain2InPlaceIndices.IsBound( id ))
975 id = myMain2InPlaceIndices( id );
977 myIdList->setSelected( ii, false );
984 SalomeApp_Application* app = myGeomGUI->getApp();
985 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
986 aSelMgr->clearSelected();
988 aSelMgr->AddOrRemoveIndex(aSh->getIO(), anIds, false);
995 myAddBtn->setEnabled( true );
996 myRemBtn->setEnabled( true );
1000 //=================================================================================
1001 // function : createOperation
1003 //=================================================================================
1004 GEOM::GEOM_IOperations_ptr GroupGUI_GroupDlg::createOperation()
1006 return getGeomEngine()->GetIGroupOperations( getStudyId() );
1009 #define RETURN_WITH_MSG(a, b) \
1011 theMessage += (b); \
1015 //=================================================================================
1016 // function : isValid()
1017 // purpose : Verify validity of input data
1018 //=================================================================================
1019 bool GroupGUI_GroupDlg::isValid( QString& theMessage )
1021 SalomeApp_Study* study = getStudy();
1023 RETURN_WITH_MSG ( !study->studyDS()->GetProperties()->IsLocked(), tr( "GEOM_STUDY_LOCKED" ) )
1025 if ( myMode == CreateGroup ) {
1026 RETURN_WITH_MSG( !CORBA::is_nil( myMainObj ), tr( "NO_MAIN_OBJ" ) )
1029 RETURN_WITH_MSG( !CORBA::is_nil( myMainObj ), tr( "NO_GROUP" ) )
1032 QString aName (getNewObjectName());
1033 RETURN_WITH_MSG ( !aName.stripWhiteSpace().isEmpty(), tr( "EMPTY_NAME" ) )
1035 RETURN_WITH_MSG ( myIdList->count(), tr( "EMPTY_LIST" ) )
1039 //=================================================================================
1040 // function : execute
1042 //=================================================================================
1043 bool GroupGUI_GroupDlg::execute( ObjectList& objects )
1045 setInPlaceObj( GEOM::GEOM_Object::_nil() );
1047 GEOM::GEOM_IGroupOperations_var anOp = GEOM::GEOM_IGroupOperations::_narrow(getOperation());
1049 GEOM::GEOM_Object_var aGroup;
1050 if (myMode == CreateGroup)
1051 aGroup = anOp->CreateGroup(myMainObj, getShapeType());
1052 else if (myMode == EditGroup)
1055 if (CORBA::is_nil(aGroup) || (myMode == CreateGroup && !anOp->IsDone()))
1058 GEOM::ListOfLong_var aCurrList = anOp->GetObjects(aGroup);
1059 if (!anOp->IsDone())
1062 if (aCurrList->length() > 0)
1064 anOp->DifferenceIDs(aGroup, aCurrList);
1065 if (!anOp->IsDone())
1069 int ii, nn = myIdList->count();
1072 GEOM::ListOfLong_var aNewList = new GEOM::ListOfLong;
1073 aNewList->length(nn);
1074 for (ii = 0; ii < nn; ii++) {
1075 aNewList[ii] = myIdList->item(ii)->text().toInt();
1077 anOp->UnionIDs(aGroup, aNewList);
1078 if (!anOp->IsDone())
1082 SalomeApp_Study* study = getStudy();
1084 char* objIOR = GEOMBase::GetIORFromObject( aGroup );
1085 string IOR( objIOR );
1088 _PTR(SObject) SO ( study->studyDS()->FindObjectIOR( IOR ) );
1090 _PTR(StudyBuilder) aBuilder (study->studyDS()->NewBuilder());
1091 aBuilder->SetName( SO, getNewObjectName() );
1096 objects.push_back( aGroup._retn() );
1101 //================================================================
1102 // Function : getFather
1103 // Purpose : Get father object for object to be added in study
1104 // ( called with addInStudy method )
1105 //================================================================
1106 GEOM::GEOM_Object_ptr GroupGUI_GroupDlg::getFather( GEOM::GEOM_Object_ptr theObj )
1108 GEOM::GEOM_Object_var aFatherObj;
1109 if ( theObj->GetType() == GEOM_GROUP ) {
1110 GEOM::GEOM_IGroupOperations_var anOp = GEOM::GEOM_IGroupOperations::_narrow( getOperation() );
1111 aFatherObj = anOp->GetMainShape( theObj );
1113 return aFatherObj._retn();