+ if (mySMESHGUI->isActiveStudyLocked())
+ return false;
+
+ if (myName->text().trimmed().isEmpty())
+ return false;
+
+ SMESH::ElementType aType = SMESH::ALL;
+ switch (myTypeId) {
+ case grpNodeSelection: aType = SMESH::NODE; break;
+ case grp0DSelection: aType = SMESH::ELEM0D; break;
+ case grpBallSelection: aType = SMESH::BALL; break;
+ case grpEdgeSelection: aType = SMESH::EDGE; break;
+ case grpFaceSelection: aType = SMESH::FACE; break;
+ case grpVolumeSelection: aType = SMESH::VOLUME; break;
+ }
+
+ bool anIsOk = false;
+ QStringList anEntryList;
+
+ SMESH::SMESH_GroupBase_var resultGroup;
+ bool isCreation, isConversion = false;
+
+ if (myGrpTypeId == 0) // standalone
+ {
+ if (!mySelectAll->isChecked() && !myElements->count() && myAllowElemsModif->isChecked())
+ return false;
+
+ mySelectionMgr->clearSelected();
+
+ if (myGroup->_is_nil()) { // creation or conversion
+ // check if group on geometry is not null
+ if (!myGroupOnGeom->_is_nil() || !myGroupOnFilter->_is_nil()) {
+ if (myMesh->_is_nil())
+ return false;
+ if ( myGroupOnGeom->_is_nil() )
+ myGroup = myMesh->ConvertToStandalone( myGroupOnFilter );
+ else
+ myGroup = myMesh->ConvertToStandalone( myGroupOnGeom );
+
+ myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
+ myGroupOnFilter = SMESH::SMESH_GroupOnFilter::_nil();
+ isConversion = true;
+ }
+ }
+
+ if (myGroup->_is_nil()) { // creation
+ if (myMesh->_is_nil())
+ return false;
+
+ myGroup = SMESH::AddGroup(myMesh, aType, myName->text());
+
+ resultGroup = SMESH::SMESH_GroupBase::_narrow( myGroup );
+ isCreation = true;
+
+ if ( mySelectAll->isChecked() ) {
+ // select all
+ myGroup->AddFrom(myMesh.in());
+ }
+ else {
+ // select manually
+
+ if ( !myFilter->_is_nil() &&
+ ( myNbChangesOfContents == 1 || !myAllowElemsModif->isChecked()))
+ {
+ myGroup->AddFrom( myFilter );
+ }
+ else
+ {
+ SMESH::long_array_var anIdList = new SMESH::long_array;
+ int i, k = myElements->count();
+ anIdList->length(k);
+ for (i = 0; i < k; i++) {
+ anIdList[i] = myElements->item(i)->text().toInt();
+ }
+ myGroup->Add(anIdList.inout());
+ }
+ }
+
+
+ } else { // edition
+
+ resultGroup = SMESH::SMESH_GroupBase::_narrow( myGroup );
+ isCreation = false;
+
+ if ( mySelectAll->isChecked() ) {
+ // select all
+ myGroup->Clear();
+ myGroup->AddFrom(myMesh.in());
+ }
+ else {
+ QList<int> aAddList;
+
+ int i, total = myElements->count();
+ for (i = 0; i < total; i++) {
+ int anId = myElements->item(i)->text().toInt();
+ int idx = myIdList.indexOf(anId);
+ if ( idx == -1 )
+ aAddList.append(anId);
+ else
+ myIdList.removeAt(idx);
+ }
+ if (!aAddList.empty()) {
+ SMESH::long_array_var anIdList = new SMESH::long_array;
+ int added = aAddList.count();
+ anIdList->length(added);
+ for (i = 0; i < added; i++)
+ anIdList[i] = aAddList[i];
+ myGroup->Add(anIdList.inout());
+ }
+ if (!myIdList.empty()) {
+ SMESH::long_array_var anIdList = new SMESH::long_array;
+ int removed = myIdList.count();
+ anIdList->length(removed);
+ for (i = 0; i < removed; i++)
+ anIdList[i] = myIdList[i];
+ myGroup->Remove(anIdList.inout());
+ }
+ /* init for next operation */
+ myIdList.clear();
+ for (i = 0; i < total; i++) {
+ myIdList.append(myElements->item(i)->text().toInt());
+ }
+ }
+ }
+
+ anIsOk = true;
+ }
+ else if (myGrpTypeId == 1) // on geom object
+ {
+ if (CORBA::is_nil(myGroupOnGeom)) { // creation
+ if (myMesh->_is_nil() || !myGeomObjects->length())
+ return false;
+
+ _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
+
+ if (myGeomObjects->length() == 1) {
+ myGroupOnGeom = myMesh->CreateGroupFromGEOM(aType,
+ myName->text().toLatin1().data(),
+ myGeomObjects[0]);
+ }
+ else {
+ SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
+ if ( aSMESHGen->_is_nil() )
+ return false;
+
+ // create a geometry group
+ GEOM::GEOM_Gen_var geomGen = SMESH::GetGEOMGen();
+ _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
+
+ if (geomGen->_is_nil() || !aStudy)
+ return false;
+
+ GEOM::GEOM_IGroupOperations_wrap op = geomGen->GetIGroupOperations(aStudy->StudyId());
+ if (op->_is_nil())
+ return false;
+
+ // check and add all selected GEOM objects: they must be
+ // a sub-shapes of the main GEOM and must be of one type
+ TopAbs_ShapeEnum aGroupType = TopAbs_SHAPE;
+ for ( int i =0; i < myGeomObjects->length(); i++) {
+ TopAbs_ShapeEnum aSubShapeType = (TopAbs_ShapeEnum)myGeomObjects[i]->GetShapeType();
+ if (i == 0)
+ aGroupType = aSubShapeType;
+ else if (aSubShapeType != aGroupType) {
+ aGroupType = TopAbs_SHAPE;
+ break;
+ }
+ }
+
+ GEOM::GEOM_Object_var aMeshShape = myMesh->GetShapeToMesh();
+ GEOM::GEOM_Object_wrap 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.toLatin1().data(), aMeshShape);
+ }
+
+ myGroupOnGeom = myMesh->CreateGroupFromGEOM(aType,
+ myName->text().toLatin1().data(),
+ aGroupVar);
+ }
+ resultGroup = SMESH::SMESH_GroupBase::_narrow( myGroupOnGeom );
+ isCreation = true;
+
+ }
+ else { // edition
+
+ resultGroup = SMESH::SMESH_GroupBase::_narrow( myGroupOnGeom );
+ isCreation = false;
+ }
+ anIsOk = true;
+ }
+ if (myGrpTypeId == 2) // group on filter
+ {
+ if ( myFilter->_is_nil() ) return false;
+
+ if (CORBA::is_nil(myGroupOnFilter)) { // creation
+ if (myMesh->_is_nil())
+ return false;
+
+ myGroupOnFilter = myMesh->CreateGroupFromFilter(aType,
+ myName->text().toLatin1().data(),
+ myFilter);
+
+ resultGroup = SMESH::SMESH_GroupBase::_narrow( myGroupOnFilter );
+ isCreation = true;
+ }
+ else
+ {
+ myGroupOnFilter->SetFilter( myFilter );
+
+ resultGroup = SMESH::SMESH_GroupBase::_narrow( myGroupOnFilter );
+ isCreation = false;
+ }
+ anIsOk = true;
+ }
+
+ if( anIsOk )
+ {
+ SALOMEDS::Color aColor = getGroupColor();
+ resultGroup->SetColor(aColor);
+
+ _PTR(SObject) aMeshGroupSO = SMESH::FindSObject( resultGroup );
+ if( aMeshGroupSO )
+ anEntryList.append( aMeshGroupSO->GetID().c_str() );
+
+ if ( isCreation )
+ {
+ SMESH::setFileType ( aMeshGroupSO, "COULEURGROUP" );
+
+ /* init for the next operation */
+ setDefaultName();