-// Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2010 CEA/DEN, EDF R&D, OPEN CASCADE
//
// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
//
// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
//
+
// SMESH SMESH_I : idl implementation based on 'SMESH' unit's calsses
// File : SMESH_Gen_i.cxx
// Author : Paul RASCLE, EDF
#ifdef WNT
#include <windows.h>
+ #include <process.h>
#else
#include <dlfcn.h>
#endif
#include "OpUtil.hxx"
#include CORBA_CLIENT_HEADER(SALOME_ModuleCatalog)
+#include CORBA_CLIENT_HEADER(SALOME_Session)
#include "GEOM_Client.hxx"
#include "Utils_ExceptHandlers.hxx"
+#include "Basics_Utils.hxx"
#include <map>
// set it in standalone mode only
//OSD::SetSignal( true );
+
+ // 0020605: EDF 1190 SMESH: Display performance. 80 seconds for 52000 cells.
+ // find out mode (embedded or standalone) here else
+ // meshes created before calling SMESH_Client::GetSMESHGen(), which calls
+ // SMESH_Gen_i::SetEmbeddedMode(), have wrong IsEmbeddedMode flag
+ if ( SALOME_NamingService* ns = GetNS() )
+ {
+ CORBA::Object_var obj = ns->Resolve( "/Kernel/Session" );
+ SALOME::Session_var session = SALOME::Session::_narrow( obj ) ;
+ if ( !session->_is_nil() )
+ {
+ CORBA::String_var s_host = session->getHostname();
+ CORBA::Long s_pid = session->getPID();
+ string my_host = Kernel_Utils::GetHostname();
+#ifdef WNT
+ long my_pid = (long)_getpid();
+#else
+ long my_pid = (long) getpid();
+#endif
+ SetEmbeddedMode( s_pid == my_pid && my_host == s_host.in() );
+ }
+ }
}
//=============================================================================
void SMESH_Gen_i::SetDefaultNbSegments(CORBA::Long theNbSegments)
throw ( SALOME::SALOME_Exception )
{
- if ( theNbSegments )
+ if ( theNbSegments > 0 )
myGen.SetDefaultNbSegments( int(theNbSegments) );
else
THROW_SALOME_CORBA_EXCEPTION( "non-positive number of segments", SALOME::BAD_PARAM );
MapShapeNbElemsItr anIt = aResMap.begin();
for(; anIt!=aResMap.end(); anIt++) {
const vector<int>& aVec = (*anIt).second;
- for(i = SMESH::Entity_Node; i < SMESH::Entity_Last; i++) {
- nbels[i] += aVec[i];
+ for(i = SMESH::Entity_Node; i < aVec.size(); i++) {
+ int nbElem = aVec[i];
+ if ( nbElem < 0 ) // algo failed, check that it has reported a message
+ {
+ SMESH_subMesh* sm = anIt->first;
+ SMESH_ComputeErrorPtr& error = sm->GetComputeError();
+ const SMESH_Algo* algo = myGen.GetAlgo( myLocMesh, sm->GetSubShape());
+ if ( algo && !error.get() || error->IsOK() )
+ error.reset( new SMESH_ComputeError( COMPERR_ALGO_FAILED,"Failed to evaluate",algo));
+ }
+ else
+ {
+ nbels[i] += aVec[i];
+ }
}
}
-#ifdef _DEBUG_
- cout<<endl;
-#endif
return nbels._retn();
}
}
typedef map< pair<string, SMESH::ElementType>, TListOfNewGroups > TGroupsMap;
typedef std::set<SMESHDS_GroupBase*> TGroups;
- TPythonDump aPythonDump; // prevent dump of called methods
+ TPythonDump* pPythonDump = new TPythonDump;
+ TPythonDump& aPythonDump = *pPythonDump; // prevent dump of called methods
// create mesh
SMESH::SMESH_Mesh_var aNewMesh = CreateEmptyMesh();
<< theMergeNodesAndElements << ", "
<< theMergeTolerance << ")";
+ delete pPythonDump; // enable python dump from GetGroups()
+
+ // 0020577: EDF 1164 SMESH: Bad dump of concatenate with create common groups
+ if ( !aNewMesh->_is_nil() )
+ {
+ SMESH::ListOfGroups_var groups = aNewMesh->GetGroups();
+ }
+
+ // IPAL21468 Change icon of compound because it need not be computed.
+ SALOMEDS::SObject_var aMeshSObj = ObjectToSObject( myCurrentStudy, aNewMesh );
+ if( !aMeshSObj->_is_nil() ) {
+ SALOMEDS::GenericAttribute_var anAttr;
+ SALOMEDS::StudyBuilder_var aBuilder = myCurrentStudy->NewBuilder();
+ anAttr = aBuilder->FindOrCreateAttribute( aMeshSObj,"AttributePixMap" );
+ SALOMEDS::AttributePixMap_var aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
+ aPixmap->SetPixMap("ICON_SMESH_TREE_MESH");
+ }
+
return aNewMesh._retn();
}
+//================================================================================
+/*!
+ * SMESH_Gen_i::GetMEDVersion
+ *
+ * Get MED version of the file by its name
+ */
+//================================================================================
+CORBA::Boolean SMESH_Gen_i::GetMEDVersion(const char* theFileName,
+ SMESH::MED_VERSION& theVersion)
+{
+ theVersion = SMESH::MED_V2_1;
+ MED::EVersion aVersion = MED::GetVersionId( theFileName );
+ switch( aVersion ) {
+ case MED::eV2_1 : theVersion = SMESH::MED_V2_1; return true;
+ case MED::eV2_2 : theVersion = SMESH::MED_V2_2; return true;
+ case MED::eVUnknown : return false;
+ }
+ return false;
+}
+
+//================================================================================
+/*!
+ * SMESH_Gen_i::GetMeshNames
+ *
+ * Get names of meshes defined in file with the specified name
+ */
+//================================================================================
+SMESH::string_array* SMESH_Gen_i::GetMeshNames(const char* theFileName)
+{
+ SMESH::string_array_var aResult = new SMESH::string_array();
+ MED::PWrapper aMed = MED::CrWrapper( theFileName );
+ MED::TErr anErr;
+ MED::TInt aNbMeshes = aMed->GetNbMeshes( &anErr );
+ if( anErr >= 0 ) {
+ aResult->length( aNbMeshes );
+ for( MED::TInt i = 0; i < aNbMeshes; i++ ) {
+ MED::PMeshInfo aMeshInfo = aMed->GetPMeshInfo( i+1 );
+ aResult[i] = CORBA::string_dup( aMeshInfo->GetName().c_str() );
+ }
+ }
+ return aResult._retn();
+}
+
//=============================================================================
/*!
* SMESH_Gen_i::Save
//if ( shapeRefFound )
//myWriter.AddAllSubMeshes();
+ // store submesh order if any
+ const TListOfListOfInt& theOrderIds = myLocMesh.GetMeshOrder();
+ if ( theOrderIds.size() ) {
+ char order_list[ 30 ];
+ strcpy( order_list, "Mesh Order" );
+ // count number of submesh ids
+ int nbIDs = 0;
+ TListOfListOfInt::const_iterator idIt = theOrderIds.begin();
+ for ( ; idIt != theOrderIds.end(); idIt++ )
+ nbIDs += (*idIt).size();
+ // number of values = number of IDs +
+ // number of lists (for separators) - 1
+ int* smIDs = new int [ nbIDs + theOrderIds.size() - 1 ];
+ idIt = theOrderIds.begin();
+ for ( int i = 0; idIt != theOrderIds.end(); idIt++ ) {
+ const TListOfInt& idList = *idIt;
+ if (idIt != theOrderIds.begin()) // not first list
+ smIDs[ i++ ] = -1/* *idList.size()*/; // separator between lists
+ // dump submesh ids from current list
+ TListOfInt::const_iterator id_smId = idList.begin();
+ for( ; id_smId != idList.end(); id_smId++ )
+ smIDs[ i++ ] = *id_smId;
+ }
+ // write HDF group
+ aSize[ 0 ] = nbIDs + theOrderIds.size() - 1;
+
+ aDataset = new HDFdataset( order_list, aTopGroup, HDF_INT32, aSize, 1 );
+ aDataset->CreateOnDisk();
+ aDataset->WriteOnDisk( smIDs );
+ aDataset->CloseOnDisk();
+ //
+ delete[] smIDs;
+ }
+
// groups root sub-branch
SALOMEDS::SObject_var myGroupsBranch;
for ( int i = GetNodeGroupsTag(); i <= GetVolumeGroupsTag(); i++ ) {
aDataset->WriteOnDisk( smIDs );
aDataset->CloseOnDisk();
//
- delete smIDs;
+ delete[] smIDs;
}
// Store node positions on sub-shapes (SMDS_Position):
}
}
}
-
}
}
}
aGroup->CloseOnDisk();
}
}
+ // read submeh order if any
+ if( aTopGroup->ExistInternalObject( "Mesh Order" ) ) {
+ aDataset = new HDFdataset( "Mesh Order", aTopGroup );
+ aDataset->OpenOnDisk();
+ size = aDataset->GetSize();
+ int* smIDs = new int[ size ];
+ aDataset->ReadFromDisk( smIDs );
+ aDataset->CloseOnDisk();
+ TListOfListOfInt anOrderIds;
+ anOrderIds.push_back( TListOfInt() );
+ for ( int i = 0; i < size; i++ )
+ if ( smIDs[ i ] < 0 ) // is separator
+ anOrderIds.push_back( TListOfInt() );
+ else
+ anOrderIds.back().push_back(smIDs[ i ]);
+
+ myNewMeshImpl->GetImpl().SetMeshOrder( anOrderIds );
+ }
}
// close mesh group
if(aTopGroup)
// context->myDocument = 0;
// }
+ myCurrentStudy = SALOMEDS::Study::_nil();
return;
}
}
}
+int SMESH_Gen_i::GetCurrentStudyID()
+{
+ return myCurrentStudy->_is_nil() || myCurrentStudy->_non_existent() ? -1 : myCurrentStudy->StudyId();
+}
+
//=============================================================================
/*!
* SMESHEngine_factory