X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FHYDROData%2FHYDROData_GeomTool.cxx;h=a152909c98247f0e26f54693bd0f917b820c8ba7;hb=fce3f1240b6161d7cb837344078e5943b90eca65;hp=cef3266d7f4e1e396df82db3c33cd8adf56c4b53;hpb=474c2cd65280d793f1c81ca528bc92e1cff988e6;p=modules%2Fhydro.git diff --git a/src/HYDROData/HYDROData_GeomTool.cxx b/src/HYDROData/HYDROData_GeomTool.cxx index cef3266d..a152909c 100644 --- a/src/HYDROData/HYDROData_GeomTool.cxx +++ b/src/HYDROData/HYDROData_GeomTool.cxx @@ -1,8 +1,4 @@ -// Copyright (C) 2007-2015 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 @@ -22,12 +18,29 @@ #include "HYDROData_GeomTool.h" +#ifndef LIGHT_MODE + #include +#include +#include + +#ifdef WIN32 + #pragma warning ( disable: 4251 ) +#endif + #include #include +#include +#include + +#ifdef WIN32 + #pragma warning ( default: 4251 ) +#endif + #include +#include #include static int _argc = 0; @@ -110,4 +123,140 @@ QString HYDROData_GeomTool::GetFreeName( SALOMEDS::Study_ptr theStudy, const QSt } 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::ExplodeShapeInGEOMandPublish( GEOM::GEOM_Gen_var theGeomEngine, + SALOMEDS::Study_ptr theStudy, + const TopoDS_Shape& theShape, + const NCollection_IndexedDataMap& aFacesToNameModif, + const QString& theName, + QString& theGeomObjEntry) +{ + GEOM::GEOM_Object_ptr aGeomObj = HYDROData_GeomTool::publishShapeInGEOM( theGeomEngine, theStudy, theShape, theName, theGeomObjEntry ); + + GEOM::GEOM_IShapesOperations_var anExpOp = theGeomEngine->GetIShapesOperations( theStudy->StudyId() ); + GEOM::ListOfGO* aFc = anExpOp->MakeExplode(aGeomObj, TopAbs_FACE, false); + + TopTools_MapOfShape mapShape; + + NCollection_IndexedDataMap aFF2N; + for (int i = 1; i <= aFacesToNameModif.Extent(); i++) + { + TopExp_Explorer exp (aFacesToNameModif.FindKey(i), TopAbs_FACE); + for (;exp.More(); exp.Next()) + aFF2N.Add(exp.Current(), aFacesToNameModif.FindFromIndex(i)); + } + + TopExp_Explorer exp (theShape, TopAbs_FACE); + QVector Names; + for (; exp.More(); exp.Next()) + { + const TopoDS_Shape& csh = exp.Current(); + if (mapShape.Add(csh)) + { + //listShape.Append(csh); + QString Qstr = aFF2N.FindFromKey(csh); + Names.push_back(Qstr); + } + } + + for (size_t i = 0; i < aFc->length(); i++) + { + std::string name = Names[i].toStdString(); + GEOM::GEOM_Object_ptr anObj = aFc->operator[](i); + //GEOMBase::PublishSubObject( anObj, name.c_str() ); + theGeomEngine->AddInStudy( theStudy, anObj, name.c_str(), aGeomObj ); + } + + return aGeomObj; +} + + + 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