Fix bug 15418: Crash on Create Group, Apply if Mesh field is empty

This commit is contained in:
jfa 2007-03-30 10:44:34 +00:00
parent 2750957fac
commit 0fcbb05a58

View File

@ -553,15 +553,18 @@ void SMESHGUI_GroupDlg::init (SMESH::SMESH_GroupBase_ptr theGroup)
//================================================================================= //=================================================================================
void SMESHGUI_GroupDlg::updateButtons() void SMESHGUI_GroupDlg::updateButtons()
{ {
bool enable; bool enable = !myName->text().stripWhiteSpace().isEmpty();
if (myGrpTypeId == 0) if (myGrpTypeId == 0) {
enable = !myName->text().stripWhiteSpace().isEmpty() && myElements->count() > 0; enable = enable && myElements->count() > 0;
else if (myGrpTypeId == 1) enable = enable && (!myGroup->_is_nil() || !myMesh->_is_nil());
{
bool isEditMode = !CORBA::is_nil( myGroupOnGeom );
enable = !myName->text().stripWhiteSpace().isEmpty() && (myGeomObjects->length() > 0 || isEditMode);
} }
else if (myGrpTypeId == 1) {
if (CORBA::is_nil(myGroupOnGeom)) { // creation mode
enable = enable && myGeomObjects->length() > 0 && !myMesh->_is_nil();
}
}
QPushButton* aBtn; QPushButton* aBtn;
aBtn = (QPushButton*) child("ok", "QPushButton"); aBtn = (QPushButton*) child("ok", "QPushButton");
if (aBtn) aBtn->setEnabled(enable); if (aBtn) aBtn->setEnabled(enable);
@ -678,11 +681,19 @@ bool SMESHGUI_GroupDlg::onApply()
if (mySMESHGUI->isActiveStudyLocked()) if (mySMESHGUI->isActiveStudyLocked())
return false; return false;
if (myGrpTypeId == 0 && if (myName->text().stripWhiteSpace().isEmpty())
!myName->text().stripWhiteSpace().isEmpty() && return false;
myElements->count() > 0) {
if (myGrpTypeId == 0) { // on mesh elements
if (!myElements->count())
return false;
mySelectionMgr->clearSelected(); mySelectionMgr->clearSelected();
if (myGroup->_is_nil()) {
if (myGroup->_is_nil()) { // creation
if (myMesh->_is_nil())
return false;
SMESH::ElementType aType = SMESH::ALL; SMESH::ElementType aType = SMESH::ALL;
switch (myTypeId) { switch (myTypeId) {
case 0: aType = SMESH::NODE; break; case 0: aType = SMESH::NODE; break;
@ -690,6 +701,7 @@ bool SMESHGUI_GroupDlg::onApply()
case 2: aType = SMESH::FACE; break; case 2: aType = SMESH::FACE; break;
case 3: aType = SMESH::VOLUME; break; case 3: aType = SMESH::VOLUME; break;
} }
SMESH::long_array_var anIdList = new SMESH::long_array; SMESH::long_array_var anIdList = new SMESH::long_array;
int i, k = myElements->count(); int i, k = myElements->count();
anIdList->length(k); anIdList->length(k);
@ -707,7 +719,6 @@ bool SMESHGUI_GroupDlg::onApply()
_PTR(SObject) aMeshGroupSO = SMESH::FindSObject(myGroup); _PTR(SObject) aMeshGroupSO = SMESH::FindSObject(myGroup);
SMESH::setFileName ( aMeshGroupSO, QString::number(myColorSpinBox->value()) ); SMESH::setFileName ( aMeshGroupSO, QString::number(myColorSpinBox->value()) );
SMESH::setFileType ( aMeshGroupSO, "COULEURGROUP" ); SMESH::setFileType ( aMeshGroupSO, "COULEURGROUP" );
/* init for next operation */ /* init for next operation */
@ -716,7 +727,7 @@ bool SMESHGUI_GroupDlg::onApply()
myElements->clear(); myElements->clear();
myGroup = SMESH::SMESH_Group::_nil(); myGroup = SMESH::SMESH_Group::_nil();
} else { } else { // edition
myGroup->SetName(myName->text()); myGroup->SetName(myName->text());
int aColorNumber = myColorSpinBox->value(); int aColorNumber = myColorSpinBox->value();
@ -759,11 +770,12 @@ bool SMESHGUI_GroupDlg::onApply()
SMESH::UpdateView(); // asv: fix of BUG PAL5515 SMESH::UpdateView(); // asv: fix of BUG PAL5515
mySelectionMgr->clearSelected(); mySelectionMgr->clearSelected();
return true; return true;
} else if (myGrpTypeId == 1 && }
!myName->text().stripWhiteSpace().isEmpty() && else if (myGrpTypeId == 1) { // on geom object
(myGeomObjects->length() > 0 || !CORBA::is_nil(myGroupOnGeom))) if (CORBA::is_nil(myGroupOnGeom)) { // creation
{ if (myMesh->_is_nil() || !myGeomObjects->length())
if (myGroupOnGeom->_is_nil()) { return false;
SMESH::ElementType aType = SMESH::ALL; SMESH::ElementType aType = SMESH::ALL;
switch (myTypeId) { switch (myTypeId) {
case 0: aType = SMESH::NODE; break; case 0: aType = SMESH::NODE; break;
@ -776,10 +788,10 @@ bool SMESHGUI_GroupDlg::onApply()
GEOM::GEOM_IGroupOperations_var aGroupOp = GEOM::GEOM_IGroupOperations_var aGroupOp =
SMESH::GetGEOMGen()->GetIGroupOperations(aStudy->StudyId()); SMESH::GetGEOMGen()->GetIGroupOperations(aStudy->StudyId());
if (myGeomObjects->length() == 1) if (myGeomObjects->length() == 1) {
myGroupOnGeom = myMesh->CreateGroupFromGEOM(aType, myName->text(),myGeomObjects[0]); myGroupOnGeom = myMesh->CreateGroupFromGEOM(aType, myName->text(),myGeomObjects[0]);
else }
{ else {
SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen(); SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
if ( aSMESHGen->_is_nil() ) if ( aSMESHGen->_is_nil() )
return false; return false;
@ -799,13 +811,11 @@ bool SMESHGUI_GroupDlg::onApply()
// check and add all selected GEOM objects: they must be // check and add all selected GEOM objects: they must be
// a sub-shapes of the main GEOM and must be of one type // a sub-shapes of the main GEOM and must be of one type
TopAbs_ShapeEnum aGroupType = TopAbs_SHAPE; TopAbs_ShapeEnum aGroupType = TopAbs_SHAPE;
for ( int i =0; i < myGeomObjects->length(); i++) for ( int i =0; i < myGeomObjects->length(); i++) {
{
TopAbs_ShapeEnum aSubShapeType = (TopAbs_ShapeEnum)myGeomObjects[i]->GetShapeType(); TopAbs_ShapeEnum aSubShapeType = (TopAbs_ShapeEnum)myGeomObjects[i]->GetShapeType();
if (i == 0) if (i == 0)
aGroupType = aSubShapeType; aGroupType = aSubShapeType;
else if (aSubShapeType != aGroupType) else if (aSubShapeType != aGroupType) {
{
aGroupType = TopAbs_SHAPE; aGroupType = TopAbs_SHAPE;
break; break;
} }
@ -840,8 +850,7 @@ bool SMESHGUI_GroupDlg::onApply()
myColorSpinBox->setValue(0); myColorSpinBox->setValue(0);
myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil(); myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
} }
else else { // edition
{
myGroupOnGeom->SetName(myName->text()); myGroupOnGeom->SetName(myName->text());
int aColorNumber = myColorSpinBox->value(); int aColorNumber = myColorSpinBox->value();
@ -924,6 +933,9 @@ void SMESHGUI_GroupDlg::onObjectSelectionChanged()
myGeomGroupBtn->setEnabled(false); myGeomGroupBtn->setEnabled(false);
myGeomGroupLine->setEnabled(false); myGeomGroupLine->setEnabled(false);
myGeomGroupLine->setText(""); myGeomGroupLine->setText("");
myGeomObjects = new GEOM::ListOfGO();
myGeomObjects->length(0);
if (myGeomGroupBtn->isOn()) if (myGeomGroupBtn->isOn())
myGeomGroupBtn->setOn(false); myGeomGroupBtn->setOn(false);
if (!myCreate) if (!myCreate)
@ -936,6 +948,7 @@ void SMESHGUI_GroupDlg::onObjectSelectionChanged()
myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil(); myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
myMesh = SMESH::SMESH_Mesh::_nil(); myMesh = SMESH::SMESH_Mesh::_nil();
updateGeomPopup(); updateGeomPopup();
updateButtons();
myIsBusy = false; myIsBusy = false;
return; return;
} }
@ -946,6 +959,7 @@ void SMESHGUI_GroupDlg::onObjectSelectionChanged()
updateGeomPopup(); updateGeomPopup();
if (myMesh->_is_nil()) if (myMesh->_is_nil())
{ {
updateButtons();
myIsBusy = false; myIsBusy = false;
return; return;
} }
@ -1010,6 +1024,7 @@ void SMESHGUI_GroupDlg::onObjectSelectionChanged()
if (aNbSel == 0 || !aMeshSO) if (aNbSel == 0 || !aMeshSO)
{ {
myGeomObjects->length(0); myGeomObjects->length(0);
updateButtons();
myIsBusy = false; myIsBusy = false;
return; return;
} }