From: mzn Date: Mon, 10 Nov 2014 13:02:04 +0000 (+0000) Subject: Bug #490: batch mode error. X-Git-Tag: BR_hydro_v_1_0_5~30 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=3ca9285025326609e2ac45bcdf42fb5ce9f8d2d8;p=modules%2Fhydro.git Bug #490: batch mode error. --- diff --git a/src/HYDROData/CMakeLists.txt b/src/HYDROData/CMakeLists.txt index a3a4c3cf..7459b7c3 100644 --- a/src/HYDROData/CMakeLists.txt +++ b/src/HYDROData/CMakeLists.txt @@ -46,6 +46,7 @@ set(PROJECT_HEADERS HYDROData_VisualState.h HYDROData_Warning.h HYDROData_Zone.h + HYDROData_GeomTool.h ) set(PROJECT_SOURCES @@ -92,6 +93,7 @@ set(PROJECT_SOURCES HYDROData_Transform.cxx HYDROData_VisualState.cxx HYDROData_Zone.cxx + HYDROData_GeomTool.cxx ) add_definitions( diff --git a/src/HYDROData/HYDROData_CalculationCase.cxx b/src/HYDROData/HYDROData_CalculationCase.cxx index 5dc58cbb..4e218713 100644 --- a/src/HYDROData/HYDROData_CalculationCase.cxx +++ b/src/HYDROData/HYDROData_CalculationCase.cxx @@ -11,6 +11,7 @@ #include "HYDROData_SplittedShapesGroup.h" #include "HYDROData_Region.h" #include "HYDROData_Tool.h" +#include "HYDROData_GeomTool.h" #include @@ -908,18 +909,9 @@ Handle(HYDROData_SplittedShapesGroup) HYDROData_CalculationCase::addNewSplittedG QString HYDROData_CalculationCase::Export( int theStudyId ) const { - int argc = 0; - char** argv = 0; - CORBA::ORB_var anORB = CORBA::ORB_init( argc, argv, "omniORB4"/*CORBA::ORB_ID*/ ); - SALOME_NamingService aNameService( anORB ); - SALOME_LifeCycleCORBA aLCC( &aNameService ); - Engines::EngineComponent_var aComponent = aLCC.FindOrLoad_Component( "FactoryServer", "GEOM" ); - GEOM::GEOM_Gen_var aGEOMEngine = GEOM::GEOM_Gen::_narrow( aComponent ); + GEOM::GEOM_Gen_var aGEOMEngine = HYDROData_GeomTool::GetGeomGen(); + SALOMEDS::Study_var aDSStudy = HYDROData_GeomTool::GetStudyByID( theStudyId ); - CORBA::Object_var aSMObject = aNameService.Resolve("/myStudyManager"); - SALOMEDS::StudyManager_var aStudyManager = SALOMEDS::StudyManager::_narrow(aSMObject); - SALOMEDS::Study_var aDSStudy = aStudyManager->GetStudyByID( theStudyId ); - QString aGeomObjEntry; bool isOK = Export( aGEOMEngine, aDSStudy, aGeomObjEntry ); return isOK ? aGeomObjEntry : QString(); @@ -1155,7 +1147,7 @@ GEOM::GEOM_Object_ptr HYDROData_CalculationCase::publishShapeInGEOM( // Puplish the GEOM object if ( !aGeomObj->_is_nil() ) { - QString aName = GEOMBase::GetDefaultName( theName ); + QString aName = HYDROData_GeomTool::GetFreeName( theStudy, theName ); SALOMEDS::SObject_var aResultSO = theGeomEngine->PublishInStudy( theStudy, SALOMEDS::SObject::_nil(), diff --git a/src/HYDROData/HYDROData_GeomTool.cxx b/src/HYDROData/HYDROData_GeomTool.cxx new file mode 100644 index 00000000..5bfd9e38 --- /dev/null +++ b/src/HYDROData/HYDROData_GeomTool.cxx @@ -0,0 +1,113 @@ +// Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#include "HYDROData_GeomTool.h" + +#include + +#include +#include + +#include +#include + +static int _argc = 0; +static CORBA::ORB_var _ORB = CORBA::ORB_init( _argc, 0, "omniORB4"/*CORBA::ORB_ID*/ ); +static SALOME_NamingService _NS( _ORB ); +static SALOME_LifeCycleCORBA _LCC( &_NS ); + + +TopoDS_Shape HYDROData_GeomTool::GetShapeFromIOR( const int theStudyId, const QString& theIOR ) +{ + // Note that GEOMBase::GetShape() cause crash in batch mode + + TopoDS_Shape aResShape; + + CORBA::Object_var aCorbaObj = _ORB->string_to_object( qPrintable( theIOR ) ); + if ( !CORBA::is_nil( aCorbaObj ) ) { + GEOM::GEOM_Object_var aGeomObj = GEOM::GEOM_Object::_narrow( aCorbaObj ); + + Engines::EngineComponent_var aComp = + _LCC.FindOrLoad_Component( "FactoryServer", "GEOM" ); + GEOM::GEOM_Gen_var aComponentGeom = GEOM::GEOM_Gen::_narrow( aComp ); + + aResShape = GEOM_Client::get_client().GetShape( aComponentGeom, aGeomObj ); + } + + return aResShape; +} + +GEOM::GEOM_Gen_var HYDROData_GeomTool::GetGeomGen() +{ + Engines::EngineComponent_var aComponent = _LCC.FindOrLoad_Component( "FactoryServer", "GEOM" ); + GEOM::GEOM_Gen_var aGEOMEngine = GEOM::GEOM_Gen::_narrow( aComponent ); + + return aGEOMEngine._retn(); +} + +SALOMEDS::Study_var HYDROData_GeomTool::GetStudyByID( const int theStudyId ) +{ + CORBA::Object_var aSMObject = _NS.Resolve("/myStudyManager"); + SALOMEDS::StudyManager_var aStudyManager = SALOMEDS::StudyManager::_narrow(aSMObject); + SALOMEDS::Study_var aDSStudy = aStudyManager->GetStudyByID( theStudyId ); + + return aDSStudy._retn(); +} + +QString HYDROData_GeomTool::GetFreeName( SALOMEDS::Study_ptr theStudy, const QString& theBaseName ) +{ + QString aName = theBaseName; + + if ( !theStudy->_is_nil() ) { + // collect all object names of GEOM component + QSet anUsedNames; + SALOMEDS::SComponent_var aComponent = theStudy->FindComponent( "GEOM" ); + if ( !aComponent->_is_nil() ) { + SALOMEDS::ChildIterator_var anIter = theStudy->NewChildIterator( aComponent ); + for ( anIter->InitEx( true ); anIter->More(); anIter->Next() ) { + anUsedNames.insert( anIter->Value()->GetName() ); + } + } + + // build a unique name + int aNumber = 0; + bool isUnique = false; + QString aPrefix = theBaseName; + QStringList aParts = aPrefix.split( "_", QString::KeepEmptyParts ); + if ( aParts.count() > 1 ) { + bool isOk; + aNumber = aParts.last().toLong( &isOk ); + if ( isOk ) { + aParts.removeLast(); + aPrefix = aParts.join( "_" ); + aNumber--; + } + } + + while ( !isUnique ) { + aName = aPrefix + "_" + QString::number( ++aNumber ); + isUnique = ( !anUsedNames.contains( aName ) ); + } + } + + return aName; +} \ No newline at end of file diff --git a/src/HYDROData/HYDROData_GeomTool.h b/src/HYDROData/HYDROData_GeomTool.h new file mode 100644 index 00000000..4abb0838 --- /dev/null +++ b/src/HYDROData/HYDROData_GeomTool.h @@ -0,0 +1,69 @@ +// Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#ifndef HYDROData_GeomTool_HeaderFile +#define HYDROData_GeomTool_HeaderFile + +#include "HYDROData.h" + +#include + +class TopoDS_Shape; +class QString; + +class HYDRODATA_EXPORT HYDROData_GeomTool { + +public: + + /** + * \brief Get shape by the specified IOR. + * \param theIOR the GEOM object IOR + * \param theStudyId the study ID + * \return the shape + */ + static TopoDS_Shape GetShapeFromIOR( const int theStudyId, const QString& theIOR ); + + /** + * \brief Get GEOM engine. + * \return the GEOM engine + */ + static GEOM::GEOM_Gen_var GetGeomGen(); + + /** + * \brief Get shape by the specified study ID. + * \param theStudyId the study ID + * \return the study + */ + static SALOMEDS::Study_var GetStudyByID( const int theStudyId ); + + /** + * \brief Get free name for GEOM object. + * \param theStudy the study + * \param theBaseName the base name + * \return the default name + */ + static QString GetFreeName( SALOMEDS::Study_ptr theStudy, const QString& theBaseName ); +}; + +#endif + + diff --git a/src/HYDROData/HYDROData_Obstacle.cxx b/src/HYDROData/HYDROData_Obstacle.cxx index 7d0469ca..08bc9a93 100644 --- a/src/HYDROData/HYDROData_Obstacle.cxx +++ b/src/HYDROData/HYDROData_Obstacle.cxx @@ -5,14 +5,13 @@ #include "HYDROData_ShapesGroup.h" #include "HYDROData_ShapesTool.h" #include "HYDROData_Tool.h" +#include "HYDROData_GeomTool.h" #include #include #include -#include - #include #include @@ -43,6 +42,7 @@ #include #include +#include IMPLEMENT_STANDARD_HANDLE(HYDROData_Obstacle,HYDROData_ArtificialObject) IMPLEMENT_STANDARD_RTTIEXT(HYDROData_Obstacle,HYDROData_ArtificialObject) @@ -203,16 +203,26 @@ QString HYDROData_Obstacle::GetFilePath() const bool HYDROData_Obstacle::ImportFromGeomIOR( const TCollection_AsciiString& theIOR ) { - if ( theIOR.IsEmpty() ) - return false; + bool aRes = false; - TopoDS_Shape aShape = GEOMBase::GetShapeFromIOR( theIOR.ToCString() ); - if ( aShape.IsNull() ) - return false; + if ( theIOR.IsEmpty() ) { + return aRes; + } + + int aDocId = -1; + if ( !HYDROData_Document::DocumentId( HYDROData_Document::Document( myLab ), aDocId ) || aDocId < 0 ) { + return aRes; + } + + // TopoDS_Shape aShape = GEOMBase::GetShapeFromIOR( theIOR.ToCString() ); + TopoDS_Shape aShape = HYDROData_GeomTool::GetShapeFromIOR( aDocId, theIOR.ToCString() ); - SetShape3D( aShape ); + if ( !aShape.IsNull() ) { + SetShape3D( aShape ); + aRes = true; + } - return true; + return aRes; } void HYDROData_Obstacle::SetGeomObjectEntry( const TCollection_AsciiString& theEntry ) @@ -244,19 +254,14 @@ TCollection_AsciiString HYDROData_Obstacle::GetGeomObjectName() const return aRes; } - int argc = 0; - char** argv = 0; - CORBA::ORB_var anORB = CORBA::ORB_init( argc, argv, "omniORB4"/*CORBA::ORB_ID*/ ); - SALOME_NamingService aNameService( anORB ); - - CORBA::Object_var aSMObject = aNameService.Resolve("/myStudyManager"); - SALOMEDS::StudyManager_var aStudyManager = SALOMEDS::StudyManager::_narrow(aSMObject); - SALOMEDS::Study_var aDSStudy = aStudyManager->GetStudyByID( aDocId ); - - TCollection_AsciiString anEntry = GetGeomObjectEntry(); - SALOMEDS::SObject_var aSObject = aDSStudy->FindObjectID( anEntry.ToCString() ); - if ( !aSObject->_is_nil() ) { - aRes = TCollection_AsciiString( aSObject->GetName() ); + SALOMEDS::Study_var aDSStudy = HYDROData_GeomTool::GetStudyByID( aDocId ); + + if ( !aDSStudy->_is_nil() ) { + TCollection_AsciiString anEntry = GetGeomObjectEntry(); + SALOMEDS::SObject_var aSObject = aDSStudy->FindObjectID( anEntry.ToCString() ); + if ( !aSObject->_is_nil() ) { + aRes = TCollection_AsciiString( aSObject->GetName() ); + } } return aRes;