1 // Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // SMESH SMESHGUI : GUI for SMESH component
24 // File : SMESHGUI_HypothesesUtils.cxx
25 // Author : Julia DOROVSKIKH, Open CASCADE S.A.S.
28 #include "SMESHGUI_HypothesesUtils.h"
31 #include "SMESHGUI_Hypotheses.h"
32 #include "SMESHGUI_XmlHandler.h"
33 #include "SMESHGUI_Utils.h"
34 #include "SMESHGUI_GEOMGenUtils.h"
36 // SALOME GUI includes
37 #include <SUIT_Desktop.h>
38 #include <SUIT_MessageBox.h>
39 #include <SUIT_OverrideCursor.h>
40 #include <SUIT_ResourceMgr.h>
42 #include <SalomeApp_Study.h>
43 #include <SalomeApp_Tools.h>
45 // SALOME KERNEL includes
46 #include <utilities.h>
63 #define LibHandle HMODULE
64 #define LoadLib( name ) LoadLibrary( name )
65 #define GetProc GetProcAddress
66 #define UnLoadLib( handle ) FreeLibrary( handle );
68 #define LibHandle void*
69 #define LoadLib( name ) dlopen( name, RTLD_LAZY )
71 #define UnLoadLib( handle ) dlclose( handle );
75 static int MYDEBUG = 0;
77 static int MYDEBUG = 0;
82 typedef IMap<QString,HypothesisData*> THypothesisDataMap;
83 THypothesisDataMap myHypothesesMap;
84 THypothesisDataMap myAlgorithmsMap;
87 //typedef QMap<QString,SMESHGUI_GenericHypothesisCreator*> THypCreatorMap;
88 //THypCreatorMap myHypCreatorMap;
90 QList<HypothesesSet*> myListOfHypothesesSets;
92 void processHypothesisStatus(const int theHypStatus,
93 SMESH::SMESH_Hypothesis_ptr theHyp,
94 const bool theIsAddition,
95 const char* theError = 0)
97 if (theHypStatus > SMESH::HYP_OK) {
99 QString aHypName ("NULL Hypothesis");
100 if (!CORBA::is_nil(theHyp)) {
101 _PTR(SObject) Shyp = SMESH::FindSObject(theHyp);
104 aHypName = Shyp->GetName().c_str();
108 CORBA::String_var hypType = theHyp->GetName();
109 aHypName = GetHypothesisData( hypType.in() )->Label;
114 bool isFatal = (theHypStatus >= SMESH::HYP_UNKNOWN_FATAL);
117 aMsg = (isFatal ? "SMESH_CANT_ADD_HYP" : "SMESH_ADD_HYP_WRN");
119 aMsg = (isFatal ? "SMESH_CANT_RM_HYP" : "SMESH_RM_HYP_WRN");
121 aMsg = QObject::tr(aMsg.toLatin1().data()).arg(aHypName);
123 if ( theError && theError[0] )
129 aMsg += QObject::tr(QString("SMESH_HYP_%1").arg(theHypStatus).toLatin1().data());
131 if ( theHypStatus == SMESH::HYP_HIDDEN_ALGO ) { // PAL18501
132 CORBA::String_var hypType = theHyp->GetName();
133 if ( HypothesisData* hd = GetHypothesisData( hypType.in() ))
134 aMsg = aMsg.arg( hd->Dim[0] );
137 SUIT_MessageBox::warning(SMESHGUI::desktop(),
138 QObject::tr("SMESH_WRN_WARNING"),
143 //================================================================================
145 * \brief Prepends dimension and appends '[custom]' to the name of hypothesis set
147 //================================================================================
149 static QString mangledHypoSetName(HypothesesSet* hypSet)
151 QString name = hypSet->name();
154 int dim = hypSet->maxDim();
156 name = QString("%1D: %2").arg(dim).arg(name);
159 if ( hypSet->getIsCustom() )
160 name = QString("%1 [custom]").arg(name);
165 //================================================================================
167 * \brief Removes dimension and '[custom]' from the name of hypothesis set
169 //================================================================================
171 static QString demangledHypoSetName(QString name)
173 name.remove(QRegExp("[0-3]D: "));
174 name.remove(" [custom]");
178 void InitAvailableHypotheses()
180 SUIT_OverrideCursor wc;
181 if ( myHypothesesMap.empty() && myAlgorithmsMap.empty() )
184 SUIT_ResourceMgr* resMgr = SMESHGUI::resourceMgr();
187 // Find name of a resource XML file ("SMESH_Meshers.xml");
189 char* cenv = getenv("SMESH_MeshersList");
191 HypsXml.sprintf("%s", cenv);
193 QStringList HypsXmlList = HypsXml.split(":", QString::SkipEmptyParts);
194 if (HypsXmlList.count() == 0) {
195 SUIT_MessageBox::critical(SMESHGUI::desktop(),
196 QObject::tr("SMESH_WRN_WARNING"),
197 QObject::tr("MESHERS_FILE_NO_VARIABLE"));
200 // get full names of xml files from HypsXmlList
201 QStringList xmlFiles;
202 xmlFiles.append( QDir::home().filePath("CustomMeshers.xml")); // may be inexistent
203 for (int i = 0; i < HypsXmlList.count(); i++) {
204 QString HypsXml = HypsXmlList[ i ];
206 // Find full path to the resource XML file
207 QString xmlFile = resMgr->path("resources", "SMESH", HypsXml + ".xml");
208 if ( xmlFile.isEmpty() ) // try PLUGIN resources
209 xmlFile = resMgr->path("resources", HypsXml, HypsXml + ".xml");
210 if ( !xmlFile.isEmpty() )
211 xmlFiles.append( xmlFile );
215 QString aNoAccessFiles;
216 for (int i = 0; i < xmlFiles.count(); i++)
218 QString xmlFile = xmlFiles[ i ];
219 QFile file (xmlFile);
220 if (file.exists() && file.open(QIODevice::ReadOnly))
224 SMESHGUI_XmlHandler* aXmlHandler = new SMESHGUI_XmlHandler();
227 QXmlInputSource source (&file);
228 QXmlSimpleReader reader;
229 reader.setContentHandler(aXmlHandler);
230 reader.setErrorHandler(aXmlHandler);
231 bool ok = reader.parse(source);
235 THypothesisDataMap::ConstIterator it1 = aXmlHandler->myHypothesesMap.begin();
237 for( ;it1 != aXmlHandler->myHypothesesMap.end(); it1++)
238 myHypothesesMap.insert( it1.key(), it1.value() );
240 it1 = aXmlHandler->myAlgorithmsMap.begin();
241 for( ;it1 != aXmlHandler->myAlgorithmsMap.end(); it1++)
242 myAlgorithmsMap.insert( it1.key(), it1.value() );
244 QList<HypothesesSet*>::iterator it;
245 for ( it = aXmlHandler->myListOfHypothesesSets.begin();
246 it != aXmlHandler->myListOfHypothesesSets.end();
249 (*it)->setIsCustom( i == 0 );
250 myListOfHypothesesSets.append( *it );
254 SUIT_MessageBox::critical(SMESHGUI::desktop(),
255 QObject::tr("INF_PARSE_ERROR"),
256 QObject::tr(aXmlHandler->errorProtocol().toLatin1().data()));
260 else if ( i > 0 ) { // 1st is ~/CustomMeshers.xml
261 if (aNoAccessFiles.isEmpty())
262 aNoAccessFiles = xmlFile;
264 aNoAccessFiles += ", " + xmlFile;
266 } // end loop on xmlFiles
269 if (!aNoAccessFiles.isEmpty()) {
270 QString aMess = QObject::tr("MESHERS_FILE_CANT_OPEN") + " " + aNoAccessFiles + "\n";
271 aMess += QObject::tr("MESHERS_FILE_CHECK_VARIABLE");
273 SUIT_MessageBox::warning(SMESHGUI::desktop(),
274 QObject::tr("SMESH_WRN_WARNING"),
282 QStringList GetAvailableHypotheses( const bool isAlgo,
285 const bool hasGeometry,
286 const bool isSubMesh)
288 QStringList aHypList;
290 // Init list of available hypotheses, if needed
291 InitAvailableHypotheses();
292 bool checkGeometry = ( isAlgo );
293 const char* context = isSubMesh ? "LOCAL" : "GLOBAL";
294 // fill list of hypotheses/algorithms
295 THypothesisDataMap& pMap = isAlgo ? myAlgorithmsMap : myHypothesesMap;
296 THypothesisDataMap::ConstIterator anIter;
297 for ( anIter = pMap.begin(); anIter != pMap.end(); anIter++ )
299 HypothesisData* aData = anIter.value();
300 if (( aData && !aData->Label.isEmpty() ) &&
301 ( theDim < 0 || aData->Dim.contains( theDim )) &&
302 ( isAlgo || aData->IsAuxOrNeedHyp == isAux ) &&
303 ( aData->Context == "ANY" || aData->Context == context ) &&
304 ( !checkGeometry || (!aData->IsNeedGeometry ||
305 ( aData->IsNeedGeometry > 0 ) == hasGeometry)))
307 aHypList.append(anIter.key());
314 QStringList GetHypothesesSets(int maxDim)
316 QStringList aSetNameList;
318 // Init list of available hypotheses, if needed
319 InitAvailableHypotheses();
320 QList<HypothesesSet*>::iterator hypoSet;
321 for ( hypoSet = myListOfHypothesesSets.begin();
322 hypoSet != myListOfHypothesesSets.end();
324 HypothesesSet* aSet = *hypoSet;
325 if ( aSet && ( aSet->count( true ) || aSet->count( false )) &&
326 aSet->maxDim() <= maxDim)
328 aSetNameList.append( mangledHypoSetName( aSet ));
331 aSetNameList.removeDuplicates();
334 // reverse order of aSetNameList
335 QStringList reversedNames;
336 for ( int i = 0; i < aSetNameList.count(); ++i )
337 reversedNames.prepend( aSetNameList[i] );
339 return reversedNames;
342 HypothesesSet* GetHypothesesSet(const QString& theSetName)
344 QString name = demangledHypoSetName( theSetName );
345 QList<HypothesesSet*>::iterator hypoSet;
346 for ( hypoSet = myListOfHypothesesSets.begin();
347 hypoSet != myListOfHypothesesSets.end();
349 HypothesesSet* aSet = *hypoSet;
350 if ( aSet && aSet->name() == name )
356 HypothesisData* GetHypothesisData (const QString& aHypType)
358 HypothesisData* aHypData = 0;
360 // Init list of available hypotheses, if needed
361 InitAvailableHypotheses();
363 if (myHypothesesMap.contains(aHypType)) {
364 aHypData = myHypothesesMap[aHypType];
366 else if (myAlgorithmsMap.contains(aHypType)) {
367 aHypData = myAlgorithmsMap[aHypType];
372 //================================================================================
374 * \brief Return the HypothesisData holding a name of a group of hypotheses
375 * a given hypothesis belongs to
377 //================================================================================
379 HypothesisData* GetGroupTitle( const HypothesisData* hyp, const bool isAlgo )
381 static std::vector< std::vector< HypothesisData > > theGroups;
382 if ( theGroups.empty() )
384 theGroups.resize(14); // 14: isAlgo * 10 + dim
386 QString dummyS("GROUP");
387 QList<int> dummyIL; dummyIL << 1;
389 HypothesisData group( dummyS,dummyS,dummyS,dummyS,dummyS,dummyS,dummyS,-1,-1,
390 dummyIL, 0, dummySL,dummySL,dummySL,dummySL,0,0 );
393 theGroups[ key ].push_back( group );
398 group.Label = "GROUP:" + QObject::tr( "SMESH_1D_ALGO_GROUP_BASIC" );
399 theGroups[ key ].push_back( group );
401 group.Label = "GROUP:" + QObject::tr( "SMESH_1D_ALGO_GROUP_ADVANCED" );
402 theGroups[ key ].push_back( group );
407 group.Label = "GROUP:" + QObject::tr( "SMESH_1D_HYP_GROUP_BASIC" );
408 theGroups[ key ].push_back( group );
410 group.Label = "GROUP:" + QObject::tr( "SMESH_1D_HYP_GROUP_PROGRESSION" );
411 theGroups[ key ].push_back( group );
413 group.Label = "GROUP:" + QObject::tr( "SMESH_1D_HYP_GROUP_ADVANCED" );
414 theGroups[ key ].push_back( group );
419 group.Label = "GROUP:" + QObject::tr( "SMESH_2D_ALGO_GROUP_REGULAR" );
420 theGroups[ key ].push_back( group );
422 group.Label = "GROUP:" + QObject::tr( "SMESH_2D_ALGO_GROUP_FREE" );
423 theGroups[ key ].push_back( group );
425 group.Label = "GROUP:" + QObject::tr( "SMESH_2D_ALGO_GROUP_ADVANCED" );
426 theGroups[ key ].push_back( group );
431 group.Label = "GROUP:" + QObject::tr( "SMESH_3D_ALGO_GROUP_REGULAR" );
432 theGroups[ key ].push_back( group );
434 group.Label = "GROUP:" + QObject::tr( "SMESH_3D_ALGO_GROUP_FREE" );
435 theGroups[ key ].push_back( group );
437 group.Label = "GROUP:" + QObject::tr( "SMESH_3D_ALGO_GROUP_ADVANCED" );
438 theGroups[ key ].push_back( group );
441 size_t key = 0, groupID = 0;
442 if ( hyp && !hyp->Dim.isEmpty() )
444 key = hyp->Dim[0] + isAlgo * 10;
445 groupID = hyp->GroupID;
448 if ( key < theGroups.size() && !theGroups[ key ].empty() )
450 std::vector< HypothesisData > & group = theGroups[ key ];
451 return & ( groupID < group.size() ? group[ groupID ] : group.back() );
453 return & theGroups[ 0 ][ 0 ];
456 bool IsAvailableHypothesis(const HypothesisData* algoData,
457 const QString& hypType,
463 if ( algoData->BasicHypos.contains( hypType ))
465 if ( algoData->OptionalHypos.contains( hypType )) {
472 bool IsCompatibleAlgorithm(const HypothesisData* algo1Data,
473 const HypothesisData* algo2Data)
475 if ( !algo1Data || !algo2Data )
477 const HypothesisData* algoIn = algo1Data, *algoMain = algo2Data;
478 if ( algoIn->Dim.first() > algoMain->Dim.first() ) {
479 algoIn = algo2Data; algoMain = algo1Data;
481 // look for any output type of algoIn between input types of algoMain
482 QStringList::const_iterator inElemType = algoIn->OutputTypes.begin();
483 for ( ; inElemType != algoIn->OutputTypes.end(); ++inElemType )
484 if ( algoMain->InputTypes.contains( *inElemType ))
489 SMESHGUI_GenericHypothesisCreator* GetHypothesisCreator(const QString& aHypType)
491 if(MYDEBUG) MESSAGE("Get HypothesisCreator for " << aHypType.toLatin1().data());
493 SMESHGUI_GenericHypothesisCreator* aCreator = 0;
495 // check, if creator for this hypothesis type already exists
497 //if (myHypCreatorMap.find(aHypType) != myHypCreatorMap.end()) {
498 // aCreator = myHypCreatorMap[aHypType];
502 // 1. Init list of available hypotheses, if needed
503 InitAvailableHypotheses();
505 // 2. Get names of plugin libraries
506 HypothesisData* aHypData = GetHypothesisData(aHypType);
510 QString aClientLibName = aHypData->ClientLibName;
511 QString aServerLibName = aHypData->ServerLibName;
513 // 3. Load Client Plugin Library
515 // load plugin library
516 if(MYDEBUG) MESSAGE("Loading client meshers plugin library ...");
517 LibHandle libHandle = LoadLib( aClientLibName.toLatin1().data() );
519 // report any error, if occured
522 const char* anError = "Can't load client meshers plugin library";
524 const char* anError = dlerror();
526 INFOS(anError); // always display this kind of error !
530 // get method, returning hypothesis creator
531 if(MYDEBUG) MESSAGE("Find GetHypothesisCreator() method ...");
532 typedef SMESHGUI_GenericHypothesisCreator* (*GetHypothesisCreator) \
534 GetHypothesisCreator procHandle =
535 (GetHypothesisCreator)GetProc(libHandle, "GetHypothesisCreator");
537 if(MYDEBUG) MESSAGE("bad hypothesis client plugin library");
538 UnLoadLib(libHandle);
541 // get hypothesis creator
542 if(MYDEBUG) MESSAGE("Get Hypothesis Creator for " << aHypType.toLatin1().data());
543 aCreator = procHandle( aHypType );
545 if(MYDEBUG) MESSAGE("no such a hypothesis in this plugin");
548 // map hypothesis creator to a hypothesis name
550 //myHypCreatorMap[aHypType] = aCreator;
552 //rnv : This dynamic property of the QObject stores the name of the plugin.
553 // It is used to obtain plugin root dir environment variable
554 // in the SMESHGUI_HypothesisDlg class. Plugin root dir environment
555 // variable is used to display documentation.
556 aCreator->setProperty(SMESH::Plugin_Name(),aHypData->PluginName);
561 catch (const SALOME::SALOME_Exception& S_ex) {
562 SalomeApp_Tools::QtCatchCorbaException(S_ex);
570 SMESH::SMESH_Hypothesis_ptr CreateHypothesis(const QString& aHypType,
571 const QString& aHypName,
574 if(MYDEBUG) MESSAGE("Create " << aHypType.toLatin1().data() <<
575 " with name " << aHypName.toLatin1().data());
576 HypothesisData* aHypData = GetHypothesisData(aHypType);
577 QString aServLib = aHypData->ServerLibName;
579 SMESH::SMESH_Hypothesis_var aHypothesis;
580 aHypothesis = SMESHGUI::GetSMESHGen()->CreateHypothesis(aHypType.toLatin1().data(),
581 aServLib.toLatin1().data());
582 if (!aHypothesis->_is_nil()) {
583 _PTR(SObject) aHypSObject = SMESH::FindSObject(aHypothesis.in());
585 if (!aHypName.isEmpty())
586 SMESH::SetName(aHypSObject, aHypName);
587 SMESHGUI::Modified();
588 SMESHGUI::GetSMESHGUI()->updateObjBrowser();
589 return aHypothesis._retn();
592 } catch (const SALOME::SALOME_Exception & S_ex) {
593 SalomeApp_Tools::QtCatchCorbaException(S_ex);
596 return SMESH::SMESH_Hypothesis::_nil();
599 bool IsApplicable(const QString& aHypType,
600 GEOM::GEOM_Object_ptr theGeomObject,
601 const bool toCheckAll)
603 if ( getenv("NO_LIMIT_ALGO_BY_SHAPE")) // allow a workaround for a case if
604 return true; // IsApplicable() returns false due to a bug
606 HypothesisData* aHypData = GetHypothesisData(aHypType);
607 QString aServLib = aHypData->ServerLibName;
608 return SMESHGUI::GetSMESHGen()->IsApplicable( aHypType.toLatin1().data(),
609 aServLib.toLatin1().data(),
615 bool AddHypothesisOnMesh (SMESH::SMESH_Mesh_ptr aMesh, SMESH::SMESH_Hypothesis_ptr aHyp)
617 if(MYDEBUG) MESSAGE ("SMESHGUI::AddHypothesisOnMesh");
618 int res = SMESH::HYP_UNKNOWN_FATAL;
619 SUIT_OverrideCursor wc;
621 if (!aMesh->_is_nil()) {
622 _PTR(SObject) SM = SMESH::FindSObject(aMesh);
623 GEOM::GEOM_Object_var aShapeObject = SMESH::GetShapeOnMeshOrSubMesh(SM);
625 CORBA::String_var error;
626 res = aMesh->AddHypothesis(aShapeObject, aHyp, error.out());
627 if (res < SMESH::HYP_UNKNOWN_FATAL) {
628 _PTR(SObject) aSH = SMESH::FindSObject(aHyp);
630 SMESH::ModifiedMesh(SM, false, aMesh->NbNodes()==0);
633 if (res > SMESH::HYP_OK) {
635 processHypothesisStatus(res, aHyp, true, error.in() );
639 catch(const SALOME::SALOME_Exception& S_ex) {
641 SalomeApp_Tools::QtCatchCorbaException(S_ex);
642 res = SMESH::HYP_UNKNOWN_FATAL;
645 return res < SMESH::HYP_UNKNOWN_FATAL;
649 bool AddHypothesisOnSubMesh (SMESH::SMESH_subMesh_ptr aSubMesh, SMESH::SMESH_Hypothesis_ptr aHyp)
651 if(MYDEBUG) MESSAGE("SMESHGUI::AddHypothesisOnSubMesh() ");
652 int res = SMESH::HYP_UNKNOWN_FATAL;
653 SUIT_OverrideCursor wc;
655 if (!aSubMesh->_is_nil() && ! aHyp->_is_nil()) {
657 SMESH::SMESH_Mesh_var aMesh = aSubMesh->GetFather();
658 _PTR(SObject) SsubM = SMESH::FindSObject(aSubMesh);
659 GEOM::GEOM_Object_var aShapeObject = SMESH::GetShapeOnMeshOrSubMesh(SsubM);
660 if (!aMesh->_is_nil() && SsubM && !aShapeObject->_is_nil())
662 CORBA::String_var error;
663 res = aMesh->AddHypothesis( aShapeObject, aHyp, error.out() );
664 if (res < SMESH::HYP_UNKNOWN_FATAL) {
665 _PTR(SObject) meshSO = SMESH::FindSObject(aMesh);
667 SMESH::ModifiedMesh(meshSO, false, aMesh->NbNodes()==0);
669 if (res > SMESH::HYP_OK) {
671 processHypothesisStatus( res, aHyp, true, error.in() );
676 SCRUTE(aHyp->_is_nil());
677 SCRUTE(aMesh->_is_nil());
679 SCRUTE(aShapeObject->_is_nil());
682 catch(const SALOME::SALOME_Exception& S_ex) {
684 SalomeApp_Tools::QtCatchCorbaException(S_ex);
685 res = SMESH::HYP_UNKNOWN_FATAL;
689 SCRUTE(aSubMesh->_is_nil());
690 SCRUTE(aHyp->_is_nil());
692 return res < SMESH::HYP_UNKNOWN_FATAL;
695 bool RemoveHypothesisOrAlgorithmOnMesh (const Handle(SALOME_InteractiveObject)& IObject)
697 int res = SMESH::HYP_UNKNOWN_FATAL;
698 SUIT_OverrideCursor wc;
701 _PTR(Study) aStudy = GetActiveStudyDocument();
702 _PTR(SObject) aHypObj = aStudy->FindObjectID( IObject->getEntry() );
705 _PTR(SObject) MorSM = SMESH::GetMeshOrSubmesh( aHypObj );
706 _PTR(SObject) aRealHypo;
707 if( aHypObj->ReferencedObject( aRealHypo ) )
709 SMESH_Hypothesis_var hypo = SMESH_Hypothesis::_narrow( SObjectToObject( aRealHypo ) );
710 RemoveHypothesisOrAlgorithmOnMesh( MorSM, hypo );
714 SMESH_Hypothesis_var hypo = SMESH_Hypothesis::_narrow( SObjectToObject( aHypObj ) );
715 SObjectList meshList = GetMeshesUsingAlgoOrHypothesis( hypo );
716 for( size_t i = 0; i < meshList.size(); i++ )
717 RemoveHypothesisOrAlgorithmOnMesh( meshList[ i ], hypo );
721 catch(const SALOME::SALOME_Exception& S_ex)
724 SalomeApp_Tools::QtCatchCorbaException(S_ex);
725 res = SMESH::HYP_UNKNOWN_FATAL;
727 return res < SMESH::HYP_UNKNOWN_FATAL;
730 bool RemoveHypothesisOrAlgorithmOnMesh (_PTR(SObject) MorSM,
731 SMESH::SMESH_Hypothesis_ptr anHyp)
733 int res = SMESH::HYP_UNKNOWN_FATAL;
734 SUIT_OverrideCursor wc;
738 GEOM::GEOM_Object_var aShapeObject = SMESH::GetShapeOnMeshOrSubMesh(MorSM);
739 SMESH::SMESH_Mesh_var aMesh = SMESH::SObjectToInterface<SMESH::SMESH_Mesh>(MorSM);
740 SMESH::SMESH_subMesh_var aSubMesh = SMESH::SObjectToInterface<SMESH::SMESH_subMesh>(MorSM);
742 if (!aSubMesh->_is_nil())
743 aMesh = aSubMesh->GetFather();
745 if (!aMesh->_is_nil()) {
746 if (aMesh->HasShapeToMesh() && !aShapeObject->_is_nil()) {
747 res = aMesh->RemoveHypothesis(aShapeObject, anHyp);
748 if (res < SMESH::HYP_UNKNOWN_FATAL) {
749 _PTR(SObject) meshSO = SMESH::FindSObject(aMesh);
751 SMESH::ModifiedMesh(meshSO, false, aMesh->NbNodes()==0);
755 else if(!aMesh->HasShapeToMesh()){
756 res = aMesh->RemoveHypothesis(aShapeObject, anHyp);
757 if (res < SMESH::HYP_UNKNOWN_FATAL) {
758 _PTR(SObject) meshSO = SMESH::FindSObject(aMesh);
760 SMESH::ModifiedMesh(meshSO, false, aMesh->NbNodes()==0);
763 if (res > SMESH::HYP_OK) {
765 processHypothesisStatus(res, anHyp, false);
769 } catch(const SALOME::SALOME_Exception& S_ex) {
771 SalomeApp_Tools::QtCatchCorbaException(S_ex);
772 res = SMESH::HYP_UNKNOWN_FATAL;
775 return res < SMESH::HYP_UNKNOWN_FATAL;
778 SObjectList GetMeshesUsingAlgoOrHypothesis(SMESH::SMESH_Hypothesis_ptr AlgoOrHyp)
780 SObjectList listSOmesh;
781 listSOmesh.resize(0);
783 unsigned int index = 0;
784 if (!AlgoOrHyp->_is_nil()) {
785 _PTR(SObject) SO_Hypothesis = SMESH::FindSObject(AlgoOrHyp);
788 SMESHGUI::activeStudy()->studyDS()->FindDependances(SO_Hypothesis);
790 if(MYDEBUG) MESSAGE("SMESHGUI::GetMeshesUsingAlgoOrHypothesis(): dependency number ="<<listSO.size());
791 for (unsigned int i = 0; i < listSO.size(); i++) {
792 _PTR(SObject) SO = listSO[i];
794 _PTR(SObject) aFather = SO->GetFather();
796 _PTR(SObject) SOfatherFather = aFather->GetFather();
797 if (SOfatherFather) {
798 if(MYDEBUG) MESSAGE("SMESHGUI::GetMeshesUsingAlgoOrHypothesis(): dependency added to list");
800 listSOmesh.resize(index);
801 listSOmesh[index - 1] = SOfatherFather;
808 if (MYDEBUG) MESSAGE("SMESHGUI::GetMeshesUsingAlgoOrHypothesis(): completed");
812 #define CASE2MESSAGE(enum) case SMESH::enum: msg = QObject::tr( "STATE_" #enum ); break;
813 QString GetMessageOnAlgoStateErrors(const algo_error_array& errors)
815 QString resMsg; // PAL14861 = QObject::tr("SMESH_WRN_MISSING_PARAMETERS") + ":\n";
816 for ( size_t i = 0; i < errors.length(); ++i ) {
817 const SMESH::AlgoStateError & error = errors[ i ];
818 const bool hasAlgo = ( strlen( error.algoName ) != 0 );
821 msg = QObject::tr( "STATE_ALGO_MISSING" );
823 switch( error.state ) {
824 CASE2MESSAGE( HYP_MISSING );
825 CASE2MESSAGE( HYP_NOTCONFORM );
826 CASE2MESSAGE( HYP_BAD_PARAMETER );
827 CASE2MESSAGE( HYP_BAD_GEOMETRY );
830 // apply args to message:
833 msg = msg.arg( error.algoName.in() );
835 msg = msg.arg( error.algoDim );
837 msg = msg.arg( QObject::tr( error.isGlobalAlgo ? "GLOBAL_ALGO" : "LOCAL_ALGO" ));
838 // %4 - hypothesis dim == algoDim
839 msg = msg.arg( error.algoDim );
841 if ( i ) resMsg += ";\n";
846 } // end of namespace SMESH