X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FHOMARDGUI%2FHOMARDGUI_Utils.cxx;h=ec600c8ffe451de8985a8ed21e2b9d4c450630b1;hb=refs%2Ftags%2FV9_13_0b1;hp=2db82b832b4367c272dc0fb5538e83930474eb52;hpb=bdbb00479184579ff9ec2e33886894326d4d6a0f;p=modules%2Fhomard.git diff --git a/src/HOMARDGUI/HOMARDGUI_Utils.cxx b/src/HOMARDGUI/HOMARDGUI_Utils.cxx index 2db82b83..ec600c8f 100644 --- a/src/HOMARDGUI/HOMARDGUI_Utils.cxx +++ b/src/HOMARDGUI/HOMARDGUI_Utils.cxx @@ -1,3 +1,22 @@ +// 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" @@ -13,7 +32,6 @@ #include "SalomeApp_Study.h" #include "SALOME_ListIO.hxx" -#include "SALOME_ListIteratorOfListIO.hxx" #include "SALOMEconfig.h" #include "utilities.h" @@ -24,20 +42,12 @@ #include #include #include +#ifndef WIN32 #include +#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 @@ -50,21 +60,19 @@ SUIT_Study* HOMARD_UTILS::GetActiveStudy() 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(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 @@ -74,14 +82,14 @@ void HOMARD_UTILS::updateObjBrowser() SalomeApp_Application* app = dynamic_cast(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( module ); if ( appMod ) { app->updateObjectBrowser(); appMod->updateObjBrowser( true ); } - else + else MESSAGE( "--- HOMARD::updateObjBrowser: appMod = NULL"); } } @@ -97,13 +105,12 @@ const SALOME_ListIO& HOMARD_UTILS::selectedIO() 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 @@ -116,11 +123,11 @@ int HOMARD_UTILS::IObjectCount() { 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 @@ -142,20 +149,7 @@ Handle(SALOME_InteractiveObject) HOMARD_UTILS::lastIObject() } //================================================================ -// 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 @@ -182,6 +176,7 @@ bool HOMARD_UTILS::isObject(_PTR(SObject) MonObj, QString TypeObject, int option if ( option == 0 ) { int position = Type.lastIndexOf(TypeObject); +// MESSAGE("position = "< 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( 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( 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); + } } //=========================================================================================================