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 isNeedGeometry,
286 const bool isSubMesh)
288 QStringList aHypList;
290 // Init list of available hypotheses, if needed
291 InitAvailableHypotheses();
292 bool checkGeometry = ( !isNeedGeometry && 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 == isNeedGeometry ))
306 aHypList.append(anIter.key());
313 QStringList GetHypothesesSets(int maxDim)
315 QStringList aSetNameList;
317 // Init list of available hypotheses, if needed
318 InitAvailableHypotheses();
319 QList<HypothesesSet*>::iterator hypoSet;
320 for ( hypoSet = myListOfHypothesesSets.begin();
321 hypoSet != myListOfHypothesesSets.end();
323 HypothesesSet* aSet = *hypoSet;
324 if ( aSet && ( aSet->count( true ) || aSet->count( false )) &&
325 aSet->maxDim() <= maxDim)
327 aSetNameList.append( mangledHypoSetName( aSet ));
330 aSetNameList.removeDuplicates();
333 // reverse order of aSetNameList
334 QStringList reversedNames;
335 for ( int i = 0; i < aSetNameList.count(); ++i )
336 reversedNames.prepend( aSetNameList[i] );
338 return reversedNames;
341 HypothesesSet* GetHypothesesSet(const QString& theSetName)
343 QString name = demangledHypoSetName( theSetName );
344 QList<HypothesesSet*>::iterator hypoSet;
345 for ( hypoSet = myListOfHypothesesSets.begin();
346 hypoSet != myListOfHypothesesSets.end();
348 HypothesesSet* aSet = *hypoSet;
349 if ( aSet && aSet->name() == name )
355 HypothesisData* GetHypothesisData (const QString& aHypType)
357 HypothesisData* aHypData = 0;
359 // Init list of available hypotheses, if needed
360 InitAvailableHypotheses();
362 if (myHypothesesMap.contains(aHypType)) {
363 aHypData = myHypothesesMap[aHypType];
365 else if (myAlgorithmsMap.contains(aHypType)) {
366 aHypData = myAlgorithmsMap[aHypType];
371 //================================================================================
373 * \brief Return the HypothesisData holding a name of a group of hypotheses
374 * a given hypothesis belongs to
376 //================================================================================
378 HypothesisData* GetGroupTitle( const HypothesisData* hyp, const bool isAlgo )
380 static std::vector< std::vector< HypothesisData > > theGroups;
381 if ( theGroups.empty() )
383 theGroups.resize(14); // 14: isAlgo * 10 + dim
385 QString dummyS("GROUP");
386 QList<int> dummyIL; dummyIL << 1;
388 HypothesisData group( dummyS,dummyS,dummyS,dummyS,dummyS,dummyS,dummyS,-1,-1,
389 dummyIL, 0, dummySL,dummySL,dummySL,dummySL );
392 theGroups[ key ].push_back( group );
397 group.Label = "GROUP:" + QObject::tr( "SMESH_1D_ALGO_GROUP_BASIC" );
398 theGroups[ key ].push_back( group );
400 group.Label = "GROUP:" + QObject::tr( "SMESH_1D_ALGO_GROUP_ADVANCED" );
401 theGroups[ key ].push_back( group );
406 group.Label = "GROUP:" + QObject::tr( "SMESH_1D_HYP_GROUP_BASIC" );
407 theGroups[ key ].push_back( group );
409 group.Label = "GROUP:" + QObject::tr( "SMESH_1D_HYP_GROUP_PROGRESSION" );
410 theGroups[ key ].push_back( group );
412 group.Label = "GROUP:" + QObject::tr( "SMESH_1D_HYP_GROUP_ADVANCED" );
413 theGroups[ key ].push_back( group );
418 group.Label = "GROUP:" + QObject::tr( "SMESH_2D_ALGO_GROUP_REGULAR" );
419 theGroups[ key ].push_back( group );
421 group.Label = "GROUP:" + QObject::tr( "SMESH_2D_ALGO_GROUP_FREE" );
422 theGroups[ key ].push_back( group );
424 group.Label = "GROUP:" + QObject::tr( "SMESH_2D_ALGO_GROUP_ADVANCED" );
425 theGroups[ key ].push_back( group );
430 group.Label = "GROUP:" + QObject::tr( "SMESH_3D_ALGO_GROUP_REGULAR" );
431 theGroups[ key ].push_back( group );
433 group.Label = "GROUP:" + QObject::tr( "SMESH_3D_ALGO_GROUP_FREE" );
434 theGroups[ key ].push_back( group );
436 group.Label = "GROUP:" + QObject::tr( "SMESH_3D_ALGO_GROUP_ADVANCED" );
437 theGroups[ key ].push_back( group );
440 size_t key = 0, groupID = 0;
441 if ( hyp && !hyp->Dim.isEmpty() )
443 key = hyp->Dim[0] + isAlgo * 10;
444 groupID = hyp->GroupID;
447 if ( key < theGroups.size() && !theGroups[ key ].empty() )
449 std::vector< HypothesisData > & group = theGroups[ key ];
450 return & ( groupID < group.size() ? group[ groupID ] : group.back() );
452 return & theGroups[ 0 ][ 0 ];
455 bool IsAvailableHypothesis(const HypothesisData* algoData,
456 const QString& hypType,
462 if ( algoData->BasicHypos.contains( hypType ))
464 if ( algoData->OptionalHypos.contains( hypType )) {
471 bool IsCompatibleAlgorithm(const HypothesisData* algo1Data,
472 const HypothesisData* algo2Data)
474 if ( !algo1Data || !algo2Data )
476 const HypothesisData* algoIn = algo1Data, *algoMain = algo2Data;
477 if ( algoIn->Dim.first() > algoMain->Dim.first() ) {
478 algoIn = algo2Data; algoMain = algo1Data;
480 // look for any output type of algoIn between input types of algoMain
481 QStringList::const_iterator inElemType = algoIn->OutputTypes.begin();
482 for ( ; inElemType != algoIn->OutputTypes.end(); ++inElemType )
483 if ( algoMain->InputTypes.contains( *inElemType ))
488 SMESHGUI_GenericHypothesisCreator* GetHypothesisCreator(const QString& aHypType)
490 if(MYDEBUG) MESSAGE("Get HypothesisCreator for " << aHypType.toLatin1().data());
492 SMESHGUI_GenericHypothesisCreator* aCreator = 0;
494 // check, if creator for this hypothesis type already exists
496 //if (myHypCreatorMap.find(aHypType) != myHypCreatorMap.end()) {
497 // aCreator = myHypCreatorMap[aHypType];
501 // 1. Init list of available hypotheses, if needed
502 InitAvailableHypotheses();
504 // 2. Get names of plugin libraries
505 HypothesisData* aHypData = GetHypothesisData(aHypType);
509 QString aClientLibName = aHypData->ClientLibName;
510 QString aServerLibName = aHypData->ServerLibName;
512 // 3. Load Client Plugin Library
514 // load plugin library
515 if(MYDEBUG) MESSAGE("Loading client meshers plugin library ...");
516 LibHandle libHandle = LoadLib( aClientLibName.toLatin1().data() );
518 // report any error, if occured
521 const char* anError = "Can't load client meshers plugin library";
523 const char* anError = dlerror();
525 INFOS(anError); // always display this kind of error !
529 // get method, returning hypothesis creator
530 if(MYDEBUG) MESSAGE("Find GetHypothesisCreator() method ...");
531 typedef SMESHGUI_GenericHypothesisCreator* (*GetHypothesisCreator) \
533 GetHypothesisCreator procHandle =
534 (GetHypothesisCreator)GetProc(libHandle, "GetHypothesisCreator");
536 if(MYDEBUG) MESSAGE("bad hypothesis client plugin library");
537 UnLoadLib(libHandle);
540 // get hypothesis creator
541 if(MYDEBUG) MESSAGE("Get Hypothesis Creator for " << aHypType.toLatin1().data());
542 aCreator = procHandle( aHypType );
544 if(MYDEBUG) MESSAGE("no such a hypothesis in this plugin");
547 // map hypothesis creator to a hypothesis name
549 //myHypCreatorMap[aHypType] = aCreator;
551 //rnv : This dynamic property of the QObject stores the name of the plugin.
552 // It is used to obtain plugin root dir environment variable
553 // in the SMESHGUI_HypothesisDlg class. Plugin root dir environment
554 // variable is used to display documentation.
555 aCreator->setProperty(SMESH::Plugin_Name(),aHypData->PluginName);
560 catch (const SALOME::SALOME_Exception& S_ex) {
561 SalomeApp_Tools::QtCatchCorbaException(S_ex);
569 SMESH::SMESH_Hypothesis_ptr CreateHypothesis(const QString& aHypType,
570 const QString& aHypName,
573 if(MYDEBUG) MESSAGE("Create " << aHypType.toLatin1().data() <<
574 " with name " << aHypName.toLatin1().data());
575 HypothesisData* aHypData = GetHypothesisData(aHypType);
576 QString aServLib = aHypData->ServerLibName;
578 SMESH::SMESH_Hypothesis_var aHypothesis;
579 aHypothesis = SMESHGUI::GetSMESHGen()->CreateHypothesis(aHypType.toLatin1().data(),
580 aServLib.toLatin1().data());
581 if (!aHypothesis->_is_nil()) {
582 _PTR(SObject) aHypSObject = SMESH::FindSObject(aHypothesis.in());
584 if (!aHypName.isEmpty())
585 SMESH::SetName(aHypSObject, aHypName);
586 SMESHGUI::Modified();
587 SMESHGUI::GetSMESHGUI()->updateObjBrowser();
588 return aHypothesis._retn();
591 } catch (const SALOME::SALOME_Exception & S_ex) {
592 SalomeApp_Tools::QtCatchCorbaException(S_ex);
595 return SMESH::SMESH_Hypothesis::_nil();
598 bool IsApplicable(const QString& aHypType,
599 GEOM::GEOM_Object_ptr theGeomObject,
600 const bool toCheckAll)
602 if ( getenv("NO_LIMIT_ALGO_BY_SHAPE")) // allow a workaround for a case if
603 return true; // IsApplicable() returns false due to a bug
605 HypothesisData* aHypData = GetHypothesisData(aHypType);
606 QString aServLib = aHypData->ServerLibName;
607 return SMESHGUI::GetSMESHGen()->IsApplicable( aHypType.toLatin1().data(),
608 aServLib.toLatin1().data(),
614 bool AddHypothesisOnMesh (SMESH::SMESH_Mesh_ptr aMesh, SMESH::SMESH_Hypothesis_ptr aHyp)
616 if(MYDEBUG) MESSAGE ("SMESHGUI::AddHypothesisOnMesh");
617 int res = SMESH::HYP_UNKNOWN_FATAL;
618 SUIT_OverrideCursor wc;
620 if (!aMesh->_is_nil()) {
621 _PTR(SObject) SM = SMESH::FindSObject(aMesh);
622 GEOM::GEOM_Object_var aShapeObject = SMESH::GetShapeOnMeshOrSubMesh(SM);
624 CORBA::String_var error;
625 res = aMesh->AddHypothesis(aShapeObject, aHyp, error.out());
626 if (res < SMESH::HYP_UNKNOWN_FATAL) {
627 _PTR(SObject) aSH = SMESH::FindSObject(aHyp);
629 SMESH::ModifiedMesh(SM, false, aMesh->NbNodes()==0);
632 if (res > SMESH::HYP_OK) {
634 processHypothesisStatus(res, aHyp, true, error.in() );
638 catch(const SALOME::SALOME_Exception& S_ex) {
640 SalomeApp_Tools::QtCatchCorbaException(S_ex);
641 res = SMESH::HYP_UNKNOWN_FATAL;
644 return res < SMESH::HYP_UNKNOWN_FATAL;
648 bool AddHypothesisOnSubMesh (SMESH::SMESH_subMesh_ptr aSubMesh, SMESH::SMESH_Hypothesis_ptr aHyp)
650 if(MYDEBUG) MESSAGE("SMESHGUI::AddHypothesisOnSubMesh() ");
651 int res = SMESH::HYP_UNKNOWN_FATAL;
652 SUIT_OverrideCursor wc;
654 if (!aSubMesh->_is_nil() && ! aHyp->_is_nil()) {
656 SMESH::SMESH_Mesh_var aMesh = aSubMesh->GetFather();
657 _PTR(SObject) SsubM = SMESH::FindSObject(aSubMesh);
658 GEOM::GEOM_Object_var aShapeObject = SMESH::GetShapeOnMeshOrSubMesh(SsubM);
659 if (!aMesh->_is_nil() && SsubM && !aShapeObject->_is_nil())
661 CORBA::String_var error;
662 res = aMesh->AddHypothesis( aShapeObject, aHyp, error.out() );
663 if (res < SMESH::HYP_UNKNOWN_FATAL) {
664 _PTR(SObject) meshSO = SMESH::FindSObject(aMesh);
666 SMESH::ModifiedMesh(meshSO, false, aMesh->NbNodes()==0);
668 if (res > SMESH::HYP_OK) {
670 processHypothesisStatus( res, aHyp, true, error.in() );
675 SCRUTE(aHyp->_is_nil());
676 SCRUTE(aMesh->_is_nil());
678 SCRUTE(aShapeObject->_is_nil());
681 catch(const SALOME::SALOME_Exception& S_ex) {
683 SalomeApp_Tools::QtCatchCorbaException(S_ex);
684 res = SMESH::HYP_UNKNOWN_FATAL;
688 SCRUTE(aSubMesh->_is_nil());
689 SCRUTE(aHyp->_is_nil());
691 return res < SMESH::HYP_UNKNOWN_FATAL;
694 bool RemoveHypothesisOrAlgorithmOnMesh (const Handle(SALOME_InteractiveObject)& IObject)
696 int res = SMESH::HYP_UNKNOWN_FATAL;
697 SUIT_OverrideCursor wc;
700 _PTR(Study) aStudy = GetActiveStudyDocument();
701 _PTR(SObject) aHypObj = aStudy->FindObjectID( IObject->getEntry() );
704 _PTR(SObject) MorSM = SMESH::GetMeshOrSubmesh( aHypObj );
705 _PTR(SObject) aRealHypo;
706 if( aHypObj->ReferencedObject( aRealHypo ) )
708 SMESH_Hypothesis_var hypo = SMESH_Hypothesis::_narrow( SObjectToObject( aRealHypo ) );
709 RemoveHypothesisOrAlgorithmOnMesh( MorSM, hypo );
713 SMESH_Hypothesis_var hypo = SMESH_Hypothesis::_narrow( SObjectToObject( aHypObj ) );
714 SObjectList meshList = GetMeshesUsingAlgoOrHypothesis( hypo );
715 for( size_t i = 0; i < meshList.size(); i++ )
716 RemoveHypothesisOrAlgorithmOnMesh( meshList[ i ], hypo );
720 catch(const SALOME::SALOME_Exception& S_ex)
723 SalomeApp_Tools::QtCatchCorbaException(S_ex);
724 res = SMESH::HYP_UNKNOWN_FATAL;
726 return res < SMESH::HYP_UNKNOWN_FATAL;
729 bool RemoveHypothesisOrAlgorithmOnMesh (_PTR(SObject) MorSM,
730 SMESH::SMESH_Hypothesis_ptr anHyp)
732 int res = SMESH::HYP_UNKNOWN_FATAL;
733 SUIT_OverrideCursor wc;
737 GEOM::GEOM_Object_var aShapeObject = SMESH::GetShapeOnMeshOrSubMesh(MorSM);
738 SMESH::SMESH_Mesh_var aMesh = SMESH::SObjectToInterface<SMESH::SMESH_Mesh>(MorSM);
739 SMESH::SMESH_subMesh_var aSubMesh = SMESH::SObjectToInterface<SMESH::SMESH_subMesh>(MorSM);
741 if (!aSubMesh->_is_nil())
742 aMesh = aSubMesh->GetFather();
744 if (!aMesh->_is_nil()) {
745 if (aMesh->HasShapeToMesh() && !aShapeObject->_is_nil()) {
746 res = aMesh->RemoveHypothesis(aShapeObject, anHyp);
747 if (res < SMESH::HYP_UNKNOWN_FATAL) {
748 _PTR(SObject) meshSO = SMESH::FindSObject(aMesh);
750 SMESH::ModifiedMesh(meshSO, false, aMesh->NbNodes()==0);
754 else if(!aMesh->HasShapeToMesh()){
755 res = aMesh->RemoveHypothesis(aShapeObject, anHyp);
756 if (res < SMESH::HYP_UNKNOWN_FATAL) {
757 _PTR(SObject) meshSO = SMESH::FindSObject(aMesh);
759 SMESH::ModifiedMesh(meshSO, false, aMesh->NbNodes()==0);
762 if (res > SMESH::HYP_OK) {
764 processHypothesisStatus(res, anHyp, false);
768 } catch(const SALOME::SALOME_Exception& S_ex) {
770 SalomeApp_Tools::QtCatchCorbaException(S_ex);
771 res = SMESH::HYP_UNKNOWN_FATAL;
774 return res < SMESH::HYP_UNKNOWN_FATAL;
777 SObjectList GetMeshesUsingAlgoOrHypothesis(SMESH::SMESH_Hypothesis_ptr AlgoOrHyp)
779 SObjectList listSOmesh;
780 listSOmesh.resize(0);
782 unsigned int index = 0;
783 if (!AlgoOrHyp->_is_nil()) {
784 _PTR(SObject) SO_Hypothesis = SMESH::FindSObject(AlgoOrHyp);
787 SMESHGUI::activeStudy()->studyDS()->FindDependances(SO_Hypothesis);
789 if(MYDEBUG) MESSAGE("SMESHGUI::GetMeshesUsingAlgoOrHypothesis(): dependency number ="<<listSO.size());
790 for (unsigned int i = 0; i < listSO.size(); i++) {
791 _PTR(SObject) SO = listSO[i];
793 _PTR(SObject) aFather = SO->GetFather();
795 _PTR(SObject) SOfatherFather = aFather->GetFather();
796 if (SOfatherFather) {
797 if(MYDEBUG) MESSAGE("SMESHGUI::GetMeshesUsingAlgoOrHypothesis(): dependency added to list");
799 listSOmesh.resize(index);
800 listSOmesh[index - 1] = SOfatherFather;
807 if (MYDEBUG) MESSAGE("SMESHGUI::GetMeshesUsingAlgoOrHypothesis(): completed");
811 #define CASE2MESSAGE(enum) case SMESH::enum: msg = QObject::tr( "STATE_" #enum ); break;
812 QString GetMessageOnAlgoStateErrors(const algo_error_array& errors)
814 QString resMsg; // PAL14861 = QObject::tr("SMESH_WRN_MISSING_PARAMETERS") + ":\n";
815 for ( size_t i = 0; i < errors.length(); ++i ) {
816 const SMESH::AlgoStateError & error = errors[ i ];
817 const bool hasAlgo = ( strlen( error.algoName ) != 0 );
820 msg = QObject::tr( "STATE_ALGO_MISSING" );
822 switch( error.state ) {
823 CASE2MESSAGE( HYP_MISSING );
824 CASE2MESSAGE( HYP_NOTCONFORM );
825 CASE2MESSAGE( HYP_BAD_PARAMETER );
826 CASE2MESSAGE( HYP_BAD_GEOMETRY );
829 // apply args to message:
832 msg = msg.arg( error.algoName.in() );
834 msg = msg.arg( error.algoDim );
836 msg = msg.arg( QObject::tr( error.isGlobalAlgo ? "GLOBAL_ALGO" : "LOCAL_ALGO" ));
837 // %4 - hypothesis dim == algoDim
838 msg = msg.arg( error.algoDim );
840 if ( i ) resMsg += ";\n";
845 } // end of namespace SMESH