#include "HYDROData_Tool.h"
#include "HYDROData_Zone.h"
+#include <GEOMBase.h>
+
#include <TopoDS.hxx>
#include <TopoDS_Shell.hxx>
#include <TopoDS_Edge.hxx>
#include <BRepBuilderAPI_Sewing.hxx>
#include <BRepTopAdaptor_FClass2d.hxx>
+#include <BRepTools.hxx>
+
#include <TopAbs.hxx>
#include <TopExp_Explorer.hxx>
#include <TopExp.hxx>
#define PYTHON_CALCULATION_ID "KIND_CALCULATION"
+#define EXPORT_NAME "HYDRO_" + GetName()
+
IMPLEMENT_STANDARD_HANDLE(HYDROData_CalculationCase, HYDROData_Entity)
IMPLEMENT_STANDARD_RTTIEXT(HYDROData_CalculationCase, HYDROData_Entity)
return aNewGroup;
}
+bool HYDROData_CalculationCase::Export( GEOM::GEOM_Gen_var theGeomEngine,
+ SALOMEDS::Study_ptr theStudy )
+{
+ // Get faces
+ // TODO
+ TopTools_ListOfShape aFaces;
+
+ // Get groups
+ // TODO
+ HYDROData_SequenceOfObjects aSplittedGroups;
+
+ return Export( theGeomEngine, theStudy, aFaces, aSplittedGroups );
+}
+
+bool HYDROData_CalculationCase::Export( GEOM::GEOM_Gen_var theGeomEngine,
+ SALOMEDS::Study_ptr theStudy,
+ const TopTools_ListOfShape& theFaces,
+ const HYDROData_SequenceOfObjects& theSplittedGroups )
+{
+ // Make shell from the faces
+ TopoDS_Shell aShell;
+ TopTools_ListOfShape aFacesList;
+
+ BRepBuilderAPI_Sewing aSewing( Precision::Confusion()*10.0 );
+
+ TopTools_ListIteratorOfListOfShape aFaceIter( theFaces );
+ for ( ; aFaceIter.More(); aFaceIter.Next() ) {
+ TopoDS_Shape aShape = aFaceIter.Value();
+ if ( !aShape.IsNull() && (aShape.ShapeType() == TopAbs_FACE) ) {
+ TopoDS_Face aFace = TopoDS::Face( aShape );
+ if ( !aFace.IsNull() ) {
+ aFacesList.Append( aFace );
+ aSewing.Add( aFace );
+ }
+ } else {
+ TopExp_Explorer anExp( aShape, TopAbs_FACE );
+ for ( ; anExp.More(); anExp.Next() ) {
+ TopoDS_Face aFace = TopoDS::Face( anExp.Current() );
+ if ( !aFace.IsNull() ) {
+ aFacesList.Append( aFace );
+ aSewing.Add( aFace );
+ }
+ }
+ }
+ } // faces iterator
+
+ aSewing.Perform();
+ TopoDS_Shape aSewedShape = aSewing.SewedShape();
+
+ if ( !aSewedShape.IsNull() ) {
+ if ( aSewedShape.ShapeType() == TopAbs_FACE && theFaces.Extent() ==1 ) {
+ // create shell from one face
+ BRep_Builder aBuilder;
+ aBuilder.MakeShell( aShell );
+ aBuilder.Add( aShell, aSewedShape);
+ } else {
+ TopExp_Explorer anExpShells( aSewedShape, TopAbs_SHELL );
+ Standard_Integer aNbOfShells = 0;
+ for ( ; anExpShells.More(); anExpShells.Next() ) {
+ aShell = TopoDS::Shell( anExpShells.Current() );
+ aNbOfShells++;
+ }
+
+ if ( aNbOfShells != 1 ) {
+ aShell.Nullify();
+ BRep_Builder aBuilder;
+ aBuilder.MakeShell( aShell );
+
+ TopExp_Explorer anExpFaces( aSewedShape, TopAbs_FACE );
+ for ( ; anExpFaces.More(); anExpFaces.Next() ) {
+ TopoDS_Face aFace = TopoDS::Face( anExpFaces.Current() );
+ if ( !aFace.IsNull() ) {
+ aBuilder.Add( aShell, aFace );
+ }
+ }
+ }
+ }
+ }
+
+ if ( !aShell.IsNull() ) {
+ TopTools_IndexedMapOfShape aMapOfFaces;
+ TopExp::MapShapes( aShell, TopAbs_FACE, aMapOfFaces );
+ if ( aMapOfFaces.Extent() != aFacesList.Extent() ) {
+ aShell.Nullify();
+ BRep_Builder aBuilder;
+ aBuilder.MakeShell( aShell );
+
+ TopTools_ListIteratorOfListOfShape anIter( aFacesList );
+ for ( ; anIter.More(); anIter.Next() ) {
+ TopoDS_Face aFace = TopoDS::Face( anIter.Value() );
+ aBuilder.Add( aShell, aFace );
+ }
+ }
+ }
+
+ // If the shell is empty - return false
+ if ( aShell.IsNull() || !TopoDS_Iterator(aShell).More() ) {
+ return false;
+ }
+
+ // Publish the shell
+ QString aName = EXPORT_NAME;
+ GEOM::GEOM_Object_ptr aPublishedObj =
+ publishShapeInGEOM( theGeomEngine, theStudy, aShell, aName );
+
+ if ( aPublishedObj->_is_nil() ) {
+ return false;
+ }
+
+ // Create groups
+ GEOM::GEOM_IGroupOperations_var aGroupOp =
+ theGeomEngine->GetIGroupOperations( theStudy->StudyId() );
+
+ GEOM::GEOM_Object_var aGroup = aGroupOp->CreateGroup( aPublishedObj, TopAbs_EDGE );
+ if ( !CORBA::is_nil(aGroup) && aGroupOp->IsDone() ) {
+ GEOM::ListOfLong_var anIndexes = new GEOM::ListOfLong;
+ aGroupOp->UnionIDs( aGroup, anIndexes );
+ if ( aGroupOp->IsDone() ) {
+ SALOMEDS::SObject_var aGroupSO =
+ theGeomEngine->AddInStudy( theStudy, aGroup, qPrintable( aName ), aPublishedObj );
+ }
+ }
+
+ return true;
+}
+
+GEOM::GEOM_Object_ptr HYDROData_CalculationCase::publishShapeInGEOM(
+ GEOM::GEOM_Gen_var theGeomEngine, SALOMEDS::Study_ptr theStudy,
+ const TopoDS_Shape& theShape, const QString& theName )
+{
+ GEOM::GEOM_Object_var aGeomObj;
+
+ bool isNil = aGeomObj->_is_nil(); ///@MZN
+
+ 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 );
+
+ // Puplish the GEOM object
+ if ( !aGeomObj->_is_nil() ) {
+ QString aName = GEOMBase::GetDefaultName( theName );
+
+ SALOMEDS::SObject_var aResultSO =
+ theGeomEngine->PublishInStudy( theStudy, SALOMEDS::SObject::_nil(),
+ aGeomObj, qPrintable( theName ) );
+ if ( aResultSO->_is_nil() ) {
+ aGeomObj = GEOM::GEOM_Object::_nil();
+ }
+ }
+ return aGeomObj._retn();
+ }
\ No newline at end of file
#include <HYDROData_Entity.h>
+// IDL includes
+#include <SALOMEconfig.h>
+#include CORBA_SERVER_HEADER(GEOM_Gen)
+
class gp_XY;
+class TopoDS_Shape;
class TopoDS_Shell;
+class TopTools_ListOfShape;
class Handle(HYDROData_Object);
class Handle(HYDROData_Region);
/**
- * Returns shell containing faces which correspond to regions.
- * \return shell as TopoDS_Shell
+ * Exports the calculation case data (shell and groups) to GEOM module.
+ * \param theGeomEngine GEOM module engine
+ * \param theStudy SALOMEDS study, is used for publishing of GEOM objects
+ * \return true in case of success
*/
- HYDRODATA_EXPORT virtual TopoDS_Shell GetShell();
-
+ HYDRODATA_EXPORT virtual bool Export( GEOM::GEOM_Gen_var theGeomEngine,
+ SALOMEDS::Study_ptr theStudy );
public:
// Public methods to work with Calculation services
*/
HYDRODATA_EXPORT virtual Handle(HYDROData_SplittedEdgesGroup) addNewSplittedGroup();
+ /**
+ * Returns shell containing faces which correspond to regions.
+ * \return shell as TopoDS_Shell
+ */
+ HYDRODATA_EXPORT virtual TopoDS_Shell GetShell();
+
+ /**
+ * Exports the given faces as shell and the given groups to GEOM module.
+ * \param theGeomEngine GEOM module engine
+ * \param theStudy SALOMEDS study, is used for publishing of GEOM objects
+ * \param theFaces the list of faces to make shell
+ * \param theSplittedGroups the list of groups
+ * \return true in case of success
+ */
+ HYDRODATA_EXPORT bool Export( GEOM::GEOM_Gen_var theGeomEngine,
+ SALOMEDS::Study_ptr theStudy,
+ const TopTools_ListOfShape& theFaces,
+ const HYDROData_SequenceOfObjects& theSplittedGroups );
+
+ /**
+ * Publish the given shape in GEOM as a GEOM object.
+ * \param theGeomEngine GEOM module engine
+ * \param theStudy SALOMEDS study, used for publishing of the shape
+ * \param theShape the shape to publish as a GEOM object
+ * \param theName the name of the published object
+ * \return the published GEOM object
+ */
+ GEOM::GEOM_Object_ptr publishShapeInGEOM( GEOM::GEOM_Gen_var theGeomEngine,
+ SALOMEDS::Study_ptr theStudy,
+ const TopoDS_Shape& theShape,
+ const QString& theName );
+
protected:
friend class HYDROData_Iterator;
#include <HYDROData_CalculationCase.h>
#include <GeometryGUI.h>
-#include <GEOMBase.h>
#include <SalomeApp_Study.h>
-#include <TopoDS_Shell.hxx>
-#include <BRepTools.hxx>
-
#include <LightApp_Application.h>
#include <LightApp_UpdateFlags.h>
return false;
}
- QString anErrorMsg;
- bool anIsOk = false;
-
- TopoDS_Shell aShell = aCalculation->GetShell();
-
- if ( !aShell.IsNull() ) {
- // TODO move this code to anothe place?
- std::ostringstream aStreamShape;
- // Write TopoDS_Shape in ASCII format to the stream
- BRepTools::Write( aShell, 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 );
-
- // Get active study
- SalomeApp_Study* aStudy =
- dynamic_cast<SalomeApp_Study*>( module()->getApp()->activeStudy() );
-
- // Restore shape from the stream and get the GEOM object
- GEOM::GEOM_Gen_var aGeomEngine = GeometryGUI::GetGeomGen(); // TODO: get GEOM engine in another way?
- GEOM::GEOM_IInsertOperations_var anInsOp = aGeomEngine->GetIInsertOperations( module()->getStudyId() );
- GEOM::GEOM_Object_var aGeomObj = anInsOp->RestoreShape( aSeqFile );
-
- // Puplish the GEOM object
- if ( !aGeomObj->_is_nil() ) {
- QString aName = GEOMBase::GetDefaultName( tr( "OBJ_PREFIX" ) + aCalculation->GetName() );
-
- SALOMEDS::Study_var aDSStudy = GeometryGUI::ClientStudyToStudy( aStudy->studyDS() );
- SALOMEDS::SObject_var aResultSO =
- aGeomEngine->PublishInStudy( aDSStudy, SALOMEDS::SObject::_nil(),
- aGeomObj, qPrintable( aName ) );
- if ( !aResultSO->_is_nil() ) {
- theUpdateFlags = UF_ObjBrowser;
- anIsOk = true;
- }
- }
+ bool isOk = false;
- if ( !anIsOk )
- theErrorMsg = tr( "IMPOSSIBLE_TO_CREATE_GEOM_SHAPE" );
+ // Get active study
+ SalomeApp_Study* aStudy =
+ dynamic_cast<SalomeApp_Study*>( module()->getApp()->activeStudy() );
- } else {
- theErrorMsg = tr( "RESULT_SHAPE_NULL" );
+ // Export
+ if ( aStudy ) {
+ SALOMEDS::Study_var aDSStudy = GeometryGUI::ClientStudyToStudy( aStudy->studyDS() );
+ GEOM::GEOM_Gen_var aGeomEngine = GeometryGUI::GetGeomGen();
+ if ( aCalculation->Export( aGeomEngine, aDSStudy ) ) {
+ theUpdateFlags = UF_ObjBrowser;
+ isOk = true;
+ }
}
- return anIsOk;
+ return isOk;
}
void HYDROGUI_ExportCalculationOp::onApply()
tr( "EXPORT_STATUS" ),
anErrorMsg );
}
-}
\ No newline at end of file
+}