Back to index

salome-smesh  6.5.0
SMESHGUI_MeshOrderOp.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // This library is free software; you can redistribute it and/or
00004 // modify it under the terms of the GNU Lesser General Public
00005 // License as published by the Free Software Foundation; either
00006 // version 2.1 of the License.
00007 //
00008 // This library is distributed in the hope that it will be useful,
00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011 // Lesser General Public License for more details.
00012 //
00013 // You should have received a copy of the GNU Lesser General Public
00014 // License along with this library; if not, write to the Free Software
00015 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00016 //
00017 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00018 //
00019 
00020 // File   : SMESHGUI_MeshOrderOp.cxx
00021 // Author : Pavel TELKOV, Open CASCADE S.A.S.
00022 //
00023 #include "SMESHGUI_MeshOrderOp.h"
00024 
00025 #include "SMESHGUI.h"
00026 #include "SMESHGUI_Utils.h"
00027 #include "SMESHGUI_MeshUtils.h"
00028 
00029 // SALOME GUI includes
00030 #include <LightApp_SelectionMgr.h>
00031 #include <SALOME_ListIO.hxx>
00032 #include <SUIT_ResourceMgr.h>
00033 #include <SUIT_OverrideCursor.h>
00034 #include <SUIT_MessageBox.h>
00035 #include <SUIT_Desktop.h>
00036 
00037 // SALOME KERNEL includes
00038 #include <SALOMEDS_SObject.hxx>
00039 #include <SALOMEDSClient_SObject.hxx>
00040 
00041 // STL includes
00042 #include <set>
00043 
00044 //================================================================================
00048 //================================================================================
00049 
00050 SMESHGUI_MeshOrderOp::SMESHGUI_MeshOrderOp()
00051   : SMESHGUI_Operation(), myDlg(0), myMgr(0)
00052 {
00053   myDlg = new SMESHGUI_MeshOrderDlg( desktop() );
00054   
00055   myHelpFileName = "constructing_meshes_page.html#mesh_order_anchor";
00056 }
00057 
00058 //================================================================================
00062 //================================================================================
00063 
00064 SMESHGUI_MeshOrderOp::~SMESHGUI_MeshOrderOp()
00065 {
00066 }
00067 
00068 //================================================================================
00072 //================================================================================
00073 
00074 LightApp_Dialog* SMESHGUI_MeshOrderOp::dlg() const
00075 {
00076   return myDlg;
00077 }
00078 
00079 //================================================================================
00083 //================================================================================
00084 
00085 void SMESHGUI_MeshOrderOp::startOperation()
00086 {
00087   SMESHGUI_Operation::startOperation();
00088   if (myMgr)
00089     myDlg->show();
00090 }
00091 
00092 //================================================================================
00096 //================================================================================
00097 
00098 void SMESHGUI_MeshOrderOp::initDialog()
00099 {
00100   if (!myDlg )
00101     return;
00102   
00103   SMESH::SMESH_Mesh_var aMesh = SMESH::SMESH_Mesh::_nil();
00104   // check selection
00105   LightApp_SelectionMgr *Sel = selectionMgr();
00106   SALOME_ListIO selected; Sel->selectedObjects( selected );
00107 
00108   if (selected.Extent() == 1)
00109     aMesh = SMESH::GetMeshByIO(selected.First());
00110   if (aMesh->_is_nil()) {
00111     SUIT_MessageBox::warning(desktop(),
00112                              tr("SMESH_WRN_WARNING"),
00113                              tr("SMESH_WRN_NO_AVAILABLE_DATA"));
00114     onCancel();
00115     return;
00116   }
00117 
00118   myMgr = new SMESHGUI_MeshOrderMgr( myDlg->GetMeshOrderBox() );
00119   myMgr->SetMesh( aMesh );
00120   if ( !myMgr->GetMeshOrder() ) {
00121     SUIT_MessageBox::information(desktop(),
00122                              tr("SMESH_INFORMATION"),
00123                              tr("SMESH_NO_CONCURENT_MESH"));
00124     
00125     onCancel();
00126     return;
00127   }
00128 }
00129 
00130 //================================================================================
00134 //================================================================================
00135 
00136 bool SMESHGUI_MeshOrderOp::onApply()
00137 {
00138   SUIT_OverrideCursor aWaitCursor;
00139   bool res = myMgr ? myMgr->SetMeshOrder() : false;
00140 
00141   if( res )
00142     SMESHGUI::Modified();
00143 
00144   delete myMgr;
00145   myMgr = 0;
00146 
00147   return res;
00148 }
00149 
00150 //================================================================================
00154 //================================================================================
00155 
00156 void SMESHGUI_MeshOrderOp::onCancel()
00157 {
00158   delete myMgr;
00159   myMgr = 0;
00160 
00161   abort();
00162 }
00163 
00164 //================================================================================
00168 //================================================================================
00169 
00170 SMESHGUI_MeshOrderMgr::SMESHGUI_MeshOrderMgr( SMESHGUI_MeshOrderBox* theBox )
00171 : myBox( theBox )
00172 {
00173   myMesh = SMESH::SMESH_Mesh::_nil();
00174 }
00175 
00176 //================================================================================
00180 //================================================================================
00181 
00182 SMESHGUI_MeshOrderMgr::~SMESHGUI_MeshOrderMgr()
00183 {
00184 }
00185 
00186 //================================================================================
00190 //================================================================================
00191 
00192 void SMESHGUI_MeshOrderMgr::SetMesh(SMESH::SMESH_Mesh_var& theMesh)
00193 {
00194   myMesh = SMESH::SMESH_Mesh::_duplicate(theMesh);
00195   _PTR(SObject) aMeshSObj = SMESH::FindSObject(theMesh);
00196   if ( myBox && aMeshSObj )
00197     myBox->setTitle( aMeshSObj->GetName().c_str() );
00198 }  
00199 
00200 //================================================================================
00204 //================================================================================
00205 
00206 bool SMESHGUI_MeshOrderMgr::GetMeshOrder()
00207 {
00208   ListListId   idListList;
00209   return GetMeshOrder(idListList);
00210 }
00211 
00212 //================================================================================
00216 //================================================================================
00217 
00218 bool SMESHGUI_MeshOrderMgr::GetMeshOrder(ListListId& theIdListList)
00219 {
00220   if (!myBox || myMesh->_is_nil())
00221     return false;
00222   myBox->Clear();
00223   SMESH::submesh_array_array_var meshOrder = myMesh->GetMeshOrder();
00224   if ( !meshOrder.operator->() || !meshOrder->length() )
00225     return false;
00226   ListListName nameListList;
00227   for ( int i = 0, n = meshOrder->length(); i < n; i++ )
00228   {
00229     QList<int> idList;
00230     QStringList nameList;
00231     const SMESH::submesh_array& aSMArray = meshOrder[i];
00232     for ( int j = 0, jn = aSMArray.length(); j < jn; j++ )
00233     {
00234       const SMESH::SMESH_subMesh_var subMesh = aSMArray[j];
00235       
00236       _PTR(SObject) aSubMeshSObj = SMESH::FindSObject(subMesh);
00237       if ( !aSubMeshSObj )
00238         continue;
00239 
00240       idList.append(subMesh->GetId() );
00241       nameList.append( QString(aSubMeshSObj->GetName().c_str()) );
00242     }
00243     theIdListList.append(idList);
00244     nameListList.append(nameList);
00245   }
00246   myBox->SetMeshes(nameListList, theIdListList);
00247   return !theIdListList.isEmpty();
00248 }
00249 
00250 //================================================================================
00254 //================================================================================
00255 
00256 bool SMESHGUI_MeshOrderMgr::IsOrderChanged() const
00257 {
00258   return myBox && myBox->IsOrderChanged();
00259 }
00260 
00261 //================================================================================
00265 //================================================================================
00266 
00267 bool SMESHGUI_MeshOrderMgr::SetMeshOrder()
00268 {
00269   return myBox ? SetMeshOrder(myBox->GetMeshIds()) : false;
00270 }
00271 
00272 //================================================================================
00276 //================================================================================
00277 
00278 bool SMESHGUI_MeshOrderMgr::SetMeshOrder( const  ListListId& theListListIds )
00279 {
00280   if (theListListIds.isEmpty() || myMesh->_is_nil())
00281     return false;
00282 
00283   _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
00284   _PTR(SObject) aMeshSObj = SMESH::FindSObject(myMesh);
00285   if ( !aStudy || !aMeshSObj )
00286     return false;
00287 
00288   std::map<int, SMESH::SMESH_subMesh_var> mapOfSubMesh;
00289   for (int i = SMESH::Tag_FirstSubMesh; i <= SMESH::Tag_LastSubMesh; i++) {
00290     _PTR(SObject) aSubmeshRoot;
00291     if ( !aMeshSObj->FindSubObject( i, aSubmeshRoot ) )
00292       continue;
00293     _PTR(ChildIterator) smIter = aStudy->NewChildIterator( aSubmeshRoot );
00294     for ( ; smIter->More(); smIter->Next() ) {
00295       _PTR(SObject) aSmObj = smIter->Value();
00296       SMESH::SMESH_subMesh_var sm =
00297         SMESH::SObjectToInterface<SMESH::SMESH_subMesh>( aSmObj );
00298       mapOfSubMesh[ sm->GetId() ] = SMESH::SMESH_subMesh::_duplicate(sm);
00299     }
00300   }
00301 
00302   // is it enought to set modifid attribute on root mesh objects only?
00303   //  it is seems that modifaction flag will be set on child submeshes 
00304   //  automatically  (see SMESH::ModifiedMesh for details)
00305   SMESH::ModifiedMesh( aMeshSObj, false, false );
00306 
00307   SMESH::submesh_array_array_var meshOrder = new SMESH::submesh_array_array();
00308   meshOrder->length(theListListIds.count() );
00309   ListListId::const_iterator it = theListListIds.constBegin();
00310   for ( int i = 0; it != theListListIds.constEnd(); ++it ) {
00311     const QList<int>& ids = *it;
00312     SMESH::submesh_array_var subMeshList = new SMESH::submesh_array();
00313     subMeshList->length( ids.count() );
00314     QList<int>::const_iterator subIt = ids.constBegin();
00315     for( int j = 0; subIt != ids.constEnd(); ++subIt )
00316       if ( mapOfSubMesh.find( *subIt ) != mapOfSubMesh.end() )
00317         subMeshList[ j++ ] = mapOfSubMesh[ *subIt ];
00318 
00319     meshOrder[ i++ ] = subMeshList;
00320   }
00321   // update object browser
00322   SMESHGUI::GetSMESHGUI()->updateObjBrowser( true, 0 );
00323 
00324   return myMesh->SetMeshOrder(meshOrder);
00325 }