+
+ bool ok = false;
+ try {
+ SMESH::Bnd_Dimension mode = myDlg->mode();
+ QString meshName = myDlg->needNewMesh() ? myDlg->getNewMeshName() : QString();
+ QString groupName = myDlg->needGroup() ? myDlg->getGroupName() : QString();
+ bool copyAll = myDlg->copySource();
+
+ QStringList entries;
+ dlg()->selectedObject( SMESHGUI_Make2DFrom3DDlg::MeshOrGroups, entries );
+ SMESH::ListOfIDSources_var groups = new SMESH::ListOfIDSources;
+ QString wrongGroups = "";
+
+ if ( mySrcMesh->_is_nil() ) // get selected groups, find groups of wrong type
+ {
+ int nbGroups = 0;
+ int goodType = ( mode == SMESH::BND_2DFROM3D ? SMESH::VOLUME : SMESH::FACE );
+ groups->length( entries.count() );
+ for ( int i = 0; i < entries.count(); ++i )
+ {
+ _PTR(SObject) sobj =
+ SMESHGUI::activeStudy()->studyDS()->FindObjectID( entries[i].toLatin1().constData() );
+ SMESH::SMESH_IDSource_var grp = SMESH::SObjectToInterface<SMESH::SMESH_IDSource>( sobj );
+ SMESH::array_of_ElementType_var types = grp->GetTypes();
+ if ( types->length() < 1 || types[0] != goodType )
+ {
+ if ( !wrongGroups.isEmpty() )
+ wrongGroups += ", ";
+ wrongGroups += sobj->GetName().c_str();
+ }
+ else
+ {
+ groups[ nbGroups++ ] = grp;
+ }
+ }
+ groups->length( nbGroups );
+ mySrcMesh = groups[0]->GetMesh();
+ }
+
+ if ( !CORBA::is_nil( mySrcMesh ) ) {
+ SMESH::SMESH_MeshEditor_var aMeshEditor = mySrcMesh->GetMeshEditor();
+ SMESH::SMESH_Group_var newGrp;
+ SMESH::SMESH_Mesh_var newMesh;
+ CORBA::Long nbAdded = aMeshEditor->MakeBoundaryElements( mode,
+ groupName.toLatin1().constData(),
+ meshName.toLatin1().constData(),
+ copyAll,
+ groups,
+ newMesh.out(),
+ newGrp.out() );
+ QString msg = tr("NB_ADDED").arg( nbAdded );
+ if ( !wrongGroups.isEmpty() )
+ msg += ".\n" + tr("WRONG_GROUPS").arg( wrongGroups );
+ SUIT_MessageBox::information( myDlg, tr("SMESH_INFORMATION"), msg);
+
+ if ( !newMesh->_is_nil() ) {
+ if( _PTR(SObject) aSObject = SMESH::ObjectToSObject( newMesh ) )
+ theEntryList.append( aSObject->GetID().c_str() );
+#ifdef WITHGENERICOBJ
+ newMesh->UnRegister();
+#endif
+ }
+ if ( !newGrp->_is_nil() ) {
+#ifdef WITHGENERICOBJ
+ newGrp->UnRegister();
+#endif
+ }
+ ok = true;
+
+ for ( int i = 0; i < entries.count(); ++i )
+ if ( SMESH_Actor* actor = SMESH::FindActorByEntry( entries[i].toLatin1().constData() ))
+ SMESH::Update(actor->getIO(),actor->GetVisibility());
+ SMESH::RepaintCurrentView();
+ }
+ }
+ catch ( ... ) {
+ }
+ return ok;
+}
+
+bool SMESHGUI_Make2DFrom3DOp::onApply()
+{
+ if ( isStudyLocked() )
+ return false;
+
+ QString msg;
+ if ( !isValid( msg ) ) {
+ dlg()->show();
+ if ( msg != "" )
+ SUIT_MessageBox::warning( myDlg, tr( "SMESH_ERROR" ), msg );
+ return false;
+ }
+
+ QStringList anEntryList;
+ bool res = false;
+ try {
+ res = compute2DMesh( anEntryList );
+ }
+ catch ( const SALOME::SALOME_Exception& S_ex ) {
+ SalomeApp_Tools::QtCatchCorbaException( S_ex );
+ }
+ catch ( ... ) {
+ }
+
+ if ( res ) {
+ SMESHGUI::Modified();
+ update( UF_ObjBrowser | UF_Model );
+ if( LightApp_Application* anApp =
+ dynamic_cast<LightApp_Application*>( SUIT_Session::session()->activeApplication() ) )
+ anApp->browseObjects( anEntryList, isApplyAndClose() );
+ myDlg->setNewMeshName( SMESH::UniqueName( "Mesh_1" ) );
+ myDlg->setGroupName( SMESH::UniqueName( "Group" ) );
+ }
+ else {
+ SUIT_MessageBox::warning( myDlg, tr( "SMESH_ERROR" ), tr( "SMESH_OPERATION_FAILED" ) );
+ }
+
+ return res;