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,14 +198,13 @@ unsigned int GEOM_Client::BufferLength()
// function : GetShape()
// 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);
if (anIndex !=0 ) return S ;
if (anIndex != 0) return S;
/******* in case of a MAIN GEOM::SHAPE ********/
if (aShape->IsMainShape()) {
@ -223,22 +222,22 @@ TopoDS_Shape GEOM_Client::GetShape( GEOM::GEOM_Gen_ptr geom, GEOM::GEOM_Object_p
TopExp::MapShapes(aMainShape, anIndices);
/* Case of only one subshape */
if (list->length() == 1)
{
if (list->length() == 1) {
S = anIndices.FindKey(list[0]);
}
else {
BRep_Builder B;
TopoDS_Compound aCompound;
B.MakeCompound(aCompound);
for(int i=0; i<list->length(); i++) {
for (int i = 0; i < list->length(); i++) {
if (0 < list[i] && list[i] <= anIndices.Extent()) {
TopoDS_Shape aSubShape = anIndices.FindKey(list[i]);
B.Add(aCompound, aSubShape);
}
}
S = aCompound;
}
Bind(IOR, 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);
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();
if(aSeq.IsNull()) return;
if(aSeq->Length() == 1 && aSeq->Value(1) == -1) {

View File

@ -47,8 +47,6 @@
#include <TColStd_MapOfInteger.hxx>
GroupGUI_GroupDlg::GroupGUI_GroupDlg(Mode mode,
QWidget* parent,
const char* name,
@ -59,12 +57,13 @@ GroupGUI_GroupDlg::GroupGUI_GroupDlg(Mode mode,
myMode( mode ),
myBusy( false )
{
QPixmap image0( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_OBJBROWSER_VERTEX" ) ) );
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 image3( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_OBJBROWSER_SOLID" ) ) );
SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
QPixmap iconSelect( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
QPixmap image0 (resMgr->loadPixmap("GEOM", tr("ICON_OBJBROWSER_VERTEX")));
QPixmap image1 (resMgr->loadPixmap("GEOM", tr("ICON_OBJBROWSER_EDGE")));
QPixmap image2 (resMgr->loadPixmap("GEOM", tr("ICON_OBJBROWSER_FACE")));
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" ) );
@ -139,7 +138,7 @@ void GroupGUI_GroupDlg::Init()
myEditCurrentArgument = myMainName;
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() ) {
Standard_Boolean aResult = Standard_False;
@ -169,14 +168,16 @@ void GroupGUI_GroupDlg::Init()
}
}
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( buttonApply, SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
connect( mySelSubBtn, 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( myRemBtn, SIGNAL( clicked() ), this, SLOT( remove() ) );
connect( myIdList, SIGNAL( selectionChanged() ), this, SLOT( selectionChanged() ) );
@ -267,6 +268,10 @@ void GroupGUI_GroupDlg::SetEditCurrentArgument()
myEditCurrentArgument = 0;
activateSelection();
if ( send == mySelAllBtn )
selectAllSubShapes();
else
updateState();
}
@ -279,6 +284,7 @@ void GroupGUI_GroupDlg::SelectionIntoArgument()
{
if ( myEditCurrentArgument ) { // Selection of a main shape is active
myEditCurrentArgument->setText( "" );
myIdList->clear();
if ( IObjectCount() == 1 ) {
Standard_Boolean aResult = Standard_False;
@ -311,19 +317,18 @@ void GroupGUI_GroupDlg::SelectionIntoArgument()
GEOMBase::ConvertIOinGEOMObject( firstIObject(), aResult );
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;
GEOMBase::ConvertListOfIOInListOfGO(selectedIO(), anObjects);
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;
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 )
aMapIndex.Add( anIndex );
@ -331,14 +336,12 @@ void GroupGUI_GroupDlg::SelectionIntoArgument()
}
}
if ( aMapIndex.Extent()>=1 )
{
if (aMapIndex.Extent() >= 1) {
QMap<int, int> aMap;
for ( int i = 0, n = myIdList->count(); i < n; 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 ) ) )
myIdList->setSelected( aMap[aMapIndex( ii )], true );
}
@ -414,19 +417,18 @@ void GroupGUI_GroupDlg::add()
GEOMBase::ConvertIOinGEOMObject( firstIObject(), aResult );
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;
GEOMBase::ConvertListOfIOInListOfGO(selectedIO(), anObjects);
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;
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 )
aMapIndex.Add( anIndex );
@ -434,8 +436,7 @@ void GroupGUI_GroupDlg::add()
}
}
if ( aMapIndex.Extent()>=1 )
{
if ( aMapIndex.Extent() >= 1 ) {
QListBoxItem* anItem;
bool isBlocked = myIdList->signalsBlocked();
myIdList->blockSignals( true );
@ -541,20 +542,19 @@ void GroupGUI_GroupDlg::updateState()
GEOMBase::ConvertIOinGEOMObject( firstIObject(), aResult );
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;
GEOM::ListOfGO anObjects;
GEOMBase::ConvertListOfIOInListOfGO(selectedIO(), anObjects);
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;
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 )
aMapIndex.Add( anIndex );
@ -564,8 +564,7 @@ void GroupGUI_GroupDlg::updateState()
else
isAdd = false;
if ( !isAdd )
{
if ( !isAdd ) {
aMapIndex.Clear();
break;
}
@ -615,7 +614,8 @@ void GroupGUI_GroupDlg::highlightSubShapes()
if ( myIdList->isSelected( ii ) )
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->AddOrRemoveIndex( aSh->getIO(), anIds, false );