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 );
71 #define LibHandle void*
73 #define LoadLib( name ) dlopen( name, RTLD_LAZY | RTLD_LOCAL )
74 #else // DYNLOAD_LOCAL
75 #define LoadLib( name ) dlopen( name, RTLD_LAZY | RTLD_GLOBAL )
76 #endif // DYNLOAD_LOCAL
78 #define UnLoadLib( handle ) dlclose( handle );
82 static int MYDEBUG = 0;
84 static int MYDEBUG = 0;
89 typedef IMap<QString,HypothesisData*> THypothesisDataMap;
90 THypothesisDataMap myHypothesesMap;
91 THypothesisDataMap myAlgorithmsMap;
94 //typedef QMap<QString,SMESHGUI_GenericHypothesisCreator*> THypCreatorMap;
95 //THypCreatorMap myHypCreatorMap;
97 QList<HypothesesSet*> myListOfHypothesesSets;
99 void processHypothesisStatus(const int theHypStatus,
100 SMESH::SMESH_Hypothesis_ptr theHyp,
101 const bool theIsAddition,
102 const char* theError = 0)
104 if (theHypStatus > SMESH::HYP_OK) {
106 QString aHypName ("NULL Hypothesis");
107 if (!CORBA::is_nil(theHyp)) {
108 _PTR(SObject) Shyp = SMESH::FindSObject(theHyp);
111 aHypName = Shyp->GetName().c_str();
115 CORBA::String_var hypType = theHyp->GetName();
116 aHypName = GetHypothesisData( hypType.in() )->Label;
121 bool isFatal = (theHypStatus >= SMESH::HYP_UNKNOWN_FATAL);
124 aMsg = (isFatal ? "SMESH_CANT_ADD_HYP" : "SMESH_ADD_HYP_WRN");
126 aMsg = (isFatal ? "SMESH_CANT_RM_HYP" : "SMESH_RM_HYP_WRN");
128 aMsg = QObject::tr(aMsg.toLatin1().data()).arg(aHypName);
130 if ( theError && theError[0] )
136 aMsg += QObject::tr(QString("SMESH_HYP_%1").arg(theHypStatus).toLatin1().data());
138 if ( theHypStatus == SMESH::HYP_HIDDEN_ALGO ) { // PAL18501
139 CORBA::String_var hypType = theHyp->GetName();
140 if ( HypothesisData* hd = GetHypothesisData( hypType.in() ))
141 aMsg = aMsg.arg( hd->Dim[0] );
144 SUIT_MessageBox::warning(SMESHGUI::desktop(),
145 QObject::tr("SMESH_WRN_WARNING"),
150 //================================================================================
152 * \brief Prepends dimension and appends '[custom]' to the name of hypothesis set
154 //================================================================================
156 static QString mangledHypoSetName(HypothesesSet* hypSet)
158 QString name = hypSet->name();
161 int dim = hypSet->maxDim();
163 name = QString("%1D: %2").arg(dim).arg(name);
166 if ( hypSet->getIsCustom() )
167 name = QString("%1 [custom]").arg(name);
172 //================================================================================
174 * \brief Removes dimension and '[custom]' from the name of hypothesis set
176 //================================================================================
178 static QString demangledHypoSetName(QString name)
180 name.remove(QRegExp("[0-3]D: "));
181 name.remove(" [custom]");
185 void InitAvailableHypotheses()
187 SUIT_OverrideCursor wc;
188 if ( myHypothesesMap.empty() && myAlgorithmsMap.empty() )
191 SUIT_ResourceMgr* resMgr = SMESHGUI::resourceMgr();
194 // Find name of a resource XML file ("SMESH_Meshers.xml");
196 char* cenv = getenv("SMESH_MeshersList");
198 HypsXml.sprintf("%s", cenv);
200 QStringList HypsXmlList = HypsXml.split(":", QString::SkipEmptyParts);
201 if (HypsXmlList.count() == 0) {
202 SUIT_MessageBox::critical(SMESHGUI::desktop(),
203 QObject::tr("SMESH_WRN_WARNING"),
204 QObject::tr("MESHERS_FILE_NO_VARIABLE"));
207 // get full names of xml files from HypsXmlList
208 QStringList xmlFiles;
209 xmlFiles.append( QDir::home().filePath("CustomMeshers.xml")); // may be inexistent
210 for (int i = 0; i < HypsXmlList.count(); i++) {
211 QString HypsXml = HypsXmlList[ i ];
213 // Find full path to the resource XML file
214 QString xmlFile = resMgr->path("resources", "SMESH", HypsXml + ".xml");
215 if ( xmlFile.isEmpty() ) // try PLUGIN resources
216 xmlFile = resMgr->path("resources", HypsXml, HypsXml + ".xml");
217 if ( !xmlFile.isEmpty() )
218 xmlFiles.append( xmlFile );
222 QString aNoAccessFiles;
223 for (int i = 0; i < xmlFiles.count(); i++)
225 QString xmlFile = xmlFiles[ i ];
226 QFile file (xmlFile);
227 if (file.exists() && file.open(QIODevice::ReadOnly))
231 SMESHGUI_XmlHandler* aXmlHandler = new SMESHGUI_XmlHandler();
234 QXmlInputSource source (&file);
235 QXmlSimpleReader reader;
236 reader.setContentHandler(aXmlHandler);
237 reader.setErrorHandler(aXmlHandler);
238 bool ok = reader.parse(source);
242 THypothesisDataMap::ConstIterator it1 = aXmlHandler->myHypothesesMap.begin();
244 for( ;it1 != aXmlHandler->myHypothesesMap.end(); it1++)
245 myHypothesesMap.insert( it1.key(), it1.value() );
247 it1 = aXmlHandler->myAlgorithmsMap.begin();
248 for( ;it1 != aXmlHandler->myAlgorithmsMap.end(); it1++)
249 myAlgorithmsMap.insert( it1.key(), it1.value() );
251 QList<HypothesesSet*>::iterator it;
252 for ( it = aXmlHandler->myListOfHypothesesSets.begin();
253 it != aXmlHandler->myListOfHypothesesSets.end();
256 (*it)->setIsCustom( i == 0 );
257 myListOfHypothesesSets.append( *it );
261 SUIT_MessageBox::critical(SMESHGUI::desktop(),
262 QObject::tr("INF_PARSE_ERROR"),
263 QObject::tr(aXmlHandler->errorProtocol().toLatin1().data()));
267 else if ( i > 0 ) { // 1st is ~/CustomMeshers.xml
268 if (aNoAccessFiles.isEmpty())
269 aNoAccessFiles = xmlFile;
271 aNoAccessFiles += ", " + xmlFile;
273 } // end loop on xmlFiles
276 if (!aNoAccessFiles.isEmpty()) {
277 QString aMess = QObject::tr("MESHERS_FILE_CANT_OPEN") + " " + aNoAccessFiles + "\n";
278 aMess += QObject::tr("MESHERS_FILE_CHECK_VARIABLE");
280 SUIT_MessageBox::warning(SMESHGUI::desktop(),
281 QObject::tr("SMESH_WRN_WARNING"),
289 QStringList GetAvailableHypotheses( const bool isAlgo,
292 const bool hasGeometry,
293 const bool isSubMesh)
295 QStringList aHypList;
297 // Init list of available hypotheses, if needed
298 InitAvailableHypotheses();
299 bool checkGeometry = ( isAlgo );
300 const char* context = isSubMesh ? "LOCAL" : "GLOBAL";
301 // fill list of hypotheses/algorithms
302 THypothesisDataMap& pMap = isAlgo ? myAlgorithmsMap : myHypothesesMap;
303 THypothesisDataMap::ConstIterator anIter;
304 for ( anIter = pMap.begin(); anIter != pMap.end(); anIter++ )
306 HypothesisData* aData = anIter.value();
307 if (( aData && !aData->Label.isEmpty() ) &&
308 ( theDim < 0 || aData->Dim.contains( theDim )) &&
309 ( isAlgo || aData->IsAuxOrNeedHyp == isAux ) &&
310 ( aData->Context == "ANY" || aData->Context == context ) &&
311 ( !checkGeometry || (!aData->IsNeedGeometry ||
312 ( aData->IsNeedGeometry > 0 ) == hasGeometry)))
314 aHypList.append(anIter.key());
321 QStringList GetHypothesesSets(int maxDim)
323 QStringList aSetNameList;
325 // Init list of available hypotheses, if needed
326 InitAvailableHypotheses();
327 QList<HypothesesSet*>::iterator hypoSet;
328 for ( hypoSet = myListOfHypothesesSets.begin();
329 hypoSet != myListOfHypothesesSets.end();
331 HypothesesSet* aSet = *hypoSet;
332 if ( aSet && ( aSet->count( true ) || aSet->count( false )) &&
333 aSet->maxDim() <= maxDim)
335 aSetNameList.append( mangledHypoSetName( aSet ));
338 aSetNameList.removeDuplicates();
341 // reverse order of aSetNameList
342 QStringList reversedNames;
343 for ( int i = 0; i < aSetNameList.count(); ++i )
344 reversedNames.prepend( aSetNameList[i] );
346 return reversedNames;
349 HypothesesSet* GetHypothesesSet(const QString& theSetName)
351 QString name = demangledHypoSetName( theSetName );
352 QList<HypothesesSet*>::iterator hypoSet;
353 for ( hypoSet = myListOfHypothesesSets.begin();
354 hypoSet != myListOfHypothesesSets.end();
356 HypothesesSet* aSet = *hypoSet;
357 if ( aSet && aSet->name() == name )
363 HypothesisData* GetHypothesisData (const QString& aHypType)
365 HypothesisData* aHypData = 0;
367 // Init list of available hypotheses, if needed
368 InitAvailableHypotheses();
370 if (myHypothesesMap.contains(aHypType)) {
371 aHypData = myHypothesesMap[aHypType];
373 else if (myAlgorithmsMap.contains(aHypType)) {
374 aHypData = myAlgorithmsMap[aHypType];
379 //================================================================================
381 * \brief Return the HypothesisData holding a name of a group of hypotheses
382 * a given hypothesis belongs to
384 //================================================================================
386 HypothesisData* GetGroupTitle( const HypothesisData* hyp, const bool isAlgo )
388 static std::vector< std::vector< HypothesisData > > theGroups;
389 if ( theGroups.empty() )
391 theGroups.resize(14); // 14: isAlgo * 10 + dim
393 QString dummyS("GROUP");
394 QList<int> dummyIL; dummyIL << 1;
396 HypothesisData group( dummyS,dummyS,dummyS,dummyS,dummyS,dummyS,dummyS,-1,-1,
397 dummyIL, 0, dummySL,dummySL,dummySL,dummySL,0,0 );
400 theGroups[ key ].push_back( group );
405 group.Label = "GROUP:" + QObject::tr( "SMESH_1D_ALGO_GROUP_BASIC" );
406 theGroups[ key ].push_back( group );
408 group.Label = "GROUP:" + QObject::tr( "SMESH_1D_ALGO_GROUP_ADVANCED" );
409 theGroups[ key ].push_back( group );
414 group.Label = "GROUP:" + QObject::tr( "SMESH_1D_HYP_GROUP_BASIC" );
415 theGroups[ key ].push_back( group );
417 group.Label = "GROUP:" + QObject::tr( "SMESH_1D_HYP_GROUP_PROGRESSION" );
418 theGroups[ key ].push_back( group );
420 group.Label = "GROUP:" + QObject::tr( "SMESH_1D_HYP_GROUP_ADVANCED" );
421 theGroups[ key ].push_back( group );
426 group.Label = "GROUP:" + QObject::tr( "SMESH_2D_ALGO_GROUP_REGULAR" );
427 theGroups[ key ].push_back( group );
429 group.Label = "GROUP:" + QObject::tr( "SMESH_2D_ALGO_GROUP_FREE" );
430 theGroups[ key ].push_back( group );
432 group.Label = "GROUP:" + QObject::tr( "SMESH_2D_ALGO_GROUP_ADVANCED" );
433 theGroups[ key ].push_back( group );
438 group.Label = "GROUP:" + QObject::tr( "SMESH_3D_ALGO_GROUP_REGULAR" );
439 theGroups[ key ].push_back( group );
441 group.Label = "GROUP:" + QObject::tr( "SMESH_3D_ALGO_GROUP_FREE" );
442 theGroups[ key ].push_back( group );
444 group.Label = "GROUP:" + QObject::tr( "SMESH_3D_ALGO_GROUP_ADVANCED" );
445 theGroups[ key ].push_back( group );
448 size_t key = 0, groupID = 0;
449 if ( hyp && !hyp->Dim.isEmpty() )
451 key = hyp->Dim[0] + isAlgo * 10;
452 groupID = hyp->GroupID;
455 if ( key < theGroups.size() && !theGroups[ key ].empty() )
457 std::vector< HypothesisData > & group = theGroups[ key ];
458 return & ( groupID < group.size() ? group[ groupID ] : group.back() );
460 return & theGroups[ 0 ][ 0 ];
463 bool IsAvailableHypothesis(const HypothesisData* algoData,
464 const QString& hypType,
470 if ( algoData->BasicHypos.contains( hypType ))
472 if ( algoData->OptionalHypos.contains( hypType )) {
479 bool IsCompatibleAlgorithm(const HypothesisData* algo1Data,
480 const HypothesisData* algo2Data)
482 if ( !algo1Data || !algo2Data )
484 const HypothesisData* algoIn = algo1Data, *algoMain = algo2Data;
485 if ( algoIn->Dim.first() > algoMain->Dim.first() ) {
486 algoIn = algo2Data; algoMain = algo1Data;
488 // look for any output type of algoIn between input types of algoMain
489 QStringList::const_iterator inElemType = algoIn->OutputTypes.begin();
490 for ( ; inElemType != algoIn->OutputTypes.end(); ++inElemType )
491 if ( algoMain->InputTypes.contains( *inElemType ))
496 SMESHGUI_GenericHypothesisCreator* GetHypothesisCreator(const QString& aHypType)
498 if(MYDEBUG) MESSAGE("Get HypothesisCreator for " << aHypType.toLatin1().data());
500 SMESHGUI_GenericHypothesisCreator* aCreator = 0;
502 // check, if creator for this hypothesis type already exists
504 //if (myHypCreatorMap.find(aHypType) != myHypCreatorMap.end()) {
505 // aCreator = myHypCreatorMap[aHypType];
509 // 1. Init list of available hypotheses, if needed
510 InitAvailableHypotheses();
512 // 2. Get names of plugin libraries
513 HypothesisData* aHypData = GetHypothesisData(aHypType);
517 QString aClientLibName = aHypData->ClientLibName;
518 QString aServerLibName = aHypData->ServerLibName;
520 // 3. Load Client Plugin Library
522 // load plugin library
523 if(MYDEBUG) MESSAGE("Loading client meshers plugin library ...");
526 LPTSTR path = new TCHAR[aClientLibName.length() + 1];
527 path[aClientLibName.toWCharArray(path)] = '\0';
529 QByteArray baPath = aClientLibName.toUtf8();
530 const char* path = baPath.data();
533 QByteArray baPath = aClientLibName.toUtf8();
534 char* path = baPath.data();
536 LibHandle libHandle = LoadLib( path );
537 #if defined(WIN32) && defined(UNICODE)
541 // report any error, if occurred
544 const char* anError = "Can't load client meshers plugin library";
546 const char* anError = dlerror();
548 INFOS(anError); // always display this kind of error !
552 // get method, returning hypothesis creator
553 if(MYDEBUG) MESSAGE("Find GetHypothesisCreator() method ...");
554 typedef SMESHGUI_GenericHypothesisCreator* (*GetHypothesisCreator) \
556 GetHypothesisCreator procHandle =
557 (GetHypothesisCreator)GetProc(libHandle, "GetHypothesisCreator");
559 if(MYDEBUG) MESSAGE("bad hypothesis client plugin library");
560 UnLoadLib(libHandle);
563 // get hypothesis creator
564 if(MYDEBUG) MESSAGE("Get Hypothesis Creator for " << aHypType.toLatin1().data());
565 aCreator = procHandle( aHypType );
567 if(MYDEBUG) MESSAGE("no such a hypothesis in this plugin");
570 // map hypothesis creator to a hypothesis name
572 //myHypCreatorMap[aHypType] = aCreator;
574 //rnv : This dynamic property of the QObject stores the name of the plugin.
575 // It is used to obtain plugin root dir environment variable
576 // in the SMESHGUI_HypothesisDlg class. Plugin root dir environment
577 // variable is used to display documentation.
578 aCreator->setProperty(SMESH::Plugin_Name(),aHypData->PluginName);
583 catch (const SALOME::SALOME_Exception& S_ex) {
584 SalomeApp_Tools::QtCatchCorbaException(S_ex);
592 SMESH::SMESH_Hypothesis_ptr CreateHypothesis(const QString& aHypType,
593 const QString& aHypName,
596 if(MYDEBUG) MESSAGE("Create " << aHypType.toLatin1().data() <<
597 " with name " << aHypName.toLatin1().data());
598 HypothesisData* aHypData = GetHypothesisData(aHypType);
599 QString aServLib = aHypData->ServerLibName;
601 SMESH::SMESH_Hypothesis_var aHypothesis;
602 aHypothesis = SMESHGUI::GetSMESHGen()->CreateHypothesis(aHypType.toLatin1().data(),
603 aServLib.toUtf8().data());
604 if (!aHypothesis->_is_nil()) {
605 _PTR(SObject) aHypSObject = SMESH::FindSObject(aHypothesis.in());
607 if (!aHypName.isEmpty())
608 SMESH::SetName(aHypSObject, aHypName);
609 SMESHGUI::Modified();
610 SMESHGUI::GetSMESHGUI()->updateObjBrowser();
611 return aHypothesis._retn();
614 } catch (const SALOME::SALOME_Exception & S_ex) {
615 SalomeApp_Tools::QtCatchCorbaException(S_ex);
618 return SMESH::SMESH_Hypothesis::_nil();
621 bool IsApplicable(const QString& aHypType,
622 GEOM::GEOM_Object_ptr theGeomObject,
623 const bool toCheckAll)
625 if ( getenv("NO_LIMIT_ALGO_BY_SHAPE")) // allow a workaround for a case if
626 return true; // IsApplicable() returns false due to a bug
628 HypothesisData* aHypData = GetHypothesisData(aHypType);
629 QString aServLib = aHypData->ServerLibName;
630 return SMESHGUI::GetSMESHGen()->IsApplicable( aHypType.toLatin1().data(),
631 aServLib.toUtf8().data(),
637 bool AddHypothesisOnMesh (SMESH::SMESH_Mesh_ptr aMesh, SMESH::SMESH_Hypothesis_ptr aHyp)
639 if(MYDEBUG) MESSAGE ("SMESHGUI::AddHypothesisOnMesh");
640 int res = SMESH::HYP_UNKNOWN_FATAL;
641 SUIT_OverrideCursor wc;
643 if (!aMesh->_is_nil()) {
644 _PTR(SObject) SM = SMESH::FindSObject(aMesh);
645 GEOM::GEOM_Object_var aShapeObject = SMESH::GetShapeOnMeshOrSubMesh(SM);
647 CORBA::String_var error;
648 res = aMesh->AddHypothesis(aShapeObject, aHyp, error.out());
649 if (res > SMESH::HYP_OK) {
651 processHypothesisStatus(res, aHyp, true, error.in() );
655 catch(const SALOME::SALOME_Exception& S_ex) {
657 SalomeApp_Tools::QtCatchCorbaException(S_ex);
658 res = SMESH::HYP_UNKNOWN_FATAL;
661 return res < SMESH::HYP_UNKNOWN_FATAL;
665 bool AddHypothesisOnSubMesh (SMESH::SMESH_subMesh_ptr aSubMesh, SMESH::SMESH_Hypothesis_ptr aHyp)
667 if(MYDEBUG) MESSAGE("SMESHGUI::AddHypothesisOnSubMesh() ");
668 int res = SMESH::HYP_UNKNOWN_FATAL;
669 SUIT_OverrideCursor wc;
671 if ( !aSubMesh->_is_nil() && !aHyp->_is_nil() ) {
673 SMESH::SMESH_Mesh_var aMesh = aSubMesh->GetFather();
674 _PTR(SObject) SsubM = SMESH::FindSObject(aSubMesh);
675 GEOM::GEOM_Object_var aShapeObject = SMESH::GetShapeOnMeshOrSubMesh(SsubM);
676 if (!aMesh->_is_nil() && SsubM && !aShapeObject->_is_nil())
678 CORBA::String_var error;
679 res = aMesh->AddHypothesis( aShapeObject, aHyp, error.out() );
680 if (res > SMESH::HYP_OK) {
682 processHypothesisStatus( res, aHyp, true, error.in() );
687 SCRUTE(aHyp->_is_nil());
688 SCRUTE(aMesh->_is_nil());
690 SCRUTE(aShapeObject->_is_nil());
693 catch(const SALOME::SALOME_Exception& S_ex) {
695 SalomeApp_Tools::QtCatchCorbaException(S_ex);
696 res = SMESH::HYP_UNKNOWN_FATAL;
700 SCRUTE(aSubMesh->_is_nil());
701 SCRUTE(aHyp->_is_nil());
703 return res < SMESH::HYP_UNKNOWN_FATAL;
706 bool RemoveHypothesisOrAlgorithmOnMesh (const Handle(SALOME_InteractiveObject)& IObject)
708 int res = SMESH::HYP_UNKNOWN_FATAL;
709 SUIT_OverrideCursor wc;
712 _PTR(Study) aStudy = getStudy();
713 _PTR(SObject) aHypObj = aStudy->FindObjectID( IObject->getEntry() );
716 _PTR(SObject) MorSM = SMESH::GetMeshOrSubmesh( aHypObj );
717 _PTR(SObject) aRealHypo;
718 if( aHypObj->ReferencedObject( aRealHypo ) )
720 SMESH_Hypothesis_var hypo = SMESH_Hypothesis::_narrow( SObjectToObject( aRealHypo ) );
721 RemoveHypothesisOrAlgorithmOnMesh( MorSM, hypo );
725 SMESH_Hypothesis_var hypo = SMESH_Hypothesis::_narrow( SObjectToObject( aHypObj ) );
726 SObjectList meshList = GetMeshesUsingAlgoOrHypothesis( hypo );
727 for( size_t i = 0; i < meshList.size(); i++ )
728 RemoveHypothesisOrAlgorithmOnMesh( meshList[ i ], hypo );
732 catch(const SALOME::SALOME_Exception& S_ex)
735 SalomeApp_Tools::QtCatchCorbaException(S_ex);
736 res = SMESH::HYP_UNKNOWN_FATAL;
738 return res < SMESH::HYP_UNKNOWN_FATAL;
741 bool RemoveHypothesisOrAlgorithmOnMesh (_PTR(SObject) MorSM,
742 SMESH::SMESH_Hypothesis_ptr anHyp)
744 int res = SMESH::HYP_UNKNOWN_FATAL;
745 SUIT_OverrideCursor wc;
749 GEOM::GEOM_Object_var aShapeObject = SMESH::GetShapeOnMeshOrSubMesh(MorSM);
750 SMESH::SMESH_Mesh_var aMesh = SMESH::SObjectToInterface<SMESH::SMESH_Mesh>(MorSM);
751 SMESH::SMESH_subMesh_var aSubMesh = SMESH::SObjectToInterface<SMESH::SMESH_subMesh>(MorSM);
753 if (!aSubMesh->_is_nil())
754 aMesh = aSubMesh->GetFather();
756 if (!aMesh->_is_nil()) {
757 if (aMesh->HasShapeToMesh() && !aShapeObject->_is_nil()) {
758 res = aMesh->RemoveHypothesis(aShapeObject, anHyp);
760 else if(!aMesh->HasShapeToMesh()){
761 res = aMesh->RemoveHypothesis(aShapeObject, anHyp);
763 if (res > SMESH::HYP_OK) {
765 processHypothesisStatus(res, anHyp, false);
768 if ( _PTR(SObject) meshSO = SMESH::FindSObject(aMesh) )
770 if ( SMESH_Actor* actor = SMESH::FindActorByEntry( meshSO->GetID().c_str() ))
771 if( actor->GetVisibility() )
775 } catch(const SALOME::SALOME_Exception& S_ex) {
777 SalomeApp_Tools::QtCatchCorbaException(S_ex);
778 res = SMESH::HYP_UNKNOWN_FATAL;
781 return res < SMESH::HYP_UNKNOWN_FATAL;
784 SObjectList GetMeshesUsingAlgoOrHypothesis(SMESH::SMESH_Hypothesis_ptr AlgoOrHyp)
786 SObjectList listSOmesh;
787 listSOmesh.resize(0);
789 unsigned int index = 0;
790 if (!AlgoOrHyp->_is_nil()) {
791 _PTR(SObject) SO_Hypothesis = SMESH::FindSObject(AlgoOrHyp);
793 SObjectList listSO = SMESH::getStudy()->FindDependances(SO_Hypothesis);
795 if(MYDEBUG) MESSAGE("SMESHGUI::GetMeshesUsingAlgoOrHypothesis(): dependency number ="<<listSO.size());
796 for (unsigned int i = 0; i < listSO.size(); i++) {
797 _PTR(SObject) SO = listSO[i];
799 _PTR(SObject) aFather = SO->GetFather();
801 _PTR(SObject) SOfatherFather = aFather->GetFather();
802 if (SOfatherFather) {
803 if(MYDEBUG) MESSAGE("SMESHGUI::GetMeshesUsingAlgoOrHypothesis(): dependency added to list");
805 listSOmesh.resize(index);
806 listSOmesh[index - 1] = SOfatherFather;
813 if (MYDEBUG) MESSAGE("SMESHGUI::GetMeshesUsingAlgoOrHypothesis(): completed");
817 #define CASE2MESSAGE(enum) case SMESH::enum: msg = QObject::tr( "STATE_" #enum ); break;
818 QString GetMessageOnAlgoStateErrors(const algo_error_array& errors)
820 QString resMsg; // PAL14861 = QObject::tr("SMESH_WRN_MISSING_PARAMETERS") + ":\n";
821 for ( size_t i = 0; i < errors.length(); ++i ) {
822 const SMESH::AlgoStateError & error = errors[ i ];
823 const bool hasAlgo = ( strlen( error.algoName ) != 0 );
826 msg = QObject::tr( "STATE_ALGO_MISSING" );
828 switch( error.state ) {
829 CASE2MESSAGE( HYP_MISSING );
830 CASE2MESSAGE( HYP_NOTCONFORM );
831 CASE2MESSAGE( HYP_BAD_PARAMETER );
832 CASE2MESSAGE( HYP_BAD_GEOMETRY );
835 // apply args to message:
838 msg = msg.arg( error.algoName.in() );
840 msg = msg.arg( error.algoDim );
842 msg = msg.arg( QObject::tr( error.isGlobalAlgo ? "GLOBAL_ALGO" : "LOCAL_ALGO" ));
843 // %4 - hypothesis dim == algoDim
844 msg = msg.arg( error.algoDim );
846 if ( i ) resMsg += ";\n";
851 } // end of namespace SMESH