HYDROData_VisualState.h
HYDROData_Warning.h
HYDROData_Zone.h
+ HYDROData_GeomTool.h
)
set(PROJECT_SOURCES
HYDROData_Transform.cxx
HYDROData_VisualState.cxx
HYDROData_Zone.cxx
+ HYDROData_GeomTool.cxx
)
add_definitions(
#include "HYDROData_SplittedShapesGroup.h"
#include "HYDROData_Region.h"
#include "HYDROData_Tool.h"
+#include "HYDROData_GeomTool.h"
#include <GEOMBase.h>
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();
// 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(),
--- /dev/null
+// 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
--- /dev/null
+// 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
+
+
#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>
#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)
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 )
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;