#include <qapplication.h>
-SMESHGUI_GenericHypothesisCreator::SMESHGUI_GenericHypothesisCreator( const QString& aHypType )
- : myHypType( aHypType ), myIsCreate( false ), myDlg( 0 )
+SMESHGUI_GenericHypothesisCreator::SMESHGUI_GenericHypothesisCreator( const QString& theHypType )
+ : myHypType( theHypType ), myIsCreate( false ), myDlg( 0 )
{
}
}
void SMESHGUI_GenericHypothesisCreator::create( SMESH::SMESH_Hypothesis_ptr initParamsHyp,
+ const QString& theHypName,
QWidget* parent)
{
MESSAGE( "Creation of hypothesis with initial params" );
if ( !CORBA::is_nil( initParamsHyp ) && hypType() == initParamsHyp->GetName() )
myInitParamsHypo = SMESH::SMESH_Hypothesis::_duplicate( initParamsHyp );
- create( false, parent );
+ create( false, theHypName, parent );
}
-void SMESHGUI_GenericHypothesisCreator::create( const bool isAlgo, QWidget* parent )
+void SMESHGUI_GenericHypothesisCreator::create( bool isAlgo,
+ const QString& theHypName,
+ QWidget* theParent )
{
MESSAGE( "Creation of hypothesis" );
- // Get default name for hypothesis/algorithm creation
- HypothesisData* aHypData = SMESH::GetHypothesisData( hypType().latin1() );
- QString aHypName = aHypData ? aHypData->Label : hypType();
-
myIsCreate = true;
// Create hypothesis/algorithm
if (isAlgo)
- SMESH::CreateHypothesis( hypType(), aHypName, isAlgo );
-
+ SMESH::CreateHypothesis( hypType(), theHypName, isAlgo );
else
{
- SMESH::SMESH_Hypothesis_var newHypo = SMESH::SMESH_Hypothesis::_narrow
- ( SMESH::CreateHypothesis( hypType(), aHypName, false ) );
-
- if( !editHypothesis( newHypo.in(), parent ) )
+ SMESH::SMESH_Hypothesis_var aHypothesis =
+ SMESH::CreateHypothesis( hypType(), theHypName, false );
+ if( !editHypothesis( aHypothesis.in(), theHypName, theParent ) )
{ //remove just created hypothesis
- _PTR(SObject) SHyp = SMESH::FindSObject( newHypo.in() );
+ _PTR(SObject) aHypSObject = SMESH::FindSObject( aHypothesis.in() );
_PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
if( aStudy && !aStudy->GetProperties()->IsLocked() )
{
_PTR(StudyBuilder) aBuilder = aStudy->NewBuilder();
- aBuilder->RemoveObjectWithChildren( SHyp );
+ aBuilder->RemoveObjectWithChildren( aHypSObject );
}
}
}
SMESHGUI::GetSMESHGUI()->updateObjBrowser( true, 0 );
}
-void SMESHGUI_GenericHypothesisCreator::edit( SMESH::SMESH_Hypothesis_ptr h, QWidget* parent )
+void SMESHGUI_GenericHypothesisCreator::edit( SMESH::SMESH_Hypothesis_ptr theHypothesis,
+ const QString& theHypName,
+ QWidget* theParent )
{
- if( CORBA::is_nil( h ) )
+ if( CORBA::is_nil( theHypothesis ) )
return;
MESSAGE("Edition of hypothesis");
myIsCreate = false;
- if( !editHypothesis( h, parent ) )
+ if( !editHypothesis( theHypothesis, theHypName, theParent ) )
return;
- SMESH::SObjectList listSOmesh = SMESH::GetMeshesUsingAlgoOrHypothesis( h );
+ SMESH::SObjectList listSOmesh = SMESH::GetMeshesUsingAlgoOrHypothesis( theHypothesis );
if( listSOmesh.size() > 0 )
- for( int i=0; i<listSOmesh.size(); i++ )
+ for( int i = 0; i < listSOmesh.size(); i++ )
{
_PTR(SObject) submSO = listSOmesh[i];
SMESH::SMESH_Mesh_var aMesh = SMESH::SObjectToInterface<SMESH::SMESH_Mesh>( submSO );
SMESHGUI::GetSMESHGUI()->updateObjBrowser( true, 0 );
}
-bool SMESHGUI_GenericHypothesisCreator::editHypothesis( SMESH::SMESH_Hypothesis_ptr h, QWidget* parent )
+bool SMESHGUI_GenericHypothesisCreator::editHypothesis( SMESH::SMESH_Hypothesis_ptr h,
+ const QString& theHypName,
+ QWidget* theParent )
{
if( CORBA::is_nil( h ) )
return false;
bool res = true;
+ myHypName = theHypName;
myHypo = SMESH::SMESH_Hypothesis::_duplicate( h );
- SMESHGUI_HypothesisDlg* Dlg =
- new SMESHGUI_HypothesisDlg( const_cast<SMESHGUI_GenericHypothesisCreator*>( this ), parent );
+ SMESHGUI_HypothesisDlg* Dlg = new SMESHGUI_HypothesisDlg( this, theParent );
myDlg = Dlg;
QFrame* fr = buildFrame();
if( fr )
{
Dlg->setCustomFrame( fr );
Dlg->setCaption( caption() );
+ Dlg->setName( theHypName );
Dlg->setHIcon( icon() );
Dlg->setType( type() );
retrieveParams();
Dlg->show();
- //connect(myDlg, SIGNAL( closed() ), this, SLOT( onDlgClosed() ));
qApp->enter_loop(); // make myDlg not modal
-// res = myDlg->exec()==QDialog::Accepted;
res = myDlg->result();
if( res ) {
QString paramValues = storeParams();
return myHypType;
}
+QString SMESHGUI_GenericHypothesisCreator::hypName() const
+{
+ return myHypName;
+}
+
const SMESHGUI_GenericHypothesisCreator::ListOfWidgets& SMESHGUI_GenericHypothesisCreator::widgets() const
{
return myParamWidgets;
* \param theHypType - specifies whether algorims or hypotheses or additional ones
* are retrieved (possible values are in HypType enumeration)
* \param theFather - start object for finding ( may be component, mesh, or sub-mesh )
- * \param theDataList - output list of hypotheses data
* \param theHyps - output list of names.
* \param theHypVars - output list of variables.
* \param theAlgoData - to select hypos able to be used by this algo (optional)
const int theHypType,
_PTR(SObject) theFather,
QStringList& theHyps,
- QValueList<SMESH::SMESH_Hypothesis_var>& theHypVars,
+ THypList& theHypList,
HypothesisData* theAlgoData)
{
// Clear hypoheses list
theHyps.clear();
- theHypVars.clear();
+ theHypList.clear();
if ( !theFather )
return;
SMESH::SMESH_Hypothesis_var aHypVar = SMESH::SMESH_Hypothesis::_narrow( aVar );
if ( !aHypVar->_is_nil() )
{
- QString aHypType( aHypVar->GetName() );
+ CORBA::String_var aHypType( aHypVar->GetName() );
HypothesisData* aData = SMESH::GetHypothesisData( aHypType );
if ( ( theDim == -1 || aData->Dim.contains( theDim ) ) &&
( isCompatible ( theAlgoData, aData, theHypType )) &&
( isAux == aData->IsAux ))
{
- //theDataList.append( aData );
- theHyps.append( aName->Value().c_str() );
- theHypVars.append( aHypVar );
+ std::string aHypName = aName->Value();
+ theHyps.append( aHypName.c_str() );
+ theHypList.append( THypItem( aHypVar, aHypName.c_str() ) );
}
}
}
* \param theTypeName - specifies hypothesis to be created
*/
//================================================================================
+namespace
+{
+ QString GetUniqueName (const QStringList& theHypNames,
+ const QString& theName,
+ size_t theIteration = 1)
+ {
+ QString aName = theName + "_" + QString::number( theIteration );
+ if ( theHypNames.contains( aName ) )
+ return GetUniqueName( theHypNames, theName, ++theIteration );
+ return aName;
+ }
+}
+
void SMESHGUI_MeshOp::createHypothesis (const int theDim,
const int theType,
const QString& theTypeName)
if (!aData)
return;
+ QStringList aHypNames;
+ TDim2Type2HypList::const_iterator aDimIter = myExistingHyps.begin();
+ for( ; aDimIter != myExistingHyps.end(); aDimIter++ ) {
+ const TType2HypList& aType2HypList = aDimIter.data();
+ TType2HypList::const_iterator aTypeIter = aType2HypList.begin();
+ for( ; aTypeIter != aType2HypList.end(); aTypeIter++ ) {
+ const THypList& aHypList = aTypeIter.data();
+ THypList::const_iterator anIter = aHypList.begin();
+ for( ; anIter != aHypList.end(); anIter++ ) {
+ const THypItem& aHypItem = *anIter;
+ const QString& aHypName = aHypItem.second;
+ aHypNames.append(aHypName);
+ }
+ }
+ }
+ QString aHypName = GetUniqueName( aHypNames, aData->Label);
+
// existing hypos
int nbHyp = myExistingHyps[theDim][theType].count();
QString aClientLibName = aData->ClientLibName;
if (aClientLibName == "") {
// Call hypothesis creation server method (without GUI)
- SMESH::CreateHypothesis(theTypeName, aData->Label, false);
+ SMESH::CreateHypothesis(theTypeName, aHypName, false);
} else {
// Get hypotheses creator client (GUI)
SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator(theTypeName);
SMESH::SMESH_Hypothesis_var initParamHyp =
getInitParamsHypothesis(theTypeName, aData->ServerLibName);
myDlg->setEnabled( false );
- aCreator->create(initParamHyp, myDlg);
+ aCreator->create(initParamHyp, aHypName, myDlg);
myDlg->setEnabled( true );
} else {
- SMESH::CreateHypothesis(theTypeName, aData->Label, false);
+ SMESH::CreateHypothesis(theTypeName, aHypName, false);
}
}
if (aDim == -1)
return;
- QValueList<SMESH::SMESH_Hypothesis_var> aList = myExistingHyps[ aDim ][ theHypType ];
+ const THypList& aList = myExistingHyps[ aDim ][ theHypType ];
if ( theIndex < 0 || theIndex >= aList.count() )
return;
- SMESH::SMESH_Hypothesis_var aHyp = aList[ theIndex ];
+ const THypItem& aHypItem = aList[ theIndex ];
+ SMESH::SMESH_Hypothesis_var aHyp = aHypItem.first;
if ( aHyp->_is_nil() )
return;
- char* aTypeName = aHyp->GetName();
+ CORBA::String_var aTypeName = aHyp->GetName();
SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator( aTypeName );
if ( aCreator ) {
myDlg->setEnabled( false );
- aCreator->edit( aHyp.in(), dlg() );
+ aCreator->edit( aHyp.in(), aHypItem.second, dlg() );
myDlg->setEnabled( true );
}
}
SMESH::SMESH_Hypothesis_var curHyp;
if ( hypIndex >= 0 && hypIndex < myExistingHyps[ dim ][ type ].count() )
- curHyp = myExistingHyps[ dim ][ type ][ hypIndex ];
+ curHyp = myExistingHyps[ dim ][ type ][ hypIndex ].first;
if ( !myToCreate && !curAlgo && !curHyp->_is_nil() ) { // edition, algo not selected
// try to find algo by selected hypothesis in order to keep it selected
bool algoDeselectedByUser = ( theDim < 0 && aDim == dim );
- QString curHypType = curHyp->GetName();
+ CORBA::String_var curHypType = curHyp->GetName();
if ( !algoDeselectedByUser &&
myObjHyps[ dim ][ type ].count() > 0 &&
- curHypType == myObjHyps[ dim ][ type ][ 0 ]->GetName())
+ curHypType == myObjHyps[ dim ][ type ].first().first->GetName())
{
- HypothesisData* hypData = SMESH::GetHypothesisData( curHyp->GetName() );
+ CORBA::String_var aName = curHyp->GetName();
+ HypothesisData* hypData = SMESH::GetHypothesisData( aName );
for ( int i = 0 ; i < myAvailableHypData[ dim ][ Algo ].count(); ++i ) {
curAlgo = myAvailableHypData[ dim ][ Algo ][ i ];
if ( curAlgo && hypData && isCompatible( curAlgo, hypData, type ))
{
// check if a selected hyp is compatible with the curAlgo
if ( !curHyp->_is_nil() ) {
- HypothesisData* hypData = SMESH::GetHypothesisData( curHyp->GetName() );
+ CORBA::String_var aName = curHyp->GetName();
+ HypothesisData* hypData = SMESH::GetHypothesisData( aName );
if ( !isCompatible( curAlgo, hypData, type ))
curHyp = SMESH::SMESH_Hypothesis::_nil();
}
hypIndex = -1;
if ( !isSubmesh && hypIndex < 0 && anExisting.count() == 1 ) {
// none is yet selected => select the sole existing if it is not optional
- QString hypTypeName = myExistingHyps[ dim ][ type ][ 0 ]->GetName();
+ CORBA::String_var hypTypeName = myExistingHyps[ dim ][ type ].first().first->GetName();
bool isOptional = true;
if ( algoByDim[ dim ] &&
- SMESH::IsAvailableHypothesis( algoByDim[ dim ], hypTypeName, isOptional ) &&
+ SMESH::IsAvailableHypothesis( algoByDim[ dim ], hypTypeName.in(), isOptional ) &&
!isOptional )
hypIndex = 0;
}
for ( int aHypType = MainHyp; aHypType <= AddHyp; aHypType++ ) {
int aHypIndex = currentHyp( aDim, aHypType );
if ( aHypIndex >= 0 && aHypIndex < myExistingHyps[ aDim ][ aHypType ].count() ) {
- SMESH::SMESH_Hypothesis_var aHypVar = myExistingHyps[ aDim ][ aHypType ][ aHypIndex ];
+ SMESH::SMESH_Hypothesis_var aHypVar = myExistingHyps[ aDim ][ aHypType ][ aHypIndex ].first;
if ( !aHypVar->_is_nil() )
SMESH::AddHypothesisOnMesh( aMeshVar, aHypVar );
}
if ( aHypIndex >= 0 && aHypIndex < myExistingHyps[ aDim ][ aHypType ].count() )
{
SMESH::SMESH_Hypothesis_var aHypVar =
- myExistingHyps[ aDim ][ aHypType ][ aHypIndex ];
+ myExistingHyps[ aDim ][ aHypType ][ aHypIndex ].first;
if ( !aHypVar->_is_nil() )
SMESH::AddHypothesisOnSubMesh( aSubMeshVar, aHypVar );
}
existingHyps( theDim, Algo, pObj, tmp, myExistingHyps[ theDim ][ Algo ]);
// look for anexisting algo of such a type
- QValueList<SMESH::SMESH_Hypothesis_var>& aHypVarList = myExistingHyps[ theDim ][ Algo ];
- QValueList<SMESH::SMESH_Hypothesis_var>::iterator anIter;
- for ( anIter = aHypVarList.begin(); anIter != aHypVarList.end(); anIter++ )
+ THypList& aHypVarList = myExistingHyps[ theDim ][ Algo ];
+ THypList::iterator anIter = aHypVarList.begin();
+ for ( ; anIter != aHypVarList.end(); anIter++ )
{
- SMESH::SMESH_Hypothesis_var aHypVar = *anIter;
- if ( !aHypVar->_is_nil() && aHypName == aHypVar->GetName() )
+ SMESH::SMESH_Hypothesis_var aHypVar = (*anIter).first;
+ CORBA::String_var aName = aHypVar->GetName();
+ if ( !aHypVar->_is_nil() && aHypName == aName )
{
anAlgoVar = aHypVar;
break;
// Create algorithm
if (aCreator)
- aCreator->create(true, myDlg);
+ aCreator->create(true, aHypName, myDlg);
else
SMESH::CreateHypothesis(aHypName, aHypData->Label, true);
}
existingHyps( theDim, Algo, aFather, tmpList, myExistingHyps[ theDim ][ Algo ] );
}
- QValueList<SMESH::SMESH_Hypothesis_var>& aNewHypVarList = myExistingHyps[ theDim ][ Algo ];
+ THypList& aNewHypVarList = myExistingHyps[ theDim ][ Algo ];
for ( anIter = aNewHypVarList.begin(); anIter != aNewHypVarList.end(); ++anIter )
{
- SMESH::SMESH_Hypothesis_var aHypVar = *anIter;
- if ( !aHypVar->_is_nil() && aHypName == aHypVar->GetName() )
+ SMESH::SMESH_Hypothesis_var aHypVar = (*anIter).first;
+ CORBA::String_var aName = aHypVar->GetName();
+ if ( !aHypVar->_is_nil() && aHypName == aName )
{
anAlgoVar = aHypVar;
break;
int aHypIndex = -1;
if ( myObjHyps[ dim ][ Algo ].count() > 0 )
{
- SMESH::SMESH_Hypothesis_var aVar = myObjHyps[ dim ][ Algo ].first();
- QString aHypTypeName = aVar->GetName();
+ SMESH::SMESH_Hypothesis_var aVar = myObjHyps[ dim ][ Algo ].first().first;
+ CORBA::String_var aHypTypeName = aVar->GetName();
HypothesisData* algoData = SMESH::GetHypothesisData( aHypTypeName );
aHypIndex = myAvailableHypData[ dim ][ Algo ].findIndex ( algoData );
// if ( aHypIndex < 0 && algoData ) {
// find index of requered hypothesis among existing ones for this dimension and type
int aHypIndex = -1;
if ( myObjHyps[ dim ][ hypType ].count() > 0 ) {
- aHypIndex = find( myObjHyps[ dim ][ hypType ].first(),
+ aHypIndex = find( myObjHyps[ dim ][ hypType ].first().first,
myExistingHyps[ dim ][ hypType ] );
if ( aHypIndex < 0 ) {
// assigned hypothesis is incompatible with the algorithm
*/
//================================================================================
int SMESHGUI_MeshOp::find( const SMESH::SMESH_Hypothesis_var& theHyp,
- const QValueList<SMESH::SMESH_Hypothesis_var>& theHypList ) const
+ const THypList& theHypList ) const
{
int aRes = -1;
if ( !theHyp->_is_nil() )
{
int i = 0;
- QValueList<SMESH::SMESH_Hypothesis_var>::const_iterator anIter;
- for ( anIter = theHypList.begin(); anIter != theHypList.end(); ++ anIter )
+ THypList::const_iterator anIter = theHypList.begin();
+ for ( ; anIter != theHypList.end(); ++ anIter )
{
- if ( theHyp->_is_equivalent( *anIter ) )
+ if ( theHyp->_is_equivalent( (*anIter).first ) )
{
aRes = i;
break;
SUIT_OverrideCursor aWaitCursor;
// Set new name
- SMESH::SetName( pObj, myDlg->objectText( SMESHGUI_MeshDlg::Obj ).latin1() );
+ QString aName = myDlg->objectText( SMESHGUI_MeshDlg::Obj );
+ SMESH::SetName( pObj, aName.latin1() );
// First, remove old algos in order to avoid messages on algorithm hiding
for ( int dim = SMESH::DIM_0D; dim <= SMESH::DIM_3D; dim++ )
{
if ( isAccessibleDim( dim ) && myObjHyps[ dim ][ Algo ].count() > 0 )
{
- SMESH::SMESH_Hypothesis_var anOldAlgo = myObjHyps[ dim ][ Algo ].first();
+ SMESH::SMESH_Hypothesis_var anOldAlgo = myObjHyps[ dim ][ Algo ].first().first;
+ CORBA::String_var anOldName = anOldAlgo->GetName();
SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( dim );
+ CORBA::String_var anAlgoName = anAlgoVar->GetName();
if ( anAlgoVar->_is_nil() || // no new algo selected or
- strcmp(anOldAlgo->GetName(), anAlgoVar->GetName()) ) // algo change
+ strcmp(anOldName.in(), anAlgoName.in()) ) // algo change
{
// remove old algorithm
- SMESH::RemoveHypothesisOrAlgorithmOnMesh ( pObj, myObjHyps[ dim ][ Algo ].first() );
+ SMESH::RemoveHypothesisOrAlgorithmOnMesh ( pObj, myObjHyps[ dim ][ Algo ].first().first );
myObjHyps[ dim ][ Algo ].clear();
}
}
if ( !anAlgoVar->_is_nil() && // some algo selected and
myObjHyps[ dim ][ Algo ].count() == 0 ) // no algo assigned
{
- SMESH::SMESH_Mesh_var aMeshVar =
- SMESH::SMESH_Mesh::_narrow( _CAST(SObject,pObj)->GetObject() );
+ SALOMEDS_SObject* aSObject = _CAST(SObject, pObj);
+ CORBA::Object_var anObject = aSObject->GetObject();
+ SMESH::SMESH_Mesh_var aMeshVar = SMESH::SMESH_Mesh::_narrow( anObject );
bool isMesh = !aMeshVar->_is_nil();
if ( isMesh ) {
SMESH::AddHypothesisOnMesh( aMeshVar, anAlgoVar );
if ( !aVar->_is_nil() )
SMESH::AddHypothesisOnSubMesh( aVar, anAlgoVar );
}
- myObjHyps[ dim ][ Algo ].append( anAlgoVar );
+ myObjHyps[ dim ][ Algo ].append( THypItem( anAlgoVar, aName) );
}
// assign hypotheses
// remove old hypotheses
if ( myObjHyps[ dim ][ hypType ].count() > 0 )
{
- anOldHypIndex = find( myObjHyps[ dim ][ hypType ].first(),
+ anOldHypIndex = find( myObjHyps[ dim ][ hypType ].first().first ,
myExistingHyps[ dim ][ hypType ] );
if ( aNewHypIndex != anOldHypIndex || // different hyps
anOldHypIndex == -1 ) // hyps of different algos
{
SMESH::RemoveHypothesisOrAlgorithmOnMesh
- ( pObj, myObjHyps[ dim ][ hypType ].first() );
+ ( pObj, myObjHyps[ dim ][ hypType ].first().first );
myObjHyps[ dim ][ hypType ].clear();
}
}
if ( isMesh )
{
SMESH::AddHypothesisOnMesh
- (aMeshVar, myExistingHyps[ dim ][ hypType ][ aNewHypIndex ] );
+ (aMeshVar, myExistingHyps[ dim ][ hypType ][ aNewHypIndex ].first );
}
else
{
SMESH::SMESH_subMesh::_narrow( _CAST(SObject,pObj)->GetObject() );
if ( !aVar->_is_nil() )
SMESH::AddHypothesisOnSubMesh
- ( aVar, myExistingHyps[ dim ][ hypType ][ aNewHypIndex ] );
+ ( aVar, myExistingHyps[ dim ][ hypType ][ aNewHypIndex ].first );
}
}
// reread all hypotheses of mesh if necessary