interface ProcExec
{
long getNodeState(in long numid);
+ string getNodeProgress(in long numid);
string getXMLState(in long numid);
string getInPortValue(in long nodeNumid, in string portName);
string setInPortValue(in string nodeName, in string portName, in string value);
void connected();
void accept(Visitor *visitor);
virtual void cleanNodes();
+ virtual std::string getProgress() const {return "0";};
protected:
struct SortHierarc
{
ForEachLoop::ForEachLoop(const std::string& name, TypeCode *typeOfDataSplitted):DynParaLoop(name,typeOfDataSplitted),
_splitterNode(NAME_OF_SPLITTERNODE,typeOfDataSplitted,this),
- _execCurrentId(0),_nodeForSpecialCases(0)
+ _execCurrentId(0),_nodeForSpecialCases(0),_currentIndex(0)
{
}
ForEachLoop::ForEachLoop(const ForEachLoop& other, ComposedNode *father, bool editionOnly):DynParaLoop(other,father,editionOnly),
_splitterNode(other._splitterNode,this),
- _execCurrentId(0),_nodeForSpecialCases(0)
+ _execCurrentId(0),_nodeForSpecialCases(0),_currentIndex(0)
{
int i=0;
if(!editionOnly)
_splitterNode.init(start);
_execCurrentId=0;
cleanDynGraph();
+ _currentIndex = 0;
+ exUpdateProgress();
}
void ForEachLoop::exUpdateState()
}
}
+void ForEachLoop::exUpdateProgress()
+{
+ // emit notification to all observers registered with the dispatcher on any change of the node's state
+ sendEvent("progress");
+}
+
void ForEachLoop::getReadyTasks(std::vector<Task *>& tasks)
{
if(!_node)
if (_initializingCounter == 0) _initNode->setState(DONE);
break;
case WORK_NODE:
+ _currentIndex++;
+ exUpdateProgress();
storeOutValsInSeqForOutOfScopeUse(_execIds[id],id);
if(_execCurrentId==_splitterNode.getNumberOfElements())
{//No more elements of _dataPortToDispatch to treat
{
DEBTRACE("Finalize node finished on branch " << id);
_unfinishedCounter--;
+ _currentIndex++;
+ exUpdateProgress();
DEBTRACE(_unfinishedCounter << " finalize nodes still running");
if (_unfinishedCounter == 0)
{
//Note: cleanDynGraph is not a virtual method (must be called from ForEachLoop object)
cleanDynGraph();
}
+
+std::string ForEachLoop::getProgress() const
+{
+ int nbElems = _splitterNode.getNumberOfElements();
+ char* aProgress = new char[];
+ if (nbElems > 0)
+ sprintf(aProgress, "%i/%i", _currentIndex, nbElems);
+ else
+ sprintf(aProgress, "0");
+ return aProgress;
+}
protected:
static const int NOT_RUNNING_BRANCH_ID;
protected:
+ int _currentIndex;
SplitterNode _splitterNode;
FakeNodeForForEachLoop *_nodeForSpecialCases;
std::vector<AnySplitOutputPort *> _outGoingPorts;//! ports linked to node outside the current scope
~ForEachLoop();
void init(bool start=true);
void exUpdateState();
+ void exUpdateProgress();
void getReadyTasks(std::vector<Task *>& tasks);
int getNumberOfInputPorts() const;
//
void writeDot(std::ostream &os) const;
virtual std::string typeName() {return "YACS__ENGINE__ForEachLoop";}
virtual void resetState(int level);
+ std::string getProgress() const;
protected:
Node *simpleClone(ComposedNode *father, bool editionOnly=true) const;
void checkLinkPossibility(OutPort *start, const std::list<ComposedNode *>& pointsOfViewStart,
Any* tmp=AtomAny::New(_nbOfTurns);
_indexPort.put(tmp);
tmp->decrRef();
+ exUpdateProgress();
}
//! Update the state of the for loop
YACS::Event ForLoop::updateStateOnFinishedEventFrom(Node *node)
{
DEBTRACE("ForLoop::updateStateOnFinishedEventFrom " << node->getName());
+ exUpdateProgress();
if((++_nbOfTurns)>=_nbOfTimesPort.getIntValue())
{
setState(YACS::DONE);
return YACS::NOEVENT;
}
+void ForLoop::exUpdateProgress()
+{
+ // emit notification to all observers registered with the dispatcher on any change of the node's state
+ sendEvent("progress");
+}
+
void ForLoop::accept(Visitor *visitor)
{
visitor->visitForLoop(this);
return ret;
}
+std::string ForLoop::getProgress() const
+{
+ char* aProgress = new char[];
+ sprintf(aProgress, "0");
+ AnyInputPort* aNbStepsPort = (AnyInputPort*)&_nbOfTimesPort;
+ if (aNbStepsPort && !aNbStepsPort->isEmpty()) {
+ int nbSteps = aNbStepsPort->getIntValue();
+ if (nbSteps > 0 && _nbOfTurns >= 0) {
+ sprintf(aProgress, "%i/%i", _nbOfTurns, nbSteps);
+ }
+ }
+ return aProgress;
+}
ForLoop(const ForLoop& other, ComposedNode *father, bool editionOnly);
ForLoop(const std::string& name);
void exUpdateState();
+ void exUpdateProgress();
void init(bool start=true);
InputPort *edGetNbOfTimesInputPort() { return &_nbOfTimesPort; }
Node *simpleClone(ComposedNode *father, bool editionOnly=true) const;
InputPort *getDecisionPort() const { return (InputPort *)&_nbOfTimesPort; }
OutputPort *edGetIndexPort() { return &_indexPort; }
virtual std::string typeName() {return "YACS__ENGINE__ForLoop";}
+ std::string getProgress() const;
protected:
YACS::Event updateStateOnFinishedEventFrom(Node *node);
void checkCFLinks(const std::list<OutPort *>& starts, InputPort *end, unsigned char& alreadyFed,
return state;
}
+std::string Proc::getNodeProgress(int numId)
+{
+ std::string progress = "0";
+ if(YACS::ENGINE::Node::idMap.count(numId) == 0)
+ {
+ cerr << "Unknown node id " << numId << endl;
+ }
+ else if (YACS::ENGINE::ComposedNode* node = dynamic_cast<YACS::ENGINE::ComposedNode*>(YACS::ENGINE::Node::idMap[numId]))
+ progress = node->getProgress();
+ return progress;
+}
+
std::string Proc::getXMLState(int numId)
{
if(YACS::ENGINE::Node::idMap.count(numId) == 0)
virtual const Proc * getProc() const;
YACS::StatesForNode getNodeState(int numId);
+ std::string Proc::getNodeProgress(int numId);
std::string getInPortValue(int nodeNumId, std::string portName);
std::string setInPortValue(std::string nodeName, std::string portName, std::string value);
std::string getOutPortValue(int nodeNumId, std::string portName);
ScenePortItem.cxx
SceneProcItem.hxx
SceneProcItem.cxx
+ SceneProgressItem.hxx
+ SceneProgressItem.cxx
SceneTextItem.hxx
SceneTextItem.cxx
SchemaComponentItem.hxx
{
DEBTRACE("GenericGui::setLoadedPresentation");
QtGuiContext::getQtCurrent()->setLoadingPresentation(true);
+ map<SceneNodeItem*, QPointF> nodesToMove;
map<YACS::ENGINE::Node*, PrsData> presNodes = _loader->getPrsData(proc);
if (!presNodes.empty())
{
inode->setExpandedPos(QPointF(pres._expx, pres._expy));
inode->setExpandedWH(pres._expWidth, pres._expHeight);
inode->setShownState(shownState(pres._shownState));
+
+ // collect nodes to correct it's Y-position if this collides with parent's header
+ if (inode->getParent() && inode->y() < inode->getParent()->getHeaderBottom())
+ nodesToMove[inode] = QPointF(inode->x(), inode->getParent()->getHeaderBottom()+1);
}
}
+ QtGuiContext::getQtCurrent()->setLoadingPresentation(false);
+
+ //after loading of presentation:
+
+ //move nodes because of progress bar, if any was added
+ map<SceneNodeItem*, QPointF>::iterator it = nodesToMove.begin();
+ for (; it!= nodesToMove.end(); ++it)
+ {
+ (*it).first->setTopLeft((*it).second);
+ }
+
+ //update links
if (Scene::_autoComputeLinks)
_guiEditor->rebuildLinks();
else
SceneComposedNodeItem *proc = dynamic_cast<SceneComposedNodeItem*>(item);
proc->updateLinks();
}
-
- QtGuiContext::getQtCurrent()->setLoadingPresentation(false);
}
// -----------------------------------------------------------------------------
for ( std::list<Node*>::iterator it = aNodeSet.begin(); it != aNodeSet.end(); it++ )
{
_procRef->addObserver(_observerRef, _serv->getEngineId((*it)->getNumId()) , "status");
+ _procRef->addObserver(_observerRef, _serv->getEngineId((*it)->getNumId()) , "progress");
}
_procRef->addObserver(_observerRef, _serv->getEngineId(_proc->getNumId()) , "executor");
}
SubjectNode *snode = _context->_mapOfExecSubjectNode[iGui];
DEBTRACE("node " << snode->getName() << " state=" << state);
- YACS::ENGINE::Node *node = snode->getNode();
- list<InputPort*> inports = node->getLocalInputPorts();
- list<InputPort*>::iterator iti = inports.begin();
- for ( ; iti != inports.end(); ++iti)
- {
- string val = _procRef->getInPortValue(numid, (*iti)->getName().c_str());
- DEBTRACE("node " << snode->getName() << " inport " << (*iti)->getName()
- << " value " << val);
- YASSERT(_context->_mapOfSubjectDataPort.count(*iti));
- SubjectDataPort* port = _context->_mapOfSubjectDataPort[*iti];
- port->setExecValue(val);
- port->update(YACS::HMI::UPDATEPROGRESS, 0, port);
- }
- list<OutputPort*> outports = node->getLocalOutputPorts();
- list<OutputPort*>::iterator ito = outports.begin();
- for ( ; ito != outports.end(); ++ito)
- {
- string val = _procRef->getOutPortValue(numid, (*ito)->getName().c_str());
- DEBTRACE("node " << snode->getName() << " outport " << (*ito)->getName()
- << " value " << val);
- YASSERT(_context->_mapOfSubjectDataPort.count(*ito));
- SubjectDataPort* port = _context->_mapOfSubjectDataPort[*ito];
- port->setExecValue(val);
- port->update(YACS::HMI::UPDATEPROGRESS, 0, port);
- }
- snode->update(YACS::HMI::UPDATEPROGRESS, state, snode);
+ if (event == "progress") { // --- Update progress bar
+ std::string progress = _procRef->getNodeProgress(numid);
+ snode->setProgress( progress );
+ snode->update(YACS::HMI::PROGRESS, state, snode);
+ }
+ else { // --- Update node ports
+ YACS::ENGINE::Node *node = snode->getNode();
+ list<InputPort*> inports = node->getLocalInputPorts();
+ list<InputPort*>::iterator iti = inports.begin();
+ for ( ; iti != inports.end(); ++iti)
+ {
+ string val = _procRef->getInPortValue(numid, (*iti)->getName().c_str());
+ DEBTRACE("node " << snode->getName() << " inport " << (*iti)->getName()
+ << " value " << val);
+ YASSERT(_context->_mapOfSubjectDataPort.count(*iti));
+ SubjectDataPort* port = _context->_mapOfSubjectDataPort[*iti];
+ port->setExecValue(val);
+ port->update(YACS::HMI::UPDATEPROGRESS, 0, port);
+ }
+ list<OutputPort*> outports = node->getLocalOutputPorts();
+ list<OutputPort*>::iterator ito = outports.begin();
+ for ( ; ito != outports.end(); ++ito)
+ {
+ string val = _procRef->getOutPortValue(numid, (*ito)->getName().c_str());
+ DEBTRACE("node " << snode->getName() << " outport " << (*ito)->getName()
+ << " value " << val);
+ YASSERT(_context->_mapOfSubjectDataPort.count(*ito));
+ SubjectDataPort* port = _context->_mapOfSubjectDataPort[*ito];
+ port->setExecValue(val);
+ port->update(YACS::HMI::UPDATEPROGRESS, 0, port);
+ }
+ snode->update(YACS::HMI::UPDATEPROGRESS, state, snode);
+ }
}
return true;
bool Resource::simplifyLink = SIMPLIFYLINK;
bool Resource::ensureVisibleWhenMoved = ENSUREVISIBLEWHENMOVED;
int Resource::dockWidgetPriority = DOCKWIDGETPRIORITY;
+QColor Resource::progressBarColor = PROGRESSBARCOLOR;
+int Resource::progressBarLabel = PROGRESSBARLABEL;
QFont Resource::pythonfont = PYTHONFONT;
// Statics for color of states
int Resource::Header_Height = ( Resource::Corner_Margin + Resource::CtrlPort_Height + Resource::Line_Space + Resource::Line_Width + Resource::Line_Space );
int Resource::Radius = 3;
+int Resource::progressBar_Height = 20;
+
bool Resource::tabPanelsUp = TABPANELSUP;
// Constructor
#define ENSUREVISIBLEWHENMOVED true
#define TABPANELSUP true
#define DOCKWIDGETPRIORITY 0
+#define PROGRESSBARCOLOR Qt::darkGreen
+#define PROGRESSBARLABEL 2
#define EDITEDNODEBRUSHCOLOR QColor(255, 255, 190)
#define NORMALNODEBRUSHCOLOR QColor(230, 235, 255)
static bool simplifyLink;
static bool ensureVisibleWhenMoved;
static int dockWidgetPriority;
+ static QColor progressBarColor;
+ static int progressBarLabel;
// Colors of state of nodes
static QColor editedNodeBrushColor;
static int Header_Height;
static int Radius;
+ static int progressBar_Height;
+
static bool tabPanelsUp;
};
}
#include "SceneLinkItem.hxx"
#include "SceneDSLinkItem.hxx"
#include "SceneCtrlLinkItem.hxx"
+#include "SceneProgressItem.hxx"
#include "LinkMatrix.hxx"
#include "LinkAStar.hxx"
#include "ItemMimeData.hxx"
son->getName().c_str(),
son);
item->addHeader();
+ if ( !QtGuiContext::getQtCurrent()->isEdition()
+ && (type == YACS::HMI::FORLOOP || type == YACS::HMI::FOREACHLOOP) )
+ {
+ item->addProgressItem();
+ }
autoPosNewChild(item, _children, true);
break;
case YACS::HMI::PYTHONNODE:
autoPosNewChild(sinode, _children, true);
}
break;
+ case PROGRESS:
+ {
+ if (dynamic_cast<SubjectForLoop*>(son) || dynamic_cast<SubjectForEachLoop*>(son))
+ {
+ if (SceneProgressItem* spitem = getProgressItem())
+ spitem->setProgress(son->getProgress().c_str());
+ }
+ }
+ break;
default:
;
// DEBTRACE("SceneComposedNodeItem::update(), event not handled: "<< eventName(event));
else
setPos(_expandedPos);
adjustHeader();
+ if (_progressItem)
+ _progressItem->adjustGeometry();
}
else
{ // --- expanding: resize, then show children
}
setPos(_expandedPos);
adjustHeader();
+ if (_progressItem)
+ _progressItem->adjustGeometry();
}
}
show();
}
adjustHeader();
+ if (_progressItem)
+ _progressItem->adjustGeometry();
}
void SceneComposedNodeItem::collisionResolv(SceneItem* child, QPointF oldPos)
QString label)
: SceneHeaderItem(scene, parent, label)
{
+ _fatherNode= dynamic_cast<SceneNodeItem*>(parent);
_width = 2*Resource::Corner_Margin + 2*Resource::DataPort_Width + Resource::Space_Margin;
_height = Resource::Header_Height;
_maxPorts = 0;
int x = Resource::Border_Margin + 1;
int y = Resource::Header_Height - Resource::Line_Space;
+ if (_fatherNode && _fatherNode->hasProgressBar())
+ y += Resource::progressBar_Height;
int w = Resource::Corner_Margin + 2*Resource::DataPort_Width + 2*Resource::Space_Margin;
if (_parent->getWidth() > w) w = _parent->getWidth() - Resource::Border_Margin;
QPen pen(getPenColor());
pen.setWidth(Resource::Thickness);
painter->setPen(pen);
- SceneNodeItem* father = dynamic_cast<SceneNodeItem*>(_parent);
- bool expanded = (father && father->isExpanded());
+ bool expanded = (_fatherNode && _fatherNode->isExpanded());
QColor baseColor = getBrushColor();
if (expanded)
painter->setBrush(baseColor);
qreal SceneHeaderNodeItem::getHeaderBottom() const
{
+ qreal res = 0;
if (_hasHeader) {
- return Resource::Header_Height + _maxPorts * (Resource::DataPort_Height + Resource::Space_Margin);
- } else {
- return 0;
- };
+ res += Resource::Header_Height + _maxPorts * (Resource::DataPort_Height + Resource::Space_Margin);
+ if (_fatherNode && _fatherNode->hasProgressBar())
+ res += Resource::progressBar_Height;
+ }
+ return res;
}
void SceneHeaderNodeItem::autoPosControl(AbstractSceneItem *item)
_outPorts.push_back(dynamic_cast<SceneOutPortItem*>(item));
};
qreal yTop = Resource::Header_Height;
+ if (_fatherNode && _fatherNode->hasProgressBar())
+ yTop += Resource::progressBar_Height;
qreal deltaY = Resource::DataPort_Height + Resource::Space_Margin;
yTop += nbPorts * deltaY;
if (nbPorts >=_maxPorts) {
qreal yTop;
qreal href = Resource::Header_Height;
+ if (_fatherNode && _fatherNode->hasProgressBar())
+ href += Resource::progressBar_Height;
bool isShown = (ss != shrinkHidden);
if (!isShown) href = Resource::Corner_Margin;
-std::list<SceneInPortItem*>::iterator iti = _inPorts.begin();
+ std::list<SceneInPortItem*>::iterator iti = _inPorts.begin();
int nbPorts = 0;
for (; iti != _inPorts.end(); ++iti)
{
void SceneHeaderNodeItem::adjustPosPorts()
{
- SceneNodeItem* father = dynamic_cast<SceneNodeItem*>(_parent);
- YASSERT(father);
- shownState ss = father->getShownState();
+ YASSERT(_fatherNode);
+ shownState ss = _fatherNode->getShownState();
if (_controlOut)
{
int x = Resource::Corner_Margin + 2*Resource::DataPort_Width + Resource::Space_Margin;
int nbPorts = _inPorts.size();
if (_outPorts.size() > nbPorts) nbPorts = _outPorts.size();
if (nbPorts) height += nbPorts*(Resource::DataPort_Height + Resource::Space_Margin);
+ if (_fatherNode && _fatherNode->hasProgressBar())
+ height += Resource::progressBar_Height;
//DEBTRACE(nbPorts << " " << width << " " << height);
return QRectF(x(), y(), width, height);
}
virtual void mousePressEvent(QGraphicsSceneMouseEvent *event);
virtual void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event);
+ SceneNodeItem* _fatherNode;
SceneHeaderItem *_header;
SceneCtrlPortItem *_controlIn;
SceneCtrlPortItem *_controlOut;
{
}
+void AbstractSceneItem::addProgressItem()
+{
+}
+
qreal AbstractSceneItem::getHeaderBottom()
{
return 0;
}
+
qreal AbstractSceneItem::getWidth()
{
return _width;
virtual void reorganize();
virtual QString getLabel();
virtual void addHeader();
+ virtual void addProgressItem();
virtual qreal getHeaderBottom();
qreal getWidth();
qreal getHeight();
virtual void shrinkExpandLink(bool se);
virtual void shrinkExpandRecursive(bool isExpanding, bool fromHere);
bool isAncestorShrinked() { return _ancestorShrinked; };
+ bool _blocX;
+ bool _blocY;
protected:
// virtual bool sceneEvent(QEvent *event);
#include "SceneComposedNodeItem.hxx"
#include "SceneProcItem.hxx"
#include "SceneHeaderNodeItem.hxx"
+#include "SceneProgressItem.hxx"
#include "SceneInPortItem.hxx"
#include "SceneOutPortItem.hxx"
#include "SceneCtrlInPortItem.hxx"
_inPorts.clear();
_outPorts.clear();
_header = 0;
+ _progressItem = 0;
_brushColor = Resource::Scene_pen;
_moving = false;
_moved = false;
return _header;
}
+void SceneNodeItem::addProgressItem()
+{
+ DEBTRACE("SceneNodeItem::addProgressItem ");
+ if (!_progressItem)
+ {
+ _progressItem = new SceneProgressItem(_scene,
+ this,
+ "progress");
+ _progressItem->setText("0");
+ updateState();
+ checkGeometryChange();
+ }
+}
+
void SceneNodeItem::paint(QPainter *painter,
const QStyleOptionGraphicsItem *option,
QWidget *widget)
{
_shownState = ss;
}
+
+bool SceneNodeItem::hasProgressBar() const
+{
+ return _progressItem != 0;
+}
class SceneHeaderNodeItem;
class SceneComposedNodeItem;
class ScenePortItem;
+ class SceneProgressItem;
class SceneNodeItem: public SceneObserverItem
{
virtual void setHeight(qreal height);
virtual void addHeader();
virtual SceneHeaderItem* getHeader();
+ virtual void addProgressItem();
+ virtual SceneProgressItem* getProgressItem() { return _progressItem; };
virtual void paint(QPainter *painter,
const QStyleOptionGraphicsItem *option,
QWidget *widget);
qreal getExpandedWidth() { return _expandedWidth; };
qreal getExpandedHeight() { return _expandedHeight; };
shownState getShownState() {return _shownState; };
- bool _blocX;
- bool _blocY;
+ bool hasProgressBar() const;
protected:
virtual QString getMimeFormat();
std::list<AbstractSceneItem*> _inPorts;
std::list<AbstractSceneItem*> _outPorts;
SceneHeaderNodeItem *_header;
+ SceneProgressItem *_progressItem;
int _execState;
bool _moving;
bool _moved;
--- /dev/null
+// Copyright (C) 2006-2013 CEA/DEN, EDF R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+#include "SceneProgressItem.hxx"
+#include "SceneHeaderNodeItem.hxx"
+#include "SceneTextItem.hxx"
+#include "Scene.hxx"
+#include <QGraphicsSceneMouseEvent>
+
+#include "Resource.hxx"
+
+#include <cassert>
+
+//#define _DEVDEBUG_
+#include "YacsTrace.hxx"
+
+using namespace std;
+using namespace YACS::ENGINE;
+using namespace YACS::HMI;
+
+
+SceneProgressItem::SceneProgressItem(QGraphicsScene *scene, SceneItem *parent,
+ QString label)
+ : SceneItem(scene, parent, label)
+{
+ YASSERT(_parent);
+ _progress = 0;
+ _width = Resource::Corner_Margin + 2*Resource::DataPort_Width + 2*Resource::Space_Margin;
+ _height = Resource::progressBar_Height;
+ _text=0;
+ _tooltip = "";
+ _brushColor = Resource::Header_brush;
+ _hiBrushColor = Resource::Header_hiBrush;
+ _penColor = Resource::Header_pen;
+ _hiPenColor = Resource::Header_hiPen;
+ int x = Resource::Border_Margin;
+ int y = Resource::DataPort_Height + 2*Resource::Space_Margin;
+ setTopLeft(QPointF(x, y));
+}
+
+SceneProgressItem::~SceneProgressItem()
+{
+}
+
+QRectF SceneProgressItem::getMinimalBoundingRect() const
+{
+ return QRectF(x(), y(), _width, _height);
+}
+
+void SceneProgressItem::paint(QPainter *painter,
+ const QStyleOptionGraphicsItem *option,
+ QWidget *widget)
+{
+// DEBTRACE("SceneProgressItem::paint");
+ painter->save();
+
+ int w = Resource::Corner_Margin + 2*Resource::DataPort_Width + 2*Resource::Space_Margin;
+ if (_parent->getWidth() > w) w = _parent->getWidth() - Resource::Corner_Margin - Resource::Space_Margin;
+ int h = Resource::progressBar_Height;
+ QPen pen(getPenColor());
+ pen.setWidth(Resource::Thickness);
+ painter->setPen(pen);
+ QRect boundRect(0, 0, w, h);
+ painter->drawRect(boundRect);
+
+ painter->setBrush(Resource::progressBarColor);
+ //correct width according to progress
+ int corr_w = w * _progress / 100;
+ painter->drawRect(QRect(0, 0, corr_w, h));
+ painter->restore();
+}
+
+void SceneProgressItem::setProgress(QString newProgress)
+{
+ QString percentageLabel;
+ QString nbStepsLabel = "-/-";
+ QStringList aSteps = newProgress.split('/');
+ if (aSteps.count() == 2)
+ { //case '5/10' view of progress
+ _progress = aSteps.at(0).toInt() * 100 / aSteps.at(1).toInt();
+ nbStepsLabel = newProgress;
+ }
+ else
+ { //case '50' view of progress
+ _progress = newProgress.toInt(); //set 0 if the conversion fails.
+ }
+ percentageLabel = QString("%1\%").arg(_progress);
+ QString resultLabel;
+ switch(Resource::progressBarLabel)
+ {
+ case 0: //Percentage: 50%
+ resultLabel = QString("%1").arg(percentageLabel);
+ break;
+ case 1: //Nb.steps: 5/10
+ resultLabel = QString("%1").arg(nbStepsLabel);
+ break;
+ case 2: //Both: 50% (5/10)
+ resultLabel = QString("%1 (%2)").arg(percentageLabel).arg(nbStepsLabel);
+ break;
+ }
+ setText(resultLabel);
+ _tooltip = QString("%1 (%2)").arg(percentageLabel).arg(nbStepsLabel);
+ update();
+}
+
+void SceneProgressItem::setText(QString label)
+{
+ if (!_text)
+ _text = new SceneTextItem(_scene, this, label, true);
+ else
+ _text->setPlainTextTrunc(label);
+ //QGraphicsItem::update();
+}
+
+void SceneProgressItem::popupMenu(QWidget *caller, const QPoint &globalPos)
+{
+ if (_parent) _parent->popupMenu(caller, globalPos);
+}
+
+void SceneProgressItem::adjustGeometry()
+{
+ prepareGeometryChange();
+ _width = _parent->getWidth() - Resource::Corner_Margin - Resource::Space_Margin;
+ update();
+}
+
+QColor SceneProgressItem::getPenColor()
+{
+ return _hiPenColor;
+}
+
+QColor SceneProgressItem::getBrushColor()
+{
+ QColor color = _brushColor;
+ if (dynamic_cast<SceneHeaderNodeItem*>(this))
+ if (getParent()->isSelected())
+ color = _hiBrushColor;
+ if (_hover)
+ color = hoverColor(color);
+ return color;
+}
+
+void SceneProgressItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
+{
+ event->ignore();
+}
+
+QString SceneProgressItem::getToolTip()
+{
+ return _tooltip;;
+}
--- /dev/null
+// Copyright (C) 2006-2013 CEA/DEN, EDF R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+#ifndef _SCENEPROGRESSITEM_HXX_
+#define _SCENEPROGRESSITEM_HXX_
+
+#include "SceneItem.hxx"
+
+namespace YACS
+{
+ namespace HMI
+ {
+ class SceneTextItem;
+
+ class SceneProgressItem: public SceneItem
+ {
+ public:
+ SceneProgressItem(QGraphicsScene *scene, SceneItem *parent,
+ QString label);
+ virtual ~SceneProgressItem();
+ virtual QRectF getMinimalBoundingRect() const;
+ virtual void paint(QPainter *painter,
+ const QStyleOptionGraphicsItem *option,
+ QWidget *widget);
+ virtual void setProgress(QString newProgress);
+ virtual int getProgress() { return _progress; };
+ virtual void setText(QString label);
+ virtual void popupMenu(QWidget *caller, const QPoint &globalPos);
+ virtual void adjustGeometry();
+
+ protected:
+ virtual void mousePressEvent(QGraphicsSceneMouseEvent *event);
+ virtual QString getToolTip();
+ QColor getPenColor();
+ QColor getBrushColor();
+ SceneTextItem* _text;
+ QString _tooltip;
+ int _progress;
+
+ };
+ }
+}
+
+#endif
update(ADDREF, 0, son);
}
+void Subject::setProgress( std::string newProgress )
+{
+ _progress = newProgress;
+}
+
// ----------------------------------------------------------------------------
GuiObserver::GuiObserver()
SETSELECT,
GEOMETRY,
EMPHASIZE,
- SWITCHSHAPE
+ SWITCHSHAPE,
+ PROGRESS
} GuiEvent;
class ProcInvoc;
bool isDestructible() { return _destructible; };
static void erase(Subject* sub, Command *command=0, bool post=false);
virtual TypeOfElem getType(){return UNKNOWN;}
+ virtual void setProgress( std::string newProgress );
+ virtual std::string getProgress() { return _progress; };
protected:
std::set<GuiObserver *> _setObs;
Subject *_parent;
bool _destructible;
bool _askRegisterUndo;
+ std::string _progress;
};
class HMI_EXPORT GuiObserver
swm->addPreference( "Ensure Node Visible When Moved", presentationGroup, LightApp_Preferences::Bool, RESOURCE_YACS, "ensureVisibleWhenMoved" );
swm->addPreference( "Tabified Panels Up", presentationGroup, LightApp_Preferences::Bool, RESOURCE_YACS, "tabPanelsUp" );
int priority = swm->addPreference( "DockWidget priority", presentationGroup, LightApp_Preferences::Selector, RESOURCE_YACS, "dockWidgetPriority" );
+ swm->addPreference( "Progress bar color", presentationGroup, LightApp_Preferences::Color, RESOURCE_YACS, "progressBarColor" );
+ int progressLabel = swm->addPreference( "Progress bar label", presentationGroup, LightApp_Preferences::Selector, RESOURCE_YACS, "progressBarLabel" );
- QStringList priorityList;
- priorityList.append( "Horizontal" );
- priorityList.append( "Vertical" );
-
+ QStringList stringsList;
+ stringsList.append( "Horizontal" );
+ stringsList.append( "Vertical" );
QList<QVariant> indexesList;
indexesList.append(0);
indexesList.append(1);
-
- swm->setPreferenceProperty( priority, "strings", priorityList );
+ swm->setPreferenceProperty( priority, "strings", stringsList );
swm->setPreferenceProperty( priority, "indexes", indexesList );
+ stringsList.clear();
+ indexesList.clear();
+
+ stringsList << "Percentage: \"50%\"" << "Nb.steps: \"5/10\"" << "Both: \"50% (5/10)\"";
+ indexesList << 0 << 1 << 2;
+ swm->setPreferenceProperty( progressLabel, "strings", stringsList );
+ swm->setPreferenceProperty( progressLabel, "indexes", indexesList );
+
int pythonGroup = swm->addPreference( "Python", genTab );
swm->addPreference( "Python Script Font", pythonGroup, LightApp_Preferences::Font, RESOURCE_YACS, "font" );
Resource::ensureVisibleWhenMoved = booleanValue("ensureVisibleWhenMoved", ENSUREVISIBLEWHENMOVED);
Resource::tabPanelsUp = booleanValue("tabPanelsUp", TABPANELSUP);
Resource::dockWidgetPriority = integerValue( "dockWidgetPriority" , DOCKWIDGETPRIORITY);
+ Resource::progressBarColor = colorValue("progressBarColor", PROGRESSBARCOLOR);
+ Resource::progressBarLabel = integerValue( "progressBarLabel" , PROGRESSBARLABEL);
// Color of state of nodes
Resource::editedNodeBrushColor = colorValue(_editedNodeBrushColor, EDITEDNODEBRUSHCOLOR);
<parameter name="addRowCols" value="false" />
<parameter name="ensureVisibleWhenMoved" value="true" />
<parameter name="tabPanelsUp" value="true" />
+ <parameter name="progressBarColor" value="#008000" />
+ <parameter name="progressBarLabel" value="2" />
<parameter name="documentation" value="yacs_help"/>
<parameter name="editedNodeBrushColor" value="255, 255, 190" />
def getNodeState(self,numid):
return self.p.getNodeState(numid)
+ def getNodeProgress(self,numid):
+ return self.p.getNodeProgress(numid)
+
def getXMLState(self, numid):
return self.p.getXMLState(numid)