// report any error, if occurred
#ifndef WIN32
const char* anError = dlerror();
- throw(SALOME_Exception(anError));
+ throw(SALOME_Exception( anError ));
#else
- throw(SALOME_Exception(LOCALIZED( "Can't load server meshers plugin library" )));
+ throw(SALOME_Exception ( SMESH_Comment("Can't load meshers plugin library " )
+ << aPlatformLibName));
#endif
}
(GetHypothesisCreator)GetProc( libHandle, "GetHypothesisCreator" );
if (!procHandle)
{
- throw(SALOME_Exception(LOCALIZED("bad hypothesis plugin library")));
+ throw(SALOME_Exception(SMESH_Comment("bad hypothesis plugin library")
+ << aPlatformLibName ));
UnLoadLib(libHandle);
}
aCreator = procHandle(theHypName);
if (!aCreator)
{
- throw(SALOME_Exception(LOCALIZED("no such a hypothesis in this plugin")));
+ throw(SALOME_Exception( SMESH_Comment( theHypName ) << " is missing from "
+ << aPlatformLibName));
}
// map hypothesis creator to a hypothesis name
myHypCreatorMap[string(theHypName)] = aCreator;
/*!
* SMESH_Gen_i::CreateHypothesis
*
- * Create hypothesis/algorothm of given type and publish it in the study
+ * Create hypothesis/algorithm of given type and publish it in the study
*/
//=============================================================================
return hyp._retn();
}
+//================================================================================
+/*!
+ * \brief Return a hypothesis initialized by given average length.
+ * \param theHypType - hypothesis type name
+ * \param theLibName - plugin library name
+ * \param theAverageLength - average length
+ * \param theQuadDominated - is quad-dominated flag
+ * \retval SMESH::SMESH_Hypothesis_ptr - the new hypothesis
+ */
+//================================================================================
+
+SMESH::SMESH_Hypothesis_ptr
+SMESH_Gen_i::CreateHypothesisByAverageLength( const char* theHypType,
+ const char* theLibName,
+ CORBA::Double theAverageLength,
+ CORBA::Boolean theQuadDominated)
+ throw ( SALOME::SALOME_Exception )
+{
+ SMESH::HypInitParams initParams = { ::SMESH_Hypothesis::BY_AVERAGE_LENGTH,
+ theAverageLength, theQuadDominated };
+
+ SMESH::SMESH_Hypothesis_var hyp =
+ GetHypothesisParameterValues( theHypType, theLibName,
+ SMESH::SMESH_Mesh::_nil(),
+ GEOM::GEOM_Object::_nil(),
+ initParams );
+ SALOMEDS::SObject_wrap so = PublishHypothesis( hyp );
+
+ TPythonDump() << hyp << " = " << this << ".CreateHypothesisByAverageLength( '"
+ << theHypType << "', '"
+ << theLibName << "', "
+ << theAverageLength << ", "
+ << theQuadDominated << " )";
+
+ return hyp._retn();
+}
+
//================================================================================
/*!
* \brief Return a hypothesis holding parameter values corresponding either to the mesh
//================================================================================
SMESH::SMESH_Hypothesis_ptr
-SMESH_Gen_i::GetHypothesisParameterValues (const char* theHypType,
- const char* theLibName,
- SMESH::SMESH_Mesh_ptr theMesh,
- GEOM::GEOM_Object_ptr theGeom,
- CORBA::Boolean byMesh)
+SMESH_Gen_i::GetHypothesisParameterValues( const char* theHypType,
+ const char* theLibName,
+ SMESH::SMESH_Mesh_ptr theMesh,
+ GEOM::GEOM_Object_ptr theGeom,
+ const SMESH::HypInitParams& theParams)
throw ( SALOME::SALOME_Exception )
{
Unexpect aCatch(SALOME_SalomeException);
+
+ const bool byMesh = ( theParams.way == ::SMESH_Hypothesis::BY_MESH );
if ( byMesh && CORBA::is_nil( theMesh ) )
return SMESH::SMESH_Hypothesis::_nil();
if ( byMesh && CORBA::is_nil( theGeom ) )
if ( hyp->SetParametersByMesh( mesh, shape ))
return SMESH::SMESH_Hypothesis::_duplicate( tmpHyp );
}
- else {
- double diagonal = 0;
- if ( mesh )
- diagonal = mesh->GetShapeDiagonalSize();
- else
- diagonal = ::SMESH_Mesh::GetShapeDiagonalSize( shape );
+ else
+ {
::SMESH_Hypothesis::TDefaults dflts;
- dflts._elemLength = diagonal / myGen.GetBoundaryBoxSegmentation();
- dflts._nbSegments = myGen.GetDefaultNbSegments();
- dflts._shape = &shape;
- // let the temporary hypothesis initialize it's values
+ dflts._way = ( ::SMESH_Hypothesis::InitWay) theParams.way;
+ dflts._nbSegments = myGen.GetDefaultNbSegments();
+ dflts._elemLength = theParams.averageLength;
+ dflts._quadDominated = theParams.quadDominated;
+ if ( theParams.way == ::SMESH_Hypothesis::BY_GEOM )
+ {
+ if ( mesh )
+ dflts._diagonal = mesh->GetShapeDiagonalSize();
+ else
+ dflts._diagonal = ::SMESH_Mesh::GetShapeDiagonalSize( shape );
+ dflts._elemLength = dflts._diagonal / myGen.GetBoundaryBoxSegmentation();
+ dflts._shape = &shape;
+ }
+
+ // let the hypothesis initialize it's values
if ( hyp->SetParametersByDefaults( dflts, mesh ))
return SMESH::SMESH_Hypothesis::_duplicate( tmpHyp );
}
continue;
initImpl->Load();
- // assure that IDs increments by one during iteration
+ // assure that IDs increment by one during iteration
::SMESH_Mesh& initLocMesh = initImpl->GetImpl();
SMESHDS_Mesh* initMeshDS = initLocMesh.GetMeshDS();
if ( initMeshDS->MaxNodeID() > initMeshDS->NbNodes() ||
// copy elements
+ SMESH::array_of_ElementType_var srcElemTypes = theMeshesArray[i]->GetTypes();
+ if ( srcElemTypes->length() == 1 && srcElemTypes[0] == SMESH::NODE ) // group of nodes
+ continue;
std::vector< const SMDS_MeshElement* > newElems( initMeshDS->NbElements() + 1, 0 );
elemIt = initImpl->GetElements( theMeshesArray[i], SMESH::ALL );
while ( elemIt->more() )
{
typedef std::map< std::string, std::string > TStr2StrMap;
typedef std::map< std::string, std::set< std::string > > TStr2StrSetMap;
- //typedef std::map< std::set<int>, int > TIdSet2IndexMap;
+ typedef std::map< std::set<int>, int > TIdSet2IndexMap;
+ typedef std::map< std::string, int > TName2IndexMap;
//================================================================================
/*!
TStr2StrMap myOld2NewEntryMap; // map of study entries
- //GEOM::ListOfGO_var mySubshapes; // sub-shapes existing in the new geometry
- //TIdSet2IndexMap myIds2SubshapeIndex; // to find an existing sub-shape
+ GEOM::ListOfGO_var mySubshapes; // sub-shapes existing in the new geometry
+ TIdSet2IndexMap myIds2SubshapeIndex; // to find an existing sub-shape
+ TName2IndexMap myName2SubshapeIndex; // to find an existing sub-shape by name
bool myGIPMapDone;
GEOM::ListOfListOfLong_var myGIPMap; // filled by GetInPlaceMap()
CORBA::String_var newEntry = newSO->GetID();
myOld2NewEntryMap.insert( std::make_pair( std::string( oldEntry.in() ),
std::string( newEntry.in() )));
+ std::string newMainEntry = newEntry.in();
SALOMEDS::Study_var study = myGen_i->getStudyServant();
GEOM::GEOM_Gen_var geomGen = myGen_i->GetGeomEngine();
GEOM::GEOM_IShapesOperations_wrap op = geomGen->GetIShapesOperations();
- GEOM::ListOfGO_var subShapes = op->GetExistingSubObjects( mainShapeNew,
+ mySubshapes = op->GetExistingSubObjects( mainShapeNew,
/*groupsOnly=*/false );
- for ( CORBA::ULong i = 0; i < subShapes->length(); ++i )
+ for ( CORBA::ULong i = 0; i < mySubshapes->length(); ++i )
{
- newSO = myGen_i->ObjectToSObject( subShapes[ i ]);
+ newSO = myGen_i->ObjectToSObject( mySubshapes[ i ]);
SALOMEDS::ChildIterator_wrap anIter = study->NewChildIterator( newSO );
+ bool refFound = false;
for ( ; anIter->More(); anIter->Next() )
{
SALOMEDS::SObject_wrap so = anIter->Value();
{
oldEntry = oldSO->GetID();
newEntry = newSO->GetID();
- myOld2NewEntryMap.insert( std::make_pair( std::string( oldEntry.in() ),
- std::string( newEntry.in() )));
+ if (( refFound = ( newMainEntry != oldEntry.in() )))
+ myOld2NewEntryMap.insert( std::make_pair( std::string( oldEntry.in() ),
+ std::string( newEntry.in() )));
+ }
+ }
+ if ( !refFound )
+ {
+ GEOM::GEOM_Object_var father = mySubshapes[ i ]->GetMainShape();
+ if ( father->_is_equivalent( mainShapeNew ))
+ {
+ GEOM::ListOfLong_var ids = mySubshapes[ i ]->GetSubShapeIndices();
+ std::set< int > idSet( &ids[0] , &ids[0] + ids->length() );
+ myIds2SubshapeIndex.insert( std::make_pair( idSet, i ));
+ CORBA::String_var name = newSO->GetName();
+ if ( name.in()[0] )
+ myName2SubshapeIndex.insert( std::make_pair( name.in(), i ));
}
}
}
GEOM::GEOM_Object_var mainShapeNew = myNewMesh_i->GetShapeToMesh();
GEOM::GEOM_Gen_var geomGen = myGen_i->GetGeomEngine();
- // try to find by entry
+ // try to find by entry or name
if ( myToPublish )
{
CORBA::String_var oldEntry = oldShape->GetStudyEntry();
{
newShape = getShapeByEntry( o2nID->second );
}
+ if ( newShape->_is_nil() )
+ {
+ CORBA::String_var name = oldShape->GetName();
+ TName2IndexMap::iterator n2ind = myName2SubshapeIndex.find( name.in() );
+ if ( n2ind != myName2SubshapeIndex.end() )
+ {
+ newShape = GEOM::GEOM_Object::_duplicate( mySubshapes[ n2ind->second ]);
+ GEOM::ListOfLong_var oldIndices = oldShape->GetSubShapeIndices();
+ GEOM::ListOfLong_var newIndices = newShape->GetSubShapeIndices();
+ if ( oldIndices->length() == 0 ||
+ newIndices->length() == 0 ||
+ getShapeType( myNewMesh_i, newIndices[0] ) !=
+ getShapeType( mySrcMesh_i, oldIndices[0] ))
+ newShape = GEOM::GEOM_Object::_nil();
+ }
+ }
}
if ( newShape->_is_nil() )
{
findNewIDs( oldIndices[i], newIndices );
}
- if ( !newIndices.empty() )
+ if ( newIndices.size() < oldIndices->length() ) // issue #17096
{
- try
- {
- if ( newIndices.size() > 1 || oldShape->GetType() == GEOM_GROUP )
+ newIndices.clear();
+ newShape = getInPlace( oldShape );
+ }
+ if ( !newIndices.empty() && newShape->_is_nil() )
+ {
+ // search for a sub-shape with same ids
+ std::set< int > idSet( newIndices.begin(), newIndices.end() );
+ TIdSet2IndexMap::iterator ids2ind = myIds2SubshapeIndex.find( idSet );
+ if ( ids2ind != myIds2SubshapeIndex.end() ) {
+ newShape = GEOM::GEOM_Object::_duplicate( mySubshapes[ ids2ind->second ]);
+ }
+ if ( newShape->_is_nil() )
+ try
{
- int groupType = getShapeType( myNewMesh_i, newIndices[0] );
+ // create a new shape
+ if ( newIndices.size() > 1 || oldShape->GetType() == GEOM_GROUP )
+ {
+ int groupType = getShapeType( myNewMesh_i, newIndices[0] );
- GEOM::GEOM_IGroupOperations_wrap grOp = geomGen->GetIGroupOperations();
- newShape = grOp->CreateGroup( mainShapeNew, groupType );
+ GEOM::GEOM_IGroupOperations_wrap grOp = geomGen->GetIGroupOperations();
+ newShape = grOp->CreateGroup( mainShapeNew, groupType );
- GEOM::ListOfLong_var newIndicesList = new GEOM::ListOfLong();
- newIndicesList->length( newIndices.size() );
- for ( size_t i = 0; i < newIndices.size(); ++i )
- newIndicesList[ i ] = newIndices[ i ];
- grOp->UnionIDs( newShape, newIndicesList );
+ GEOM::ListOfLong_var newIndicesList = new GEOM::ListOfLong();
+ newIndicesList->length( newIndices.size() );
+ for ( size_t i = 0; i < newIndices.size(); ++i )
+ newIndicesList[ i ] = newIndices[ i ];
+ grOp->UnionIDs( newShape, newIndicesList );
+ }
+ else
+ {
+ GEOM::GEOM_IShapesOperations_wrap shOp = geomGen->GetIShapesOperations();
+ newShape = shOp->GetSubShape( mainShapeNew, newIndices[0] );
+ }
}
- else
+ catch (...)
{
- GEOM::GEOM_IShapesOperations_wrap shOp = geomGen->GetIShapesOperations();
- newShape = shOp->GetSubShape( mainShapeNew, newIndices[0] );
}
- }
- catch (...)
- {
- }
}
}
}
}
+ //================================================================================
+ /*!
+ * \brief Get new sub-shape by calling GetInPlace()
+ */
+ GEOM::GEOM_Object_ptr getInPlace( GEOM::GEOM_Object_ptr oldShape )
+ {
+ GEOM::GEOM_Object_var newShape;
+
+ GEOM::GEOM_Object_var mainShapeNew = myNewMesh_i->GetShapeToMesh();
+ GEOM::GEOM_Gen_var geomGen = myGen_i->GetGeomEngine();
+ GEOM::GEOM_IShapesOperations_wrap op = geomGen->GetIShapesOperations();
+ try
+ {
+ newShape = op->GetInPlace( mainShapeNew, oldShape );
+ }
+ catch( ... )
+ {
+ }
+ return newShape._retn();
+ }
+
//================================================================================
/*!
* \brief Find a new sub-shape indices by an old one in myGIPMap. Return
const char* theURL,
bool isMultiFile )
{
+ // localizing
+ Kernel_Utils::Localizer loc;
+
if (!myStudyContext)
UpdateStudy();
const char* theURL,
bool isMultiFile )
{
+ // localizing
+ Kernel_Utils::Localizer loc;
+
//if (!myStudyContext)
UpdateStudy();
SALOMEDS::Study_var aStudy = getStudyServant();
try { // protect persistence mechanism against exceptions
myHyp = this->createHypothesis( hypname.c_str(), libname.c_str() );
}
+ catch( SALOME::SALOME_Exception& ex )
+ {
+ INFOS( "Exception during hypothesis creation: " << ex.details.text );
+ }
catch (...) {
INFOS( "Exception during hypothesis creation" );
}
if (aCreator)
{
TopoDS_Shape shape = GeomObjectToShape( theGeomObject );
- return shape.IsNull() || aCreator->IsApplicable( shape, toCheckAll );
+ const SMESH_Algo::Features& feat = SMESH_Algo::GetFeatures( theAlgoType );
+ return shape.IsNull() || aCreator->IsApplicable( shape, toCheckAll, feat._dim );
}
else
{