Fix for bug 11299: Crash during group creation using incorrect sub-shape IDs.

This commit is contained in:
jfa 2006-02-01 12:45:13 +00:00
parent 9eefb7a14e
commit 77c6e92158
3 changed files with 195 additions and 178 deletions

View File

@ -198,47 +198,46 @@ unsigned int GEOM_Client::BufferLength()
// function : GetShape() // function : GetShape()
// purpose : // purpose :
//======================================================================= //=======================================================================
TopoDS_Shape GEOM_Client::GetShape( GEOM::GEOM_Gen_ptr geom, GEOM::GEOM_Object_ptr aShape )
{
TopoDS_Shape S;
TCollection_AsciiString IOR = geom->GetStringFromIOR(aShape);
Standard_Integer anIndex = Find(IOR, S);
TopoDS_Shape GEOM_Client::GetShape( GEOM::GEOM_Gen_ptr geom, GEOM::GEOM_Object_ptr aShape ) if (anIndex != 0) return S;
{
TopoDS_Shape S;
TCollection_AsciiString IOR = geom->GetStringFromIOR(aShape);
Standard_Integer anIndex = Find(IOR, S);
if (anIndex !=0 ) return S ;
/******* in case of a MAIN GEOM::SHAPE ********/ /******* in case of a MAIN GEOM::SHAPE ********/
if (aShape->IsMainShape()) { if (aShape->IsMainShape()) {
S = Load(geom, aShape); S = Load(geom, aShape);
Bind(IOR, S); Bind(IOR, S);
return S; return S;
} }
/******* in case of SUB GEOM::SHAPE ***********/ /******* in case of SUB GEOM::SHAPE ***********/
// Load and Explore the Main Shape // Load and Explore the Main Shape
TopoDS_Shape aMainShape = GetShape (geom, aShape->GetMainShape()); TopoDS_Shape aMainShape = GetShape (geom, aShape->GetMainShape());
GEOM::ListOfLong_var list = aShape->GetSubShapeIndices(); GEOM::ListOfLong_var list = aShape->GetSubShapeIndices();
TopTools_IndexedMapOfShape anIndices; TopTools_IndexedMapOfShape anIndices;
TopExp::MapShapes(aMainShape, anIndices); TopExp::MapShapes(aMainShape, anIndices);
/* Case of only one subshape */ /* Case of only one subshape */
if (list->length() == 1) if (list->length() == 1) {
{ S = anIndices.FindKey(list[0]);
S = anIndices.FindKey(list[0]); }
}
else { else {
BRep_Builder B; BRep_Builder B;
TopoDS_Compound aCompound; TopoDS_Compound aCompound;
B.MakeCompound(aCompound); B.MakeCompound(aCompound);
for(int i=0; i<list->length(); i++) { for (int i = 0; i < list->length(); i++) {
TopoDS_Shape aSubShape = anIndices.FindKey(list[i]); if (0 < list[i] && list[i] <= anIndices.Extent()) {
B.Add(aCompound, aSubShape); TopoDS_Shape aSubShape = anIndices.FindKey(list[i]);
B.Add(aCompound, aSubShape);
}
} }
S = aCompound; S = aCompound;
} }
Bind(IOR, S); Bind(IOR, S);
return S; return S;
} }

View File

