+ SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator( aHyp->GetName() );
+ if ( aCreator ) {
+ myDlg->setEnabled( false );
+ aCreator->edit( aHyp.in(), aHypItem.second, dlg() );
+ myDlg->setEnabled( true );
+ }
+}
+
+//================================================================================
+/*!
+ * \brief access to hypothesis data
+ * \param theDim - hyp dimension
+ * \param theHypType - hyp type (Algo,MainHyp or AddHyp)
+ * \param theIndex - index in the list
+ * \retval HypothesisData* - result data, may be 0
+ */
+//================================================================================
+
+HypothesisData* SMESHGUI_MeshOp::hypData( const int theDim,
+ const int theHypType,
+ const int theIndex)
+{
+ if ( theDim > -1 && theDim <= SMESH::DIM_3D &&
+ theHypType > -1 && theHypType < NbHypTypes &&
+ theIndex > -1 && theIndex < myAvailableHypData[ theDim ][ theHypType ].count() )
+ return myAvailableHypData[ theDim ][ theHypType ][ theIndex ];
+ return 0;
+}
+
+//================================================================================
+/*!
+ * \brief Set available algos and hypos according to the selected algorithm
+ * \param theIndex - algorithm index
+ */
+//================================================================================
+
+void SMESHGUI_MeshOp::onAlgoSelected( const int theIndex,
+ const int theDim )
+{
+ if ( myIgnoreAlgoSelection )
+ return;
+
+ int aDim = theDim < 0 ? getTabDim( sender(), myDlg ): theDim;
+ if (aDim == -1)
+ return;
+
+ // find highest available dimension, all algos of this dimension are available for choice
+ int aTopDim = -1;
+ for (int i = SMESH::DIM_0D; i <= SMESH::DIM_3D; i++)
+ if (isAccessibleDim( i ))
+ aTopDim = i;
+ if (aTopDim == -1)
+ return;
+
+ const bool isSubmesh = ( myToCreate ? !myIsMesh : myDlg->isObjectShown( SMESHGUI_MeshDlg::Mesh ));
+
+ HypothesisData* algoData = hypData( aDim, Algo, theIndex );
+ HypothesisData* algoByDim[4];
+ algoByDim[ aDim ] = algoData;
+
+ QStringList anAvailable;
+ if ( !algoData ) { // all algos becomes available
+ availableHyps( aDim, Algo, anAvailable, myAvailableHypData[ aDim ][ Algo ]);
+ myDlg->tab( aDim )->setAvailableHyps( Algo, anAvailable );
+ }
+
+ // check that algorithms of other dimentions are compatible with
+ // the selected one
+
+ // 2 loops: backward and forward from algo dimension
+ for ( int forward = false; forward <= true; ++forward )
+ {
+ int dim = aDim + 1, lastDim = SMESH::DIM_3D, dir = 1;
+ if ( !forward ) {
+ dim = aDim - 1; lastDim = SMESH::DIM_0D; dir = -1;
+ }
+ HypothesisData* prevAlgo = algoData;
+ bool noCompatible = false;
+ for ( ; dim * dir <= lastDim * dir; dim += dir)
+ {
+ if ( !isAccessibleDim( dim ))
+ continue;
+ if ( noCompatible ) { // the selected algo has no compatible ones
+ anAvailable.clear();
+ myDlg->tab( dim )->setAvailableHyps( Algo, anAvailable );
+ myAvailableHypData[dim][Algo].clear();
+ algoByDim[ dim ] = 0;
+ continue;
+ }
+ // get currently selected algo
+ int algoIndex = currentHyp( dim, Algo );
+ HypothesisData* curAlgo = hypData( dim, Algo, algoIndex );
+ if ( curAlgo ) { // some algo selected
+ if ( !isCompatible( prevAlgo, curAlgo, Algo ))
+ curAlgo = 0;
+ }
+ // set new available algoritms
+ availableHyps( dim, Algo, anAvailable, myAvailableHypData[dim][Algo], prevAlgo );
+ HypothesisData* soleCompatible = 0;
+ if ( anAvailable.count() == 1 )
+ soleCompatible = myAvailableHypData[dim][Algo][0];
+ if ( dim == aTopDim && prevAlgo ) // all available algoritms should be selectable any way
+ availableHyps( dim, Algo, anAvailable, myAvailableHypData[dim][Algo], 0 );
+ myDlg->tab( dim )->setAvailableHyps( Algo, anAvailable );
+ noCompatible = anAvailable.isEmpty();
+
+ // restore previously selected algo
+ algoIndex = myAvailableHypData[dim][Algo].indexOf( curAlgo );
+ if ( !isSubmesh && algoIndex < 0 && soleCompatible && !forward && dim != SMESH::DIM_0D)
+ // select the sole compatible algo
+ algoIndex = myAvailableHypData[dim][Algo].indexOf( soleCompatible );
+ setCurrentHyp( dim, Algo, algoIndex );
+
+ // remember current algo
+ prevAlgo = algoByDim[ dim ] = hypData( dim, Algo, algoIndex );
+ }
+ }
+
+ // set hypotheses corresponding to the found algoritms
+
+ _PTR(SObject) pObj = SMESH::GetActiveStudyDocument()->FindComponent("SMESH");
+
+ for ( int dim = SMESH::DIM_0D; dim <= SMESH::DIM_3D; dim++ )
+ {
+ if ( !isAccessibleDim( dim ))
+ continue;
+ for ( int type = MainHyp; type < NbHypTypes; type++ )
+ {
+ myAvailableHypData[ dim ][ type ].clear();
+ QStringList anAvailable, anExisting;
+
+ HypothesisData* curAlgo = algoByDim[ dim ];
+ int hypIndex = currentHyp( dim, type );
+
+ SMESH::SMESH_Hypothesis_var curHyp;
+ if ( hypIndex >= 0 && hypIndex < myExistingHyps[ dim ][ type ].count() )
+ 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 );
+ CORBA::String_var curHypType = curHyp->GetName();
+ if ( !algoDeselectedByUser &&
+ myObjHyps[ dim ][ type ].count() > 0 &&
+ curHypType == myObjHyps[ dim ][ type ].first().first->GetName())
+ {
+ HypothesisData* hypData = SMESH::GetHypothesisData( curHyp->GetName() );
+ for (int i = 0; i < myAvailableHypData[ dim ][ Algo ].count(); ++i) {
+ curAlgo = myAvailableHypData[ dim ][ Algo ][ i ];
+ if (curAlgo && hypData && isCompatible(curAlgo, hypData, type))
+ break;
+ else
+ curAlgo = 0;
+ }
+ }
+ }
+ // get hyps compatible with curAlgo
+ if ( curAlgo )
+ {
+ // check if a selected hyp is compatible with the curAlgo
+ if ( !curHyp->_is_nil() ) {
+ HypothesisData* hypData = SMESH::GetHypothesisData( curHyp->GetName() );
+ if ( !isCompatible( curAlgo, hypData, type ))
+ curHyp = SMESH::SMESH_Hypothesis::_nil();
+ }
+ existingHyps( dim, type, pObj, anExisting, myExistingHyps[ dim ][ type ], curAlgo);
+ availableHyps( dim, type, anAvailable, myAvailableHypData[ dim ][ type ], curAlgo);
+ }
+ // set list of hypotheses
+ myDlg->tab( dim )->setAvailableHyps( type, anAvailable );
+ myDlg->tab( dim )->setExistingHyps( type, anExisting );
+
+ // set current existing hypothesis
+ if ( !curHyp->_is_nil() && !anExisting.isEmpty() )
+ hypIndex = this->find( curHyp, myExistingHyps[ dim ][ type ]);
+ else
+ hypIndex = -1;
+ if ( !isSubmesh && hypIndex < 0 && anExisting.count() == 1 ) {
+ // none is yet selected => select the sole existing if it is not optional
+ CORBA::String_var hypTypeName = myExistingHyps[ dim ][ type ].first().first->GetName();
+ bool isOptional = true;
+ if ( algoByDim[ dim ] &&
+ SMESH::IsAvailableHypothesis( algoByDim[ dim ], hypTypeName.in(), isOptional ) &&
+ !isOptional )
+ hypIndex = 0;
+ }
+ setCurrentHyp( dim, type, hypIndex );
+ }
+ }
+}
+
+//================================================================================
+/*!
+ * \brief Creates and selects hypothesis of hypotheses set
+ * \param theSetName - The name of hypotheses set
+ */
+//================================================================================
+void SMESHGUI_MeshOp::onHypoSet( const QString& theSetName )
+{
+ HypothesesSet* aHypoSet = SMESH::GetHypothesesSet(theSetName);
+ if (!aHypoSet) return;
+
+ // clear all hyps
+ for (int dim = SMESH::DIM_0D; dim <= SMESH::DIM_3D; dim++) {
+ setCurrentHyp(dim, Algo, -1);
+ setCurrentHyp(dim, AddHyp, -1);
+ setCurrentHyp(dim, MainHyp, -1);
+ }
+
+ for (int aHypType = Algo; aHypType < AddHyp; aHypType++) {
+ bool isAlgo = (aHypType == Algo);
+
+ // set hyps from the set
+ QStringList* aHypoList = isAlgo ? &aHypoSet->AlgoList : &aHypoSet->HypoList;
+ for (int i = 0, n = aHypoList->count(); i < n; i++) {
+ const QString& aHypoTypeName = (*aHypoList)[ i ];
+ HypothesisData* aHypData = SMESH::GetHypothesisData(aHypoTypeName);
+ if (!aHypData)
+ continue;
+
+ int aDim = aHypData->Dim[0];
+ // create or/and set
+ if (isAlgo) {
+ int index = myAvailableHypData[aDim][Algo].indexOf( aHypData );
+ if ( index < 0 ) {
+ QStringList anAvailable;
+ availableHyps( aDim, Algo, anAvailable, myAvailableHypData[aDim][Algo] );
+ myDlg->tab( aDim )->setAvailableHyps( Algo, anAvailable );
+ index = myAvailableHypData[aDim][Algo].indexOf( aHypData );
+ }
+ setCurrentHyp( aDim, Algo, index );
+ onAlgoSelected( index, aDim );
+ }
+ else {
+ bool mainHyp = true;
+ QStringList anAvailable;
+ availableHyps( aDim, MainHyp, anAvailable, myAvailableHypData[aDim][MainHyp] );
+ myDlg->tab( aDim )->setAvailableHyps( MainHyp, anAvailable );
+ int index = myAvailableHypData[aDim][MainHyp].indexOf( aHypData );
+ if ( index < 0 ) {
+ mainHyp = false;
+ index = myAvailableHypData[aDim][AddHyp].indexOf( aHypData );
+ }
+ if (index >= 0)
+ createHypothesis(aDim, mainHyp ? MainHyp : AddHyp, aHypoTypeName);
+ }
+ } // loop on hypos in the set
+ } // loop on algo/hypo