From 7066120acbaf7c1129b6f0145122a6033157993c Mon Sep 17 00:00:00 2001 From: eap Date: Mon, 1 Feb 2021 18:29:14 +0300 Subject: [PATCH] bos #20543: EDF 22638 - hyperpatch with CADSurf Add a methods to hypothesis allowing to set hyper-patch by shapes --- idl/BLSURFPlugin_Algorithm.idl | 12 +- src/BLSURFPlugin/BLSURFPlugin_BLSURF.cxx | 28 +++ src/BLSURFPlugin/BLSURFPlugin_BLSURF.hxx | 180 +++++++++--------- src/BLSURFPlugin/BLSURFPlugin_Hypothesis.cxx | 85 ++++++++- src/BLSURFPlugin/BLSURFPlugin_Hypothesis.hxx | 20 +- .../BLSURFPlugin_Hypothesis_i.cxx | 90 ++++++++- .../BLSURFPlugin_Hypothesis_i.hxx | 5 +- src/GUI/BLSURFPluginGUI_HypothesisCreator.cxx | 86 ++++++++- src/GUI/BLSURFPluginGUI_HypothesisCreator.h | 4 +- 9 files changed, 397 insertions(+), 113 deletions(-) diff --git a/idl/BLSURFPlugin_Algorithm.idl b/idl/BLSURFPlugin_Algorithm.idl index 2e4b001..0812e1f 100644 --- a/idl/BLSURFPlugin_Algorithm.idl +++ b/idl/BLSURFPlugin_Algorithm.idl @@ -121,8 +121,11 @@ module BLSURFPlugin typedef sequence TPeriodicityList; // Hyper-patches - typedef sequence THyperPatch; - typedef sequence THyperPatchList; + typedef sequence< long > THyperPatch; + typedef sequence< THyperPatch > THyperPatchList; + typedef sequence< string > THyperPatchEntries; + typedef sequence< THyperPatchEntries > THyperPatchEntriesList; + typedef sequence< GEOM::ListOfGO > THyperPatchShapesList; /*! * BLSURFPlugin_BLSURF: interface of BLSURF algorithm @@ -500,7 +503,10 @@ module BLSURFPlugin * Set hyper-patches */ void SetHyperPatches(in THyperPatchList hpl); - THyperPatchList GetHyperPatches(); + THyperPatchList GetHyperPatches( in GEOM::GEOM_Object mainShape ); + void SetHyperPatchShapes(in THyperPatchShapesList hpsl); + THyperPatchEntriesList GetHyperPatchShapes(); + void SetHyperPatchEntries(in THyperPatchEntriesList hpel); /*! * To merges edges. diff --git a/src/BLSURFPlugin/BLSURFPlugin_BLSURF.cxx b/src/BLSURFPlugin/BLSURFPlugin_BLSURF.cxx index eaa9178..27695e9 100644 --- a/src/BLSURFPlugin/BLSURFPlugin_BLSURF.cxx +++ b/src/BLSURFPlugin/BLSURFPlugin_BLSURF.cxx @@ -991,6 +991,14 @@ void BLSURFPlugin_BLSURF::SetParameters(const BLSURFPlugin_Hypothesis* hyp, if ( !opIt->second.empty() ) { set_param(css, opIt->first.c_str(), opIt->second.c_str()); } + + if ( hyp->GetHyperPatches().size() < hyp->GetHyperPatchEntries().size() ) + { + std::map< std::string, TopoDS_Shape > entryToShape; + FillEntryToShape( hyp, entryToShape ); + const_cast( hyp )->SetHyperPatchIDsByEntry( theGeomShape, + entryToShape ); + } } if ( BLSURFPlugin_Hypothesis::HasPreCADOptions( hyp )) @@ -3602,3 +3610,23 @@ bool BLSURFPlugin_BLSURF::Evaluate(SMESH_Mesh& aMesh, return true; } + +//================================================================================ +/*! + * \brief Find TopoDS_Shape for each hyper-patch study entry in a hypothesis + */ +//================================================================================ + +void BLSURFPlugin_BLSURF::FillEntryToShape( const BLSURFPlugin_Hypothesis* hyp, + std::map< std::string, TopoDS_Shape > & entryToShape ) +{ + SMESH_Gen_i* smeshGen = SMESH_Gen_i::GetSMESHGen(); + for ( const ::BLSURFPlugin_Hypothesis::THyperPatchEntries& entries : hyp->GetHyperPatchEntries() ) + for ( const std::string& entry : entries ) + { + GEOM::GEOM_Object_var go = smeshGen->GetGeomObjectByEntry( entry ); + TopoDS_Shape shape = smeshGen->GeomObjectToShape( go ); + if ( !shape.IsNull() ) + entryToShape.insert({ entry, shape }); + } +} diff --git a/src/BLSURFPlugin/BLSURFPlugin_BLSURF.hxx b/src/BLSURFPlugin/BLSURFPlugin_BLSURF.hxx index 4c7b1a9..8601819 100644 --- a/src/BLSURFPlugin/BLSURFPlugin_BLSURF.hxx +++ b/src/BLSURFPlugin/BLSURFPlugin_BLSURF.hxx @@ -73,94 +73,98 @@ extern "C"{ class TopoDS_Shape; -class BLSURFPlugin_BLSURF: public SMESH_2D_Algo { - public: - BLSURFPlugin_BLSURF(int hypId, SMESH_Gen* gen, bool theHasGEOM); - - virtual ~BLSURFPlugin_BLSURF(); - - virtual bool CheckHypothesis(SMESH_Mesh& aMesh, - const TopoDS_Shape& aShape, - SMESH_Hypothesis::Hypothesis_Status& aStatus); - - void SetParameters(const BLSURFPlugin_Hypothesis* hyp, cadsurf_session_t *css, const TopoDS_Shape& shape); - - virtual bool Compute(SMESH_Mesh& aMesh, const TopoDS_Shape& aShape); - virtual bool Compute(SMESH_Mesh & aMesh, SMESH_MesherHelper* aHelper); - - virtual void CancelCompute(); - bool computeCanceled() { return _compute_canceled; } - - virtual bool Evaluate(SMESH_Mesh& aMesh, const TopoDS_Shape& aShape, - MapShapeNbElems& aResMap); - - // List of ids - typedef std::vector TListOfIDs; - - // PreCad Edges periodicity - struct TPreCadPeriodicityIDs { - TListOfIDs shape1IDs; - TListOfIDs shape2IDs; - std::vector theSourceVerticesCoords; - std::vector theTargetVerticesCoords; - }; - - // Edge periodicity - struct TEdgePeriodicityIDs { - int theFace1ID; - int theEdge1ID; - int theFace2ID; - int theEdge2ID; - int edge_orientation; - }; - - // Vertex periodicity - struct TVertexPeriodicityIDs { - int theEdge1ID; - int theVertex1ID; - int theEdge2ID; - int theVertex2ID; - }; - - // Vector of pairs of ids - typedef std::vector< TPreCadPeriodicityIDs > TPreCadIDsPeriodicityVector; - typedef std::vector< std::pair > TShapesIDsPeriodicityVector; - typedef std::vector< TEdgePeriodicityIDs > TEdgesIDsPeriodicityVector; - typedef std::vector< TVertexPeriodicityIDs > TVerticesIDsPeriodicityVector; - - - - protected: - const BLSURFPlugin_Hypothesis* _hypothesis; - bool _haveViscousLayers; - - TPreCadIDsPeriodicityVector _preCadFacesIDsPeriodicityVector; - TPreCadIDsPeriodicityVector _preCadEdgesIDsPeriodicityVector; - - private: - bool compute(SMESH_Mesh& aMesh, - const TopoDS_Shape& aShape, - bool allowSubMeshClearing); - - void set_param(cadsurf_session_t *css, - const char * option_name, - const char * option_value); - - TopoDS_Shape entryToShape(std::string entry); - void addCoordsFromVertices(const std::vector &theVerticesEntries, std::vector &theVerticesCoords); - void addCoordsFromVertex(BLSURFPlugin_Hypothesis::TEntry theVertexEntry, std::vector &theVerticesCoords); - void createEnforcedVertexOnFace(TopoDS_Shape FaceShape, BLSURFPlugin_Hypothesis::TEnfVertexList enfVertexList); - void createPreCadFacesPeriodicity(TopoDS_Shape theGeomShape, const BLSURFPlugin_Hypothesis::TPreCadPeriodicity &preCadPeriodicity); - void createPreCadEdgesPeriodicity(TopoDS_Shape theGeomShape, const BLSURFPlugin_Hypothesis::TPreCadPeriodicity &preCadPeriodicity); - void Set_NodeOnEdge(SMESHDS_Mesh* meshDS, const SMDS_MeshNode* node, const TopoDS_Shape& ed); - void BRepClass_FaceClassifierPerform(BRepClass_FaceClassifier* fc, const TopoDS_Face& face, const gp_Pnt& P, const Standard_Real Tol); - - private: - PyObject * main_mod; - PyObject * main_dict; - SMESH_MesherHelper* myHelper; - - volatile bool _compute_canceled; +class BLSURFPlugin_BLSURF: public SMESH_2D_Algo +{ +public: + BLSURFPlugin_BLSURF(int hypId, SMESH_Gen* gen, bool theHasGEOM); + + virtual ~BLSURFPlugin_BLSURF(); + + virtual bool CheckHypothesis(SMESH_Mesh& aMesh, + const TopoDS_Shape& aShape, + SMESH_Hypothesis::Hypothesis_Status& aStatus); + + void SetParameters(const BLSURFPlugin_Hypothesis* hyp, cadsurf_session_t *css, const TopoDS_Shape& shape); + + virtual bool Compute(SMESH_Mesh& aMesh, const TopoDS_Shape& aShape); + virtual bool Compute(SMESH_Mesh & aMesh, SMESH_MesherHelper* aHelper); + + virtual void CancelCompute(); + bool computeCanceled() { return _compute_canceled; } + + virtual bool Evaluate(SMESH_Mesh& aMesh, const TopoDS_Shape& aShape, + MapShapeNbElems& aResMap); + + static void FillEntryToShape( const BLSURFPlugin_Hypothesis* hyp, + std::map< std::string, TopoDS_Shape > & s2eMap ); + + // List of ids + typedef std::vector TListOfIDs; + + // PreCad Edges periodicity + struct TPreCadPeriodicityIDs { + TListOfIDs shape1IDs; + TListOfIDs shape2IDs; + std::vector theSourceVerticesCoords; + std::vector theTargetVerticesCoords; + }; + + // Edge periodicity + struct TEdgePeriodicityIDs { + int theFace1ID; + int theEdge1ID; + int theFace2ID; + int theEdge2ID; + int edge_orientation; + }; + + // Vertex periodicity + struct TVertexPeriodicityIDs { + int theEdge1ID; + int theVertex1ID; + int theEdge2ID; + int theVertex2ID; + }; + + // Vector of pairs of ids + typedef std::vector< TPreCadPeriodicityIDs > TPreCadIDsPeriodicityVector; + typedef std::vector< std::pair > TShapesIDsPeriodicityVector; + typedef std::vector< TEdgePeriodicityIDs > TEdgesIDsPeriodicityVector; + typedef std::vector< TVertexPeriodicityIDs > TVerticesIDsPeriodicityVector; + + + +protected: + const BLSURFPlugin_Hypothesis* _hypothesis; + bool _haveViscousLayers; + + TPreCadIDsPeriodicityVector _preCadFacesIDsPeriodicityVector; + TPreCadIDsPeriodicityVector _preCadEdgesIDsPeriodicityVector; + +private: + bool compute(SMESH_Mesh& aMesh, + const TopoDS_Shape& aShape, + bool allowSubMeshClearing); + + void set_param(cadsurf_session_t *css, + const char * option_name, + const char * option_value); + + TopoDS_Shape entryToShape(std::string entry); + void addCoordsFromVertices(const std::vector &theVerticesEntries, std::vector &theVerticesCoords); + void addCoordsFromVertex(BLSURFPlugin_Hypothesis::TEntry theVertexEntry, std::vector &theVerticesCoords); + void createEnforcedVertexOnFace(TopoDS_Shape FaceShape, BLSURFPlugin_Hypothesis::TEnfVertexList enfVertexList); + void createPreCadFacesPeriodicity(TopoDS_Shape theGeomShape, const BLSURFPlugin_Hypothesis::TPreCadPeriodicity &preCadPeriodicity); + void createPreCadEdgesPeriodicity(TopoDS_Shape theGeomShape, const BLSURFPlugin_Hypothesis::TPreCadPeriodicity &preCadPeriodicity); + void Set_NodeOnEdge(SMESHDS_Mesh* meshDS, const SMDS_MeshNode* node, const TopoDS_Shape& ed); + void BRepClass_FaceClassifierPerform(BRepClass_FaceClassifier* fc, const TopoDS_Face& face, const gp_Pnt& P, const Standard_Real Tol); + +private: + PyObject * main_mod; + PyObject * main_dict; + SMESH_MesherHelper* myHelper; + + volatile bool _compute_canceled; }; #endif diff --git a/src/BLSURFPlugin/BLSURFPlugin_Hypothesis.cxx b/src/BLSURFPlugin/BLSURFPlugin_Hypothesis.cxx index 038b59b..3db9478 100644 --- a/src/BLSURFPlugin/BLSURFPlugin_Hypothesis.cxx +++ b/src/BLSURFPlugin/BLSURFPlugin_Hypothesis.cxx @@ -44,6 +44,12 @@ #include #define MESHGEMS_VERSION_HEX (MESHGEMS_VERSION_MAJOR << 16 | MESHGEMS_VERSION_MINOR << 8 | MESHGEMS_VERSION_PATCH) +#include +#include +#include +#include +#include + namespace { struct GET_DEFAULT // struct used to get default value from GetOptionValue() @@ -816,8 +822,9 @@ std::string BLSURFPlugin_Hypothesis::GetTags() { return GetPreCADOptionValue("tags", GET_DEFAULT()); } + //============================================================================= -void BLSURFPlugin_Hypothesis::SetHyperPatches(const THyperPatchList& hpl) +void BLSURFPlugin_Hypothesis::SetHyperPatches(const THyperPatchList& hpl, bool notifyMesh) { if ( hpl != _hyperPatchList ) { @@ -862,9 +869,63 @@ void BLSURFPlugin_Hypothesis::SetHyperPatches(const THyperPatchList& hpl) _hyperPatchList.erase( _hyperPatchList.begin() + j ); } } + if ( notifyMesh ) + NotifySubMeshesHypothesisModification(); + } +} +//============================================================================= +void BLSURFPlugin_Hypothesis::SetHyperPatches(const THyperPatchEntriesList& hpel) +{ + if ( hpel != _hyperPatchEntriesList ) + { + _hyperPatchEntriesList = hpel; + _hyperPatchList.clear(); + NotifySubMeshesHypothesisModification(); } } +//================================================================================ +/*! + * \brief Set _hyperPatchList by _hyperPatchEntriesList + */ +//================================================================================ + +void BLSURFPlugin_Hypothesis:: +SetHyperPatchIDsByEntry( const TopoDS_Shape& mainShape, + const std::map< std::string, TopoDS_Shape >& entryToShape) +{ + _hyperPatchList.clear(); + if ( _hyperPatchEntriesList.empty() || mainShape.IsNull() ) + return; + + _hyperPatchList.resize( _hyperPatchEntriesList.size() ); + + TopTools_IndexedMapOfShape shapeMap; + TopExp::MapShapes( mainShape, shapeMap ); + + for ( size_t i = 0; i < _hyperPatchEntriesList.size(); ++i ) + { + THyperPatchTags & idsList = _hyperPatchList [ i ]; + const THyperPatchEntries & entryList = _hyperPatchEntriesList[ i ]; + for ( const std::string & entry : entryList ) + { + auto e2sIt = entryToShape.find( entry ); + if ( e2sIt != entryToShape.end() ) + { + for ( TopExp_Explorer fExp( e2sIt->second, TopAbs_FACE ); fExp.More(); fExp.Next() ) + { + int id = shapeMap.FindIndex( fExp.Current() ); + if ( id > 0 ) + idsList.insert( id ); + } + } + } + } + THyperPatchList hpl; + hpl.swap( _hyperPatchList ); + SetHyperPatches( hpl, /*notifyMesh=*/false ); +} + //============================================================================= /*! * \brief Return a tag of a face taking into account the hyper-patches. Optionally @@ -2187,6 +2248,13 @@ std::ostream & BLSURFPlugin_Hypothesis::SaveTo(std::ostream & save) save << " " << _nbVolumeProximityLayers; save << " " << _volumeProximityRatio; + // hyper-patches as entries + std::ostringstream hpStream; + boost::archive::text_oarchive( hpStream ) << _hyperPatchEntriesList; + std::string hpString = hpStream.str(); + save << " " << hpString.size() << " " << hpString; + + return save; } @@ -3218,6 +3286,21 @@ std::istream & BLSURFPlugin_Hypothesis::LoadFrom(std::istream & load) isOK = static_cast( load >> _volumeProximityRatio ); } + // hyper-patches as entries (issue bos #20543) + if ( static_cast( load >> i ) && i > 0 ) + { + std::string buffer( i, '\0' ); + load.get( buffer[0] ); // remove a white-space + load.get( & buffer[0], i + 1 ); + + std::istringstream istream( buffer.data() ); + boost::archive::text_iarchive archive( istream ); + try { + archive >> _hyperPatchEntriesList; + } + catch (...) {} + } + return load; } diff --git a/src/BLSURFPlugin/BLSURFPlugin_Hypothesis.hxx b/src/BLSURFPlugin/BLSURFPlugin_Hypothesis.hxx index 0bc6061..e6b7334 100644 --- a/src/BLSURFPlugin/BLSURFPlugin_Hypothesis.hxx +++ b/src/BLSURFPlugin/BLSURFPlugin_Hypothesis.hxx @@ -222,11 +222,18 @@ public: // Hyper-patches typedef std::set< int > THyperPatchTags; typedef std::vector< THyperPatchTags > THyperPatchList; - - void SetHyperPatches(const THyperPatchList& hpl); - const THyperPatchList& GetHyperPatches() const { return _hyperPatchList; } + typedef std::set< std::string > THyperPatchEntries; + typedef std::vector< THyperPatchEntries > THyperPatchEntriesList; + + void SetHyperPatches(const THyperPatchList& hpl, bool notifyMesh=true); + void SetHyperPatches(const THyperPatchEntriesList& hpl); + void SetHyperPatchIDsByEntry( const TopoDS_Shape& mainShape, + const std::map< std::string, TopoDS_Shape >& entryToShape); + const THyperPatchList& GetHyperPatches() const { return _hyperPatchList; } + const THyperPatchEntriesList& GetHyperPatchEntries() const { return _hyperPatchEntriesList; } static int GetHyperPatchTag( int faceTag, const BLSURFPlugin_Hypothesis* hyp, int* iPatch=0 ); + void SetPreCADMergeEdges(bool theVal); bool GetPreCADMergeEdges() const { return _preCADMergeEdges; } @@ -657,11 +664,12 @@ private: TPreCadPeriodicityVector _preCadFacesPeriodicityVector; TPreCadPeriodicityVector _preCadEdgesPeriodicityVector; - TFacesPeriodicityVector _facesPeriodicityVector; - TEdgesPeriodicityVector _edgesPeriodicityVector; + TFacesPeriodicityVector _facesPeriodicityVector; + TEdgesPeriodicityVector _edgesPeriodicityVector; TVerticesPeriodicityVector _verticesPeriodicityVector; - THyperPatchList _hyperPatchList; + THyperPatchList _hyperPatchList; + THyperPatchEntriesList _hyperPatchEntriesList; // Called by SaveTo to store content of _preCadFacesPeriodicityVector and _preCadEdgesPeriodicityVector void SavePreCADPeriodicity(std::ostream & save, const char* shapeType); diff --git a/src/BLSURFPlugin/BLSURFPlugin_Hypothesis_i.cxx b/src/BLSURFPlugin/BLSURFPlugin_Hypothesis_i.cxx index 4fb63f6..9495b48 100644 --- a/src/BLSURFPlugin/BLSURFPlugin_Hypothesis_i.cxx +++ b/src/BLSURFPlugin/BLSURFPlugin_Hypothesis_i.cxx @@ -24,6 +24,7 @@ // --- // #include "BLSURFPlugin_Hypothesis_i.hxx" +#include "BLSURFPlugin_BLSURF.hxx" #include #include @@ -1212,16 +1213,80 @@ void BLSURFPlugin_Hypothesis_i::SetHyperPatches(const BLSURFPlugin::THyperPatchL } if ( GetImpl()->GetHyperPatches() != patchList ) { + GetImpl()->SetHyperPatches( ::BLSURFPlugin_Hypothesis::THyperPatchEntriesList() ); // erase entries GetImpl()->SetHyperPatches( patchList ); SMESH::TPythonDump() << _this() << ".SetHyperPatches( " << hplDump << " )"; } } //============================================================================= -BLSURFPlugin::THyperPatchList* BLSURFPlugin_Hypothesis_i::GetHyperPatches() +void BLSURFPlugin_Hypothesis_i::SetHyperPatchEntries(const BLSURFPlugin::THyperPatchEntriesList& hpe) +{ + ::BLSURFPlugin_Hypothesis::THyperPatchEntriesList patchList( hpe.length() ); + SMESH_Comment hpeDump; + hpeDump << "["; + for ( size_t i = 0; i < patchList.size(); ++i ) + { + hpeDump << "[ "; + const BLSURFPlugin::THyperPatchEntries& entryList = hpe[ i ]; + for ( CORBA::ULong j = 0; j < entryList.length(); ++j ) + { + patchList[ i ].insert( entryList[ j ].in() ); + hpeDump << entryList[ j ].in() << ( j+1 < entryList.length() ? ", " : " ]" ); + } + hpeDump << ( i+1 < patchList.size() ? "," : "]"); + } + if ( GetImpl()->GetHyperPatchEntries() != patchList ) + { + GetImpl()->SetHyperPatches( ::BLSURFPlugin_Hypothesis::THyperPatchList(), /*notify=*/false ); + GetImpl()->SetHyperPatches( patchList ); + // TPythonDump converts entries to objects + SMESH::TPythonDump() << _this() << ".SetHyperPatchShapes( " << hpeDump << " )"; + } +} + +//============================================================================= +void BLSURFPlugin_Hypothesis_i::SetHyperPatchShapes(const BLSURFPlugin::THyperPatchShapesList& hpsl) +{ + BLSURFPlugin::THyperPatchEntriesList patchList; + patchList.length( hpsl.length() ); + for ( size_t i = 0; i < hpsl.length(); ++i ) + { + const GEOM::ListOfGO& shapeList = hpsl[ i ]; + BLSURFPlugin::THyperPatchEntries& entryList = patchList[ i ]; + entryList.length( shapeList.length() ); + for ( CORBA::ULong j = 0; j < shapeList.length(); ++j ) + { + CORBA::String_var entry = shapeList[ j ]->GetStudyEntry(); + if ( !entry.in() || !entry.in()[0] ) + THROW_SALOME_CORBA_EXCEPTION( "BLSURFPlugin_Hypothesis::SetHyperPatchShapes(), " + "Not published hyper-patch shape", SALOME::BAD_PARAM ); + entryList[ j ] = CORBA::string_dup( entry ); + } + } + this->SetHyperPatchEntries( patchList ); +} + +//============================================================================= +BLSURFPlugin::THyperPatchList* +BLSURFPlugin_Hypothesis_i::GetHyperPatches( GEOM::GEOM_Object_ptr mainShape ) { const ::BLSURFPlugin_Hypothesis::THyperPatchList& hpl = GetImpl()->GetHyperPatches(); - BLSURFPlugin::THyperPatchList* resHpl = new BLSURFPlugin::THyperPatchList(); + BLSURFPlugin::THyperPatchList* resHpl = new BLSURFPlugin::THyperPatchList(); + if ( hpl.empty() && + !CORBA::is_nil( mainShape ) && + !GetImpl()->GetHyperPatchEntries().empty() ) + { + // set IDs by entries + SMESH_Gen_i* smeshGen = SMESH_Gen_i::GetSMESHGen(); + TopoDS_Shape S = smeshGen->GeomObjectToShape( mainShape ); + if ( !S.IsNull() ) + { + std::map< std::string, TopoDS_Shape > entryToShape; + BLSURFPlugin_BLSURF::FillEntryToShape( GetImpl(), entryToShape ); + GetImpl()->SetHyperPatchIDsByEntry( S, entryToShape ); + } + } resHpl->length( hpl.size() ); ::BLSURFPlugin_Hypothesis::THyperPatchList::const_iterator hpIt = hpl.begin(); @@ -1238,6 +1303,27 @@ BLSURFPlugin::THyperPatchList* BLSURFPlugin_Hypothesis_i::GetHyperPatches() return resHpl; } +//============================================================================= +BLSURFPlugin::THyperPatchEntriesList* BLSURFPlugin_Hypothesis_i::GetHyperPatchShapes() +{ + const ::BLSURFPlugin_Hypothesis::THyperPatchEntriesList& hpel = GetImpl()->GetHyperPatchEntries(); + BLSURFPlugin::THyperPatchEntriesList* resHpl = new BLSURFPlugin::THyperPatchEntriesList(); + resHpl->length( hpel.size() ); + + ::BLSURFPlugin_Hypothesis::THyperPatchEntriesList::const_iterator hpIt = hpel.begin(); + for ( int i = 0; hpIt != hpel.end(); ++hpIt, ++i ) + { + const ::BLSURFPlugin_Hypothesis::THyperPatchEntries& hp = *hpIt; + BLSURFPlugin::THyperPatchEntries& resHp = (*resHpl)[ i ]; + resHp.length( hp.size() ); + + ::BLSURFPlugin_Hypothesis::THyperPatchEntries::const_iterator entry = hp.begin(); + for ( int j = 0; entry != hp.end(); ++entry, ++j ) + resHp[ j ] = CORBA::string_dup( entry->c_str() ); + } + return resHpl; +} + //============================================================================= /*! * BLSURFPlugin_Hypothesis_i::SetPreCADMergeEdges diff --git a/src/BLSURFPlugin/BLSURFPlugin_Hypothesis_i.hxx b/src/BLSURFPlugin/BLSURFPlugin_Hypothesis_i.hxx index 9dd6691..e6ccf2b 100644 --- a/src/BLSURFPlugin/BLSURFPlugin_Hypothesis_i.hxx +++ b/src/BLSURFPlugin/BLSURFPlugin_Hypothesis_i.hxx @@ -216,7 +216,10 @@ public: char* GetTags(); void SetHyperPatches(const BLSURFPlugin::THyperPatchList& hpl); - BLSURFPlugin::THyperPatchList* GetHyperPatches(); + BLSURFPlugin::THyperPatchList* GetHyperPatches( GEOM::GEOM_Object_ptr mainShape ); + void SetHyperPatchShapes(const BLSURFPlugin::THyperPatchShapesList& hpsl); + BLSURFPlugin::THyperPatchEntriesList* GetHyperPatchShapes(); + void SetHyperPatchEntries(const BLSURFPlugin::THyperPatchEntriesList& hpel); void SetPreCADMergeEdges(CORBA::Boolean theValue); CORBA::Boolean GetPreCADMergeEdges(); diff --git a/src/GUI/BLSURFPluginGUI_HypothesisCreator.cxx b/src/GUI/BLSURFPluginGUI_HypothesisCreator.cxx index 873f781..e13c6c5 100644 --- a/src/GUI/BLSURFPluginGUI_HypothesisCreator.cxx +++ b/src/GUI/BLSURFPluginGUI_HypothesisCreator.cxx @@ -2019,9 +2019,13 @@ void BLSURFPluginGUI_HypothesisCreator::retrieveParams() const } // Hyper patches + QString patchEntries; for ( int i = 0; i < data.hyperpatches.size(); ++i ) - that->addHyPatchToTable( data.hyperpatches[i] ); - + { + if ( i < data.hyperEntries.size() ) + patchEntries = data.hyperEntries[i]; + that->addHyPatchToTable( data.hyperpatches[i], patchEntries ); + } // update widgets that->myStdWidget->onPhysicalMeshChanged(); that->myStdWidget->onGeometricMeshChanged(); @@ -2229,8 +2233,14 @@ bool BLSURFPluginGUI_HypothesisCreator::readParamsFromHypo( BlsurfHypothesisData // Hyper Patches + GEOM::GEOM_Object_var geom = myHyPatchFaceSelector->GetGeomObjectByEntry( getMainShapeEntry() ); + if ( geom->_is_nil() ) + geom = myHyPatchFaceSelector->GetGeomObjectByEntry( getShapeEntry() ); + h_data.hyperpatches.clear(); - BLSURFPlugin::THyperPatchList_var patchList = h->GetHyperPatches(); + h_data.hyperEntries.clear(); + BLSURFPlugin::THyperPatchList_var patchList = h->GetHyperPatches( geom ); + BLSURFPlugin::THyperPatchEntriesList_var patchEntriesList = h->GetHyperPatchShapes(); for ( CORBA::ULong i = 0; i < patchList->length(); ++i ) { QString tags; @@ -2239,7 +2249,19 @@ bool BLSURFPluginGUI_HypothesisCreator::readParamsFromHypo( BlsurfHypothesisData tags += QString::number( patch[j] ) + " "; if ( !tags.isEmpty() ) h_data.hyperpatches.append( tags ); + + if ( patchEntriesList->length() == patchList->length() ) + { + QString entries; + BLSURFPlugin::THyperPatchEntries& patchEntries = patchEntriesList[i]; + for ( CORBA::ULong j = 0; j < patchEntries.length(); ++j ) + entries += patchEntries[j].in() + QString(" "); + if ( !entries.isEmpty() ) + h_data.hyperEntries.append( entries ); + } } + if ( h_data.hyperpatches.size() != h_data.hyperEntries.size() ) + h_data.hyperEntries.clear(); return true; } @@ -2531,8 +2553,10 @@ bool BLSURFPluginGUI_HypothesisCreator::storeParamsToHypo( const BlsurfHypothesi } // Hyper-patches - BLSURFPlugin::THyperPatchList_var hpl = new BLSURFPlugin::THyperPatchList(); - hpl->length( h_data.hyperpatches.size() ); + BLSURFPlugin::THyperPatchList_var hpl = new BLSURFPlugin::THyperPatchList(); + BLSURFPlugin::THyperPatchEntriesList_var hpel = new BLSURFPlugin::THyperPatchEntriesList(); + hpl ->length( h_data.hyperpatches.size() ); + hpel->length( h_data.hyperEntries.size() ); for ( int i = 0; i < h_data.hyperpatches.size(); ++i ) { @@ -2541,9 +2565,22 @@ bool BLSURFPluginGUI_HypothesisCreator::storeParamsToHypo( const BlsurfHypothesi patch.length( tags.size() ); for ( int j = 0; j < tags.size(); ++j ) - patch[ j ] = tags[ j ].toDouble(); + patch[ j ] = tags[ j ].toInt(); + + if ( i < h_data.hyperEntries.size() ) + { + QStringList entries = h_data.hyperEntries[i].split(" ", QString::SkipEmptyParts); + BLSURFPlugin::THyperPatchEntries& pe = hpel[ i ]; + pe.length( entries.size() ); + + for ( int j = 0; j < entries.size(); ++j ) + pe[ j ] = CORBA::string_dup( entries[ j ].toStdString().c_str() ); + } } - h->SetHyperPatches( hpl ); + if ( h_data.hyperEntries.size() == h_data.hyperpatches.size() ) + h->SetHyperPatchEntries( hpel ); + else + h->SetHyperPatches( hpl ); } // try @@ -2708,8 +2745,16 @@ QString BLSURFPluginGUI_HypothesisCreator::readParamsFromWidgets( BlsurfHypothes // Hyper-patches h_data.hyperpatches.clear(); + h_data.hyperEntries.clear(); for ( int row = 0; row < myHyPatchTable->rowCount(); ++row ) - h_data.hyperpatches.append( myHyPatchTable->item( row, 0 )->text() ); + { + QTableWidgetItem* cell = myHyPatchTable->item( row, 0 ); + h_data.hyperpatches.append( cell->text() ); + if ( cell->data( Qt::UserRole ).isValid() ) + h_data.hyperEntries.append( cell->data( Qt::UserRole ).toString() ); + } + if ( h_data.hyperpatches.size() != h_data.hyperEntries.size() ) + h_data.hyperEntries.clear(); return guiHyp; } @@ -3462,7 +3507,23 @@ void BLSURFPluginGUI_HypothesisCreator::onHyPatchAdd() QStringList tagList = myHyPatchTagsLE->text().split(" ", QString::SkipEmptyParts); if ( tagList.size() > 1 ) { - addHyPatchToTable( myHyPatchTagsLE->text() ); + LightApp_SelectionMgr* selMrg = SMESHGUI::GetSMESHGUI()->selectionMgr(); + SALOME_ListIO aList; + selMrg->selectedObjects( aList ); + QString entries; + for ( SALOME_ListIteratorOfListIO anIt( aList ); anIt.More(); anIt.Next() ) + { + Handle(SALOME_InteractiveObject) io = anIt.Value(); + GEOM::GEOM_Object_var go = myHyPatchFaceSelector->GetGeomObjectByEntry( io->getEntry() ); + if ( !CORBA::is_nil( go )) + entries += io->getEntry() + QString(" "); + else + { + entries.clear(); + break; + } + } + addHyPatchToTable( myHyPatchTagsLE->text(), entries ); myHyPatchTagsLE->setText(""); } } @@ -3473,12 +3534,17 @@ void BLSURFPluginGUI_HypothesisCreator::onHyPatchAdd() */ //================================================================================ -void BLSURFPluginGUI_HypothesisCreator::addHyPatchToTable(const QString& tags) +void BLSURFPluginGUI_HypothesisCreator::addHyPatchToTable(const QString& tags, + const QString& entries) { if ( tags.isEmpty() ) return; QTableWidgetItem* cell = new QTableWidgetItem( tags ); cell->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEnabled ); + if ( entries.isEmpty() ) + cell->setData( Qt::UserRole, QVariant() ); + else + cell->setData( Qt::UserRole, entries ); int row = myHyPatchTable->rowCount(); myHyPatchTable->insertRow( row ); diff --git a/src/GUI/BLSURFPluginGUI_HypothesisCreator.h b/src/GUI/BLSURFPluginGUI_HypothesisCreator.h index 9533eec..2cf2c11 100644 --- a/src/GUI/BLSURFPluginGUI_HypothesisCreator.h +++ b/src/GUI/BLSURFPluginGUI_HypothesisCreator.h @@ -186,7 +186,7 @@ typedef struct TGroupNameEnfVertexListMap groupNameEnfVertexListMap; */ TPreCadPeriodicityVector preCadPeriodicityVector; - QStringList hyperpatches; + QStringList hyperpatches, hyperEntries; QString myName; } BlsurfHypothesisData; @@ -271,7 +271,7 @@ private: static LightApp_SelectionMgr* selectionMgr(); void avoidSimultaneousSelection(ListOfWidgets &myCustomWidgets) const; void AddPreCadSequenceToVector(BlsurfHypothesisData& h_data, BLSURFPlugin::TPeriodicityList_var preCadFacePeriodicityVector, bool onFace) const; - void addHyPatchToTable(const QString& tags); + void addHyPatchToTable(const QString& tags, const QString& entries); bool hasGeom() const; private: -- 2.39.2