1 // Copyright (C) 2014-2015 EDF-R&D
2 // This library is free software; you can redistribute it and/or
3 // modify it under the terms of the GNU Lesser General Public
4 // License as published by the Free Software Foundation; either
5 // version 2.1 of the License, or (at your option) any later version.
7 // This library is distributed in the hope that it will be useful,
8 // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10 // Lesser General Public License for more details.
12 // You should have received a copy of the GNU Lesser General Public
13 // License along with this library; if not, write to the Free Software
14 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #include "HYDROData_GeomTool.h"
21 #include <TopoDS_Shape.hxx>
23 #include <SALOME_NamingService.hxx>
24 #include <SALOME_LifeCycleCORBA.hxx>
26 #include <QStringList>
30 static CORBA::ORB_var _ORB = CORBA::ORB_init( _argc, 0, "omniORB4"/*CORBA::ORB_ID*/ );
31 static SALOME_NamingService _NS( _ORB );
32 static SALOME_LifeCycleCORBA _LCC( &_NS );
35 TopoDS_Shape HYDROData_GeomTool::GetShapeFromIOR( const int theStudyId, const QString& theIOR )
37 // Note that GEOMBase::GetShape() cause crash in batch mode
39 TopoDS_Shape aResShape;
41 CORBA::Object_var aCorbaObj = _ORB->string_to_object( qPrintable( theIOR ) );
42 if ( !CORBA::is_nil( aCorbaObj ) ) {
43 GEOM::GEOM_Object_var aGeomObj = GEOM::GEOM_Object::_narrow( aCorbaObj );
45 Engines::EngineComponent_var aComp =
46 _LCC.FindOrLoad_Component( "FactoryServer", "GEOM" );
47 GEOM::GEOM_Gen_var aComponentGeom = GEOM::GEOM_Gen::_narrow( aComp );
49 aResShape = GEOM_Client::get_client().GetShape( aComponentGeom, aGeomObj );
55 GEOM::GEOM_Gen_var HYDROData_GeomTool::GetGeomGen()
57 Engines::EngineComponent_var aComponent = _LCC.FindOrLoad_Component( "FactoryServer", "GEOM" );
58 GEOM::GEOM_Gen_var aGEOMEngine = GEOM::GEOM_Gen::_narrow( aComponent );
60 return aGEOMEngine._retn();
63 SALOMEDS::Study_var HYDROData_GeomTool::GetStudyByID( const int theStudyId )
65 CORBA::Object_var aSMObject = _NS.Resolve("/myStudyManager");
66 SALOMEDS::StudyManager_var aStudyManager = SALOMEDS::StudyManager::_narrow(aSMObject);
67 SALOMEDS::Study_var aDSStudy = aStudyManager->GetStudyByID( theStudyId );
69 return aDSStudy._retn();
72 QString HYDROData_GeomTool::GetFreeName( SALOMEDS::Study_ptr theStudy, const QString& theBaseName )
74 QString aName = theBaseName;
76 if ( !theStudy->_is_nil() ) {
77 // collect all object names of GEOM component
78 QSet<QString> anUsedNames;
79 SALOMEDS::SComponent_var aComponent = theStudy->FindComponent( "GEOM" );
80 if ( !aComponent->_is_nil() ) {
81 SALOMEDS::ChildIterator_var anIter = theStudy->NewChildIterator( aComponent );
82 for ( anIter->InitEx( true ); anIter->More(); anIter->Next() ) {
83 anUsedNames.insert( anIter->Value()->GetName() );
87 // build an unique name
89 bool isUnique = false;
90 QString aPrefix = theBaseName;
91 QStringList aParts = aPrefix.split( "_", QString::KeepEmptyParts );
92 if ( aParts.count() > 1 ) {
94 aNumber = aParts.last().toLong( &isOk );
97 aPrefix = aParts.join( "_" );
102 while ( !isUnique ) {
103 aName = aPrefix + "_" + QString::number( ++aNumber );
104 isUnique = ( !anUsedNames.contains( aName ) );