Salome HOME
c59a1ddc64e84ebe0cd923592a2bee1e97d7e4ed
[modules/yacs.git] / src / genericgui / EditionProc.cxx
1 //  Copyright (C) 2006-2008  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.
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 #include "EditionProc.hxx"
20
21 #include "QtGuiContext.hxx"
22 #include "LinkInfo.hxx"
23 #include "Logger.hxx"
24
25 //#define _DEVDEBUG_
26 #include "YacsTrace.hxx"
27
28 #include <cassert>
29
30 using namespace std;
31
32 using namespace YACS;
33 using namespace YACS::HMI;
34 using namespace YACS::ENGINE;
35
36 EditionProc::EditionProc(Subject* subject,
37                          QWidget* parent,
38                          const char* name)
39   : EditionBloc(subject, parent, name)
40 {
41   DEBTRACE("EditionProc::EditionProc");
42   _statusLog = new QTextEdit(this);
43   _wid->gridLayout1->addWidget(_statusLog);
44   _errorLog = "";
45   _modifLog = "";
46 }
47
48 EditionProc::~EditionProc()
49 {
50   DEBTRACE("EditionProc::~EditionProc");
51 }
52
53 void EditionProc::update(GuiEvent event, int type, Subject* son)
54 {
55   DEBTRACE("EditionProc::update " << GuiObserver::eventName(event));
56   EditionBloc::update(event, type, son);
57   YACS::ENGINE::Proc* proc = QtGuiContext::getQtCurrent()->getProc();
58   Logger* logger = 0;
59   string statusLog = "";
60   switch (event)
61     {
62     case EDIT:
63       if (QtGuiContext::getQtCurrent()->_setOfModifiedSubjects.empty())
64         _modifLog = "";
65       else
66         _modifLog = "--- some elements are modified and not taken into account. Confirmation or annulation required ---\n";
67       statusLog = _modifLog + _errorLog;
68       _statusLog->setText(statusLog.c_str());
69       break;
70     case UPDATE:
71       if (!proc->isValid())
72         {
73           _errorLog = "--- YACS schema is not valid ---\n\n";
74           _errorLog += proc->getErrorReport();
75         }
76       else
77         {
78           // --- Check consistency
79           LinkInfo info(LinkInfo::ALL_DONT_STOP);
80           proc->checkConsistency(info);
81           if (info.areWarningsOrErrors())
82             _errorLog = info.getGlobalRepr();
83           else
84             {
85               _errorLog = "--- No Validity Errors ---\n";
86               _errorLog += "--- No Consistency Errors ---\n";
87             }
88         }
89       // --- Add initial logger info
90       logger = proc->getLogger("parser");
91       if (!logger->isEmpty())
92         {
93           _errorLog += "--- Original file import log ---\n";
94           _errorLog += logger->getStr();  
95         }
96       statusLog = _modifLog + _errorLog;
97       _statusLog->setText(statusLog.c_str());
98       break;
99     default:
100       ;
101     }
102
103 }