From 0b909dd4d9814131c841c34a8d4146616fd034f4 Mon Sep 17 00:00:00 2001 From: vsv Date: Thu, 30 Mar 2006 13:57:19 +0000 Subject: [PATCH] Read groups --- src/DriverUNV/DriverUNV_R_SMDS_Mesh.cxx | 68 ++++++++++++++++++++++++- src/DriverUNV/DriverUNV_R_SMDS_Mesh.h | 20 ++++++++ src/DriverUNV/UNV2417_Structure.cxx | 46 ++++++++++++++--- src/DriverUNV/UNV2417_Structure.hxx | 3 ++ src/SMDS/SMDS_MeshGroup.hxx | 13 +++++ src/SMESH_I/SMESH_Mesh_i.cxx | 56 +++++++++++++------- src/SMESH_I/SMESH_Mesh_i.hxx | 2 + 7 files changed, 181 insertions(+), 27 deletions(-) diff --git a/src/DriverUNV/DriverUNV_R_SMDS_Mesh.cxx b/src/DriverUNV/DriverUNV_R_SMDS_Mesh.cxx index bc38d269b..70a913602 100644 --- a/src/DriverUNV/DriverUNV_R_SMDS_Mesh.cxx +++ b/src/DriverUNV/DriverUNV_R_SMDS_Mesh.cxx @@ -19,6 +19,7 @@ // #include "DriverUNV_R_SMDS_Mesh.h" #include "SMDS_Mesh.hxx" +#include "SMDS_MeshGroup.hxx" #include "utilities.h" @@ -37,6 +38,13 @@ static int MYDEBUG = 0; #endif +DriverUNV_R_SMDS_Mesh::~DriverUNV_R_SMDS_Mesh() +{ + if (myGroup != 0) + delete myGroup; +} + + Driver_Mesh::Status DriverUNV_R_SMDS_Mesh::Perform() { Status aResult = DRS_OK; @@ -73,7 +81,6 @@ Driver_Mesh::Status DriverUNV_R_SMDS_Mesh::Perform() aLabel); } else { - cout<<"### Id of element = "<AddEdgeWithID(aRec.node_labels[0], aRec.node_labels[1], @@ -248,8 +255,67 @@ Driver_Mesh::Status DriverUNV_R_SMDS_Mesh::Perform() } { using namespace UNV2417; + in_stream.seekg(0); TDataSet aDataSet2417; UNV2417::Read(in_stream,aDataSet2417); + if(MYDEBUG) MESSAGE("Perform - aDataSet2417.size() = "< 0) { + myGroup = new SMDS_MeshGroup(myMesh); + TDataSet::const_iterator anIter = aDataSet2417.begin(); + for(; anIter != aDataSet2417.end(); anIter++){ + const TGroupId& aLabel = anIter->first; + const TRecord& aRec = anIter->second; + //SMDS_MeshGroup* aNewGroup = (SMDS_MeshGroup*) myGroup->AddSubGroup(SMDSAbs_Edge); + //myGroupNames.insert(TGroupNamesMap::value_type(aNewGroup, aRec.GroupName)); + //myGroupId.insert(TGroupIdMap::value_type(aNewGroup, aLabel)); + + int aNodesNb = aRec.NodeList.size(); + int i; + if (aNodesNb > 0) { + SMDS_MeshGroup* aNodesGroup = (SMDS_MeshGroup*) myGroup->AddSubGroup(SMDSAbs_Node); + std::string aGrName = aRec.GroupName + "_Nodes"; + myGroupNames.insert(TGroupNamesMap::value_type(aNodesGroup, aGrName)); + myGroupId.insert(TGroupIdMap::value_type(aNodesGroup, aLabel)); + + for (i = 0; i < aNodesNb; i++) { + const SMDS_MeshNode* aNode = myMesh->FindNode(aRec.NodeList[i]); + if (aNode) + aNodesGroup->Add(aNode); + } + } + int aElementsNb = aRec.ElementList.size(); + if (aElementsNb > 0){ + SMDS_MeshGroup* aEdgesGroup = 0; + SMDS_MeshGroup* aFacesGroup = 0; + + for (i = 0; i < aElementsNb; i++) { + const SMDS_MeshElement* aElement = myMesh->FindElement(aRec.ElementList[i]); + if (aElement) { + switch (aElement->GetType()) { + case SMDSAbs_Edge: + if (!aEdgesGroup) { + aEdgesGroup = (SMDS_MeshGroup*) myGroup->AddSubGroup(SMDSAbs_Edge); + std::string aEdgesGrName = aRec.GroupName + "_Edges"; + myGroupNames.insert(TGroupNamesMap::value_type(aEdgesGroup, aEdgesGrName)); + myGroupId.insert(TGroupIdMap::value_type(aEdgesGroup, aLabel)); + } + aEdgesGroup->Add(aElement); + break; + case SMDSAbs_Face: + if (!aFacesGroup) { + aFacesGroup = (SMDS_MeshGroup*) myGroup->AddSubGroup(SMDSAbs_Face); + std::string aFacesGrName = aRec.GroupName + "_Faces"; + myGroupNames.insert(TGroupNamesMap::value_type(aFacesGroup, aFacesGrName)); + myGroupId.insert(TGroupIdMap::value_type(aFacesGroup, aLabel)); + } + aFacesGroup->Add(aElement); + break; + } + } + } + } + } + } } } catch(const std::exception& exc){ diff --git a/src/DriverUNV/DriverUNV_R_SMDS_Mesh.h b/src/DriverUNV/DriverUNV_R_SMDS_Mesh.h index 46c6ad347..a07e9a5de 100644 --- a/src/DriverUNV/DriverUNV_R_SMDS_Mesh.h +++ b/src/DriverUNV/DriverUNV_R_SMDS_Mesh.h @@ -21,13 +21,33 @@ #define _INCLUDE_DRIVERUNV_R_SMDS_MESH #include "Driver_SMDS_Mesh.h" +#include +#include + class SMDS_Mesh; +class SMDS_MeshGroup; + + +typedef std::map TGroupNamesMap; +typedef std::map TGroupIdMap; class DriverUNV_R_SMDS_Mesh: public Driver_SMDS_Mesh { public: + DriverUNV_R_SMDS_Mesh():Driver_SMDS_Mesh(),myGroup(0) {}; + ~DriverUNV_R_SMDS_Mesh(); + virtual Status Perform(); + + const SMDS_MeshGroup* GetGroup() const { return myGroup;} + const TGroupNamesMap& GetGroupNamesMap() const { return myGroupNames; } + const TGroupIdMap& GetGroupIdMap() const { return myGroupId; } + + private: + SMDS_MeshGroup* myGroup; + TGroupNamesMap myGroupNames; + TGroupIdMap myGroupId; }; #endif diff --git a/src/DriverUNV/UNV2417_Structure.cxx b/src/DriverUNV/UNV2417_Structure.cxx index d68ef3b5b..f5e84926c 100644 --- a/src/DriverUNV/UNV2417_Structure.cxx +++ b/src/DriverUNV/UNV2417_Structure.cxx @@ -11,20 +11,43 @@ static int MYDEBUG = 1; static int MYDEBUG = 0; #endif -static string _label_dataset = "2417"; + +static string _group_labels[] = {"2417", "2429", "2430", "2432", "2435"}; +#define NBGROUP 5 + +//static string _label_dataset = "2435"; void UNV2417::Read(std::ifstream& in_stream, TDataSet& theDataSet) { if(!in_stream.good()) EXCEPTION(runtime_error,"ERROR: Input file not good."); - /* - * adjust the \p istream to our - * position - */ - if(!beginning_of_dataset(in_stream,_label_dataset)) - EXCEPTION(runtime_error,"WARNING: Could not find "<<_label_dataset<<" dataset!"); + std::string olds, news; + + while(true){ + in_stream >> olds >> news; + /* + * a "-1" followed by a number means the beginning of a dataset + * stop combing at the end of the file + */ + while( ((olds != "-1") || (news == "-1") ) && !in_stream.eof() ){ + olds = news; + in_stream >> news; + } + if(in_stream.eof()) + return; + for (int i = 0; i < NBGROUP; i++) { + if (news == _group_labels[i]) { + ReadGroup(news, in_stream, theDataSet); + } + } + } +} + + +void UNV2417::ReadGroup(const std::string& myGroupLabel, std::ifstream& in_stream, TDataSet& theDataSet) +{ TGroupId aId; for(; !in_stream.eof();){ in_stream >> aId ; @@ -41,14 +64,21 @@ void UNV2417::Read(std::ifstream& in_stream, TDataSet& theDataSet) in_stream>>aTmp; in_stream>>aTmp; in_stream>>aTmp; + in_stream>>aTmp; in_stream>>n_nodes; + in_stream>>aRec.GroupName; + int aElType; int aElId; int aNum; - for(int j=0; j < n_nodes; j++){ + for(int j=0; j < n_nodes; j++){ in_stream>>aElType; in_stream>>aElId; + if (myGroupLabel.compare("2435") == 0) { + in_stream>>aTmp; + in_stream>>aTmp; + } switch (aElType) { case 7: // Nodes aNum = aRec.NodeList.size(); diff --git a/src/DriverUNV/UNV2417_Structure.hxx b/src/DriverUNV/UNV2417_Structure.hxx index de19e06de..b502c7b78 100644 --- a/src/DriverUNV/UNV2417_Structure.hxx +++ b/src/DriverUNV/UNV2417_Structure.hxx @@ -23,6 +23,7 @@ #include #include #include +#include namespace UNV2417{ @@ -30,6 +31,7 @@ namespace UNV2417{ typedef std::vector TListOfId; // Nodal connectivitiesList of Id struct TRecord{ + std::string GroupName; TListOfId NodeList; TListOfId ElementList; }; @@ -38,6 +40,7 @@ namespace UNV2417{ typedef std::map TDataSet; void Read(std::ifstream& in_stream, TDataSet& theDataSet); + void ReadGroup(const std::string& myGroupLabel, std::ifstream& in_stream, TDataSet& theDataSet); }; diff --git a/src/SMDS/SMDS_MeshGroup.hxx b/src/SMDS/SMDS_MeshGroup.hxx index 37893fab4..a670deb5e 100644 --- a/src/SMDS/SMDS_MeshGroup.hxx +++ b/src/SMDS/SMDS_MeshGroup.hxx @@ -60,6 +60,8 @@ class SMDS_WNT_EXPORT SMDS_MeshGroup:public SMDS_MeshObject bool IsEmpty() const { return myElements.empty(); } int Extent() const { return myElements.size(); } + int SubGroupsNb() const { return myChildren.size(); } + SMDSAbs_ElementType GetType() const { return myType; } bool Contains(const SMDS_MeshElement * theElem) const; @@ -72,16 +74,27 @@ class SMDS_WNT_EXPORT SMDS_MeshGroup:public SMDS_MeshObject const SMDS_MeshElement* Next() const { return *(const_cast(myIterator))++; } + void InitSubGroupsIterator() const + { const_cast(myGroupIterator) = myChildren.begin(); } + + bool MoreSubGroups() const { return myGroupIterator != myChildren.end(); } + + const SMDS_MeshGroup* NextSubGroup() const + { return *(const_cast(myGroupIterator))++; } + private: SMDS_MeshGroup(SMDS_MeshGroup* theParent, const SMDSAbs_ElementType theType = SMDSAbs_All); typedef std::set::const_iterator TIterator; + typedef std::list::const_iterator TGroupIterator; + const SMDS_Mesh * myMesh; SMDSAbs_ElementType myType; std::set myElements; SMDS_MeshGroup * myParent; std::list myChildren; TIterator myIterator; + TGroupIterator myGroupIterator; }; #endif diff --git a/src/SMESH_I/SMESH_Mesh_i.cxx b/src/SMESH_I/SMESH_Mesh_i.cxx index 05d8ff0cf..86277a0e0 100644 --- a/src/SMESH_I/SMESH_Mesh_i.cxx +++ b/src/SMESH_I/SMESH_Mesh_i.cxx @@ -73,6 +73,8 @@ using SMESH::TPythonDump; int SMESH_Mesh_i::myIdGenerator = 0; + + //============================================================================= /*! * Constructor @@ -235,6 +237,18 @@ int SMESH_Mesh_i::ImportUNVFile( const char* theFileName ) // Read mesh with name = into SMESH_Mesh _impl->UNVToMesh( theFileName ); + CreateGroupServants(); + + SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy(); + if ( !aStudy->_is_nil() ) { + // publishing of the groups in the study (sub-meshes are out of scope of UNV import) + map::iterator it = _mapGroups.begin(); + for (; it != _mapGroups.end(); it++ ) { + SMESH::SMESH_GroupBase_var aGroup = SMESH::SMESH_GroupBase::_duplicate( it->second ); + _gen_i->PublishGroup( aStudy, _this(), aGroup, + GEOM::GEOM_Object::_nil(), aGroup->GetName()); + } + } return 1; } @@ -266,24 +280,7 @@ int SMESH_Mesh_i::importMEDFile( const char* theFileName, const char* theMeshNam { // Read mesh with name = and all its groups into SMESH_Mesh int status = _impl->MEDToMesh( theFileName, theMeshName ); - - // Create group servants, if any groups were imported - list aGroupIds = _impl->GetGroupIds(); - for ( list::iterator it = aGroupIds.begin(); it != aGroupIds.end(); it++ ) { - SMESH_Group_i* aGroupImpl = new SMESH_Group_i( SMESH_Gen_i::GetPOA(), this, *it ); - - // PAL7962: san -- To ensure correct mapping of servant and correct reference counting in GenericObj_i - SMESH_Gen_i::GetPOA()->activate_object( aGroupImpl ); - aGroupImpl->Register(); - // PAL7962: san -- To ensure correct mapping of servant and correct reference counting in GenericObj_i - - SMESH::SMESH_Group_var aGroup = SMESH::SMESH_Group::_narrow( aGroupImpl->_this() ); - _mapGroups[*it] = SMESH::SMESH_Group::_duplicate( aGroup ); - - // register CORBA object for persistence - int nextId = _gen_i->RegisterObject( aGroup ); - if(MYDEBUG) MESSAGE( "Add group to map with id = "<< nextId); - } + CreateGroupServants(); return status; } @@ -1581,3 +1578,26 @@ CORBA::Long SMESH_Mesh_i::GetMeshPtr() { return (CORBA::Long)_impl; } + + +void SMESH_Mesh_i::CreateGroupServants() +{ + // Create group servants, if any groups were imported + list aGroupIds = _impl->GetGroupIds(); + for ( list::iterator it = aGroupIds.begin(); it != aGroupIds.end(); it++ ) { + SMESH_Group_i* aGroupImpl = new SMESH_Group_i( SMESH_Gen_i::GetPOA(), this, *it ); + + // PAL7962: san -- To ensure correct mapping of servant and correct reference counting in GenericObj_i + SMESH_Gen_i::GetPOA()->activate_object( aGroupImpl ); + aGroupImpl->Register(); + // PAL7962: san -- To ensure correct mapping of servant and correct reference counting in GenericObj_i + + SMESH::SMESH_Group_var aGroup = SMESH::SMESH_Group::_narrow( aGroupImpl->_this() ); + _mapGroups[*it] = SMESH::SMESH_Group::_duplicate( aGroup ); + + // register CORBA object for persistence + int nextId = _gen_i->RegisterObject( aGroup ); + if(MYDEBUG) MESSAGE( "Add group to map with id = "<< nextId); + } +} + diff --git a/src/SMESH_I/SMESH_Mesh_i.hxx b/src/SMESH_I/SMESH_Mesh_i.hxx index 9167f325d..dcfa1a33d 100644 --- a/src/SMESH_I/SMESH_Mesh_i.hxx +++ b/src/SMESH_I/SMESH_Mesh_i.hxx @@ -260,6 +260,8 @@ public: map _mapSubMesh; //NRI private: + void CreateGroupServants(); + static int myIdGenerator; ::SMESH_Mesh* _impl; // :: force no namespace here SMESH_Gen_i* _gen_i; -- 2.39.2