+
+//=================================================================================
+// function : UpdateControlState()
+// purpose :
+//=================================================================================
+void SMESHGUI_EditHypothesesDlg::UpdateControlState()
+{
+ bool isEnabled = ( !myMesh ->_is_nil() && !myGeomShape->_is_nil() && ListHypAssignation->count() && ListAlgoAssignation->count() ) ||
+ ( !mySubMesh->_is_nil() && !myGeomShape->_is_nil() && ( ListHypAssignation->count() || ListAlgoAssignation->count() ) );
+
+ buttonOk ->setEnabled( myNbModification && isEnabled && !myImportedMesh );
+ buttonApply->setEnabled( myNbModification && isEnabled && !myImportedMesh );
+
+ SelectButtonC1A2 ->setEnabled( ALLOW_CHANGE_SHAPE && !myImportedMesh );
+ LineEditC1A2 ->setEnabled( ALLOW_CHANGE_SHAPE && !myImportedMesh );
+ ListHypDefinition ->setEnabled( !myImportedMesh );
+ ListHypAssignation ->setEnabled( !myImportedMesh );
+ ListAlgoDefinition ->setEnabled( !myImportedMesh );
+ ListAlgoAssignation->setEnabled( !myImportedMesh );
+}
+
+//=================================================================================
+// function : StoreMesh()
+// purpose :
+//=================================================================================
+bool SMESHGUI_EditHypothesesDlg::StoreMesh()
+{
+ MapIOR anOldHypos, aNewHypos;
+ if ( myGeomShape->_is_nil() )
+ return false;
+ // 1. Check whether the geometric shape has changed
+ SALOMEDS::SObject_var aMeshSO = SMESH::FindSObject( myMesh );
+ GEOM::GEOM_Object_var aIniGeomShape = SMESH::GetShapeOnMeshOrSubMesh( aMeshSO );
+ bool bShapeChanged = aIniGeomShape->_is_nil() || !aIniGeomShape->_is_equivalent( myGeomShape );
+ if ( bShapeChanged ) {
+ // VSR : TODO : Set new shape - not supported yet by SMESH engine
+ // 1. remove all old hypotheses and algorithms and also submeshes
+ // 2. set new shape
+ }
+
+ int nbFail = 0;
+ MapIOR::iterator it;
+ // 2. remove not used hypotheses from the mesh
+ for ( it = myMapOldHypos.begin(); it != myMapOldHypos.end(); ++it ) {
+ string ior = it->first;
+ int index = findItem( ListHypAssignation, ior );
+ if ( index < 0 ) {
+ SMESH::SMESH_Hypothesis_var aHyp = SMESH::IORToInterface<SMESH::SMESH_Hypothesis>(ior.c_str());
+ if ( !aHyp->_is_nil() ){
+ if (!SMESH::RemoveHypothesisOrAlgorithmOnMesh( aMeshSO, aHyp ))
+ nbFail++;
+ }
+ }
+ }
+ // 3. remove not used algorithms from the mesh
+ for ( it = myMapOldAlgos.begin(); it != myMapOldAlgos.end(); ++it ) {
+ string ior = it->first;
+ int index = findItem( ListAlgoAssignation, ior );
+ if ( index < 0 ) {
+ SMESH::SMESH_Hypothesis_var aHyp = SMESH::IORToInterface<SMESH::SMESH_Hypothesis>(ior.c_str());
+ if ( !aHyp->_is_nil() ){
+ if (!SMESH::RemoveHypothesisOrAlgorithmOnMesh( aMeshSO, aHyp ))
+ nbFail++;
+ }
+ }
+ }
+ // 4. Add new algorithms
+ for ( int i = 0; i < ListAlgoAssignation->count(); i++ ) {
+ if ( ListAlgoAssignation->item( i )->rtti() == ListBoxIOR::RTTI_IOR ) {
+ ListBoxIOR* anItem = ( ListBoxIOR* )( ListAlgoAssignation->item( i ) );
+ if ( anItem ) {
+ string ior = anItem->GetIOR();
+ if ( myMapOldAlgos.find( ior ) == myMapOldAlgos.end() ) {
+ SMESH::SMESH_Hypothesis_var aHyp = SMESH::IORToInterface<SMESH::SMESH_Hypothesis>(ior.c_str());
+ if ( !aHyp->_is_nil() ){
+ if (!SMESH::AddHypothesisOnMesh( myMesh, aHyp ))
+ nbFail++;
+ }
+ }
+ }
+ }
+ }
+ // 5. Add new hypotheses
+ for ( int i = 0; i < ListHypAssignation->count(); i++ ) {
+ if ( ListHypAssignation->item( i )->rtti() == ListBoxIOR::RTTI_IOR ) {
+ ListBoxIOR* anItem = ( ListBoxIOR* )( ListHypAssignation->item( i ) );
+ if ( anItem ) {
+ string ior = anItem->GetIOR();
+ if ( myMapOldHypos.find( ior ) == myMapOldHypos.end() ) {
+ SMESH::SMESH_Hypothesis_var aHyp = SMESH::IORToInterface<SMESH::SMESH_Hypothesis>(ior.c_str());
+ if ( !aHyp->_is_nil() ){
+ if (!SMESH::AddHypothesisOnMesh( myMesh, aHyp ))
+ nbFail++;
+ }
+ }
+ }
+ }
+ }
+ return ( nbFail == 0 );
+}
+
+//=================================================================================
+// function : StoreSubMesh()
+// purpose :
+//=================================================================================
+bool SMESHGUI_EditHypothesesDlg::StoreSubMesh()
+{
+ MapIOR anOldHypos, aNewHypos;
+ if ( myGeomShape->_is_nil() )
+ return false;
+ // 1. Check whether the geometric shape has changed
+ SALOMEDS::SObject_var aSubMeshSO = SMESH::FindSObject( mySubMesh );
+ GEOM::GEOM_Object_var aIniGeomShape = SMESH::GetShapeOnMeshOrSubMesh( aSubMeshSO );
+ bool bShapeChanged = aIniGeomShape->_is_nil() || !aIniGeomShape->_is_equivalent( myGeomShape );
+ if ( bShapeChanged ) {
+ // VSR : TODO : Set new shape - not supported yet by engine
+ // 1. remove all old hypotheses and algorithms
+ // 2. set new shape
+ }
+ int nbFail = 0;
+ MapIOR::iterator it;
+ // 2. remove not used hypotheses from the submesh
+ for ( it = myMapOldHypos.begin(); it != myMapOldHypos.end(); ++it ) {
+ string ior = it->first;
+ int index = findItem( ListHypAssignation, ior );
+ if ( index < 0 ) {
+ SMESH::SMESH_Hypothesis_var aHyp = SMESH::IORToInterface<SMESH::SMESH_Hypothesis>(ior.c_str());
+ if ( !aHyp->_is_nil() ){
+ if (!SMESH::RemoveHypothesisOrAlgorithmOnMesh( aSubMeshSO, aHyp ))
+ nbFail++;
+ }
+ }
+ }
+ // 3. remove not used algorithms from the submesh
+ for ( it = myMapOldAlgos.begin(); it != myMapOldAlgos.end(); ++it ) {
+ string ior = it->first;
+ int index = findItem( ListAlgoAssignation, ior );
+ if ( index < 0 ) {
+ SMESH::SMESH_Hypothesis_var aHyp = SMESH::IORToInterface<SMESH::SMESH_Hypothesis>(ior.c_str());
+ if ( !aHyp->_is_nil() ){
+ if (!SMESH::RemoveHypothesisOrAlgorithmOnMesh( aSubMeshSO, aHyp ))
+ nbFail++;
+ }
+ }
+ }
+ // 4. Add new algorithms
+ for ( int i = 0; i < ListAlgoAssignation->count(); i++ ) {
+ if ( ListAlgoAssignation->item( i )->rtti() == ListBoxIOR::RTTI_IOR ) {
+ ListBoxIOR* anItem = ( ListBoxIOR* )( ListAlgoAssignation->item( i ) );
+ if ( anItem ) {
+ string ior = anItem->GetIOR();
+ if ( myMapOldAlgos.find( ior ) == myMapOldAlgos.end() ) {
+ SMESH::SMESH_Hypothesis_var aHyp = SMESH::IORToInterface<SMESH::SMESH_Hypothesis>(ior.c_str());
+ if ( !aHyp->_is_nil() ){
+ if (!SMESH::AddHypothesisOnSubMesh( mySubMesh, aHyp ))
+ nbFail++;
+ }
+ }
+ }
+ }
+ }
+ // 5. Add new hypotheses
+ for ( int i = 0; i < ListHypAssignation->count(); i++ ) {
+ if ( ListHypAssignation->item( i )->rtti() == ListBoxIOR::RTTI_IOR ) {
+ ListBoxIOR* anItem = ( ListBoxIOR* )( ListHypAssignation->item( i ) );
+ if ( anItem ) {
+ string ior = anItem->GetIOR();
+ if ( myMapOldHypos.find( ior ) == myMapOldHypos.end() ) {
+ SMESH::SMESH_Hypothesis_var aHyp = SMESH::IORToInterface<SMESH::SMESH_Hypothesis>(ior.c_str());
+ if ( !aHyp->_is_nil() ){
+ if (!SMESH::AddHypothesisOnSubMesh( mySubMesh, aHyp ))
+ nbFail++;
+ }
+ }
+ }
+ }
+ }
+ return ( nbFail == 0 );
+}