+ throw(SALOME::SALOME_Exception)
+{
+ SMESH::log_array_var aLog;
+
+ SMESH_TRY;
+ if ( _preMeshInfo )
+ _preMeshInfo->FullLoadFromFile();
+
+ list < SMESHDS_Command * >logDS = _impl->GetLog();
+ aLog = new SMESH::log_array;
+ int indexLog = 0;
+ int lg = logDS.size();
+ SCRUTE(lg);
+ aLog->length(lg);
+ list < SMESHDS_Command * >::iterator its = logDS.begin();
+ while(its != logDS.end()){
+ SMESHDS_Command *com = *its;
+ int comType = com->GetType();
+ //SCRUTE(comType);
+ int lgcom = com->GetNumber();
+ //SCRUTE(lgcom);
+ const list < int >&intList = com->GetIndexes();
+ int inum = intList.size();
+ //SCRUTE(inum);
+ list < int >::const_iterator ii = intList.begin();
+ const list < double >&coordList = com->GetCoords();
+ int rnum = coordList.size();
+ //SCRUTE(rnum);
+ list < double >::const_iterator ir = coordList.begin();
+ aLog[indexLog].commandType = comType;
+ aLog[indexLog].number = lgcom;
+ aLog[indexLog].coords.length(rnum);
+ aLog[indexLog].indexes.length(inum);
+ for(int i = 0; i < rnum; i++){
+ aLog[indexLog].coords[i] = *ir;
+ //MESSAGE(" "<<i<<" "<<ir.Value());
+ ir++;
+ }
+ for(int i = 0; i < inum; i++){
+ aLog[indexLog].indexes[i] = *ii;
+ //MESSAGE(" "<<i<<" "<<ii.Value());
+ ii++;
+ }
+ indexLog++;
+ its++;
+ }
+ if(clearAfterGet)
+ _impl->ClearLog();
+
+ SMESH_CATCH( SMESH::throwCorbaException );
+
+ return aLog._retn();
+}
+
+
+//=============================================================================
+/*!
+ *
+ */
+//=============================================================================
+
+void SMESH_Mesh_i::ClearLog() throw(SALOME::SALOME_Exception)
+{
+ SMESH_TRY;
+ _impl->ClearLog();
+ SMESH_CATCH( SMESH::throwCorbaException );
+}
+
+//=============================================================================
+/*!
+ *
+ */
+//=============================================================================
+
+CORBA::Long SMESH_Mesh_i::GetId()throw(SALOME::SALOME_Exception)
+{
+ return _id;
+}
+
+//=============================================================================
+/*!
+ *
+ */
+//=============================================================================
+
+CORBA::Long SMESH_Mesh_i::GetStudyId()throw(SALOME::SALOME_Exception)
+{
+ return _studyId;
+}
+
+//=============================================================================
+namespace
+{
+ //!< implementation of struct used to call methods of SMESH_Mesh_i from SMESH_Mesh
+ // issue 0020918: groups removal is caused by hyp modification
+ // issue 0021208: to forget not loaded mesh data at hyp modification
+ struct TCallUp_i : public SMESH_Mesh::TCallUp
+ {
+ SMESH_Mesh_i* _mesh;
+ TCallUp_i(SMESH_Mesh_i* mesh):_mesh(mesh) {}
+ virtual void RemoveGroup (const int theGroupID) { _mesh->removeGroup( theGroupID ); }
+ virtual void HypothesisModified () { _mesh->onHypothesisModified(); }
+ virtual void Load () { _mesh->Load(); }
+ };
+}
+
+//================================================================================
+/*!
+ * \brief callback from _impl to forget not loaded mesh data (issue 0021208)
+ */
+//================================================================================
+
+void SMESH_Mesh_i::onHypothesisModified()
+{
+ if ( _preMeshInfo )
+ _preMeshInfo->ForgetOrLoad();
+}
+
+//=============================================================================
+/*!
+ *
+ */
+//=============================================================================
+
+void SMESH_Mesh_i::SetImpl(::SMESH_Mesh * impl)
+{
+ if(MYDEBUG) MESSAGE("SMESH_Mesh_i::SetImpl");
+ _impl = impl;
+ if ( _impl )
+ _impl->SetCallUp( new TCallUp_i(this));
+}
+
+//=============================================================================
+/*!
+ *
+ */
+//=============================================================================
+
+::SMESH_Mesh & SMESH_Mesh_i::GetImpl()
+{
+ if(MYDEBUG) MESSAGE("SMESH_Mesh_i::GetImpl()");
+ return *_impl;
+}
+
+//=============================================================================
+/*!
+ * Return mesh editor
+ */
+//=============================================================================
+
+SMESH::SMESH_MeshEditor_ptr SMESH_Mesh_i::GetMeshEditor()
+ throw (SALOME::SALOME_Exception)
+{
+ SMESH::SMESH_MeshEditor_var aMeshEdVar;
+
+ SMESH_TRY;
+ if ( _preMeshInfo )
+ _preMeshInfo->FullLoadFromFile();
+
+ // Create MeshEditor
+ if ( !_editor )
+ _editor = new SMESH_MeshEditor_i( this, false );
+ aMeshEdVar = _editor->_this();
+
+ // Update Python script
+ TPythonDump() << _editor << " = "
+ << SMESH::SMESH_Mesh_var(_this()) << ".GetMeshEditor()";
+
+ SMESH_CATCH( SMESH::throwCorbaException );
+
+ return aMeshEdVar._retn();
+}
+
+//=============================================================================
+/*!
+ * Return mesh edition previewer
+ */
+//=============================================================================
+
+SMESH::SMESH_MeshEditor_ptr SMESH_Mesh_i::GetMeshEditPreviewer()
+ throw (SALOME::SALOME_Exception)
+{
+ SMESH::SMESH_MeshEditor_var aMeshEdVar;
+
+ SMESH_TRY;
+ if ( _preMeshInfo )
+ _preMeshInfo->FullLoadFromFile();
+
+ if ( !_previewEditor )
+ _previewEditor = new SMESH_MeshEditor_i( this, true );
+ aMeshEdVar = _previewEditor->_this();
+
+ SMESH_CATCH( SMESH::throwCorbaException );
+
+ return aMeshEdVar._retn();
+}
+
+//================================================================================
+/*!
+ * \brief Return true if the mesh has been edited since a last total re-compute
+ * and those modifications may prevent successful partial re-compute
+ */
+//================================================================================
+
+CORBA::Boolean SMESH_Mesh_i::HasModificationsToDiscard() throw(SALOME::SALOME_Exception)
+{
+ Unexpect aCatch(SALOME_SalomeException);
+ return _impl->HasModificationsToDiscard();
+}
+
+//================================================================================
+/*!
+ * \brief Returns a random unique color
+ */
+//================================================================================
+
+static SALOMEDS::Color getUniqueColor( const std::list<SALOMEDS::Color>& theReservedColors )
+{
+ const int MAX_ATTEMPTS = 100;
+ int cnt = 0;
+ double tolerance = 0.5;
+ SALOMEDS::Color col;
+
+ bool ok = false;
+ while ( !ok ) {
+ // generate random color
+ double red = (double)rand() / RAND_MAX;
+ double green = (double)rand() / RAND_MAX;
+ double blue = (double)rand() / RAND_MAX;
+ // check existence in the list of the existing colors
+ bool matched = false;
+ std::list<SALOMEDS::Color>::const_iterator it;
+ for ( it = theReservedColors.begin(); it != theReservedColors.end() && !matched; ++it ) {
+ SALOMEDS::Color color = *it;
+ double tol = fabs( color.R - red ) + fabs( color.G - green ) + fabs( color.B - blue );
+ matched = tol < tolerance;
+ }
+ if ( (cnt+1) % 20 == 0 ) tolerance = tolerance/2;
+ ok = ( ++cnt == MAX_ATTEMPTS ) || !matched;
+ col.R = red;
+ col.G = green;
+ col.B = blue;
+ }
+ return col;
+}
+
+//=============================================================================
+/*!
+ * Sets auto-color mode. If it is on, groups get unique random colors
+ */
+//=============================================================================
+
+void SMESH_Mesh_i::SetAutoColor(CORBA::Boolean theAutoColor) throw(SALOME::SALOME_Exception)
+{
+ Unexpect aCatch(SALOME_SalomeException);
+ _impl->SetAutoColor(theAutoColor);
+
+ TPythonDump pyDump; // not to dump group->SetColor() from below code
+ pyDump << SMESH::SMESH_Mesh_var(_this()) <<".SetAutoColor( "<<theAutoColor<<" )";
+
+ std::list<SALOMEDS::Color> aReservedColors;
+ map<int, SMESH::SMESH_GroupBase_ptr>::iterator it = _mapGroups.begin();
+ for ( ; it != _mapGroups.end(); it++ ) {
+ if ( CORBA::is_nil( it->second )) continue;
+ SALOMEDS::Color aColor = getUniqueColor( aReservedColors );
+ it->second->SetColor( aColor );
+ aReservedColors.push_back( aColor );
+ }
+}
+
+//=============================================================================
+/*!
+ * Returns true if auto-color mode is on
+ */
+//=============================================================================
+
+CORBA::Boolean SMESH_Mesh_i::GetAutoColor() throw(SALOME::SALOME_Exception)
+{
+ Unexpect aCatch(SALOME_SalomeException);
+ return _impl->GetAutoColor();
+}
+
+//=============================================================================
+/*!
+ * Checks if there are groups with equal names
+ */
+//=============================================================================
+
+CORBA::Boolean SMESH_Mesh_i::HasDuplicatedGroupNamesMED()
+{
+ return _impl->HasDuplicatedGroupNamesMED();
+}
+
+//================================================================================
+/*!
+ * \brief Care of a file before exporting mesh into it
+ */
+//================================================================================
+
+void SMESH_Mesh_i::PrepareForWriting (const char* file, bool overwrite)
+{
+ SMESH_File aFile( file );
+ SMESH_Comment msg;
+ if (aFile.exists()) {
+ // existing filesystem node
+ if ( !aFile.isDirectory() ) {
+ if ( aFile.openForWriting() ) {
+ if ( overwrite && ! aFile.remove()) {
+ msg << "Can't replace " << aFile.getName();
+ }
+ } else {
+ msg << "Can't write into " << aFile.getName();
+ }
+ } else {
+ msg << "Location " << aFile.getName() << " is not a file";
+ }
+ }
+ else {
+ // nonexisting file; check if it can be created
+ if ( !aFile.openForWriting() ) {
+ msg << "You cannot create the file "
+ << aFile.getName()
+ << ". Check the directory existance and access rights";
+ }
+ aFile.remove();
+ }
+
+ if ( !msg.empty() )
+ {
+ msg << ".";
+ THROW_SALOME_CORBA_EXCEPTION(msg.c_str(), SALOME::BAD_PARAM);
+ }
+}
+
+//================================================================================
+/*!
+ * \brief Prepares a file for export and pass names of mesh groups from study to mesh DS
+ * \param file - file name
+ * \param overwrite - to erase the file or not
+ * \retval string - mesh name
+ */
+//================================================================================
+
+string SMESH_Mesh_i::prepareMeshNameAndGroups(const char* file,
+ CORBA::Boolean overwrite)
+{
+ // Perform Export
+ PrepareForWriting(file, overwrite);
+ string aMeshName = "Mesh";
+ SALOMEDS::Study_var aStudy = _gen_i->GetCurrentStudy();
+ if ( !aStudy->_is_nil() ) {
+ SALOMEDS::SObject_wrap aMeshSO = _gen_i->ObjectToSObject( aStudy, _this() );
+ if ( !aMeshSO->_is_nil() ) {
+ CORBA::String_var name = aMeshSO->GetName();
+ aMeshName = name;
+ // asv : 27.10.04 : fix of 6903: check for StudyLocked before adding attributes
+ if ( !aStudy->GetProperties()->IsLocked() )
+ {
+ SALOMEDS::GenericAttribute_wrap anAttr;
+ SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
+ anAttr=aStudyBuilder->FindOrCreateAttribute(aMeshSO, "AttributeExternalFileDef");
+ SALOMEDS::AttributeExternalFileDef_wrap aFileName = anAttr;
+ ASSERT(!aFileName->_is_nil());
+ aFileName->SetValue(file);
+ anAttr=aStudyBuilder->FindOrCreateAttribute(aMeshSO, "AttributeFileType");
+ SALOMEDS::AttributeFileType_wrap aFileType = anAttr;
+ ASSERT(!aFileType->_is_nil());
+ aFileType->SetValue("FICHIERMED");
+ }
+ }
+ }
+ // Update Python script
+ // set name of mesh before export
+ TPythonDump() << _gen_i << ".SetName("
+ << SMESH::SMESH_Mesh_var(_this()) << ", '" << aMeshName.c_str() << "')";
+
+ // check names of groups
+ checkGroupNames();
+
+ return aMeshName;
+}
+
+//================================================================================
+/*!
+ * \brief Export to med file
+ */
+//================================================================================
+
+void SMESH_Mesh_i::ExportToMEDX (const char* file,
+ CORBA::Boolean auto_groups,
+ SMESH::MED_VERSION theVersion,
+ CORBA::Boolean overwrite,
+ CORBA::Boolean autoDimension)
+ throw(SALOME::SALOME_Exception)
+{
+ SMESH_TRY;
+ if ( _preMeshInfo )
+ _preMeshInfo->FullLoadFromFile();
+
+ string aMeshName = prepareMeshNameAndGroups(file, overwrite);
+ _impl->ExportMED( file, aMeshName.c_str(), auto_groups, theVersion, 0, autoDimension );
+
+ TPythonDump() << SMESH::SMESH_Mesh_var(_this()) << ".ExportToMEDX( r'"
+ << file << "', " << auto_groups << ", "
+ << theVersion << ", " << overwrite << ", "
+ << autoDimension << " )";
+
+ SMESH_CATCH( SMESH::throwCorbaException );
+}
+
+//================================================================================
+/*!
+ * \brief Export a mesh to a med file
+ */
+//================================================================================
+
+void SMESH_Mesh_i::ExportToMED (const char* file,
+ CORBA::Boolean auto_groups,
+ SMESH::MED_VERSION theVersion)
+ throw(SALOME::SALOME_Exception)
+{
+ ExportToMEDX(file,auto_groups,theVersion,true);
+}
+
+//================================================================================
+/*!
+ * \brief Export a mesh to a med file
+ */
+//================================================================================
+
+void SMESH_Mesh_i::ExportMED (const char* file,
+ CORBA::Boolean auto_groups)
+ throw(SALOME::SALOME_Exception)
+{
+ ExportToMEDX(file,auto_groups,SMESH::MED_V2_2,true);
+}
+
+//================================================================================
+/*!
+ * \brief Export a mesh to a SAUV file
+ */
+//================================================================================
+
+void SMESH_Mesh_i::ExportSAUV (const char* file,
+ CORBA::Boolean auto_groups)
+ throw(SALOME::SALOME_Exception)
+{
+ Unexpect aCatch(SALOME_SalomeException);
+ if ( _preMeshInfo )
+ _preMeshInfo->FullLoadFromFile();
+
+ string aMeshName = prepareMeshNameAndGroups(file, true);
+ TPythonDump() << SMESH::SMESH_Mesh_var( _this())
+ << ".ExportSAUV( r'" << file << "', " << auto_groups << " )";
+ _impl->ExportSAUV(file, aMeshName.c_str(), auto_groups);
+}
+
+
+//================================================================================
+/*!
+ * \brief Export a mesh to a DAT file
+ */
+//================================================================================
+
+void SMESH_Mesh_i::ExportDAT (const char *file)
+ throw(SALOME::SALOME_Exception)
+{
+ Unexpect aCatch(SALOME_SalomeException);
+ if ( _preMeshInfo )
+ _preMeshInfo->FullLoadFromFile();
+
+ // Update Python script
+ // check names of groups
+ checkGroupNames();
+ TPythonDump() << SMESH::SMESH_Mesh_var(_this()) << ".ExportDAT( r'" << file << "' )";
+
+ // Perform Export
+ PrepareForWriting(file);
+ _impl->ExportDAT(file);
+}
+
+//================================================================================
+/*!
+ * \brief Export a mesh to an UNV file
+ */
+//================================================================================
+
+void SMESH_Mesh_i::ExportUNV (const char *file)
+ throw(SALOME::SALOME_Exception)
+{
+ Unexpect aCatch(SALOME_SalomeException);
+ if ( _preMeshInfo )
+ _preMeshInfo->FullLoadFromFile();
+
+ // Update Python script
+ // check names of groups
+ checkGroupNames();
+ TPythonDump() << SMESH::SMESH_Mesh_var(_this()) << ".ExportUNV( r'" << file << "' )";
+
+ // Perform Export
+ PrepareForWriting(file);
+ _impl->ExportUNV(file);
+}
+
+//================================================================================
+/*!
+ * \brief Export a mesh to an STL file
+ */
+//================================================================================
+
+void SMESH_Mesh_i::ExportSTL (const char *file, const bool isascii)
+ throw(SALOME::SALOME_Exception)
+{
+ Unexpect aCatch(SALOME_SalomeException);
+ if ( _preMeshInfo )
+ _preMeshInfo->FullLoadFromFile();
+
+ // Update Python script
+ // check names of groups
+ checkGroupNames();
+ TPythonDump() << SMESH::SMESH_Mesh_var(_this())
+ << ".ExportSTL( r'" << file << "', " << isascii << " )";
+
+ // Perform Export
+ PrepareForWriting(file);
+ _impl->ExportSTL(file, isascii);
+}
+
+//================================================================================
+/*!
+ * \brief Export a part of mesh to a med file
+ */
+//================================================================================
+
+void SMESH_Mesh_i::ExportPartToMED(SMESH::SMESH_IDSource_ptr meshPart,
+ const char* file,
+ CORBA::Boolean auto_groups,
+ SMESH::MED_VERSION version,
+ CORBA::Boolean overwrite,
+ CORBA::Boolean autoDimension,
+ const GEOM::ListOfFields& fields,
+ const char* geomAssocFields)
+ throw (SALOME::SALOME_Exception)
+{
+ SMESH_TRY;
+ if ( _preMeshInfo )
+ _preMeshInfo->FullLoadFromFile();
+
+ // check fields
+ bool have0dField = false;
+ if ( fields.length() > 0 )
+ {
+ GEOM::GEOM_Object_var shapeToMesh = GetShapeToMesh();
+ if ( shapeToMesh->_is_nil() )
+ THROW_SALOME_CORBA_EXCEPTION( "No shape to mesh", SALOME::INTERNAL_ERROR );
+
+ for ( size_t i = 0; i < fields.length(); ++i )
+ {
+ if ( fields[i]->GetDataType() == GEOM::FDT_String )
+ THROW_SALOME_CORBA_EXCEPTION
+ ( "Export of string fields is not supported", SALOME::BAD_PARAM);
+ GEOM::GEOM_Object_var fieldShape = fields[i]->GetShape();
+ if ( fieldShape->_is_nil() )
+ THROW_SALOME_CORBA_EXCEPTION( "Null shape under a field", SALOME::INTERNAL_ERROR );
+ if ( !fieldShape->IsSame( shapeToMesh ) )
+ THROW_SALOME_CORBA_EXCEPTION
+ ( "Field defined not on shape", SALOME::BAD_PARAM);
+ if ( fields[i]->GetDimension() == 0 )
+ have0dField = true;
+ }
+ if ( geomAssocFields )
+ for ( int i = 0; geomAssocFields[i]; ++i )
+ switch ( geomAssocFields[i] ) {
+ case 'v':case 'e':case 'f':case 's': break;
+ case 'V':case 'E':case 'F':case 'S': break;
+ default: THROW_SALOME_CORBA_EXCEPTION
+ ( "geomAssocFields can include only [vefs] characters", SALOME::BAD_PARAM);
+ }
+ }
+
+ SMESHDS_Mesh* meshDS = _impl->GetMeshDS();
+
+ // write mesh
+
+ string aMeshName = "Mesh";
+ SMESHUtils::Deleter< SMESH_MeshPartDS > tmpDSDeleter(0);
+ if ( CORBA::is_nil( meshPart ) ||
+ SMESH::DownCast< SMESH_Mesh_i* >( meshPart ))
+ {
+ aMeshName = prepareMeshNameAndGroups(file, overwrite);
+ _impl->ExportMED( file, aMeshName.c_str(), auto_groups,
+ version, 0, autoDimension, /*addODOnVertices=*/have0dField);
+ meshDS = _impl->GetMeshDS();
+ }
+ else
+ {
+ if ( _preMeshInfo )
+ _preMeshInfo->FullLoadFromFile();
+
+ PrepareForWriting(file, overwrite);
+
+ SALOMEDS::Study_var aStudy = _gen_i->GetCurrentStudy();
+ if ( !aStudy->_is_nil() ) {
+ SALOMEDS::SObject_wrap SO = _gen_i->ObjectToSObject( aStudy, meshPart );
+ if ( !SO->_is_nil() ) {
+ CORBA::String_var name = SO->GetName();
+ aMeshName = name;
+ }
+ }
+ SMESH_MeshPartDS* partDS = new SMESH_MeshPartDS( meshPart );
+ _impl->ExportMED( file, aMeshName.c_str(), auto_groups,
+ version, partDS, autoDimension, /*addODOnVertices=*/have0dField);
+ meshDS = tmpDSDeleter._obj = partDS;
+ }
+
+ // write fields
+
+ if ( _impl->HasShapeToMesh() )
+ {
+ DriverMED_W_Field fieldWriter;
+ fieldWriter.SetFile( file );
+ fieldWriter.SetMeshName( aMeshName );
+ fieldWriter.AddODOnVertices( have0dField );
+
+ exportMEDFields( fieldWriter, meshDS, fields, geomAssocFields );
+ }
+
+ // dump
+ GEOM::ListOfGBO_var goList = new GEOM::ListOfGBO;
+ goList->length( fields.length() );
+ for ( size_t i = 0; i < fields.length(); ++i )
+ {
+ GEOM::GEOM_BaseObject_var gbo = GEOM::GEOM_BaseObject::_narrow( fields[i] );
+ goList[i] = gbo;
+ }
+ TPythonDump() << _this() << ".ExportPartToMED( "
+ << meshPart << ", r'" << file << "', "
+ << auto_groups << ", " << version << ", " << overwrite << ", "
+ << autoDimension << ", " << goList
+ << ", '" << ( geomAssocFields ? geomAssocFields : "" ) << "'" << " )";
+
+ SMESH_CATCH( SMESH::throwCorbaException );
+}
+
+//================================================================================
+/*!
+ * Write GEOM fields to MED file
+ */
+//================================================================================
+
+void SMESH_Mesh_i::exportMEDFields( DriverMED_W_Field& fieldWriter,
+ SMESHDS_Mesh* meshDS,
+ const GEOM::ListOfFields& fields,
+ const char* geomAssocFields)
+{
+#define METH "SMESH_Mesh_i::exportMEDFields() "
+
+ if (( fields.length() < 1 ) &&
+ ( !geomAssocFields || !geomAssocFields[0] ))
+ return;
+
+ std::vector< double > dblVals( meshDS->MaxShapeIndex()+1 );
+ std::vector< int > intVals( meshDS->MaxShapeIndex()+1 );
+ std::vector< int > subIdsByDim[ 4 ];
+ const double noneDblValue = 0.;
+ const double noneIntValue = 0;
+
+ for ( size_t iF = 0; iF < fields.length(); ++iF )
+ {
+ // set field data
+
+ int dim = fields[ iF ]->GetDimension();
+ SMDSAbs_ElementType elemType;
+ TopAbs_ShapeEnum shapeType;
+ switch ( dim ) {
+ case 0: elemType = SMDSAbs_0DElement; shapeType = TopAbs_VERTEX; break;
+ case 1: elemType = SMDSAbs_Edge; shapeType = TopAbs_EDGE; break;
+ case 2: elemType = SMDSAbs_Face; shapeType = TopAbs_FACE; break;
+ case 3: elemType = SMDSAbs_Volume; shapeType = TopAbs_SOLID; break;
+ default:
+ continue; // skip fields on whole shape
+ }
+ GEOM::field_data_type dataType = fields[ iF ]->GetDataType();
+ if ( dataType == GEOM::FDT_String )
+ continue;
+ GEOM::ListOfLong_var stepIDs = fields[ iF ]->GetSteps();
+ if ( stepIDs->length() < 1 )
+ continue;
+ GEOM::string_array_var comps = fields[ iF ]->GetComponents();
+ if ( comps->length() < 1 )
+ continue;
+ CORBA::String_var name = fields[ iF ]->GetName();
+
+ if ( !fieldWriter.Set( meshDS,
+ name.in(),
+ elemType,
+ comps->length(),
+ /*isIntData=*/false ))//( dataType == GEOM::FDT_Int )))
+ continue;
+
+ for ( size_t iC = 0; iC < comps->length(); ++iC )
+ fieldWriter.SetCompName( iC, comps[ iC ].in() );
+
+ // find sub-shape IDs
+
+ std::vector< int >& subIds = subIdsByDim[ dim ];
+ if ( subIds.empty() )
+ for ( int id = 1; id <= meshDS->MaxShapeIndex(); ++id )
+ if ( meshDS->IndexToShape( id ).ShapeType() == shapeType )
+ subIds.push_back( id );
+
+ // write steps
+
+ SMDS_ElemIteratorPtr elemIt = fieldWriter.GetOrderedElems();
+ if ( !elemIt )
+ continue;
+
+ for ( size_t iS = 0; iS < stepIDs->length(); ++iS )
+ {
+ GEOM::GEOM_FieldStep_var step = fields[ iF ]->GetStep( stepIDs[ iS ]);
+ if ( step->_is_nil() )
+ continue;
+
+ CORBA::Long stamp = step->GetStamp();
+ CORBA::Long id = step->GetID();
+ fieldWriter.SetDtIt( int( stamp ), int( id ));
+
+ // fill dblVals or intVals
+ switch ( dataType )
+ {
+ case GEOM::FDT_Double:
+ {
+ GEOM::GEOM_DoubleFieldStep_var dblStep = GEOM::GEOM_DoubleFieldStep::_narrow( step );
+ if ( dblStep->_is_nil() ) continue;
+ GEOM::ListOfDouble_var vv = dblStep->GetValues();
+ if ( vv->length() != subIds.size() )
+ THROW_SALOME_CORBA_EXCEPTION( METH "BUG: wrong nb subIds", SALOME::INTERNAL_ERROR );
+ for ( size_t i = 0; i < vv->length(); ++i )
+ dblVals[ subIds[ i ]] = vv[ i ];
+ break;
+ }
+ case GEOM::FDT_Int:
+ {
+ GEOM::GEOM_IntFieldStep_var intStep = GEOM::GEOM_IntFieldStep::_narrow( step );
+ if ( intStep->_is_nil() ) continue;
+ GEOM::ListOfLong_var vv = intStep->GetValues();
+ if ( vv->length() != subIds.size() )
+ THROW_SALOME_CORBA_EXCEPTION( METH "BUG: wrong nb subIds", SALOME::INTERNAL_ERROR );
+ for ( size_t i = 0; i < vv->length(); ++i )
+ intVals[ subIds[ i ]] = (int) vv[ i ];
+ break;
+ }
+ case GEOM::FDT_Bool:
+ {
+ GEOM::GEOM_BoolFieldStep_var boolStep = GEOM::GEOM_BoolFieldStep::_narrow( step );
+ if ( boolStep->_is_nil() ) continue;
+ GEOM::short_array_var vv = boolStep->GetValues();
+ if ( vv->length() != subIds.size() )
+ THROW_SALOME_CORBA_EXCEPTION( METH "BUG: wrong nb subIds", SALOME::INTERNAL_ERROR );
+ for ( size_t i = 0; i < vv->length(); ++i )
+ intVals[ subIds[ i ]] = (int) vv[ i ];
+ break;
+ }
+ default: continue;
+ }
+
+ // pass values to fieldWriter
+ elemIt = fieldWriter.GetOrderedElems();
+ if ( dataType == GEOM::FDT_Double )
+ while ( elemIt->more() )
+ {
+ const SMDS_MeshElement* e = elemIt->next();
+ const int shapeID = e->getshapeId();
+ if ( shapeID < 1 || shapeID >= (int) dblVals.size() )
+ fieldWriter.AddValue( noneDblValue );
+ else
+ fieldWriter.AddValue( dblVals[ shapeID ]);
+ }
+ else
+ while ( elemIt->more() )
+ {
+ const SMDS_MeshElement* e = elemIt->next();
+ const int shapeID = e->getshapeId();
+ if ( shapeID < 1 || shapeID >= (int) intVals.size() )
+ fieldWriter.AddValue( (double) noneIntValue );
+ else
+ fieldWriter.AddValue( (double) intVals[ shapeID ]);
+ }
+
+ // write a step
+ fieldWriter.Perform();
+ SMESH_ComputeErrorPtr res = fieldWriter.GetError();
+ if ( res && res->IsKO() )
+ {
+ if ( res->myComment.empty() )
+ { THROW_SALOME_CORBA_EXCEPTION( METH "Fatal error", SALOME::INTERNAL_ERROR ); }
+ else
+ { THROW_SALOME_CORBA_EXCEPTION( res->myComment.c_str(), SALOME::INTERNAL_ERROR ); }
+ }
+
+ } // loop on steps
+ } // loop on fields
+
+ if ( !geomAssocFields || !geomAssocFields[0] )
+ return;
+
+ // write geomAssocFields
+
+ std::vector< int > shapeDim( TopAbs_SHAPE + 1 );
+ shapeDim[ TopAbs_COMPOUND ] = 3;
+ shapeDim[ TopAbs_COMPSOLID ] = 3;
+ shapeDim[ TopAbs_SOLID ] = 3;
+ shapeDim[ TopAbs_SHELL ] = 2;
+ shapeDim[ TopAbs_FACE ] = 2;
+ shapeDim[ TopAbs_WIRE ] = 1;
+ shapeDim[ TopAbs_EDGE ] = 1;
+ shapeDim[ TopAbs_VERTEX ] = 0;
+ shapeDim[ TopAbs_SHAPE ] = 3;
+
+ for ( int iF = 0; geomAssocFields[ iF ]; ++iF )
+ {
+ std::vector< std::string > compNames;
+ switch ( geomAssocFields[ iF ]) {
+ case 'v': case 'V':
+ fieldWriter.Set( meshDS, "_vertices_", SMDSAbs_Node, /*nbComps=*/2, /*isInt=*/false );
+ compNames.push_back( "dim" );
+ break;
+ case 'e': case 'E':
+ fieldWriter.Set( meshDS, "_edges_", SMDSAbs_Edge, /*nbComps=*/1, /*isInt=*/false );
+ break;
+ case 'f': case 'F':
+ fieldWriter.Set( meshDS, "_faces_", SMDSAbs_Face, /*nbComps=*/1, /*isInt=*/false );
+ break;
+ case 's': case 'S':
+ fieldWriter.Set( meshDS, "_solids_", SMDSAbs_Volume, /*nbComps=*/1, /*isInt=*/false );
+ break;
+ default: continue;
+ }
+ compNames.push_back( "id" );
+ for ( size_t iC = 0; iC < compNames.size(); ++iC )
+ fieldWriter.SetCompName( iC, compNames[ iC ].c_str() );
+
+ fieldWriter.SetDtIt( -1, -1 );
+
+ SMDS_ElemIteratorPtr elemIt = fieldWriter.GetOrderedElems();
+ if ( !elemIt )
+ continue;
+
+ if ( compNames.size() == 2 ) // _vertices_
+ while ( elemIt->more() )
+ {
+ const SMDS_MeshElement* e = elemIt->next();
+ const int shapeID = e->getshapeId();
+ if ( shapeID < 1 )
+ {
+ fieldWriter.AddValue( (double) -1 );
+ fieldWriter.AddValue( (double) -1 );
+ }
+ else
+ {
+ const TopoDS_Shape& S = meshDS->IndexToShape( shapeID );
+ fieldWriter.AddValue( (double) ( S.IsNull() ? -1 : shapeDim[ S.ShapeType() ]));
+ fieldWriter.AddValue( (double) shapeID );
+ }
+ }
+ else
+ while ( elemIt->more() )
+ {
+ const SMDS_MeshElement* e = elemIt->next();
+ const int shapeID = e->getshapeId();
+ if ( shapeID < 1 )
+ fieldWriter.AddValue( (double) -1 );
+ else
+ fieldWriter.AddValue( (double) shapeID );
+ }
+
+ // write a step
+ fieldWriter.Perform();
+ SMESH_ComputeErrorPtr res = fieldWriter.GetError();
+ if ( res && res->IsKO() )
+ {
+ if ( res->myComment.empty() )
+ { THROW_SALOME_CORBA_EXCEPTION( METH "Fatal error", SALOME::INTERNAL_ERROR ); }
+ else
+ { THROW_SALOME_CORBA_EXCEPTION( res->myComment.c_str(), SALOME::INTERNAL_ERROR ); }
+ }
+
+ } // loop on geomAssocFields
+
+#undef METH
+}
+
+//================================================================================
+/*!
+ * \brief Export a part of mesh to a DAT file
+ */
+//================================================================================
+
+void SMESH_Mesh_i::ExportPartToDAT(::SMESH::SMESH_IDSource_ptr meshPart,
+ const char* file)
+ throw (SALOME::SALOME_Exception)
+{
+ Unexpect aCatch(SALOME_SalomeException);
+ if ( _preMeshInfo )
+ _preMeshInfo->FullLoadFromFile();
+
+ PrepareForWriting(file);
+
+ SMESH_MeshPartDS partDS( meshPart );
+ _impl->ExportDAT(file,&partDS);
+
+ TPythonDump() << SMESH::SMESH_Mesh_var(_this())
+ << ".ExportPartToDAT( " << meshPart << ", r'" << file << "' )";
+}
+//================================================================================
+/*!
+ * \brief Export a part of mesh to an UNV file
+ */
+//================================================================================
+
+void SMESH_Mesh_i::ExportPartToUNV(::SMESH::SMESH_IDSource_ptr meshPart,
+ const char* file)
+ throw (SALOME::SALOME_Exception)
+{
+ Unexpect aCatch(SALOME_SalomeException);
+ if ( _preMeshInfo )
+ _preMeshInfo->FullLoadFromFile();
+
+ PrepareForWriting(file);
+
+ SMESH_MeshPartDS partDS( meshPart );
+ _impl->ExportUNV(file, &partDS);
+
+ TPythonDump() << SMESH::SMESH_Mesh_var(_this())
+ << ".ExportPartToUNV( " << meshPart<< ", r'" << file << "' )";
+}
+//================================================================================
+/*!
+ * \brief Export a part of mesh to an STL file
+ */
+//================================================================================
+
+void SMESH_Mesh_i::ExportPartToSTL(::SMESH::SMESH_IDSource_ptr meshPart,
+ const char* file,
+ ::CORBA::Boolean isascii)
+ throw (SALOME::SALOME_Exception)
+{
+ Unexpect aCatch(SALOME_SalomeException);
+ if ( _preMeshInfo )
+ _preMeshInfo->FullLoadFromFile();
+
+ PrepareForWriting(file);
+
+ SMESH_MeshPartDS partDS( meshPart );
+ _impl->ExportSTL(file, isascii, &partDS);
+
+ TPythonDump() << SMESH::SMESH_Mesh_var(_this()) << ".ExportPartToSTL( "
+ << meshPart<< ", r'" << file << "', " << isascii << ")";
+}
+
+//================================================================================
+/*!
+ * \brief Export a part of mesh to an STL file
+ */
+//================================================================================
+
+void SMESH_Mesh_i::ExportCGNS(::SMESH::SMESH_IDSource_ptr meshPart,
+ const char* file,
+ CORBA::Boolean overwrite)
+ throw (SALOME::SALOME_Exception)
+{
+#ifdef WITH_CGNS
+ Unexpect aCatch(SALOME_SalomeException);
+ if ( _preMeshInfo )
+ _preMeshInfo->FullLoadFromFile();
+
+ PrepareForWriting(file,overwrite);
+
+ std::string meshName("");
+ SALOMEDS::Study_var study = _gen_i->GetCurrentStudy();
+ SALOMEDS::SObject_wrap so = _gen_i->ObjectToSObject( study, meshPart );
+ if ( !so->_is_nil() )
+ {
+ CORBA::String_var name = so->GetName();
+ meshName = name.in();
+ }
+ SMESH_MeshPartDS partDS( meshPart );
+ _impl->ExportCGNS(file, &partDS, meshName.c_str() );
+
+ TPythonDump() << SMESH::SMESH_Mesh_var(_this()) << ".ExportCGNS( "
+ << meshPart<< ", r'" << file << "', " << overwrite << ")";
+#else
+ THROW_SALOME_CORBA_EXCEPTION("CGNS library is unavailable", SALOME::INTERNAL_ERROR);
+#endif
+}
+
+//================================================================================
+/*!
+ * \brief Export a part of mesh to a GMF file
+ */
+//================================================================================
+
+void SMESH_Mesh_i::ExportGMF(::SMESH::SMESH_IDSource_ptr meshPart,
+ const char* file,
+ bool withRequiredGroups)
+ throw (SALOME::SALOME_Exception)
+{
+ Unexpect aCatch(SALOME_SalomeException);
+ if ( _preMeshInfo )
+ _preMeshInfo->FullLoadFromFile();
+
+ PrepareForWriting(file,/*overwrite=*/true);
+
+ SMESH_MeshPartDS partDS( meshPart );
+ _impl->ExportGMF(file, &partDS, withRequiredGroups);
+
+ TPythonDump() << SMESH::SMESH_Mesh_var(_this()) << ".ExportGMF( "
+ << meshPart<< ", r'"
+ << file << "', "
+ << withRequiredGroups << ")";
+}
+
+//=============================================================================
+/*!
+ * Return computation progress [0.,1]
+ */
+//=============================================================================
+
+CORBA::Double SMESH_Mesh_i::GetComputeProgress()
+{
+ SMESH_TRY;
+
+ return _impl->GetComputeProgress();
+
+ SMESH_CATCH( SMESH::doNothing );
+ return 0.;
+}
+
+CORBA::Long SMESH_Mesh_i::NbNodes()throw(SALOME::SALOME_Exception)
+{
+ Unexpect aCatch(SALOME_SalomeException);
+ if ( _preMeshInfo )
+ return _preMeshInfo->NbNodes();
+
+ return _impl->NbNodes();
+}
+
+CORBA::Long SMESH_Mesh_i::NbElements()throw (SALOME::SALOME_Exception)
+{
+ Unexpect aCatch(SALOME_SalomeException);
+ if ( _preMeshInfo )
+ return _preMeshInfo->NbElements();
+
+ return Nb0DElements() + NbEdges() + NbFaces() + NbVolumes() + NbBalls();
+}
+
+CORBA::Long SMESH_Mesh_i::Nb0DElements()throw (SALOME::SALOME_Exception)
+{
+ Unexpect aCatch(SALOME_SalomeException);
+ if ( _preMeshInfo )
+ return _preMeshInfo->Nb0DElements();
+
+ return _impl->Nb0DElements();
+}
+
+CORBA::Long SMESH_Mesh_i::NbBalls() throw (SALOME::SALOME_Exception)
+{
+ Unexpect aCatch(SALOME_SalomeException);
+ if ( _preMeshInfo )
+ return _preMeshInfo->NbBalls();
+
+ return _impl->NbBalls();
+}
+
+CORBA::Long SMESH_Mesh_i::NbEdges()throw(SALOME::SALOME_Exception)
+{
+ Unexpect aCatch(SALOME_SalomeException);
+ if ( _preMeshInfo )
+ return _preMeshInfo->NbEdges();
+
+ return _impl->NbEdges();
+}
+
+CORBA::Long SMESH_Mesh_i::NbEdgesOfOrder(SMESH::ElementOrder order)
+ throw(SALOME::SALOME_Exception)
+{
+ Unexpect aCatch(SALOME_SalomeException);
+ if ( _preMeshInfo )
+ return _preMeshInfo->NbEdges( (SMDSAbs_ElementOrder) order );
+
+ return _impl->NbEdges( (SMDSAbs_ElementOrder) order);
+}
+
+//=============================================================================
+
+CORBA::Long SMESH_Mesh_i::NbFaces()throw(SALOME::SALOME_Exception)
+{
+ Unexpect aCatch(SALOME_SalomeException);
+ if ( _preMeshInfo )
+ return _preMeshInfo->NbFaces();
+
+ return _impl->NbFaces();
+}
+
+CORBA::Long SMESH_Mesh_i::NbTriangles()throw(SALOME::SALOME_Exception)
+{
+ Unexpect aCatch(SALOME_SalomeException);
+ if ( _preMeshInfo )
+ return _preMeshInfo->NbTriangles();
+
+ return _impl->NbTriangles();
+}
+
+CORBA::Long SMESH_Mesh_i::NbBiQuadTriangles()throw(SALOME::SALOME_Exception)
+{
+ Unexpect aCatch(SALOME_SalomeException);
+ if ( _preMeshInfo )
+ return _preMeshInfo->NbBiQuadTriangles();
+
+ return _impl->NbBiQuadTriangles();
+}
+
+CORBA::Long SMESH_Mesh_i::NbQuadrangles()throw(SALOME::SALOME_Exception)
+{
+ Unexpect aCatch(SALOME_SalomeException);
+ if ( _preMeshInfo )
+ return _preMeshInfo->NbQuadrangles();
+
+ return _impl->NbQuadrangles();
+}
+
+CORBA::Long SMESH_Mesh_i::NbBiQuadQuadrangles()throw(SALOME::SALOME_Exception)
+{
+ Unexpect aCatch(SALOME_SalomeException);
+ if ( _preMeshInfo )
+ return _preMeshInfo->NbBiQuadQuadrangles();
+
+ return _impl->NbBiQuadQuadrangles();
+}
+
+CORBA::Long SMESH_Mesh_i::NbPolygons() throw(SALOME::SALOME_Exception)
+{
+ Unexpect aCatch(SALOME_SalomeException);
+ if ( _preMeshInfo )
+ return _preMeshInfo->NbPolygons();
+
+ return _impl->NbPolygons();
+}
+
+CORBA::Long SMESH_Mesh_i::NbPolygonsOfOrder(SMESH::ElementOrder order) throw(SALOME::SALOME_Exception)
+{
+ Unexpect aCatch(SALOME_SalomeException);
+ if ( _preMeshInfo )
+ return _preMeshInfo->NbPolygons((SMDSAbs_ElementOrder) order);
+
+ return _impl->NbPolygons((SMDSAbs_ElementOrder)order);
+}
+
+CORBA::Long SMESH_Mesh_i::NbFacesOfOrder(SMESH::ElementOrder order)
+ throw(SALOME::SALOME_Exception)
+{
+ Unexpect aCatch(SALOME_SalomeException);
+ if ( _preMeshInfo )
+ return _preMeshInfo->NbFaces( (SMDSAbs_ElementOrder) order );
+
+ return _impl->NbFaces( (SMDSAbs_ElementOrder) order);
+}
+
+CORBA::Long SMESH_Mesh_i::NbTrianglesOfOrder(SMESH::ElementOrder order)
+ throw(SALOME::SALOME_Exception)
+{
+ Unexpect aCatch(SALOME_SalomeException);
+ if ( _preMeshInfo )
+ return _preMeshInfo->NbTriangles( (SMDSAbs_ElementOrder) order );
+
+ return _impl->NbTriangles( (SMDSAbs_ElementOrder) order);
+}
+
+CORBA::Long SMESH_Mesh_i::NbQuadranglesOfOrder(SMESH::ElementOrder order)
+ throw(SALOME::SALOME_Exception)
+{
+ Unexpect aCatch(SALOME_SalomeException);
+ if ( _preMeshInfo )
+ return _preMeshInfo->NbQuadrangles( (SMDSAbs_ElementOrder) order );
+
+ return _impl->NbQuadrangles( (SMDSAbs_ElementOrder) order);
+}
+
+//=============================================================================
+
+CORBA::Long SMESH_Mesh_i::NbVolumes()throw(SALOME::SALOME_Exception)
+{
+ Unexpect aCatch(SALOME_SalomeException);
+ if ( _preMeshInfo )
+ return _preMeshInfo->NbVolumes();
+
+ return _impl->NbVolumes();
+}
+
+CORBA::Long SMESH_Mesh_i::NbTetras()throw(SALOME::SALOME_Exception)
+{
+ Unexpect aCatch(SALOME_SalomeException);
+ if ( _preMeshInfo )
+ return _preMeshInfo->NbTetras();
+
+ return _impl->NbTetras();
+}
+
+CORBA::Long SMESH_Mesh_i::NbHexas()throw(SALOME::SALOME_Exception)
+{
+ Unexpect aCatch(SALOME_SalomeException);
+ if ( _preMeshInfo )
+ return _preMeshInfo->NbHexas();
+
+ return _impl->NbHexas();
+}
+
+CORBA::Long SMESH_Mesh_i::NbTriQuadraticHexas()throw(SALOME::SALOME_Exception)
+{
+ Unexpect aCatch(SALOME_SalomeException);
+ if ( _preMeshInfo )
+ return _preMeshInfo->NbTriQuadHexas();
+
+ return _impl->NbTriQuadraticHexas();
+}
+
+CORBA::Long SMESH_Mesh_i::NbPyramids()throw(SALOME::SALOME_Exception)
+{
+ Unexpect aCatch(SALOME_SalomeException);
+ if ( _preMeshInfo )
+ return _preMeshInfo->NbPyramids();
+
+ return _impl->NbPyramids();
+}
+
+CORBA::Long SMESH_Mesh_i::NbPrisms()throw(SALOME::SALOME_Exception)
+{
+ Unexpect aCatch(SALOME_SalomeException);
+ if ( _preMeshInfo )
+ return _preMeshInfo->NbPrisms();
+
+ return _impl->NbPrisms();
+}
+
+CORBA::Long SMESH_Mesh_i::NbHexagonalPrisms()throw(SALOME::SALOME_Exception)
+{
+ Unexpect aCatch(SALOME_SalomeException);
+ if ( _preMeshInfo )
+ return _preMeshInfo->NbHexPrisms();
+
+ return _impl->NbHexagonalPrisms();
+}
+
+CORBA::Long SMESH_Mesh_i::NbPolyhedrons()throw(SALOME::SALOME_Exception)
+{
+ Unexpect aCatch(SALOME_SalomeException);
+ if ( _preMeshInfo )
+ return _preMeshInfo->NbPolyhedrons();
+
+ return _impl->NbPolyhedrons();
+}
+
+CORBA::Long SMESH_Mesh_i::NbVolumesOfOrder(SMESH::ElementOrder order)
+ throw(SALOME::SALOME_Exception)
+{
+ Unexpect aCatch(SALOME_SalomeException);
+ if ( _preMeshInfo )
+ return _preMeshInfo->NbVolumes( (SMDSAbs_ElementOrder) order );
+
+ return _impl->NbVolumes( (SMDSAbs_ElementOrder) order);
+}
+
+CORBA::Long SMESH_Mesh_i::NbTetrasOfOrder(SMESH::ElementOrder order)
+ throw(SALOME::SALOME_Exception)
+{
+ Unexpect aCatch(SALOME_SalomeException);
+ if ( _preMeshInfo )
+ return _preMeshInfo->NbTetras( (SMDSAbs_ElementOrder) order);
+
+ return _impl->NbTetras( (SMDSAbs_ElementOrder) order);
+}
+
+CORBA::Long SMESH_Mesh_i::NbHexasOfOrder(SMESH::ElementOrder order)
+ throw(SALOME::SALOME_Exception)
+{
+ Unexpect aCatch(SALOME_SalomeException);
+ if ( _preMeshInfo )
+ return _preMeshInfo->NbHexas( (SMDSAbs_ElementOrder) order);
+
+ return _impl->NbHexas( (SMDSAbs_ElementOrder) order);
+}
+
+CORBA::Long SMESH_Mesh_i::NbPyramidsOfOrder(SMESH::ElementOrder order)
+ throw(SALOME::SALOME_Exception)
+{
+ Unexpect aCatch(SALOME_SalomeException);
+ if ( _preMeshInfo )
+ return _preMeshInfo->NbPyramids( (SMDSAbs_ElementOrder) order);
+
+ return _impl->NbPyramids( (SMDSAbs_ElementOrder) order);
+}
+
+CORBA::Long SMESH_Mesh_i::NbPrismsOfOrder(SMESH::ElementOrder order)
+ throw(SALOME::SALOME_Exception)
+{
+ Unexpect aCatch(SALOME_SalomeException);
+ if ( _preMeshInfo )
+ return _preMeshInfo->NbPrisms( (SMDSAbs_ElementOrder) order);
+
+ return _impl->NbPrisms( (SMDSAbs_ElementOrder) order);
+}
+
+//=============================================================================
+/*!
+ * Returns nb of published sub-meshes
+ */
+//=============================================================================
+
+CORBA::Long SMESH_Mesh_i::NbSubMesh()throw(SALOME::SALOME_Exception)
+{
+ Unexpect aCatch(SALOME_SalomeException);
+ return _mapSubMesh_i.size();
+}
+
+//=============================================================================
+/*!
+ * Dumps mesh into a string
+ */
+//=============================================================================
+
+char* SMESH_Mesh_i::Dump()
+{
+ ostringstream os;
+ _impl->Dump( os );
+ return CORBA::string_dup( os.str().c_str() );
+}
+
+//=============================================================================
+/*!
+ * Method of SMESH_IDSource interface
+ */
+//=============================================================================
+
+SMESH::long_array* SMESH_Mesh_i::GetIDs()
+{
+ return GetElementsId();
+}
+
+//=============================================================================
+/*!
+ * Returns ids of all elements
+ */
+//=============================================================================
+
+SMESH::long_array* SMESH_Mesh_i::GetElementsId()
+ throw (SALOME::SALOME_Exception)
+{
+ Unexpect aCatch(SALOME_SalomeException);
+ if ( _preMeshInfo )
+ _preMeshInfo->FullLoadFromFile();
+
+ SMESH::long_array_var aResult = new SMESH::long_array();
+ SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
+
+ if ( aSMESHDS_Mesh == NULL )
+ return aResult._retn();
+
+ long nbElements = NbElements();
+ aResult->length( nbElements );
+ SMDS_ElemIteratorPtr anIt = aSMESHDS_Mesh->elementsIterator();
+ for ( int i = 0, n = nbElements; i < n && anIt->more(); i++ )
+ aResult[i] = anIt->next()->GetID();
+
+ return aResult._retn();
+}
+
+
+//=============================================================================
+/*!
+ * Returns ids of all elements of given type
+ */
+//=============================================================================
+
+SMESH::long_array* SMESH_Mesh_i::GetElementsByType( SMESH::ElementType theElemType )
+ throw (SALOME::SALOME_Exception)
+{
+ Unexpect aCatch(SALOME_SalomeException);
+ if ( _preMeshInfo )
+ _preMeshInfo->FullLoadFromFile();
+
+ SMESH::long_array_var aResult = new SMESH::long_array();
+ SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
+
+ if ( aSMESHDS_Mesh == NULL )
+ return aResult._retn();
+
+ long nbElements = NbElements();
+
+ // No sense in returning ids of elements along with ids of nodes:
+ // when theElemType == SMESH::ALL, return node ids only if
+ // there are no elements
+ if ( theElemType == SMESH::NODE || (theElemType == SMESH::ALL && nbElements == 0) )
+ return GetNodesId();
+
+ aResult->length( nbElements );
+
+ int i = 0;
+
+ SMDS_ElemIteratorPtr anIt = aSMESHDS_Mesh->elementsIterator( (SMDSAbs_ElementType)theElemType );
+ while ( i < nbElements && anIt->more() )
+ aResult[i++] = anIt->next()->GetID();
+
+ aResult->length( i );
+
+ return aResult._retn();
+}
+
+//=============================================================================
+/*!
+ * Returns ids of all nodes
+ */
+//=============================================================================
+
+SMESH::long_array* SMESH_Mesh_i::GetNodesId()
+ throw (SALOME::SALOME_Exception)
+{
+ Unexpect aCatch(SALOME_SalomeException);
+ if ( _preMeshInfo )
+ _preMeshInfo->FullLoadFromFile();
+
+ SMESH::long_array_var aResult = new SMESH::long_array();
+ SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
+
+ if ( aSMESHDS_Mesh == NULL )
+ return aResult._retn();
+
+ long nbNodes = NbNodes();
+ aResult->length( nbNodes );
+ SMDS_NodeIteratorPtr anIt = aSMESHDS_Mesh->nodesIterator(/*idInceasingOrder=*/true);
+ for ( int i = 0, n = nbNodes; i < n && anIt->more(); i++ )
+ aResult[i] = anIt->next()->GetID();
+
+ return aResult._retn();
+}
+
+//=============================================================================
+/*!
+ *
+ */
+//=============================================================================
+
+SMESH::ElementType SMESH_Mesh_i::GetElementType( const CORBA::Long id, const bool iselem )
+ throw (SALOME::SALOME_Exception)
+{
+ SMESH::ElementType type;
+ SMESH_TRY;
+
+ if ( _preMeshInfo )
+ _preMeshInfo->FullLoadFromFile();
+
+ type = ( SMESH::ElementType ) _impl->GetElementType( id, iselem );
+
+ SMESH_CATCH( SMESH::throwCorbaException );
+
+ return type;
+}
+
+//=============================================================================
+/*!
+ *
+ */
+//=============================================================================
+
+SMESH::EntityType SMESH_Mesh_i::GetElementGeomType( const CORBA::Long id )
+ throw (SALOME::SALOME_Exception)
+{
+ if ( _preMeshInfo )
+ _preMeshInfo->FullLoadFromFile();
+
+ const SMDS_MeshElement* e = _impl->GetMeshDS()->FindElement(id);
+ if ( !e )
+ THROW_SALOME_CORBA_EXCEPTION( "invalid element id", SALOME::BAD_PARAM );
+
+ return ( SMESH::EntityType ) e->GetEntityType();
+}
+
+//=============================================================================
+/*!
+ *
+ */
+//=============================================================================
+
+SMESH::GeometryType SMESH_Mesh_i::GetElementShape( const CORBA::Long id )
+ throw (SALOME::SALOME_Exception)
+{
+ if ( _preMeshInfo )
+ _preMeshInfo->FullLoadFromFile();
+
+ const SMDS_MeshElement* e = _impl->GetMeshDS()->FindElement(id);
+ if ( !e )
+ THROW_SALOME_CORBA_EXCEPTION( "invalid element id", SALOME::BAD_PARAM );
+
+ return ( SMESH::GeometryType ) e->GetGeomType();
+}
+
+//=============================================================================
+/*!
+ * Returns ID of elements for given submesh
+ */
+//=============================================================================
+SMESH::long_array* SMESH_Mesh_i::GetSubMeshElementsId(const CORBA::Long ShapeID)
+ throw (SALOME::SALOME_Exception)
+{
+ SMESH::long_array_var aResult = new SMESH::long_array();
+
+ SMESH_TRY;
+ if ( _preMeshInfo )
+ _preMeshInfo->FullLoadFromFile();
+
+ SMESH_subMesh* SM = _impl->GetSubMeshContaining(ShapeID);
+ if(!SM) return aResult._retn();
+
+ SMESHDS_SubMesh* SDSM = SM->GetSubMeshDS();
+ if(!SDSM) return aResult._retn();
+
+ aResult->length(SDSM->NbElements());
+
+ SMDS_ElemIteratorPtr eIt = SDSM->GetElements();
+ int i = 0;
+ while ( eIt->more() ) {
+ aResult[i++] = eIt->next()->GetID();
+ }
+
+ SMESH_CATCH( SMESH::throwCorbaException );
+
+ return aResult._retn();
+}
+
+//=============================================================================
+/*!
+ * Returns ID of nodes for given submesh
+ * If param all==true - returns all nodes, else -
+ * returns only nodes on shapes.
+ */
+//=============================================================================
+
+SMESH::long_array* SMESH_Mesh_i::GetSubMeshNodesId(const CORBA::Long ShapeID,
+ CORBA::Boolean all)
+ throw (SALOME::SALOME_Exception)
+{
+ SMESH::long_array_var aResult = new SMESH::long_array();
+
+ SMESH_TRY;
+ if ( _preMeshInfo )
+ _preMeshInfo->FullLoadFromFile();
+
+ SMESH_subMesh* SM = _impl->GetSubMeshContaining(ShapeID);
+ if(!SM) return aResult._retn();
+
+ SMESHDS_SubMesh* SDSM = SM->GetSubMeshDS();
+ if(!SDSM) return aResult._retn();
+
+ set<int> theElems;
+ if( !all || (SDSM->NbElements()==0) ) { // internal nodes or vertex submesh
+ SMDS_NodeIteratorPtr nIt = SDSM->GetNodes();
+ while ( nIt->more() ) {
+ const SMDS_MeshNode* elem = nIt->next();
+ theElems.insert( elem->GetID() );
+ }
+ }
+ else { // all nodes of submesh elements
+ SMDS_ElemIteratorPtr eIt = SDSM->GetElements();
+ while ( eIt->more() ) {
+ const SMDS_MeshElement* anElem = eIt->next();
+ SMDS_ElemIteratorPtr nIt = anElem->nodesIterator();
+ while ( nIt->more() ) {
+ const SMDS_MeshElement* elem = nIt->next();
+ theElems.insert( elem->GetID() );
+ }
+ }
+ }
+
+ aResult->length(theElems.size());
+ set<int>::iterator itElem;
+ int i = 0;
+ for ( itElem = theElems.begin(); itElem != theElems.end(); itElem++ )
+ aResult[i++] = *itElem;
+
+ SMESH_CATCH( SMESH::throwCorbaException );
+
+ return aResult._retn();
+}
+
+//=============================================================================
+/*!
+ * Returns type of elements for given submesh
+ */
+//=============================================================================
+
+SMESH::ElementType SMESH_Mesh_i::GetSubMeshElementType(const CORBA::Long ShapeID)
+ throw (SALOME::SALOME_Exception)
+{
+ SMESH::ElementType type;
+
+ SMESH_TRY;
+ if ( _preMeshInfo )
+ _preMeshInfo->FullLoadFromFile();
+
+ SMESH_subMesh* SM = _impl->GetSubMeshContaining(ShapeID);
+ if(!SM) return SMESH::ALL;
+
+ SMESHDS_SubMesh* SDSM = SM->GetSubMeshDS();
+ if(!SDSM) return SMESH::ALL;
+
+ if(SDSM->NbElements()==0)
+ return (SM->GetSubShape().ShapeType() == TopAbs_VERTEX) ? SMESH::NODE : SMESH::ALL;
+
+ SMDS_ElemIteratorPtr eIt = SDSM->GetElements();
+ const SMDS_MeshElement* anElem = eIt->next();
+
+ type = ( SMESH::ElementType ) anElem->GetType();
+
+ SMESH_CATCH( SMESH::throwCorbaException );
+
+ return type;
+}
+
+
+//=============================================================================
+/*!
+ * Returns pointer to _impl as an integer value. Is called from constructor of SMESH_Client
+ */
+//=============================================================================
+
+CORBA::LongLong SMESH_Mesh_i::GetMeshPtr()
+{
+ if ( _preMeshInfo )
+ _preMeshInfo->FullLoadFromFile();
+
+ CORBA::LongLong pointeur = CORBA::LongLong(_impl);
+ if ( MYDEBUG )
+ MESSAGE("CORBA::LongLong SMESH_Mesh_i::GetMeshPtr() "<<pointeur);
+ return pointeur;
+}
+
+
+//=============================================================================
+/*!
+ * Get XYZ coordinates of node as list of double
+ * If there is not node for given ID - returns empty list
+ */
+//=============================================================================
+
+SMESH::double_array* SMESH_Mesh_i::GetNodeXYZ(const CORBA::Long id)
+{
+ if ( _preMeshInfo )
+ _preMeshInfo->FullLoadFromFile();
+
+ SMESH::double_array_var aResult = new SMESH::double_array();
+ SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
+ if ( aSMESHDS_Mesh == NULL )
+ return aResult._retn();
+
+ // find node
+ const SMDS_MeshNode* aNode = aSMESHDS_Mesh->FindNode(id);
+ if(!aNode)
+ return aResult._retn();
+
+ // add coordinates
+ aResult->length(3);
+ aResult[0] = aNode->X();
+ aResult[1] = aNode->Y();
+ aResult[2] = aNode->Z();
+ return aResult._retn();
+}
+
+
+//=============================================================================
+/*!
+ * For given node returns list of IDs of inverse elements
+ * If there is not node for given ID - returns empty list
+ */
+//=============================================================================
+
+SMESH::long_array* SMESH_Mesh_i::GetNodeInverseElements(const CORBA::Long id)
+{
+ if ( _preMeshInfo )
+ _preMeshInfo->FullLoadFromFile();
+
+ SMESH::long_array_var aResult = new SMESH::long_array();
+ SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
+ if ( aSMESHDS_Mesh == NULL )
+ return aResult._retn();
+
+ // find node
+ const SMDS_MeshNode* aNode = aSMESHDS_Mesh->FindNode(id);
+ if(!aNode)
+ return aResult._retn();
+
+ // find inverse elements
+ SMDS_ElemIteratorPtr eIt = aNode->GetInverseElementIterator();
+ aResult->length( aNode->NbInverseElements() );
+ for( int i = 0; eIt->more(); ++i )
+ {
+ const SMDS_MeshElement* elem = eIt->next();
+ aResult[ i ] = elem->GetID();
+ }
+ return aResult._retn();
+}
+
+//=============================================================================
+/*!
+ * \brief Return position of a node on shape
+ */
+//=============================================================================
+
+SMESH::NodePosition* SMESH_Mesh_i::GetNodePosition(CORBA::Long NodeID)
+{
+ if ( _preMeshInfo )
+ _preMeshInfo->FullLoadFromFile();
+
+ SMESH::NodePosition* aNodePosition = new SMESH::NodePosition();
+ aNodePosition->shapeID = 0;
+ aNodePosition->shapeType = GEOM::SHAPE;
+
+ SMESHDS_Mesh* mesh = _impl->GetMeshDS();
+ if ( !mesh ) return aNodePosition;
+
+ if ( const SMDS_MeshNode* aNode = mesh->FindNode(NodeID) )
+ {
+ if ( SMDS_PositionPtr pos = aNode->GetPosition() )
+ {
+ aNodePosition->shapeID = aNode->getshapeId();
+ switch ( pos->GetTypeOfPosition() ) {
+ case SMDS_TOP_EDGE:
+ aNodePosition->shapeType = GEOM::EDGE;
+ aNodePosition->params.length(1);
+ aNodePosition->params[0] =
+ static_cast<SMDS_EdgePosition*>( pos )->GetUParameter();
+ break;
+ case SMDS_TOP_FACE:
+ aNodePosition->shapeType = GEOM::FACE;
+ aNodePosition->params.length(2);
+ aNodePosition->params[0] =
+ static_cast<SMDS_FacePosition*>( pos )->GetUParameter();
+ aNodePosition->params[1] =
+ static_cast<SMDS_FacePosition*>( pos )->GetVParameter();
+ break;
+ case SMDS_TOP_VERTEX:
+ aNodePosition->shapeType = GEOM::VERTEX;
+ break;
+ case SMDS_TOP_3DSPACE:
+ if ( TopExp_Explorer(_impl->GetShapeToMesh(), TopAbs_SOLID).More() )
+ aNodePosition->shapeType = GEOM::SOLID;
+ else if ( TopExp_Explorer(_impl->GetShapeToMesh(), TopAbs_SHELL).More() )
+ aNodePosition->shapeType = GEOM::SHELL;
+ break;
+ default:;
+ }
+ }
+ }
+ return aNodePosition;
+}
+
+//=============================================================================
+/*!
+ * \brief Return position of an element on shape
+ */
+//=============================================================================
+
+SMESH::ElementPosition SMESH_Mesh_i::GetElementPosition(CORBA::Long ElemID)
+{
+ if ( _preMeshInfo )
+ _preMeshInfo->FullLoadFromFile();
+
+ SMESH::ElementPosition anElementPosition;
+ anElementPosition.shapeID = 0;
+ anElementPosition.shapeType = GEOM::SHAPE;
+
+ SMESHDS_Mesh* mesh = _impl->GetMeshDS();
+ if ( !mesh ) return anElementPosition;
+
+ if ( const SMDS_MeshElement* anElem = mesh->FindElement( ElemID ) )
+ {
+ anElementPosition.shapeID = anElem->getshapeId();
+ const TopoDS_Shape& aSp = mesh->IndexToShape( anElem->getshapeId() );
+ if ( !aSp.IsNull() ) {
+ switch ( aSp.ShapeType() ) {
+ case TopAbs_EDGE:
+ anElementPosition.shapeType = GEOM::EDGE;
+ break;
+ case TopAbs_FACE:
+ anElementPosition.shapeType = GEOM::FACE;
+ break;
+ case TopAbs_VERTEX:
+ anElementPosition.shapeType = GEOM::VERTEX;
+ break;
+ case TopAbs_SOLID:
+ anElementPosition.shapeType = GEOM::SOLID;
+ break;
+ case TopAbs_SHELL:
+ anElementPosition.shapeType = GEOM::SHELL;
+ break;
+ default:;
+ }
+ }
+ }
+ return anElementPosition;
+}
+
+//=============================================================================
+/*!
+ * If given element is node returns IDs of shape from position
+ * If there is not node for given ID - returns -1
+ */
+//=============================================================================
+
+CORBA::Long SMESH_Mesh_i::GetShapeID(const CORBA::Long id)
+{
+ if ( _preMeshInfo )
+ _preMeshInfo->FullLoadFromFile();
+
+ SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
+ if ( aSMESHDS_Mesh == NULL )
+ return -1;
+
+ // try to find node
+ const SMDS_MeshNode* aNode = aSMESHDS_Mesh->FindNode(id);
+ if(aNode) {
+ return aNode->getshapeId();
+ }
+
+ return -1;
+}
+
+
+//=============================================================================
+/*!
+ * For given element returns ID of result shape after
+ * ::FindShape() from SMESH_MeshEditor
+ * If there is not element for given ID - returns -1
+ */
+//=============================================================================
+
+CORBA::Long SMESH_Mesh_i::GetShapeIDForElem(const CORBA::Long id)
+{
+ if ( _preMeshInfo )
+ _preMeshInfo->FullLoadFromFile();
+
+ SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
+ if ( aSMESHDS_Mesh == NULL )
+ return -1;
+
+ // try to find element
+ const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
+ if(!elem)
+ return -1;
+
+ ::SMESH_MeshEditor aMeshEditor(_impl);
+ int index = aMeshEditor.FindShape( elem );
+ if(index>0)
+ return index;
+
+ return -1;
+}
+
+
+//=============================================================================
+/*!
+ * Returns number of nodes for given element
+ * If there is not element for given ID - returns -1
+ */
+//=============================================================================
+
+CORBA::Long SMESH_Mesh_i::GetElemNbNodes(const CORBA::Long id)
+{
+ if ( _preMeshInfo )
+ _preMeshInfo->FullLoadFromFile();
+
+ SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
+ if ( aSMESHDS_Mesh == NULL ) return -1;
+ // try to find element
+ const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
+ if(!elem) return -1;
+ return elem->NbNodes();
+}
+
+
+//=============================================================================
+/*!
+ * Returns ID of node by given index for given element
+ * If there is not element for given ID - returns -1
+ * If there is not node for given index - returns -2
+ */
+//=============================================================================
+
+CORBA::Long SMESH_Mesh_i::GetElemNode(const CORBA::Long id, const CORBA::Long index)
+{
+ if ( _preMeshInfo )
+ _preMeshInfo->FullLoadFromFile();
+
+ SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
+ if ( aSMESHDS_Mesh == NULL ) return -1;
+ const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
+ if(!elem) return -1;
+ if( index>=elem->NbNodes() || index<0 ) return -1;
+ return elem->GetNode(index)->GetID();
+}
+
+//=============================================================================
+/*!
+ * Returns IDs of nodes of given element
+ */
+//=============================================================================
+
+SMESH::long_array* SMESH_Mesh_i::GetElemNodes(const CORBA::Long id)
+{
+ if ( _preMeshInfo )
+ _preMeshInfo->FullLoadFromFile();
+
+ SMESH::long_array_var aResult = new SMESH::long_array();
+ if ( SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS() )
+ {
+ if ( const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id) )
+ {
+ aResult->length( elem->NbNodes() );
+ for ( int i = 0; i < elem->NbNodes(); ++i )
+ aResult[ i ] = elem->GetNode( i )->GetID();
+ }
+ }
+ return aResult._retn();
+}
+
+//=============================================================================
+/*!
+ * Returns true if given node is medium node
+ * in given quadratic element
+ */
+//=============================================================================
+
+CORBA::Boolean SMESH_Mesh_i::IsMediumNode(const CORBA::Long ide, const CORBA::Long idn)
+{
+ if ( _preMeshInfo )
+ _preMeshInfo->FullLoadFromFile();
+
+ SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
+ if ( aSMESHDS_Mesh == NULL ) return false;
+ // try to find node
+ const SMDS_MeshNode* aNode = aSMESHDS_Mesh->FindNode(idn);
+ if(!aNode) return false;
+ // try to find element
+ const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(ide);
+ if(!elem) return false;
+
+ return elem->IsMediumNode(aNode);
+}
+
+
+//=============================================================================
+/*!
+ * Returns true if given node is medium node
+ * in one of quadratic elements
+ */
+//=============================================================================
+
+CORBA::Boolean SMESH_Mesh_i::IsMediumNodeOfAnyElem(const CORBA::Long idn,
+ SMESH::ElementType theElemType)
+{
+ if ( _preMeshInfo )
+ _preMeshInfo->FullLoadFromFile();
+
+ SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
+ if ( aSMESHDS_Mesh == NULL ) return false;
+
+ // try to find node
+ const SMDS_MeshNode* aNode = aSMESHDS_Mesh->FindNode(idn);
+ if(!aNode) return false;
+
+ SMESH_MesherHelper aHelper( *(_impl) );
+
+ SMDSAbs_ElementType aType;
+ if(theElemType==SMESH::EDGE) aType = SMDSAbs_Edge;
+ else if(theElemType==SMESH::FACE) aType = SMDSAbs_Face;
+ else if(theElemType==SMESH::VOLUME) aType = SMDSAbs_Volume;
+ else aType = SMDSAbs_All;
+
+ return aHelper.IsMedium(aNode,aType);
+}
+
+
+//=============================================================================
+/*!
+ * Returns number of edges for given element
+ */
+//=============================================================================
+
+CORBA::Long SMESH_Mesh_i::ElemNbEdges(const CORBA::Long id)
+{
+ if ( _preMeshInfo )
+ _preMeshInfo->FullLoadFromFile();
+
+ SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
+ if ( aSMESHDS_Mesh == NULL ) return -1;
+ const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
+ if(!elem) return -1;
+ return elem->NbEdges();
+}
+
+
+//=============================================================================
+/*!
+ * Returns number of faces for given element
+ */
+//=============================================================================
+
+CORBA::Long SMESH_Mesh_i::ElemNbFaces(const CORBA::Long id)