]> SALOME platform Git repositories - modules/hydro.git/commitdiff
Salome HOME
Bug #490: batch mode error.
authormzn <mzn@opencascade.com>
Mon, 10 Nov 2014 13:02:04 +0000 (13:02 +0000)
committermzn <mzn@opencascade.com>
Mon, 10 Nov 2014 13:02:04 +0000 (13:02 +0000)
src/HYDROData/CMakeLists.txt
src/HYDROData/HYDROData_CalculationCase.cxx
src/HYDROData/HYDROData_GeomTool.cxx [new file with mode: 0644]
src/HYDROData/HYDROData_GeomTool.h [new file with mode: 0644]
src/HYDROData/HYDROData_Obstacle.cxx

index a3a4c3cfbddfb87953883734b5d91fb3f2e49d50..7459b7c3c0da50c0e5b0108f0b9168c6c6c91b2e 100644 (file)
@@ -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(
index 5dc58cbb1bce3c1b114ecdb06d14dba537ec3f2b..4e218713b73e9787fbf7540ad8294598182bb878 100644 (file)
@@ -11,6 +11,7 @@
 #include "HYDROData_SplittedShapesGroup.h"
 #include "HYDROData_Region.h"
 #include "HYDROData_Tool.h"
+#include "HYDROData_GeomTool.h"
 
 #include <GEOMBase.h>
 
@@ -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 (file)
index 0000000..5bfd9e3
--- /dev/null
@@ -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 <TopoDS_Shape.hxx>
+
+#include <SALOME_NamingService.hxx>
+#include <SALOME_LifeCycleCORBA.hxx>
+
+#include <QStringList>
+#include <QSet>
+
+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<QString> 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 (file)
index 0000000..4abb083
--- /dev/null
@@ -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 <GEOM_Client.hxx>
+
+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
+
+
index 7d0469ca666487a7b60f89e18154611947cab1e2..08bc9a931002b2e7225f072de426aaa576ca392a 100644 (file)
@@ -5,14 +5,13 @@
 #include "HYDROData_ShapesGroup.h"
 #include "HYDROData_ShapesTool.h"
 #include "HYDROData_Tool.h"
+#include "HYDROData_GeomTool.h"
 
 #include <Basics_Utils.hxx>
 
 #include <BRepTools.hxx>
 #include <BRep_Builder.hxx>
 
-#include <GEOMBase.h>
-
 #include <IGESControl_Reader.hxx>
 #include <IGESData_IGESModel.hxx>
 
@@ -43,6 +42,7 @@
 
 #include <SALOMEDSClient.hxx>
 #include <SALOME_NamingService.hxx>
+#include <SALOME_LifeCycleCORBA.hxx>
 
 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;