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 ); else if (myGrpTypeId == 1) {
enable = !myName->text().stripWhiteSpace().isEmpty() && (myGeomObjects->length() > 0 || isEditMode); 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,18 +681,27 @@ 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;
case 1: aType = SMESH::EDGE; break; case 1: aType = SMESH::EDGE; break;
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);
@ -700,23 +712,22 @@ bool SMESHGUI_GroupDlg::onApply()
myGroup = SMESH::AddGroup(myMesh, aType, myName->text()); myGroup = SMESH::AddGroup(myMesh, aType, myName->text());
myGroup->Add(anIdList.inout()); myGroup->Add(anIdList.inout());
int aColorNumber = myColorSpinBox->value(); int aColorNumber = myColorSpinBox->value();
myGroup->SetColorNumber(aColorNumber); myGroup->SetColorNumber(aColorNumber);
_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 */
myName->setText(""); myName->setText("");
myColorSpinBox->setValue(0); myColorSpinBox->setValue(0);
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;
@ -771,88 +783,85 @@ 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;
} }
_PTR(Study) aStudy = SMESH::GetActiveStudyDocument(); _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
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;
// create a geometry group // create a geometry group
GEOM::GEOM_Gen_var geomGen = SMESH::GetGEOMGen(); GEOM::GEOM_Gen_var geomGen = SMESH::GetGEOMGen();
_PTR(Study) aStudy = SMESH::GetActiveStudyDocument(); _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
if (geomGen->_is_nil() || !aStudy) if (geomGen->_is_nil() || !aStudy)
return false; return false;
GEOM::GEOM_IGroupOperations_var op = GEOM::GEOM_IGroupOperations_var op =
geomGen->GetIGroupOperations(aStudy->StudyId()); geomGen->GetIGroupOperations(aStudy->StudyId());
if (op->_is_nil()) if (op->_is_nil())
return false; return false;
// 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;
{ break;
aGroupType = TopAbs_SHAPE; }
break; }
}
} GEOM::GEOM_Object_var aMeshShape = myMesh->GetShapeToMesh();
GEOM::GEOM_Object_var aGroupVar = op->CreateGroup(aMeshShape, aGroupType);
GEOM::GEOM_Object_var aMeshShape = myMesh->GetShapeToMesh(); op->UnionList(aGroupVar, myGeomObjects);
GEOM::GEOM_Object_var aGroupVar = op->CreateGroup(aMeshShape, aGroupType);
op->UnionList(aGroupVar, myGeomObjects); if (op->IsDone()) {
// publish the GEOM group in study
QString aNewGeomGroupName ("Auto_group_for_");
aNewGeomGroupName += myName->text();
SALOMEDS::SObject_var aNewGroupSO =
geomGen->AddInStudy(aSMESHGen->GetCurrentStudy(), aGroupVar, aNewGeomGroupName, aMeshShape);
}
myGroupOnGeom = myMesh->CreateGroupFromGEOM(aType, myName->text(), aGroupVar);
}
if (op->IsDone()) {
// publish the GEOM group in study
QString aNewGeomGroupName ("Auto_group_for_");
aNewGeomGroupName += myName->text();
SALOMEDS::SObject_var aNewGroupSO =
geomGen->AddInStudy(aSMESHGen->GetCurrentStudy(), aGroupVar, aNewGeomGroupName, aMeshShape);
}
myGroupOnGeom = myMesh->CreateGroupFromGEOM(aType, myName->text(), aGroupVar);
}
int aColorNumber = myColorSpinBox->value(); int aColorNumber = myColorSpinBox->value();
myGroupOnGeom->SetColorNumber(aColorNumber); myGroupOnGeom->SetColorNumber(aColorNumber);
_PTR(SObject) aMeshGroupSO = SMESH::FindSObject(myGroupOnGeom); _PTR(SObject) aMeshGroupSO = SMESH::FindSObject(myGroupOnGeom);
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 */
myName->setText(""); myName->setText("");
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(); myGroupOnGeom->SetColorNumber(aColorNumber);
myGroupOnGeom->SetColorNumber(aColorNumber); }
}
mySMESHGUI->updateObjBrowser(true); mySMESHGUI->updateObjBrowser(true);
mySelectionMgr->clearSelected(); mySelectionMgr->clearSelected();
return true; return true;
} }
return false; return false;
} }
@ -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;
} }
@ -1001,19 +1015,20 @@ void SMESHGUI_GroupDlg::onObjectSelectionChanged()
return; return;
} else if (myCurrentLineEdit == myGeomGroupLine) { } else if (myCurrentLineEdit == myGeomGroupLine) {
myGeomObjects = new GEOM::ListOfGO(); myGeomObjects = new GEOM::ListOfGO();
// The mesh SObject // The mesh SObject
_PTR(SObject) aMeshSO = SMESH::FindSObject(myMesh); _PTR(SObject) aMeshSO = SMESH::FindSObject(myMesh);
if (aNbSel == 0 || !aMeshSO) if (aNbSel == 0 || !aMeshSO)
{ {
myGeomObjects->length(0); myGeomObjects->length(0);
updateButtons();
myIsBusy = false; myIsBusy = false;
return; return;
} }
myGeomObjects->length(aNbSel); myGeomObjects->length(aNbSel);
GEOM::GEOM_Object_var aGeomGroup; GEOM::GEOM_Object_var aGeomGroup;