1 // Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // SMESH SMESHGUI : GUI for SMESH component
24 // File : SMESHGUI_MeshUtils.cxx
25 // Author : Open CASCADE S.A.S.
28 #include "SMESHGUI_MeshUtils.h"
31 #include "SMESHGUI_Utils.h"
33 // SALOME KERNEL includes
34 #include <SALOMEDSClient_Study.hxx>
37 #include <QStringList>
40 #include <SALOMEconfig.h>
41 #include CORBA_SERVER_HEADER(SMESH_Group)
42 #include CORBA_SERVER_HEADER(SMESH_Measurements)
46 SMESH_Mesh_var GetMeshByIO(const Handle(SALOME_InteractiveObject)& theIO)
48 CORBA::Object_var anObj = IObjectToObject(theIO);
49 if(!CORBA::is_nil(anObj)){
50 SMESH_Mesh_var aMesh = SMESH_Mesh::_narrow(anObj);
51 if(!CORBA::is_nil(aMesh))
53 SMESH_GroupBase_var aGroup = SMESH_GroupBase::_narrow(anObj);
54 if(!CORBA::is_nil(aGroup))
55 return aGroup->GetMesh();
56 SMESH_subMesh_var aSubMesh = SMESH_subMesh::_narrow(anObj);
57 if(!CORBA::is_nil(aSubMesh))
58 return aSubMesh->GetFather();
60 return SMESH_Mesh::_nil();
63 QString UniqueMeshName(const QString& theBaseName, const QString& thePostfix)
65 QString baseName = thePostfix.isEmpty() ?
66 theBaseName : theBaseName + "_" + thePostfix;
67 if ( _PTR(Study) aStudy = GetActiveStudyDocument() ) {
68 QString name = baseName;
69 while ( !aStudy->FindObjectByName( name.toLatin1().data(), "SMESH" ).empty() ) {
71 QStringList names = name.split("_", QString::KeepEmptyParts);
72 if ( names.count() > 0 ) {
74 int index = names.last().toInt( &ok );
80 names.append( QString::number( nb+1 ) );
81 name = names.join( "_" );
88 QString UniqueName(const QString& theBaseName, _PTR(SObject) theParent, const QString& thePostfix)
90 QString baseName = thePostfix.isEmpty() ?
91 theBaseName : theBaseName + "_" + thePostfix;
92 QString name = baseName;
93 if ( _PTR(Study) aStudy = GetActiveStudyDocument() ) {
94 _PTR(SObject) p = theParent;
95 if ( !p ) p = aStudy->FindComponent( "SMESH" );
97 _PTR(ChildIterator) iter = aStudy->NewChildIterator( p );
101 for ( ; iter->More(); iter->Next() ) {
102 _PTR(SObject) so = iter->Value();
103 if ( !so ) continue; // skip bad objects
105 if ( so->ReferencedObject( ref ) ) continue; // skip references
106 QString n = so->GetName().c_str();
107 if ( !n.isEmpty() && n == name ) {
108 QStringList names = name.split("_", QString::KeepEmptyParts);
109 if ( names.count() > 0 ) {
111 names.last().toInt( &ok );
115 names.append( QString::number( ++idx ) );
116 name = names.join( "_" );
128 SMESH::Measurements_var& GetMeasurements()
130 static SMESH::Measurements_var aMeasurements;
131 if (CORBA::is_nil(aMeasurements)) {
132 aMeasurements = SMESHGUI::GetSMESHGen()->CreateMeasurements();
134 return aMeasurements;
136 } // end of namespace SMESH