+}
+
+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<TopoDS_Shape, QString, TopTools_ShapeMapHasher>& 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<TopoDS_Shape, QString, TopTools_ShapeMapHasher> 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<QString> 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++)
+ GEOMBase::PublishSubObject(aFc->operator[](i), Names[i]);
+
+ 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