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"
43 #include <qlineedit.h>
46 #include <TColStd_IndexedMapOfInteger.hxx>
47 #include <TColStd_MapOfInteger.hxx>
48 #include <TColStd_DataMapIteratorOfDataMapOfIntegerInteger.hxx>
50 enum { ALL_SUBSHAPES = 0, GET_IN_PLACE, SUBSHAPES_OF_SHAPE2 };
52 GroupGUI_GroupDlg::GroupGUI_GroupDlg(Mode mode, GeometryGUI* theGeometryGUI, QWidget* parent)
53 :GEOMBase_Skeleton( theGeometryGUI, parent, "GroupGUI_GroupDlg", false,
54 WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu),
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 setCaption( myMode == CreateGroup ? tr( "CREATE_GROUP_TITLE" ) : tr( "EDIT_GROUP_TITLE" ) );
68 // Shape type button group
69 GroupConstructors->setEnabled( myMode == CreateGroup );
70 GroupConstructors->setTitle( tr( "SHAPE_TYPE" ) );
71 RadioButton1->setPixmap( image0 );
72 RadioButton2->setPixmap( image1 );
73 RadioButton3->setPixmap( image2 );
74 RadioButton4->setPixmap( image3 );
78 GroupBoxName->setTitle( tr( "GROUP_NAME" ) );
80 // Main shape and sub-shapes
81 QGroupBox* GroupMedium = new QGroupBox( 1, Qt::Vertical, tr( "MAIN_SUB_SHAPES" ), this );
82 GroupMedium->setInsideMargin( 10 );
83 Layout1->addWidget( GroupMedium, 2, 0 );
85 QWidget* aFrame = new QWidget( GroupMedium );
86 QGridLayout* aMedLayout = new QGridLayout( aFrame, 6, 4, 0, 6 );
88 QLabel* aMainLabel = new QLabel( tr( "MAIN_SHAPE" ), aFrame );
90 mySelBtn = new QPushButton( aFrame );
91 mySelBtn->setPixmap( iconSelect );
92 mySelBtn->setEnabled( myMode == CreateGroup );
94 myMainName = new QLineEdit( aFrame );
95 myMainName->setReadOnly( true );
96 myMainName->setEnabled( myMode == CreateGroup );
98 QLabel* aSecondLabel = new QLabel( tr( "SECOND_SHAPE" ), aFrame );
100 mySelBtn2 = new QPushButton( aFrame );
101 mySelBtn2->setPixmap( iconSelect );
102 mySelBtn2->setEnabled( false );
104 myShape2Name = new QLineEdit( aFrame );
105 myShape2Name->setReadOnly( true );
106 myShape2Name->setEnabled( false );
108 //mySelSubBtn = new QRadioButton ( tr( "SELECT_SUB_SHAPES" ), aFrame );
109 //myPlaceCheckBox = new QCheckBox ( tr( "GET_IN_PLACE" ), aFrame );
110 mySelectionWayGroup = new QButtonGroup(1, Qt::Horizontal, tr("SELECT_SUB_SHAPES"),aFrame);
111 mySelectionWayGroup->setExclusive(true);
112 QRadioButton* allSubs = new QRadioButton(tr("ALL_SUBSHAPES") ,mySelectionWayGroup);
113 QRadioButton* inPlaceSubs = new QRadioButton(tr("GET_IN_PLACE") ,mySelectionWayGroup);
114 QRadioButton* shape2Subs = new QRadioButton(tr("SUBSHAPES_OF_SHAPE2"),mySelectionWayGroup);
115 mySelectionWayGroup->insert(allSubs , ALL_SUBSHAPES);
116 mySelectionWayGroup->insert(inPlaceSubs, GET_IN_PLACE);
117 mySelectionWayGroup->insert(shape2Subs , SUBSHAPES_OF_SHAPE2);
118 mySelectionWayGroup->setButton( ALL_SUBSHAPES );
120 mySelAllBtn = new QPushButton( tr( "SELECT_ALL" ), aFrame );
121 myAddBtn = new QPushButton( tr( "ADD" ), aFrame );
122 myRemBtn = new QPushButton( tr( "REMOVE" ), aFrame );
123 myIdList = new QListBox( aFrame );
125 myIdList->setSelectionMode( QListBox::Extended );
126 myIdList->setRowMode( QListBox::FitToWidth );
128 aMedLayout->addWidget( aMainLabel, 0, 0 );
129 aMedLayout->addWidget( mySelBtn, 0, 1 );
130 aMedLayout->addMultiCellWidget( myMainName, 0, 0, 2, 3 );
132 aMedLayout->addWidget( aSecondLabel, 1, 0 );
133 aMedLayout->addWidget( mySelBtn2, 1, 1 );
134 aMedLayout->addMultiCellWidget( myShape2Name, 1, 1, 2, 3 );
137 //aMedLayout->addMultiCellWidget( mySelSubBtn, 2, 2, 0, 1 );
138 //aMedLayout->addWidget( myPlaceCheckBox, 2, 2 );
139 //aMedLayout->addMultiCellWidget( myPlaceCheckBox, 2, 2, 0, 2 );
140 aMedLayout->addMultiCellWidget( mySelectionWayGroup, 2, 4, 0, 2 );
141 aMedLayout->addWidget( mySelAllBtn, 2, 3 );
142 aMedLayout->addWidget( myAddBtn, 3, 3 );
143 aMedLayout->addWidget( myRemBtn, 4, 3 );
144 aMedLayout->addMultiCellWidget( myIdList, 5, 5, 0, 3 );
145 aMedLayout->setRowStretch( 5, 1 );
148 setHelpFileName("work_with_groups_page.html");
153 GroupGUI_GroupDlg::~GroupGUI_GroupDlg()
158 //=================================================================================
161 //=================================================================================
162 void GroupGUI_GroupDlg::Init()
164 // san -- TODO: clear selected sub-shapes...
165 //mySelSubBtn->setChecked( true );
166 if ( myMode == CreateGroup ) {
167 initName( tr( "GROUP_PREFIX" ) );
169 // Get ready for main shape selection
170 myEditCurrentArgument = myMainName;
172 connect( GroupConstructors, SIGNAL( clicked( int ) ), this, SLOT( ConstructorsClicked( int ) ) );
173 connect( mySelBtn, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
174 connect( mySelBtn2, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
176 else if ( myMode == EditGroup && IObjectCount() ) {
177 Standard_Boolean aResult = Standard_False;
178 GEOM::GEOM_Object_var anObj =
179 GEOMBase::ConvertIOinGEOMObject( firstIObject(), aResult );
181 if ( aResult && !CORBA::is_nil( anObj ) && anObj->GetType() == GEOM_GROUP ) {
184 ResultName->setText( GEOMBase::GetName( myGroup ) );
186 GEOM::GEOM_IGroupOperations_var anOp = GEOM::GEOM_IGroupOperations::_narrow( getOperation() );
187 myMainObj = anOp->GetMainShape( myGroup );
188 if ( !CORBA::is_nil( myMainObj ) )
189 myMainName->setText( GEOMBase::GetName( myMainObj ) );
191 setShapeType( (TopAbs_ShapeEnum)anOp->GetType( myGroup ) );
193 GEOM::ListOfLong_var aCurrList = anOp->GetObjects( myGroup );
194 QListBoxItem* anItem;
195 for ( int i = 0, n = aCurrList->length(); i < n; i++ ) {
196 anItem = new QListBoxText( QString( "%1" ).arg(aCurrList[i] ) );
197 myIdList->insertItem( anItem );
200 myEditCurrentArgument = 0;
202 connect( mySelBtn2, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
205 LightApp_SelectionMgr* aSelMgr =
206 ((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr();
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( mySelSubBtn, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
214 //connect( myPlaceCheckBox, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
215 connect( mySelectionWayGroup,SIGNAL(clicked(int)),this,SLOT(SetEditCurrentArgument()));
216 connect( mySelAllBtn, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
217 connect( myAddBtn, SIGNAL( clicked() ), this, SLOT( add() ) );
218 connect( myRemBtn, SIGNAL( clicked() ), this, SLOT( remove() ) );
219 connect( myIdList, SIGNAL( selectionChanged() ), this, SLOT( selectionChanged() ) );
221 setInPlaceObj( GEOM::GEOM_Object::_nil() );
223 myBusy = true; // just activate but do not select in the list
226 // activate subshapes selection if Main Shape is Selected
227 // if ( !CORBA::is_nil( myMainObj ) ) {
228 // myEditCurrentArgument = 0;
229 // activateSelection();
234 //=================================================================================
235 // function : enterEvent()
237 //=================================================================================
238 void GroupGUI_GroupDlg::enterEvent( QEvent* e )
240 if ( !buttonCancel->isEnabled() )
241 this->ActivateThisDialog();
244 //=======================================================================
245 //function : closeEvent
246 //purpose : remove temporary geom object
247 //=======================================================================
249 void GroupGUI_GroupDlg::closeEvent(QCloseEvent* e)
251 setInPlaceObj( GEOM::GEOM_Object::_nil() );
253 GEOMBase_Skeleton::closeEvent(e);
256 //=================================================================================
257 // function : ClickOnOk()
259 //=================================================================================
260 void GroupGUI_GroupDlg::ClickOnOk()
262 if ( ClickOnApply() )
266 //=================================================================================
267 // function : ClickOnApply()
269 //=================================================================================
270 bool GroupGUI_GroupDlg::ClickOnApply()
272 if ( !onAccept( myMode == CreateGroup, true ) )
275 if ( myMode == CreateGroup )
285 //=================================================================================
286 // function : ActivateThisDialog()
288 //=================================================================================
289 void GroupGUI_GroupDlg::ActivateThisDialog()
291 GEOMBase_Skeleton::ActivateThisDialog();
293 connect( ((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
294 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
299 //=================================================================================
300 // function : LineEditReturnPressed()
302 //=================================================================================
303 void GroupGUI_GroupDlg::LineEditReturnPressed()
305 QLineEdit* send = ( QLineEdit* )sender();
307 if ( send == myMainName && !myEditCurrentArgument ) {
308 myEditCurrentArgument = myMainName;
312 GEOMBase_Skeleton::LineEditReturnPressed();
317 //=================================================================================
318 // function : SetEditCurrentArgument()
320 //=================================================================================
321 void GroupGUI_GroupDlg::SetEditCurrentArgument()
323 QPushButton* send = (QPushButton*)sender();
325 if ( send == mySelBtn ) {
326 myEditCurrentArgument = myMainName;
327 myShape2Name->setText( "" );
329 else if ( /*(QRadioButton*)sender() == mySelSubBtn ||*/ send == mySelAllBtn )
330 myEditCurrentArgument = 0;
331 else if ( send == mySelBtn2 || sender() == mySelectionWayGroup ) {
332 setInPlaceObj( GEOM::GEOM_Object::_nil() );
333 //if ( myPlaceCheckBox->isChecked() )
334 myShape2Name->setText( "" );
335 if ( subSelectionWay() != ALL_SUBSHAPES )
337 myEditCurrentArgument = myShape2Name;
340 //myEditCurrentArgument = myMainName;
341 myEditCurrentArgument = 0;
347 if ( send == mySelAllBtn ) {
348 // myShape2Name->setText( "" );
349 // myPlaceCheckBox->setChecked( false );
350 // mySelBtn2->setEnabled( false );
351 // myShape2Name->setEnabled( false );
352 selectAllSubShapes();
358 //=================================================================================
359 // function : onGetInPlace()
361 //=================================================================================
362 void GroupGUI_GroupDlg::onGetInPlace()
364 setInPlaceObj( GEOM::GEOM_Object::_nil() );
365 myEditCurrentArgument->setText( "" );
367 bool isBlocked = myIdList->signalsBlocked();
368 myIdList->blockSignals( true );
369 myIdList->clearSelection();
370 myIdList->blockSignals( isBlocked );
372 if (IObjectCount() != 1 )
375 Standard_Boolean aResult = Standard_False;
376 GEOM::GEOM_Object_var anObj =
377 GEOMBase::ConvertIOinGEOMObject( firstIObject(), aResult );
378 if ( aResult && !anObj->_is_nil() && GEOMBase::IsShape( anObj ) ) {
379 if ( !anObj->_is_equivalent(myMainObj) && !anObj->_is_equivalent( myGroup )) {
380 SUIT_OverrideCursor wc;
381 myEditCurrentArgument->setText( GEOMBase::GetName( anObj ) );
382 GEOM::GEOM_IShapesOperations_var aShapesOp =
383 getGeomEngine()->GetIShapesOperations( getStudyId() );
384 if ( subSelectionWay() == GET_IN_PLACE ) {
385 GEOM::GEOM_Object_var aGetInPlaceObj = aShapesOp->GetInPlace(myMainObj, anObj);
386 setInPlaceObj( aGetInPlaceObj );
389 setInPlaceObj( anObj );
391 myEditCurrentArgument = 0;
392 //myBusy = true; // just activate but do not select in the list
399 //=======================================================================
400 //function : setInPlaceObj
401 //purpose : temporarily add an object to study and remove old InPlaceObj
402 //=======================================================================
404 void GroupGUI_GroupDlg::setInPlaceObj( GEOM::GEOM_Object_var theObj )
406 if ( ! myInPlaceObj->_is_equivalent( theObj ) )
408 const char* tmpName = "__InPlaceObj__";
409 // remove old InPlaceObj
410 if ( !myInPlaceObj->_is_nil() ) {
411 if (_PTR(SObject) SO = getStudy()->studyDS()->FindObject( tmpName )) {
412 getStudy()->studyDS()->NewBuilder()->RemoveObjectWithChildren( SO );
413 getGeomEngine()->RemoveObject(myInPlaceObj);
416 // publish InPlaceObj to enable localSelection(InPlaceObj)
417 if ( !theObj->_is_nil() && subSelectionWay() == GET_IN_PLACE ) {
418 SALOMEDS::Study_var aStudyDS = GeometryGUI::ClientStudyToStudy(getStudy()->studyDS());
419 SALOMEDS::SObject_var aSO =
420 getGeomEngine()->AddInStudy(aStudyDS, theObj, tmpName, myMainObj);
422 myInPlaceObj = theObj;
424 // build map of indices
425 myMain2InPlaceIndices.Clear();
426 if ( !myInPlaceObj->_is_nil() ) {
427 GEOM::GEOM_IShapesOperations_var aShapesOp = getGeomEngine()->GetIShapesOperations( getStudyId() );
428 GEOM::GEOM_ILocalOperations_var aLocOp = getGeomEngine()->GetILocalOperations( getStudyId() );
430 GEOM::ListOfGO_var aSubObjects = aShapesOp->MakeExplode( myInPlaceObj, getShapeType(), false);
431 for (int i = 0; i < aSubObjects->length(); i++)
433 CORBA::Long aMainIndex = aLocOp->GetSubShapeIndex( myMainObj, aSubObjects[i] );
434 CORBA::Long aPlaceIndex = aLocOp->GetSubShapeIndex( myInPlaceObj, aSubObjects[i] );
435 if ( aMainIndex >= 0 && aPlaceIndex > 0)
436 myMain2InPlaceIndices.Bind( aMainIndex, aPlaceIndex );
441 //=================================================================================
442 // function : SelectionIntoArgument()
443 // purpose : Called when selection has changed
444 //=================================================================================
445 void GroupGUI_GroupDlg::SelectionIntoArgument()
447 // if (myPlaceCheckBox->isChecked() && myEditCurrentArgument == myShape2Name )
448 if (subSelectionWay() != ALL_SUBSHAPES && myEditCurrentArgument == myShape2Name ) {
453 if ( myEditCurrentArgument == myMainName) { // Selection of a main shape is active
454 myEditCurrentArgument->setText( "" );
457 if ( IObjectCount() == 1 ) {
458 Standard_Boolean aResult = Standard_False;
459 GEOM::GEOM_Object_var anObj =
460 GEOMBase::ConvertIOinGEOMObject( firstIObject(), aResult );
462 if ( aResult && !anObj->_is_nil() && GEOMBase::IsShape( anObj ) ) {
464 myEditCurrentArgument->setText( GEOMBase::GetName( anObj ) );
465 // activate subshapes selection by default
466 myEditCurrentArgument = 0;
473 myMainObj = GEOM::GEOM_Object::_nil();
475 else { // an attempt to synchronize list box selection with 3d viewer
480 bool isBlocked = myIdList->signalsBlocked();
481 myIdList->blockSignals( true );
482 myIdList->clearSelection();
484 TColStd_IndexedMapOfInteger aMapIndex;
486 SALOME_ListIO aSelIOs;
487 SalomeApp_Application* app = myGeomGUI->getApp();
489 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
491 QMap<QString, TColStd_IndexedMapOfInteger> aMap;
492 aSelMgr->selectedSubOwners(aMap);
493 if (aMap.size() == 1)
494 aMapIndex = aMap.begin().data();
497 bool subselected = aMapIndex.Extent();
499 // convert inPlace indices to main indices
500 //if ( subselected && myPlaceCheckBox->isChecked() )
501 if ( subselected && subSelectionWay() != ALL_SUBSHAPES )
503 TColStd_IndexedMapOfInteger aMapIndex2;
505 TColStd_DataMapIteratorOfDataMapOfIntegerInteger m2ip( myMain2InPlaceIndices );
506 for ( ; m2ip.More(); m2ip.Next() ) {
507 int inPlaceId = m2ip.Value();
508 if ( aMapIndex.Contains( inPlaceId )) {
509 aMapIndex2.Add( m2ip.Key() );
512 aMapIndex = aMapIndex2;
515 // try to find out and process the object browser selection
516 if ( !subselected ) {
517 globalSelection( GEOM_ALLSHAPES );
519 GEOM::ListOfGO anObjects;
520 GEOMBase::ConvertListOfIOInListOfGO(selectedIO(), anObjects);
522 GEOM::GEOM_ILocalOperations_var aLocOp = getGeomEngine()->GetILocalOperations( getStudyId() );
523 GEOM::GEOM_IShapesOperations_var aShapesOp = getGeomEngine()->GetIShapesOperations( getStudyId() );
525 for (int i = 0; i < anObjects.length(); i++)
527 GEOM::GEOM_Object_var aGeomObj = anObjects[i];
528 GEOM::ListOfGO_var aSubObjects = new GEOM::ListOfGO();
530 if ( GEOMBase::GetShape(aGeomObj, aShape, getShapeType()) )
532 aSubObjects->length(1);
533 aSubObjects[0] = aGeomObj;
535 else if (aGeomObj->GetType() == GEOM_GROUP)
536 aSubObjects = aShapesOp->MakeExplode( aGeomObj, getShapeType(), false);
540 for (int i = 0; i < aSubObjects->length(); i++)
543 if ( GEOMBase::GetShape(aSubObjects[i], aShape, getShapeType()) )
546 anIndex = aLocOp->GetSubShapeIndex( myMainObj, aSubObjects[i] );
547 if ( anIndex >= 0 ) {
548 //if ( myPlaceCheckBox->isChecked() && ! myMain2InPlaceIndices.IsBound( anIndex ))
549 if ( subSelectionWay() != ALL_SUBSHAPES &&
550 ! myMain2InPlaceIndices.IsBound( anIndex ))
552 aMapIndex.Add( anIndex );
557 if ( !myMainObj->_is_nil() /*&& mySelSubBtn->isChecked()*/)
558 if ( subSelectionWay() == ALL_SUBSHAPES )
559 localSelection( myMainObj, getShapeType() );
560 else if ( !myInPlaceObj->_is_nil() )
561 localSelection( myInPlaceObj, getShapeType() );
564 if (aMapIndex.Extent() >= 1) {
566 for ( int i = 0, n = myIdList->count(); i < n; i++ )
567 aMap.insert( myIdList->item( i )->text().toInt(), i );
569 for ( int ii = 1, nn = aMapIndex.Extent(); ii <= nn; ii++ ) {
570 if ( aMap.contains( aMapIndex( ii ) ) )
571 myIdList->setSelected( aMap[aMapIndex( ii )], true );
574 myIdList->blockSignals( isBlocked );
580 //=================================================================================
581 // function : ConstructorsClicked()
582 // purpose : Radio button management
583 //=================================================================================
584 void GroupGUI_GroupDlg::ConstructorsClicked( int constructorId )
589 setInPlaceObj( myInPlaceObj ); // to rebuild myMain2InPlaceIndices
592 //=================================================================================
593 // function : selectAllSubShapes
595 //=================================================================================
596 void GroupGUI_GroupDlg::selectAllSubShapes()
598 if ( CORBA::is_nil( myMainObj ) )
601 GEOM::ListOfLong_var aSubShapes;
602 // if ( !myPlaceCheckBox->isChecked() )
603 if ( subSelectionWay() == ALL_SUBSHAPES )
606 GEOM::GEOM_IShapesOperations_var aShOp = getGeomEngine()->GetIShapesOperations( getStudyId() );
607 aSubShapes = aShOp->SubShapeAllIDs(myMainObj, getShapeType(), false);
609 if ( !aShOp->IsDone() )
614 aSubShapes = new GEOM::ListOfLong();
615 aSubShapes->length( myMain2InPlaceIndices.Extent() );
616 TColStd_DataMapIteratorOfDataMapOfIntegerInteger m2ip( myMain2InPlaceIndices );
617 for ( int i = 0; m2ip.More(); i++, m2ip.Next() )
618 aSubShapes[ i ] = m2ip.Key();
620 bool isBlocked = myIdList->signalsBlocked();
621 myIdList->blockSignals( true );
623 QListBoxItem* anItem;
624 for ( int i = 0, n = aSubShapes->length(); i < n; i++ ) {
625 CORBA::Long anIndex = aSubShapes[i];
629 QString text = QString( "%1" ).arg( anIndex );
630 if ( !myInPlaceObj->_is_nil() )
631 anItem = myIdList->findItem( text, Qt::ExactMatch);
633 anItem = new QListBoxText( text );
634 myIdList->insertItem( anItem );
636 myIdList->setSelected( anItem, true );
639 myIdList->blockSignals( isBlocked );
640 highlightSubShapes();
643 //=================================================================================
646 //=================================================================================
647 void GroupGUI_GroupDlg::add()
649 TColStd_MapOfInteger aMap;
650 for ( int i = 0, n = myIdList->count(); i < n; i++ )
651 aMap.Add( myIdList->item( i )->text().toInt() );
653 TColStd_IndexedMapOfInteger aMapIndex;
655 SALOME_ListIO aSelIOs;
656 SalomeApp_Application* app = myGeomGUI->getApp();
658 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
660 QMap<QString, TColStd_IndexedMapOfInteger> aMap;
661 aSelMgr->selectedSubOwners(aMap);
662 if (aMap.size() == 1)
663 aMapIndex = aMap.begin().data();
666 GEOM::ListOfGO anObjects;
667 // get selected sub-shapes of myInPlaceObj
668 if ( aMapIndex.Extent() > 0 && !myInPlaceObj->_is_nil() )
670 GEOM::GEOM_IShapesOperations_var aShapesOp = getGeomEngine()->GetIShapesOperations( getStudyId() );
672 anObjects.length( aMapIndex.Extent() );
673 for ( int i = 1; i <= aMapIndex.Extent(); i++ )
674 anObjects[ i-1 ] = aShapesOp->GetSubShape( myInPlaceObj, aMapIndex( i ));
679 // try to find out and process the object browser selection or InPlace sub-shapes
680 if ( !aMapIndex.Extent() )
682 if ( anObjects.length() == 0 )
683 GEOMBase::ConvertListOfIOInListOfGO(aSelIOs, anObjects);
685 GEOM::GEOM_ILocalOperations_var aLocOp = getGeomEngine()->GetILocalOperations( getStudyId() );
686 GEOM::GEOM_IShapesOperations_var aShapesOp = getGeomEngine()->GetIShapesOperations( getStudyId() );
688 for (int i = 0; i < anObjects.length(); i++)
690 GEOM::GEOM_Object_var aGeomObj = anObjects[i];
691 GEOM::ListOfGO_var aSubObjects = new GEOM::ListOfGO();
693 if ( GEOMBase::GetShape(aGeomObj, aShape, getShapeType()) )
695 aSubObjects->length(1);
696 aSubObjects[0] = aGeomObj;
698 else if (aGeomObj->GetType() == GEOM_GROUP)
699 aSubObjects = aShapesOp->MakeExplode( aGeomObj, getShapeType(), false);
703 for (int i = 0; i < aSubObjects->length(); i++)
706 if ( GEOMBase::GetShape(aSubObjects[i], aShape, getShapeType()) )
709 anIndex = aLocOp->GetSubShapeIndex( myMainObj, aSubObjects[i] );
711 aMapIndex.Add( anIndex );
717 if ( aMapIndex.Extent() >= 1 ) {
718 QListBoxItem* anItem;
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 anItem = new QListBoxText( QString( "%1" ).arg( aMapIndex( i ) ) );
727 myIdList->insertItem( anItem );
728 myIdList->setSelected( anItem, true );
731 myIdList->blockSignals( isBlocked );
737 //=================================================================================
740 //=================================================================================
741 void GroupGUI_GroupDlg::remove()
743 bool isBlocked = myIdList->signalsBlocked();
744 myIdList->blockSignals( true );
746 for ( int i = myIdList->count() - 1; i >= 0; i-- ) {
747 if ( myIdList->isSelected( i ) )
748 myIdList->removeItem( i );
751 myIdList->blockSignals( isBlocked );
753 highlightSubShapes();
757 //=================================================================================
758 // function : getConstructorId()
760 //=================================================================================
761 int GroupGUI_GroupDlg::getConstructorId() const
763 return GroupConstructors->id( GroupConstructors->selected() );
766 //=======================================================================
767 //function : subSelectionWay
769 //=======================================================================
771 int GroupGUI_GroupDlg::subSelectionWay() const
773 return mySelectionWayGroup->id( mySelectionWayGroup->selected() );
776 //=================================================================================
777 // function : getShapeType()
779 //=================================================================================
780 TopAbs_ShapeEnum GroupGUI_GroupDlg::getShapeType() const
782 switch ( getConstructorId() ) {
783 case 0: return TopAbs_VERTEX;
784 case 1: return TopAbs_EDGE;
785 case 2: return TopAbs_FACE;
786 case 3: return TopAbs_SOLID;
787 default: return TopAbs_SHAPE;
791 //=================================================================================
792 // function : setShapeType()
794 //=================================================================================
795 void GroupGUI_GroupDlg::setShapeType( const TopAbs_ShapeEnum theType )
799 case TopAbs_VERTEX: anId = 0; break;
800 case TopAbs_EDGE: anId = 1; break;
801 case TopAbs_FACE: anId = 2; break;
802 case TopAbs_SOLID: anId = 3; break;
804 GroupConstructors->setButton( anId );
808 //=================================================================================
809 // function : activateSelection
810 // purpose : Activate selection in accordance with myEditCurrentArgument
811 //=================================================================================
812 void GroupGUI_GroupDlg::activateSelection()
814 globalSelection( GEOM_ALLSHAPES );
817 if ( !myMainObj->_is_nil() && !myEditCurrentArgument/* && mySelSubBtn->isChecked()*/) {
818 // if ( !myPlaceCheckBox->isChecked() )
819 if ( subSelectionWay() == ALL_SUBSHAPES )
820 localSelection( myMainObj, getShapeType() );
821 else if ( !myInPlaceObj->_is_nil() )
822 localSelection( myInPlaceObj, getShapeType() );
825 SelectionIntoArgument();
828 //=================================================================================
829 // function : updateState
831 //=================================================================================
832 void GroupGUI_GroupDlg::updateState()
836 TColStd_IndexedMapOfInteger aMapIndex;
838 SALOME_ListIO aSelIOs;
839 SalomeApp_Application* app = myGeomGUI->getApp();
841 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
843 QMap<QString, TColStd_IndexedMapOfInteger> aMap;
844 aSelMgr->selectedSubOwners(aMap);
845 if (aMap.size() == 1)
846 aMapIndex = aMap.begin().data();
850 // try to find out and process the object browser selection
851 if ( !aMapIndex.Extent() && !CORBA::is_nil( myMainObj ) ) {
852 GEOM::ListOfGO anObjects;
853 //GEOMBase::ConvertListOfIOInListOfGO(selectedIO(), anObjects);
854 GEOMBase::ConvertListOfIOInListOfGO(aSelIOs, anObjects);
856 GEOM::GEOM_ILocalOperations_var aLocOp = getGeomEngine()->GetILocalOperations( getStudyId() );
857 GEOM::GEOM_IShapesOperations_var aShapesOp = getGeomEngine()->GetIShapesOperations( getStudyId() );
861 for (int i = 0; i < anObjects.length(); i++)
863 GEOM::GEOM_Object_var aGeomObj = anObjects[i];
864 GEOM::ListOfGO_var aSubObjects = new GEOM::ListOfGO();
866 if ( GEOMBase::GetShape(aGeomObj, aShape, getShapeType()) ) {
867 aSubObjects->length(1);
868 aSubObjects[0] = aGeomObj;
870 else if (aGeomObj->GetType() == GEOM_GROUP) {
871 aSubObjects = aShapesOp->MakeExplode( aGeomObj, getShapeType(), false);
878 for (int i = 0; i < aSubObjects->length(); i++)
882 if ( GEOMBase::GetShape(aSubObjects[i], aShape, getShapeType()) )
885 anIndex = aLocOp->GetSubShapeIndex( myMainObj, aSubObjects[i] );
887 aMapIndex.Add( anIndex );
906 isAdd = aMapIndex.Extent() > 0;
908 myAddBtn->setEnabled( !myEditCurrentArgument && !CORBA::is_nil( myMainObj ) && isAdd );
910 for ( int ii = 0, nn = myIdList->count(); !hasSel && ii < nn; ii++ )
911 hasSel = myIdList->isSelected( ii );
912 myRemBtn->setEnabled( hasSel );
913 //mySelSubBtn->setEnabled( !CORBA::is_nil( myMainObj ) );
914 //myPlaceCheckBox->setEnabled( !CORBA::is_nil( myMainObj ) );
915 mySelectionWayGroup->setEnabled( !CORBA::is_nil( myMainObj ) );
916 mySelAllBtn->setEnabled( !CORBA::is_nil( myMainObj ) );
917 // mySelBtn2->setEnabled( myPlaceCheckBox->isChecked() );
918 // myShape2Name->setEnabled( myPlaceCheckBox->isChecked() );
919 mySelBtn2->setEnabled( subSelectionWay() != ALL_SUBSHAPES );
920 myShape2Name->setEnabled( subSelectionWay() != ALL_SUBSHAPES );
921 // if ( !myPlaceCheckBox->isChecked() )
922 if ( subSelectionWay() == ALL_SUBSHAPES )
923 setInPlaceObj( GEOM::GEOM_Object::_nil() );
926 //=================================================================================
927 // function : selectionChanged
929 //=================================================================================
930 void GroupGUI_GroupDlg::selectionChanged()
932 highlightSubShapes();
935 //=================================================================================
936 // function : highlightSubShapes
938 //=================================================================================
939 void GroupGUI_GroupDlg::highlightSubShapes()
941 if ( CORBA::is_nil( myMainObj ) )
944 Standard_Boolean isOk;
947 if ( myInPlaceObj->_is_nil() )
948 objIOR = GEOMBase::GetIORFromObject( myMainObj );
950 objIOR = GEOMBase::GetIORFromObject( myInPlaceObj );
952 Handle(GEOM_AISShape) aSh = GEOMBase::ConvertIORinGEOMAISShape( objIOR, isOk, true );
954 if ( !isOk || aSh.IsNull() )
957 TColStd_MapOfInteger anIds;
961 int ii = 0, nn = myIdList->count();
962 for ( ; ii < nn; ii++ )
963 if ( myIdList->isSelected( ii ) ) {
964 int id = myIdList->item( ii )->text().toInt();
965 // if ( myPlaceCheckBox->isChecked() )
966 if ( subSelectionWay() != ALL_SUBSHAPES )
968 if (myMain2InPlaceIndices.IsBound( id ))
969 id = myMain2InPlaceIndices( id );
971 myIdList->setSelected( ii, false );
978 SalomeApp_Application* app = myGeomGUI->getApp();
979 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
980 aSelMgr->clearSelected();
982 aSelMgr->AddOrRemoveIndex(aSh->getIO(), anIds, false);
989 myAddBtn->setEnabled( true );
990 myRemBtn->setEnabled( true );
994 //=================================================================================
995 // function : createOperation
997 //=================================================================================
998 GEOM::GEOM_IOperations_ptr GroupGUI_GroupDlg::createOperation()
1000 return getGeomEngine()->GetIGroupOperations( getStudyId() );
1003 #define RETURN_WITH_MSG(a, b) \
1005 theMessage += (b); \
1009 //=================================================================================
1010 // function : isValid()
1011 // purpose : Verify validity of input data
1012 //=================================================================================
1013 bool GroupGUI_GroupDlg::isValid( QString& theMessage )
1015 SalomeApp_Study* study = getStudy();
1017 RETURN_WITH_MSG ( !study->studyDS()->GetProperties()->IsLocked(), tr( "GEOM_STUDY_LOCKED" ) )
1019 if ( myMode == CreateGroup ) {
1020 RETURN_WITH_MSG( !CORBA::is_nil( myMainObj ), tr( "NO_MAIN_OBJ" ) )
1023 RETURN_WITH_MSG( !CORBA::is_nil( myMainObj ), tr( "NO_GROUP" ) )
1026 QString aName (getNewObjectName());
1027 RETURN_WITH_MSG ( !aName.stripWhiteSpace().isEmpty(), tr( "EMPTY_NAME" ) )
1029 RETURN_WITH_MSG ( myIdList->count(), tr( "EMPTY_LIST" ) )
1033 //=================================================================================
1034 // function : execute
1036 //=================================================================================
1037 bool GroupGUI_GroupDlg::execute( ObjectList& objects )
1039 setInPlaceObj( GEOM::GEOM_Object::_nil() );
1041 GEOM::GEOM_IGroupOperations_var anOp = GEOM::GEOM_IGroupOperations::_narrow(getOperation());
1043 GEOM::GEOM_Object_var aGroup;
1044 if (myMode == CreateGroup)
1045 aGroup = anOp->CreateGroup(myMainObj, getShapeType());
1046 else if (myMode == EditGroup)
1049 if (CORBA::is_nil(aGroup) || (myMode == CreateGroup && !anOp->IsDone()))
1052 GEOM::ListOfLong_var aCurrList = anOp->GetObjects(aGroup);
1053 if (!anOp->IsDone())
1056 if (aCurrList->length() > 0)
1058 anOp->DifferenceIDs(aGroup, aCurrList);
1059 if (!anOp->IsDone())
1063 int ii, nn = myIdList->count();
1066 GEOM::ListOfLong_var aNewList = new GEOM::ListOfLong;
1067 aNewList->length(nn);
1068 for (ii = 0; ii < nn; ii++) {
1069 aNewList[ii] = myIdList->item(ii)->text().toInt();
1071 anOp->UnionIDs(aGroup, aNewList);
1072 if (!anOp->IsDone())
1076 SalomeApp_Study* study = getStudy();
1078 char* objIOR = GEOMBase::GetIORFromObject( aGroup );
1079 string IOR( objIOR );
1082 _PTR(SObject) SO ( study->studyDS()->FindObjectIOR( IOR ) );
1084 _PTR(StudyBuilder) aBuilder (study->studyDS()->NewBuilder());
1085 aBuilder->SetName( SO, getNewObjectName() );
1090 objects.push_back( aGroup._retn() );
1095 //================================================================
1096 // Function : getFather
1097 // Purpose : Get father object for object to be added in study
1098 // ( called with addInStudy method )
1099 //================================================================
1100 GEOM::GEOM_Object_ptr GroupGUI_GroupDlg::getFather( GEOM::GEOM_Object_ptr theObj )
1102 GEOM::GEOM_Object_var aFatherObj;
1103 if ( theObj->GetType() == GEOM_GROUP ) {
1104 GEOM::GEOM_IGroupOperations_var anOp = GEOM::GEOM_IGroupOperations::_narrow( getOperation() );
1105 aFatherObj = anOp->GetMainShape( theObj );
1107 return aFatherObj._retn();