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_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*
72 #define LoadLib( name ) dlopen( name, RTLD_LAZY | RTLD_GLOBAL )
74 #define UnLoadLib( handle ) dlclose( handle );
78 static int MYDEBUG = 0;
80 static int MYDEBUG = 0;
85 typedef IMap<QString,HypothesisData*> THypothesisDataMap;
86 THypothesisDataMap myHypothesesMap;
87 THypothesisDataMap myAlgorithmsMap;
90 //typedef QMap<QString,SMESHGUI_GenericHypothesisCreator*> THypCreatorMap;
91 //THypCreatorMap myHypCreatorMap;
93 QList<HypothesesSet*> myListOfHypothesesSets;
95 void processHypothesisStatus(const int theHypStatus,
96 SMESH::SMESH_Hypothesis_ptr theHyp,
97 const bool theIsAddition,
98 const char* theError = 0)
100 if (theHypStatus > SMESH::HYP_OK) {
102 QString aHypName ("NULL Hypothesis");
103 if (!CORBA::is_nil(theHyp)) {
104 _PTR(SObject) Shyp = SMESH::FindSObject(theHyp);
107 aHypName = Shyp->GetName().c_str();
111 CORBA::String_var hypType = theHyp->GetName();
112 aHypName = GetHypothesisData( hypType.in() )->Label;
117 bool isFatal = (theHypStatus >= SMESH::HYP_UNKNOWN_FATAL);
120 aMsg = (isFatal ? "SMESH_CANT_ADD_HYP" : "SMESH_ADD_HYP_WRN");
122 aMsg = (isFatal ? "SMESH_CANT_RM_HYP" : "SMESH_RM_HYP_WRN");
124 aMsg = QObject::tr(aMsg.toLatin1().data()).arg(aHypName);
126 if ( theError && theError[0] )
132 aMsg += QObject::tr(QString("SMESH_HYP_%1").arg(theHypStatus).toLatin1().data());
134 if ( theHypStatus == SMESH::HYP_HIDDEN_ALGO ) { // PAL18501
135 CORBA::String_var hypType = theHyp->GetName();
136 if ( HypothesisData* hd = GetHypothesisData( hypType.in() ))
137 aMsg = aMsg.arg( hd->Dim[0] );
140 SUIT_MessageBox::warning(SMESHGUI::desktop(),
141 QObject::tr("SMESH_WRN_WARNING"),
146 //================================================================================
148 * \brief Prepends dimension and appends '[custom]' to the name of hypothesis set
150 //================================================================================
152 static QString mangledHypoSetName(HypothesesSet* hypSet)
154 QString name = hypSet->name();
157 int dim = hypSet->maxDim();
159 name = QString("%1D: %2").arg(dim).arg(name);
162 if ( hypSet->getIsCustom() )
163 name = QString("%1 [custom]").arg(name);
168 //================================================================================
170 * \brief Removes dimension and '[custom]' from the name of hypothesis set
172 //================================================================================
174 static QString demangledHypoSetName(QString name)
176 name.remove(QRegExp("[0-3]D: "));
177 name.remove(" [custom]");
181 void InitAvailableHypotheses()
183 SUIT_OverrideCursor wc;
184 if ( myHypothesesMap.empty() && myAlgorithmsMap.empty() )
187 SUIT_ResourceMgr* resMgr = SMESHGUI::resourceMgr();
190 // Find name of a resource XML file ("SMESH_Meshers.xml");
192 char* cenv = getenv("SMESH_MeshersList");
194 HypsXml.sprintf("%s", cenv);
196 QStringList HypsXmlList = HypsXml.split(":", QString::SkipEmptyParts);
197 if (HypsXmlList.count() == 0) {
198 SUIT_MessageBox::critical(SMESHGUI::desktop(),
199 QObject::tr("SMESH_WRN_WARNING"),
200 QObject::tr("MESHERS_FILE_NO_VARIABLE"));
203 // get full names of xml files from HypsXmlList
204 QStringList xmlFiles;
205 xmlFiles.append( QDir::home().filePath("CustomMeshers.xml")); // may be inexistent
206 for (int i = 0; i < HypsXmlList.count(); i++) {
207 QString HypsXml = HypsXmlList[ i ];
209 // Find full path to the resource XML file
210 QString xmlFile = resMgr->path("resources", "SMESH", HypsXml + ".xml");
211 if ( xmlFile.isEmpty() ) // try PLUGIN resources
212 xmlFile = resMgr->path("resources", HypsXml, HypsXml + ".xml");
213 if ( !xmlFile.isEmpty() )
214 xmlFiles.append( xmlFile );
218 QString aNoAccessFiles;
219 for (int i = 0; i < xmlFiles.count(); i++)
221 QString xmlFile = xmlFiles[ i ];
222 QFile file (xmlFile);
223 if (file.exists() && file.open(QIODevice::ReadOnly))
227 SMESHGUI_XmlHandler* aXmlHandler = new SMESHGUI_XmlHandler();
230 QXmlInputSource source (&file);
231 QXmlSimpleReader reader;
232 reader.setContentHandler(aXmlHandler);
233 reader.setErrorHandler(aXmlHandler);
234 bool ok = reader.parse(source);
238 THypothesisDataMap::ConstIterator it1 = aXmlHandler->myHypothesesMap.begin();
240 for( ;it1 != aXmlHandler->myHypothesesMap.end(); it1++)
241 myHypothesesMap.insert( it1.key(), it1.value() );
243 it1 = aXmlHandler->myAlgorithmsMap.begin();
244 for( ;it1 != aXmlHandler->myAlgorithmsMap.end(); it1++)
245 myAlgorithmsMap.insert( it1.key(), it1.value() );
247 QList<HypothesesSet*>::iterator it;
248 for ( it = aXmlHandler->myListOfHypothesesSets.begin();
249 it != aXmlHandler->myListOfHypothesesSets.end();
252 (*it)->setIsCustom( i == 0 );
253 myListOfHypothesesSets.append( *it );
257 SUIT_MessageBox::critical(SMESHGUI::desktop(),
258 QObject::tr("INF_PARSE_ERROR"),
259 QObject::tr(aXmlHandler->errorProtocol().toLatin1().data()));
263 else if ( i > 0 ) { // 1st is ~/CustomMeshers.xml
264 if (aNoAccessFiles.isEmpty())
265 aNoAccessFiles = xmlFile;
267 aNoAccessFiles += ", " + xmlFile;
269 } // end loop on xmlFiles
272 if (!aNoAccessFiles.isEmpty()) {
273 QString aMess = QObject::tr("MESHERS_FILE_CANT_OPEN") + " " + aNoAccessFiles + "\n";
274 aMess += QObject::tr("MESHERS_FILE_CHECK_VARIABLE");
276 SUIT_MessageBox::warning(SMESHGUI::desktop(),
277 QObject::tr("SMESH_WRN_WARNING"),
285 QStringList GetAvailableHypotheses( const bool isAlgo,
288 const bool hasGeometry,
289 const bool isSubMesh)
291 QStringList aHypList;
293 // Init list of available hypotheses, if needed
294 InitAvailableHypotheses();
295 bool checkGeometry = ( isAlgo );
296 const char* context = isSubMesh ? "LOCAL" : "GLOBAL";
297 // fill list of hypotheses/algorithms
298 THypothesisDataMap& pMap = isAlgo ? myAlgorithmsMap : myHypothesesMap;
299 THypothesisDataMap::ConstIterator anIter;
300 for ( anIter = pMap.begin(); anIter != pMap.end(); anIter++ )
302 HypothesisData* aData = anIter.value();
303 if (( aData && !aData->Label.isEmpty() ) &&
304 ( theDim < 0 || aData->Dim.contains( theDim )) &&
305 ( isAlgo || aData->IsAuxOrNeedHyp == isAux ) &&
306 ( aData->Context == "ANY" || aData->Context == context ) &&
307 ( !checkGeometry || (!aData->IsNeedGeometry ||
308 ( aData->IsNeedGeometry > 0 ) == hasGeometry)))
310 aHypList.append(anIter.key());
317 QStringList GetHypothesesSets(int maxDim)
319 QStringList aSetNameList;
321 // Init list of available hypotheses, if needed
322 InitAvailableHypotheses();
323 QList<HypothesesSet*>::iterator hypoSet;
324 for ( hypoSet = myListOfHypothesesSets.begin();
325 hypoSet != myListOfHypothesesSets.end();
327 HypothesesSet* aSet = *hypoSet;
328 if ( aSet && ( aSet->count( true ) || aSet->count( false )) &&
329 aSet->maxDim() <= maxDim)
331 aSetNameList.append( mangledHypoSetName( aSet ));
334 aSetNameList.removeDuplicates();
337 // reverse order of aSetNameList
338 QStringList reversedNames;
339 for ( int i = 0; i < aSetNameList.count(); ++i )
340 reversedNames.prepend( aSetNameList[i] );
342 return reversedNames;
345 HypothesesSet* GetHypothesesSet(const QString& theSetName)
347 QString name = demangledHypoSetName( theSetName );
348 QList<HypothesesSet*>::iterator hypoSet;
349 for ( hypoSet = myListOfHypothesesSets.begin();
350 hypoSet != myListOfHypothesesSets.end();
352 HypothesesSet* aSet = *hypoSet;
353 if ( aSet && aSet->name() == name )
359 HypothesisData* GetHypothesisData (const QString& aHypType)
361 HypothesisData* aHypData = 0;
363 // Init list of available hypotheses, if needed
364 InitAvailableHypotheses();
366 if (myHypothesesMap.contains(aHypType)) {
367 aHypData = myHypothesesMap[aHypType];
369 else if (myAlgorithmsMap.contains(aHypType)) {
370 aHypData = myAlgorithmsMap[aHypType];
375 //================================================================================
377 * \brief Return the HypothesisData holding a name of a group of hypotheses
378 * a given hypothesis belongs to
380 //================================================================================
382 HypothesisData* GetGroupTitle( const HypothesisData* hyp, const bool isAlgo )
384 static std::vector< std::vector< HypothesisData > > theGroups;
385 if ( theGroups.empty() )
387 theGroups.resize(14); // 14: isAlgo * 10 + dim
389 QString dummyS("GROUP");
390 QList<int> dummyIL; dummyIL << 1;
392 HypothesisData group( dummyS,dummyS,dummyS,dummyS,dummyS,dummyS,dummyS,-1,-1,
393 dummyIL, 0, dummySL,dummySL,dummySL,dummySL,0,0 );
396 theGroups[ key ].push_back( group );
401 group.Label = "GROUP:" + QObject::tr( "SMESH_1D_ALGO_GROUP_BASIC" );
402 theGroups[ key ].push_back( group );
404 group.Label = "GROUP:" + QObject::tr( "SMESH_1D_ALGO_GROUP_ADVANCED" );
405 theGroups[ key ].push_back( group );
410 group.Label = "GROUP:" + QObject::tr( "SMESH_1D_HYP_GROUP_BASIC" );
411 theGroups[ key ].push_back( group );
413 group.Label = "GROUP:" + QObject::tr( "SMESH_1D_HYP_GROUP_PROGRESSION" );
414 theGroups[ key ].push_back( group );
416 group.Label = "GROUP:" + QObject::tr( "SMESH_1D_HYP_GROUP_ADVANCED" );
417 theGroups[ key ].push_back( group );
422 group.Label = "GROUP:" + QObject::tr( "SMESH_2D_ALGO_GROUP_REGULAR" );
423 theGroups[ key ].push_back( group );
425 group.Label = "GROUP:" + QObject::tr( "SMESH_2D_ALGO_GROUP_FREE" );
426 theGroups[ key ].push_back( group );
428 group.Label = "GROUP:" + QObject::tr( "SMESH_2D_ALGO_GROUP_ADVANCED" );
429 theGroups[ key ].push_back( group );
434 group.Label = "GROUP:" + QObject::tr( "SMESH_3D_ALGO_GROUP_REGULAR" );
435 theGroups[ key ].push_back( group );
437 group.Label = "GROUP:" + QObject::tr( "SMESH_3D_ALGO_GROUP_FREE" );
438 theGroups[ key ].push_back( group );
440 group.Label = "GROUP:" + QObject::tr( "SMESH_3D_ALGO_GROUP_ADVANCED" );
441 theGroups[ key ].push_back( group );
444 size_t key = 0, groupID = 0;
445 if ( hyp && !hyp->Dim.isEmpty() )
447 key = hyp->Dim[0] + isAlgo * 10;
448 groupID = hyp->GroupID;
451 if ( key < theGroups.size() && !theGroups[ key ].empty() )
453 std::vector< HypothesisData > & group = theGroups[ key ];
454 return & ( groupID < group.size() ? group[ groupID ] : group.back() );
456 return & theGroups[ 0 ][ 0 ];
459 bool IsAvailableHypothesis(const HypothesisData* algoData,
460 const QString& hypType,
466 if ( algoData->BasicHypos.contains( hypType ))
468 if ( algoData->OptionalHypos.contains( hypType )) {
475 bool IsCompatibleAlgorithm(const HypothesisData* algo1Data,
476 const HypothesisData* algo2Data)
478 if ( !algo1Data || !algo2Data )
480 const HypothesisData* algoIn = algo1Data, *algoMain = algo2Data;
481 if ( algoIn->Dim.first() > algoMain->Dim.first() ) {
482 algoIn = algo2Data; algoMain = algo1Data;
484 // look for any output type of algoIn between input types of algoMain
485 QStringList::const_iterator inElemType = algoIn->OutputTypes.begin();
486 for ( ; inElemType != algoIn->OutputTypes.end(); ++inElemType )
487 if ( algoMain->InputTypes.contains( *inElemType ))
492 SMESHGUI_GenericHypothesisCreator* GetHypothesisCreator(const QString& aHypType)
494 if(MYDEBUG) MESSAGE("Get HypothesisCreator for " << aHypType.toLatin1().data());
496 SMESHGUI_GenericHypothesisCreator* aCreator = 0;
498 // check, if creator for this hypothesis type already exists
500 //if (myHypCreatorMap.find(aHypType) != myHypCreatorMap.end()) {
501 // aCreator = myHypCreatorMap[aHypType];
505 // 1. Init list of available hypotheses, if needed
506 InitAvailableHypotheses();
508 // 2. Get names of plugin libraries
509 HypothesisData* aHypData = GetHypothesisData(aHypType);
513 QString aClientLibName = aHypData->ClientLibName;
514 QString aServerLibName = aHypData->ServerLibName;
516 // 3. Load Client Plugin Library
518 // load plugin library
519 if(MYDEBUG) MESSAGE("Loading client meshers plugin library ...");
520 LibHandle libHandle = LoadLib( aClientLibName.toLatin1().data() );
522 // report any error, if occured
525 const char* anError = "Can't load client meshers plugin library";
527 const char* anError = dlerror();
529 INFOS(anError); // always display this kind of error !
533 // get method, returning hypothesis creator
534 if(MYDEBUG) MESSAGE("Find GetHypothesisCreator() method ...");
535 typedef SMESHGUI_GenericHypothesisCreator* (*GetHypothesisCreator) \
537 GetHypothesisCreator procHandle =
538 (GetHypothesisCreator)GetProc(libHandle, "GetHypothesisCreator");
540 if(MYDEBUG) MESSAGE("bad hypothesis client plugin library");
541 UnLoadLib(libHandle);
544 // get hypothesis creator
545 if(MYDEBUG) MESSAGE("Get Hypothesis Creator for " << aHypType.toLatin1().data());
546 aCreator = procHandle( aHypType );
548 if(MYDEBUG) MESSAGE("no such a hypothesis in this plugin");
551 // map hypothesis creator to a hypothesis name
553 //myHypCreatorMap[aHypType] = aCreator;
555 //rnv : This dynamic property of the QObject stores the name of the plugin.
556 // It is used to obtain plugin root dir environment variable
557 // in the SMESHGUI_HypothesisDlg class. Plugin root dir environment
558 // variable is used to display documentation.
559 aCreator->setProperty(SMESH::Plugin_Name(),aHypData->PluginName);
564 catch (const SALOME::SALOME_Exception& S_ex) {
565 SalomeApp_Tools::QtCatchCorbaException(S_ex);
573 SMESH::SMESH_Hypothesis_ptr CreateHypothesis(const QString& aHypType,
574 const QString& aHypName,
577 if(MYDEBUG) MESSAGE("Create " << aHypType.toLatin1().data() <<
578 " with name " << aHypName.toLatin1().data());
579 HypothesisData* aHypData = GetHypothesisData(aHypType);
580 QString aServLib = aHypData->ServerLibName;
582 SMESH::SMESH_Hypothesis_var aHypothesis;
583 aHypothesis = SMESHGUI::GetSMESHGen()->CreateHypothesis(aHypType.toLatin1().data(),
584 aServLib.toLatin1().data());
585 if (!aHypothesis->_is_nil()) {
586 _PTR(SObject) aHypSObject = SMESH::FindSObject(aHypothesis.in());
588 if (!aHypName.isEmpty())
589 SMESH::SetName(aHypSObject, aHypName);
590 SMESHGUI::Modified();
591 SMESHGUI::GetSMESHGUI()->updateObjBrowser();
592 return aHypothesis._retn();
595 } catch (const SALOME::SALOME_Exception & S_ex) {
596 SalomeApp_Tools::QtCatchCorbaException(S_ex);
599 return SMESH::SMESH_Hypothesis::_nil();
602 bool IsApplicable(const QString& aHypType,
603 GEOM::GEOM_Object_ptr theGeomObject,
604 const bool toCheckAll)
606 if ( getenv("NO_LIMIT_ALGO_BY_SHAPE")) // allow a workaround for a case if
607 return true; // IsApplicable() returns false due to a bug
609 HypothesisData* aHypData = GetHypothesisData(aHypType);
610 QString aServLib = aHypData->ServerLibName;
611 return SMESHGUI::GetSMESHGen()->IsApplicable( aHypType.toLatin1().data(),
612 aServLib.toLatin1().data(),
618 bool AddHypothesisOnMesh (SMESH::SMESH_Mesh_ptr aMesh, SMESH::SMESH_Hypothesis_ptr aHyp)
620 if(MYDEBUG) MESSAGE ("SMESHGUI::AddHypothesisOnMesh");
621 int res = SMESH::HYP_UNKNOWN_FATAL;
622 SUIT_OverrideCursor wc;
624 if (!aMesh->_is_nil()) {
625 _PTR(SObject) SM = SMESH::FindSObject(aMesh);
626 GEOM::GEOM_Object_var aShapeObject = SMESH::GetShapeOnMeshOrSubMesh(SM);
628 CORBA::String_var error;
629 res = aMesh->AddHypothesis(aShapeObject, aHyp, error.out());
630 if (res < SMESH::HYP_UNKNOWN_FATAL) {
631 _PTR(SObject) aSH = SMESH::FindSObject(aHyp);
633 SMESH::ModifiedMesh(SM, false, aMesh->NbNodes()==0);
636 if (res > SMESH::HYP_OK) {
638 processHypothesisStatus(res, aHyp, true, error.in() );
642 catch(const SALOME::SALOME_Exception& S_ex) {
644 SalomeApp_Tools::QtCatchCorbaException(S_ex);
645 res = SMESH::HYP_UNKNOWN_FATAL;
648 return res < SMESH::HYP_UNKNOWN_FATAL;
652 bool AddHypothesisOnSubMesh (SMESH::SMESH_subMesh_ptr aSubMesh, SMESH::SMESH_Hypothesis_ptr aHyp)
654 if(MYDEBUG) MESSAGE("SMESHGUI::AddHypothesisOnSubMesh() ");
655 int res = SMESH::HYP_UNKNOWN_FATAL;
656 SUIT_OverrideCursor wc;
658 if (!aSubMesh->_is_nil() && ! aHyp->_is_nil()) {
660 SMESH::SMESH_Mesh_var aMesh = aSubMesh->GetFather();
661 _PTR(SObject) SsubM = SMESH::FindSObject(aSubMesh);
662 GEOM::GEOM_Object_var aShapeObject = SMESH::GetShapeOnMeshOrSubMesh(SsubM);
663 if (!aMesh->_is_nil() && SsubM && !aShapeObject->_is_nil())
665 CORBA::String_var error;
666 res = aMesh->AddHypothesis( aShapeObject, aHyp, error.out() );
667 if (res < SMESH::HYP_UNKNOWN_FATAL) {
668 _PTR(SObject) meshSO = SMESH::FindSObject(aMesh);
670 SMESH::ModifiedMesh(meshSO, false, aMesh->NbNodes()==0);
672 if (res > SMESH::HYP_OK) {
674 processHypothesisStatus( res, aHyp, true, error.in() );
679 SCRUTE(aHyp->_is_nil());
680 SCRUTE(aMesh->_is_nil());
682 SCRUTE(aShapeObject->_is_nil());
685 catch(const SALOME::SALOME_Exception& S_ex) {
687 SalomeApp_Tools::QtCatchCorbaException(S_ex);
688 res = SMESH::HYP_UNKNOWN_FATAL;
692 SCRUTE(aSubMesh->_is_nil());
693 SCRUTE(aHyp->_is_nil());
695 return res < SMESH::HYP_UNKNOWN_FATAL;
698 bool RemoveHypothesisOrAlgorithmOnMesh (const Handle(SALOME_InteractiveObject)& IObject)
700 int res = SMESH::HYP_UNKNOWN_FATAL;
701 SUIT_OverrideCursor wc;
704 _PTR(Study) aStudy = GetActiveStudyDocument();
705 _PTR(SObject) aHypObj = aStudy->FindObjectID( IObject->getEntry() );
708 _PTR(SObject) MorSM = SMESH::GetMeshOrSubmesh( aHypObj );
709 _PTR(SObject) aRealHypo;
710 if( aHypObj->ReferencedObject( aRealHypo ) )
712 SMESH_Hypothesis_var hypo = SMESH_Hypothesis::_narrow( SObjectToObject( aRealHypo ) );
713 RemoveHypothesisOrAlgorithmOnMesh( MorSM, hypo );
717 SMESH_Hypothesis_var hypo = SMESH_Hypothesis::_narrow( SObjectToObject( aHypObj ) );
718 SObjectList meshList = GetMeshesUsingAlgoOrHypothesis( hypo );
719 for( size_t i = 0; i < meshList.size(); i++ )
720 RemoveHypothesisOrAlgorithmOnMesh( meshList[ i ], hypo );
724 catch(const SALOME::SALOME_Exception& S_ex)
727 SalomeApp_Tools::QtCatchCorbaException(S_ex);
728 res = SMESH::HYP_UNKNOWN_FATAL;
730 return res < SMESH::HYP_UNKNOWN_FATAL;
733 bool RemoveHypothesisOrAlgorithmOnMesh (_PTR(SObject) MorSM,
734 SMESH::SMESH_Hypothesis_ptr anHyp)
736 int res = SMESH::HYP_UNKNOWN_FATAL;
737 SUIT_OverrideCursor wc;
741 GEOM::GEOM_Object_var aShapeObject = SMESH::GetShapeOnMeshOrSubMesh(MorSM);
742 SMESH::SMESH_Mesh_var aMesh = SMESH::SObjectToInterface<SMESH::SMESH_Mesh>(MorSM);
743 SMESH::SMESH_subMesh_var aSubMesh = SMESH::SObjectToInterface<SMESH::SMESH_subMesh>(MorSM);
745 if (!aSubMesh->_is_nil())
746 aMesh = aSubMesh->GetFather();
748 if (!aMesh->_is_nil()) {
749 if (aMesh->HasShapeToMesh() && !aShapeObject->_is_nil()) {
750 res = aMesh->RemoveHypothesis(aShapeObject, anHyp);
752 else if(!aMesh->HasShapeToMesh()){
753 res = aMesh->RemoveHypothesis(aShapeObject, anHyp);
755 if (res > SMESH::HYP_OK) {
757 processHypothesisStatus(res, anHyp, false);
760 if ( _PTR(SObject) meshSO = SMESH::FindSObject(aMesh) )
762 if ( res < SMESH::HYP_UNKNOWN_FATAL )
763 SMESH::ModifiedMesh(meshSO, false, aMesh->NbNodes()==0);
765 if ( SMESH_Actor* actor = SMESH::FindActorByEntry( meshSO->GetID().c_str() ))
766 if( actor->GetVisibility() )
770 } catch(const SALOME::SALOME_Exception& S_ex) {
772 SalomeApp_Tools::QtCatchCorbaException(S_ex);
773 res = SMESH::HYP_UNKNOWN_FATAL;
776 return res < SMESH::HYP_UNKNOWN_FATAL;
779 SObjectList GetMeshesUsingAlgoOrHypothesis(SMESH::SMESH_Hypothesis_ptr AlgoOrHyp)
781 SObjectList listSOmesh;
782 listSOmesh.resize(0);
784 unsigned int index = 0;
785 if (!AlgoOrHyp->_is_nil()) {
786 _PTR(SObject) SO_Hypothesis = SMESH::FindSObject(AlgoOrHyp);
789 SMESHGUI::activeStudy()->studyDS()->FindDependances(SO_Hypothesis);
791 if(MYDEBUG) MESSAGE("SMESHGUI::GetMeshesUsingAlgoOrHypothesis(): dependency number ="<<listSO.size());
792 for (unsigned int i = 0; i < listSO.size(); i++) {
793 _PTR(SObject) SO = listSO[i];
795 _PTR(SObject) aFather = SO->GetFather();
797 _PTR(SObject) SOfatherFather = aFather->GetFather();
798 if (SOfatherFather) {
799 if(MYDEBUG) MESSAGE("SMESHGUI::GetMeshesUsingAlgoOrHypothesis(): dependency added to list");
801 listSOmesh.resize(index);
802 listSOmesh[index - 1] = SOfatherFather;
809 if (MYDEBUG) MESSAGE("SMESHGUI::GetMeshesUsingAlgoOrHypothesis(): completed");
813 #define CASE2MESSAGE(enum) case SMESH::enum: msg = QObject::tr( "STATE_" #enum ); break;
814 QString GetMessageOnAlgoStateErrors(const algo_error_array& errors)
816 QString resMsg; // PAL14861 = QObject::tr("SMESH_WRN_MISSING_PARAMETERS") + ":\n";
817 for ( size_t i = 0; i < errors.length(); ++i ) {
818 const SMESH::AlgoStateError & error = errors[ i ];
819 const bool hasAlgo = ( strlen( error.algoName ) != 0 );
822 msg = QObject::tr( "STATE_ALGO_MISSING" );
824 switch( error.state ) {
825 CASE2MESSAGE( HYP_MISSING );
826 CASE2MESSAGE( HYP_NOTCONFORM );
827 CASE2MESSAGE( HYP_BAD_PARAMETER );
828 CASE2MESSAGE( HYP_BAD_GEOMETRY );
831 // apply args to message:
834 msg = msg.arg( error.algoName.in() );
836 msg = msg.arg( error.algoDim );
838 msg = msg.arg( QObject::tr( error.isGlobalAlgo ? "GLOBAL_ALGO" : "LOCAL_ALGO" ));
839 // %4 - hypothesis dim == algoDim
840 msg = msg.arg( error.algoDim );
842 if ( i ) resMsg += ";\n";
847 } // end of namespace SMESH