mirror of
https://git.salome-platform.org/gitpub/modules/smesh.git
synced 2024-12-29 10:50:34 +05:00
Read groups
This commit is contained in:
parent
bff8d08b7b
commit
0b909dd4d9
@ -19,6 +19,7 @@
|
|||||||
//
|
//
|
||||||
#include "DriverUNV_R_SMDS_Mesh.h"
|
#include "DriverUNV_R_SMDS_Mesh.h"
|
||||||
#include "SMDS_Mesh.hxx"
|
#include "SMDS_Mesh.hxx"
|
||||||
|
#include "SMDS_MeshGroup.hxx"
|
||||||
|
|
||||||
#include "utilities.h"
|
#include "utilities.h"
|
||||||
|
|
||||||
@ -37,6 +38,13 @@ static int MYDEBUG = 0;
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
DriverUNV_R_SMDS_Mesh::~DriverUNV_R_SMDS_Mesh()
|
||||||
|
{
|
||||||
|
if (myGroup != 0)
|
||||||
|
delete myGroup;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
Driver_Mesh::Status DriverUNV_R_SMDS_Mesh::Perform()
|
Driver_Mesh::Status DriverUNV_R_SMDS_Mesh::Perform()
|
||||||
{
|
{
|
||||||
Status aResult = DRS_OK;
|
Status aResult = DRS_OK;
|
||||||
@ -73,7 +81,6 @@ Driver_Mesh::Status DriverUNV_R_SMDS_Mesh::Perform()
|
|||||||
aLabel);
|
aLabel);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
cout<<"### Id of element = "<<aRec.fe_descriptor_id<<endl;
|
|
||||||
// quadratic edge (with 3 nodes)
|
// quadratic edge (with 3 nodes)
|
||||||
anElement = myMesh->AddEdgeWithID(aRec.node_labels[0],
|
anElement = myMesh->AddEdgeWithID(aRec.node_labels[0],
|
||||||
aRec.node_labels[1],
|
aRec.node_labels[1],
|
||||||
@ -248,8 +255,67 @@ Driver_Mesh::Status DriverUNV_R_SMDS_Mesh::Perform()
|
|||||||
}
|
}
|
||||||
{
|
{
|
||||||
using namespace UNV2417;
|
using namespace UNV2417;
|
||||||
|
in_stream.seekg(0);
|
||||||
TDataSet aDataSet2417;
|
TDataSet aDataSet2417;
|
||||||
UNV2417::Read(in_stream,aDataSet2417);
|
UNV2417::Read(in_stream,aDataSet2417);
|
||||||
|
if(MYDEBUG) MESSAGE("Perform - aDataSet2417.size() = "<<aDataSet2417.size());
|
||||||
|
if (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){
|
catch(const std::exception& exc){
|
||||||
|
@ -21,13 +21,33 @@
|
|||||||
#define _INCLUDE_DRIVERUNV_R_SMDS_MESH
|
#define _INCLUDE_DRIVERUNV_R_SMDS_MESH
|
||||||
|
|
||||||
#include "Driver_SMDS_Mesh.h"
|
#include "Driver_SMDS_Mesh.h"
|
||||||
|
#include <map>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
|
||||||
class SMDS_Mesh;
|
class SMDS_Mesh;
|
||||||
|
class SMDS_MeshGroup;
|
||||||
|
|
||||||
|
|
||||||
|
typedef std::map<SMDS_MeshGroup*, std::string> TGroupNamesMap;
|
||||||
|
typedef std::map<SMDS_MeshGroup*, int> TGroupIdMap;
|
||||||
|
|
||||||
class DriverUNV_R_SMDS_Mesh: public Driver_SMDS_Mesh
|
class DriverUNV_R_SMDS_Mesh: public Driver_SMDS_Mesh
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
DriverUNV_R_SMDS_Mesh():Driver_SMDS_Mesh(),myGroup(0) {};
|
||||||
|
~DriverUNV_R_SMDS_Mesh();
|
||||||
|
|
||||||
virtual Status Perform();
|
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
|
#endif
|
||||||
|
@ -11,20 +11,43 @@ static int MYDEBUG = 1;
|
|||||||
static int MYDEBUG = 0;
|
static int MYDEBUG = 0;
|
||||||
#endif
|
#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)
|
void UNV2417::Read(std::ifstream& in_stream, TDataSet& theDataSet)
|
||||||
{
|
{
|
||||||
if(!in_stream.good())
|
if(!in_stream.good())
|
||||||
EXCEPTION(runtime_error,"ERROR: Input file not good.");
|
EXCEPTION(runtime_error,"ERROR: Input file not good.");
|
||||||
|
|
||||||
/*
|
std::string olds, news;
|
||||||
* adjust the \p istream to our
|
|
||||||
* position
|
while(true){
|
||||||
*/
|
in_stream >> olds >> news;
|
||||||
if(!beginning_of_dataset(in_stream,_label_dataset))
|
/*
|
||||||
EXCEPTION(runtime_error,"WARNING: Could not find "<<_label_dataset<<" dataset!");
|
* 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;
|
TGroupId aId;
|
||||||
for(; !in_stream.eof();){
|
for(; !in_stream.eof();){
|
||||||
in_stream >> aId ;
|
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>>aTmp;
|
in_stream>>aTmp;
|
||||||
|
in_stream>>aTmp;
|
||||||
in_stream>>n_nodes;
|
in_stream>>n_nodes;
|
||||||
|
|
||||||
|
in_stream>>aRec.GroupName;
|
||||||
|
|
||||||
int aElType;
|
int aElType;
|
||||||
int aElId;
|
int aElId;
|
||||||
int aNum;
|
int aNum;
|
||||||
for(int j=0; j < n_nodes; j++){
|
for(int j=0; j < n_nodes; j++){
|
||||||
in_stream>>aElType;
|
in_stream>>aElType;
|
||||||
in_stream>>aElId;
|
in_stream>>aElId;
|
||||||
|
if (myGroupLabel.compare("2435") == 0) {
|
||||||
|
in_stream>>aTmp;
|
||||||
|
in_stream>>aTmp;
|
||||||
|
}
|
||||||
switch (aElType) {
|
switch (aElType) {
|
||||||
case 7: // Nodes
|
case 7: // Nodes
|
||||||
aNum = aRec.NodeList.size();
|
aNum = aRec.NodeList.size();
|
||||||
|
@ -23,6 +23,7 @@
|
|||||||
#include <map>
|
#include <map>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
|
||||||
namespace UNV2417{
|
namespace UNV2417{
|
||||||
@ -30,6 +31,7 @@ namespace UNV2417{
|
|||||||
typedef std::vector<int> TListOfId; // Nodal connectivitiesList of Id
|
typedef std::vector<int> TListOfId; // Nodal connectivitiesList of Id
|
||||||
|
|
||||||
struct TRecord{
|
struct TRecord{
|
||||||
|
std::string GroupName;
|
||||||
TListOfId NodeList;
|
TListOfId NodeList;
|
||||||
TListOfId ElementList;
|
TListOfId ElementList;
|
||||||
};
|
};
|
||||||
@ -38,6 +40,7 @@ namespace UNV2417{
|
|||||||
typedef std::map<TGroupId, TRecord> TDataSet;
|
typedef std::map<TGroupId, TRecord> TDataSet;
|
||||||
|
|
||||||
void Read(std::ifstream& in_stream, TDataSet& theDataSet);
|
void Read(std::ifstream& in_stream, TDataSet& theDataSet);
|
||||||
|
void ReadGroup(const std::string& myGroupLabel, std::ifstream& in_stream, TDataSet& theDataSet);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -60,6 +60,8 @@ class SMDS_WNT_EXPORT SMDS_MeshGroup:public SMDS_MeshObject
|
|||||||
bool IsEmpty() const { return myElements.empty(); }
|
bool IsEmpty() const { return myElements.empty(); }
|
||||||
int Extent() const { return myElements.size(); }
|
int Extent() const { return myElements.size(); }
|
||||||
|
|
||||||
|
int SubGroupsNb() const { return myChildren.size(); }
|
||||||
|
|
||||||
SMDSAbs_ElementType GetType() const { return myType; }
|
SMDSAbs_ElementType GetType() const { return myType; }
|
||||||
|
|
||||||
bool Contains(const SMDS_MeshElement * theElem) const;
|
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
|
const SMDS_MeshElement* Next() const
|
||||||
{ return *(const_cast<TIterator&>(myIterator))++; }
|
{ return *(const_cast<TIterator&>(myIterator))++; }
|
||||||
|
|
||||||
|
void InitSubGroupsIterator() const
|
||||||
|
{ const_cast<TGroupIterator&>(myGroupIterator) = myChildren.begin(); }
|
||||||
|
|
||||||
|
bool MoreSubGroups() const { return myGroupIterator != myChildren.end(); }
|
||||||
|
|
||||||
|
const SMDS_MeshGroup* NextSubGroup() const
|
||||||
|
{ return *(const_cast<TGroupIterator&>(myGroupIterator))++; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
SMDS_MeshGroup(SMDS_MeshGroup* theParent,
|
SMDS_MeshGroup(SMDS_MeshGroup* theParent,
|
||||||
const SMDSAbs_ElementType theType = SMDSAbs_All);
|
const SMDSAbs_ElementType theType = SMDSAbs_All);
|
||||||
|
|
||||||
typedef std::set<const SMDS_MeshElement *>::const_iterator TIterator;
|
typedef std::set<const SMDS_MeshElement *>::const_iterator TIterator;
|
||||||
|
typedef std::list<const SMDS_MeshGroup *>::const_iterator TGroupIterator;
|
||||||
|
|
||||||
const SMDS_Mesh * myMesh;
|
const SMDS_Mesh * myMesh;
|
||||||
SMDSAbs_ElementType myType;
|
SMDSAbs_ElementType myType;
|
||||||
std::set<const SMDS_MeshElement *> myElements;
|
std::set<const SMDS_MeshElement *> myElements;
|
||||||
SMDS_MeshGroup * myParent;
|
SMDS_MeshGroup * myParent;
|
||||||
std::list<const SMDS_MeshGroup*> myChildren;
|
std::list<const SMDS_MeshGroup*> myChildren;
|
||||||
TIterator myIterator;
|
TIterator myIterator;
|
||||||
|
TGroupIterator myGroupIterator;
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
@ -73,6 +73,8 @@ using SMESH::TPythonDump;
|
|||||||
|
|
||||||
int SMESH_Mesh_i::myIdGenerator = 0;
|
int SMESH_Mesh_i::myIdGenerator = 0;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//=============================================================================
|
//=============================================================================
|
||||||
/*!
|
/*!
|
||||||
* Constructor
|
* Constructor
|
||||||
@ -235,6 +237,18 @@ int SMESH_Mesh_i::ImportUNVFile( const char* theFileName )
|
|||||||
// Read mesh with name = <theMeshName> into SMESH_Mesh
|
// Read mesh with name = <theMeshName> into SMESH_Mesh
|
||||||
_impl->UNVToMesh( theFileName );
|
_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<int, SMESH::SMESH_GroupBase_ptr>::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;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -266,24 +280,7 @@ int SMESH_Mesh_i::importMEDFile( const char* theFileName, const char* theMeshNam
|
|||||||
{
|
{
|
||||||
// Read mesh with name = <theMeshName> and all its groups into SMESH_Mesh
|
// Read mesh with name = <theMeshName> and all its groups into SMESH_Mesh
|
||||||
int status = _impl->MEDToMesh( theFileName, theMeshName );
|
int status = _impl->MEDToMesh( theFileName, theMeshName );
|
||||||
|
CreateGroupServants();
|
||||||
// Create group servants, if any groups were imported
|
|
||||||
list<int> aGroupIds = _impl->GetGroupIds();
|
|
||||||
for ( list<int>::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);
|
|
||||||
}
|
|
||||||
|
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
@ -1581,3 +1578,26 @@ CORBA::Long SMESH_Mesh_i::GetMeshPtr()
|
|||||||
{
|
{
|
||||||
return (CORBA::Long)_impl;
|
return (CORBA::Long)_impl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void SMESH_Mesh_i::CreateGroupServants()
|
||||||
|
{
|
||||||
|
// Create group servants, if any groups were imported
|
||||||
|
list<int> aGroupIds = _impl->GetGroupIds();
|
||||||
|
for ( list<int>::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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -260,6 +260,8 @@ public:
|
|||||||
map<int, ::SMESH_subMesh*> _mapSubMesh; //NRI
|
map<int, ::SMESH_subMesh*> _mapSubMesh; //NRI
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void CreateGroupServants();
|
||||||
|
|
||||||
static int myIdGenerator;
|
static int myIdGenerator;
|
||||||
::SMESH_Mesh* _impl; // :: force no namespace here
|
::SMESH_Mesh* _impl; // :: force no namespace here
|
||||||
SMESH_Gen_i* _gen_i;
|
SMESH_Gen_i* _gen_i;
|
||||||
|
Loading…
Reference in New Issue
Block a user