1 // Copyright (C) 2007-2014 CEA/DEN, EDF R&D, OPEN CASCADE
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 // File : SMESHGUI_MeshOrderOp.cxx
21 // Author : Pavel TELKOV, Open CASCADE S.A.S.
23 #include "SMESHGUI_MeshOrderOp.h"
26 #include "SMESHGUI_Utils.h"
27 #include "SMESHGUI_MeshUtils.h"
29 // SALOME GUI includes
30 #include <LightApp_SelectionMgr.h>
31 #include <SALOME_ListIO.hxx>
32 #include <SUIT_ResourceMgr.h>
33 #include <SUIT_OverrideCursor.h>
34 #include <SUIT_MessageBox.h>
35 #include <SUIT_Desktop.h>
37 // SALOME KERNEL includes
38 #include <SALOMEDS_SObject.hxx>
39 #include <SALOMEDSClient_SObject.hxx>
44 //================================================================================
48 //================================================================================
50 SMESHGUI_MeshOrderOp::SMESHGUI_MeshOrderOp()
51 : SMESHGUI_Operation(), myDlg(0), myMgr(0)
53 myDlg = new SMESHGUI_MeshOrderDlg( desktop() );
55 myHelpFileName = "constructing_meshes_page.html#mesh_order_anchor";
58 //================================================================================
62 //================================================================================
64 SMESHGUI_MeshOrderOp::~SMESHGUI_MeshOrderOp()
68 //================================================================================
70 * \brief Return operation dialog
72 //================================================================================
74 LightApp_Dialog* SMESHGUI_MeshOrderOp::dlg() const
79 //================================================================================
81 * \brief perform it's intention action: compute 2D mesh on 3D
83 //================================================================================
85 void SMESHGUI_MeshOrderOp::startOperation()
87 SMESHGUI_Operation::startOperation();
92 //================================================================================
94 * \brief Init dialog and mesh order box
96 //================================================================================
98 void SMESHGUI_MeshOrderOp::initDialog()
103 SMESH::SMESH_Mesh_var aMesh = SMESH::SMESH_Mesh::_nil();
105 LightApp_SelectionMgr *Sel = selectionMgr();
106 SALOME_ListIO selected; Sel->selectedObjects( selected );
108 if (selected.Extent() == 1)
109 aMesh = SMESH::GetMeshByIO(selected.First());
110 if (aMesh->_is_nil()) {
111 SUIT_MessageBox::warning(desktop(),
112 tr("SMESH_WRN_WARNING"),
113 tr("SMESH_WRN_NO_AVAILABLE_DATA"));
118 myMgr = new SMESHGUI_MeshOrderMgr( myDlg->GetMeshOrderBox() );
119 myMgr->SetMesh( aMesh );
120 if ( !myMgr->GetMeshOrder() ) {
121 SUIT_MessageBox::information(desktop(),
122 tr("SMESH_INFORMATION"),
123 tr("SMESH_NO_CONCURENT_MESH"));
130 //================================================================================
132 * \brief Apply changes
134 //================================================================================
136 bool SMESHGUI_MeshOrderOp::onApply()
138 SUIT_OverrideCursor aWaitCursor;
139 bool res = myMgr ? myMgr->SetMeshOrder() : false;
142 SMESHGUI::Modified();
150 //================================================================================
152 * \brief Apply changes
154 //================================================================================
156 void SMESHGUI_MeshOrderOp::onCancel()
164 //================================================================================
168 //================================================================================
170 SMESHGUI_MeshOrderMgr::SMESHGUI_MeshOrderMgr( SMESHGUI_MeshOrderBox* theBox )
173 myMesh = SMESH::SMESH_Mesh::_nil();
176 //================================================================================
180 //================================================================================
182 SMESHGUI_MeshOrderMgr::~SMESHGUI_MeshOrderMgr()
186 //================================================================================
188 * \brief Set root mesh object
190 //================================================================================
192 void SMESHGUI_MeshOrderMgr::SetMesh(SMESH::SMESH_Mesh_var& theMesh)
194 myMesh = SMESH::SMESH_Mesh::_duplicate(theMesh);
195 _PTR(SObject) aMeshSObj = SMESH::FindSObject(theMesh);
196 if ( myBox && aMeshSObj )
197 myBox->setTitle( aMeshSObj->GetName().c_str() );
200 //================================================================================
202 * \brief Check for concurents between submesh objects
204 //================================================================================
206 bool SMESHGUI_MeshOrderMgr::GetMeshOrder()
208 ListListId idListList;
209 return GetMeshOrder(idListList);
212 //================================================================================
214 * \brief Check for concurents between submesh objects
216 //================================================================================
218 bool SMESHGUI_MeshOrderMgr::GetMeshOrder(ListListId& theIdListList)
220 if (!myBox || myMesh->_is_nil())
223 SMESH::submesh_array_array_var meshOrder = myMesh->GetMeshOrder();
224 if ( !meshOrder.operator->() || !meshOrder->length() )
226 ListListName nameListList;
227 for ( int i = 0, n = meshOrder->length(); i < n; i++ )
230 QStringList nameList;
231 const SMESH::submesh_array& aSMArray = meshOrder[i];
232 for ( int j = 0, jn = aSMArray.length(); j < jn; j++ )
234 const SMESH::SMESH_subMesh_var subMesh = aSMArray[j];
236 _PTR(SObject) aSubMeshSObj = SMESH::FindSObject(subMesh);
240 idList.append(subMesh->GetId() );
241 nameList.append( QString(aSubMeshSObj->GetName().c_str()) );
243 theIdListList.append(idList);
244 nameListList.append(nameList);
246 myBox->SetMeshes(nameListList, theIdListList);
247 return !theIdListList.isEmpty();
250 //================================================================================
252 * \brief Returns status is order changed by user
254 //================================================================================
256 bool SMESHGUI_MeshOrderMgr::IsOrderChanged() const
258 return myBox && myBox->IsOrderChanged();
261 //================================================================================
263 * \brief Store submesh priority order
265 //================================================================================
267 bool SMESHGUI_MeshOrderMgr::SetMeshOrder()
269 return myBox ? SetMeshOrder(myBox->GetMeshIds()) : false;
272 //================================================================================
274 * \brief Store submesh priority order
276 //================================================================================
278 bool SMESHGUI_MeshOrderMgr::SetMeshOrder( const ListListId& theListListIds )
280 if (theListListIds.isEmpty() || myMesh->_is_nil())
283 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
284 _PTR(SObject) aMeshSObj = SMESH::FindSObject(myMesh);
285 if ( !aStudy || !aMeshSObj )
288 std::map<int, SMESH::SMESH_subMesh_var> mapOfSubMesh;
289 for (int i = SMESH::Tag_FirstSubMesh; i <= SMESH::Tag_LastSubMesh; i++) {
290 _PTR(SObject) aSubmeshRoot;
291 if ( !aMeshSObj->FindSubObject( i, aSubmeshRoot ) )
293 _PTR(ChildIterator) smIter = aStudy->NewChildIterator( aSubmeshRoot );
294 for ( ; smIter->More(); smIter->Next() ) {
295 _PTR(SObject) aSmObj = smIter->Value();
296 SMESH::SMESH_subMesh_var sm =
297 SMESH::SObjectToInterface<SMESH::SMESH_subMesh>( aSmObj );
298 if ( !sm->_is_nil() )
299 mapOfSubMesh[ sm->GetId() ] = SMESH::SMESH_subMesh::_duplicate(sm);
303 // is it enought to set modifid attribute on root mesh objects only?
304 // it is seems that modifaction flag will be set on child submeshes
305 // automatically (see SMESH::ModifiedMesh for details)
306 SMESH::ModifiedMesh( aMeshSObj, false, false );
308 SMESH::submesh_array_array_var meshOrder = new SMESH::submesh_array_array();
309 meshOrder->length(theListListIds.count() );
310 ListListId::const_iterator it = theListListIds.constBegin();
311 for ( int i = 0; it != theListListIds.constEnd(); ++it ) {
312 const QList<int>& ids = *it;
313 SMESH::submesh_array_var subMeshList = new SMESH::submesh_array();
314 subMeshList->length( ids.count() );
315 QList<int>::const_iterator subIt = ids.constBegin();
316 for( int j = 0; subIt != ids.constEnd(); ++subIt )
317 if ( mapOfSubMesh.find( *subIt ) != mapOfSubMesh.end() )
318 subMeshList[ j++ ] = mapOfSubMesh[ *subIt ];
320 meshOrder[ i++ ] = subMeshList;
322 // update object browser
323 SMESHGUI::GetSMESHGUI()->updateObjBrowser( true, 0 );
325 return myMesh->SetMeshOrder(meshOrder);