Version: 8.3.0
EditionProc.cxx
Go to the documentation of this file.
1 // Copyright (C) 2006-2016 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 "EditionProc.hxx"
21 
22 #include "QtGuiContext.hxx"
23 #include "LinkInfo.hxx"
24 #include "Logger.hxx"
25 #include <QComboBox>
26 
27 //#define _DEVDEBUG_
28 #include "YacsTrace.hxx"
29 
30 #include <cassert>
31 
32 using namespace std;
33 
34 using namespace YACS;
35 using namespace YACS::HMI;
36 using namespace YACS::ENGINE;
37 
38 EditionProc::EditionProc(Subject* subject,
39  QWidget* parent,
40  const char* name)
41  : EditionBloc(subject, parent, name)
42 {
43  DEBTRACE("EditionProc::EditionProc");
44  _statusLog = new QTextEdit(this);
45  _wid->gridLayout1->addWidget(_statusLog);
46  _errorLog = "";
47  _modifLog = "";
48 
49  if (!QtGuiContext::getQtCurrent()->isEdition())
50  {
51  QHBoxLayout* hbox = new QHBoxLayout();
52  QLabel* la = new QLabel("Shutdown level:",this);
53  QComboBox* cb = new QComboBox(this);
54  cb->addItem("0",0 );
55  cb->addItem("1",1 );
56  cb->addItem("2",2 );
57  cb->addItem("3",3 );
58  int level=1;
59  if (QtGuiContext::getQtCurrent()->getGuiExecutor())
61  DEBTRACE(level);
62  cb->setCurrentIndex(level);
63  connect(cb, SIGNAL(currentIndexChanged(int)), this, SLOT(onLevelChange(int)));
64  hbox->addWidget(la);
65  hbox->addWidget(cb);
66  _wid->gridLayout1->addLayout(hbox,4,0);
67  }
68 }
69 
71 {
72  DEBTRACE("EditionProc::~EditionProc");
73 }
74 
75 void EditionProc::update(GuiEvent event, int type, Subject* son)
76 {
77  DEBTRACE("EditionProc::update " << GuiObserver::eventName(event));
78  EditionBloc::update(event, type, son);
79  string statusLog = "";
80  switch (event)
81  {
82  case EDIT:
83  if (QtGuiContext::getQtCurrent()->_setOfModifiedSubjects.empty())
84  _modifLog = "";
85  else
86  _modifLog = "--- some elements are modified and not taken into account. Confirmation or annulation required ---\n";
87  case UPDATE:
88  synchronize();
89  break;
90  case UPDATEPROGRESS:
91  {
92  if(type != YACS::FINISHED)break;
93  if (!QtGuiContext::getQtCurrent()) break;
94  if (!QtGuiContext::getQtCurrent()->getGuiExecutor()) break;
97  _statusLog->setText(QString::fromStdString(_errorLog));
98  break;
99  }
100  default:
101  ;
102  }
103 
104 }
105 
107 {
108  DEBTRACE("EditionProc::synchronize");
110  Logger* logger = 0;
111  string statusLog = "";
112 
113  if (!QtGuiContext::getQtCurrent()->isEdition())
114  return;
115  if (!proc->isValid())
116  {
117  _errorLog = "--- YACS schema is not valid ---\n\n";
118  _errorLog += proc->getErrorReport();
120  }
121  else
122  {
123  // --- Check consistency
124  LinkInfo info(LinkInfo::ALL_DONT_STOP);
125  _errorLog="";
126  try
127  {
128  proc->checkConsistency(info);
129  if (info.areWarningsOrErrors())
130  _errorLog += info.getGlobalRepr();
131  else
132  {
133  _errorLog += "--- No Validity Errors ---\n";
134  _errorLog += "--- No Consistency Errors ---\n";
135  }
136  }
137  catch (Exception &ex)
138  {
139  _errorLog = "--- YACS schema has consistency errors ---\n\n";
140  _errorLog += ex.what();
141  }
143  }
144  // --- Add initial logger info
145  logger = proc->getLogger("parser");
146  if (!logger->isEmpty())
147  {
148  _errorLog += "--- Original file import log ---\n";
149  _errorLog += logger->getStr();
150  }
151  statusLog = _modifLog + _errorLog;
152  _statusLog->setText(statusLog.c_str());
153 }
154 
156 {
157  DEBTRACE("EditionProc::onLevelChange " << index);
158  if (QtGuiContext::getQtCurrent()->getGuiExecutor())
160 }