+ // Get parameters appropriate to initialize a new hypothesis
+ SMESH::SMESH_Hypothesis_var initParamHyp =
+ getInitParamsHypothesis(theTypeName, aData->ServerLibName);
+
+ removeCustomFilters(); // Issue 0020170
+
+ // set shapes, of mesh and sub-mesh if any
+ initHypCreator( aCreator );
+
+ myDlg->setEnabled( false );
+ aCreator->create(initParamHyp, aHypName, myDlg, this, SLOT( onHypoCreated( int ) ) );
+ dialog = true;
+ }
+ else {
+ SMESH::SMESH_Hypothesis_var aHyp =
+ SMESH::CreateHypothesis(theTypeName, aHypName, false);
+ aHyp.out();
+ }
+ }
+
+ if( !dialog )
+ onHypoCreated(2);
+}
+
+//================================================================================
+/*!
+ * Necessary steps after hypothesis creation
+ * \param result - creation result:
+ * 0 = rejected
+ * 1 = accepted
+ * 2 = additional value meaning that slot is called not from dialog box
+ */
+//================================================================================
+void SMESHGUI_MeshOp::onHypoCreated( int result )
+{
+ if( result != 2 )
+ {
+ int obj = myDlg->getActiveObject();
+ onActivateObject( obj ); // Issue 0020170. Restore filters
+ myDlg->setEnabled( true );
+ }
+
+ _PTR(SComponent) aFather = SMESH::GetActiveStudyDocument()->FindComponent("SMESH");
+
+ int nbHyp = myExistingHyps[myDim][myType].count();
+ HypothesisData* algoData = hypData( myDim, Algo, currentHyp( myDim, Algo ));
+ QStringList aNewHyps;
+ existingHyps(myDim, myType, aFather, aNewHyps, myExistingHyps[myDim][myType], algoData);
+ if (aNewHyps.count() > nbHyp)
+ {
+ for (int i = nbHyp; i < aNewHyps.count(); i++)
+ myDlg->tab(myDim)->addHyp(myType, aNewHyps[i]);
+ }
+
+ if( result!=2 && myHypoSet )
+ processSet();
+}
+
+//================================================================================
+/*!
+ * \brief Calls plugin methods for hypothesis editing
+ * \param theHypType - specifies whether main hypothesis or additional one
+ * is edited
+ * \param theIndex - index of existing hypothesis
+ *
+ * Calls plugin methods for hypothesis editing
+ */
+//================================================================================
+void SMESHGUI_MeshOp::onEditHyp( const int theHypType, const int theIndex )
+{
+ // Speicfies dimension of hypothesis to be created
+ int aDim = getTabDim( sender(), myDlg );
+ if (aDim == -1)
+ return;
+
+ const THypList& aList = myExistingHyps[ aDim ][ theHypType ];
+ if ( theIndex < 0 || theIndex >= aList.count() )
+ return;
+ const THypItem& aHypItem = aList[ theIndex ];
+ SMESH::SMESH_Hypothesis_var aHyp = aHypItem.first;
+ if ( aHyp->_is_nil() )
+ return;
+
+ SMESHGUI_GenericHypothesisCreator* aCreator =
+ SMESH::GetHypothesisCreator( SMESH::toQStr( aHyp->GetName() ));
+ if ( aCreator )
+ {
+ // set initial parameters
+ SMESH::SMESH_Hypothesis_var initParamHyp =
+ getInitParamsHypothesis( SMESH::toQStr( aHyp->GetName() ),
+ SMESH::toQStr( aHyp->GetLibName() ));
+ aCreator->setInitParamsHypothesis( initParamHyp );
+
+ // set shapes, of mesh and sub-mesh if any
+ initHypCreator( aCreator );
+
+ removeCustomFilters(); // Issue 0020170
+ myDlg->setEnabled( false );
+
+ aCreator->edit( aHyp.in(), aHypItem.second, dlg(), this, SLOT( onHypoEdited( int ) ) );
+ }
+}
+
+//================================================================================
+/*!
+ * Necessary steps after hypothesis edition
+ * \param result - creation result:
+ * 0 = rejected
+ * 1 = accepted
+ */
+//================================================================================
+void SMESHGUI_MeshOp::onHypoEdited( int result )
+{
+ int obj = myDlg->getActiveObject();
+ onActivateObject( obj ); // Issue 0020170. Restore filters
+ 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;
+
+ // check that tab enabled of one less dimension
+ if ( aDim > SMESH::DIM_0D )
+ {
+ if ( isAccessibleDim( aDim - 1 ) )
+ {
+ if (( myDlg->currentMeshType() != MT_ANY ) &&
+ ( !algoData || ( myIsOnGeometry && algoData->InputTypes.isEmpty() )))
+ for (int i = aDim - 1; i >= SMESH::DIM_0D; i--)
+ if ( isAccessibleDim( i ) ) {
+ myDlg->disableTab( i );
+ setCurrentHyp(i, Algo, -1);
+ }
+ }
+ else if ( algoData && myIsOnGeometry && !algoData->InputTypes.isEmpty() )
+ {
+ myDlg->enableTab( aDim - 1 );
+ }
+ }
+
+ // check that algorithms of other dimentions are compatible with
+ // the selected one
+ if ( !algoData ) { // all algos becomes available
+ if (myDlg->currentMeshType() == MT_ANY || aDim == SMESH::DIM_1D || aDim == SMESH::DIM_0D)
+ availableHyps( aDim, Algo, anAvailable, myAvailableHypData[ aDim ][ Algo ]);
+ else{
+ anAvailable.clear();
+ for (int i = 0; i < myFilteredAlgoData[aDim].count(); ++i) {
+ HypothesisData* aCurAlgo = myFilteredAlgoData[aDim][ i ];
+ anAvailable.append( aCurAlgo->Label );
+ }
+ }
+ myDlg->tab( aDim )->setAvailableHyps( Algo, anAvailable );
+ }
+ // 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
+ if (myDlg->currentMeshType() == MT_ANY || dim == SMESH::DIM_1D || dim == SMESH::DIM_0D)
+ availableHyps( dim, Algo, anAvailable, myAvailableHypData[dim][Algo], prevAlgo );
+ else{
+ anAvailable.clear();
+ myAvailableHypData[dim][Algo].clear();
+ for (int i = 0; i < myFilteredAlgoData[dim].count(); ++i) {
+ HypothesisData* aCurAlgo = myFilteredAlgoData[dim][ i ];
+ if ( isCompatible ( prevAlgo, aCurAlgo, Algo )) {
+ anAvailable.append( aCurAlgo->Label );
+ myAvailableHypData[dim][Algo].append( aCurAlgo );
+ }
+ }
+ }
+ HypothesisData* soleCompatible = 0;
+ if ( anAvailable.count() == 1 )
+ soleCompatible = myAvailableHypData[dim][Algo][0];
+ if ( dim == aTopDim && prevAlgo ) {// all available algoritms should be selectable any way
+ if (myDlg->currentMeshType() == MT_ANY)
+ 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;
+
+ // get indices of selected hyps
+ const int nbTypes = nbDlgHypTypes(dim);
+ std::vector<int> hypIndexByType( nbTypes, -1 );
+ for ( int dlgType = MainHyp; dlgType < nbTypes; dlgType++ )
+ {
+ hypIndexByType[ dlgType ] = currentHyp( dim, dlgType );
+ }
+
+ // update hyps
+ for ( int dlgType = MainHyp; dlgType < nbTypes; dlgType++ )
+ {
+ const int type = Min( dlgType, AddHyp );
+ myAvailableHypData[ dim ][ type ].clear();
+ QStringList anAvailable, anExisting;
+
+ HypothesisData* curAlgo = algoByDim[ dim ];
+ int hypIndex = hypIndexByType[ dlgType ];
+
+ 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 );
+ QString curHypType = SMESH::toQStr( curHyp->GetName() );
+ if ( !algoDeselectedByUser &&
+ myObjHyps[ dim ][ type ].count() > 0 &&
+ curHypType == SMESH::toQStr( 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
+ bool defaulHypAvlbl = false;
+ if ( curAlgo )