#include <TCollection_AsciiString.hxx>
#include <OSD.hxx>
-#ifdef WNT
+#ifdef WIN32
#include <windows.h>
#include <process.h>
#else
#include <dlfcn.h>
#endif
-#ifdef WNT
+#ifdef WIN32
#define LibHandle HMODULE
#define LoadLib( name ) LoadLibrary( name )
#define GetProc GetProcAddress
#include <GEOM_Client.hxx>
#include <Basics_Utils.hxx>
+#include <Basics_DirUtils.hxx>
#include <HDFOI.hxx>
#include <OpUtil.hxx>
#include <SALOMEDS_Tool.hxx>
#include <SALOME_Container_i.hxx>
+#include <SALOME_DataContainer_i.hxx>
#include <SALOME_LifeCycleCORBA.hxx>
#include <SALOME_NamingService.hxx>
#include <Utils_CorbaException.hxx>
myIsHistoricalPythonDump = true;
myToForgetMeshDataOnHypModif = false;
+ myImportedStudyChanged = true;
+ myImportedStudyId = 0;
+
// set it in standalone mode only
//OSD::SetSignal( true );
CORBA::String_var str_host = session->getHostname();
CORBA::Long s_pid = session->getPID();
string my_host = Kernel_Utils::GetHostname();
-#ifdef WNT
+#ifdef WIN32
long my_pid = (long)_getpid();
#else
long my_pid = (long) getpid();
!strcmp( theLibName+libNameLen-3, ".so" ))
{
//the old format
-#ifdef WNT
+#ifdef WIN32
aPlatformLibName = std::string( theLibName+3, libNameLen-6 ) + ".dll";
#else
aPlatformLibName = theLibName;
else
{
//try to use new format
-#ifdef WNT
- aPlatformLibName = theLibName + ".dll";
+#ifdef WIN32
+ aPlatformLibName = theLibName;
+ aPlatformLibName += ".dll";
#else
aPlatformLibName = "lib" + std::string( theLibName ) + ".so";
#endif
if (!libHandle)
{
// report any error, if occured
-#ifndef WNT
+#ifndef WIN32
const char* anError = dlerror();
throw(SALOME_Exception(anError));
#else
std::string medfilename(theFileName);
medfilename += ".med";
std::string cmd;
-#ifdef WNT
+#ifdef WIN32
cmd = "%PYTHONBIN% ";
#else
cmd = "python ";
cmd += "\"";
system(cmd.c_str());
SMESH::mesh_array* result = CreateMeshesFromMEDorSAUV(medfilename.c_str(), theStatus, "CreateMeshesFromSAUV", sauvfilename.c_str());
-#ifdef WNT
+#ifdef WIN32
cmd = "%PYTHONBIN% ";
#else
cmd = "python ";
myLocShape = SMESH_Mesh::PseudoShape();
// call implementation compute
::SMESH_Mesh& myLocMesh = meshServant->GetImpl();
-#ifdef WITH_SMESH_CANCEL_COMPUTE
myGen.PrepareCompute( myLocMesh, myLocShape);
-#endif
bool ok = myGen.Compute( myLocMesh, myLocShape);
meshServant->CreateGroupServants(); // algos can create groups (issue 0020918)
myLocMesh.GetMeshDS()->Modified();
void SMESH_Gen_i::CancelCompute( SMESH::SMESH_Mesh_ptr theMesh,
GEOM::GEOM_Object_ptr theShapeObject )
{
-#ifdef WITH_SMESH_CANCEL_COMPUTE
SMESH_Mesh_i* meshServant = dynamic_cast<SMESH_Mesh_i*>( GetServant( theMesh ).in() );
::SMESH_Mesh& myLocMesh = meshServant->GetImpl();
TopoDS_Shape myLocShape;
else
myLocShape = SMESH_Mesh::PseudoShape();
myGen.CancelCompute( myLocMesh, myLocShape);
-#endif
}
//=============================================================================
//Remove the files if they exist: BugID: 11225
-#ifndef WNT /* unix functionality */
+#ifndef WIN32 /* unix functionality */
TCollection_AsciiString cmd("rm -f \"");
#else /* windows */
TCollection_AsciiString cmd("del /F \"");
string libname = string( myHyp->GetLibName() );
// BUG SWP13062
// Needs for save crossplatform libname, i.e. parth of name ( ".dll" for
- // WNT and ".so" for X-system) must be deleted
+ // WIN32 and ".so" for X-system) must be deleted
int libname_len = libname.length();
-#ifdef WNT
+#ifdef WIN32
if( libname_len > 4 )
libname.resize( libname_len - 4 );
#else
string libname = string( myHyp->GetLibName() );
// BUG SWP13062
// Needs for save crossplatform libname, i.e. parth of name ( ".dll" for
- // WNT and ".so" for X-system) must be deleted
+ // WIN32 and ".so" for X-system) must be deleted
int libname_len = libname.length();
-#ifdef WNT
+#ifdef WIN32
if( libname_len > 4 )
libname.resize( libname_len - 4 );
#else
// so for each node/element, we store a submesh ID
// Make maps of submesh IDs of elements sorted by element IDs
- typedef int TElemID;
- typedef int TSubMID;
- map< TElemID, TSubMID > eId2smId, nId2smId;
- map< TElemID, TSubMID >::iterator hint; // insertion to map is done before hint
+ // typedef int TElemID;
+ // typedef int TSubMID;
+ // map< TElemID, TSubMID > eId2smId, nId2smId;
const map<int,SMESHDS_SubMesh*>& aSubMeshes = mySMESHDSMesh->SubMeshes();
map<int,SMESHDS_SubMesh*>::const_iterator itSubM ( aSubMeshes.begin() );
- SMDS_NodeIteratorPtr itNode;
- SMDS_ElemIteratorPtr itElem;
- for ( itSubM = aSubMeshes.begin(); itSubM != aSubMeshes.end() ; itSubM++ )
- {
- TSubMID aSubMeID = itSubM->first;
- SMESHDS_SubMesh* aSubMesh = itSubM->second;
- if ( aSubMesh->IsComplexSubmesh() )
- continue; // submesh containing other submeshs
- // nodes
- hint = nId2smId.begin(); // optimize insertion basing on increasing order of elem Ids in submesh
- for ( itNode = aSubMesh->GetNodes(); itNode->more(); ++hint)
- hint = nId2smId.insert( hint, make_pair( itNode->next()->GetID(), aSubMeID ));
- // elements
- hint = eId2smId.begin();
- for ( itElem = aSubMesh->GetElements(); itElem->more(); ++hint)
- hint = eId2smId.insert( hint, make_pair( itElem->next()->GetID(), aSubMeID ));
- }
-
- // Care of elements that are not on submeshes
- if ( mySMESHDSMesh->NbNodes() != nId2smId.size() ) {
- for ( itNode = mySMESHDSMesh->nodesIterator(); itNode->more(); )
- /* --- stl_map.h says : */
- /* A %map relies on unique keys and thus a %pair is only inserted if its */
- /* first element (the key) is not already present in the %map. */
- nId2smId.insert( make_pair( itNode->next()->GetID(), 0 ));
- }
- int nbElems = mySMESHDSMesh->NbEdges() + mySMESHDSMesh->NbFaces() + mySMESHDSMesh->NbVolumes();
- if ( nbElems != eId2smId.size() ) {
- for ( itElem = mySMESHDSMesh->elementsIterator(); itElem->more(); )
- eId2smId.insert( make_pair( itElem->next()->GetID(), 0 ));
- }
+ // SMDS_NodeIteratorPtr itNode;
+ // SMDS_ElemIteratorPtr itElem;
+ // for ( itSubM = aSubMeshes.begin(); itSubM != aSubMeshes.end() ; itSubM++ )
+ // {
+ // TSubMID aSubMeID = itSubM->first;
+ // SMESHDS_SubMesh* aSubMesh = itSubM->second;
+ // if ( aSubMesh->IsComplexSubmesh() )
+ // continue; // sub-mesh containing other sub-meshes
+ // // nodes
+ // for ( itNode = aSubMesh->GetNodes(); itNode->more(); ++hint)
+ // nId2smId.insert( nId2smId.back(), make_pair( itNode->next()->GetID(), aSubMeID ));
+ // // elements
+ // for ( itElem = aSubMesh->GetElements(); itElem->more(); ++hint)
+ // hint = eId2smId.insert( eId2smId.back(), make_pair( itElem->next()->GetID(), aSubMeID ));
+ // }
+
+ // // Care of elements that are not on submeshes
+ // if ( mySMESHDSMesh->NbNodes() != nId2smId.size() ) {
+ // for ( itNode = mySMESHDSMesh->nodesIterator(); itNode->more(); )
+ // /* --- stl_map.h says : */
+ // /* A %map relies on unique keys and thus a %pair is only inserted if its */
+ // /* first element (the key) is not already present in the %map. */
+ // nId2smId.insert( make_pair( itNode->next()->GetID(), 0 ));
+ // }
+ // int nbElems = mySMESHDSMesh->GetMeshInfo().NbElements();
+ // if ( nbElems != eId2smId.size() ) {
+ // for ( itElem = mySMESHDSMesh->elementsIterator(); itElem->more(); )
+ // eId2smId.insert( make_pair( itElem->next()->GetID(), 0 ));
+ // }
// Store submesh IDs
for ( int isNode = 0; isNode < 2; ++isNode )
{
- map< TElemID, TSubMID >& id2smId = isNode ? nId2smId : eId2smId;
- if ( id2smId.empty() ) continue;
- map< TElemID, TSubMID >::const_iterator id_smId = id2smId.begin();
- // make and fill array of submesh IDs
- int* smIDs = new int [ id2smId.size() ];
- for ( int i = 0; id_smId != id2smId.end(); ++id_smId, ++i )
- smIDs[ i ] = id_smId->second;
+ // map< TElemID, TSubMID >& id2smId = isNode ? nId2smId : eId2smId;
+ // if ( id2smId.empty() ) continue;
+ // map< TElemID, TSubMID >::const_iterator id_smId = id2smId.begin();
+ // // make and fill array of submesh IDs
+ // int* smIDs = new int [ id2smId.size() ];
+ // for ( int i = 0; id_smId != id2smId.end(); ++id_smId, ++i )
+ // smIDs[ i ] = id_smId->second;
+ SMDS_ElemIteratorPtr eIt =
+ mySMESHDSMesh->elementsIterator( isNode ? SMDSAbs_Node : SMDSAbs_All );
+ int nbElems = isNode ? mySMESHDSMesh->NbNodes() : mySMESHDSMesh->GetMeshInfo().NbElements();
+ if ( nbElems < 1 )
+ continue;
+ std::vector<int> smIDs; smIDs.reserve( nbElems );
+ while ( eIt->more() )
+ if ( const SMDS_MeshElement* e = eIt->next())
+ smIDs.push_back( e->getshapeId() );
// write HDF group
- aSize[ 0 ] = id2smId.size();
+ aSize[ 0 ] = nbElems;
string aDSName( isNode ? "Node Submeshes" : "Element Submeshes");
aDataset = new HDFdataset( (char*)aDSName.c_str(), aGroup, HDF_INT32, aSize, 1 );
aDataset->CreateOnDisk();
- aDataset->WriteOnDisk( smIDs );
+ aDataset->WriteOnDisk( & smIDs[0] );
aDataset->CloseOnDisk();
- //
- delete[] smIDs;
}
aGroup->CloseOnDisk();
// creation of tree nodes for all data objects in the study
// to support tree representation customization and drag-n-drop:
- SALOMEDS::UseCaseBuilder_wrap useCaseBuilder = theComponent->GetStudy()->GetUseCaseBuilder();
+ SALOMEDS::Study_var study = theComponent->GetStudy();
+ SALOMEDS::UseCaseBuilder_wrap useCaseBuilder = study->GetUseCaseBuilder();
if ( !useCaseBuilder->IsUseCaseNode( theComponent ) ) {
useCaseBuilder->SetRootCurrent();
useCaseBuilder->Append( theComponent ); // component object is added as the top level item
- SALOMEDS::ChildIterator_wrap it = theComponent->GetStudy()->NewChildIterator( theComponent );
+ SALOMEDS::ChildIterator_wrap it = study->NewChildIterator( theComponent );
for (it->InitEx(true); it->More(); it->Next()) {
useCaseBuilder->AppendTo( it->Value()->GetFather(), it->Value() );
}
{
StudyContext* myStudyContext = GetCurrentStudyContext();
if ( myStudyContext && !CORBA::is_nil( theObject )) {
+ if (GetCurrentStudyID() == myImportedStudyId)
+ myImportedStudyChanged = true;
CORBA::String_var iorString = GetORB()->object_to_string( theObject );
return myStudyContext->addObject( string( iorString.in() ) );
}
}
}
+//=================================================================================
+// function : importData
+// purpose : imports mesh data file (the med one) into the SMESH internal data structure
+//=================================================================================
+Engines::ListOfIdentifiers* SMESH_Gen_i::importData(
+ CORBA::Long studyId, Engines::DataContainer_ptr data, const Engines::ListOfOptions& options)
+{
+ Engines::ListOfIdentifiers_var aResultIds = new Engines::ListOfIdentifiers;
+ list<string> aResultList;
+
+ CORBA::Object_var aSMObject = myNS->Resolve( "/myStudyManager" );
+ SALOMEDS::StudyManager_var aStudyManager = SALOMEDS::StudyManager::_narrow( aSMObject );
+ SALOMEDS::Study_var aStudy = aStudyManager->GetStudyByID( studyId );
+ SetCurrentStudy(aStudy);
+
+ // load and store temporary imported file
+ string aFileName = Kernel_Utils::GetTmpFileName();
+ aFileName += string(".") + data->extension();
+ Engines::TMPFile* aFileStream = data->get();
+ const char *aBuffer = (const char*)aFileStream->NP_data();
+#ifdef WIN32
+ std::ofstream aFile(aFileName.c_str(), std::ios::binary);
+#else
+ std::ofstream aFile(aFileName.c_str());
+#endif
+ aFile.write(aBuffer, aFileStream->length());
+ aFile.close();
+
+ // Retrieve mesh names from the file
+ DriverMED_R_SMESHDS_Mesh aReader;
+ aReader.SetFile( aFileName );
+ aReader.SetMeshId(-1);
+ Driver_Mesh::Status aStatus;
+ list<string> aNames = aReader.GetMeshNames(aStatus);
+ SMESH::mesh_array_var aResult = new SMESH::mesh_array();
+ SMESH::DriverMED_ReadStatus aStatus2 = (SMESH::DriverMED_ReadStatus)aStatus;
+ if (aStatus2 == SMESH::DRS_OK) {
+ // Iterate through all meshes and create mesh objects
+ for ( list<string>::iterator it = aNames.begin(); it != aNames.end(); it++ ) {
+ // create mesh
+ SMESH::SMESH_Mesh_var mesh = createMesh();
+
+ // publish mesh in the study
+ SALOMEDS::SObject_var aSO;
+ if (CanPublishInStudy(mesh)) {
+ aSO = PublishMesh(aStudy, mesh.in(), (*it).c_str());
+ aResultList.push_back(aSO->GetID());
+ }
+ // Read mesh data (groups are published automatically by ImportMEDFile())
+ SMESH_Mesh_i* meshServant = dynamic_cast<SMESH_Mesh_i*>( GetServant( mesh ).in() );
+ ASSERT( meshServant );
+ meshServant->ImportMEDFile( aFileName.c_str(), (*it).c_str() );
+ //meshServant->GetImpl().GetMeshDS()->Modified();
+ }
+ } else {
+ MESSAGE("Opening MED file problems "<<aFileName.c_str())
+ return aResultIds._retn();
+ }
+
+ // remove temporary file
+#ifdef WIN32
+ DeleteFileA(aFileName.c_str());
+#else
+ unlink(aFileName.c_str());
+#endif
+
+ if (!aResultList.empty()) {
+ aResultIds->length(aResultList.size());
+ list<string>::iterator aListIter = aResultList.begin();
+ for(int a = 0; aListIter != aResultList.end(); aListIter++, a++)
+ aResultIds[a] = aListIter->c_str();
+ }
+
+ myImportedStudyId = studyId;
+ myImportedStudyChanged = false;
+
+ return aResultIds._retn();
+}
+
+//=================================================================================
+// function : getModifiedData
+// purpose : exports all geometry of this GEOM module into one BRep file
+//=================================================================================
+Engines::ListOfData* SMESH_Gen_i::getModifiedData(CORBA::Long studyId)
+{
+ Engines::ListOfData_var aResult = new Engines::ListOfData;
+
+ if (!myImportedStudyChanged) {
+ INFOS("SMESH module data was not changed")
+ return aResult._retn();
+ }
+
+ CORBA::Object_var aSMObject = myNS->Resolve("/myStudyManager");
+ SALOMEDS::StudyManager_var aStudyManager = SALOMEDS::StudyManager::_narrow(aSMObject);
+ SALOMEDS::Study_var aStudy = aStudyManager->GetStudyByID(studyId);
+ SetCurrentStudy(aStudy);
+ SALOMEDS::SComponent_var aComponent = aStudy->FindComponent("SMESH");
+
+ if (CORBA::is_nil(aComponent))
+ return aResult._retn();
+
+ std::string aFullPath(Kernel_Utils::GetTmpFileName());
+ aFullPath += ".med";
+ StudyContext* myStudyContext = GetCurrentStudyContext();
+
+ SALOMEDS::ChildIterator_var anIter = aStudy->NewChildIterator(aComponent); // check only published meshes
+ int aNumMeshes = 0; // number of meshes in result
+ for(; anIter->More(); anIter->Next()) {
+ SALOMEDS::SObject_var aSO = anIter->Value();
+ CORBA::Object_var anObj = aSO->GetObject();
+ if (!CORBA::is_nil(anObj)) {
+ SMESH::SMESH_Mesh_var aCORBAMesh = SMESH::SMESH_Mesh::_narrow(anObj);
+ if(!aCORBAMesh->_is_nil()) {
+ SMESH_Mesh_i* myImpl = dynamic_cast<SMESH_Mesh_i*>(GetServant(aCORBAMesh).in());
+ if (myImpl) {
+ myImpl->Load();
+ SMESH_Mesh& aMesh = myImpl->GetImpl();
+ CORBA::String_var objName = aSO->GetName();
+ aMesh.ExportMED(aFullPath.c_str(), objName.in(), false, MED::eV2_2, 0);
+ aNumMeshes++;
+ }
+ }
+ }
+ }
+ if (aNumMeshes > 0) { // prepare a container to store files
+ INFOS("Write "<<aNumMeshes<<" meshes to "<<aFullPath.c_str());
+ aResult->length(1);
+ Engines::DataContainer_var aData = (new Engines_DataContainer_i(
+ aFullPath.c_str(), "", "", true))->_this();
+ aResult[0] = aData;
+ }
+ return aResult._retn();
+}
+
//=============================================================================
/*!
* SMESHEngine_factory