Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #include "SMESHGUI_MeshUtils.h"
00029
00030 #include "SMESHGUI.h"
00031 #include "SMESHGUI_Utils.h"
00032
00033
00034 #include <SALOMEDSClient_Study.hxx>
00035
00036
00037 #include <QStringList>
00038
00039
00040 #include <SALOMEconfig.h>
00041 #include CORBA_SERVER_HEADER(SMESH_Group)
00042 #include CORBA_SERVER_HEADER(SMESH_Measurements)
00043
00044 namespace SMESH
00045 {
00046 SMESH_Mesh_var GetMeshByIO(const Handle(SALOME_InteractiveObject)& theIO)
00047 {
00048 CORBA::Object_var anObj = IObjectToObject(theIO);
00049 if(!CORBA::is_nil(anObj)){
00050 SMESH_Mesh_var aMesh = SMESH_Mesh::_narrow(anObj);
00051 if(!CORBA::is_nil(aMesh))
00052 return aMesh;
00053 SMESH_GroupBase_var aGroup = SMESH_GroupBase::_narrow(anObj);
00054 if(!CORBA::is_nil(aGroup))
00055 return aGroup->GetMesh();
00056 SMESH_subMesh_var aSubMesh = SMESH_subMesh::_narrow(anObj);
00057 if(!CORBA::is_nil(aSubMesh))
00058 return aSubMesh->GetFather();
00059 }
00060 return SMESH_Mesh::_nil();
00061 }
00062
00063 QString UniqueMeshName(const QString& theBaseName, const QString& thePostfix)
00064 {
00065 QString baseName = thePostfix.isEmpty() ?
00066 theBaseName : theBaseName + "_" + thePostfix;
00067 if ( _PTR(Study) aStudy = GetActiveStudyDocument() ) {
00068 QString name = baseName;
00069 while ( !aStudy->FindObjectByName( name.toLatin1().data(), "SMESH" ).empty() ) {
00070 int nb = 0;
00071 QStringList names = name.split("_", QString::KeepEmptyParts);
00072 if ( names.count() > 0 ) {
00073 bool ok;
00074 int index = names.last().toInt( &ok );
00075 if ( ok ) {
00076 nb = index;
00077 names.removeLast();
00078 }
00079 }
00080 names.append( QString::number( nb+1 ) );
00081 name = names.join( "_" );
00082 }
00083 return name;
00084 }
00085 return baseName;
00086 }
00087
00088 QString UniqueName(const QString& theBaseName, _PTR(SObject) theParent, const QString& thePostfix)
00089 {
00090 QString baseName = thePostfix.isEmpty() ?
00091 theBaseName : theBaseName + "_" + thePostfix;
00092 QString name = baseName;
00093 if ( _PTR(Study) aStudy = GetActiveStudyDocument() ) {
00094 _PTR(SObject) p = theParent;
00095 if ( !p ) p = aStudy->FindComponent( "SMESH" );
00096 if ( p ) {
00097 _PTR(ChildIterator) iter = aStudy->NewChildIterator( p );
00098 int idx = 0;
00099 while( true ) {
00100 bool found = false;
00101 for ( ; iter->More(); iter->Next() ) {
00102 _PTR(SObject) so = iter->Value();
00103 if ( !so ) continue;
00104 _PTR(SObject) ref;
00105 if ( so->ReferencedObject( ref ) ) continue;
00106 QString n = so->GetName().c_str();
00107 if ( !n.isEmpty() && n == name ) {
00108 QStringList names = name.split("_", QString::KeepEmptyParts);
00109 if ( names.count() > 0 ) {
00110 bool ok;
00111 names.last().toInt( &ok );
00112 if ( ok )
00113 names.removeLast();
00114 }
00115 names.append( QString::number( ++idx ) );
00116 name = names.join( "_" );
00117 found = true;
00118 break;
00119 }
00120 }
00121 if ( !found ) break;
00122 }
00123 }
00124 }
00125 return name;
00126 }
00127
00128 SMESH::Measurements_var& GetMeasurements()
00129 {
00130 static SMESH::Measurements_var aMeasurements;
00131 if (CORBA::is_nil(aMeasurements)) {
00132 aMeasurements = SMESHGUI::GetSMESHGen()->CreateMeasurements();
00133 }
00134 return aMeasurements;
00135 }
00136 }