-// 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
-//
+// Copyright (C) 2014-2015 EDF-R&D
// 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.
+// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
#include "HYDROData_GeomTool.h"
+#ifndef LIGHT_MODE
+
#include <TopoDS_Shape.hxx>
+#include <BRepTools.hxx>
+
+#ifdef WIN32
+ #pragma warning ( disable: 4251 )
+#endif
+
#include <SALOME_NamingService.hxx>
#include <SALOME_LifeCycleCORBA.hxx>
+#ifdef WIN32
+ #pragma warning ( default: 4251 )
+#endif
+
#include <QStringList>
#include <QSet>
}
return aName;
-}
\ No newline at end of file
+}
+
+GEOM::GEOM_Object_ptr HYDROData_GeomTool::publishShapeInGEOM(
+ GEOM::GEOM_Gen_var theGeomEngine, SALOMEDS::Study_ptr theStudy,
+ const TopoDS_Shape& theShape, const QString& theName,
+ QString& theGeomObjEntry )
+{
+ theGeomObjEntry = "";
+ GEOM::GEOM_Object_var aGeomObj;
+
+ if ( theGeomEngine->_is_nil() || theStudy->_is_nil() ||
+ theShape.IsNull() ) {
+ return aGeomObj._retn();
+ }
+
+ std::ostringstream aStreamShape;
+ // Write TopoDS_Shape in ASCII format to the stream
+ BRepTools::Write( theShape, aStreamShape );
+ // Returns the number of bytes that have been stored in the stream's buffer.
+ int aSize = aStreamShape.str().size();
+ // Allocate octect buffer of required size
+ CORBA::Octet* anOctetBuf = SALOMEDS::TMPFile::allocbuf( aSize );
+ // Copy ostrstream content to the octect buffer
+ memcpy( anOctetBuf, aStreamShape.str().c_str(), aSize );
+ // Create TMPFile
+ SALOMEDS::TMPFile_var aSeqFile = new SALOMEDS::TMPFile( aSize, aSize, anOctetBuf, 1 );
+
+ // Restore shape from the stream and get the GEOM object
+ GEOM::GEOM_IInsertOperations_var anInsOp = theGeomEngine->GetIInsertOperations( theStudy->StudyId() );
+ aGeomObj = anInsOp->RestoreShape( aSeqFile );
+
+ // Publish the GEOM object
+ theGeomObjEntry = publishGEOMObject( theGeomEngine, theStudy, aGeomObj, theName );
+
+ return aGeomObj._retn();
+}
+
+ GEOM::GEOM_Object_ptr HYDROData_GeomTool::createFaceInGEOM( GEOM::GEOM_Gen_var theGeomEngine,
+ SALOMEDS::Study_ptr theStudy,
+ const int theWidth,
+ const int theHeight,
+ const QString& theName,
+ QString& theFaceEntry )
+{
+ theFaceEntry = "";
+ GEOM::GEOM_Object_var aGeomObj;
+
+ if ( theGeomEngine->_is_nil() || theStudy->_is_nil() ) {
+ return aGeomObj._retn();
+ }
+
+ GEOM::GEOM_IBasicOperations_var aBasicOperations = theGeomEngine->GetIBasicOperations( theStudy->StudyId() );
+ GEOM::GEOM_IBlocksOperations_var aBlocksOperations = theGeomEngine->GetIBlocksOperations( theStudy->StudyId() );
+
+ GEOM::GEOM_Object_var P1 = aBasicOperations->MakePointXYZ( -0.5 * theWidth, -0.5 * theHeight, 0 );
+ GEOM::GEOM_Object_var P2 = aBasicOperations->MakePointXYZ( 0.5 * theWidth, -0.5 * theHeight, 0 );
+ GEOM::GEOM_Object_var P3 = aBasicOperations->MakePointXYZ( 0.5 * theWidth, 0.5 * theHeight, 0 );
+ GEOM::GEOM_Object_var P4 = aBasicOperations->MakePointXYZ( -0.5 * theWidth, 0.5 * theHeight, 0 );
+
+ GEOM::GEOM_Object_var aFace = aBlocksOperations->MakeQuad4Vertices( P1, P2 ,P3, P4 );
+
+ // Publish the face
+ theFaceEntry = publishGEOMObject( theGeomEngine, theStudy, aFace, theName );
+
+ return aFace._retn();
+}
+
+QString HYDROData_GeomTool::publishGEOMObject( GEOM::GEOM_Gen_var theGeomEngine,
+ SALOMEDS::Study_ptr theStudy,
+ GEOM::GEOM_Object_ptr theGeomObj,
+ const QString& theName )
+{
+ QString anEntry;
+
+ if ( !theGeomObj->_is_nil() ) {
+ QString aName = HYDROData_GeomTool::GetFreeName( theStudy, theName );
+
+ SALOMEDS::SObject_var aResultSO =
+ theGeomEngine->PublishInStudy( theStudy, SALOMEDS::SObject::_nil(),
+ theGeomObj, qPrintable( aName ) );
+ if ( !aResultSO->_is_nil() ) {
+ anEntry = aResultSO->GetID();
+ }
+ }
+
+ return anEntry;
+}
+
+#endif