]> SALOME platform Git repositories - modules/hydro.git/commitdiff
Salome HOME
Feature #233: Export of groups.
authormzn <mzn@opencascade.com>
Tue, 17 Dec 2013 09:52:02 +0000 (09:52 +0000)
committermzn <mzn@opencascade.com>
Tue, 17 Dec 2013 09:52:02 +0000 (09:52 +0000)
Move export to GEOM code from GUI to the data model.

src/HYDROData/CMakeLists.txt
src/HYDROData/HYDROData_CalculationCase.cxx
src/HYDROData/HYDROData_CalculationCase.h
src/HYDROGUI/HYDROGUI_ExportCalculationOp.cxx
src/HYDROPy/CMakeLists.txt

index 3aa79d5613243b3836a97a176e4aca3d4ab38d2b..e8840cd24e9520d46278dec7672c16ba5a1184f5 100644 (file)
@@ -82,9 +82,11 @@ set(PROJECT_SOURCES
 add_definitions(
   -DHYDRODATA_EXPORTS
   ${CAS_DEFINITIONS}
+  ${OMNIORB_DEFINITIONS}
   ${QT_DEFINITIONS}
 #  ${GUI_CXXFLAGS}
   ${GUI_DEFINITIONS}
+  ${GEOM_DEFINITIONS}
 )
 
 include_directories(
@@ -98,7 +100,7 @@ include_directories(
 add_library(HYDROData SHARED ${PROJECT_SOURCES} ${PROJECT_HEADERS})
 target_link_libraries(HYDROData ${GEOM_GEOMUtils} ${CAS_OCAF} ${CAS_OCAFVIS} ${CAS_TKG3d} ${CAS_TKGeomBase} ${CAS_TKGeomAlgo}
                       ${CAS_TKBrep} ${CAS_TKIGES} ${CAS_TKSTEP} ${CAS_TKTopAlgo} ${CAS_TKBO} ${CAS_TKBool} ${CAS_TKOffset}
-                      ${QT_LIBRARIES} ${GUI_ImageComposer} ${CAS_TKHLR} )
+                      ${QT_LIBRARIES} ${GUI_ImageComposer} ${CAS_TKHLR} ${GEOM_GEOM} ${GEOM_GEOMBase} )
 INSTALL(TARGETS HYDROData EXPORT ${PROJECT_NAME}TargetGroup DESTINATION ${SALOME_INSTALL_LIBS})
 
 set(PROJECT_LIBRARIES HYDROData)
index 29c0b3145d3c83882a5b7c912ef469da9f35e681..40a986951e49c3a652fddf8e96befb4445fe430b 100644 (file)
@@ -14,6 +14,8 @@
 #include "HYDROData_Tool.h"
 #include "HYDROData_Zone.h"
 
+#include <GEOMBase.h>
+
 #include <TopoDS.hxx>
 #include <TopoDS_Shell.hxx>
 #include <TopoDS_Edge.hxx>
@@ -22,6 +24,8 @@
 #include <BRepBuilderAPI_Sewing.hxx>
 #include <BRepTopAdaptor_FClass2d.hxx>
 
+#include <BRepTools.hxx>
+
 #include <TopAbs.hxx>
 #include <TopExp_Explorer.hxx>
 #include <TopExp.hxx>
@@ -34,6 +38,8 @@
 
 #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)
 
@@ -753,4 +759,172 @@ Handle(HYDROData_SplittedEdgesGroup) HYDROData_CalculationCase::addNewSplittedGr
   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
index eef8ea0b2ad04a10119b4a03a4931bfbd72f79f6..30d61d53f6c611962bf8fffdfe708db363dfcfef 100644 (file)
@@ -5,9 +5,15 @@
 
 #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);
@@ -190,11 +196,13 @@ public:
 
 
   /**
-   * 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
@@ -236,6 +244,38 @@ private:
    */
   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;
index 77722af36d2ebeeeec1da79c503b4e80235b2e6e..8e3f852269c927ff25d3d220ff6a4747b65b3493 100644 (file)
 #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>
 
@@ -84,56 +80,23 @@ bool HYDROGUI_ExportCalculationOp::processApply( int& theUpdateFlags,
     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()
@@ -182,4 +145,4 @@ void HYDROGUI_ExportCalculationOp::onApply()
                                tr( "EXPORT_STATUS" ),
                                anErrorMsg ); 
   }
-}
\ No newline at end of file
+}
index 73dc14259c459f68fb2d5d486de7923e1a132d2b..09d94dd3bc83700bf523b8b3783fb0b5d7f0a605 100644 (file)
@@ -18,6 +18,7 @@ ADD_DEFINITIONS(
   ${QT_DEFINITIONS}
   ${CAS_DEFINITIONS}
   ${PYTHON_DEFINITIONS}
+  ${OMNIORB_DEFINITIONS}
 )
 
 # libraries to link to