@ -117,7 +117,25 @@ void GEOMImpl_IGroupOperations::AddObject(Handle(GEOM_Object) theGroup, int theS
Handle(GEOM_Function) aFunction = theGroup->GetFunction(1); Handle(GEOM_Function) aFunction = theGroup->GetFunction(1);
if(aFunction.IsNull()) return; if(aFunction.IsNull()) return;
GEOM_ISubShape aSSI(aFunction); GEOM_ISubShape aSSI (aFunction);
// Check sub-shape index validity
TDF_Label aLabel = aSSI.GetMainShape()->GetOwnerEntry();
if (aLabel.IsRoot()) return;
Handle(GEOM_Object) anObj = GEOM_Object::GetObject(aLabel);
if (anObj.IsNull()) return;
TopoDS_Shape aMainShape = anObj->GetValue();
if (aMainShape.IsNull()) return;
TopTools_IndexedMapOfShape aMapOfShapes;
TopExp::MapShapes(aMainShape, aMapOfShapes);
if (theSubShapeID < 1 || aMapOfShapes.Extent() < theSubShapeID) {
SetErrorCode("Invalid sub-shape index: out of range");
return;
}
// Add sub-shape index
Handle(TColStd_HArray1OfInteger) aSeq = aSSI.GetIndices(); Handle(TColStd_HArray1OfInteger) aSeq = aSSI.GetIndices();
if(aSeq.IsNull()) return; if(aSeq.IsNull()) return;
if(aSeq->Length() == 1 && aSeq->Value(1) == -1) { if(aSeq->Length() == 1 && aSeq->Value(1) == -1) {
@ -137,14 +155,14 @@ void GEOMImpl_IGroupOperations::AddObject(Handle(GEOM_Object) theGroup, int theS
aSSI.SetIndices(aNewSeq); aSSI.SetIndices(aNewSeq);
} }
//Make a Python command //Make a Python command
TCollection_AsciiString anOldDescr = aFunction->GetDescription(); TCollection_AsciiString anOldDescr = aFunction->GetDescription();
GEOM::TPythonDump(aFunction) << anOldDescr.ToCString() << "\n\t" GEOM::TPythonDump(aFunction) << anOldDescr.ToCString() << "\n\t"
<< "geompy.AddObject(" << theGroup << ", " << theSubShapeID << ")"; << "geompy.AddObject(" << theGroup << ", " << theSubShapeID << ")";
SetErrorCode(OK); SetErrorCode(OK);
return; return;
} }
//============================================================================= //=============================================================================

View File

