+SMESH::DriverMED_ReadStatus
+SMESH_Mesh_i::ImportMEDFile( const char* theFileName, const char* theMeshName )
+ throw ( SALOME::SALOME_Exception )
+{
+ Unexpect aCatch(SALOME_SalomeException);
+ int status;
+ try {
+ status = importMEDFile( theFileName, theMeshName );
+ }
+ catch( SALOME_Exception& S_ex ) {
+ THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
+ }
+ catch ( ... ) {
+ THROW_SALOME_CORBA_EXCEPTION("ImportMEDFile(): unknown exception", SALOME::BAD_PARAM);
+ }
+
+ SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
+ if ( !aStudy->_is_nil() ) {
+ // publishing of the groups in the study (sub-meshes are out of scope of MED import)
+ map<int, SMESH::SMESH_GroupBase_ptr>::iterator it = _mapGroups.begin();
+ for (; it != _mapGroups.end(); it++ ) {
+ SMESH::SMESH_GroupBase_var aGroup = SMESH::SMESH_GroupBase::_duplicate( it->second );
+ _gen_i->PublishGroup( aStudy, _this(), aGroup,
+ GEOM::GEOM_Object::_nil(), aGroup->GetName());
+ }
+ }
+ return ConvertDriverMEDReadStatus(status);
+}
+
+//=============================================================================
+/*!
+ * ImportUNVFile
+ *
+ * Imports mesh data from MED file
+ */
+//=============================================================================
+
+int SMESH_Mesh_i::ImportUNVFile( const char* theFileName )
+ throw ( SALOME::SALOME_Exception )
+{
+ // Read mesh with name = <theMeshName> into SMESH_Mesh
+ _impl->UNVToMesh( theFileName );
+
+ return 1;
+}
+
+//=============================================================================
+/*!
+ * ImportSTLFile
+ *
+ * Imports mesh data from STL file
+ */
+//=============================================================================
+int SMESH_Mesh_i::ImportSTLFile( const char* theFileName )
+ throw ( SALOME::SALOME_Exception )
+{
+ // Read mesh with name = <theMeshName> into SMESH_Mesh
+ _impl->STLToMesh( theFileName );
+
+ return 1;
+}
+
+//=============================================================================
+/*!
+ * importMEDFile
+ *
+ * Imports mesh data from MED file
+ */
+//=============================================================================
+
+int SMESH_Mesh_i::importMEDFile( const char* theFileName, const char* theMeshName )
+{
+ // Read mesh with name = <theMeshName> and all its groups into SMESH_Mesh
+ int status = _impl->MEDToMesh( theFileName, theMeshName );
+
+ // Create group servants, if any groups were imported
+ list<int> aGroupIds = _impl->GetGroupIds();
+ for ( list<int>::iterator it = aGroupIds.begin(); it != aGroupIds.end(); it++ ) {
+ SMESH_Group_i* aGroupImpl = new SMESH_Group_i( SMESH_Gen_i::GetPOA(), this, *it );
+
+ // PAL7962: san -- To ensure correct mapping of servant and correct reference counting in GenericObj_i
+ SMESH_Gen_i::GetPOA()->activate_object( aGroupImpl );
+ aGroupImpl->Register();
+ // PAL7962: san -- To ensure correct mapping of servant and correct reference counting in GenericObj_i
+
+ SMESH::SMESH_Group_var aGroup = SMESH::SMESH_Group::_narrow( aGroupImpl->_this() );
+ _mapGroups[*it] = SMESH::SMESH_Group::_duplicate( aGroup );
+
+ // register CORBA object for persistence
+ int nextId = _gen_i->RegisterObject( aGroup );
+ if(MYDEBUG) MESSAGE( "Add group to map with id = "<< nextId);
+ }
+
+ return status;
+}
+
+//=============================================================================
+/*!
+ *
+ */
+//=============================================================================
+
+static SMESH::Hypothesis_Status ConvertHypothesisStatus
+ (SMESH_Hypothesis::Hypothesis_Status theStatus)
+{
+ SMESH::Hypothesis_Status res;
+ switch (theStatus)
+ {
+ case SMESH_Hypothesis::HYP_OK:
+ res = SMESH::HYP_OK; break;
+ case SMESH_Hypothesis::HYP_MISSING:
+ res = SMESH::HYP_MISSING; break;
+ case SMESH_Hypothesis::HYP_CONCURENT:
+ res = SMESH::HYP_CONCURENT; break;
+ case SMESH_Hypothesis::HYP_BAD_PARAMETER:
+ res = SMESH::HYP_BAD_PARAMETER; break;
+ case SMESH_Hypothesis::HYP_INCOMPATIBLE:
+ res = SMESH::HYP_INCOMPATIBLE; break;
+ case SMESH_Hypothesis::HYP_NOTCONFORM:
+ res = SMESH::HYP_NOTCONFORM; break;
+ case SMESH_Hypothesis::HYP_ALREADY_EXIST:
+ res = SMESH::HYP_ALREADY_EXIST; break;
+ case SMESH_Hypothesis::HYP_BAD_DIM:
+ res = SMESH::HYP_BAD_DIM; break;
+ default:
+ res = SMESH::HYP_UNKNOWN_FATAL;
+ }
+ return res;
+}
+
+//=============================================================================
+/*!
+ * AddHypothesis
+ *
+ * calls internal addHypothesis() and then adds a reference to <anHyp> under
+ * the SObject actually having a reference to <aSubShape>.
+ * NB: For this method to work, it is necessary to add a reference to sub-shape first.
+ */
+//=============================================================================
+
+SMESH::Hypothesis_Status SMESH_Mesh_i::AddHypothesis(GEOM::GEOM_Object_ptr aSubShapeObject,
+ SMESH::SMESH_Hypothesis_ptr anHyp)
+ throw(SALOME::SALOME_Exception)
+{
+ Unexpect aCatch(SALOME_SalomeException);
+ SMESH_Hypothesis::Hypothesis_Status status = addHypothesis( aSubShapeObject, anHyp );
+
+ if ( !SMESH_Hypothesis::IsStatusFatal(status) )
+ _gen_i->AddHypothesisToShape(_gen_i->GetCurrentStudy(), _this(),
+ aSubShapeObject, anHyp );
+
+ if(MYDEBUG) MESSAGE( " AddHypothesis(): status = " << status );
+
+ // Update Python script
+ TCollection_AsciiString aStr ("status = ");
+ SMESH_Gen_i::AddObject(aStr, _this()) += ".AddHypothesis(";
+ SMESH_Gen_i::AddObject(aStr, aSubShapeObject) += ", ";
+ SMESH_Gen_i::AddObject(aStr, anHyp) += ")";
+
+ SMESH_Gen_i::AddToCurrentPyScript(aStr);
+
+ return ConvertHypothesisStatus(status);
+}
+
+//=============================================================================
+/*!
+ *
+ */
+//=============================================================================
+
+SMESH_Hypothesis::Hypothesis_Status
+ SMESH_Mesh_i::addHypothesis(GEOM::GEOM_Object_ptr aSubShapeObject,
+ SMESH::SMESH_Hypothesis_ptr anHyp)
+{
+ if(MYDEBUG) MESSAGE("addHypothesis");
+
+ if (CORBA::is_nil(aSubShapeObject))
+ THROW_SALOME_CORBA_EXCEPTION("bad subShape reference",
+ SALOME::BAD_PARAM);
+
+ SMESH::SMESH_Hypothesis_var myHyp = SMESH::SMESH_Hypothesis::_narrow(anHyp);
+ if (CORBA::is_nil(myHyp))
+ THROW_SALOME_CORBA_EXCEPTION("bad hypothesis reference",
+ SALOME::BAD_PARAM);
+
+ SMESH_Hypothesis::Hypothesis_Status status = SMESH_Hypothesis::HYP_OK;
+ try
+ {
+ TopoDS_Shape myLocSubShape = _gen_i->GeomObjectToShape( aSubShapeObject);
+ int hypId = myHyp->GetId();
+ status = _impl->AddHypothesis(myLocSubShape, hypId);
+ if ( !SMESH_Hypothesis::IsStatusFatal(status) ) {
+ _mapHypo[hypId] = myHyp;
+ // assure there is a corresponding submesh
+ if ( !_impl->IsMainShape( myLocSubShape )) {
+ int shapeId = _impl->GetMeshDS()->ShapeToIndex( myLocSubShape );
+ if ( _mapSubMesh_i.find( shapeId ) == _mapSubMesh_i.end() )
+ createSubMesh( aSubShapeObject );
+ }
+ }
+ }
+ catch(SALOME_Exception & S_ex)
+ {
+ THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
+ }
+ return status;
+}
+
+//=============================================================================
+/*!
+ *
+ */
+//=============================================================================
+
+SMESH::Hypothesis_Status SMESH_Mesh_i::RemoveHypothesis(GEOM::GEOM_Object_ptr aSubShapeObject,
+ SMESH::SMESH_Hypothesis_ptr anHyp)
+ throw(SALOME::SALOME_Exception)
+{
+ Unexpect aCatch(SALOME_SalomeException);
+ SMESH_Hypothesis::Hypothesis_Status status = removeHypothesis( aSubShapeObject, anHyp );
+
+ if ( !SMESH_Hypothesis::IsStatusFatal(status) )
+ _gen_i->RemoveHypothesisFromShape(_gen_i->GetCurrentStudy(), _this(),
+ aSubShapeObject, anHyp );
+
+ // Update Python script
+ TCollection_AsciiString aStr ("status = ");
+ SMESH_Gen_i::AddObject(aStr, _this()) += ".RemoveHypothesis(";
+ SMESH_Gen_i::AddObject(aStr, aSubShapeObject) += ", ";
+ SMESH_Gen_i::AddObject(aStr, anHyp) += ")";
+
+ SMESH_Gen_i::AddToCurrentPyScript(aStr);
+
+ return ConvertHypothesisStatus(status);
+}