+bool SMESH_Mesh::GetAutoColor() throw(SALOME_Exception)
+{
+ Unexpect aCatch(SalomeException);
+ return _isAutoColor;
+}
+
+//=======================================================================
+//function : SetIsModified
+//purpose : Set the flag meaning that the mesh has been edited "manually"
+//=======================================================================
+
+void SMESH_Mesh::SetIsModified(bool isModified)
+{
+ _isModified = isModified;
+
+ if ( _isModified )
+ // check if mesh becomes empty as result of modification
+ HasModificationsToDiscard();
+}
+
+//=======================================================================
+//function : HasModificationsToDiscard
+//purpose : Return true if the mesh has been edited since a total re-compute
+// and those modifications may prevent successful partial re-compute.
+// As a side effect reset _isModified flag if mesh is empty
+//issue : 0020693
+//=======================================================================
+
+bool SMESH_Mesh::HasModificationsToDiscard() const
+{
+ if ( ! _isModified )
+ return false;
+
+ // return true if the next Compute() will be partial and
+ // existing but changed elements may prevent successful re-compute
+ bool hasComputed = false, hasNotComputed = false;
+ map <int, SMESH_subMesh*>::const_iterator i_sm = _mapSubMesh.begin();
+ for ( ; i_sm != _mapSubMesh.end() ; ++i_sm )
+ switch ( i_sm->second->GetSubShape().ShapeType() )
+ {
+ case TopAbs_EDGE:
+ case TopAbs_FACE:
+ case TopAbs_SOLID:
+ if ( i_sm->second->IsMeshComputed() )
+ hasComputed = true;
+ else
+ hasNotComputed = true;
+ if ( hasComputed && hasNotComputed)
+ return true;
+ }
+
+ if ( !hasComputed )
+ const_cast<SMESH_Mesh*>(this)->_isModified = false;
+
+ return false;
+}
+
+//================================================================================
+/*!
+ * \brief Check if any groups of the same type have equal names
+ */
+//================================================================================
+
+bool SMESH_Mesh::HasDuplicatedGroupNamesMED()
+{
+ //set<string> aGroupNames; // Corrected for Mantis issue 0020028
+ map< SMDSAbs_ElementType, set<string> > aGroupNames;
+ for ( map<int, SMESH_Group*>::iterator it = _mapGroup.begin(); it != _mapGroup.end(); it++ )
+ {
+ SMESH_Group* aGroup = it->second;
+ SMDSAbs_ElementType aType = aGroup->GetGroupDS()->GetType();
+ string aGroupName = aGroup->GetName();
+ aGroupName.resize(MAX_MED_GROUP_NAME_LENGTH);
+ if (!aGroupNames[aType].insert(aGroupName).second)
+ return true;
+ }
+
+ return false;
+}
+
+//================================================================================
+/*!
+ * \brief Export the mesh to a med file
+ */
+//================================================================================
+
+void SMESH_Mesh::ExportMED(const char * file,
+ const char* theMeshName,
+ bool theAutoGroups,
+ int theVersion,
+ const SMESHDS_Mesh* meshPart)
+ throw(SALOME_Exception)
+{
+ Unexpect aCatch(SalomeException);
+
+ DriverMED_W_SMESHDS_Mesh myWriter;
+ myWriter.SetFile ( file, MED::EVersion(theVersion) );
+ myWriter.SetMesh ( meshPart ? (SMESHDS_Mesh*) meshPart : _myMeshDS );
+ if ( !theMeshName )
+ myWriter.SetMeshId ( _idDoc );
+ else {
+ myWriter.SetMeshId ( -1 );
+ myWriter.SetMeshName( theMeshName );
+ }
+
+ if ( theAutoGroups ) {
+ myWriter.AddGroupOfNodes();
+ myWriter.AddGroupOfEdges();
+ myWriter.AddGroupOfFaces();
+ myWriter.AddGroupOfVolumes();
+ }
+
+ // Pass groups to writer. Provide unique group names.
+ //set<string> aGroupNames; // Corrected for Mantis issue 0020028
+ if ( !meshPart )
+ {
+ map< SMDSAbs_ElementType, set<string> > aGroupNames;
+ char aString [256];
+ int maxNbIter = 10000; // to guarantee cycle finish
+ for ( map<int, SMESH_Group*>::iterator it = _mapGroup.begin(); it != _mapGroup.end(); it++ ) {
+ SMESH_Group* aGroup = it->second;
+ SMESHDS_GroupBase* aGroupDS = aGroup->GetGroupDS();
+ if ( aGroupDS ) {
+ SMDSAbs_ElementType aType = aGroupDS->GetType();
+ string aGroupName0 = aGroup->GetName();
+ aGroupName0.resize(MAX_MED_GROUP_NAME_LENGTH);
+ string aGroupName = aGroupName0;
+ for (int i = 1; !aGroupNames[aType].insert(aGroupName).second && i < maxNbIter; i++) {
+ sprintf(&aString[0], "GR_%d_%s", i, aGroupName0.c_str());
+ aGroupName = aString;
+ aGroupName.resize(MAX_MED_GROUP_NAME_LENGTH);
+ }
+ aGroupDS->SetStoreName( aGroupName.c_str() );
+ myWriter.AddGroup( aGroupDS );
+ }
+ }
+ }
+ // Perform export
+ myWriter.Perform();
+}
+
+//================================================================================
+/*!
+ * \brief Export the mesh to a DAT file
+ */
+//================================================================================
+
+void SMESH_Mesh::ExportDAT(const char * file,
+ const SMESHDS_Mesh* meshPart) throw(SALOME_Exception)
+{
+ Unexpect aCatch(SalomeException);
+ DriverDAT_W_SMDS_Mesh myWriter;
+ myWriter.SetFile( file );
+ myWriter.SetMesh( meshPart ? (SMESHDS_Mesh*) meshPart : _myMeshDS );
+ myWriter.SetMeshId(_idDoc);
+ myWriter.Perform();
+}
+
+//================================================================================
+/*!
+ * \brief Export the mesh to an UNV file
+ */
+//================================================================================
+
+void SMESH_Mesh::ExportUNV(const char * file,
+ const SMESHDS_Mesh* meshPart) throw(SALOME_Exception)