@ -47,24 +47,23 @@
#include <TColStd_MapOfInteger.hxx> #include <TColStd_MapOfInteger.hxx>
GroupGUI_GroupDlg::GroupGUI_GroupDlg(Mode mode,
QWidget* parent,
GroupGUI_GroupDlg::GroupGUI_GroupDlg(Mode mode, const char* name,
QWidget* parent, bool modal,
const char* name, WFlags fl)
bool modal,
WFlags fl)
:GEOMBase_Skeleton( parent, "GroupGUI_GroupDlg", false, :GEOMBase_Skeleton( parent, "GroupGUI_GroupDlg", false,
WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu), WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu),
myMode( mode ), myMode( mode ),
myBusy( false ) myBusy( false )
{ {
QPixmap image0( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_OBJBROWSER_VERTEX" ) ) ); SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
QPixmap image1( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_OBJBROWSER_EDGE" ) ) );
QPixmap image2( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_OBJBROWSER_FACE" ) ) ); QPixmap image0 (resMgr->loadPixmap("GEOM", tr("ICON_OBJBROWSER_VERTEX")));
QPixmap image3( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_OBJBROWSER_SOLID" ) ) ); QPixmap image1 (resMgr->loadPixmap("GEOM", tr("ICON_OBJBROWSER_EDGE")));
QPixmap image2 (resMgr->loadPixmap("GEOM", tr("ICON_OBJBROWSER_FACE")));
QPixmap iconSelect( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) ); QPixmap image3 (resMgr->loadPixmap("GEOM", tr("ICON_OBJBROWSER_SOLID")));
QPixmap iconSelect (resMgr->loadPixmap("GEOM", tr("ICON_SELECT")));
setCaption( myMode == CreateGroup ? tr( "CREATE_GROUP_TITLE" ) : tr( "EDIT_GROUP_TITLE" ) ); setCaption( myMode == CreateGroup ? tr( "CREATE_GROUP_TITLE" ) : tr( "EDIT_GROUP_TITLE" ) );
@ -97,13 +96,13 @@ GroupGUI_GroupDlg::GroupGUI_GroupDlg(Mode mode,
myMainName = new QLineEdit( aFrame ); myMainName = new QLineEdit( aFrame );
myMainName->setReadOnly( true ); myMainName->setReadOnly( true );
myMainName->setEnabled( myMode == CreateGroup ); myMainName->setEnabled( myMode == CreateGroup );
mySelSubBtn = new QPushButton( tr( "SELECT_SUB_SHAPES" ), aFrame ); mySelSubBtn = new QPushButton( tr( "SELECT_SUB_SHAPES" ), aFrame );
mySelAllBtn = new QPushButton( tr( "SELECT_ALL" ), aFrame ); mySelAllBtn = new QPushButton( tr( "SELECT_ALL" ), aFrame );
myAddBtn = new QPushButton( tr( "ADD" ), aFrame ); myAddBtn = new QPushButton( tr( "ADD" ), aFrame );
myRemBtn = new QPushButton( tr( "REMOVE" ), aFrame ); myRemBtn = new QPushButton( tr( "REMOVE" ), aFrame );
myIdList = new QListBox( aFrame ); myIdList = new QListBox( aFrame );
myIdList->setSelectionMode( QListBox::Extended ); myIdList->setSelectionMode( QListBox::Extended );
myIdList->setRowMode( QListBox::FitToWidth ); myIdList->setRowMode( QListBox::FitToWidth );
@ -138,14 +137,14 @@ void GroupGUI_GroupDlg::Init()
// Get ready for main shape selection // Get ready for main shape selection
myEditCurrentArgument = myMainName; myEditCurrentArgument = myMainName;
connect( GroupConstructors, SIGNAL( clicked( int ) ), this, SLOT( ConstructorsClicked( int ) ) ); connect( GroupConstructors, SIGNAL( clicked( int ) ), this, SLOT( ConstructorsClicked( int ) ) );
connect( mySelBtn, SIGNAL( clicked() ), this, SLOT(SetEditCurrentArgument())); connect( mySelBtn, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
} }
else if ( myMode == EditGroup && IObjectCount() ) { else if ( myMode == EditGroup && IObjectCount() ) {
Standard_Boolean aResult = Standard_False; Standard_Boolean aResult = Standard_False;
GEOM::GEOM_Object_var anObj = GEOM::GEOM_Object_var anObj =
GEOMBase::ConvertIOinGEOMObject( firstIObject(), aResult ); GEOMBase::ConvertIOinGEOMObject( firstIObject(), aResult );
if ( aResult && !CORBA::is_nil( anObj ) && anObj->GetType() == GEOM_GROUP ) { if ( aResult && !CORBA::is_nil( anObj ) && anObj->GetType() == GEOM_GROUP ) {
myGroup = anObj; myGroup = anObj;
@ -154,29 +153,31 @@ void GroupGUI_GroupDlg::Init()
GEOM::GEOM_IGroupOperations_var anOp = GEOM::GEOM_IGroupOperations::_narrow( getOperation() ); GEOM::GEOM_IGroupOperations_var anOp = GEOM::GEOM_IGroupOperations::_narrow( getOperation() );
myMainObj = anOp->GetMainShape( myGroup ); myMainObj = anOp->GetMainShape( myGroup );
if ( !CORBA::is_nil( myMainObj ) ) if ( !CORBA::is_nil( myMainObj ) )
myMainName->setText( GEOMBase::GetName( myMainObj ) ); myMainName->setText( GEOMBase::GetName( myMainObj ) );
setShapeType( (TopAbs_ShapeEnum)anOp->GetType( myGroup ) ); setShapeType( (TopAbs_ShapeEnum)anOp->GetType( myGroup ) );
GEOM::ListOfLong_var aCurrList = anOp->GetObjects( myGroup ); GEOM::ListOfLong_var aCurrList = anOp->GetObjects( myGroup );
QListBoxItem* anItem; QListBoxItem* anItem;
for ( int i = 0, n = aCurrList->length(); i < n; i++ ) { for ( int i = 0, n = aCurrList->length(); i < n; i++ ) {
anItem = new QListBoxText( QString( "%1" ).arg(aCurrList[i] ) ); anItem = new QListBoxText( QString( "%1" ).arg(aCurrList[i] ) );
myIdList->insertItem( anItem ); myIdList->insertItem( anItem );
} }
myEditCurrentArgument = 0; myEditCurrentArgument = 0;
} }
} }
LightApp_SelectionMgr* aSelMgr =
((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr();
connect( aSelMgr, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
connect( buttonOk , SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) ); connect( buttonOk , SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
connect( buttonApply, SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) ); connect( buttonApply, SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
connect( mySelSubBtn, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) ); connect( mySelSubBtn, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
connect( mySelAllBtn, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) ); connect( mySelAllBtn, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
connect( ((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
connect( mySelAllBtn, SIGNAL( clicked() ), this, SLOT( selectAllSubShapes() ) );
connect( myAddBtn, SIGNAL( clicked() ), this, SLOT( add() ) ); connect( myAddBtn, SIGNAL( clicked() ), this, SLOT( add() ) );
connect( myRemBtn, SIGNAL( clicked() ), this, SLOT( remove() ) ); connect( myRemBtn, SIGNAL( clicked() ), this, SLOT( remove() ) );
connect( myIdList, SIGNAL( selectionChanged() ), this, SLOT( selectionChanged() ) ); connect( myIdList, SIGNAL( selectionChanged() ), this, SLOT( selectionChanged() ) );
@ -228,8 +229,8 @@ void GroupGUI_GroupDlg::ActivateThisDialog()
{ {
GEOMBase_Skeleton::ActivateThisDialog(); GEOMBase_Skeleton::ActivateThisDialog();
connect( ((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(), connect( ((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) ); SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
activateSelection(); activateSelection();
} }
@ -241,7 +242,7 @@ void GroupGUI_GroupDlg::ActivateThisDialog()
void GroupGUI_GroupDlg::LineEditReturnPressed() void GroupGUI_GroupDlg::LineEditReturnPressed()
{ {
QLineEdit* send = ( QLineEdit* )sender(); QLineEdit* send = ( QLineEdit* )sender();
if ( send == myMainName && !myEditCurrentArgument ) { if ( send == myMainName && !myEditCurrentArgument ) {
myEditCurrentArgument = myMainName; myEditCurrentArgument = myMainName;
activateSelection(); activateSelection();
@ -267,7 +268,11 @@ void GroupGUI_GroupDlg::SetEditCurrentArgument()
myEditCurrentArgument = 0; myEditCurrentArgument = 0;
activateSelection(); activateSelection();
updateState();
if ( send == mySelAllBtn )
selectAllSubShapes();
else
updateState();
} }
@ -279,7 +284,8 @@ void GroupGUI_GroupDlg::SelectionIntoArgument()
{ {
if ( myEditCurrentArgument ) { // Selection of a main shape is active if ( myEditCurrentArgument ) { // Selection of a main shape is active
myEditCurrentArgument->setText( "" ); myEditCurrentArgument->setText( "" );
myIdList->clear();
if ( IObjectCount() == 1 ) { if ( IObjectCount() == 1 ) {
Standard_Boolean aResult = Standard_False; Standard_Boolean aResult = Standard_False;
GEOM::GEOM_Object_var anObj = GEOM::GEOM_Object_var anObj =
@ -289,13 +295,13 @@ void GroupGUI_GroupDlg::SelectionIntoArgument()
myMainObj = anObj; myMainObj = anObj;
myEditCurrentArgument->setText( GEOMBase::GetName( anObj ) ); myEditCurrentArgument->setText( GEOMBase::GetName( anObj ) );
updateState(); updateState();
return; return;
} }
} }
myMainObj = GEOM::GEOM_Object::_nil(); myMainObj = GEOM::GEOM_Object::_nil();
} }
else { // an attempt to synchronize list box selection with 3d viewer else { // an attempt to synchronize list box selection with 3d viewer
if ( myBusy ) if ( myBusy )
return; return;
@ -308,40 +314,37 @@ void GroupGUI_GroupDlg::SelectionIntoArgument()
if ( IObjectCount() == 1 ) { if ( IObjectCount() == 1 ) {
Standard_Boolean aResult = Standard_False; Standard_Boolean aResult = Standard_False;
GEOM::GEOM_Object_var anObj = GEOM::GEOM_Object_var anObj =
GEOMBase::ConvertIOinGEOMObject( firstIObject(), aResult ); GEOMBase::ConvertIOinGEOMObject( firstIObject(), aResult );
if ( aResult && !anObj->_is_nil() ) if ( aResult && !anObj->_is_nil() )
((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr()->GetIndexes( firstIObject(), aMapIndex ); ((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->
selectionMgr()->GetIndexes( firstIObject(), aMapIndex );
} }
if ( !aMapIndex.Extent() ) // try to find out and process the object browser selection // try to find out and process the object browser selection
{ if ( !aMapIndex.Extent() ) {
GEOM::ListOfGO anObjects; GEOM::ListOfGO anObjects;
GEOMBase::ConvertListOfIOInListOfGO(selectedIO(), anObjects); GEOMBase::ConvertListOfIOInListOfGO(selectedIO(), anObjects);
GEOM::GEOM_ILocalOperations_var aLocOp = getGeomEngine()->GetILocalOperations( getStudyId() ); GEOM::GEOM_ILocalOperations_var aLocOp = getGeomEngine()->GetILocalOperations( getStudyId() );
for (int i = 0; i < anObjects.length(); i++) for (int i = 0; i < anObjects.length(); i++) {
{ TopoDS_Shape aShape;
TopoDS_Shape aShape; if ( GEOMBase::GetShape(anObjects[i], aShape, getShapeType()) ) {
if ( GEOMBase::GetShape(anObjects[i], aShape, getShapeType()) ) CORBA::Long anIndex = aLocOp->GetSubShapeIndex( myMainObj, anObjects[i] );
{ if ( anIndex >= 0 )
CORBA::Long anIndex = aLocOp->GetSubShapeIndex( myMainObj, anObjects[i] ); aMapIndex.Add( anIndex );
if ( anIndex >= 0 ) }
aMapIndex.Add( anIndex );
}
}
} }
}
if ( aMapIndex.Extent()>=1 )
{ if (aMapIndex.Extent() >= 1) {
QMap<int, int> aMap; QMap<int, int> aMap;
for ( int i = 0, n = myIdList->count(); i < n; i++ ) for ( int i = 0, n = myIdList->count(); i < n; i++ )
aMap.insert( myIdList->item( i )->text().toInt(), i ); aMap.insert( myIdList->item( i )->text().toInt(), i );
for ( int ii = 1, nn = aMapIndex.Extent(); ii <= nn; ii++ ) for ( int ii = 1, nn = aMapIndex.Extent(); ii <= nn; ii++ ) {
{ if ( aMap.contains( aMapIndex( ii ) ) )
if ( aMap.contains( aMapIndex( ii ) ) ) myIdList->setSelected( aMap[aMapIndex( ii )], true );
myIdList->setSelected( aMap[aMapIndex( ii )], true ); }
}
} }
myIdList->blockSignals( isBlocked ); myIdList->blockSignals( isBlocked );
} }
@ -379,7 +382,7 @@ void GroupGUI_GroupDlg::selectAllSubShapes()
bool isBlocked = myIdList->signalsBlocked(); bool isBlocked = myIdList->signalsBlocked();
myIdList->blockSignals( true ); myIdList->blockSignals( true );
myIdList->clear(); myIdList->clear();
QListBoxItem* anItem; QListBoxItem* anItem;
for ( int i = 0, n = aSubShapes->length(); i < n; i++ ) { for ( int i = 0, n = aSubShapes->length(); i < n; i++ ) {
CORBA::Long anIndex = aLocOp->GetSubShapeIndex( myMainObj, aSubShapes[i] ); CORBA::Long anIndex = aLocOp->GetSubShapeIndex( myMainObj, aSubShapes[i] );
@ -405,53 +408,51 @@ void GroupGUI_GroupDlg::add()
TColStd_MapOfInteger aMap; TColStd_MapOfInteger aMap;
for ( int i = 0, n = myIdList->count(); i < n; i++ ) for ( int i = 0, n = myIdList->count(); i < n; i++ )
aMap.Add( myIdList->item( i )->text().toInt() ); aMap.Add( myIdList->item( i )->text().toInt() );
TColStd_IndexedMapOfInteger aMapIndex; TColStd_IndexedMapOfInteger aMapIndex;
if ( IObjectCount() == 1 ) { if ( IObjectCount() == 1 ) {
Standard_Boolean aResult = Standard_False; Standard_Boolean aResult = Standard_False;
GEOM::GEOM_Object_var anObj = GEOM::GEOM_Object_var anObj =
GEOMBase::ConvertIOinGEOMObject( firstIObject(), aResult ); GEOMBase::ConvertIOinGEOMObject( firstIObject(), aResult );
if ( aResult && !anObj->_is_nil() ) if ( aResult && !anObj->_is_nil() )
((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr()->GetIndexes( firstIObject(), aMapIndex ); ((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->
selectionMgr()->GetIndexes( firstIObject(), aMapIndex );
} }
if ( !aMapIndex.Extent() ) // try to find out and process the object browser selection
{
GEOM::ListOfGO anObjects;
GEOMBase::ConvertListOfIOInListOfGO(selectedIO(), anObjects);
GEOM::GEOM_ILocalOperations_var aLocOp = getGeomEngine()->GetILocalOperations( getStudyId() );
for (int i = 0; i < anObjects.length(); i++)
{
TopoDS_Shape aShape;
if ( GEOMBase::GetShape(anObjects[i], aShape, getShapeType()) )
{
CORBA::Long anIndex = aLocOp->GetSubShapeIndex( myMainObj, anObjects[i] );
if ( anIndex >= 0 )
aMapIndex.Add( anIndex );
}
}
}
if ( aMapIndex.Extent()>=1 )
{
QListBoxItem* anItem;
bool isBlocked = myIdList->signalsBlocked();
myIdList->blockSignals( true );
for ( int i = 1, n = aMapIndex.Extent(); i <= n; i++ ) { // try to find out and process the object browser selection
if ( aMap.Contains( aMapIndex( i ) ) ) if ( !aMapIndex.Extent() ) {
continue; GEOM::ListOfGO anObjects;
GEOMBase::ConvertListOfIOInListOfGO(selectedIO(), anObjects);
anItem = new QListBoxText( QString( "%1" ).arg( aMapIndex( i ) ) ); GEOM::GEOM_ILocalOperations_var aLocOp = getGeomEngine()->GetILocalOperations( getStudyId() );
myIdList->insertItem( anItem ); for (int i = 0; i < anObjects.length(); i++) {
myIdList->setSelected( anItem, true ); TopoDS_Shape aShape;
if ( GEOMBase::GetShape(anObjects[i], aShape, getShapeType()) ) {
CORBA::Long anIndex = aLocOp->GetSubShapeIndex( myMainObj, anObjects[i] );
if ( anIndex >= 0 )
aMapIndex.Add( anIndex );
} }
myIdList->blockSignals( isBlocked );
} }
}
if ( aMapIndex.Extent() >= 1 ) {
QListBoxItem* anItem;
bool isBlocked = myIdList->signalsBlocked();
myIdList->blockSignals( true );
for ( int i = 1, n = aMapIndex.Extent(); i <= n; i++ ) {
if ( aMap.Contains( aMapIndex( i ) ) )
continue;
anItem = new QListBoxText( QString( "%1" ).arg( aMapIndex( i ) ) );
myIdList->insertItem( anItem );
myIdList->setSelected( anItem, true );
}
myIdList->blockSignals( isBlocked );
}
updateState(); updateState();
} }
@ -462,7 +463,7 @@ void GroupGUI_GroupDlg::add()
void GroupGUI_GroupDlg::remove() void GroupGUI_GroupDlg::remove()
{ {
for ( int i = myIdList->count() - 1; i >= 0; i-- ) { for ( int i = myIdList->count() - 1; i >= 0; i-- ) {
if ( myIdList->isSelected( i ) ) if ( myIdList->isSelected( i ) )
myIdList->removeItem( i ); myIdList->removeItem( i );
} }
updateState(); updateState();
@ -505,7 +506,7 @@ void GroupGUI_GroupDlg::setShapeType( const TopAbs_ShapeEnum theType )
case TopAbs_EDGE: anId = 1; break; case TopAbs_EDGE: anId = 1; break;
case TopAbs_FACE: anId = 2; break; case TopAbs_FACE: anId = 2; break;
case TopAbs_SOLID: anId = 3; break; case TopAbs_SOLID: anId = 3; break;
} }
GroupConstructors->setButton( anId ); GroupConstructors->setButton( anId );
} }
@ -534,46 +535,44 @@ void GroupGUI_GroupDlg::updateState()
bool isAdd = false; bool isAdd = false;
TColStd_IndexedMapOfInteger aMapIndex; TColStd_IndexedMapOfInteger aMapIndex;
if ( IObjectCount() == 1 ) { if ( IObjectCount() == 1 ) {
Standard_Boolean aResult = Standard_False; Standard_Boolean aResult = Standard_False;
GEOM::GEOM_Object_var anObj = GEOM::GEOM_Object_var anObj =
GEOMBase::ConvertIOinGEOMObject( firstIObject(), aResult ); GEOMBase::ConvertIOinGEOMObject( firstIObject(), aResult );
if ( aResult && !anObj->_is_nil() ) if ( aResult && !anObj->_is_nil() )
((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr()->GetIndexes( firstIObject(), aMapIndex ); ((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->
selectionMgr()->GetIndexes( firstIObject(), aMapIndex );
} }
if ( !aMapIndex.Extent() && !CORBA::is_nil( myMainObj ) ) // try to find out and process the object browser selection // try to find out and process the object browser selection
{ if ( !aMapIndex.Extent() && !CORBA::is_nil( myMainObj ) ) {
isAdd = true; isAdd = true;
GEOM::ListOfGO anObjects; GEOM::ListOfGO anObjects;
GEOMBase::ConvertListOfIOInListOfGO(selectedIO(), anObjects); GEOMBase::ConvertListOfIOInListOfGO(selectedIO(), anObjects);
GEOM::GEOM_ILocalOperations_var aLocOp = getGeomEngine()->GetILocalOperations( getStudyId() ); GEOM::GEOM_ILocalOperations_var aLocOp = getGeomEngine()->GetILocalOperations( getStudyId() );
for (int i = 0; i < anObjects.length(); i++) for (int i = 0; i < anObjects.length(); i++) {
{ TopoDS_Shape aShape;
TopoDS_Shape aShape; if ( GEOMBase::GetShape(anObjects[i], aShape, getShapeType()) ) {
if ( GEOMBase::GetShape(anObjects[i], aShape, getShapeType()) ) CORBA::Long anIndex = aLocOp->GetSubShapeIndex( myMainObj, anObjects[i] );
{ if ( anIndex >= 0 )
CORBA::Long anIndex = aLocOp->GetSubShapeIndex( myMainObj, anObjects[i] ); aMapIndex.Add( anIndex );
if ( anIndex >= 0 ) else
aMapIndex.Add( anIndex ); isAdd = false;
else }
isAdd = false; else
} isAdd = false;
else
isAdd = false; if ( !isAdd ) {
aMapIndex.Clear();
if ( !isAdd ) break;
{ }
aMapIndex.Clear();
break;
}
}
} }
}
isAdd = aMapIndex.Extent() > 0; isAdd = aMapIndex.Extent() > 0;
myAddBtn->setEnabled( !myEditCurrentArgument && !CORBA::is_nil( myMainObj ) && isAdd ); myAddBtn->setEnabled( !myEditCurrentArgument && !CORBA::is_nil( myMainObj ) && isAdd );
bool hasSel = false; bool hasSel = false;
for ( int ii = 0, nn = myIdList->count(); !hasSel && ii < nn; ii++ ) for ( int ii = 0, nn = myIdList->count(); !hasSel && ii < nn; ii++ )
@ -602,7 +601,7 @@ void GroupGUI_GroupDlg::highlightSubShapes()
return; return;
Standard_Boolean isOk; Standard_Boolean isOk;
Handle(GEOM_AISShape) aSh = Handle(GEOM_AISShape) aSh =
GEOMBase::ConvertIORinGEOMAISShape( GEOMBase::GetIORFromObject( myMainObj ), isOk, true ); GEOMBase::ConvertIORinGEOMAISShape( GEOMBase::GetIORFromObject( myMainObj ), isOk, true );
if ( !isOk || aSh.IsNull() ) if ( !isOk || aSh.IsNull() )
return; return;
@ -613,9 +612,10 @@ void GroupGUI_GroupDlg::highlightSubShapes()
for ( int ii = 0, nn = myIdList->count(); ii < nn; ii++ ) for ( int ii = 0, nn = myIdList->count(); ii < nn; ii++ )
if ( myIdList->isSelected( ii ) ) if ( myIdList->isSelected( ii ) )
anIds.Add( myIdList->item( ii )->text().toInt() ); anIds.Add( myIdList->item( ii )->text().toInt() );
LightApp_SelectionMgr* aSelMgr = ((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(); LightApp_SelectionMgr* aSelMgr =
((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr();
aSelMgr->clearSelected(); aSelMgr->clearSelected();
aSelMgr->AddOrRemoveIndex( aSh->getIO(), anIds, false ); aSelMgr->AddOrRemoveIndex( aSh->getIO(), anIds, false );
@ -670,9 +670,9 @@ bool GroupGUI_GroupDlg::isValid( QString& theMessage )
bool GroupGUI_GroupDlg::execute( ObjectList& objects ) bool GroupGUI_GroupDlg::execute( ObjectList& objects )
{ {
GEOM::GEOM_IGroupOperations_var anOp = GEOM::GEOM_IGroupOperations::_narrow( getOperation() ); GEOM::GEOM_IGroupOperations_var anOp = GEOM::GEOM_IGroupOperations::_narrow( getOperation() );
GEOM::GEOM_Object_var aGroup; GEOM::GEOM_Object_var aGroup;
if ( myMode == CreateGroup ) if ( myMode == CreateGroup )
aGroup = anOp->CreateGroup( myMainObj, getShapeType() ); aGroup = anOp->CreateGroup( myMainObj, getShapeType() );
else if ( myMode == EditGroup ) else if ( myMode == EditGroup )
aGroup = myGroup; aGroup = myGroup;
@ -691,7 +691,7 @@ bool GroupGUI_GroupDlg::execute( ObjectList& objects )
} }
for ( int ii = 0, nn = myIdList->count(); ii < nn; ii++ ) { for ( int ii = 0, nn = myIdList->count(); ii < nn; ii++ ) {
anOp->AddObject( aGroup, myIdList->item( ii )->text().toInt() ); anOp->AddObject( aGroup, myIdList->item( ii )->text().toInt() );
if ( !anOp->IsDone() ) if ( !anOp->IsDone() )
return false; return false;
} }
@ -701,9 +701,9 @@ bool GroupGUI_GroupDlg::execute( ObjectList& objects )
string IOR = GEOMBase::GetIORFromObject( aGroup ); string IOR = GEOMBase::GetIORFromObject( aGroup );
if ( IOR != "" ) { if ( IOR != "" ) {
_PTR(SObject) SO ( study->studyDS()->FindObjectIOR( IOR ) ); _PTR(SObject) SO ( study->studyDS()->FindObjectIOR( IOR ) );
if ( SO ) { if ( SO ) {
_PTR(StudyBuilder) aBuilder (study->studyDS()->NewBuilder()); _PTR(StudyBuilder) aBuilder (study->studyDS()->NewBuilder());
aBuilder->SetName( SO, getNewObjectName() ); aBuilder->SetName( SO, getNewObjectName() );
} }
} }
} }