1 // Copyright (C) 2007-2019 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_GEOMGenUtils.h"
32 #include "SMESHGUI_Hypotheses.h"
33 #include "SMESHGUI_Utils.h"
34 #include "SMESHGUI_VTKUtils.h"
35 #include "SMESHGUI_XmlHandler.h"
37 #include "SMESH_Actor.h"
39 // SALOME GUI includes
40 #include <SUIT_Desktop.h>
41 #include <SUIT_MessageBox.h>
42 #include <SUIT_OverrideCursor.h>
43 #include <SUIT_ResourceMgr.h>
45 #include <SalomeApp_Study.h>
46 #include <SalomeApp_Tools.h>
48 // SALOME KERNEL includes
49 #include <utilities.h>
66 #define LibHandle HMODULE
67 #define LoadLib( name ) LoadLibrary( name )
68 #define GetProc GetProcAddress
69 #define UnLoadLib( handle ) FreeLibrary( handle );
72 #define LibHandle void*
74 #define LoadLib( name ) dlopen( name, RTLD_LAZY | RTLD_LOCAL )
75 #else // DYNLOAD_LOCAL
76 #define LoadLib( name ) dlopen( name, RTLD_LAZY | RTLD_GLOBAL )
77 #endif // DYNLOAD_LOCAL
79 #define UnLoadLib( handle ) dlclose( handle );
84 static int MYDEBUG = 0;
86 static int MYDEBUG = 0;
91 typedef IMap<QString,HypothesisData*> THypothesisDataMap;
92 THypothesisDataMap myHypothesesMap;
93 THypothesisDataMap myAlgorithmsMap;
96 //typedef QMap<QString,SMESHGUI_GenericHypothesisCreator*> THypCreatorMap;
97 //THypCreatorMap myHypCreatorMap;
99 QList<HypothesesSet*> myListOfHypothesesSets;
101 void processHypothesisStatus(const int theHypStatus,
102 SMESH::SMESH_Hypothesis_ptr theHyp,
103 const bool theIsAddition,
104 const char* theError = 0)
106 if (theHypStatus > SMESH::HYP_OK) {
108 QString aHypName ("NULL Hypothesis");
109 if (!CORBA::is_nil(theHyp)) {
110 _PTR(SObject) Shyp = SMESH::FindSObject(theHyp);
113 aHypName = Shyp->GetName().c_str();
117 CORBA::String_var hypType = theHyp->GetName();
118 aHypName = GetHypothesisData( hypType.in() )->Label;
123 bool isFatal = (theHypStatus >= SMESH::HYP_UNKNOWN_FATAL);
126 aMsg = (isFatal ? "SMESH_CANT_ADD_HYP" : "SMESH_ADD_HYP_WRN");
128 aMsg = (isFatal ? "SMESH_CANT_RM_HYP" : "SMESH_RM_HYP_WRN");
130 aMsg = QObject::tr(aMsg.toLatin1().data()).arg(aHypName);
132 if ( theError && theError[0] )
138 aMsg += QObject::tr(QString("SMESH_HYP_%1").arg(theHypStatus).toLatin1().data());
140 if ( theHypStatus == SMESH::HYP_HIDDEN_ALGO ) { // PAL18501
141 CORBA::String_var hypType = theHyp->GetName();
142 if ( HypothesisData* hd = GetHypothesisData( hypType.in() ))
143 aMsg = aMsg.arg( hd->Dim[0] );
146 SUIT_MessageBox::warning(SMESHGUI::desktop(),
147 QObject::tr("SMESH_WRN_WARNING"),
152 //================================================================================
154 * \brief Prepends dimension and appends '[custom]' to the name of hypothesis set
156 //================================================================================
158 static QString mangledHypoSetName(HypothesesSet* hypSet)
160 QString name = hypSet->name();
163 int dim = hypSet->maxDim();
165 name = QString("%1D: %2").arg(dim).arg(name);
168 if ( hypSet->getIsCustom() )
169 name = QString("%1 [custom]").arg(name);
174 //================================================================================
176 * \brief Removes dimension and '[custom]' from the name of hypothesis set
178 //================================================================================
180 static QString demangledHypoSetName(QString name)
182 name.remove(QRegExp("[0-3]D: "));
183 name.remove(" [custom]");
187 void InitAvailableHypotheses()
189 SUIT_OverrideCursor wc;
190 if ( myHypothesesMap.empty() && myAlgorithmsMap.empty() )
193 SUIT_ResourceMgr* resMgr = SMESHGUI::resourceMgr();
196 // Find name of a resource XML file ("SMESH_Meshers.xml");
198 char* cenv = getenv("SMESH_MeshersList");
200 HypsXml.sprintf("%s", cenv);
202 QStringList HypsXmlList = HypsXml.split(env_sep, QString::SkipEmptyParts);
203 if (HypsXmlList.count() == 0) {
204 SUIT_MessageBox::critical(SMESHGUI::desktop(),
205 QObject::tr("SMESH_WRN_WARNING"),
206 QObject::tr("MESHERS_FILE_NO_VARIABLE"));
209 // get full names of xml files from HypsXmlList
210 QStringList xmlFiles;
211 xmlFiles.append( QDir::home().filePath("CustomMeshers.xml")); // may be inexistent
212 for (int i = 0; i < HypsXmlList.count(); i++) {
213 QString HypsXml = HypsXmlList[ i ];
215 // Find full path to the resource XML file
216 QString xmlFile = resMgr->path("resources", "SMESH", HypsXml + ".xml");
217 if ( xmlFile.isEmpty() ) // try PLUGIN resources
218 xmlFile = resMgr->path("resources", HypsXml, HypsXml + ".xml");
219 if ( !xmlFile.isEmpty() )
220 xmlFiles.append( xmlFile );
224 QString aNoAccessFiles;
225 for (int i = 0; i < xmlFiles.count(); i++)
227 QString xmlFile = xmlFiles[ i ];
228 QFile file (xmlFile);
229 if (file.exists() && file.open(QIODevice::ReadOnly))
233 SMESHGUI_XmlHandler* aXmlHandler = new SMESHGUI_XmlHandler();
236 QXmlInputSource source (&file);
237 QXmlSimpleReader reader;
238 reader.setContentHandler(aXmlHandler);
239 reader.setErrorHandler(aXmlHandler);
240 bool ok = reader.parse(source);
244 THypothesisDataMap::ConstIterator it1 = aXmlHandler->myHypothesesMap.begin();
246 for( ;it1 != aXmlHandler->myHypothesesMap.end(); it1++)
247 myHypothesesMap.insert( it1.key(), it1.value() );
249 it1 = aXmlHandler->myAlgorithmsMap.begin();
250 for( ;it1 != aXmlHandler->myAlgorithmsMap.end(); it1++)
251 myAlgorithmsMap.insert( it1.key(), it1.value() );
253 QList<HypothesesSet*>::iterator it;
254 for ( it = aXmlHandler->myListOfHypothesesSets.begin();
255 it != aXmlHandler->myListOfHypothesesSets.end();
258 (*it)->setIsCustom( i == 0 );
259 myListOfHypothesesSets.append( *it );
263 SUIT_MessageBox::critical(SMESHGUI::desktop(),
264 QObject::tr("INF_PARSE_ERROR"),
265 QObject::tr(aXmlHandler->errorProtocol().toLatin1().data()));
269 else if ( i > 0 ) { // 1st is ~/CustomMeshers.xml
270 if (aNoAccessFiles.isEmpty())
271 aNoAccessFiles = xmlFile;
273 aNoAccessFiles += ", " + xmlFile;
275 } // end loop on xmlFiles
278 if (!aNoAccessFiles.isEmpty()) {
279 QString aMess = QObject::tr("MESHERS_FILE_CANT_OPEN") + " " + aNoAccessFiles + "\n";
280 aMess += QObject::tr("MESHERS_FILE_CHECK_VARIABLE");
282 SUIT_MessageBox::warning(SMESHGUI::desktop(),
283 QObject::tr("SMESH_WRN_WARNING"),
291 QStringList GetAvailableHypotheses( const bool isAlgo,
294 const bool hasGeometry,
295 const bool isSubMesh)
297 QStringList aHypList;
299 // Init list of available hypotheses, if needed
300 InitAvailableHypotheses();
301 bool checkGeometry = ( isAlgo );
302 const char* context = isSubMesh ? "LOCAL" : "GLOBAL";
303 // fill list of hypotheses/algorithms
304 THypothesisDataMap& pMap = isAlgo ? myAlgorithmsMap : myHypothesesMap;
305 THypothesisDataMap::ConstIterator anIter;
306 for ( anIter = pMap.begin(); anIter != pMap.end(); anIter++ )
308 HypothesisData* aData = anIter.value();
309 if (( aData && !aData->Label.isEmpty() ) &&
310 ( theDim < 0 || aData->Dim.contains( theDim )) &&
311 ( isAlgo || aData->IsAuxOrNeedHyp == isAux ) &&
312 ( aData->Context == "ANY" || aData->Context == context ) &&
313 ( !checkGeometry || (!aData->IsNeedGeometry ||
314 ( aData->IsNeedGeometry > 0 ) == hasGeometry)))
316 aHypList.append(anIter.key());
323 QStringList GetHypothesesSets(int maxDim)
325 QStringList aSetNameList;
327 // Init list of available hypotheses, if needed
328 InitAvailableHypotheses();
329 QList<HypothesesSet*>::iterator hypoSet;
330 for ( hypoSet = myListOfHypothesesSets.begin();
331 hypoSet != myListOfHypothesesSets.end();
333 HypothesesSet* aSet = *hypoSet;
334 if ( aSet && ( aSet->count( true ) || aSet->count( false )) &&
335 aSet->maxDim() <= maxDim)
337 aSetNameList.append( mangledHypoSetName( aSet ));
340 aSetNameList.removeDuplicates();
343 // reverse order of aSetNameList
344 QStringList reversedNames;
345 for ( int i = 0; i < aSetNameList.count(); ++i )
346 reversedNames.prepend( aSetNameList[i] );
348 return reversedNames;
351 HypothesesSet* GetHypothesesSet(const QString& theSetName)
353 QString name = demangledHypoSetName( theSetName );
354 QList<HypothesesSet*>::iterator hypoSet;
355 for ( hypoSet = myListOfHypothesesSets.begin();
356 hypoSet != myListOfHypothesesSets.end();
358 HypothesesSet* aSet = *hypoSet;
359 if ( aSet && aSet->name() == name )
365 HypothesisData* GetHypothesisData (const QString& aHypType)
367 HypothesisData* aHypData = 0;
369 // Init list of available hypotheses, if needed
370 InitAvailableHypotheses();
372 if (myHypothesesMap.contains(aHypType)) {
373 aHypData = myHypothesesMap[aHypType];
375 else if (myAlgorithmsMap.contains(aHypType)) {
376 aHypData = myAlgorithmsMap[aHypType];
381 //================================================================================
383 * \brief Return the HypothesisData holding a name of a group of hypotheses
384 * a given hypothesis belongs to
386 //================================================================================
388 HypothesisData* GetGroupTitle( const HypothesisData* hyp, const bool isAlgo )
390 static std::vector< std::vector< HypothesisData > > theGroups;
391 if ( theGroups.empty() )
393 theGroups.resize(14); // 14: isAlgo * 10 + dim
395 QString dummyS("GROUP");
396 QList<int> dummyIL; dummyIL << 1;
398 HypothesisData group( dummyS,dummyS,dummyS,dummyS,dummyS,dummyS,dummyS,-1,-1,
399 dummyIL, 0, dummySL,dummySL,dummySL,dummySL,0,0 );
402 theGroups[ key ].push_back( group );
407 group.Label = "GROUP:" + QObject::tr( "SMESH_1D_ALGO_GROUP_BASIC" );
408 theGroups[ key ].push_back( group );
410 group.Label = "GROUP:" + QObject::tr( "SMESH_1D_ALGO_GROUP_ADVANCED" );
411 theGroups[ key ].push_back( group );
416 group.Label = "GROUP:" + QObject::tr( "SMESH_1D_HYP_GROUP_BASIC" );
417 theGroups[ key ].push_back( group );
419 group.Label = "GROUP:" + QObject::tr( "SMESH_1D_HYP_GROUP_PROGRESSION" );
420 theGroups[ key ].push_back( group );
422 group.Label = "GROUP:" + QObject::tr( "SMESH_1D_HYP_GROUP_ADVANCED" );
423 theGroups[ key ].push_back( group );
428 group.Label = "GROUP:" + QObject::tr( "SMESH_2D_ALGO_GROUP_REGULAR" );
429 theGroups[ key ].push_back( group );
431 group.Label = "GROUP:" + QObject::tr( "SMESH_2D_ALGO_GROUP_FREE" );
432 theGroups[ key ].push_back( group );
434 group.Label = "GROUP:" + QObject::tr( "SMESH_2D_ALGO_GROUP_ADVANCED" );
435 theGroups[ key ].push_back( group );
440 group.Label = "GROUP:" + QObject::tr( "SMESH_3D_ALGO_GROUP_REGULAR" );
441 theGroups[ key ].push_back( group );
443 group.Label = "GROUP:" + QObject::tr( "SMESH_3D_ALGO_GROUP_FREE" );
444 theGroups[ key ].push_back( group );
446 group.Label = "GROUP:" + QObject::tr( "SMESH_3D_ALGO_GROUP_ADVANCED" );
447 theGroups[ key ].push_back( group );
450 size_t key = 0, groupID = 0;
451 if ( hyp && !hyp->Dim.isEmpty() )
453 key = hyp->Dim[0] + isAlgo * 10;
454 groupID = hyp->GroupID;
457 if ( key < theGroups.size() && !theGroups[ key ].empty() )
459 std::vector< HypothesisData > & group = theGroups[ key ];
460 return & ( groupID < group.size() ? group[ groupID ] : group.back() );
462 return & theGroups[ 0 ][ 0 ];
465 bool IsAvailableHypothesis(const HypothesisData* algoData,
466 const QString& hypType,
472 if ( algoData->BasicHypos.contains( hypType ))
474 if ( algoData->OptionalHypos.contains( hypType )) {
481 bool IsCompatibleAlgorithm(const HypothesisData* algo1Data,
482 const HypothesisData* algo2Data)
484 if ( !algo1Data || !algo2Data )
486 const HypothesisData* algoIn = algo1Data, *algoMain = algo2Data;
487 if ( algoIn->Dim.first() > algoMain->Dim.first() ) {
488 algoIn = algo2Data; algoMain = algo1Data;
490 // look for any output type of algoIn between input types of algoMain
491 QStringList::const_iterator inElemType = algoIn->OutputTypes.begin();
492 for ( ; inElemType != algoIn->OutputTypes.end(); ++inElemType )
493 if ( algoMain->InputTypes.contains( *inElemType ))
498 SMESHGUI_GenericHypothesisCreator* GetHypothesisCreator(const QString& aHypType)
500 if(MYDEBUG) MESSAGE("Get HypothesisCreator for " << aHypType.toLatin1().data());
502 SMESHGUI_GenericHypothesisCreator* aCreator = 0;
504 // check, if creator for this hypothesis type already exists
506 //if (myHypCreatorMap.find(aHypType) != myHypCreatorMap.end()) {
507 // aCreator = myHypCreatorMap[aHypType];
511 // 1. Init list of available hypotheses, if needed
512 InitAvailableHypotheses();
514 // 2. Get names of plugin libraries
515 HypothesisData* aHypData = GetHypothesisData(aHypType);
519 QString aClientLibName = aHypData->ClientLibName;
520 QString aServerLibName = aHypData->ServerLibName;
522 // 3. Load Client Plugin Library
524 // load plugin library
525 if(MYDEBUG) MESSAGE("Loading client meshers plugin library ...");
528 LPTSTR path = new TCHAR[aClientLibName.length() + 1];
529 path[aClientLibName.toWCharArray(path)] = '\0';
531 QByteArray baPath = aClientLibName.toUtf8();
532 const char* path = baPath.data();
535 QByteArray baPath = aClientLibName.toUtf8();
536 char* path = baPath.data();
538 LibHandle libHandle = LoadLib( path );
539 #if defined(WIN32) && defined(UNICODE)
543 // report any error, if occurred
546 const char* anError = "Can't load client meshers plugin library";
548 const char* anError = dlerror();
550 INFOS(anError); // always display this kind of error !
554 // get method, returning hypothesis creator
555 if(MYDEBUG) MESSAGE("Find GetHypothesisCreator() method ...");
556 typedef SMESHGUI_GenericHypothesisCreator* (*GetHypothesisCreator) \
558 GetHypothesisCreator procHandle =
559 (GetHypothesisCreator)GetProc(libHandle, "GetHypothesisCreator");
561 if(MYDEBUG) MESSAGE("bad hypothesis client plugin library");
562 UnLoadLib(libHandle);
565 // get hypothesis creator
566 if(MYDEBUG) MESSAGE("Get Hypothesis Creator for " << aHypType.toLatin1().data());
567 aCreator = procHandle( aHypType );
569 if(MYDEBUG) MESSAGE("no such a hypothesis in this plugin");
572 // map hypothesis creator to a hypothesis name
574 //myHypCreatorMap[aHypType] = aCreator;
576 //rnv : This dynamic property of the QObject stores the name of the plugin.
577 // It is used to obtain plugin root dir environment variable
578 // in the SMESHGUI_HypothesisDlg class. Plugin root dir environment
579 // variable is used to display documentation.
580 aCreator->setProperty(SMESH::Plugin_Name(),aHypData->PluginName);
585 catch (const SALOME::SALOME_Exception& S_ex) {
586 SalomeApp_Tools::QtCatchCorbaException(S_ex);
594 SMESH::SMESH_Hypothesis_ptr CreateHypothesis(const QString& aHypType,
595 const QString& aHypName,
598 if(MYDEBUG) MESSAGE("Create " << aHypType.toLatin1().data() <<
599 " with name " << aHypName.toLatin1().data());
600 HypothesisData* aHypData = GetHypothesisData(aHypType);
601 QString aServLib = aHypData->ServerLibName;
603 SMESH::SMESH_Hypothesis_var aHypothesis;
604 aHypothesis = SMESHGUI::GetSMESHGen()->CreateHypothesis(aHypType.toLatin1().data(),
605 aServLib.toUtf8().data());
606 if (!aHypothesis->_is_nil()) {
607 _PTR(SObject) aHypSObject = SMESH::FindSObject(aHypothesis.in());
609 if (!aHypName.isEmpty())
610 SMESH::SetName(aHypSObject, aHypName);
611 SMESHGUI::Modified();
612 SMESHGUI::GetSMESHGUI()->updateObjBrowser();
613 return aHypothesis._retn();
616 } catch (const SALOME::SALOME_Exception & S_ex) {
617 SalomeApp_Tools::QtCatchCorbaException(S_ex);
620 return SMESH::SMESH_Hypothesis::_nil();
623 bool IsApplicable(const QString& aHypType,
624 GEOM::GEOM_Object_ptr theGeomObject,
625 const bool toCheckAll)
627 if ( getenv("NO_LIMIT_ALGO_BY_SHAPE")) // allow a workaround for a case if
628 return true; // IsApplicable() returns false due to a bug
630 HypothesisData* aHypData = GetHypothesisData(aHypType);
631 QString aServLib = aHypData->ServerLibName;
632 return SMESHGUI::GetSMESHGen()->IsApplicable( aHypType.toLatin1().data(),
633 aServLib.toUtf8().data(),
639 bool AddHypothesisOnMesh (SMESH::SMESH_Mesh_ptr aMesh, SMESH::SMESH_Hypothesis_ptr aHyp)
641 if(MYDEBUG) MESSAGE ("SMESHGUI::AddHypothesisOnMesh");
642 int res = SMESH::HYP_UNKNOWN_FATAL;
643 SUIT_OverrideCursor wc;
645 if (!aMesh->_is_nil()) {
646 _PTR(SObject) SM = SMESH::FindSObject(aMesh);
647 GEOM::GEOM_Object_var aShapeObject = SMESH::GetShapeOnMeshOrSubMesh(SM);
649 CORBA::String_var error;
650 res = aMesh->AddHypothesis(aShapeObject, aHyp, error.out());
651 if (res > SMESH::HYP_OK) {
653 processHypothesisStatus(res, aHyp, true, error.in() );
657 catch(const SALOME::SALOME_Exception& S_ex) {
659 SalomeApp_Tools::QtCatchCorbaException(S_ex);
660 res = SMESH::HYP_UNKNOWN_FATAL;
663 return res < SMESH::HYP_UNKNOWN_FATAL;
667 bool AddHypothesisOnSubMesh (SMESH::SMESH_subMesh_ptr aSubMesh, SMESH::SMESH_Hypothesis_ptr aHyp)
669 if(MYDEBUG) MESSAGE("SMESHGUI::AddHypothesisOnSubMesh() ");
670 int res = SMESH::HYP_UNKNOWN_FATAL;
671 SUIT_OverrideCursor wc;
673 if ( !aSubMesh->_is_nil() && !aHyp->_is_nil() ) {
675 SMESH::SMESH_Mesh_var aMesh = aSubMesh->GetFather();
676 _PTR(SObject) SsubM = SMESH::FindSObject(aSubMesh);
677 GEOM::GEOM_Object_var aShapeObject = SMESH::GetShapeOnMeshOrSubMesh(SsubM);
678 if (!aMesh->_is_nil() && SsubM && !aShapeObject->_is_nil())
680 CORBA::String_var error;
681 res = aMesh->AddHypothesis( aShapeObject, aHyp, error.out() );
682 if (res > SMESH::HYP_OK) {
684 processHypothesisStatus( res, aHyp, true, error.in() );
689 SCRUTE(aHyp->_is_nil());
690 SCRUTE(aMesh->_is_nil());
692 SCRUTE(aShapeObject->_is_nil());
695 catch(const SALOME::SALOME_Exception& S_ex) {
697 SalomeApp_Tools::QtCatchCorbaException(S_ex);
698 res = SMESH::HYP_UNKNOWN_FATAL;
702 SCRUTE(aSubMesh->_is_nil());
703 SCRUTE(aHyp->_is_nil());
705 return res < SMESH::HYP_UNKNOWN_FATAL;
708 bool RemoveHypothesisOrAlgorithmOnMesh (const Handle(SALOME_InteractiveObject)& IObject)
710 int res = SMESH::HYP_UNKNOWN_FATAL;
711 SUIT_OverrideCursor wc;
714 _PTR(Study) aStudy = getStudy();
715 _PTR(SObject) aHypObj = aStudy->FindObjectID( IObject->getEntry() );
718 _PTR(SObject) MorSM = SMESH::GetMeshOrSubmesh( aHypObj );
719 _PTR(SObject) aRealHypo;
720 if( aHypObj->ReferencedObject( aRealHypo ) )
722 SMESH_Hypothesis_var hypo = SMESH_Hypothesis::_narrow( SObjectToObject( aRealHypo ) );
723 RemoveHypothesisOrAlgorithmOnMesh( MorSM, hypo );
727 SMESH_Hypothesis_var hypo = SMESH_Hypothesis::_narrow( SObjectToObject( aHypObj ) );
728 SObjectList meshList = GetMeshesUsingAlgoOrHypothesis( hypo );
729 for( size_t i = 0; i < meshList.size(); i++ )
730 RemoveHypothesisOrAlgorithmOnMesh( meshList[ i ], hypo );
734 catch(const SALOME::SALOME_Exception& S_ex)
737 SalomeApp_Tools::QtCatchCorbaException(S_ex);
738 res = SMESH::HYP_UNKNOWN_FATAL;
740 return res < SMESH::HYP_UNKNOWN_FATAL;
743 bool RemoveHypothesisOrAlgorithmOnMesh (_PTR(SObject) MorSM,
744 SMESH::SMESH_Hypothesis_ptr anHyp)
746 int res = SMESH::HYP_UNKNOWN_FATAL;
747 SUIT_OverrideCursor wc;
751 GEOM::GEOM_Object_var aShapeObject = SMESH::GetShapeOnMeshOrSubMesh(MorSM);
752 SMESH::SMESH_Mesh_var aMesh = SMESH::SObjectToInterface<SMESH::SMESH_Mesh>(MorSM);
753 SMESH::SMESH_subMesh_var aSubMesh = SMESH::SObjectToInterface<SMESH::SMESH_subMesh>(MorSM);
755 if (!aSubMesh->_is_nil())
756 aMesh = aSubMesh->GetFather();
758 if (!aMesh->_is_nil()) {
759 if (aMesh->HasShapeToMesh() && !aShapeObject->_is_nil()) {
760 res = aMesh->RemoveHypothesis(aShapeObject, anHyp);
762 else if(!aMesh->HasShapeToMesh()){
763 res = aMesh->RemoveHypothesis(aShapeObject, anHyp);
765 if (res > SMESH::HYP_OK) {
767 processHypothesisStatus(res, anHyp, false);
770 if ( _PTR(SObject) meshSO = SMESH::FindSObject(aMesh) )
772 if ( SMESH_Actor* actor = SMESH::FindActorByEntry( meshSO->GetID().c_str() ))
773 if( actor->GetVisibility() )
777 } catch(const SALOME::SALOME_Exception& S_ex) {
779 SalomeApp_Tools::QtCatchCorbaException(S_ex);
780 res = SMESH::HYP_UNKNOWN_FATAL;
783 return res < SMESH::HYP_UNKNOWN_FATAL;
786 SObjectList GetMeshesUsingAlgoOrHypothesis(SMESH::SMESH_Hypothesis_ptr AlgoOrHyp)
788 SObjectList listSOmesh;
789 listSOmesh.resize(0);
791 unsigned int index = 0;
792 if (!AlgoOrHyp->_is_nil()) {
793 _PTR(SObject) SO_Hypothesis = SMESH::FindSObject(AlgoOrHyp);
795 SObjectList listSO = SMESH::getStudy()->FindDependances(SO_Hypothesis);
797 if(MYDEBUG) MESSAGE("SMESHGUI::GetMeshesUsingAlgoOrHypothesis(): dependency number ="<<listSO.size());
798 for (unsigned int i = 0; i < listSO.size(); i++) {
799 _PTR(SObject) SO = listSO[i];
801 _PTR(SObject) aFather = SO->GetFather();
803 _PTR(SObject) SOfatherFather = aFather->GetFather();
804 if (SOfatherFather) {
805 if(MYDEBUG) MESSAGE("SMESHGUI::GetMeshesUsingAlgoOrHypothesis(): dependency added to list");
807 listSOmesh.resize(index);
808 listSOmesh[index - 1] = SOfatherFather;
815 if (MYDEBUG) MESSAGE("SMESHGUI::GetMeshesUsingAlgoOrHypothesis(): completed");
819 #define CASE2MESSAGE(enum) case SMESH::enum: msg = QObject::tr( "STATE_" #enum ); break;
820 QString GetMessageOnAlgoStateErrors(const algo_error_array& errors)
822 QString resMsg; // PAL14861 = QObject::tr("SMESH_WRN_MISSING_PARAMETERS") + ":\n";
823 for ( size_t i = 0; i < errors.length(); ++i ) {
824 const SMESH::AlgoStateError & error = errors[ i ];
825 const bool hasAlgo = ( strlen( error.algoName ) != 0 );
828 msg = QObject::tr( "STATE_ALGO_MISSING" );
830 switch( error.state ) {
831 CASE2MESSAGE( HYP_MISSING );
832 CASE2MESSAGE( HYP_NOTCONFORM );
833 CASE2MESSAGE( HYP_BAD_PARAMETER );
834 CASE2MESSAGE( HYP_BAD_GEOMETRY );
837 // apply args to message:
840 msg = msg.arg( error.algoName.in() );
842 msg = msg.arg( error.algoDim );
844 msg = msg.arg( QObject::tr( error.isGlobalAlgo ? "GLOBAL_ALGO" : "LOCAL_ALGO" ));
845 // %4 - hypothesis dim == algoDim
846 msg = msg.arg( error.algoDim );
848 if ( i ) resMsg += ";\n";
853 } // end of namespace SMESH