+// Copyright (C) 2011-2024 CEA, EDF
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
#include "HOMARDGUI_Utils.h"
#include "SalomeApp_Study.h"
#include "SALOME_ListIO.hxx"
-#include "SALOME_ListIteratorOfListIO.hxx"
#include "SALOMEconfig.h"
#include "utilities.h"
#include <qstring.h>
#include <qstringlist.h>
#include <sys/stat.h>
+#ifndef WIN32
#include <dirent.h>
+#endif
SALOME_ListIO HOMARD_UTILS::mySelected;
-//================================================================
-// Function : GetCStudy
-// Returne un pointeur sur l'etude courante
-//================================================================
- _PTR(Study) HOMARD_UTILS::GetCStudy(const SalomeApp_Study* theStudy)
-{
- return theStudy->studyDS();
-}
-
-
//================================================================
// Function : GetActiveStudy
// Returne un pointeur sur l'etude active
else
return NULL;
}
-
+
//================================================================
-// Function : GetActiveStudyDocument
+// Function : getStudy
// Returne un pointeur sur l'etude active
//================================================================
-_PTR(Study) HOMARD_UTILS::GetActiveStudyDocument()
+_PTR(Study) HOMARD_UTILS::getStudy()
{
- SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>(GetActiveStudy());
- if (aStudy){
- return aStudy->studyDS();
- }
- else
- return _PTR(Study)();
+ static _PTR(Study) _study;
+ if(!_study)
+ _study = SalomeApp_Application::getStudy();
+ return _study;
}
-
+
//================================================================
// Function : updateObjBrowser
// Purpose : met a jour l arbre d 'etude pour Homard
SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>(SUIT_Session::session()->activeApplication());
if (app) {
// Le nom identifiant doit etre la valeur du parametre
- // name de la section HOMARD du fichier SalomeApp.xml
+ // name de la section HOMARD du fichier SalomeApp.xml
CAM_Module* module = app->module("Homard" );
SalomeApp_Module* appMod = dynamic_cast<SalomeApp_Module*>( module );
if ( appMod ) {
app->updateObjectBrowser();
appMod->updateObjBrowser( true );
}
- else
+ else
MESSAGE( "--- HOMARD::updateObjBrowser: appMod = NULL");
}
}
if( aSelectionMgr )
{
aSelectionMgr->selectedObjects( mySelected );
- for (SALOME_ListIteratorOfListIO it (mySelected); it.More(); it.Next())
- SCRUTE(it.Value()->getEntry());
+ for (SALOME_ListIteratorOfListIO it (mySelected); it.More(); it.Next())
+ SCRUTE(it.Value()->getEntry());
};
return mySelected;
-
}
-
+
//================================================================
// Function : IObjectCount
// Return the number of selected objects
{
aSelectionMgr->selectedObjects( mySelected );
SCRUTE(mySelected.Extent());
- return mySelected.Extent();
+ return mySelected.Extent();
}
return 0;
}
-
+
//================================================================
// Function : firstIObject
// Purpose : Return the first selected object in the selected object list
}
//================================================================
-// Function : isXmgrace
-// Retourne vrai si le fichier associe est de type ASCII
-//================================================================
-bool HOMARD_UTILS::isXmgrace(_PTR(SObject) MonObj)
-{
- _PTR(GenericAttribute) anAttr;
- if (!MonObj->FindAttribute(anAttr, "AttributeComment")) return false;
- _PTR(AttributeComment) aFileComment (anAttr);
- std::string Type = aFileComment->Value();
- if (QString(Type.c_str()) == QString("HomardOuputQual")) return true;
- return false;
-}
-//================================================================
-// Retourne vrai si l objet est du type voulu
+// Retourne vrai si l'objet est du type voulu
// . Dans le cas d'un cas, d'une hypothese, d'une zone, on se contente
// d'une comparaison simple entre le type stocke et TypeObject.
// . Pour l'iteration, le type stocke en attribut est sous la forme
if ( option == 0 )
{
int position = Type.lastIndexOf(TypeObject);
+// MESSAGE("position = "<<position);
if ( position == 0 ) { bOK = true ; }
}
else
return bOK ;
}
//================================================================
-// Retourne vrai si l objet est une frontiere discrete
+// Retourne vrai si l'objet est une frontiere CAO
//================================================================
-bool HOMARD_UTILS::isBoundaryDi(_PTR(SObject) MonObj)
+bool HOMARD_UTILS::isBoundaryCAO(_PTR(SObject) MonObj)
{
- return isObject( MonObj, QString("BoundaryDiHomard"), -1 ) ;
+ return isObject( MonObj, QString("BoundaryCAOHomard"), -1 ) ;
}
//================================================================
-// Retourne vrai si l objet est une zone
+// Retourne vrai si l'objet est une frontiere analytique
//================================================================
-bool HOMARD_UTILS::isZone(_PTR(SObject) MonObj)
+bool HOMARD_UTILS::isBoundaryAn(_PTR(SObject) MonObj)
{
- return isObject( MonObj, QString("ZoneHomard"), -1 ) ;
+ return isObject( MonObj, QString("BoundaryAnHomard"), -1 ) ;
}
//================================================================
-// Retourne vrai si l objet est une Hypothese
+// Retourne vrai si l'objet est une frontiere discrete
//================================================================
-bool HOMARD_UTILS::isHypo(_PTR(SObject) MonObj)
-{
- return isObject( MonObj, QString("HypoHomard"), -1 ) ;
-}
-//================================================================
-// Retourne vrai si l objet est une iteration
-//================================================================
-bool HOMARD_UTILS::isIter(_PTR(SObject) MonObj)
+bool HOMARD_UTILS::isBoundaryDi(_PTR(SObject) MonObj)
{
- return isObject( MonObj, QString("IterationHomard"), 0 ) ;
+ return isObject( MonObj, QString("BoundaryDiHomard"), -1 ) ;
}
//================================================================
-// Retourne vrai si l objet est un cas
+// Retourne vrai si l'objet est un cas
//================================================================
bool HOMARD_UTILS::isCase(_PTR(SObject) MonObj)
{
return isObject( MonObj, QString("CasHomard"), -1 ) ;
}
//================================================================
-// Retourne vrai si l objet est un fichier de messages
+// Retourne vrai si l'objet est une Hypothese
//================================================================
-bool HOMARD_UTILS::isFileMess(_PTR(SObject) MonObj)
+bool HOMARD_UTILS::isHypo(_PTR(SObject) MonObj)
{
- return isObject( MonObj, QString("Mess"), 0 ) ;
+ return isObject( MonObj, QString("HypoHomard"), -1 ) ;
}
//================================================================
-// Retourne vrai si l objet est un fichier de bilan
+// Retourne vrai si l'objet est une iteration
//================================================================
-bool HOMARD_UTILS::isFileSummary(_PTR(SObject) MonObj)
+bool HOMARD_UTILS::isIter(_PTR(SObject) MonObj)
{
- return isObject( MonObj, QString("Summary"), 0 ) ;
+ return isObject( MonObj, QString("IterationHomard"), 0 ) ;
}
//================================================================
-// Function : ChercheFileDansSelection
-// Retourne Le nom du fichier associe
+// Retourne vrai si l'objet est un schema YACS
//================================================================
-QString HOMARD_UTILS::ChercheFileDansSelection()
+bool HOMARD_UTILS::isYACS(_PTR(SObject) MonObj)
{
- MESSAGE("ChercheFileDansSelection");
- int nbSel = HOMARD_UTILS::IObjectCount() ;
- if (nbSel > 1 or nbSel == 0) return QString::null;
-
- Handle(SALOME_InteractiveObject) aIO = HOMARD_UTILS::firstIObject();
- ASSERT(aIO);
- if (!( aIO->hasEntry())) return QString::null;
-
- _PTR(Study) myStudy = HOMARD_UTILS::GetActiveStudyDocument();
- _PTR(SObject) aSObj ( myStudy->FindObjectID( aIO->getEntry() ) );
- if (!aSObj) return QString::null;
-
- _PTR(GenericAttribute) anAttr;
- if (!aSObj->FindAttribute(anAttr, "AttributeExternalFileDef")) return QString::null;
- _PTR(AttributeExternalFileDef) aFileName (anAttr);
- std::string aFile = aFileName->Value();
- SCRUTE(aFile);
- return QString(aFile.c_str());
+ return isObject( MonObj, QString("YACSHomard"), -1 ) ;
}
-
-//============================================================
-// Function ChercheDansDir
-// Cherche tous les fichiers dans la directory qui correspondent
-// a la fois a la base et au numero d iteration, numero d iteration +1
-// exple info.00.bilan
-// ou qual.tetr.00.dat
-//================================================================================
-QStringList HOMARD_UTILS::ChercheDansDir(QString direct, QString base, int numIter)
-//================================================================================
-{
- QStringList liste;
-
-
- QString strNum = QString("");
- if (numIter != -1) strNum = HOMARD_UTILS::Transforme(numIter);
- QString strNum1 = QString("");
- if (numIter != -1) strNum1 = HOMARD_UTILS::Transforme(numIter+1);
-
- struct dirent **namelist;
- int n = scandir(direct.toLatin1(), &namelist, 0, alphasort);
- while(n--)
- {
- QString fich =QString( namelist[n]->d_name);
- if (fich.contains(base) > 0)
- {
- if (numIter != -1)
- {
- if ((fich.contains(strNum)>0) or (fich.contains(strNum1)>0))
- liste.append(fich);
- }
- else
- {
- liste.append(fich);
- }
- }
- }
- return liste;
-}
-
-QString HOMARD_UTILS::Transforme(int num)
-{
- std::ostringstream nb ;
- nb << std::setw(2) << std::setfill('0') << num ;
- QString retour= QString(nb.str().c_str());
- return retour;
-
-}
-
-//=============================================================================
-void HOMARD_UTILS::AddNewRoot(int Tag, QString Racine)
-//=============================================================================
+//================================================================
+// Retourne vrai si l'objet est une zone
+//================================================================
+bool HOMARD_UTILS::isZone(_PTR(SObject) MonObj)
{
- _PTR(Study) myStudy = HOMARD_UTILS::GetActiveStudyDocument();
- ASSERT(myStudy);
- _PTR(StudyBuilder) myBuilder( myStudy->NewBuilder() );
- ASSERT(myBuilder);
- _PTR(SComponent) aFather=myStudy->FindComponent("HOMARD");
- ASSERT(aFather);
-
- _PTR(SObject) InfoRoot = myBuilder->NewObjectToTag (aFather, Tag);
- _PTR(GenericAttribute) anAttr;
- anAttr = myBuilder->FindOrCreateAttribute(InfoRoot, "AttributeName");
- _PTR(AttributeName) aName (anAttr);
- aName->SetValue(Racine.toStdString());
+ return isObject( MonObj, QString("ZoneHomard"), -1 ) ;
}
-//=============================================================================
-void HOMARD_UTILS::RangeSousTag(int Tag,QString FileName, int TagFichier, QString Comment,QString FileDir)
-//=============================================================================
+//================================================================
+// Retourne vrai si l'objet est un fichier de type TypeFile
+//================================================================
+bool HOMARD_UTILS::isFileType(_PTR(SObject) MonObj, QString TypeFile)
{
- _PTR(SObject) Root;
- _PTR(Study) myStudy = HOMARD_UTILS::GetActiveStudyDocument();
- ASSERT(myStudy);
- _PTR(StudyBuilder) myBuilder( myStudy->NewBuilder() );
- ASSERT(myBuilder);
- _PTR(SComponent) aFather=myStudy->FindComponent("HOMARD");
- ASSERT(aFather);
- bool found = aFather->FindSubObject(Tag,Root);
- ASSERT(found);
-
- _PTR(SObject) MonInfo = myBuilder->NewObjectToTag (Root, TagFichier);
- ASSERT(MonInfo);
- _PTR(GenericAttribute) anAttr;
- anAttr = myBuilder->FindOrCreateAttribute(MonInfo, "AttributeName");
- _PTR(AttributeName) aName (anAttr);
- aName->SetValue(FileName.toStdString());
- QString FileComplet = FileDir +QString("/") +FileName;
- anAttr = myBuilder->FindOrCreateAttribute(MonInfo, "AttributeExternalFileDef");
- _PTR(AttributeExternalFileDef) aFile (anAttr);
- aFile->SetValue((FileComplet).toStdString());
- anAttr = myBuilder->FindOrCreateAttribute(MonInfo, "AttributeComment");
- _PTR(AttributeComment) aComment (anAttr);
- aComment->SetValue(Comment.toStdString());
+ return isObject( MonObj, TypeFile, 0 ) ;
}
//=========================================================================================================
-void HOMARD_UTILS::PushOnHelp(QString monFichierAide)
+void HOMARD_UTILS::PushOnHelp(QString monFichierAide, QString contexte, QString LanguageShort)
{
- LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
- if (app) {
- HOMARDGUI* aHomardGUI = dynamic_cast<HOMARDGUI*>( app->module( "Homard" ) );
- app->onHelpContextModule(aHomardGUI ? app->moduleName(aHomardGUI->moduleName()) : QString(""), monFichierAide);
- }
+ MESSAGE("Debut de PushOnHelp avec monFichierAide = "<< monFichierAide.toStdString().c_str());
+ LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
+ if (app)
+ {
+ HOMARDGUI* aHomardGUI = dynamic_cast<HOMARDGUI*>( app->module( "Homard" ) );
+ // Repertoire de reference de la documentation
+ QString rep = aHomardGUI ? app->moduleName(aHomardGUI->moduleName()) : QString("") ;
+ // WARNING/ATTENTION : si on savait recuperer la langue depuis les preferences, on ne ferait pas le passage par argument
+// SUIT_ResourceMgr* resMgr = getApp()->resourceMgr();
+// SUIT_ResourceMgr* resMgr = myModule->getApp()->resourceMgr();
+// QString langue = resMgr->stringValue("language", "language", "en");
+// QString langue = "fr" ;
+ MESSAGE(". LanguageShort " << LanguageShort.toStdString().c_str()) ;
+ // Complement du fichier
+ QString fichier = QString(LanguageShort+"/"+monFichierAide) ;
+ MESSAGE(". Appel de onHelpContextModule avec :");
+ MESSAGE(" rep = "<< rep.toStdString().c_str());
+ MESSAGE(" fichier = "<< fichier.toStdString().c_str());
+ MESSAGE(" contexte = "<< contexte.toStdString().c_str());
+ app->onHelpContextModule(rep, fichier, contexte);
+ }
}
//=========================================================================================================