Salome HOME
Copyright update 2020
[modules/homard.git] / src / HOMARDGUI / MonEditFile.cxx
1 // Copyright (C) 2011-2020  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #include "MonEditFile.h"
21
22 #include <QFile>
23 #include <QTextStream>
24 #include <QMessageBox>
25
26 #include "SalomeApp_Tools.h"
27 #include "HOMARDGUI_Utils.h"
28 #include "HomardQtCommun.h"
29 #include <utilities.h>
30
31 using namespace std;
32
33 /* ---------------------------------------------------------
34  * MonEditFile classe derivee de EditFile
35  *               elle meme generee par uic
36  * Ouvre le fichier passe en parametre
37  * et affiche le texte correspondant dans la fenetre de log
38  * ---------------------------------------------------------
39  */
40
41 /* ---------------------------------------------------------
42  * MonEditFile Constructeur
43  * ---------------------------------------------------------
44  */
45 MonEditFile::MonEditFile( QWidget* parent,  bool modal,
46                           HOMARD::HOMARD_Gen_var myHomardGen,
47                           QString aFileName, int option):
48 //    QWidget(0),
49     Ui_EditFile(),
50     _aFileName (aFileName),
51     _option (option),
52     _codret (0)
53 {
54   MESSAGE("Debut de MonEditFile " << aFileName.toStdString().c_str());
55   setupUi(this);
56   InitConnect();
57   EditText();
58 }
59 /*
60  *  Destroys the object and frees any allocated resources
61  */
62 MonEditFile::~MonEditFile()
63 {
64    MESSAGE("Destructeur de ~MonEditFile");
65 }
66 // ------------------------------------------------------------------------
67 void MonEditFile::InitConnect()
68 // ------------------------------------------------------------------------
69 {
70     connect( buttonQuit,     SIGNAL(pressed()), this, SLOT(close()));
71     connect( buttonPrint,    SIGNAL(pressed()), this, SLOT(PushOnPrint()));
72 }
73 // ------------------------------------------------------------------------
74 void MonEditFile::EditText()
75 // ------------------------------------------------------------------------
76 {
77 // Creation de l'objet fichier QT associe
78   QFile file( _aFileName );
79 // Ouverture
80   bool bOpen = file.open( QIODevice::ReadOnly | QIODevice::Text ) ;
81 //
82   if ( bOpen )
83   {
84 // Lecture
85 //    Remarque : il serait plus clair de tout lire d'un coup mais cela ne marche pas !
86 //               alors on fait ligne par ligne et on cumule en ajoutant un saut de ligne.
87     QTextStream stream( &file );
88     QString tout;
89     while ( !stream.atEnd() )
90     {
91       tout = tout + stream.readLine() + "\n" ;
92     }
93 //       tout = stream.readAll() ;
94     QTBEditFile->setPlainText( tout );
95   }
96   else
97   {
98     // Option = 0 : emission d'un message d'erreur
99     if ( _option == 0 )
100     {
101       MESSAGE( "EditText " << _aFileName.toStdString().c_str() << " est impossible a ouvrir ");
102       QMessageBox::warning( 0, QObject::tr("HOM_WARNING"),
103                               QObject::tr("HOM_SELECT_FILE_3") );
104     }
105     // Sinon : rien
106     _codret = 1 ;
107   }
108 }
109 // ------------------------------------------------------------------------
110 void MonEditFile::PushOnPrint()
111 // ------------------------------------------------------------------------
112 {
113   MESSAGE("Debut de MonEditFile::PushOnPrint")
114   QMessageBox::warning( 0, QObject::tr("HOM_WARNING"),
115                             QObject::tr("HOM_INACTIVE_BUTTON") );
116   return;
117 }
118
119