1 // Copyright (C) 2007-2020 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_VTKUtils.h"
28 #include "SMESHGUI_MeshUtils.h"
30 // SALOME GUI includes
31 #include <LightApp_SelectionMgr.h>
32 #include <SALOME_ListIO.hxx>
33 #include <SUIT_ResourceMgr.h>
34 #include <SUIT_OverrideCursor.h>
35 #include <SUIT_MessageBox.h>
36 #include <SUIT_Desktop.h>
38 // SALOME KERNEL includes
39 #include <SALOMEDS_SObject.hxx>
40 #include <SALOMEDSClient_SObject.hxx>
45 //================================================================================
49 //================================================================================
51 SMESHGUI_MeshOrderOp::SMESHGUI_MeshOrderOp()
52 : SMESHGUI_Operation(), myDlg(0), myMgr(0)
54 myDlg = new SMESHGUI_MeshOrderDlg( desktop() );
56 myHelpFileName = "constructing_meshes.html#mesh-order-anchor";
59 //================================================================================
63 //================================================================================
65 SMESHGUI_MeshOrderOp::~SMESHGUI_MeshOrderOp()
69 //================================================================================
71 * \brief Return operation dialog
73 //================================================================================
75 LightApp_Dialog* SMESHGUI_MeshOrderOp::dlg() const
80 //================================================================================
82 * \brief perform it's intention action: compute 2D mesh on 3D
84 //================================================================================
86 void SMESHGUI_MeshOrderOp::startOperation()
88 SMESHGUI_Operation::startOperation();
93 //================================================================================
95 * \brief Init dialog and mesh order box
97 //================================================================================
99 void SMESHGUI_MeshOrderOp::initDialog()
104 SMESH::SMESH_Mesh_var aMesh = SMESH::SMESH_Mesh::_nil();
106 LightApp_SelectionMgr *Sel = selectionMgr();
107 SALOME_ListIO selected; Sel->selectedObjects( selected );
109 if (selected.Extent() == 1)
110 aMesh = SMESH::GetMeshByIO(selected.First());
111 if (aMesh->_is_nil()) {
112 SUIT_MessageBox::warning(desktop(),
113 tr("SMESH_WRN_WARNING"),
114 tr("SMESH_WRN_NO_AVAILABLE_DATA"));
119 myMgr = new SMESHGUI_MeshOrderMgr( myDlg->GetMeshOrderBox() );
120 myMgr->SetMesh( aMesh );
121 if ( !myMgr->GetMeshOrder() ) {
122 SUIT_MessageBox::information(desktop(),
123 tr("SMESH_INFORMATION"),
124 tr("SMESH_NO_CONCURENT_MESH"));
131 //================================================================================
133 * \brief Apply changes
135 //================================================================================
137 bool SMESHGUI_MeshOrderOp::onApply()
139 SUIT_OverrideCursor aWaitCursor;
140 bool res = myMgr ? myMgr->SetMeshOrder() : false;
144 SMESHGUI::Modified();
154 //================================================================================
156 * \brief Apply changes
158 //================================================================================
160 void SMESHGUI_MeshOrderOp::onCancel()
168 //================================================================================
172 //================================================================================
174 SMESHGUI_MeshOrderMgr::SMESHGUI_MeshOrderMgr( SMESHGUI_MeshOrderBox* theBox )
177 myMesh = SMESH::SMESH_Mesh::_nil();
180 //================================================================================
184 //================================================================================
186 SMESHGUI_MeshOrderMgr::~SMESHGUI_MeshOrderMgr()
190 //================================================================================
192 * \brief Set root mesh object
194 //================================================================================
196 void SMESHGUI_MeshOrderMgr::SetMesh(SMESH::SMESH_Mesh_var& theMesh)
198 myMesh = SMESH::SMESH_Mesh::_duplicate(theMesh);
199 _PTR(SObject) aMeshSObj = SMESH::FindSObject(theMesh);
200 if ( myBox && aMeshSObj )
201 myBox->setTitle( aMeshSObj->GetName().c_str() );
204 //================================================================================
206 * \brief Check for concurrents between submesh objects
208 //================================================================================
210 bool SMESHGUI_MeshOrderMgr::GetMeshOrder()
212 ListListId idListList;
213 return GetMeshOrder(idListList);
216 //================================================================================
218 * \brief Check for concurrents between submesh objects
220 //================================================================================
222 bool SMESHGUI_MeshOrderMgr::GetMeshOrder(ListListId& theIdListList)
224 if (!myBox || myMesh->_is_nil())
227 SMESH::submesh_array_array_var meshOrder = myMesh->GetMeshOrder();
228 if ( !meshOrder.operator->() || !meshOrder->length() )
230 ListListName nameListList;
231 for ( int i = 0, n = meshOrder->length(); i < n; i++ )
234 QStringList nameList;
235 const SMESH::submesh_array& aSMArray = meshOrder[i];
236 for ( int j = 0, jn = aSMArray.length(); j < jn; j++ )
238 const SMESH::SMESH_subMesh_var subMesh = aSMArray[j];
240 _PTR(SObject) aSubMeshSObj = SMESH::FindSObject(subMesh);
244 idList.append(subMesh->GetId() );
245 nameList.append( QString(aSubMeshSObj->GetName().c_str()) );
247 theIdListList.append(idList);
248 nameListList.append(nameList);
250 myBox->SetMeshes(nameListList, theIdListList);
251 return !theIdListList.isEmpty();
254 //================================================================================
256 * \brief Returns status is order changed by user
258 //================================================================================
260 bool SMESHGUI_MeshOrderMgr::IsOrderChanged() const
262 return myBox && myBox->IsOrderChanged();
265 //================================================================================
267 * \brief Store submesh priority order
269 //================================================================================
271 bool SMESHGUI_MeshOrderMgr::SetMeshOrder()
273 return myBox ? SetMeshOrder(myBox->GetMeshIds()) : false;
276 //================================================================================
278 * \brief Store submesh priority order
280 //================================================================================
282 bool SMESHGUI_MeshOrderMgr::SetMeshOrder( const ListListId& theListListIds )
284 if (theListListIds.isEmpty() || myMesh->_is_nil())
287 _PTR(Study) aStudy = SMESH::getStudy();
288 _PTR(SObject) aMeshSObj = SMESH::FindSObject(myMesh);
289 if ( !aStudy || !aMeshSObj )
292 std::map<int, SMESH::SMESH_subMesh_var> mapOfSubMesh;
293 for (int i = SMESH::Tag_FirstSubMesh; i <= SMESH::Tag_LastSubMesh; i++) {
294 _PTR(SObject) aSubmeshRoot;
295 if ( !aMeshSObj->FindSubObject( i, aSubmeshRoot ) )
297 _PTR(ChildIterator) smIter = aStudy->NewChildIterator( aSubmeshRoot );
298 for ( ; smIter->More(); smIter->Next() ) {
299 _PTR(SObject) aSmObj = smIter->Value();
300 SMESH::SMESH_subMesh_var sm =
301 SMESH::SObjectToInterface<SMESH::SMESH_subMesh>( aSmObj );
302 if ( !sm->_is_nil() )
303 mapOfSubMesh[ sm->GetId() ] = SMESH::SMESH_subMesh::_duplicate(sm);
307 SMESH::submesh_array_array_var meshOrder = new SMESH::submesh_array_array();
308 meshOrder->length(theListListIds.count() );
309 ListListId::const_iterator it = theListListIds.constBegin();
310 for ( int i = 0; it != theListListIds.constEnd(); ++it ) {
311 const QList<int>& ids = *it;
312 SMESH::submesh_array_var subMeshList = new SMESH::submesh_array();
313 subMeshList->length( ids.count() );
314 QList<int>::const_iterator subIt = ids.constBegin();
315 for( int j = 0; subIt != ids.constEnd(); ++subIt )
316 if ( mapOfSubMesh.find( *subIt ) != mapOfSubMesh.end() )
317 subMeshList[ j++ ] = mapOfSubMesh[ *subIt ];
319 meshOrder[ i++ ] = subMeshList;
321 // update object browser
322 SMESHGUI::GetSMESHGUI()->updateObjBrowser( true, 0 );
324 return myMesh->SetMeshOrder(meshOrder);