-// Copyright (C) 2004-2012 CEA/DEN, EDF R&D
+// Copyright (C) 2004-2013 CEA/DEN, EDF R&D
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
#include "SMESH_MeshEditor.hxx"
#include "SMESH_OctreeNode.hxx"
#include "SMESH_Group.hxx"
+#include <SMESH_subMeshEventListener.hxx>
+#include <SMESH_HypoFilter.hxx>
#include "SMDS_MeshElement.hxx"
#include "SMDS_MeshNode.hxx"
#define HOLE_ID -1
-#ifndef GHS3D_VERSION
-#define GHS3D_VERSION 41
-#endif
-
typedef const list<const SMDS_MeshFace*> TTriaList;
static void removeFile( const TCollection_AsciiString& fileName )
GEOM::GEOM_Object_var aGeomObj;
TopoDS_Shape S = TopoDS_Shape();
SALOMEDS::SObject_var aSObj = myStudy->FindObjectID( entry.c_str() );
- SALOMEDS::GenericAttribute_var anAttr;
-
- if (!aSObj->_is_nil() && aSObj->FindAttribute(anAttr, "AttributeIOR")) {
- SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
- CORBA::String_var aVal = anIOR->Value();
- CORBA::Object_var obj = myStudy->ConvertIORToObject(aVal);
+ if (!aSObj->_is_nil() ) {
+ CORBA::Object_var obj = aSObj->GetObject();
aGeomObj = GEOM::GEOM_Object::_narrow(obj);
+ aSObj->UnRegister();
}
if ( !aGeomObj->_is_nil() )
S = smeshGen_i->GeomObjectToShape( aGeomObj.in() );
return meshDS->ShapeToIndex( solids(2) );
}
-//=======================================================================
-//function : countShape
-//purpose :
-//=======================================================================
-
+// //=======================================================================
+// //function : countShape
+// //purpose :
+// //=======================================================================
+//
// template < class Mesh, class Shape >
// static int countShape( Mesh* mesh, Shape shape ) {
// TopExp_Explorer expShape ( mesh->ShapeToMesh(), shape );
// }
// return nbShape;
// }
-
-//=======================================================================
-//function : getShape
-//purpose :
-//=======================================================================
-
+//
+// //=======================================================================
+// //function : getShape
+// //purpose :
+// //=======================================================================
+//
// template < class Mesh, class Shape, class Tab >
// void getShape(Mesh* mesh, Shape shape, Tab *t_Shape) {
// TopExp_Explorer expShape ( mesh->ShapeToMesh(), shape );
// }
// return;
// }
-
-// //=======================================================================
-// //function : findEdgeID
-// //purpose :
-// //=======================================================================
+//
+// // //=======================================================================
+// // //function : findEdgeID
+// // //purpose :
+// // //=======================================================================
//
// static int findEdgeID(const SMDS_MeshNode* aNode,
// const SMESHDS_Mesh* theMesh,
// delete [] t_Dist;
// return theMesh->ShapeToIndex( foundEdge );
// }
-
-
-//=======================================================================
-//function : readGMFFile
-//purpose : read GMF file with geometry associated to mesh
-// TODO
-//=======================================================================
-
-// static bool readGMFFile(
-// const int fileOpen,
+//
+//
+// // =======================================================================
+// // function : readGMFFile
+// // purpose : read GMF file with geometry associated to mesh
+// // =======================================================================
+//
+// static bool readGMFFile(const int fileOpen,
// const char* theFileName,
// SMESH_Mesh& theMesh,
// const int nbShape,
//
//
// // The keyword does not exist yet => to update when it is created
-// // int nbTriangle = GmfStatKwd(InpMsh, GmfSubdomain);
+// // int nbSubdomains = GmfStatKwd(InpMsh, GmfSubdomain);
// // int id_tri[3];
//
//
// // case GmfHexahedra:
// {
// int nodeDim, shapeID, *nodeID;
-// SMDS_MeshNode** node;
+// const SMDS_MeshNode** node;
// // std::vector< SMDS_MeshNode* > enfNode( nbRef );
// SMDS_MeshElement * aGMFElement;
//
-// node = new SMDS_MeshNode*[nbRef];
+// node = new const SMDS_MeshNode*[nbRef];
// nodeID = new int[ nbRef ];
//
// for ( int iElem = 0; iElem < nbElem; iElem++ )
//purpose : Update or create groups in mesh
//=======================================================================
-static void addElemInMeshGroup(SMESH_Mesh* theMesh,
- const SMDS_MeshElement* anElem,
- std::string groupName,
- std::set<std::string> groupsToRemove)
+static void addElemInMeshGroup(SMESH_Mesh* theMesh,
+ const SMDS_MeshElement* anElem,
+ std::string& groupName,
+ std::set<std::string>& groupsToRemove)
{
+ if ( !anElem ) return; // issue 0021776
+
bool groupDone = false;
SMESH_Mesh::GroupIteratorPtr grIt = theMesh->GetGroups();
while (grIt->more()) {
groupDone = true;
}
if (!groupDone)
- throw SALOME_Exception(LOCALIZED("A enforced vertex node was not added to a group"));
+ throw SALOME_Exception(LOCALIZED("A given element was not added to a group"));
}
// for ( int iRef = 0; iRef < nbRef; iRef++ )
// nodeAssigne[ nodeID[ iRef ]] = 1;
}
+ break;
case GmfTetrahedra:
if ( elemSearcher ) {
// Issue 0020682. Avoid creating nodes and tetras at place where
TopAbs_State result = pntCls->GetPointState( myPoint );
if ( result == TopAbs_OUT )
continue;
- if (pntCls->FindElementsByPoint(myPoint, SMDSAbs_Node, foundElems) == 0)
- continue;
+ //if (pntCls->FindElementsByPoint(myPoint, SMDSAbs_Node, foundElems) == 0)
+ //continue;
// if ( result != TopAbs_IN )
// continue;
return false;
}
int TypTab[] = {GmfSca};
+ double ValTab[] = {0.0};
GmfSetKwd(idxRequired, GmfVertices, requiredNodes + solSize);
GmfSetKwd(idxSol, GmfSolAtVertices, requiredNodes + solSize, 1, TypTab);
// int usedEnforcedNodes = 0;
// std::string gn = "";
for (ghs3dNodeIt = theRequiredNodes.begin();ghs3dNodeIt != theRequiredNodes.end();++ghs3dNodeIt) {
GmfSetLin(idxRequired, GmfVertices, (*ghs3dNodeIt)->X(), (*ghs3dNodeIt)->Y(), (*ghs3dNodeIt)->Z(), dummyint);
- GmfSetLin(idxSol, GmfSolAtVertices, 0.0);
+ GmfSetLin(idxSol, GmfSolAtVertices, ValTab);
if (theEnforcedNodes.find((*ghs3dNodeIt)) != theEnforcedNodes.end())
gn = theEnforcedNodes.find((*ghs3dNodeIt))->second;
aNodeGroupByGhs3dId[usedEnforcedNodes] = gn;
if (theEnforcedVertices.find(coords) != theEnforcedVertices.end())
continue;
- double size = theNodeIDToSizeMap.find(nodeIt->first->GetID())->second;
+// double size = theNodeIDToSizeMap.find(nodeIt->first->GetID())->second;
// theGhs3dIdToNodeMap.insert( make_pair( nbNodes + i, (*nodeIt) ));
// MESSAGE("Adding enforced node (" << x << "," << y <<"," << z << ")");
// X Y Z PHY_SIZE DUMMY_INT
<< x << space
<< y << space
<< z << space
- << size << space
+ << -1 << space
<< dummyint << space;
theFile << std::endl;
theEnforcedNodeIdToGhs3dIdMap.insert( make_pair( nodeIt->first->GetID(), aGhs3dID ));
theMesh.GetMeshDS()->Modified();
return ok;
}
+
+namespace
+{
+ //================================================================================
+ /*!
+ * \brief Sub-mesh event listener setting enforced elements as soon as an enforced
+ * mesh is loaded
+ */
+ struct _EnforcedMeshRestorer : public SMESH_subMeshEventListener
+ {
+ _EnforcedMeshRestorer():
+ SMESH_subMeshEventListener( /*isDeletable = */true, Name() )
+ {}
+
+ //================================================================================
+ /*!
+ * \brief Returns an ID of listener
+ */
+ static const char* Name() { return "GHS3DPlugin_GHS3D::_EnforcedMeshRestorer"; }
+
+ //================================================================================
+ /*!
+ * \brief Treat events of the subMesh
+ */
+ void ProcessEvent(const int event,
+ const int eventType,
+ SMESH_subMesh* subMesh,
+ SMESH_subMeshEventListenerData* data,
+ const SMESH_Hypothesis* hyp)
+ {
+ if ( SMESH_subMesh::SUBMESH_LOADED == event &&
+ SMESH_subMesh::COMPUTE_EVENT == eventType &&
+ data &&
+ !data->mySubMeshes.empty() )
+ {
+ // An enforced mesh (subMesh->_father) has been loaded from hdf file
+ if ( GHS3DPlugin_Hypothesis* hyp = GetGHSHypothesis( data->mySubMeshes.front() ))
+ hyp->RestoreEnfElemsByMeshes();
+ }
+ }
+ //================================================================================
+ /*!
+ * \brief Returns GHS3DPlugin_Hypothesis used to compute a subMesh
+ */
+ static GHS3DPlugin_Hypothesis* GetGHSHypothesis( SMESH_subMesh* subMesh )
+ {
+ SMESH_HypoFilter ghsHypFilter( SMESH_HypoFilter::HasName( "GHS3D_Parameters" ));
+ return (GHS3DPlugin_Hypothesis* )
+ subMesh->GetFather()->GetHypothesis( subMesh->GetSubShape(),
+ ghsHypFilter,
+ /*visitAncestors=*/true);
+ }
+ };
+}
+
+//================================================================================
+/*!
+ * \brief Set an event listener to set enforced elements as soon as an enforced
+ * mesh is loaded
+ */
+//================================================================================
+
+void GHS3DPlugin_GHS3D::SubmeshRestored(SMESH_subMesh* subMesh)
+{
+ if ( GHS3DPlugin_Hypothesis* hyp = _EnforcedMeshRestorer::GetGHSHypothesis( subMesh ))
+ {
+ GHS3DPlugin_Hypothesis::TGHS3DEnforcedMeshList enfMeshes = hyp->_GetEnforcedMeshes();
+ GHS3DPlugin_Hypothesis::TGHS3DEnforcedMeshList::iterator it = enfMeshes.begin();
+ for(;it != enfMeshes.end();++it) {
+ GHS3DPlugin_Hypothesis::TGHS3DEnforcedMesh* enfMesh = *it;
+ if ( SMESH_Mesh* mesh = GetMeshByPersistentID( enfMesh->persistID ))
+ {
+ SMESH_subMesh* smToListen = mesh->GetSubMesh( mesh->GetShapeToMesh() );
+ // a listener set to smToListen will care of hypothesis stored in SMESH_EventListenerData
+ subMesh->SetEventListener( new _EnforcedMeshRestorer(),
+ SMESH_subMeshEventListenerData::MakeData( subMesh ),
+ smToListen);
+ }
+ }
+ }
+}