+ aCreator->edit( aHyp.in(), dlg() );
+}
+
+//================================================================================
+/*!
+ * \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 < 3 &&
+ 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_1D; i <= SMESH::DIM_3D; i++)
+ if (isAccessibleDim( i ))
+ aTopDim = i;
+ if (aTopDim == -1)
+ return;
+
+ HypothesisData* algoData = hypData( aDim, Algo, theIndex );
+ HypothesisData* algoByDim[3];
+ 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_1D; 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].findIndex( curAlgo );
+ if ( algoIndex < 0 && soleCompatible )
+ // select the sole compatible algo
+ algoIndex = myAvailableHypData[dim][Algo].findIndex( soleCompatible );
+ setCurrentHyp( dim, Algo, algoIndex );
+
+ // remember current algo
+ prevAlgo = algoByDim[ dim ] = hypData( dim, Algo, algoIndex );
+ }
+ }
+
+ // set hypotheses corresponding to the found algoritms
+
+ //QString anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
+ _PTR(SObject) pObj;// = studyDS()->FindObjectID( anObjEntry.latin1() );
+ if ( !pObj )
+ pObj = SMESH::GetActiveStudyDocument()->FindComponent("SMESH");
+
+ for ( int dim = SMESH::DIM_1D; dim <= SMESH::DIM_3D; dim++ )
+ {
+ if ( !isAccessibleDim( dim ))
+ continue;
+ for ( int type = MainHyp; type < NbHypTypes; type++ )
+ {
+ myAvailableHypData[ dim ][ type ].clear();
+ QStringList anAvailable, anExisting;
+ SMESH::SMESH_Hypothesis_var curHyp;
+
+ // get hyps compatible with curAlgo
+ if ( HypothesisData* curAlgo = algoByDim[ dim ] )
+ {
+ // get current existing hypothesis
+ int hypIndex = currentHyp( dim, type );
+ if ( hypIndex >= 0 && hypIndex < myExistingHyps[ dim ][ type ].count() ) {
+ curHyp = myExistingHyps[ dim ][ type ][ hypIndex ];
+ QString hypTypeName = curHyp->GetName();
+ HypothesisData* hypData = SMESH::GetHypothesisData( hypTypeName );
+ 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
+ int hypIndex = -1;
+ if ( !curHyp->_is_nil() && !anExisting.isEmpty() )
+ hypIndex = this->find( curHyp, myExistingHyps[ dim ][ type ]);
+ if ( 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();
+ bool isOptional = true;
+ if ( algoByDim[ dim ] &&
+ SMESH::IsAvailableHypothesis( algoByDim[ dim ], hypTypeName, isOptional ) &&
+ !isOptional )
+ hypIndex = 0;
+ }
+ setCurrentHyp( dim, type, hypIndex );
+ }
+ }