+ * SMESH_Mesh_i::removeGroup
+ *
+ * Should be called by ~SMESH_Group_i()
+ */
+//=============================================================================
+
+void SMESH_Mesh_i::removeGroup( const int theId )
+{
+ if(MYDEBUG) MESSAGE("SMESH_Mesh_i::removeGroup()" );
+ if ( _mapGroups.find( theId ) != _mapGroups.end() ) {
+ SMESH::SMESH_GroupBase_ptr group = _mapGroups[theId];
+ _mapGroups.erase( theId );
+ removeGeomGroupData( group );
+ if (! _impl->RemoveGroup( theId ))
+ {
+ // it seems to be a call up from _impl caused by hyp modification (issue 0020918)
+ RemoveGroup( group );
+ }
+ }
+}
+
+//=============================================================================
+/*!
+ *
+ */
+//=============================================================================
+
+SMESH::log_array * SMESH_Mesh_i::GetLog(CORBA::Boolean clearAfterGet)
+throw(SALOME::SALOME_Exception)
+{
+ if(MYDEBUG) MESSAGE("SMESH_Mesh_i::GetLog");
+
+ SMESH::log_array_var aLog;
+ try{
+ 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();
+ }
+ catch(SALOME_Exception & S_ex){
+ THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
+ }
+ return aLog._retn();
+}
+
+
+//=============================================================================
+/*!
+ *
+ */
+//=============================================================================
+
+void SMESH_Mesh_i::ClearLog() throw(SALOME::SALOME_Exception)
+{
+ if(MYDEBUG) MESSAGE("SMESH_Mesh_i::ClearLog");
+ _impl->ClearLog();
+}
+
+//=============================================================================
+/*!
+ *
+ */
+//=============================================================================
+
+CORBA::Long SMESH_Mesh_i::GetId()throw(SALOME::SALOME_Exception)
+{
+ if(MYDEBUG) MESSAGE("SMESH_Mesh_i::GetId");
+ return _id;
+}
+
+//=============================================================================
+/*!
+ *
+ */
+//=============================================================================
+
+CORBA::Long SMESH_Mesh_i::GetStudyId()throw(SALOME::SALOME_Exception)
+{
+ return _studyId;
+}
+
+//=============================================================================
+namespace
+{
+ //!< implementation of struct used to call SMESH_Mesh_i::removeGroup() from
+ // SMESH_Mesh::RemoveGroup() (issue 0020918)
+ struct TRmGroupCallUp_i : public SMESH_Mesh::TRmGroupCallUp
+ {
+ SMESH_Mesh_i* _mesh;
+ TRmGroupCallUp_i(SMESH_Mesh_i* mesh):_mesh(mesh) {}
+ virtual void RemoveGroup (const int theGroupID) { _mesh->removeGroup( theGroupID ); }
+ };
+}
+
+//=============================================================================
+/*!
+ *
+ */
+//=============================================================================
+
+void SMESH_Mesh_i::SetImpl(::SMESH_Mesh * impl)
+{
+ if(MYDEBUG) MESSAGE("SMESH_Mesh_i::SetImpl");
+ _impl = impl;
+ if ( _impl )
+ _impl->SetRemoveGroupCallUp( new TRmGroupCallUp_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()
+{
+ // Create MeshEditor
+ SMESH_MeshEditor_i *aMeshEditor = new SMESH_MeshEditor_i( this, false );
+ SMESH::SMESH_MeshEditor_var aMesh = aMeshEditor->_this();
+
+ // Update Python script
+ TPythonDump() << aMeshEditor << " = " << _this() << ".GetMeshEditor()";
+
+ return aMesh._retn();
+}
+
+//=============================================================================
+/*!
+ * Return mesh edition previewer
+ */
+//=============================================================================
+
+SMESH::SMESH_MeshEditor_ptr SMESH_Mesh_i::GetMeshEditPreviewer()
+{
+ SMESH_MeshEditor_i *aMeshEditor = new SMESH_MeshEditor_i( this, true );
+ SMESH::SMESH_MeshEditor_var aMesh = aMeshEditor->_this();
+ return aMesh._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();
+}
+
+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;
+}
+
+//=============================================================================
+/*!
+ *
+ */
+//=============================================================================
+void SMESH_Mesh_i::SetAutoColor(CORBA::Boolean theAutoColor) throw(SALOME::SALOME_Exception)
+{
+ Unexpect aCatch(SALOME_SalomeException);
+ _impl->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 );
+ }
+}
+
+//=============================================================================
+/*!
+ *
+ */
+//=============================================================================
+CORBA::Boolean SMESH_Mesh_i::GetAutoColor() throw(SALOME::SALOME_Exception)
+{
+ Unexpect aCatch(SALOME_SalomeException);
+ return _impl->GetAutoColor();
+}
+
+
+//=============================================================================
+/*!
+ * Export in different formats
+ */
+//=============================================================================
+
+CORBA::Boolean SMESH_Mesh_i::HasDuplicatedGroupNamesMED()
+{
+ return _impl->HasDuplicatedGroupNamesMED();
+}
+
+void SMESH_Mesh_i::PrepareForWriting (const char* file, bool overwrite)
+{
+ TCollection_AsciiString aFullName ((char*)file);
+ OSD_Path aPath (aFullName);
+ OSD_File aFile (aPath);
+ if (aFile.Exists()) {
+ // existing filesystem node
+ if (aFile.KindOfFile() == OSD_FILE) {
+ if (aFile.IsWriteable()) {
+ if (overwrite) {
+ aFile.Reset();
+ aFile.Remove();
+ }
+ if (aFile.Failed()) {
+ TCollection_AsciiString msg ("File ");
+ msg += aFullName + " cannot be replaced.";
+ THROW_SALOME_CORBA_EXCEPTION(msg.ToCString(), SALOME::BAD_PARAM);
+ }
+ } else {
+ TCollection_AsciiString msg ("File ");
+ msg += aFullName + " cannot be overwritten.";
+ THROW_SALOME_CORBA_EXCEPTION(msg.ToCString(), SALOME::BAD_PARAM);
+ }
+ } else {
+ TCollection_AsciiString msg ("Location ");
+ msg += aFullName + " is not a file.";
+ THROW_SALOME_CORBA_EXCEPTION(msg.ToCString(), SALOME::BAD_PARAM);
+ }
+ } else {
+ // nonexisting file; check if it can be created
+ aFile.Reset();
+ aFile.Build(OSD_WriteOnly, OSD_Protection());
+ if (aFile.Failed()) {
+ TCollection_AsciiString msg ("You cannot create the file ");
+ msg += aFullName + ". Check the directory existance and access rights.";
+ THROW_SALOME_CORBA_EXCEPTION(msg.ToCString(), SALOME::BAD_PARAM);
+ } else {
+ aFile.Close();
+ aFile.Remove();
+ }
+ }
+}
+
+void SMESH_Mesh_i::ExportToMEDX (const char* file,
+ CORBA::Boolean auto_groups,
+ SMESH::MED_VERSION theVersion,
+ CORBA::Boolean overwrite)
+ throw(SALOME::SALOME_Exception)
+{
+ Unexpect aCatch(SALOME_SalomeException);
+
+ // Perform Export
+ PrepareForWriting(file, overwrite);
+ const char* aMeshName = "Mesh";
+ SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
+ if ( !aStudy->_is_nil() ) {
+ SALOMEDS::SObject_var aMeshSO = _gen_i->ObjectToSObject( aStudy, _this() );
+ if ( !aMeshSO->_is_nil() ) {
+ aMeshName = aMeshSO->GetName();
+ // asv : 27.10.04 : fix of 6903: check for StudyLocked before adding attributes
+ if ( !aStudy->GetProperties()->IsLocked() )
+ {
+ SALOMEDS::GenericAttribute_var anAttr;
+ SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
+ SALOMEDS::AttributeExternalFileDef_var aFileName;
+ anAttr=aStudyBuilder->FindOrCreateAttribute(aMeshSO, "AttributeExternalFileDef");
+ aFileName = SALOMEDS::AttributeExternalFileDef::_narrow(anAttr);
+ ASSERT(!aFileName->_is_nil());
+ aFileName->SetValue(file);
+ SALOMEDS::AttributeFileType_var aFileType;
+ anAttr=aStudyBuilder->FindOrCreateAttribute(aMeshSO, "AttributeFileType");
+ aFileType = SALOMEDS::AttributeFileType::_narrow(anAttr);
+ ASSERT(!aFileType->_is_nil());
+ aFileType->SetValue("FICHIERMED");
+ }
+ }
+ }
+ // Update Python script
+ // set name of mesh before export
+ TPythonDump() << _gen_i << ".SetName(" << _this() << ", '" << aMeshName << "')";
+
+ // check names of groups
+ checkGroupNames();
+
+ TPythonDump() << _this() << ".ExportToMEDX( r'"
+ << file << "', " << auto_groups << ", " << theVersion << ", " << overwrite << " )";
+
+ _impl->ExportMED( file, aMeshName, auto_groups, theVersion );
+}
+
+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);
+}
+
+void SMESH_Mesh_i::ExportMED (const char* file,
+ CORBA::Boolean auto_groups)
+ throw(SALOME::SALOME_Exception)
+{
+ ExportToMEDX(file,auto_groups,SMESH::MED_V2_1,true);
+}
+
+void SMESH_Mesh_i::ExportDAT (const char *file)
+ throw(SALOME::SALOME_Exception)
+{
+ Unexpect aCatch(SALOME_SalomeException);
+
+ // Update Python script
+ // check names of groups
+ checkGroupNames();
+ TPythonDump() << _this() << ".ExportDAT( r'" << file << "' )";
+
+ // Perform Export
+ PrepareForWriting(file);
+ _impl->ExportDAT(file);
+}
+
+void SMESH_Mesh_i::ExportUNV (const char *file)
+ throw(SALOME::SALOME_Exception)
+{
+ Unexpect aCatch(SALOME_SalomeException);
+
+ // Update Python script
+ // check names of groups
+ checkGroupNames();
+ TPythonDump() << _this() << ".ExportUNV( r'" << file << "' )";
+
+ // Perform Export
+ PrepareForWriting(file);
+ _impl->ExportUNV(file);
+}
+
+void SMESH_Mesh_i::ExportSTL (const char *file, const bool isascii)
+ throw(SALOME::SALOME_Exception)
+{
+ Unexpect aCatch(SALOME_SalomeException);
+
+ // Update Python script
+ // check names of groups
+ checkGroupNames();
+ TPythonDump() << _this() << ".ExportSTL( r'" << file << "', " << isascii << " )";
+
+ // Perform Export
+ PrepareForWriting(file);
+ _impl->ExportSTL(file, isascii);
+}
+
+//=============================================================================
+/*!
+ *
+ */
+//=============================================================================
+
+SALOME_MED::MESH_ptr SMESH_Mesh_i::GetMEDMesh()throw(SALOME::SALOME_Exception)
+{
+ Unexpect aCatch(SALOME_SalomeException);
+ SMESH_MEDMesh_i *aMedMesh = new SMESH_MEDMesh_i(this);
+ SALOME_MED::MESH_var aMesh = aMedMesh->_this();
+ return aMesh._retn();
+}
+
+//=============================================================================
+/*!
+ *
+ */
+//=============================================================================
+CORBA::Long SMESH_Mesh_i::NbNodes()throw(SALOME::SALOME_Exception)
+{
+ Unexpect aCatch(SALOME_SalomeException);
+ return _impl->NbNodes();
+}
+
+//=============================================================================
+/*!
+ *
+ */
+//=============================================================================
+CORBA::Long SMESH_Mesh_i::NbElements()throw (SALOME::SALOME_Exception)
+{
+ Unexpect aCatch(SALOME_SalomeException);
+ return Nb0DElements() + NbEdges() + NbFaces() + NbVolumes();
+}
+
+//=============================================================================
+/*!
+ *
+ */
+//=============================================================================
+CORBA::Long SMESH_Mesh_i::Nb0DElements()throw (SALOME::SALOME_Exception)
+{
+ Unexpect aCatch(SALOME_SalomeException);
+ return _impl->Nb0DElements();
+}
+
+//=============================================================================
+/*!
+ *
+ */
+//=============================================================================
+CORBA::Long SMESH_Mesh_i::NbEdges()throw(SALOME::SALOME_Exception)
+{
+ Unexpect aCatch(SALOME_SalomeException);
+ return _impl->NbEdges();
+}
+
+CORBA::Long SMESH_Mesh_i::NbEdgesOfOrder(SMESH::ElementOrder order)
+ throw(SALOME::SALOME_Exception)
+{
+ Unexpect aCatch(SALOME_SalomeException);
+ return _impl->NbEdges( (SMDSAbs_ElementOrder) order);
+}
+
+//=============================================================================
+/*!
+ *
+ */
+//=============================================================================
+CORBA::Long SMESH_Mesh_i::NbFaces()throw(SALOME::SALOME_Exception)
+{
+ Unexpect aCatch(SALOME_SalomeException);
+ return _impl->NbFaces();
+}
+
+CORBA::Long SMESH_Mesh_i::NbTriangles()throw(SALOME::SALOME_Exception)
+{
+ Unexpect aCatch(SALOME_SalomeException);
+ return _impl->NbTriangles();
+}
+
+CORBA::Long SMESH_Mesh_i::NbQuadrangles()throw(SALOME::SALOME_Exception)
+{
+ Unexpect aCatch(SALOME_SalomeException);
+ return _impl->NbQuadrangles();
+}
+
+CORBA::Long SMESH_Mesh_i::NbPolygons()throw(SALOME::SALOME_Exception)
+{
+ Unexpect aCatch(SALOME_SalomeException);
+ return _impl->NbPolygons();
+}
+
+CORBA::Long SMESH_Mesh_i::NbFacesOfOrder(SMESH::ElementOrder order)
+ throw(SALOME::SALOME_Exception)
+{
+ Unexpect aCatch(SALOME_SalomeException);
+ return _impl->NbFaces( (SMDSAbs_ElementOrder) order);
+}
+
+CORBA::Long SMESH_Mesh_i::NbTrianglesOfOrder(SMESH::ElementOrder order)
+ throw(SALOME::SALOME_Exception)
+{
+ Unexpect aCatch(SALOME_SalomeException);
+ return _impl->NbTriangles( (SMDSAbs_ElementOrder) order);
+}
+
+CORBA::Long SMESH_Mesh_i::NbQuadranglesOfOrder(SMESH::ElementOrder order)
+ throw(SALOME::SALOME_Exception)
+{
+ Unexpect aCatch(SALOME_SalomeException);
+ return _impl->NbQuadrangles( (SMDSAbs_ElementOrder) order);
+}
+
+//=============================================================================
+/*!
+ *
+ */
+//=============================================================================
+CORBA::Long SMESH_Mesh_i::NbVolumes()throw(SALOME::SALOME_Exception)
+{
+ Unexpect aCatch(SALOME_SalomeException);
+ return _impl->NbVolumes();
+}
+
+CORBA::Long SMESH_Mesh_i::NbTetras()throw(SALOME::SALOME_Exception)
+{
+ Unexpect aCatch(SALOME_SalomeException);
+ return _impl->NbTetras();
+}
+
+CORBA::Long SMESH_Mesh_i::NbHexas()throw(SALOME::SALOME_Exception)
+{
+ Unexpect aCatch(SALOME_SalomeException);
+ return _impl->NbHexas();
+}
+
+CORBA::Long SMESH_Mesh_i::NbPyramids()throw(SALOME::SALOME_Exception)
+{
+ Unexpect aCatch(SALOME_SalomeException);
+ return _impl->NbPyramids();
+}
+
+CORBA::Long SMESH_Mesh_i::NbPrisms()throw(SALOME::SALOME_Exception)
+{
+ Unexpect aCatch(SALOME_SalomeException);
+ return _impl->NbPrisms();
+}
+
+CORBA::Long SMESH_Mesh_i::NbPolyhedrons()throw(SALOME::SALOME_Exception)
+{
+ Unexpect aCatch(SALOME_SalomeException);
+ return _impl->NbPolyhedrons();
+}
+
+CORBA::Long SMESH_Mesh_i::NbVolumesOfOrder(SMESH::ElementOrder order)
+ throw(SALOME::SALOME_Exception)
+{
+ Unexpect aCatch(SALOME_SalomeException);
+ return _impl->NbVolumes( (SMDSAbs_ElementOrder) order);
+}
+
+CORBA::Long SMESH_Mesh_i::NbTetrasOfOrder(SMESH::ElementOrder order)
+ throw(SALOME::SALOME_Exception)
+{
+ Unexpect aCatch(SALOME_SalomeException);
+ return _impl->NbTetras( (SMDSAbs_ElementOrder) order);
+}
+
+CORBA::Long SMESH_Mesh_i::NbHexasOfOrder(SMESH::ElementOrder order)
+ throw(SALOME::SALOME_Exception)
+{
+ Unexpect aCatch(SALOME_SalomeException);
+ return _impl->NbHexas( (SMDSAbs_ElementOrder) order);
+}
+
+CORBA::Long SMESH_Mesh_i::NbPyramidsOfOrder(SMESH::ElementOrder order)
+ throw(SALOME::SALOME_Exception)
+{
+ Unexpect aCatch(SALOME_SalomeException);
+ return _impl->NbPyramids( (SMDSAbs_ElementOrder) order);
+}
+
+CORBA::Long SMESH_Mesh_i::NbPrismsOfOrder(SMESH::ElementOrder order)
+ throw(SALOME::SALOME_Exception)
+{
+ Unexpect aCatch(SALOME_SalomeException);
+ return _impl->NbPrisms( (SMDSAbs_ElementOrder) order);
+}
+
+//=============================================================================
+/*!
+ *
+ */
+//=============================================================================
+CORBA::Long SMESH_Mesh_i::NbSubMesh()throw(SALOME::SALOME_Exception)
+{
+ Unexpect aCatch(SALOME_SalomeException);
+ return _mapSubMesh_i.size();
+}
+
+//=============================================================================
+/*!
+ *
+ */
+//=============================================================================
+char* SMESH_Mesh_i::Dump()
+{
+ ostringstream os;
+ _impl->Dump( os );
+ return CORBA::string_dup( os.str().c_str() );
+}
+
+//=============================================================================
+/*!
+ *
+ */
+//=============================================================================
+SMESH::long_array* SMESH_Mesh_i::GetIDs()
+{
+// SMESH::long_array_var aResult = new SMESH::long_array();
+// SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
+// int aMinId = aSMESHDS_Mesh->MinElementID();
+// int aMaxId = aSMESHDS_Mesh->MaxElementID();
+
+// aResult->length(aMaxId - aMinId + 1);
+
+// for (int i = 0, id = aMinId; id <= aMaxId; id++ )
+// aResult[i++] = id;
+
+// return aResult._retn();
+ // PAL12398
+ return GetElementsId();
+}
+
+//=============================================================================
+/*!
+ *
+ */
+//=============================================================================
+
+SMESH::long_array* SMESH_Mesh_i::GetElementsId()
+ throw (SALOME::SALOME_Exception)
+{
+ Unexpect aCatch(SALOME_SalomeException);
+ MESSAGE("SMESH_Mesh_i::GetElementsId");
+ 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();
+}
+
+
+//=============================================================================
+/*!
+ *
+ */
+//=============================================================================
+
+SMESH::long_array* SMESH_Mesh_i::GetElementsByType( SMESH::ElementType theElemType )
+ throw (SALOME::SALOME_Exception)
+{
+ Unexpect aCatch(SALOME_SalomeException);
+ MESSAGE("SMESH_subMesh_i::GetElementsByType");
+ 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();
+ while ( i < nbElements && anIt->more() ) {
+ const SMDS_MeshElement* anElem = anIt->next();
+ if ( theElemType == SMESH::ALL || anElem->GetType() == (SMDSAbs_ElementType)theElemType )
+ aResult[i++] = anElem->GetID();
+ }
+
+ aResult->length( i );
+
+ return aResult._retn();
+}
+
+//=============================================================================
+/*!
+ *
+ */
+//=============================================================================
+
+SMESH::long_array* SMESH_Mesh_i::GetNodesId()
+ throw (SALOME::SALOME_Exception)
+{
+ Unexpect aCatch(SALOME_SalomeException);
+ MESSAGE("SMESH_subMesh_i::GetNodesId");
+ 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)
+{
+ return ( SMESH::ElementType )_impl->GetElementType( id, iselem );
+}
+
+//=============================================================================
+/*!
+ *
+ */
+//=============================================================================
+
+SMESH::EntityType SMESH_Mesh_i::GetElementGeomType( const CORBA::Long id )
+ throw (SALOME::SALOME_Exception)
+{
+ 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();
+}
+
+//=============================================================================
+/*!
+ * 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_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();
+ }
+
+ 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_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;
+
+ 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_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();
+ return ( SMESH::ElementType ) anElem->GetType();
+}
+
+
+//=============================================================================
+/*!
+ *
+ */
+//=============================================================================
+
+CORBA::LongLong SMESH_Mesh_i::GetMeshPtr()
+{
+ 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)
+{
+ 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)
+{
+ 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();
+ TColStd_SequenceOfInteger IDs;
+ while(eIt->more()) {
+ const SMDS_MeshElement* elem = eIt->next();
+ IDs.Append(elem->GetID());
+ }
+ if(IDs.Length()>0) {
+ aResult->length(IDs.Length());
+ int i = 1;
+ for(; i<=IDs.Length(); i++) {
+ aResult[i-1] = IDs.Value(i);
+ }
+ }
+ return aResult._retn();
+}
+
+//=============================================================================
+/*!
+ * \brief Return position of a node on shape
+ */
+//=============================================================================
+
+SMESH::NodePosition* SMESH_Mesh_i::GetNodePosition(CORBA::Long NodeID)
+{
+ 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;
+}
+
+//=============================================================================
+/*!
+ * 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)
+{
+ 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)
+{
+ 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::SMESH_MeshEditor_var aMeshEditor = SMESH_Mesh_i::GetMeshEditor();
+ ::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)
+{
+ 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)
+{
+ 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)
+{
+ 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)
+{
+ 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)
+{
+ 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)
+{
+ 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)
+{
+ 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->NbFaces();
+}
+
+//=======================================================================
+//function : GetElemFaceNodes
+//purpose : Returns nodes of given face (counted from zero) for given element.
+//=======================================================================
+
+SMESH::long_array* SMESH_Mesh_i::GetElemFaceNodes(CORBA::Long elemId,
+ CORBA::Short faceIndex)
+{
+ SMESH::long_array_var aResult = new SMESH::long_array();
+ if ( SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS() )
+ {
+ if ( const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(elemId) )
+ {
+ SMDS_VolumeTool vtool( elem );
+ if ( faceIndex < vtool.NbFaces() )
+ {
+ aResult->length( vtool.NbFaceNodes( faceIndex ));
+ const SMDS_MeshNode** nn = vtool.GetFaceNodes( faceIndex );
+ for ( int i = 0; i < aResult->length(); ++i )
+ aResult[ i ] = nn[ i ]->GetID();
+ }
+ }
+ }
+ return aResult._retn();
+}
+
+//=======================================================================
+//function : FindElementByNodes
+//purpose : Returns an element based on all given nodes.
+//=======================================================================
+
+CORBA::Long SMESH_Mesh_i::FindElementByNodes(const SMESH::long_array& nodes)
+{
+ CORBA::Long elemID(0);
+ if ( SMESHDS_Mesh* mesh = _impl->GetMeshDS() )
+ {
+ vector< const SMDS_MeshNode * > nn( nodes.length() );
+ for ( int i = 0; i < nodes.length(); ++i )
+ if ( !( nn[i] = mesh->FindNode( nodes[i] )))
+ return elemID;
+
+ const SMDS_MeshElement* elem = mesh->FindElement( nn );
+ if ( !elem && ( _impl->NbEdges( ORDER_QUADRATIC ) ||
+ _impl->NbFaces( ORDER_QUADRATIC ) ||
+ _impl->NbVolumes( ORDER_QUADRATIC )))
+ elem = mesh->FindElement( nn, SMDSAbs_All, /*noMedium=*/true );
+
+ if ( elem ) elemID = CORBA::Long( elem->GetID() );
+ }
+ return elemID;
+}
+
+//=============================================================================
+/*!
+ * Returns true if given element is polygon
+ */
+//=============================================================================
+
+CORBA::Boolean SMESH_Mesh_i::IsPoly(const CORBA::Long id)
+{
+ SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
+ if ( aSMESHDS_Mesh == NULL ) return false;
+ const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
+ if(!elem) return false;
+ return elem->IsPoly();
+}
+
+
+//=============================================================================
+/*!
+ * Returns true if given element is quadratic