Version: 9.16.0
FormHPContainer.cxx
Go to the documentation of this file.
1// Copyright (C) 2006-2026 CEA, EDF
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 "FormHPContainer.hxx"
23#include "QtGuiContext.hxx"
24#include "guiObservers.hxx"
25//#define _DEVDEBUG_
26#include "Resource.hxx"
27#include "YacsTrace.hxx"
28
29#include <QIntValidator>
30#include <QLineEdit>
31
32#ifdef HAS_PYEDITOR
33#include <PyEditor_Editor.h>
34#endif
35
36#include <sstream>
37#include <limits>
38
39using namespace std;
40
41FormHPContainer::FormHPContainer(QWidget *parent):FormContainerBase(parent),_poolSz(new QLineEdit(this)),_initScriptModified(false)
42{
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);
51 //
52#ifdef HAS_PYEDITOR
53 _initScript=new PyEditor_Editor(_advancedParams->tw_advance);
54#else
55 _initScript=new QTextEdit(this);
56#endif
57 connect(_initScript,SIGNAL(textChanged()),this,SLOT(initSciptChanged()));
58 QGridLayout *gridLayout(new QGridLayout(_initScript));
59 _advancedParams->tw_advance->addTab(_initScript,"Init Script");
60}
61
63{
64}
65
67{
68 DEBTRACE("FormHPContainer::FillPanel");
70 if(!container)
71 return ;
73 if(!hpc)
74 throw YACS::Exception("FormHPContainer::FillPanel : not a HP Container !");
75 _poolSz->setText(QString("%1").arg(hpc->getSizeOfPool()));
76 std::string initScript;
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())
84 {
85 //if the schema is in execution do not allow editing
86 _poolSz->setEnabled(false);
87 _initScript->setEnabled(false);
88 }
89}
90
92{
93 return QString("Container (HP)");
94}
95
96void FormHPContainer::onModifySzOfPool(const QString& newSz)
97{
98 if (!_container)
99 return;
100 map<string,string> properties(_container->getProperties());
101 uint sz;
102 bool isOK;
103 sz=newSz.toUInt(&isOK);
104 if(!isOK)
105 return ;
107 if(properties[YACS::ENGINE::HomogeneousPoolContainer::SIZE_OF_POOL_KEY] != newSz.toStdString())
108 onModified();
109}
110
112{
114 YASSERT(scont);
115 bool ret(scont->setName(le_name->text().toStdString()));
116 std::map<std::string,std::string> properties(_properties);
118 {
119 std::string text(_initScript->toPlainText().toStdString());
120 std::string text2(BuildWithFinalEndLine(text));
122 }
124 DEBTRACE(ret);
125 if(ret)
126 ret = scont->setProperties(properties);
127 return ret;
128}
129
131{
133 onModified();
134}
135
136std::string FormHPContainer::BuildWithFinalEndLine(const std::string& script)
137{
138 if(script.empty())
139 return std::string("\n");
140 std::size_t sz(script.length());
141 if(script[sz-1]!='\n')
142 {
143 std::string ret(script);
144 ret+="\n";
145 return ret;
146 }
147 else
148 return script;
149}
#define YASSERT(val)
YASSERT macro is always defined, used like assert, but throw a YACS::Exception instead of abort.
Definition: YacsTrace.hxx:59
#define DEBTRACE(msg)
Definition: YacsTrace.hxx:31
virtual void onModified()
std::map< std::string, std::string > _properties
YACS::ENGINE::Container * _container
virtual void FillPanel(YACS::ENGINE::Container *container)
FormAdvParamContainer * _advancedParams
void FillPanel(YACS::ENGINE::Container *container)
QTextEdit * _initScript
static std::string BuildWithFinalEndLine(const std::string &script)
virtual ~FormHPContainer()
void onModifySzOfPool(const QString &newSz)
QString getTypeStr() const
FormHPContainer(QWidget *parent=0)
QLineEdit * _poolSz
virtual std::map< std::string, std::string > getProperties() const =0
virtual int getSizeOfPool() const =0
static QtGuiContext * getQtCurrent()
virtual bool setProperties(std::map< std::string, std::string > properties)
virtual bool setName(std::string name)