// Module : SMESH
// $Header$
-using namespace std;
#include <TopExp.hxx>
#include <TopExp_Explorer.hxx>
#include <TopoDS.hxx>
#include <TopoDS_Shape.hxx>
#include <TopTools_MapOfShape.hxx>
#include <TopTools_IndexedMapOfShape.hxx>
+#include <TopTools_ListOfShape.hxx>
+#include <TopTools_ListIteratorOfListOfShape.hxx>
#include <gp_Pnt.hxx>
#include <BRep_Tool.hxx>
#include <TCollection_AsciiString.hxx>
+#include <OSD.hxx>
#include "Utils_CorbaException.hxx"
#include "SMESH_Hypothesis_i.hxx"
#include "SMESH_Algo_i.hxx"
#include "SMESH_Group_i.hxx"
+#include "SMESH_PythonDump.hxx"
#include "SMESHDS_Document.hxx"
#include "SMESHDS_Group.hxx"
-#include "SMESH_topo.hxx"
+#include "SMESHDS_GroupOnGeom.hxx"
+#include "SMESH_Mesh.hxx"
+#include "SMESH_Hypothesis.hxx"
#include "SMESH_Group.hxx"
+#include "SMESH_MeshEditor.hxx"
+
+#include "SMDS_EdgePosition.hxx"
+#include "SMDS_FacePosition.hxx"
#include CORBA_SERVER_HEADER(SMESH_Group)
#include CORBA_SERVER_HEADER(SMESH_Filter)
-#include "SMESH_Filter_i.hxx"
-#include "Document_Reader.h"
#include "DriverMED_W_SMESHDS_Mesh.h"
#include "DriverMED_R_SMESHDS_Mesh.h"
-#include "DriverMED_R_SMESHDS_Document.h"
-#include "DriverUNV_R_SMESHDS_Document.h"
-#include "DriverDAT_R_SMESHDS_Document.h"
#include "SALOMEDS_Tool.hxx"
#include "SALOME_NamingService.hxx"
#include <map>
+using namespace std;
+using SMESH::TPythonDump;
+
#define NUM_TMP_FILES 2
-// Tags definition ===========================================================
-// Top level
-long Tag_HypothesisRoot = 1; // hypotheses root
-long Tag_AlgorithmsRoot = 2; // algorithms root
-// Mesh/Submesh
-long Tag_RefOnShape = 1; // references to shape
-long Tag_RefOnAppliedHypothesis = 2; // applied hypotheses root
-long Tag_RefOnAppliedAlgorithms = 3; // applied algorithms root
-// Mesh only
-long Tag_SubMeshOnVertex = 4; // sub-meshes roots by type
-long Tag_SubMeshOnEdge = 5; // ...
-long Tag_SubMeshOnFace = 6; // ...
-long Tag_SubMeshOnSolid = 7; // ...
-long Tag_SubMeshOnCompound = 8; // ...
-long Tag_NodeGroups = 9; // Group roots by type
-long Tag_EdgeGroups = 10; // ...
-long Tag_FaceGroups = 11; // ...
-long Tag_VolumeGroups = 12; // ...
-// ===========================================================================
+#ifdef _DEBUG_
+static int MYDEBUG = 1;
+#else
+static int MYDEBUG = 0;
+#endif
// Static variables definition
CORBA::ORB_var SMESH_Gen_i::myOrb;
PortableServer::POA_var SMESH_Gen_i::myPoa;
SALOME_NamingService* SMESH_Gen_i::myNS = NULL;
SALOME_LifeCycleCORBA* SMESH_Gen_i::myLCC = NULL;
-
-//=============================================================================
-/*!
- * FindMaxChildTag [ static internal ]
- *
- * Finds maximum child tag for the given object
- */
-//=============================================================================
-
-static long FindMaxChildTag( SALOMEDS::SObject_ptr theSObject )
-{
- long aTag = 0;
- if ( !theSObject->_is_nil() ) {
- SALOMEDS::Study_var aStudy = theSObject->GetStudy();
- if ( !aStudy->_is_nil() ) {
- SALOMEDS::ChildIterator_var anIter = aStudy->NewChildIterator( theSObject );
- for ( ; anIter->More(); anIter->Next() ) {
- long nTag = anIter->Value()->Tag();
- if ( nTag > aTag )
- aTag = nTag;
- }
- }
- }
- return aTag;
-}
-
-//=============================================================================
-/*!
- * Get...Tag [ static ]
- *
- * Methods which determine SMESH data model structure
- */
-//=============================================================================
-
-long SMESH_Gen_i::GetHypothesisRootTag()
-{
- return Tag_HypothesisRoot;
-}
-
-long SMESH_Gen_i::GetAlgorithmsRootTag()
-{
- return Tag_AlgorithmsRoot;
-}
-
-long SMESH_Gen_i::GetRefOnShapeTag()
-{
- return Tag_RefOnShape;
-}
-
-long SMESH_Gen_i::GetRefOnAppliedHypothesisTag()
-{
- return Tag_RefOnAppliedHypothesis;
-}
-
-long SMESH_Gen_i::GetRefOnAppliedAlgorithmsTag()
-{
- return Tag_RefOnAppliedAlgorithms;
-}
-
-long SMESH_Gen_i::GetSubMeshOnVertexTag()
-{
- return Tag_SubMeshOnVertex;
-}
-
-long SMESH_Gen_i::GetSubMeshOnEdgeTag()
-{
- return Tag_SubMeshOnEdge;
-}
-
-long SMESH_Gen_i::GetSubMeshOnFaceTag()
-{
- return Tag_SubMeshOnFace;
-}
-
-long SMESH_Gen_i::GetSubMeshOnSolidTag()
-{
- return Tag_SubMeshOnSolid;
-}
-
-long SMESH_Gen_i::GetSubMeshOnCompoundTag()
-{
- return Tag_SubMeshOnCompound;
-}
-
-long SMESH_Gen_i::GetNodeGroupsTag()
-{
- return Tag_NodeGroups;
-}
-
-long SMESH_Gen_i::GetEdgeGroupsTag()
-{
- return Tag_EdgeGroups;
-}
-
-long SMESH_Gen_i::GetFaceGroupsTag()
-{
- return Tag_FaceGroups;
-}
-
-long SMESH_Gen_i::GetVolumeGroupsTag()
-{
- return Tag_VolumeGroups;
-}
+SMESH_Gen_i* SMESH_Gen_i::mySMESHGen = NULL;
//=============================================================================
/*!
return aServant;
}
catch (...) {
- MESSAGE( "GetServant - Unknown exception was caught!!!" );
+ INFOS( "GetServant - Unknown exception was caught!!!" );
return NULL;
}
}
}
}
catch( ... ) {
- MESSAGE( "SObjectToObject - Unknown exception was caught!!!" );
+ INFOS( "SObjectToObject - Unknown exception was caught!!!" );
}
}
return anObj;
SMESH_Gen_i::SMESH_Gen_i()
{
- MESSAGE( "SMESH_Gen_i::SMESH_Gen_i : default constructor" );
+ INFOS( "SMESH_Gen_i::SMESH_Gen_i : default constructor" );
}
//=============================================================================
const char* interfaceName )
: Engines_Component_i( orb, poa, contId, instanceName, interfaceName )
{
- MESSAGE( "SMESH_Gen_i::SMESH_Gen_i : standard constructor" );
+ INFOS( "SMESH_Gen_i::SMESH_Gen_i : standard constructor" );
myOrb = CORBA::ORB::_duplicate(orb);
myPoa = PortableServer::POA::_duplicate(poa);
_thisObj = this ;
_id = myPoa->activate_object( _thisObj );
+ myIsEmbeddedMode = false;
myShapeReader = NULL; // shape reader
+ mySMESHGen = this;
+
+ OSD::SetSignal( true );
}
//=============================================================================
SMESH_Gen_i::~SMESH_Gen_i()
{
- MESSAGE( "SMESH_Gen_i::~SMESH_Gen_i" );
+ INFOS( "SMESH_Gen_i::~SMESH_Gen_i" );
// delete hypothesis creators
map<string, GenericHypothesisCreator_i*>::iterator itHyp;
delete myShapeReader;
}
-//=============================================================================
-/*!
- * SMESH_Gen_i::CreateFilterManager
- *
- * Create filter manager
- */
-//=============================================================================
-
-SMESH::FilterManager_ptr SMESH_Gen_i::CreateFilterManager()
-{
- SMESH::FilterManager_i* aFilter = new SMESH::FilterManager_i();
- SMESH::FilterManager_var anObj = aFilter->_this();
- return anObj._retn();
-}
-
//=============================================================================
/*!
* SMESH_Gen_i::createHypothesis
throw (SALOME::SALOME_Exception)
{
Unexpect aCatch(SALOME_SalomeException);
- MESSAGE( "Create Hypothesis <" << theHypName << "> from " << theLibName);
+ if(MYDEBUG) MESSAGE( "Create Hypothesis <" << theHypName << "> from " << theLibName);
- // get study context
- StudyContext* myStudyContext = GetCurrentStudyContext();
-
// create a new hypothesis object servant
SMESH_Hypothesis_i* myHypothesis_i = 0;
SMESH::SMESH_Hypothesis_var hypothesis_i;
if (myHypCreatorMap.find(string(theHypName)) == myHypCreatorMap.end())
{
// load plugin library
- MESSAGE("Loading server meshers plugin library ...");
+ if(MYDEBUG) MESSAGE("Loading server meshers plugin library ...");
void* libHandle = dlopen (theLibName, RTLD_LAZY);
if (!libHandle)
{
}
// get method, returning hypothesis creator
- MESSAGE("Find GetHypothesisCreator() method ...");
+ if(MYDEBUG) MESSAGE("Find GetHypothesisCreator() method ...");
typedef GenericHypothesisCreator_i* (*GetHypothesisCreator)(const char* theHypName);
GetHypothesisCreator procHandle =
(GetHypothesisCreator)dlsym( libHandle, "GetHypothesisCreator" );
}
// get hypothesis creator
- MESSAGE("Get Hypothesis Creator for " << theHypName);
+ if(MYDEBUG) MESSAGE("Get Hypothesis Creator for " << theHypName);
GenericHypothesisCreator_i* aCreator = procHandle(theHypName);
if (!aCreator)
{
}
// create a new hypothesis object, store its ref. in studyContext
- MESSAGE("Create Hypothesis " << theHypName);
+ if(MYDEBUG) MESSAGE("Create Hypothesis " << theHypName);
myHypothesis_i =
- myHypCreatorMap[string(theHypName)]->Create
- (myPoa, myCurrentStudy->StudyId(), &myGen);
+ myHypCreatorMap[string(theHypName)]->Create (myPoa, GetCurrentStudyID(), &myGen);
// _CS_gbo Explicit activation (no longer made in the constructor).
myHypothesis_i->Activate();
myHypothesis_i->SetLibName(theLibName); // for persistency assurance
// activate the CORBA servant of hypothesis
hypothesis_i = SMESH::SMESH_Hypothesis::_narrow( myHypothesis_i->_this() );
- string iorString = GetORB()->object_to_string( hypothesis_i );
- int nextId = myStudyContext->addObject( iorString );
- MESSAGE( "Add hypo to map with id = "<< nextId << " and IOR = " << iorString.c_str() );
+ int nextId = RegisterObject( hypothesis_i );
+ if(MYDEBUG) MESSAGE( "Add hypo to map with id = "<< nextId );
return hypothesis_i._retn();
}
throw ( SALOME::SALOME_Exception )
{
Unexpect aCatch(SALOME_SalomeException);
- MESSAGE( "SMESH_Gen_i::createMesh" );
-
- // get current study
- StudyContext* myStudyContext = GetCurrentStudyContext();
+ if(MYDEBUG) MESSAGE( "SMESH_Gen_i::createMesh" );
// Get or create the GEOM_Client instance
try {
// create a new mesh object servant, store it in a map in study context
- SMESH_Mesh_i* meshServant = new SMESH_Mesh_i( GetPOA(),
- this,
- myCurrentStudy->StudyId() );
+ SMESH_Mesh_i* meshServant = new SMESH_Mesh_i( GetPOA(), this, GetCurrentStudyID() );
// create a new mesh object
- meshServant->SetImpl( myGen.CreateMesh( myCurrentStudy->StudyId() ) );
+ meshServant->SetImpl( myGen.CreateMesh( GetCurrentStudyID(), myIsEmbeddedMode ));
// activate the CORBA servant of Mesh
- SMESH::SMESH_Mesh_var mesh = meshServant->_this();
- string iorString = GetORB()->object_to_string( mesh );
- int nextId = myStudyContext->addObject( iorString );
- MESSAGE( "Add mesh to map with id = "<< nextId << " and IOR = " << iorString.c_str() );
+ SMESH::SMESH_Mesh_var mesh = SMESH::SMESH_Mesh::_narrow( meshServant->_this() );
+ int nextId = RegisterObject( mesh );
+ if(MYDEBUG) MESSAGE( "Add mesh to map with id = "<< nextId);
return mesh._retn();
}
catch (SALOME_Exception& S_ex) {
return myShapeReader;
}
+//=============================================================================
+/*!
+ * SMESH_Gen_i::SetEmbeddedMode
+ *
+ * Set current mode
+ */
+//=============================================================================
+
+void SMESH_Gen_i::SetEmbeddedMode( CORBA::Boolean theMode )
+{
+ myIsEmbeddedMode = theMode;
+}
+
+//=============================================================================
+/*!
+ * SMESH_Gen_i::IsEmbeddedMode
+ *
+ * Get current mode
+ */
+//=============================================================================
+
+CORBA::Boolean SMESH_Gen_i::IsEmbeddedMode()
+{
+ return myIsEmbeddedMode;
+}
+
//=============================================================================
/*!
* SMESH_Gen_i::SetCurrentStudy
void SMESH_Gen_i::SetCurrentStudy( SALOMEDS::Study_ptr theStudy )
{
- MESSAGE( "SMESH_Gen_i::SetCurrentStudy" );
+ //if(MYDEBUG)
+ //MESSAGE( "SMESH_Gen_i::SetCurrentStudy" );
myCurrentStudy = SALOMEDS::Study::_duplicate( theStudy );
// create study context, if it doesn't exist and set current study
- int studyId = myCurrentStudy->StudyId();
- MESSAGE( "SMESH_Gen_i::SetCurrentStudy: study Id = " << studyId );
+ int studyId = GetCurrentStudyID();
+ if(MYDEBUG) MESSAGE( "SMESH_Gen_i::SetCurrentStudy: study Id = " << studyId );
if ( myStudyContextMap.find( studyId ) == myStudyContextMap.end() ) {
myStudyContextMap[ studyId ] = new StudyContext;
}
+
+ SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
+ if( !myCurrentStudy->FindComponent( "GEOM" )->_is_nil() )
+ aStudyBuilder->LoadWith( myCurrentStudy->FindComponent( "GEOM" ), GetGeomEngine() );
+
// set current study for geom engine
- if ( !CORBA::is_nil( GetGeomEngine() ) )
- GetGeomEngine()->GetCurrentStudy( myCurrentStudy->StudyId() );
+ //if ( !CORBA::is_nil( GetGeomEngine() ) )
+ // GetGeomEngine()->GetCurrentStudy( myCurrentStudy->StudyId() );
}
//=============================================================================
SALOMEDS::Study_ptr SMESH_Gen_i::GetCurrentStudy()
{
- MESSAGE( "SMESH_Gen_i::GetCurrentStudy: study Id = " << myCurrentStudy->StudyId() );
+ if(MYDEBUG) MESSAGE( "SMESH_Gen_i::GetCurrentStudy: study Id = " << GetCurrentStudyID() );
return SALOMEDS::Study::_duplicate( myCurrentStudy );
}
//=============================================================================
StudyContext* SMESH_Gen_i::GetCurrentStudyContext()
{
- ASSERT( !CORBA::is_nil( myCurrentStudy ) )
- ASSERT( myStudyContextMap.find( myCurrentStudy->StudyId() ) != myStudyContextMap.end() );
- return myStudyContextMap[ myCurrentStudy->StudyId() ];
+ if ( !CORBA::is_nil( myCurrentStudy ) &&
+ myStudyContextMap.find( GetCurrentStudyID() ) != myStudyContextMap.end() )
+ return myStudyContextMap[ myCurrentStudy->StudyId() ];
+ else
+ return 0;
}
//=============================================================================
throw ( SALOME::SALOME_Exception )
{
Unexpect aCatch(SALOME_SalomeException);
- ASSERT( !CORBA::is_nil( myCurrentStudy ) );
// Create hypothesis/algorithm
SMESH::SMESH_Hypothesis_var hyp = this->createHypothesis( theHypName, theLibName );
// Publish hypothesis/algorithm in the study
- if ( this->CanPublishInStudy( hyp ) ) {
- this->PublishInStudy( myCurrentStudy, SALOMEDS::SObject::_nil(), hyp, "" );
+ if ( CanPublishInStudy( hyp ) ) {
+ SALOMEDS::SObject_var aSO = PublishHypothesis( myCurrentStudy, hyp );
+ if ( !aSO->_is_nil() ) {
+ // Update Python script
+ TPythonDump() << aSO << " = " << this << ".CreateHypothesis('"
+ << theHypName << "', '" << theLibName << "')";
+ }
}
+
return hyp._retn();
}
-
+
+//================================================================================
+/*!
+ * \brief Return hypothesis of given type holding parameter values of the existing mesh
+ * \param theHypType - hypothesis type name
+ * \param theLibName - plugin library name
+ * \param theMesh - The mesh of interest
+ * \param theGeom - The shape to get parameter values from
+ * \retval SMESH::SMESH_Hypothesis_ptr - The returned hypothesis may be the one existing
+ * in a study and used to compute the mesh, or a temporary one created just to pass
+ * parameter values
+ */
+//================================================================================
+
+SMESH::SMESH_Hypothesis_ptr
+SMESH_Gen_i::GetHypothesisParameterValues (const char* theHypType,
+ const char* theLibName,
+ SMESH::SMESH_Mesh_ptr theMesh,
+ GEOM::GEOM_Object_ptr theGeom)
+ throw ( SALOME::SALOME_Exception )
+{
+ Unexpect aCatch(SALOME_SalomeException);
+ if ( CORBA::is_nil( theMesh ) )
+ THROW_SALOME_CORBA_EXCEPTION( "bad Mesh reference", SALOME::BAD_PARAM );
+ if ( CORBA::is_nil( theGeom ) )
+ THROW_SALOME_CORBA_EXCEPTION( "bad shape object reference", SALOME::BAD_PARAM );
+
+ // -----------------------------------------------
+ // find hypothesis used to mesh theGeom
+ // -----------------------------------------------
+
+ // get mesh and shape
+ SMESH_Mesh_i* meshServant = SMESH::DownCast<SMESH_Mesh_i*>( theMesh );
+ TopoDS_Shape shape = GeomObjectToShape( theGeom );
+ if ( !meshServant || shape.IsNull() )
+ return SMESH::SMESH_Hypothesis::_nil();
+ ::SMESH_Mesh& mesh = meshServant->GetImpl();
+
+ if ( mesh.NbNodes() == 0 ) // empty mesh
+ return SMESH::SMESH_Hypothesis::_nil();
+
+ // create a temporary hypothesis to know its dimention
+ SMESH::SMESH_Hypothesis_var tmpHyp = this->createHypothesis( theHypType, theLibName );
+ SMESH_Hypothesis_i* hypServant = SMESH::DownCast<SMESH_Hypothesis_i*>( tmpHyp );
+ if ( !hypServant )
+ return SMESH::SMESH_Hypothesis::_nil();
+ ::SMESH_Hypothesis* hyp = hypServant->GetImpl();
+
+ // look for a hypothesis of theHypType used to mesh the shape
+ if ( myGen.GetShapeDim( shape ) == hyp->GetDim() )
+ {
+ // check local shape
+ SMESH::ListOfHypothesis_var aHypList = theMesh->GetHypothesisList( theGeom );
+ int nbLocalHyps = aHypList->length();
+ for ( int i = 0; i < nbLocalHyps; i++ )
+ if ( strcmp( theHypType, aHypList[i]->GetName() ) == 0 ) // FOUND local!
+ return SMESH::SMESH_Hypothesis::_duplicate( aHypList[i] );
+ // check super shapes
+ TopTools_ListIteratorOfListOfShape itShape( mesh.GetAncestors( shape ));
+ while ( nbLocalHyps == 0 && itShape.More() ) {
+ GEOM::GEOM_Object_ptr geomObj = ShapeToGeomObject( itShape.Value() );
+ if ( ! CORBA::is_nil( geomObj )) {
+ SMESH::ListOfHypothesis_var aHypList = theMesh->GetHypothesisList( geomObj );
+ nbLocalHyps = aHypList->length();
+ for ( int i = 0; i < nbLocalHyps; i++ )
+ if ( strcmp( theHypType, aHypList[i]->GetName() ) == 0 ) // FOUND global!
+ return SMESH::SMESH_Hypothesis::_duplicate( aHypList[i] );
+ }
+ itShape.Next();
+ }
+ }
+
+ // let the temporary hypothesis find out some how parameter values
+ if ( hyp->SetParametersByMesh( &mesh, shape ))
+ return SMESH::SMESH_Hypothesis::_duplicate( tmpHyp );
+
+ return SMESH::SMESH_Hypothesis::_nil();
+}
+
//=============================================================================
/*!
* SMESH_Gen_i::CreateMesh
*/
//=============================================================================
-SMESH::SMESH_Mesh_ptr SMESH_Gen_i::CreateMesh( GEOM::GEOM_Shape_ptr theShape )
+SMESH::SMESH_Mesh_ptr SMESH_Gen_i::CreateMesh( GEOM::GEOM_Object_ptr theShapeObject )
throw ( SALOME::SALOME_Exception )
{
Unexpect aCatch(SALOME_SalomeException);
- MESSAGE( "SMESH_Gen_i::CreateMesh" );
- ASSERT( !CORBA::is_nil( myCurrentStudy ) );
+ if(MYDEBUG) MESSAGE( "SMESH_Gen_i::CreateMesh" );
// create mesh
SMESH::SMESH_Mesh_var mesh = this->createMesh();
- // publish mesh in the study
- if ( this->CanPublishInStudy( mesh ) ) {
- this->PublishInStudy( myCurrentStudy, SALOMEDS::SObject::_nil(), mesh.in(), "" );
- }
// set shape
- SMESH_Mesh_i* meshServant = dynamic_cast<SMESH_Mesh_i*>( GetServant( mesh ).in() );
+ SMESH_Mesh_i* meshServant = SMESH::DownCast<SMESH_Mesh_i*>( mesh );
ASSERT( meshServant );
- meshServant->SetShape( theShape );
+ meshServant->SetShape( theShapeObject );
+
+ // publish mesh in the study
+ if ( CanPublishInStudy( mesh ) ) {
+ SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
+ aStudyBuilder->NewCommand(); // There is a transaction
+ SALOMEDS::SObject_var aSO = PublishMesh( myCurrentStudy, mesh.in() );
+ aStudyBuilder->CommitCommand();
+ if ( !aSO->_is_nil() ) {
+ // Update Python script
+ TPythonDump() << aSO << " = " << this << ".CreateMesh(" << theShapeObject << ")";
+ }
+ }
+
return mesh._retn();
}
-
+
+//=============================================================================
+/*!
+ * SMESH_Gen_i::CreateMeshFromUNV
+ *
+ * Create mesh and import data from UNV file
+ */
+//=============================================================================
+
+SMESH::SMESH_Mesh_ptr SMESH_Gen_i::CreateMeshesFromUNV( const char* theFileName )
+ throw ( SALOME::SALOME_Exception )
+{
+ Unexpect aCatch(SALOME_SalomeException);
+ if(MYDEBUG) MESSAGE( "SMESH_Gen_i::CreateMeshesFromUNV" );
+
+ SMESH::SMESH_Mesh_var aMesh = createMesh();
+ string aFileName;
+ // publish mesh in the study
+ if ( CanPublishInStudy( aMesh ) ) {
+ SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
+ aStudyBuilder->NewCommand(); // There is a transaction
+ SALOMEDS::SObject_var aSO = PublishMesh( myCurrentStudy, aMesh.in(), aFileName.c_str() );
+ aStudyBuilder->CommitCommand();
+ if ( !aSO->_is_nil() ) {
+ // Update Python script
+ TPythonDump() << aSO << " = smeshgen.CreateMeshesFromUNV('" << theFileName << "')";
+ }
+ }
+
+ SMESH_Mesh_i* aServant = dynamic_cast<SMESH_Mesh_i*>( GetServant( aMesh ).in() );
+ ASSERT( aServant );
+ aServant->ImportUNVFile( theFileName );
+ return aMesh._retn();
+}
+
//=============================================================================
/*!
* SMESH_Gen_i::CreateMeshFromMED
throw ( SALOME::SALOME_Exception )
{
Unexpect aCatch(SALOME_SalomeException);
- MESSAGE( "SMESH_Gen_i::CreateMeshFromMED" );
- ASSERT( !CORBA::is_nil( myCurrentStudy ) );
+ if(MYDEBUG) MESSAGE( "SMESH_Gen_i::CreateMeshFromMED" );
+
+ // Python Dump
+ TPythonDump aPythonDump;
+ aPythonDump << "([";
+ //TCollection_AsciiString aStr ("([");
// Retrieve mesh names from the file
DriverMED_R_SMESHDS_Mesh myReader;
myReader.SetFile( theFileName );
myReader.SetMeshId( -1 );
- list<string> aNames = myReader.GetMeshNames();
-
+ Driver_Mesh::Status aStatus;
+ list<string> aNames = myReader.GetMeshNames(aStatus);
SMESH::mesh_array_var aResult = new SMESH::mesh_array();
- aResult->length( aNames.size() );
- int i = 0;
-
- // Iterate through all meshes and create mesh objects
- theStatus = SMESH::DRS_OK;
- for ( list<string>::iterator it = aNames.begin(); it != aNames.end(); it++ ) {
- // create mesh
- SMESH::SMESH_Mesh_var mesh = createMesh();
+ theStatus = (SMESH::DriverMED_ReadStatus)aStatus;
+ if (theStatus == SMESH::DRS_OK) {
+ SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
+ aStudyBuilder->NewCommand(); // There is a transaction
+ aResult->length( aNames.size() );
+ int i = 0;
- // publish mesh in the study
- if ( CanPublishInStudy( mesh ) ) {
- PublishInStudy( myCurrentStudy, SALOMEDS::SObject::_nil(), mesh.in(), (*it).c_str() );
- }
+ // Iterate through all meshes and create mesh objects
+ for ( list<string>::iterator it = aNames.begin(); it != aNames.end(); it++ ) {
+ // Python Dump
+ //if (i > 0) aStr += ", ";
+ if (i > 0) aPythonDump << ", ";
+
+ // create mesh
+ SMESH::SMESH_Mesh_var mesh = createMesh();
+
+ // publish mesh in the study
+ SALOMEDS::SObject_var aSO;
+ if ( CanPublishInStudy( mesh ) )
+ aSO = PublishMesh( myCurrentStudy, mesh.in(), (*it).c_str() );
+ if ( !aSO->_is_nil() ) {
+ // Python Dump
+ aPythonDump << aSO;
+ //aStr += aSO->GetID();
+ } else {
+ // Python Dump
+ aPythonDump << "mesh_" << i;
+// aStr += "mesh_";
+// aStr += TCollection_AsciiString(i);
+ }
- // Read mesh data (groups are published automatically by ImportMEDFile())
- SMESH_Mesh_i* meshServant = dynamic_cast<SMESH_Mesh_i*>( GetServant( mesh ).in() );
- ASSERT( meshServant );
- SMESH::DriverMED_ReadStatus status1 =
- meshServant->ImportMEDFile( theFileName, (*it).c_str() );
- if (status1 > theStatus)
- theStatus = status1;
+ // Read mesh data (groups are published automatically by ImportMEDFile())
+ SMESH_Mesh_i* meshServant = dynamic_cast<SMESH_Mesh_i*>( GetServant( mesh ).in() );
+ ASSERT( meshServant );
+ SMESH::DriverMED_ReadStatus status1 =
+ meshServant->ImportMEDFile( theFileName, (*it).c_str() );
+ if (status1 > theStatus)
+ theStatus = status1;
- aResult[i++] = SMESH::SMESH_Mesh::_duplicate( mesh );
+ aResult[i++] = SMESH::SMESH_Mesh::_duplicate( mesh );
+ }
+ aStudyBuilder->CommitCommand();
}
+ // Update Python script
+ aPythonDump << "], status) = " << this << ".CreateMeshesFromMED('" << theFileName << "')";
+
return aResult._retn();
}
+//=============================================================================
+/*!
+ * SMESH_Gen_i::CreateMeshFromSTL
+ *
+ * Create mesh and import data from STL file
+ */
+//=============================================================================
+
+SMESH::SMESH_Mesh_ptr SMESH_Gen_i::CreateMeshesFromSTL( const char* theFileName )
+ throw ( SALOME::SALOME_Exception )
+{
+ Unexpect aCatch(SALOME_SalomeException);
+ if(MYDEBUG) MESSAGE( "SMESH_Gen_i::CreateMeshesFromSTL" );
+
+ SMESH::SMESH_Mesh_var aMesh = createMesh();
+ string aFileName;
+ // publish mesh in the study
+ if ( CanPublishInStudy( aMesh ) ) {
+ SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
+ aStudyBuilder->NewCommand(); // There is a transaction
+ SALOMEDS::SObject_var aSO = PublishInStudy
+ ( myCurrentStudy, SALOMEDS::SObject::_nil(), aMesh.in(), aFileName.c_str() );
+ aStudyBuilder->CommitCommand();
+ if ( !aSO->_is_nil() ) {
+ // Update Python script
+ TPythonDump() << aSO << " = " << this << ".CreateMeshesFromSTL('" << theFileName << "')";
+ }
+ }
+
+ SMESH_Mesh_i* aServant = dynamic_cast<SMESH_Mesh_i*>( GetServant( aMesh ).in() );
+ ASSERT( aServant );
+ aServant->ImportSTLFile( theFileName );
+ return aMesh._retn();
+}
+
//=============================================================================
/*!
* SMESH_Gen_i::IsReadyToCompute
//=============================================================================
CORBA::Boolean SMESH_Gen_i::IsReadyToCompute( SMESH::SMESH_Mesh_ptr theMesh,
- GEOM::GEOM_Shape_ptr theShape )
+ GEOM::GEOM_Object_ptr theShapeObject )
throw ( SALOME::SALOME_Exception )
{
Unexpect aCatch(SALOME_SalomeException);
- MESSAGE( "SMESH_Gen_i::IsReadyToCompute" );
+ if(MYDEBUG) MESSAGE( "SMESH_Gen_i::IsReadyToCompute" );
- if ( CORBA::is_nil( theShape ) )
- THROW_SALOME_CORBA_EXCEPTION( "bad shape reference",
+ if ( CORBA::is_nil( theShapeObject ) )
+ THROW_SALOME_CORBA_EXCEPTION( "bad shape object reference",
SALOME::BAD_PARAM );
if ( CORBA::is_nil( theMesh ) )
ASSERT( meshServant );
if ( meshServant ) {
// get local TopoDS_Shape
- TopoDS_Shape myLocShape = GetShapeReader()->GetShape( GetGeomEngine(), theShape );
+ TopoDS_Shape myLocShape = GeomObjectToShape( theShapeObject );
// call implementation
::SMESH_Mesh& myLocMesh = meshServant->GetImpl();
return myGen.CheckAlgoState( myLocMesh, myLocShape );
}
}
catch ( SALOME_Exception& S_ex ) {
- MESSAGE( "catch exception "<< S_ex.what() );
+ INFOS( "catch exception "<< S_ex.what() );
}
return false;
}
+//================================================================================
+/*!
+ * \brief Returns errors of hypotheses definintion
+ * \param theMesh - the mesh
+ * \param theSubObject - the main or sub- shape
+ * \retval SMESH::algo_error_array* - sequence of errors
+ */
+//================================================================================
+
+SMESH::algo_error_array* SMESH_Gen_i::GetAlgoState( SMESH::SMESH_Mesh_ptr theMesh,
+ GEOM::GEOM_Object_ptr theSubObject )
+ throw ( SALOME::SALOME_Exception )
+{
+ Unexpect aCatch(SALOME_SalomeException);
+ if(MYDEBUG) MESSAGE( "SMESH_Gen_i::GetAlgoState()" );
+
+ if ( CORBA::is_nil( theSubObject ) )
+ THROW_SALOME_CORBA_EXCEPTION( "bad shape object reference", SALOME::BAD_PARAM );
+
+ if ( CORBA::is_nil( theMesh ) )
+ THROW_SALOME_CORBA_EXCEPTION( "bad Mesh reference",SALOME::BAD_PARAM );
+
+ SMESH::algo_error_array_var error_array = new SMESH::algo_error_array;
+ try {
+ SMESH_Mesh_i* meshServant = SMESH::DownCast<SMESH_Mesh_i*>( theMesh );
+ ASSERT( meshServant );
+ if ( meshServant ) {
+ TopoDS_Shape myLocShape = GeomObjectToShape( theSubObject );
+ ::SMESH_Mesh& myLocMesh = meshServant->GetImpl();
+ list< ::SMESH_Gen::TAlgoStateError > error_list;
+ list< ::SMESH_Gen::TAlgoStateError >::iterator error;
+ // call ::SMESH_Gen::GetAlgoState()
+ myGen.GetAlgoState( myLocMesh, myLocShape, error_list );
+ error_array->length( error_list.size() );
+ int i = 0;
+ for ( error = error_list.begin(); error != error_list.end(); ++error )
+ {
+ // error name
+ SMESH::AlgoStateErrorName errName;
+ switch ( error->_name ) {
+ case ::SMESH_Gen::MISSING_ALGO: errName = SMESH::MISSING_ALGO; break;
+ case ::SMESH_Gen::MISSING_HYPO: errName = SMESH::MISSING_HYPO; break;
+ case ::SMESH_Gen::NOT_CONFORM_MESH: errName = SMESH::NOT_CONFORM_MESH; break;
+ default:
+ THROW_SALOME_CORBA_EXCEPTION( "bad error name",SALOME::BAD_PARAM );
+ }
+ // algo name
+ CORBA::String_var algoName;
+ if ( error->_algo ) {
+ if ( !myCurrentStudy->_is_nil() ) {
+ // find algo in the study
+ SALOMEDS::SComponent_var father = SALOMEDS::SComponent::_narrow
+ ( myCurrentStudy->FindComponent( ComponentDataType() ) );
+ if ( !father->_is_nil() ) {
+ SALOMEDS::ChildIterator_var itBig = myCurrentStudy->NewChildIterator( father );
+ for ( ; itBig->More(); itBig->Next() ) {
+ SALOMEDS::SObject_var gotBranch = itBig->Value();
+ if ( gotBranch->Tag() == GetAlgorithmsRootTag() ) {
+ SALOMEDS::ChildIterator_var algoIt = myCurrentStudy->NewChildIterator( gotBranch );
+ for ( ; algoIt->More(); algoIt->Next() ) {
+ SALOMEDS::SObject_var algoSO = algoIt->Value();
+ CORBA::Object_var algoIOR = SObjectToObject( algoSO );
+ if ( !CORBA::is_nil( algoIOR )) {
+ SMESH_Hypothesis_i* myImpl = SMESH::DownCast<SMESH_Hypothesis_i*>( algoIOR );
+ if ( myImpl && myImpl->GetImpl() == error->_algo ) {
+ algoName = algoSO->GetName();
+ break;
+ }
+ }
+ } // loop on algo SO's
+ break;
+ } // if algo tag
+ } // SMESH component iterator
+ }
+ }
+ if ( algoName.in() == 0 )
+ // use algo type name
+ algoName = CORBA::string_dup( error->_algo->GetName() );
+ }
+ // fill AlgoStateError structure
+ SMESH::AlgoStateError & errStruct = error_array[ i++ ];
+ errStruct.name = errName;
+ errStruct.algoName = algoName;
+ errStruct.algoDim = error->_algoDim;
+ errStruct.isGlobalAlgo = error->_isGlobalAlgo;
+ }
+ }
+ }
+ catch ( SALOME_Exception& S_ex ) {
+ INFOS( "catch exception "<< S_ex.what() );
+ }
+ return error_array._retn();
+}
+
//=============================================================================
/*!
* SMESH_Gen_i::GetSubShapesId
*/
//=============================================================================
-SMESH::long_array* SMESH_Gen_i::GetSubShapesId( GEOM::GEOM_Shape_ptr theMainShape,
- const SMESH::shape_array& theListOfSubShape )
+SMESH::long_array* SMESH_Gen_i::GetSubShapesId( GEOM::GEOM_Object_ptr theMainShapeObject,
+ const SMESH::object_array& theListOfSubShapeObject )
throw ( SALOME::SALOME_Exception )
{
Unexpect aCatch(SALOME_SalomeException);
- MESSAGE( "SMESH_Gen_i::GetSubShapesId" );
+ if(MYDEBUG) MESSAGE( "SMESH_Gen_i::GetSubShapesId" );
SMESH::long_array_var shapesId = new SMESH::long_array;
set<int> setId;
- if ( CORBA::is_nil( theMainShape ) )
- THROW_SALOME_CORBA_EXCEPTION( "bad shape reference",
+ if ( CORBA::is_nil( theMainShapeObject ) )
+ THROW_SALOME_CORBA_EXCEPTION( "bad shape object reference",
SALOME::BAD_PARAM );
try
{
- if (! myShapeReader) myShapeReader = new GEOM_Client(GetContainerRef());
- ASSERT(myShapeReader);
- TopoDS_Shape myMainShape = GetShapeReader()->GetShape(GetGeomEngine(),theMainShape);
+ TopoDS_Shape myMainShape = GeomObjectToShape(theMainShapeObject);
TopTools_IndexedMapOfShape myIndexToShape;
TopExp::MapShapes(myMainShape,myIndexToShape);
- for (int i=0; i<theListOfSubShape.length(); i++)
+ for ( int i = 0; i < theListOfSubShapeObject.length(); i++ )
{
- GEOM::GEOM_Shape_var aShape
- = GEOM::GEOM_Shape::_narrow(theListOfSubShape[i]);
- if (CORBA::is_nil(aShape))
- THROW_SALOME_CORBA_EXCEPTION("bad shape reference", \
- SALOME::BAD_PARAM);
- TopoDS_Shape locShape = GetShapeReader()->GetShape(GetGeomEngine(),aShape);
+ GEOM::GEOM_Object_var aShapeObject
+ = GEOM::GEOM_Object::_narrow(theListOfSubShapeObject[i]);
+ if ( CORBA::is_nil( aShapeObject ) )
+ THROW_SALOME_CORBA_EXCEPTION ("bad shape object reference", \
+ SALOME::BAD_PARAM );
+
+ TopoDS_Shape locShape = GeomObjectToShape(aShapeObject);
for (TopExp_Explorer exp(locShape,TopAbs_FACE); exp.More(); exp.Next())
{
const TopoDS_Face& F = TopoDS::Face(exp.Current());
setId.insert(myIndexToShape.FindIndex(F));
- SCRUTE(myIndexToShape.FindIndex(F));
+ if(MYDEBUG) SCRUTE(myIndexToShape.FindIndex(F));
}
for (TopExp_Explorer exp(locShape,TopAbs_EDGE); exp.More(); exp.Next())
{
const TopoDS_Edge& E = TopoDS::Edge(exp.Current());
setId.insert(myIndexToShape.FindIndex(E));
- SCRUTE(myIndexToShape.FindIndex(E));
+ if(MYDEBUG) SCRUTE(myIndexToShape.FindIndex(E));
}
for (TopExp_Explorer exp(locShape,TopAbs_VERTEX); exp.More(); exp.Next())
{
const TopoDS_Vertex& V = TopoDS::Vertex(exp.Current());
setId.insert(myIndexToShape.FindIndex(V));
- SCRUTE(myIndexToShape.FindIndex(V));
+ if(MYDEBUG) SCRUTE(myIndexToShape.FindIndex(V));
}
}
shapesId->length(setId.size());
int i=0;
for (iind = setId.begin(); iind != setId.end(); iind++)
{
- SCRUTE((*iind));
+ if(MYDEBUG) SCRUTE((*iind));
shapesId[i] = (*iind);
- SCRUTE(shapesId[i]);
+ if(MYDEBUG) SCRUTE(shapesId[i]);
i++;
}
}
//=============================================================================
CORBA::Boolean SMESH_Gen_i::Compute( SMESH::SMESH_Mesh_ptr theMesh,
- GEOM::GEOM_Shape_ptr theShape )
+ GEOM::GEOM_Object_ptr theShapeObject )
throw ( SALOME::SALOME_Exception )
{
Unexpect aCatch(SALOME_SalomeException);
- MESSAGE( "SMESH_Gen_i::Compute" );
+ if(MYDEBUG) MESSAGE( "SMESH_Gen_i::Compute" );
- if ( CORBA::is_nil( theShape ) )
- THROW_SALOME_CORBA_EXCEPTION( "bad shape reference",
+ if ( CORBA::is_nil( theShapeObject ) )
+ THROW_SALOME_CORBA_EXCEPTION( "bad shape object reference",
SALOME::BAD_PARAM );
if ( CORBA::is_nil( theMesh ) )
THROW_SALOME_CORBA_EXCEPTION( "bad Mesh reference",
SALOME::BAD_PARAM );
+ // Update Python script
+ TPythonDump() << "isDone = " << this << ".Compute( "
+ << theMesh << ", " << theShapeObject << ")";
+ TPythonDump() << "if not isDone: print 'Mesh " << theMesh << " : computation failed'";
+
try {
// get mesh servant
SMESH_Mesh_i* meshServant = dynamic_cast<SMESH_Mesh_i*>( GetServant( theMesh ).in() );
ASSERT( meshServant );
if ( meshServant ) {
// get local TopoDS_Shape
- TopoDS_Shape myLocShape = GetShapeReader()->GetShape( GetGeomEngine(), theShape );
- // call implementarion compute
+ TopoDS_Shape myLocShape = GeomObjectToShape( theShapeObject );
+ // call implementation compute
::SMESH_Mesh& myLocMesh = meshServant->GetImpl();
return myGen.Compute( myLocMesh, myLocShape);
}
}
catch ( SALOME_Exception& S_ex ) {
- MESSAGE( "Compute(): catch exception "<< S_ex.what() );
+ INFOS( "Compute(): catch exception "<< S_ex.what() );
}
catch ( ... ) {
- MESSAGE( "Compute(): unknown exception " );
+ INFOS( "Compute(): unknown exception " );
}
return false;
}
+//================================================================================
+/*!
+ * \brief Return geometrical object the given element is built on
+ * \param theMesh - the mesh the element is in
+ * \param theElementID - the element ID
+ * \param theGeomName - the name of the result geom object if it is not yet published
+ * \retval GEOM::GEOM_Object_ptr - the found or just published geom object
+ */
+//================================================================================
+
+GEOM::GEOM_Object_ptr
+SMESH_Gen_i::GetGeometryByMeshElement( SMESH::SMESH_Mesh_ptr theMesh,
+ CORBA::Long theElementID,
+ const char* theGeomName)
+ throw ( SALOME::SALOME_Exception )
+{
+ Unexpect aCatch(SALOME_SalomeException);
+ if ( CORBA::is_nil( theMesh ) )
+ THROW_SALOME_CORBA_EXCEPTION( "bad Mesh reference", SALOME::BAD_PARAM );
+
+ GEOM::GEOM_Object_var mainShape = theMesh->GetShapeToMesh();
+ GEOM::GEOM_Gen_var geomGen = GetGeomEngine();
+
+ // get a core mesh DS
+ SMESH_Mesh_i* meshServant = SMESH::DownCast<SMESH_Mesh_i*>( theMesh );
+ if ( meshServant && !geomGen->_is_nil() && !mainShape->_is_nil() )
+ {
+ ::SMESH_Mesh & mesh = meshServant->GetImpl();
+ SMESHDS_Mesh* meshDS = mesh.GetMeshDS();
+ // find the element in mesh
+ if ( const SMDS_MeshElement * elem = meshDS->FindElement( theElementID ) )
+ // find a shape id by the element
+ if ( int shapeID = ::SMESH_MeshEditor( &mesh ).FindShape( elem )) {
+ // get a geom object by the shape id
+ GEOM::GEOM_Object_var geom = ShapeToGeomObject( meshDS->IndexToShape( shapeID ));
+ if ( geom->_is_nil() ) {
+ GEOM::GEOM_IShapesOperations_var op =
+ geomGen->GetIShapesOperations( GetCurrentStudyID() );
+ if ( !op->_is_nil() )
+ geom = op->GetSubShape( mainShape, shapeID );
+ }
+ if ( !geom->_is_nil() ) {
+ // try to find the corresponding SObject
+ GeomObjectToShape( geom ); // geom client remembers the found shape
+ SALOMEDS::SObject_var SObj = ObjectToSObject( myCurrentStudy, geom.in() );
+ if ( SObj->_is_nil() )
+ // publish a new subshape
+ SObj = geomGen->AddInStudy( myCurrentStudy, geom, theGeomName, mainShape );
+ // return only published geometry
+ if ( !SObj->_is_nil() )
+ return geom._retn();
+ }
+ }
+ }
+ return GEOM::GEOM_Object::_nil();
+}
+
//=============================================================================
/*!
* SMESH_Gen_i::Save
*/
//=============================================================================
SALOMEDS::TMPFile* SMESH_Gen_i::Save( SALOMEDS::SComponent_ptr theComponent,
- const char* theURL,
- bool isMultiFile )
+ const char* theURL,
+ bool isMultiFile )
{
INFOS( "SMESH_Gen_i::Save" );
- ASSERT( theComponent->GetStudy()->StudyId() == myCurrentStudy->StudyId() )
+// ASSERT( theComponent->GetStudy()->StudyId() == myCurrentStudy->StudyId() )
+ // san -- in case <myCurrentStudy> differs from theComponent's study,
+ // use that of the component
+ if ( myCurrentStudy->_is_nil() ||
+ theComponent->GetStudy()->StudyId() != myCurrentStudy->StudyId() )
+ SetCurrentStudy( theComponent->GetStudy() );
+
+ // Store study contents as a set of python commands
+ SavePython(myCurrentStudy);
+
StudyContext* myStudyContext = GetCurrentStudyContext();
// Declare a byte stream
// Obtain a temporary dir
TCollection_AsciiString tmpDir =
- ( isMultiFile ) ? TCollection_AsciiString( ( char* )theURL ) : SALOMEDS_Tool::GetTmpDir();
+ ( isMultiFile ) ? TCollection_AsciiString( ( char* )theURL ) : ( char* )SALOMEDS_Tool::GetTmpDir().c_str();
// Create a sequence of files processed
SALOMEDS::ListOfFileNames_var aFileSeq = new SALOMEDS::ListOfFileNames;
TCollection_AsciiString aStudyName( "" );
if ( isMultiFile )
- aStudyName = ( SALOMEDS_Tool::GetNameFromPath( myCurrentStudy->URL() ) );
+ aStudyName = ( (char*)SALOMEDS_Tool::GetNameFromPath( myCurrentStudy->URL() ).c_str() );
// Set names of temporary files
TCollection_AsciiString filename =
HDFgroup* aSubSubGroup;
hdf_size aSize[ 1 ];
+
+ //Remove the files if they exist: BugID: 11225
+ TCollection_AsciiString cmd("rm -f \"");
+ cmd+=filename;
+ cmd+="\" \"";
+ cmd+=meshfile;
+ cmd+="\"";
+ system(cmd.ToCString());
+
// MED writer to be used by storage process
DriverMED_W_SMESHDS_Mesh myWriter;
myWriter.SetFile( meshfile.ToCString() );
// ---> create HDF file
aFile = new HDFfile( filename.ToCString() );
aFile->CreateOnDisk();
-
+
// --> iterator for top-level objects
SALOMEDS::ChildIterator_var itBig = myCurrentStudy->NewChildIterator( theComponent );
for ( ; itBig->More(); itBig->Next() ) {
// write reference on a shape if exists
SALOMEDS::SObject_var myRef;
+ bool shapeRefFound = false;
bool found = gotBranch->FindSubObject( GetRefOnShapeTag(), myRef );
if ( found ) {
SALOMEDS::SObject_var myShape;
bool ok = myRef->ReferencedObject( myShape );
if ( ok ) {
+ shapeRefFound = (! CORBA::is_nil( myShape->GetObject() ));
string myRefOnObject = myShape->GetID();
- if ( myRefOnObject.length() > 0 ) {
+ if ( shapeRefFound && myRefOnObject.length() > 0 ) {
aSize[ 0 ] = myRefOnObject.length() + 1;
aDataset = new HDFdataset( "Ref on shape", aTopGroup, HDF_STRING, aSize, 1 );
aDataset->CreateOnDisk();
// write applied hypotheses if exist
SALOMEDS::SObject_var myHypBranch;
found = gotBranch->FindSubObject( GetRefOnAppliedHypothesisTag(), myHypBranch );
- if ( found ) {
+ if ( found && !shapeRefFound ) { // remove applied hyps
+ myCurrentStudy->NewBuilder()->RemoveObjectWithChildren( myHypBranch );
+ }
+ if ( found && shapeRefFound ) {
aGroup = new HDFgroup( "Applied Hypotheses", aTopGroup );
aGroup->CreateOnDisk();
// write applied algorithms if exist
SALOMEDS::SObject_var myAlgoBranch;
found = gotBranch->FindSubObject( GetRefOnAppliedAlgorithmsTag(), myAlgoBranch );
- if ( found ) {
+ if ( found && !shapeRefFound ) { // remove applied algos
+ myCurrentStudy->NewBuilder()->RemoveObjectWithChildren( myAlgoBranch );
+ }
+ if ( found && shapeRefFound ) {
aGroup = new HDFgroup( "Applied Algorithms", aTopGroup );
aGroup->CreateOnDisk();
}
// --> submesh objects sub-branches
+
for ( int i = GetSubMeshOnVertexTag(); i <= GetSubMeshOnCompoundTag(); i++ ) {
SALOMEDS::SObject_var mySubmeshBranch;
found = gotBranch->FindSubObject( i, mySubmeshBranch );
+
+ if ( found ) // check if there is shape reference in submeshes
+ {
+ bool hasShapeRef = false;
+ SALOMEDS::ChildIterator_var itSM =
+ myCurrentStudy->NewChildIterator( mySubmeshBranch );
+ for ( ; itSM->More(); itSM->Next() ) {
+ SALOMEDS::SObject_var mySubRef, myShape, mySObject = itSM->Value();
+ if ( mySObject->FindSubObject( GetRefOnShapeTag(), mySubRef ))
+ mySubRef->ReferencedObject( myShape );
+ if ( !CORBA::is_nil( myShape ) && !CORBA::is_nil( myShape->GetObject() ))
+ hasShapeRef = true;
+ else
+ { // remove one submesh
+ if ( shapeRefFound )
+ { // unassign hypothesis
+ SMESH::SMESH_subMesh_var mySubMesh =
+ SMESH::SMESH_subMesh::_narrow( SObjectToObject( mySObject ));
+ if ( !mySubMesh->_is_nil() ) {
+ int shapeID = mySubMesh->GetId();
+ TopoDS_Shape S = mySMESHDSMesh->IndexToShape( shapeID );
+ const list<const SMESHDS_Hypothesis*>& hypList =
+ mySMESHDSMesh->GetHypothesis( S );
+ list<const SMESHDS_Hypothesis*>::const_iterator hyp = hypList.begin();
+ while ( hyp != hypList.end() ) {
+ int hypID = (*hyp++)->GetID(); // goto next hyp here because
+ myLocMesh.RemoveHypothesis( S, hypID ); // hypList changes here
+ }
+ }
+ }
+ myCurrentStudy->NewBuilder()->RemoveObjectWithChildren( mySObject );
+ }
+ } // loop on submeshes of a type
+ if ( !shapeRefFound || !hasShapeRef ) { // remove the whole submeshes branch
+ myCurrentStudy->NewBuilder()->RemoveObjectWithChildren( mySubmeshBranch );
+ found = false;
+ }
+ } // end check if there is shape reference in submeshes
if ( found ) {
char name_meshgroup[ 30 ];
if ( i == GetSubMeshOnVertexTag() )
strcpy( name_meshgroup, "SubMeshes On Vertex" );
else if ( i == GetSubMeshOnEdgeTag() )
strcpy( name_meshgroup, "SubMeshes On Edge" );
+ else if ( i == GetSubMeshOnWireTag() )
+ strcpy( name_meshgroup, "SubMeshes On Wire" );
else if ( i == GetSubMeshOnFaceTag() )
strcpy( name_meshgroup, "SubMeshes On Face" );
+ else if ( i == GetSubMeshOnShellTag() )
+ strcpy( name_meshgroup, "SubMeshes On Shell" );
else if ( i == GetSubMeshOnSolidTag() )
strcpy( name_meshgroup, "SubMeshes On Solid" );
else if ( i == GetSubMeshOnCompoundTag() )
for ( ; itSM->More(); itSM->Next() ) {
SALOMEDS::SObject_var mySObject = itSM->Value();
CORBA::Object_var anSubObject = SObjectToObject( mySObject );
- if ( !CORBA::is_nil( anSubObject ) ) {
+ if ( !CORBA::is_nil( anSubObject ))
+ {
SMESH::SMESH_subMesh_var mySubMesh = SMESH::SMESH_subMesh::_narrow( anSubObject ) ;
int subid = myStudyContext->findId( string( GetORB()->object_to_string( anSubObject ) ) );
aSubGroup = new HDFgroup( submeshGrpName, aGroup );
aSubGroup->CreateOnDisk();
-// // Put submesh data to MED convertor
-// if ( myImpl->_mapSubMesh.find( mySubMesh->GetId() ) != myImpl->_mapSubMesh.end() ) {
-// MESSAGE( "VSR - SMESH_Gen_i::Save(): saving submesh with ID = "
-// << mySubMesh->GetId() << " to MED file" );
-// ::SMESH_subMesh* aLocalSubmesh = myImpl->_mapSubMesh[mySubMesh->GetId()];
-// myWriter.AddSubMesh( aLocalSubmesh->GetSubMeshDS(), subid );
-// }
-
- // write reference on a shape if exists
- SALOMEDS::SObject_var mySubRef;
- found = mySObject->FindSubObject( GetRefOnShapeTag(), mySubRef );
- if ( found ) {
- SALOMEDS::SObject_var myShape;
- bool ok = mySubRef->ReferencedObject( myShape );
- if ( ok ) {
- string myRefOnObject = myShape->GetID();
- if ( myRefOnObject.length() > 0 ) {
- aSize[ 0 ] = myRefOnObject.length() + 1;
- aDataset = new HDFdataset( "Ref on shape", aSubGroup, HDF_STRING, aSize, 1 );
- aDataset->CreateOnDisk();
- aDataset->WriteOnDisk( ( char* )( myRefOnObject.c_str() ) );
- aDataset->CloseOnDisk();
- }
- }
- }
+ // write reference on a shape, already checked if it exists
+ SALOMEDS::SObject_var mySubRef, myShape;
+ if ( mySObject->FindSubObject( GetRefOnShapeTag(), mySubRef ))
+ mySubRef->ReferencedObject( myShape );
+ string myRefOnObject = myShape->GetID();
+ if ( myRefOnObject.length() > 0 ) {
+ aSize[ 0 ] = myRefOnObject.length() + 1;
+ aDataset = new HDFdataset( "Ref on shape", aSubGroup, HDF_STRING, aSize, 1 );
+ aDataset->CreateOnDisk();
+ aDataset->WriteOnDisk( ( char* )( myRefOnObject.c_str() ) );
+ aDataset->CloseOnDisk();
+ }
// write applied hypotheses if exist
SALOMEDS::SObject_var mySubHypBranch;
}
}
// All sub-meshes will be stored in MED file
- myWriter.AddAllSubMeshes();
+ if ( shapeRefFound )
+ myWriter.AddAllSubMeshes();
// groups root sub-branch
SALOMEDS::SObject_var myGroupsBranch;
aGroup->CreateOnDisk();
SALOMEDS::ChildIterator_var it = myCurrentStudy->NewChildIterator( myGroupsBranch );
- int grpNb = 0;
for ( ; it->More(); it->Next() ) {
SALOMEDS::SObject_var mySObject = it->Value();
CORBA::Object_var aSubObject = SObjectToObject( mySObject );
if ( !CORBA::is_nil( aSubObject ) ) {
- SMESH_Group_i* myGroupImpl = dynamic_cast<SMESH_Group_i*>( GetServant( aSubObject ).in() );
+ SMESH_GroupBase_i* myGroupImpl =
+ dynamic_cast<SMESH_GroupBase_i*>( GetServant( aSubObject ).in() );
if ( !myGroupImpl )
continue;
// Store the group contents into MED file
if ( myLocMesh.GetGroup( myGroupImpl->GetLocalID() ) ) {
- MESSAGE( "VSR - SMESH_Gen_i::Save(): saving group with StoreName = "
+
+ if(MYDEBUG) MESSAGE( "VSR - SMESH_Gen_i::Save(): saving group with StoreName = "
<< grpName << " to MED file" );
- SMESHDS_Group* aGrpDS = myLocMesh.GetGroup( myGroupImpl->GetLocalID() )->GetGroupDS();
- aGrpDS->SetStoreName( grpName );
+ SMESHDS_GroupBase* aGrpBaseDS =
+ myLocMesh.GetGroup( myGroupImpl->GetLocalID() )->GetGroupDS();
+ aGrpBaseDS->SetStoreName( grpName );
// Pass SMESHDS_Group to MED writer
- myWriter.AddGroup( aGrpDS );
+ SMESHDS_Group* aGrpDS = dynamic_cast<SMESHDS_Group*>( aGrpBaseDS );
+ if ( aGrpDS )
+ myWriter.AddGroup( aGrpDS );
+
+ // write reference on a shape if exists
+ SMESHDS_GroupOnGeom* aGeomGrp =
+ dynamic_cast<SMESHDS_GroupOnGeom*>( aGrpBaseDS );
+ if ( aGeomGrp ) {
+ SALOMEDS::SObject_var mySubRef, myShape;
+ if (mySObject->FindSubObject( GetRefOnShapeTag(), mySubRef ) &&
+ mySubRef->ReferencedObject( myShape ) &&
+ !CORBA::is_nil( myShape->GetObject() ))
+ {
+ string myRefOnObject = myShape->GetID();
+ if ( myRefOnObject.length() > 0 ) {
+ char aRefName[ 30 ];
+ sprintf( aRefName, "Ref on shape %d", anId);
+ aSize[ 0 ] = myRefOnObject.length() + 1;
+ aDataset = new HDFdataset(aRefName, aGroup, HDF_STRING, aSize, 1);
+ aDataset->CreateOnDisk();
+ aDataset->WriteOnDisk( ( char* )( myRefOnObject.c_str() ) );
+ aDataset->CloseOnDisk();
+ }
+ }
+ else // shape ref is invalid:
+ {
+ // save a group on geometry as ordinary group
+ myWriter.AddGroup( aGeomGrp );
+ }
+ }
}
}
}
aGroup->CloseOnDisk();
}
- }
-
- // Flush current mesh information into MED file
- if ( strcmp( strHasData.c_str(), "1" ) == 0 )
- myWriter.Add();
+ } // loop on groups
+
+ if ( strcmp( strHasData.c_str(), "1" ) == 0 )
+ {
+ // Flush current mesh information into MED file
+ myWriter.Perform();
+
+ // maybe a shape was deleted in the study
+ if ( !shapeRefFound && !mySMESHDSMesh->ShapeToMesh().IsNull() ) {
+ TopoDS_Shape nullShape;
+ myLocMesh.ShapeToMesh( nullShape ); // remove shape referring data
+ }
+
+ // Store node positions on sub-shapes (SMDS_Position):
+
+ if ( !mySMESHDSMesh->SubMeshes().empty() )
+ {
+ aGroup = new HDFgroup( "Node Positions", aTopGroup );
+ aGroup->CreateOnDisk();
+
+ // in aGroup, create 5 datasets to contain:
+ // "Nodes on Edges" - ID of node on edge
+ // "Edge positions" - U parameter on node on edge
+ // "Nodes on Faces" - ID of node on face
+ // "Face U positions" - U parameter of node on face
+ // "Face V positions" - V parameter of node on face
+
+ // Find out nb of nodes on edges and faces
+ // Collect corresponing sub-meshes
+ int nbEdgeNodes = 0, nbFaceNodes = 0;
+ list<SMESHDS_SubMesh*> aEdgeSM, aFaceSM;
+ // loop on SMESHDS_SubMesh'es
+ const map<int,SMESHDS_SubMesh*>& aSubMeshes = mySMESHDSMesh->SubMeshes();
+ map<int,SMESHDS_SubMesh*>::const_iterator itSubM ( aSubMeshes.begin() );
+ for ( ; itSubM != aSubMeshes.end() ; itSubM++ )
+ {
+ SMESHDS_SubMesh* aSubMesh = (*itSubM).second;
+ if ( aSubMesh->IsComplexSubmesh() )
+ continue; // submesh containing other submeshs
+ int nbNodes = aSubMesh->NbNodes();
+ if ( nbNodes == 0 ) continue;
+
+ int aShapeID = (*itSubM).first;
+ int aShapeType = mySMESHDSMesh->IndexToShape( aShapeID ).ShapeType();
+ // write only SMDS_FacePosition and SMDS_EdgePosition
+ switch ( aShapeType ) {
+ case TopAbs_FACE:
+ nbFaceNodes += nbNodes;
+ aFaceSM.push_back( aSubMesh );
+ break;
+ case TopAbs_EDGE:
+ nbEdgeNodes += nbNodes;
+ aEdgeSM.push_back( aSubMesh );
+ break;
+ default:
+ continue;
+ }
+ }
+ // Treat positions on edges or faces
+ for ( int onFace = 0; onFace < 2; onFace++ )
+ {
+ // Create arrays to store in datasets
+ int iNode = 0, nbNodes = ( onFace ? nbFaceNodes : nbEdgeNodes );
+ if (!nbNodes) continue;
+ int* aNodeIDs = new int [ nbNodes ];
+ double* aUPos = new double [ nbNodes ];
+ double* aVPos = ( onFace ? new double[ nbNodes ] : 0 );
+
+ // Fill arrays
+ // loop on sub-meshes
+ list<SMESHDS_SubMesh*> * pListSM = ( onFace ? &aFaceSM : &aEdgeSM );
+ list<SMESHDS_SubMesh*>::iterator itSM = pListSM->begin();
+ for ( ; itSM != pListSM->end(); itSM++ )
+ {
+ SMESHDS_SubMesh* aSubMesh = (*itSM);
+ if ( aSubMesh->IsComplexSubmesh() )
+ continue; // submesh containing other submeshs
+
+ SMDS_NodeIteratorPtr itNode = aSubMesh->GetNodes();
+ // loop on nodes in aSubMesh
+ while ( itNode->more() )
+ {
+ //node ID
+ const SMDS_MeshNode* node = itNode->next();
+ aNodeIDs [ iNode ] = node->GetID();
+
+ // Position
+ const SMDS_PositionPtr pos = node->GetPosition();
+ if ( onFace ) { // on FACE
+ const SMDS_FacePosition* fPos =
+ dynamic_cast<const SMDS_FacePosition*>( pos.get() );
+ if ( fPos ) {
+ aUPos[ iNode ] = fPos->GetUParameter();
+ aVPos[ iNode ] = fPos->GetVParameter();
+ iNode++;
+ }
+ else
+ nbNodes--;
+ }
+ else { // on EDGE
+ const SMDS_EdgePosition* ePos =
+ dynamic_cast<const SMDS_EdgePosition*>( pos.get() );
+ if ( ePos ) {
+ aUPos[ iNode ] = ePos->GetUParameter();
+ iNode++;
+ }
+ else
+ nbNodes--;
+ }
+ } // loop on nodes in aSubMesh
+ } // loop on sub-meshes
+
+ // Write datasets
+ if ( nbNodes )
+ {
+ aSize[ 0 ] = nbNodes;
+ // IDS
+ string aDSName( onFace ? "Nodes on Faces" : "Nodes on Edges");
+ aDataset = new HDFdataset( (char*)aDSName.c_str(), aGroup, HDF_INT32, aSize, 1 );
+ aDataset->CreateOnDisk();
+ aDataset->WriteOnDisk( aNodeIDs );
+ aDataset->CloseOnDisk();
+
+ // U Positions
+ aDSName = ( onFace ? "Face U positions" : "Edge positions");
+ aDataset = new HDFdataset( (char*)aDSName.c_str(), aGroup, HDF_FLOAT64, aSize, 1);
+ aDataset->CreateOnDisk();
+ aDataset->WriteOnDisk( aUPos );
+ aDataset->CloseOnDisk();
+ // V Positions
+ if ( onFace ) {
+ aDataset = new HDFdataset( "Face V positions", aGroup, HDF_FLOAT64, aSize, 1);
+ aDataset->CreateOnDisk();
+ aDataset->WriteOnDisk( aVPos );
+ aDataset->CloseOnDisk();
+ }
+ }
+ delete [] aNodeIDs;
+ delete [] aUPos;
+ if ( aVPos ) delete [] aVPos;
+
+ } // treat positions on edges or faces
+
+ // close "Node Positions" group
+ aGroup->CloseOnDisk();
+
+ } // if ( there are submeshes in SMESHDS_Mesh )
+ } // if ( hasData )
// close mesh HDF group
aTopGroup->CloseOnDisk();
SALOMEDS::TMPFile* SMESH_Gen_i::SaveASCII( SALOMEDS::SComponent_ptr theComponent,
const char* theURL,
bool isMultiFile ) {
- MESSAGE( "SMESH_Gen_i::SaveASCII" );
+ if(MYDEBUG) MESSAGE( "SMESH_Gen_i::SaveASCII" );
SALOMEDS::TMPFile_var aStreamFile = Save( theComponent, theURL, isMultiFile );
return aStreamFile._retn();
}
{
INFOS( "SMESH_Gen_i::Load" );
- ASSERT( theComponent->GetStudy()->StudyId() == myCurrentStudy->StudyId() )
+ if ( myCurrentStudy->_is_nil() ||
+ theComponent->GetStudy()->StudyId() != myCurrentStudy->StudyId() )
+ SetCurrentStudy( theComponent->GetStudy() );
+
+/* if( !theComponent->_is_nil() )
+ {
+ //SALOMEDS::Study_var aStudy = SALOMEDS::Study::_narrow( theComponent->GetStudy() );
+ if( !myCurrentStudy->FindComponent( "GEOM" )->_is_nil() )
+ loadGeomData( myCurrentStudy->FindComponent( "GEOM" ) );
+ }*/
+
StudyContext* myStudyContext = GetCurrentStudyContext();
// Get temporary files location
TCollection_AsciiString tmpDir =
- isMultiFile ? TCollection_AsciiString( ( char* )theURL ) : SALOMEDS_Tool::GetTmpDir();
+ isMultiFile ? TCollection_AsciiString( ( char* )theURL ) : ( char* )SALOMEDS_Tool::GetTmpDir().c_str();
// Convert the stream into sequence of files to process
SALOMEDS::ListOfFileNames_var aFileSeq = SALOMEDS_Tool::PutStreamToFiles( theStream,
isMultiFile );
TCollection_AsciiString aStudyName( "" );
if ( isMultiFile )
- aStudyName = ( SALOMEDS_Tool::GetNameFromPath( myCurrentStudy->URL() ) );
+ aStudyName = ( (char*)SALOMEDS_Tool::GetNameFromPath( myCurrentStudy->URL() ).c_str() );
// Set names of temporary files
TCollection_AsciiString filename = tmpDir + aStudyName + TCollection_AsciiString( "_SMESH.hdf" );
aFile->OpenOnDisk( HDF_RDONLY );
}
catch ( HDFexception ) {
- MESSAGE( "Load(): " << filename << " not found!" );
+ INFOS( "Load(): " << filename << " not found!" );
return false;
}
char* hypname_str = new char[ size ];
aDataset->ReadFromDisk( hypname_str );
hypname = string( hypname_str );
- delete hypname_str;
+ delete [] hypname_str;
aDataset->CloseOnDisk();
}
// --> get hypothesis plugin library name
size = aDataset->GetSize();
char* libname_str = new char[ size ];
aDataset->ReadFromDisk( libname_str );
- SCRUTE( libname_str );
+ if(MYDEBUG) SCRUTE( libname_str );
libname = string( libname_str );
- delete libname_str;
+ delete [] libname_str;
aDataset->CloseOnDisk();
}
// --> get hypothesis data
char* hypdata_str = new char[ size ];
aDataset->ReadFromDisk( hypdata_str );
hypdata = string( hypdata_str );
- delete hypdata_str;
+ delete [] hypdata_str;
aDataset->CloseOnDisk();
}
}
// --> restore hypothesis from data
if ( id > 0 && !hypname.empty()/* && !hypdata.empty()*/ ) { // VSR : persistent data can be empty
- MESSAGE("VSR - load hypothesis : id = " << id <<
+ if(MYDEBUG) MESSAGE("VSR - load hypothesis : id = " << id <<
", name = " << hypname.c_str() << ", persistent string = " << hypdata.c_str());
SMESH::SMESH_Hypothesis_var myHyp;
myHyp = this->createHypothesis( hypname.c_str(), libname.c_str() );
}
catch (...) {
- MESSAGE( "Exception during hypothesis creation" );
+ INFOS( "Exception during hypothesis creation" );
}
SMESH_Hypothesis_i* myImpl = dynamic_cast<SMESH_Hypothesis_i*>( GetServant( myHyp ).in() );
myStudyContext->mapOldToNew( id, newId );
}
else
- MESSAGE( "VSR - SMESH_Gen::Load - can't get servant" );
+ if(MYDEBUG) MESSAGE( "VSR - SMESH_Gen::Load - can't get servant" );
}
}
}
char* hypname_str = new char[ size ];
aDataset->ReadFromDisk( hypname_str );
hypname = string( hypname_str );
- delete hypname_str;
+ delete [] hypname_str;
aDataset->CloseOnDisk();
}
// --> get algorithm plugin library name
size = aDataset->GetSize();
char* libname_str = new char[ size ];
aDataset->ReadFromDisk( libname_str );
- SCRUTE( libname_str );
+ if(MYDEBUG) SCRUTE( libname_str );
libname = string( libname_str );
- delete libname_str;
+ delete [] libname_str;
aDataset->CloseOnDisk();
}
// --> get algorithm data
size = aDataset->GetSize();
char* hypdata_str = new char[ size ];
aDataset->ReadFromDisk( hypdata_str );
- SCRUTE( hypdata_str );
+ if(MYDEBUG) SCRUTE( hypdata_str );
hypdata = string( hypdata_str );
- delete hypdata_str;
+ delete [] hypdata_str;
aDataset->CloseOnDisk();
}
}
// --> restore algorithm from data
if ( id > 0 && !hypname.empty()/* && !hypdata.empty()*/ ) { // VSR : persistent data can be empty
- MESSAGE("VSR - load algo : id = " << id <<
+ if(MYDEBUG) MESSAGE("VSR - load algo : id = " << id <<
", name = " << hypname.c_str() << ", persistent string = " << hypdata.c_str());
SMESH::SMESH_Hypothesis_var myHyp;
myHyp = this->createHypothesis( hypname.c_str(), libname.c_str() );
}
catch (...) {
- MESSAGE( "Exception during hypothesis creation" );
+ INFOS( "Exception during hypothesis creation" );
}
SMESH_Hypothesis_i* myImpl = dynamic_cast<SMESH_Hypothesis_i*>( GetServant( myHyp ).in() );
myStudyContext->mapOldToNew( id, newId );
}
else
- MESSAGE( "VSR - SMESH_Gen::Load - can't get servant" );
+ if(MYDEBUG) MESSAGE( "VSR - SMESH_Gen::Load - can't get servant" );
}
}
}
int aNbObjects = aTopGroup->nInternalObjects();
if ( aNbObjects > 0 ) {
// create mesh
- MESSAGE( "VSR - load mesh : id = " << id );
+ if(MYDEBUG) MESSAGE( "VSR - load mesh : id = " << id );
SMESH::SMESH_Mesh_var myNewMesh = this->createMesh();
SMESH_Mesh_i* myNewMeshImpl = dynamic_cast<SMESH_Mesh_i*>( GetServant( myNewMesh ).in() );
- if ( !myNewMeshImpl )
+ if ( !myNewMeshImpl )
continue;
string iorString = GetORB()->object_to_string( myNewMesh );
int newId = myStudyContext->findId( iorString );
// read mesh data from MED file
myReader.SetMesh( mySMESHDSMesh );
myReader.SetMeshId( id );
- myReader.ReadMySelf();
+ myReader.Perform();
hasData = true;
}
}
// try to read and set reference to shape
- GEOM::GEOM_Shape_var aShape;
+ GEOM::GEOM_Object_var aShapeObject;
if ( aTopGroup->ExistInternalObject( "Ref on shape" ) ) {
// load mesh "Ref on shape" - it's an entry to SObject
aDataset = new HDFdataset( "Ref on shape", aTopGroup );
SALOMEDS::SObject_var shapeSO = myCurrentStudy->FindObjectID( refFromFile );
// Make sure GEOM data are loaded first
- loadGeomData( shapeSO->GetFatherComponent() );
+ //loadGeomData( shapeSO->GetFatherComponent() );
CORBA::Object_var shapeObject = SObjectToObject( shapeSO );
if ( !CORBA::is_nil( shapeObject ) ) {
- aShape = GEOM::GEOM_Shape::_narrow( shapeObject );
- if ( !aShape->_is_nil() )
- myNewMeshImpl->setShape( aShape );
+ aShapeObject = GEOM::GEOM_Object::_narrow( shapeObject );
+ if ( !aShapeObject->_is_nil() )
+ myNewMeshImpl->SetShape( aShapeObject );
}
}
}
- // try to get applied hypotheses
- if ( aTopGroup->ExistInternalObject( "Applied Hypotheses" ) ) {
- aGroup = new HDFgroup( "Applied Hypotheses", aTopGroup );
+ // try to get applied algorithms
+ if ( aTopGroup->ExistInternalObject( "Applied Algorithms" ) ) {
+ aGroup = new HDFgroup( "Applied Algorithms", aTopGroup );
aGroup->OpenOnDisk();
- // get number of applied hypotheses
+ // get number of applied algorithms
int aNbSubObjects = aGroup->nInternalObjects();
- MESSAGE( "VSR - number of applied hypotheses = " << aNbSubObjects );
+ if(MYDEBUG) MESSAGE( "VSR - number of applied algos " << aNbSubObjects );
for ( int j = 0; j < aNbSubObjects; j++ ) {
char name_dataset[ HDF_NAME_MAX_LEN+1 ];
aGroup->InternalObjectIndentify( j, name_dataset );
- // check if it is a hypothesis
- if ( string( name_dataset ).substr( 0, 3 ) == string( "Hyp" ) ) {
+ // check if it is an algorithm
+ if ( string( name_dataset ).substr( 0, 4 ) == string( "Algo" ) ) {
aDataset = new HDFdataset( name_dataset, aGroup );
aDataset->OpenOnDisk();
size = aDataset->GetSize();
aDataset->ReadFromDisk( refFromFile );
aDataset->CloseOnDisk();
- // san - it is impossible to recover applied hypotheses using their entries within Load() method
+ // san - it is impossible to recover applied algorithms using their entries within Load() method
//SALOMEDS::SObject_var hypSO = myCurrentStudy->FindObjectID( refFromFile );
//CORBA::Object_var hypObject = SObjectToObject( hypSO );
CORBA::Object_var hypObject = GetORB()->string_to_object( anIOR.c_str() );
if ( !CORBA::is_nil( hypObject ) ) {
SMESH::SMESH_Hypothesis_var anHyp = SMESH::SMESH_Hypothesis::_narrow( hypObject );
- if ( !anHyp->_is_nil() && !aShape->_is_nil() )
- myNewMeshImpl->addHypothesis( aShape, anHyp );
+ if ( !anHyp->_is_nil() && !aShapeObject->_is_nil() )
+ myNewMeshImpl->addHypothesis( aShapeObject, anHyp );
}
}
}
}
aGroup->CloseOnDisk();
}
-
- // try to get applied algorithms
- if ( aTopGroup->ExistInternalObject( "Applied Algorithms" ) ) {
- aGroup = new HDFgroup( "Applied Algorithms", aTopGroup );
+
+ // try to get applied hypotheses
+ if ( aTopGroup->ExistInternalObject( "Applied Hypotheses" ) ) {
+ aGroup = new HDFgroup( "Applied Hypotheses", aTopGroup );
aGroup->OpenOnDisk();
- // get number of applied algorithms
+ // get number of applied hypotheses
int aNbSubObjects = aGroup->nInternalObjects();
- MESSAGE( "VSR - number of applied algos " << aNbSubObjects );
for ( int j = 0; j < aNbSubObjects; j++ ) {
char name_dataset[ HDF_NAME_MAX_LEN+1 ];
aGroup->InternalObjectIndentify( j, name_dataset );
- // check if it is an algorithm
- if ( string( name_dataset ).substr( 0, 4 ) == string( "Algo" ) ) {
+ // check if it is a hypothesis
+ if ( string( name_dataset ).substr( 0, 3 ) == string( "Hyp" ) ) {
aDataset = new HDFdataset( name_dataset, aGroup );
aDataset->OpenOnDisk();
size = aDataset->GetSize();
aDataset->ReadFromDisk( refFromFile );
aDataset->CloseOnDisk();
- // san - it is impossible to recover applied algorithms using their entries within Load() method
+ // san - it is impossible to recover applied hypotheses using their entries within Load() method
//SALOMEDS::SObject_var hypSO = myCurrentStudy->FindObjectID( refFromFile );
//CORBA::Object_var hypObject = SObjectToObject( hypSO );
CORBA::Object_var hypObject = GetORB()->string_to_object( anIOR.c_str() );
if ( !CORBA::is_nil( hypObject ) ) {
SMESH::SMESH_Hypothesis_var anHyp = SMESH::SMESH_Hypothesis::_narrow( hypObject );
- if ( !anHyp->_is_nil() && !aShape->_is_nil() )
- myNewMeshImpl->addHypothesis( aShape, anHyp );
+ if ( !anHyp->_is_nil() && !aShapeObject->_is_nil() )
+ myNewMeshImpl->addHypothesis( aShapeObject, anHyp );
}
}
}
strcpy( name_meshgroup, "SubMeshes On Vertex" );
else if ( j == GetSubMeshOnEdgeTag() )
strcpy( name_meshgroup, "SubMeshes On Edge" );
+ else if ( j == GetSubMeshOnWireTag() )
+ strcpy( name_meshgroup, "SubMeshes On Wire" );
else if ( j == GetSubMeshOnFaceTag() )
strcpy( name_meshgroup, "SubMeshes On Face" );
+ else if ( j == GetSubMeshOnShellTag() )
+ strcpy( name_meshgroup, "SubMeshes On Shell" );
else if ( j == GetSubMeshOnSolidTag() )
strcpy( name_meshgroup, "SubMeshes On Solid" );
else if ( j == GetSubMeshOnCompoundTag() )
aSubGroup->OpenOnDisk();
// try to read and set reference to subshape
- GEOM::GEOM_Shape_var aSubShape;
+ GEOM::GEOM_Object_var aSubShapeObject;
SMESH::SMESH_subMesh_var aSubMesh;
-
+
if ( aSubGroup->ExistInternalObject( "Ref on shape" ) ) {
// load submesh "Ref on shape" - it's an entry to SObject
aDataset = new HDFdataset( "Ref on shape", aSubGroup );
SALOMEDS::SObject_var subShapeSO = myCurrentStudy->FindObjectID( refFromFile );
CORBA::Object_var subShapeObject = SObjectToObject( subShapeSO );
if ( !CORBA::is_nil( subShapeObject ) ) {
- aSubShape = GEOM::GEOM_Shape::_narrow( subShapeObject );
- if ( !aSubShape->_is_nil() )
+ aSubShapeObject = GEOM::GEOM_Object::_narrow( subShapeObject );
+ if ( !aSubShapeObject->_is_nil() )
aSubMesh = SMESH::SMESH_subMesh::_duplicate
- ( myNewMeshImpl->createSubMesh( aSubShape ) );
+ ( myNewMeshImpl->createSubMesh( aSubShapeObject ) );
if ( aSubMesh->_is_nil() )
continue;
string iorSubString = GetORB()->object_to_string( aSubMesh );
// VSR: Get submesh data from MED convertor
// int anInternalSubmeshId = aSubMesh->GetId(); // this is not a persistent ID, it's an internal one computed from sub-shape
// if (myNewMeshImpl->_mapSubMesh.find(anInternalSubmeshId) != myNewMeshImpl->_mapSubMesh.end()) {
-// MESSAGE("VSR - SMESH_Gen_i::Load(): loading from MED file submesh with ID = " <<
+// if(MYDEBUG) MESSAGE("VSR - SMESH_Gen_i::Load(): loading from MED file submesh with ID = " <<
// subid << " for subshape # " << anInternalSubmeshId);
// SMESHDS_SubMesh* aSubMeshDS =
// myNewMeshImpl->_mapSubMesh[anInternalSubmeshId]->CreateSubMeshDS();
// if ( !aSubMeshDS ) {
-// MESSAGE("VSR - SMESH_Gen_i::Load(): FAILED to create a submesh for subshape # " <<
+// if(MYDEBUG) MESSAGE("VSR - SMESH_Gen_i::Load(): FAILED to create a submesh for subshape # " <<
// anInternalSubmeshId << " in current mesh!");
// }
// else
// myReader.GetSubMesh( aSubMeshDS, subid );
// }
- // try to get applied hypotheses
- if ( aSubGroup->ExistInternalObject( "Applied Hypotheses" ) ) {
- // open "applied hypotheses" HDF group
- aSubSubGroup = new HDFgroup( "Applied Hypotheses", aSubGroup );
+ // try to get applied algorithms
+ if ( aSubGroup->ExistInternalObject( "Applied Algorithms" ) ) {
+ // open "applied algorithms" HDF group
+ aSubSubGroup = new HDFgroup( "Applied Algorithms", aSubGroup );
aSubSubGroup->OpenOnDisk();
- // get number of applied hypotheses
+ // get number of applied algorithms
int aNbSubObjects = aSubSubGroup->nInternalObjects();
for ( int l = 0; l < aNbSubObjects; l++ ) {
char name_dataset[ HDF_NAME_MAX_LEN+1 ];
aSubSubGroup->InternalObjectIndentify( l, name_dataset );
- // check if it is a hypothesis
- if ( string( name_dataset ).substr( 0, 3 ) == string( "Hyp" ) ) {
+ // check if it is an algorithm
+ if ( string( name_dataset ).substr( 0, 4 ) == string( "Algo" ) ) {
aDataset = new HDFdataset( name_dataset, aSubSubGroup );
aDataset->OpenOnDisk();
size = aDataset->GetSize();
char* refFromFile = new char[ size ];
aDataset->ReadFromDisk( refFromFile );
aDataset->CloseOnDisk();
-
+
//SALOMEDS::SObject_var hypSO = myCurrentStudy->FindObjectID( refFromFile );
//CORBA::Object_var hypObject = SObjectToObject( hypSO );
int id = atoi( refFromFile );
CORBA::Object_var hypObject = GetORB()->string_to_object( anIOR.c_str() );
if ( !CORBA::is_nil( hypObject ) ) {
SMESH::SMESH_Hypothesis_var anHyp = SMESH::SMESH_Hypothesis::_narrow( hypObject );
- if ( !anHyp->_is_nil() && !aShape->_is_nil() )
- myNewMeshImpl->addHypothesis( aSubShape, anHyp );
+ if ( !anHyp->_is_nil() && !aShapeObject->_is_nil() )
+ myNewMeshImpl->addHypothesis( aSubShapeObject, anHyp );
}
}
}
}
- // close "applied hypotheses" HDF group
+ // close "applied algorithms" HDF group
aSubSubGroup->CloseOnDisk();
}
-
- // try to get applied algorithms
- if ( aSubGroup->ExistInternalObject( "Applied Algorithms" ) ) {
- // open "applied algorithms" HDF group
- aSubSubGroup = new HDFgroup( "Applied Algorithms", aSubGroup );
+
+ // try to get applied hypotheses
+ if ( aSubGroup->ExistInternalObject( "Applied Hypotheses" ) ) {
+ // open "applied hypotheses" HDF group
+ aSubSubGroup = new HDFgroup( "Applied Hypotheses", aSubGroup );
aSubSubGroup->OpenOnDisk();
- // get number of applied algorithms
+ // get number of applied hypotheses
int aNbSubObjects = aSubSubGroup->nInternalObjects();
for ( int l = 0; l < aNbSubObjects; l++ ) {
char name_dataset[ HDF_NAME_MAX_LEN+1 ];
aSubSubGroup->InternalObjectIndentify( l, name_dataset );
- // check if it is an algorithm
- if ( string( name_dataset ).substr( 0, 4 ) == string( "Algo" ) ) {
+ // check if it is a hypothesis
+ if ( string( name_dataset ).substr( 0, 3 ) == string( "Hyp" ) ) {
aDataset = new HDFdataset( name_dataset, aSubSubGroup );
aDataset->OpenOnDisk();
size = aDataset->GetSize();
char* refFromFile = new char[ size ];
aDataset->ReadFromDisk( refFromFile );
aDataset->CloseOnDisk();
-
+
//SALOMEDS::SObject_var hypSO = myCurrentStudy->FindObjectID( refFromFile );
//CORBA::Object_var hypObject = SObjectToObject( hypSO );
int id = atoi( refFromFile );
CORBA::Object_var hypObject = GetORB()->string_to_object( anIOR.c_str() );
if ( !CORBA::is_nil( hypObject ) ) {
SMESH::SMESH_Hypothesis_var anHyp = SMESH::SMESH_Hypothesis::_narrow( hypObject );
- if ( !anHyp->_is_nil() && !aShape->_is_nil() )
- myNewMeshImpl->addHypothesis( aSubShape, anHyp );
+ if ( !anHyp->_is_nil() && !aShapeObject->_is_nil() )
+ myNewMeshImpl->addHypothesis( aSubShapeObject, anHyp );
}
}
}
}
- // close "applied algorithms" HDF group
+ // close "applied hypotheses" HDF group
aSubSubGroup->CloseOnDisk();
}
-
+
// close submesh HDF group
aSubGroup->CloseOnDisk();
}
}
}
- if(hasData){
+ if(hasData) {
// Read sub-meshes from MED
- MESSAGE("JFA - Create all sub-meshes");
+ if(MYDEBUG) MESSAGE("Create all sub-meshes");
myReader.CreateAllSubMeshes();
- }
+
+
+ // Read node positions on sub-shapes (SMDS_Position)
+
+ if ( aTopGroup->ExistInternalObject( "Node Positions" ))
+ {
+ // There are 5 datasets to read:
+ // "Nodes on Edges" - ID of node on edge
+ // "Edge positions" - U parameter on node on edge
+ // "Nodes on Faces" - ID of node on face
+ // "Face U positions" - U parameter of node on face
+ // "Face V positions" - V parameter of node on face
+ char* aEid_DSName = "Nodes on Edges";
+ char* aEu_DSName = "Edge positions";
+ char* aFu_DSName = "Face U positions";
+ //char* aFid_DSName = "Nodes on Faces";
+ //char* aFv_DSName = "Face V positions";
+
+ // data to retrieve
+ int nbEids = 0, nbFids = 0;
+ int *aEids = 0, *aFids = 0;
+ double *aEpos = 0, *aFupos = 0, *aFvpos = 0;
+
+ // open a group
+ aGroup = new HDFgroup( "Node Positions", aTopGroup );
+ aGroup->OpenOnDisk();
+
+ // loop on 5 data sets
+ int aNbObjects = aGroup->nInternalObjects();
+ for ( int i = 0; i < aNbObjects; i++ )
+ {
+ // identify dataset
+ char aDSName[ HDF_NAME_MAX_LEN+1 ];
+ aGroup->InternalObjectIndentify( i, aDSName );
+ // read data
+ aDataset = new HDFdataset( aDSName, aGroup );
+ aDataset->OpenOnDisk();
+ if ( aDataset->GetType() == HDF_FLOAT64 ) // Positions
+ {
+ double* pos = new double [ aDataset->GetSize() ];
+ aDataset->ReadFromDisk( pos );
+ // which one?
+ if ( strncmp( aDSName, aEu_DSName, strlen( aEu_DSName )) == 0 )
+ aEpos = pos;
+ else if ( strncmp( aDSName, aFu_DSName, strlen( aFu_DSName )) == 0 )
+ aFupos = pos;
+ else
+ aFvpos = pos;
+ }
+ else // NODE IDS
+ {
+ int aSize = aDataset->GetSize();
+
+ // for reading files, created from 18.07.2005 till 10.10.2005
+ if (aDataset->GetType() == HDF_STRING)
+ aSize /= sizeof(int);
+
+ int* ids = new int [aSize];
+ aDataset->ReadFromDisk( ids );
+ // on face or nodes?
+ if ( strncmp( aDSName, aEid_DSName, strlen( aEid_DSName )) == 0 ) {
+ aEids = ids;
+ nbEids = aSize;
+ }
+ else {
+ aFids = ids;
+ nbFids = aSize;
+ }
+ }
+ } // loop on 5 datasets
+
+ // Set node positions on edges or faces
+ for ( int onFace = 0; onFace < 2; onFace++ )
+ {
+ int nbNodes = ( onFace ? nbFids : nbEids );
+ if ( nbNodes == 0 ) continue;
+ int* aNodeIDs = ( onFace ? aFids : aEids );
+ double* aUPos = ( onFace ? aFupos : aEpos );
+ double* aVPos = ( onFace ? aFvpos : 0 );
+ // loop on node IDs
+ for ( int iNode = 0; iNode < nbNodes; iNode++ )
+ {
+ const SMDS_MeshNode* node = mySMESHDSMesh->FindNode( aNodeIDs[ iNode ]);
+ ASSERT( node );
+ SMDS_PositionPtr aPos = node->GetPosition();
+ ASSERT( aPos )
+ if ( onFace ) {
+ ASSERT( aPos->GetTypeOfPosition() == SMDS_TOP_FACE );
+ SMDS_FacePosition* fPos = const_cast<SMDS_FacePosition*>
+ ( static_cast<const SMDS_FacePosition*>( aPos.get() ));
+ fPos->SetUParameter( aUPos[ iNode ]);
+ fPos->SetVParameter( aVPos[ iNode ]);
+ }
+ else {
+ ASSERT( aPos->GetTypeOfPosition() == SMDS_TOP_EDGE );
+ SMDS_EdgePosition* fPos = const_cast<SMDS_EdgePosition*>
+ ( static_cast<const SMDS_EdgePosition*>( aPos.get() ));
+ fPos->SetUParameter( aUPos[ iNode ]);
+ }
+ }
+ }
+ if ( aEids ) delete [] aEids;
+ if ( aFids ) delete [] aFids;
+ if ( aEpos ) delete [] aEpos;
+ if ( aFupos ) delete [] aFupos;
+ if ( aFvpos ) delete [] aFvpos;
+
+ aGroup->CloseOnDisk();
+
+ } // if ( aTopGroup->ExistInternalObject( "Node Positions" ) )
+ } // if ( hasData )
// Recompute State (as computed sub-meshes are restored from MED)
- if ( !aShape->_is_nil() ) {
- MESSAGE("JFA - Compute State Engine ...");
-// map<int, ::SMESH_subMesh*>::iterator anAllSubMeshes = myNewMeshImpl->_mapSubMesh.begin();
-// for (; anAllSubMeshes != myNewMeshImpl->_mapSubMesh.end(); anAllSubMeshes++)
-// {
-// (*anAllSubMeshes).second->GetSubMeshDS(); // init SMESH_subMesh::_meshDS
-// (*anAllSubMeshes).second->ComputeStateEngine(SMESH_subMesh::SUBMESH_RESTORED);
-// }
- TopoDS_Shape myLocShape = GetShapeReader()->GetShape( GetGeomEngine(), aShape );
- myNewMeshImpl->GetImpl().GetSubMesh(myLocShape)->ComputeStateEngine(SMESH_subMesh::SUBMESH_RESTORED);
- MESSAGE("JFA - Compute State Engine finished");
+ if ( !aShapeObject->_is_nil() ) {
+ MESSAGE("Compute State Engine ...");
+ TopoDS_Shape myLocShape = GeomObjectToShape( aShapeObject );
+ myNewMeshImpl->GetImpl().GetSubMesh(myLocShape)->ComputeStateEngine
+ (SMESH_subMesh::SUBMESH_RESTORED);
+ MESSAGE("Compute State Engine finished");
}
// try to get groups
char* nameFromFile = new char[ size ];
aDataset->ReadFromDisk( nameFromFile );
aDataset->CloseOnDisk();
-
+
+ // Try to find a shape reference
+ TopoDS_Shape aShape;
+ char aRefName[ 30 ];
+ sprintf( aRefName, "Ref on shape %d", subid);
+ if ( aGroup->ExistInternalObject( aRefName ) ) {
+ // load mesh "Ref on shape" - it's an entry to SObject
+ aDataset = new HDFdataset( aRefName, aGroup );
+ aDataset->OpenOnDisk();
+ size = aDataset->GetSize();
+ char* refFromFile = new char[ size ];
+ aDataset->ReadFromDisk( refFromFile );
+ aDataset->CloseOnDisk();
+ if ( strlen( refFromFile ) > 0 ) {
+ SALOMEDS::SObject_var shapeSO = myCurrentStudy->FindObjectID( refFromFile );
+ CORBA::Object_var shapeObject = SObjectToObject( shapeSO );
+ if ( !CORBA::is_nil( shapeObject ) ) {
+ aShapeObject = GEOM::GEOM_Object::_narrow( shapeObject );
+ if ( !aShapeObject->_is_nil() )
+ aShape = GeomObjectToShape( aShapeObject );
+ }
+ }
+ }
// Create group servant
- SMESH::SMESH_Group_var aNewGroup = SMESH::SMESH_Group::_duplicate
- ( myNewMeshImpl->createGroup( (SMESH::ElementType)(ii - GetNodeGroupsTag() + 1),
- nameFromFile ) );
+ SMESH::ElementType type = (SMESH::ElementType)(ii - GetNodeGroupsTag() + 1);
+ SMESH::SMESH_GroupBase_var aNewGroup = SMESH::SMESH_GroupBase::_duplicate
+ ( myNewMeshImpl->createGroup( type, nameFromFile, aShape ) );
// Obtain a SMESHDS_Group object
if ( aNewGroup->_is_nil() )
continue;
int newSubId = myStudyContext->findId( iorSubString );
myStudyContext->mapOldToNew( subid, newSubId );
- SMESH_Group_i* aGroupImpl = dynamic_cast<SMESH_Group_i*>( GetServant( aNewGroup ).in() );
+ SMESH_GroupBase_i* aGroupImpl =
+ dynamic_cast<SMESH_GroupBase_i*>( GetServant( aNewGroup ).in() );
if ( !aGroupImpl )
continue;
if ( !aLocalGroup )
continue;
- SMESHDS_Group* aGroupDS = aLocalGroup->GetGroupDS();
- aGroupDS->SetStoreName( name_dataset );
+ SMESHDS_GroupBase* aGroupBaseDS = aLocalGroup->GetGroupDS();
+ aGroupBaseDS->SetStoreName( name_dataset );
// Fill group with contents from MED file
- myReader.GetGroup( aGroupDS );
+ SMESHDS_Group* aGrp = dynamic_cast<SMESHDS_Group*>( aGroupBaseDS );
+ if ( aGrp )
+ myReader.GetGroup( aGrp );
}
}
aGroup->CloseOnDisk();
const SALOMEDS::TMPFile& theStream,
const char* theURL,
bool isMultiFile ) {
- MESSAGE( "SMESH_Gen_i::LoadASCII" );
+ if(MYDEBUG) MESSAGE( "SMESH_Gen_i::LoadASCII" );
return Load( theComponent, theStream, theURL, isMultiFile );
}
void SMESH_Gen_i::Close( SALOMEDS::SComponent_ptr theComponent )
{
- MESSAGE( "SMESH_Gen_i::Close" );
+ if(MYDEBUG) MESSAGE( "SMESH_Gen_i::Close" );
// Clear study contexts data
- int studyId = myCurrentStudy->StudyId();
+ int studyId = GetCurrentStudyID();
if ( myStudyContextMap.find( studyId ) != myStudyContextMap.end() ) {
delete myStudyContextMap[ studyId ];
myStudyContextMap.erase( studyId );
char* SMESH_Gen_i::ComponentDataType()
{
- MESSAGE( "SMESH_Gen_i::ComponentDataType" );
- return strdup( "SMESH" );
+ if(MYDEBUG) MESSAGE( "SMESH_Gen_i::ComponentDataType" );
+ return CORBA::string_dup( "SMESH" );
}
*/
//=============================================================================
-char* SMESH_Gen_i::IORToLocalPersistentID( SALOMEDS::SObject_ptr theSObject,
+char* SMESH_Gen_i::IORToLocalPersistentID( SALOMEDS::SObject_ptr /*theSObject*/,
const char* IORString,
- CORBA::Boolean isMultiFile,
- CORBA::Boolean isASCII )
+ CORBA::Boolean /*isMultiFile*/,
+ CORBA::Boolean /*isASCII*/ )
{
- MESSAGE( "SMESH_Gen_i::IORToLocalPersistentID" );
+ if(MYDEBUG) MESSAGE( "SMESH_Gen_i::IORToLocalPersistentID" );
StudyContext* myStudyContext = GetCurrentStudyContext();
- if ( strcmp( IORString, "" ) != 0 ) {
+ if ( myStudyContext && strcmp( IORString, "" ) != 0 ) {
int anId = myStudyContext->findId( IORString );
if ( anId ) {
- MESSAGE( "VSR " << anId )
+ if(MYDEBUG) MESSAGE( "VSR " << anId )
char strId[ 20 ];
sprintf( strId, "%d", anId );
return CORBA::string_dup( strId );
}
}
- return strdup( "" );
+ return CORBA::string_dup( "" );
}
//=============================================================================
*/
//=============================================================================
-char* SMESH_Gen_i::LocalPersistentIDToIOR( SALOMEDS::SObject_ptr theSObject,
+char* SMESH_Gen_i::LocalPersistentIDToIOR( SALOMEDS::SObject_ptr /*theSObject*/,
const char* aLocalPersistentID,
- CORBA::Boolean isMultiFile,
- CORBA::Boolean isASCII )
+ CORBA::Boolean /*isMultiFile*/,
+ CORBA::Boolean /*isASCII*/ )
{
- MESSAGE( "SMESH_Gen_i::LocalPersistentIDToIOR(): id = " << aLocalPersistentID );
+ if(MYDEBUG) MESSAGE( "SMESH_Gen_i::LocalPersistentIDToIOR(): id = " << aLocalPersistentID );
StudyContext* myStudyContext = GetCurrentStudyContext();
- if ( strcmp( aLocalPersistentID, "" ) != 0 ) {
+ if ( myStudyContext && strcmp( aLocalPersistentID, "" ) != 0 ) {
int anId = atoi( aLocalPersistentID );
return CORBA::string_dup( myStudyContext->getIORbyOldId( anId ).c_str() );
}
- return strdup( "" );
-}
-
-//=============================================================================
-/*!
- * SMESH_Gen_i::CanPublishInStudy
- *
- * Returns true if object can be published in the study
- */
-//=============================================================================
-
-bool SMESH_Gen_i::CanPublishInStudy(CORBA::Object_ptr theIOR)
-{
- SMESH::SMESH_Mesh_var aMesh = SMESH::SMESH_Mesh::_narrow(theIOR);
- if( !aMesh->_is_nil() )
- return true;
-
- SMESH::SMESH_subMesh_var aSubMesh = SMESH::SMESH_subMesh::_narrow(theIOR);
- if( !aSubMesh->_is_nil() )
- return true;
-
- SMESH::SMESH_Hypothesis_var aHyp = SMESH::SMESH_Hypothesis::_narrow(theIOR);
- if( !aHyp->_is_nil() )
- return true;
-
- SMESH::SMESH_Group_var aGroup = SMESH::SMESH_Group::_narrow(theIOR);
- if( !aGroup->_is_nil() )
- return true;
-
- return false;
+ return CORBA::string_dup( "" );
}
-//=============================================================================
-/*!
- * SMESH_Gen_i::PublishInStudy
- *
- * Publish object in the study
- */
-//=============================================================================
+//=======================================================================
+//function : RegisterObject
+//purpose :
+//=======================================================================
-SALOMEDS::SObject_ptr SMESH_Gen_i::PublishInStudy(SALOMEDS::Study_ptr theStudy,
- SALOMEDS::SObject_ptr theSObject,
- CORBA::Object_ptr theIOR,
- const char* theName)
-throw (SALOME::SALOME_Exception)
+int SMESH_Gen_i::RegisterObject(CORBA::Object_ptr theObject)
{
- Unexpect aCatch(SALOME_SalomeException);
- MESSAGE( "********** SMESH_Gen_i::PublishInStudy()" );
- SALOMEDS::SObject_var aSO;
-
- // san - first try to find SObject corresponding to SMESH component in theStudy
- // It is dangerous to use FindComponent("MESH") for this, as some other component
- // of type "MESH" might be present in theStudy.
- // So component's user name obtained from ModuleCatalog is passed to FindObject()...
- SALOME_ModuleCatalog::ModuleCatalog_var aCat =
- SALOME_ModuleCatalog::ModuleCatalog::_narrow( GetNS()->Resolve("/Kernel/ModulCatalog") );
- if ( CORBA::is_nil( aCat ) )
- return aSO._retn();
-
- SALOME_ModuleCatalog::Acomponent_var aComp = aCat->GetComponent( "SMESH" );
- if ( CORBA::is_nil( aComp ) )
- return aSO._retn();
-
- SALOMEDS::SComponent_var father =
- SALOMEDS::SComponent::_narrow( theStudy->FindObject( strdup( aComp->componentusername() ) ) );
- SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder();
-
- SALOMEDS::GenericAttribute_var anAttr;
- SALOMEDS::AttributeName_var aName;
- SALOMEDS::AttributePixMap_var aPixmap;
-
- if ( father->_is_nil() ) {
- father = aStudyBuilder->NewComponent( "MESH" );
- anAttr = aStudyBuilder->FindOrCreateAttribute( father, "AttributeName" );
- aName = SALOMEDS::AttributeName::_narrow( anAttr );
- aName ->SetValue( strdup( aComp->componentusername() ) );
- anAttr = aStudyBuilder->FindOrCreateAttribute( father, "AttributePixMap" );
- aPixmap = SALOMEDS::AttributePixMap::_narrow( anAttr );
- aPixmap ->SetPixMap( "ICON_OBJBROWSER_SMESH" );
- aStudyBuilder->DefineComponentInstance( father, SMESH_Gen::_this() );
- }
-
- if ( father->_is_nil() )
- return aSO._retn();
-
- SALOMEDS::AttributeIOR_var anIOR;
- SALOMEDS::AttributeSelectable_var aSelAttr;
- TCollection_AsciiString anObjName("obj");
-
- // Publishing a mesh
- SMESH::SMESH_Mesh_var aMesh = SMESH::SMESH_Mesh::_narrow( theIOR );
- if( !aMesh->_is_nil() ) {
- // Find correct free tag
- long aTag = FindMaxChildTag( father.in() );
- if ( aTag <= GetAlgorithmsRootTag() )
- aTag = GetAlgorithmsRootTag() + 1;
- else
- aTag++;
- // Add New Mesh
- SALOMEDS::SObject_var newMesh = aStudyBuilder->NewObjectToTag( father, aTag );
- anAttr = aStudyBuilder->FindOrCreateAttribute( newMesh, "AttributePixMap" );
- aPixmap = SALOMEDS::AttributePixMap::_narrow( anAttr );
- aPixmap ->SetPixMap( "ICON_SMESH_TREE_MESH" );
- anAttr = aStudyBuilder->FindOrCreateAttribute( newMesh, "AttributeIOR" );
- anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
- anIOR ->SetValue( GetORB()->object_to_string( aMesh ) );
- aSO = SALOMEDS::SObject::_narrow( newMesh );
- anObjName = TCollection_AsciiString( "Mesh" );
- }
-
- // Publishing a sub-mesh
- SMESH::SMESH_subMesh_var aSubMesh = SMESH::SMESH_subMesh::_narrow( theIOR );
- if( aSO->_is_nil() && !aSubMesh->_is_nil() ) {
- // try to obtain a parent mesh's SObject
- MESSAGE( "********** SMESH_Gen_i::PublishInStudy(): publishing submesh..." );
- SALOMEDS::SObject_var aParentSO;
- SMESH::SMESH_Mesh_var aParentMesh;
- SMESH_subMesh_i* aServant = dynamic_cast<SMESH_subMesh_i*>( GetServant( aSubMesh ).in() );
- if ( aServant != NULL ) {
- aParentMesh = aServant->_mesh_i->_this();
- if ( !aParentMesh->_is_nil() ) {
- aParentSO = theStudy->FindObjectIOR( GetORB()->object_to_string( aParentMesh ) );
- }
- }
-
- // Find submesh sub-tree tag
- if ( !aParentSO->_is_nil() ) {
- long aRootTag = GetSubMeshOnVertexTag();
- char* aRootName = "";
-
- SMESH_Mesh_i* aMeshServant = aServant->_mesh_i;
- if ( aMeshServant->_mapSubMesh.find( aServant->GetId() ) != aMeshServant->_mapSubMesh.end() ) {
- MESSAGE( "********** SMESH_Gen_i::PublishInStudy(): local submesh found" )
- SMESH_subMesh* aLocalSubMesh = aMeshServant->_mapSubMesh[aServant->GetId()];
- switch ( aLocalSubMesh->GetSubShape().ShapeType() ) {
- case TopAbs_VERTEX:
- aRootTag = GetSubMeshOnVertexTag();
- aRootName = "SubMeshes on Vertex";
- break;
- case TopAbs_EDGE:
- aRootTag = GetSubMeshOnEdgeTag();
- aRootName = "SubMeshes on Edge";
- break;
- case TopAbs_FACE:
- aRootTag = GetSubMeshOnFaceTag();
- aRootName = "SubMeshes on Face";
- break;
- case TopAbs_SOLID:
- aRootTag = GetSubMeshOnSolidTag();
- aRootName = "SubMeshes on Solid";
- break;
- default:
- aRootTag = GetSubMeshOnCompoundTag();
- aRootName = "SubMeshes on Compound";
- break;
- }
- }
-
- // Find or create submesh root
- SALOMEDS::SObject_var aRootSO;
- if ( !aParentSO->FindSubObject ( aRootTag, aRootSO ) ) {
- MESSAGE( "********** SMESH_Gen_i::PublishInStudy(): creating submesh root..." )
- aRootSO = aStudyBuilder->NewObjectToTag( aParentSO, aRootTag );
- anAttr = aStudyBuilder->FindOrCreateAttribute( aRootSO, "AttributeName" );
- aName = SALOMEDS::AttributeName::_narrow( anAttr );
- aName ->SetValue( aRootName );
- anAttr = aStudyBuilder->FindOrCreateAttribute( aRootSO, "AttributeSelectable" );
- aSelAttr = SALOMEDS::AttributeSelectable::_narrow( anAttr );
- aSelAttr ->SetSelectable( false );
- }
-
- // Add new submesh to corresponding sub-tree
- MESSAGE( "********** SMESH_Gen_i::PublishInStudy(): adding submesh to study..." )
- SALOMEDS::SObject_var newMesh = aStudyBuilder->NewObject( aRootSO );
- anAttr = aStudyBuilder->FindOrCreateAttribute( newMesh, "AttributePixMap" );
- aPixmap = SALOMEDS::AttributePixMap::_narrow( anAttr );
- aPixmap ->SetPixMap( "ICON_SMESH_TREE_MESH" );
- anAttr = aStudyBuilder->FindOrCreateAttribute( newMesh, "AttributeIOR" );
- anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
- anIOR ->SetValue( GetORB()->object_to_string( aSubMesh ) );
- aSO = SALOMEDS::SObject::_narrow( newMesh );
- anObjName = TCollection_AsciiString( "SubMesh" );
- }
- }
-
- // Publishing a hypothesis or algorithm
- SMESH::SMESH_Hypothesis_var aHyp = SMESH::SMESH_Hypothesis::_narrow( theIOR );
- if( aSO->_is_nil() && !aHyp->_is_nil() ) {
- //Find or Create Hypothesis root
- SALOMEDS::SObject_var HypothesisRoot;
- Standard_Integer aRootTag =
- SMESH::SMESH_Algo::_narrow( theIOR )->_is_nil() ? GetHypothesisRootTag() : GetAlgorithmsRootTag();
-
- if ( !father->FindSubObject ( aRootTag, HypothesisRoot ) ) {
- HypothesisRoot = aStudyBuilder->NewObjectToTag( father, aRootTag );
- anAttr = aStudyBuilder->FindOrCreateAttribute( HypothesisRoot, "AttributeName" );
- aName = SALOMEDS::AttributeName::_narrow( anAttr );
- aName ->SetValue( aRootTag == GetHypothesisRootTag() ? "Hypotheses" : "Algorithms" );
- anAttr = aStudyBuilder->FindOrCreateAttribute( HypothesisRoot, "AttributeSelectable" );
- aSelAttr = SALOMEDS::AttributeSelectable::_narrow( anAttr );
- aSelAttr ->SetSelectable( false );
- anAttr = aStudyBuilder->FindOrCreateAttribute( HypothesisRoot, "AttributePixMap" );
- aPixmap = SALOMEDS::AttributePixMap::_narrow( anAttr );
- aPixmap ->SetPixMap( aRootTag == GetHypothesisRootTag() ? "ICON_SMESH_TREE_HYPO" : "ICON_SMESH_TREE_ALGO" );
- }
-
- // Add New Hypothesis
- string aPmName;
- SALOMEDS::SObject_var newHypo = aStudyBuilder->NewObject( HypothesisRoot );
- anAttr = aStudyBuilder->FindOrCreateAttribute( newHypo, "AttributePixMap" );
- aPixmap = SALOMEDS::AttributePixMap::_narrow( anAttr );
- aPmName = ( aRootTag == GetHypothesisRootTag() ? "ICON_SMESH_TREE_HYPO_" : "ICON_SMESH_TREE_ALGO_" );
- aPmName += aHyp->GetName();
- aPixmap ->SetPixMap( aPmName.c_str() );
- anAttr = aStudyBuilder->FindOrCreateAttribute( newHypo, "AttributeIOR" );
- anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
- anIOR ->SetValue( GetORB()->object_to_string( aHyp ) );
- aSO = SALOMEDS::SObject::_narrow( newHypo );
- anObjName = TCollection_AsciiString( aHyp->GetName() );
- }
-
- // Publishing a group
- SMESH::SMESH_Group_var aGroup = SMESH::SMESH_Group::_narrow(theIOR);
- if( aSO->_is_nil() && !aGroup->_is_nil() ) {
- // try to obtain a parent mesh's SObject
- MESSAGE( "********** SMESH_Gen_i::PublishInStudy(): publishing group..." );
- SALOMEDS::SObject_var aParentSO;
- SMESH::SMESH_Mesh_var aParentMesh;
- SMESH_Group_i* aServant = dynamic_cast<SMESH_Group_i*>( GetServant( aGroup ).in() );
- if ( aServant != NULL ) {
- aParentMesh = SMESH::SMESH_Mesh::_narrow( GetPOA()->servant_to_reference( aServant->GetMeshServant() ) );
- if ( !aParentMesh->_is_nil() ) {
- MESSAGE( "********** SMESH_Gen_i::PublishInStudy(): publishing group: refernce to mesh is OK" );
- string anIOR = GetORB()->object_to_string( aParentMesh );
- MESSAGE( "********** SMESH_Gen_i::PublishInStudy(): publishing group: mesh IOR = "<<anIOR.c_str() );
- aParentSO = theStudy->FindObjectIOR( anIOR.c_str() );
- }
- }
-
- // Find proper group sub-tree tag
- if ( !aParentSO->_is_nil() ) {
- MESSAGE( "********** SMESH_Gen_i::PublishInStudy(): publishing group: parent mesh found" );
- int aType = (int)aGroup->GetType();
- const char* aRootNames[] = { "Compound Groups", "Groups of Nodes", "Groups of Edges", "Groups of Faces", "Groups of Volumes" };
-
- // Currently, groups with heterogenous content are not supported
- if ( aType != SMESH::ALL ) {
- MESSAGE( "********** SMESH_Gen_i::PublishInStudy(): publishing group: group type OK" );
- long aRootTag = GetNodeGroupsTag() + aType - 1;
-
- // Find or create groups root
- SALOMEDS::SObject_var aRootSO;
- if ( !aParentSO->FindSubObject ( aRootTag, aRootSO ) ) {
- MESSAGE( "********** SMESH_Gen_i::PublishInStudy(): creating groups root..." )
- aRootSO = aStudyBuilder->NewObjectToTag( aParentSO, aRootTag );
- anAttr = aStudyBuilder->FindOrCreateAttribute( aRootSO, "AttributeName" );
- aName = SALOMEDS::AttributeName::_narrow( anAttr );
- aName ->SetValue( aRootNames[aType] );
- anAttr = aStudyBuilder->FindOrCreateAttribute( aRootSO, "AttributeSelectable" );
- aSelAttr = SALOMEDS::AttributeSelectable::_narrow( anAttr );
- aSelAttr ->SetSelectable( false );
- }
-
- // Add new group to corresponding sub-tree
- MESSAGE( "********** SMESH_Gen_i::PublishInStudy(): adding group to study..." )
- SALOMEDS::SObject_var aGroupSO = aStudyBuilder->NewObject( aRootSO );
- anAttr = aStudyBuilder->FindOrCreateAttribute( aGroupSO, "AttributePixMap" );
- aPixmap = SALOMEDS::AttributePixMap::_narrow( anAttr );
- aPixmap ->SetPixMap( "ICON_SMESH_TREE_GROUP" );
- anAttr = aStudyBuilder->FindOrCreateAttribute( aGroupSO, "AttributeIOR" );
- anIOR = SALOMEDS::AttributeIOR::_narrow( anAttr );
- anIOR ->SetValue( GetORB()->object_to_string( aGroup ) );
- aSO = SALOMEDS::SObject::_narrow( aGroupSO );
- anObjName = TCollection_AsciiString( "Group" );
- }
- }
- }
-
- // Setting SObject's name
- if ( !aSO->_is_nil() ) {
- if ( strlen( theName ) == 0 )
- anObjName += TCollection_AsciiString( "_" ) + TCollection_AsciiString( aSO->Tag() );
- else
- anObjName = TCollection_AsciiString( strdup( theName ) );
- anAttr = aStudyBuilder->FindOrCreateAttribute( aSO, "AttributeName" );
- aName = SALOMEDS::AttributeName::_narrow( anAttr );
- aName ->SetValue( anObjName.ToCString() );
+ StudyContext* myStudyContext = GetCurrentStudyContext();
+ if ( myStudyContext && !CORBA::is_nil( theObject )) {
+ string iorString = GetORB()->object_to_string( theObject );
+ return myStudyContext->addObject( iorString );
}
-
- MESSAGE( "********** SMESH_Gen_i::PublishInStudy(): COMPLETED" )
- return aSO._retn();
+ return 0;
}
//=============================================================================
const char* instanceName,
const char* interfaceName )
{
- MESSAGE( "PortableServer::ObjectId* SMESHEngine_factory()" );
- SCRUTE(interfaceName);
- SMESH_Gen_i * mySMESH_Gen
- = new SMESH_Gen_i(orb, poa, contId, instanceName, interfaceName);
- return mySMESH_Gen->getId() ;
+ if(MYDEBUG) MESSAGE( "PortableServer::ObjectId* SMESHEngine_factory()" );
+ if(MYDEBUG) SCRUTE(interfaceName);
+ SMESH_Gen_i* aSMESHGen = new SMESH_Gen_i(orb, poa, contId, instanceName, interfaceName);
+ return aSMESHGen->getId() ;
}
}