1 // Copyright (C) 2006-2016 CEA/DEN, EDF R&D
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include "FormHPContainer.hxx"
21 #include "FormAdvParamContainer.hxx"
22 #include "HomogeneousPoolContainer.hxx"
23 #include "QtGuiContext.hxx"
24 #include "guiObservers.hxx"
26 #include "Resource.hxx"
27 #include "YacsTrace.hxx"
29 #include <QIntValidator>
33 #include <PyEditor_Editor.h>
41 FormHPContainer::FormHPContainer(QWidget *parent):FormContainerBase(parent),_poolSz(new QLineEdit(this)),_initScriptModified(false)
43 QIntValidator *iv(new QIntValidator(_poolSz)); iv->setRange(1,INT_MAX);
44 _poolSz->setValidator(iv);
45 label_15->setText("Size of pool :");
46 gridLayout_2_2->addWidget(_poolSz);
47 FormHPContainer::FillPanel(0); // --- set widgets before signal connexion to avoid false modif detection
48 connect(_poolSz, SIGNAL(textChanged(const QString&)),this, SLOT(onModifySzOfPool(const QString&)));
49 ch_aoc->setEnabled(false);
50 ch_aoc->setCheckState(Qt::Checked);
53 _initScript=new PyEditor_Editor(_advancedParams->tw_advance);
55 _initScript=new QTextEdit(this);
57 connect(_initScript,SIGNAL(textChanged()),this,SLOT(initSciptChanged()));
58 QGridLayout *gridLayout(new QGridLayout(_initScript));
59 _advancedParams->tw_advance->addTab(_initScript,"Init Script");
62 FormHPContainer::~FormHPContainer()
66 void FormHPContainer::FillPanel(YACS::ENGINE::Container *container)
68 DEBTRACE("FormHPContainer::FillPanel");
69 FormContainerBase::FillPanel(container);
72 YACS::ENGINE::HomogeneousPoolContainer *hpc(dynamic_cast<YACS::ENGINE::HomogeneousPoolContainer *>(container));
74 throw YACS::Exception("FormHPContainer::FillPanel : not a HP Container !");
75 _poolSz->setText(QString("%1").arg(hpc->getSizeOfPool()));
76 std::string initScript;
77 if(_properties.count(YACS::ENGINE::HomogeneousPoolContainer::INITIALIZE_SCRIPT_KEY))
78 initScript=_properties[YACS::ENGINE::HomogeneousPoolContainer::INITIALIZE_SCRIPT_KEY];
79 std::string initScript2(BuildWithFinalEndLine(initScript));
80 _initScript->blockSignals(true);
81 _initScript->setText(initScript2.c_str());
82 _initScript->blockSignals(false);
83 if (!YACS::HMI::QtGuiContext::getQtCurrent()->isEdition())
85 //if the schema is in execution do not allow editing
86 _poolSz->setEnabled(false);
87 _initScript->setEnabled(false);
91 QString FormHPContainer::getTypeStr() const
93 return QString("Container (HP)");
96 void FormHPContainer::onModifySzOfPool(const QString& newSz)
100 map<string,string> properties(_container->getProperties());
103 sz=newSz.toUInt(&isOK);
106 _properties[YACS::ENGINE::HomogeneousPoolContainer::SIZE_OF_POOL_KEY] = newSz.toStdString();
107 if(properties[YACS::ENGINE::HomogeneousPoolContainer::SIZE_OF_POOL_KEY] != newSz.toStdString())
111 bool FormHPContainer::onApply()
113 YACS::HMI::SubjectContainerBase *scont(YACS::HMI::QtGuiContext::getQtCurrent()->_mapOfSubjectContainer[_container]);
115 bool ret(scont->setName(le_name->text().toStdString()));
116 std::map<std::string,std::string> properties(_properties);
117 if(_initScriptModified)
119 std::string text(_initScript->toPlainText().toStdString());
120 std::string text2(BuildWithFinalEndLine(text));
121 properties[YACS::ENGINE::HomogeneousPoolContainer::INITIALIZE_SCRIPT_KEY]=text2;
123 _initScriptModified=false;
126 ret = scont->setProperties(properties);
130 void FormHPContainer::initSciptChanged()
132 _initScriptModified=true;
136 std::string FormHPContainer::BuildWithFinalEndLine(const std::string& script)
139 return std::string("\n");
140 std::size_t sz(script.length());
141 if(script[sz-1]!='\n')
143 std::string ret(script);