-// Copyright (C) 2007-2010 CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2011 CEA/DEN, EDF R&D, OPEN CASCADE
//
-// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
-// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either
-// version 2.1 of the License.
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License.
//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
-// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
//
-// SMESH SMESH_I : idl implementation based on 'SMESH' unit's calsses
// File : SMESH_Gen_i.cxx
// Author : Paul RASCLE, EDF
// Module : SMESH
#include "DriverMED_W_SMESHDS_Mesh.h"
#include "DriverMED_R_SMESHDS_Mesh.h"
+#ifdef WITH_CGNS
+#include "DriverCGNS_Read.hxx"
+#endif
#include "SALOMEDS_Tool.hxx"
#include "SALOME_NamingService.hxx"
SMESH_Gen_i::~SMESH_Gen_i()
{
- INFOS( "SMESH_Gen_i::~SMESH_Gen_i" );
+ MESSAGE( "SMESH_Gen_i::~SMESH_Gen_i" );
// delete hypothesis creators
map<string, GenericHypothesisCreator_i*>::iterator itHyp;
}
}
- // let the temporary hypothesis find out some how parameter values by mesh
+ // let the temporary hypothesis find out somehow parameter values by mesh
if ( hyp->SetParametersByMesh( mesh, shape ))
return SMESH::SMESH_Hypothesis::_duplicate( tmpHyp );
}
::SMESH_Hypothesis::TDefaults dflts;
dflts._elemLength = diagonal / myGen.GetBoundaryBoxSegmentation();
dflts._nbSegments = myGen.GetDefaultNbSegments();
+ dflts._shape = &shape;
// let the temporary hypothesis initialize it's values
if ( hyp->SetParametersByDefaults( dflts, mesh ))
return SMESH::SMESH_Hypothesis::_duplicate( tmpHyp );
return aMesh._retn();
}
+//================================================================================
+/*!
+ * \brief Create meshes and import data from the CGSN file
+ */
+//================================================================================
+
+SMESH::mesh_array* SMESH_Gen_i::CreateMeshesFromCGNS( const char* theFileName,
+ SMESH::DriverMED_ReadStatus& theStatus)
+ throw ( SALOME::SALOME_Exception )
+{
+ Unexpect aCatch(SALOME_SalomeException);
+
+ SMESH::mesh_array_var aResult = new SMESH::mesh_array();
+
+#ifdef WITH_CGNS
+ // Retrieve nb meshes from the file
+ DriverCGNS_Read myReader;
+ myReader.SetFile( theFileName );
+ Driver_Mesh::Status aStatus;
+ int nbMeshes = myReader.GetNbMeshes(aStatus);
+ theStatus = (SMESH::DriverMED_ReadStatus)aStatus;
+
+ aResult->length( nbMeshes );
+
+ { // open a new scope to make aPythonDump die before PythonDump in SMESH_Mesh::GetGroups()
+
+ // Python Dump
+ TPythonDump aPythonDump;
+ aPythonDump << "([";
+
+ if (theStatus == SMESH::DRS_OK)
+ {
+ SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
+ aStudyBuilder->NewCommand(); // There is a transaction
+
+ int i = 0;
+
+ // Iterate through all meshes and create mesh objects
+ for ( ; i < nbMeshes; ++i )
+ {
+ // Python Dump
+ if (i > 0) aPythonDump << ", ";
+
+ // create mesh
+ SMESH::SMESH_Mesh_var mesh = createMesh();
+ aResult[i] = SMESH::SMESH_Mesh::_duplicate( mesh );
+
+ // Read mesh data (groups are published automatically by ImportMEDFile())
+ SMESH_Mesh_i* meshServant = dynamic_cast<SMESH_Mesh_i*>( GetServant( mesh ).in() );
+ ASSERT( meshServant );
+ string meshName;
+ SMESH::DriverMED_ReadStatus status1 =
+ meshServant->ImportCGNSFile( theFileName, i, meshName );
+ if (status1 > theStatus)
+ theStatus = status1;
+
+ meshServant->GetImpl().GetMeshDS()->Modified();
+ // publish mesh in the study
+ SALOMEDS::SObject_var aSO;
+ if ( CanPublishInStudy( mesh ) )
+ aSO = PublishMesh( myCurrentStudy, mesh.in(), meshName.c_str() );
+
+ // Python Dump
+ if ( !aSO->_is_nil() )
+ aPythonDump << aSO;
+ else
+ aPythonDump << "mesh_" << i;
+ }
+ aStudyBuilder->CommitCommand();
+ }
+
+ aPythonDump << "], status) = " << this << ".CreateMeshesFromCGNS(r'" << theFileName << "')";
+ }
+ // Dump creation of groups
+ for ( int i = 0; i < aResult->length(); ++i )
+ SMESH::ListOfGroups_var groups = aResult[ i ]->GetGroups();
+#else
+ THROW_SALOME_CORBA_EXCEPTION("CGNS library is unavailable", SALOME::INTERNAL_ERROR);
+#endif
+
+ return aResult._retn();
+}
+
//=============================================================================
/*!
* SMESH_Gen_i::IsReadyToCompute
myLocShape = SMESH_Mesh::PseudoShape();
// call implementation compute
::SMESH_Mesh& myLocMesh = meshServant->GetImpl();
+#ifdef WITH_SMESH_CANCEL_COMPUTE
+ myGen.PrepareCompute( myLocMesh, myLocShape);
+#endif
bool ok = myGen.Compute( myLocMesh, myLocShape);
meshServant->CreateGroupServants(); // algos can create groups (issue 0020918)
myLocMesh.GetMeshDS()->Modified();
return false;
}
+//=============================================================================
+/*!
+ * SMESH_Gen_i::CancelCompute
+ *
+ * Cancel Compute mesh on a shape
+ */
+//=============================================================================
+
+void SMESH_Gen_i::CancelCompute( SMESH::SMESH_Mesh_ptr theMesh,
+ GEOM::GEOM_Object_ptr theShapeObject )
+{
+#ifdef WITH_SMESH_CANCEL_COMPUTE
+ SMESH_Mesh_i* meshServant = dynamic_cast<SMESH_Mesh_i*>( GetServant( theMesh ).in() );
+ ::SMESH_Mesh& myLocMesh = meshServant->GetImpl();
+ TopoDS_Shape myLocShape;
+ if(theMesh->HasShapeToMesh())
+ myLocShape = GeomObjectToShape( theShapeObject );
+ else
+ myLocShape = SMESH_Mesh::PseudoShape();
+ myGen.CancelCompute( myLocMesh, myLocShape);
+#endif
+}
+
//=============================================================================
/*!
* SMESH_Gen_i::Precompute
SMESH_subMesh* sm = anIt->first;
SMESH_ComputeErrorPtr& error = sm->GetComputeError();
const SMESH_Algo* algo = myGen.GetAlgo( myLocMesh, sm->GetSubShape());
- if ( algo && !error.get() || error->IsOK() )
+ if ( (algo && !error.get()) || error->IsOK() )
error.reset( new SMESH_ComputeError( COMPERR_ALGO_FAILED,"Failed to evaluate",algo));
}
else
if ( elem->GetType() != SMDSAbs_Node )
{
int ID = toKeepIDs ? elem->GetID() : 0;
- const SMDS_MeshElement * newElem = editor.AddElement( nodes,
- elem->GetType(),
- elem->IsPoly(),
- ID);
+ const SMDS_MeshElement * newElem;
+ if ( elem->GetEntityType() == SMDSEntity_Polyhedra )
+ newElem = editor.GetMeshDS()->
+ AddPolyhedralVolumeWithID( nodes,
+ static_cast<const SMDS_VtkVolume*>(elem)->GetQuantities(),
+ elem->GetID());
+ else
+ newElem = editor.AddElement( nodes,elem->GetType(),elem->IsPoly(),ID);
+
if ( toCopyGroups && !toKeepIDs )
e2eMapByType[ elem->GetType() ].insert( make_pair( elem, newElem ));
}
}
}
+ newMeshDS->Modified();
+
*pyDump << newMesh << " = " << this
<< ".CopyMesh( " << meshPart << ", "
<< "'" << meshName << "', "
if ( !CORBA::is_nil( anObject ) ) {
SMESH::SMESH_Mesh_var myMesh = SMESH::SMESH_Mesh::_narrow( anObject ) ;
if ( !myMesh->_is_nil() ) {
+ TPythonDump pd; // not to dump GetGroups()
SMESH::ListOfGroups_var groups = myMesh->GetGroups();
+ pd << ""; // to avoid optimizing pd out
for ( int i = 0; i < groups->length(); ++i )
{
SMESH_GroupBase_i* grImpl = SMESH::DownCast<SMESH_GroupBase_i*>( groups[i]);
// groups root sub-branch
SALOMEDS::SObject_var myGroupsBranch;
- for ( int i = GetNodeGroupsTag(); i <= GetVolumeGroupsTag(); i++ ) {
+ for ( int i = GetNodeGroupsTag(); i <= Get0DElementsGroupsTag(); i++ ) {
found = gotBranch->FindSubObject( i, myGroupsBranch );
if ( found ) {
char name_group[ 30 ];
strcpy( name_group, "Groups of Faces" );
else if ( i == GetVolumeGroupsTag() )
strcpy( name_group, "Groups of Volumes" );
+ else if ( i == Get0DElementsGroupsTag() )
+ strcpy( name_group, "Groups of 0D Elements" );
aGroup = new HDFgroup( name_group, aTopGroup );
aGroup->CreateOnDisk();
myWriter.AddGroup( aGeomGrp );
}
}
+ else if ( SMESH_GroupOnFilter_i* aFilterGrp_i =
+ dynamic_cast<SMESH_GroupOnFilter_i*>( myGroupImpl ))
+ {
+ std::string str = aFilterGrp_i->FilterToString();
+ std::string hdfGrpName = "Filter " + SMESH_Comment(anId);
+ aSize[ 0 ] = str.length() + 1;
+ aDataset = new HDFdataset( hdfGrpName.c_str(), aGroup, HDF_STRING, aSize, 1);
+ aDataset->CreateOnDisk();
+ aDataset->WriteOnDisk( ( char* )( str.c_str() ) );
+ aDataset->CloseOnDisk();
+ }
}
}
aGroup->CloseOnDisk();
delete[] smIDs;
}
+ aGroup->CloseOnDisk();
+
// Store node positions on sub-shapes (SMDS_Position):
// ----------------------------------------------------
int size = aStreamFile.in().length();
_CORBA_Octet* buffer = new _CORBA_Octet[size*3+1];
for ( int i = 0; i < size; i++ )
- sprintf( (char*)&(buffer[i*3]), "|%02x", (char*)(aStreamFile[i]) );
+ sprintf( (char*)&(buffer[i*3]), "|%02x", aStreamFile[i] );
buffer[size * 3] = '\0';
int* anAutoColor = new int[ size ];
aDataset->ReadFromDisk( anAutoColor );
aDataset->CloseOnDisk();
- myNewMeshImpl->SetAutoColor( (bool)anAutoColor[0] );
+ myNewMeshImpl->GetImpl().SetAutoColor( (bool)anAutoColor[0] );
}
// try to read and set reference to shape
}
}
- // try to get applied algorithms
+ // Try to get applied ALGORITHMS (mesh is not cleared by algo addition because
+ // nodes and elements are not yet put into sub-meshes)
if ( aTopGroup->ExistInternalObject( "Applied Algorithms" ) ) {
aGroup = new HDFgroup( "Applied Algorithms", aTopGroup );
aGroup->OpenOnDisk();
if ( aSubMesh->_is_nil() )
continue;
- // VSR: Get submesh data from MED convertor
- // int anInternalSubmeshId = aSubMesh->GetId(); // this is not a persistent ID, it's an internal one computed from sub-shape
- // if (myNewMeshImpl->_mapSubMesh.find(anInternalSubmeshId) != myNewMeshImpl->_mapSubMesh.end()) {
- // if(MYDEBUG) MESSAGE("VSR - SMESH_Gen_i::Load(): loading from MED file submesh with ID = " <<
- // subid << " for subshape # " << anInternalSubmeshId);
- // SMESHDS_SubMesh* aSubMeshDS =
- // myNewMeshImpl->_mapSubMesh[anInternalSubmeshId]->CreateSubMeshDS();
- // if ( !aSubMeshDS ) {
- // if(MYDEBUG) MESSAGE("VSR - SMESH_Gen_i::Load(): FAILED to create a submesh for subshape # " <<
- // anInternalSubmeshId << " in current mesh!");
- // }
- // else
- // myReader.GetSubMesh( aSubMeshDS, subid );
- // }
-
// try to get applied algorithms
if ( aSubGroup->ExistInternalObject( "Applied Algorithms" ) ) {
// open "applied algorithms" HDF group
aDataset->ReadFromDisk( refFromFile );
aDataset->CloseOnDisk();
- //SALOMEDS::SObject_var hypSO = myCurrentStudy->FindObjectID( refFromFile );
- //CORBA::Object_var hypObject = SObjectToObject( hypSO );
int id = atoi( refFromFile );
string anIOR = myStudyContext->getIORbyOldId( id );
if ( !anIOR.empty() ) {
aDataset->ReadFromDisk( refFromFile );
aDataset->CloseOnDisk();
- //SALOMEDS::SObject_var hypSO = myCurrentStudy->FindObjectID( refFromFile );
- //CORBA::Object_var hypObject = SObjectToObject( hypSO );
int id = atoi( refFromFile );
string anIOR = myStudyContext->getIORbyOldId( id );
if ( !anIOR.empty() ) {
if(hasData) {
- // Read sub-meshes from MED
- // -------------------------
+ // Read sub-meshes
+ // ----------------
if(MYDEBUG) MESSAGE("Create all sub-meshes");
bool submeshesInFamilies = ( ! aTopGroup->ExistInternalObject( "Submeshes" ));
- if ( submeshesInFamilies )
+ if ( submeshesInFamilies ) // from MED
{
// old way working before fix of PAL 12992
myReader.CreateAllSubMeshes();
} // if ( hasData )
// try to get groups
- for ( int ii = GetNodeGroupsTag(); ii <= GetVolumeGroupsTag(); ii++ ) {
+ for ( int ii = GetNodeGroupsTag(); ii <= Get0DElementsGroupsTag(); ii++ ) {
char name_group[ 30 ];
if ( ii == GetNodeGroupsTag() )
strcpy( name_group, "Groups of Nodes" );
strcpy( name_group, "Groups of Faces" );
else if ( ii == GetVolumeGroupsTag() )
strcpy( name_group, "Groups of Volumes" );
+ else if ( ii == Get0DElementsGroupsTag() )
+ strcpy( name_group, "Groups of 0D Elements" );
if ( aTopGroup->ExistInternalObject( name_group ) ) {
aGroup = new HDFgroup( name_group, aTopGroup );
}
}
}
+ // Try to read a filter of SMESH_GroupOnFilter
+ SMESH::Filter_var filter;
+ SMESH_PredicatePtr predicate;
+ std::string hdfGrpName = "Filter " + SMESH_Comment(subid);
+ if ( aGroup->ExistInternalObject( hdfGrpName.c_str() ))
+ {
+ aDataset = new HDFdataset( hdfGrpName.c_str(), aGroup );
+ aDataset->OpenOnDisk();
+ size = aDataset->GetSize();
+ char* persistStr = new char[ size ];
+ aDataset->ReadFromDisk( persistStr );
+ aDataset->CloseOnDisk();
+ if ( strlen( persistStr ) > 0 ) {
+ filter = SMESH_GroupOnFilter_i::StringToFilter( persistStr );
+ predicate = SMESH_GroupOnFilter_i::GetPredicate( filter );
+ }
+ }
+
// Create group servant
SMESH::ElementType type = (SMESH::ElementType)(ii - GetNodeGroupsTag() + 1);
SMESH::SMESH_GroupBase_var aNewGroup = SMESH::SMESH_GroupBase::_duplicate
- ( myNewMeshImpl->createGroup( type, nameFromFile, aShape ) );
+ ( myNewMeshImpl->createGroup( type, nameFromFile, aShape, predicate ) );
// Obtain a SMESHDS_Group object
if ( aNewGroup->_is_nil() )
continue;
int newSubId = myStudyContext->findId( iorSubString );
myStudyContext->mapOldToNew( subid, newSubId );
- SMESH_GroupBase_i* aGroupImpl =
- dynamic_cast<SMESH_GroupBase_i*>( GetServant( aNewGroup ).in() );
+ SMESH_GroupBase_i* aGroupImpl = SMESH::DownCast< SMESH_GroupBase_i*>( aNewGroup );
if ( !aGroupImpl )
continue;
- SMESH_Group* aLocalGroup = myLocMesh.GetGroup( aGroupImpl->GetLocalID() );
- if ( !aLocalGroup )
+ if ( SMESH_GroupOnFilter_i* aFilterGroup =
+ dynamic_cast< SMESH_GroupOnFilter_i*>( aGroupImpl ))
+ aFilterGroup->SetFilter( filter );
+
+ SMESHDS_GroupBase* aGroupBaseDS = aGroupImpl->GetGroupDS();
+ if ( !aGroupBaseDS )
continue;
- SMESHDS_GroupBase* aGroupBaseDS = aLocalGroup->GetGroupDS();
aGroupBaseDS->SetStoreName( name_dataset );
// ouv : NPAL12872
}
} // loop on meshes
+ // update hyps needing full mesh data restored (issue 20918)
+ for ( hyp_data = hypDataList.begin(); hyp_data != hypDataList.end(); ++hyp_data )
+ {
+ SMESH_Hypothesis_i* hyp = hyp_data->first;
+ hyp->UpdateAsMeshesRestored();
+ }
+
// notify algos on completed restoration
for ( meshi_group = meshGroupList.begin(); meshi_group != meshGroupList.end(); ++meshi_group )
{
ComputeStateEngine (SMESH_subMesh::SUBMESH_RESTORED);
}
- for ( hyp_data = hypDataList.begin(); hyp_data != hypDataList.end(); ++hyp_data )
- {
- SMESH_Hypothesis_i* hyp = hyp_data->first;
- hyp->UpdateAsMeshesRestored(); // for hyps needing full mesh data restored (issue 20918)
- }
-
// close mesh group
if(aTopGroup)
aTopGroup->CloseOnDisk();