Skip to content

Commit

Permalink
Merge branch 'parser_work'
Browse files Browse the repository at this point in the history
  • Loading branch information
guruofquality committed Mar 29, 2015
2 parents aaad929 + d1dbd2e commit 5f519b6
Show file tree
Hide file tree
Showing 169 changed files with 28,188 additions and 217 deletions.
1 change: 1 addition & 0 deletions pothos-gui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ set(SOURCES
PropertiesPanel/ConnectionPropertiesPanel.cpp
PropertiesPanel/BlockPropertiesPanel.cpp
PropertiesPanel/BreakerPropertiesPanel.cpp
PropertiesPanel/GraphPropertiesPanel.cpp
PropertiesPanel/PropertyEditWidget.cpp

MessageWindow/MessageWindowDock.cpp
Expand Down
91 changes: 90 additions & 1 deletion pothos-gui/EvalEngine/BlockEval.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <cassert>
#include <iostream>
#include <QApplication>
#include <QRegExp>

//! helper to convert the port info vector into JSON for serialization of the block
static Poco::JSON::Array::Ptr portInfosToJSON(const std::vector<Pothos::PortInfo> &infos)
Expand Down Expand Up @@ -207,6 +208,11 @@ bool BlockEval::evaluationProcedure(void)
{
_lastBlockStatus.blockErrorMsgs.push_back(tr("Error: empty ID"));
}
else if (_newBlockInfo.id.count(QRegExp("^[a-zA-Z]\\w*$")) != 1)
{
_lastBlockStatus.blockErrorMsgs.push_back(
tr("'%1' is not a legal ID").arg(_newBlockInfo.id));
}

//load its port info
if (evalSuccess and _queryPortDesc) try
Expand Down Expand Up @@ -360,11 +366,71 @@ bool BlockEval::didPropKeyHaveChange(const QString &key) const
{
if (_newBlockInfo.properties.count(key) == 0) return true;
if (_lastBlockInfo.properties.count(key) == 0) return true;
return _newBlockInfo.properties.at(key) != _lastBlockInfo.properties.at(key);
const auto newVal = _newBlockInfo.properties.at(key);
const auto oldVal = _lastBlockInfo.properties.at(key);
if (newVal != oldVal) return true;
return (this->didExprHaveChange(newVal));
}

bool BlockEval::didExprHaveChange(const QString &expr) const
{
for (const auto &name : this->getConstantsUsed(expr))
{
const bool foundInNew = _newBlockInfo.constants.count(name) != 0;
const bool foundInLast = _lastBlockInfo.constants.count(name) != 0;

//token is not a constant -- ignore
if (not foundInNew and not foundInLast) continue;

//constant removal detection -- report as changed
if (foundInNew and not foundInLast) return true;
if (not foundInNew and foundInLast) return true;

//constant expression changed
if (_newBlockInfo.constants.at(name) != _lastBlockInfo.constants.at(name)) return true;
}

return false;
}

bool BlockEval::isConstantUsed(const QString &name) const
{
QStringList used;
for (const auto &pair : _newBlockInfo.properties)
{
const auto &propVal = pair.second;
used += this->getConstantsUsed(propVal);
}
return used.contains(name);
}

QStringList BlockEval::getConstantsUsed(const QString &expr, const size_t depth) const
{
//probably encountered a loop, declare this a change
if (depth > _newBlockInfo.constants.size()) return QStringList();

//create a recursive list of used constants by traversing expressions
QStringList used;
for (const auto &tok : expr.split(QRegExp("\\W"), QString::SkipEmptyParts))
{
//is this token a constant? then inspect it
if (_newBlockInfo.constants.count(tok) != 0)
{
used.push_back(tok);
used += this->getConstantsUsed(_newBlockInfo.constants.at(tok), depth+1);
}
if (_lastBlockInfo.constants.count(tok) != 0)
{
used.push_back(tok);
used += this->getConstantsUsed(_lastBlockInfo.constants.at(tok), depth+1);
}
}
return used;
}

bool BlockEval::updateAllProperties(void)
{
//create a block evaluator if need-be
if (not _blockEval) try
{
Pothos::Proxy evalEnv;
Expand All @@ -387,6 +453,10 @@ bool BlockEval::updateAllProperties(void)
return false;
}

//apply constants before eval property expressions
if (not this->applyConstants()) return false;

//update each property
bool hasError = false;
for (const auto &pair : _newBlockInfo.properties)
{
Expand All @@ -406,6 +476,25 @@ bool BlockEval::updateAllProperties(void)
return not hasError;
}

bool BlockEval::applyConstants(void)
{
for (const auto &name : _newBlockInfo.constantNames)
{
if (not this->isConstantUsed(name)) continue;
try
{
const auto &expr = _newBlockInfo.constants.at(name);
_blockEval.callProxy("applyConstant", name.toStdString(), expr.toStdString());
}
catch (const Pothos::Exception &ex)
{
this->reportError("applyConstants", ex);
return false;
}
}
return true;
}

void BlockEval::reportError(const std::string &action, const Pothos::Exception &ex)
{
//poco_error_f2(Poco::Logger::get("PothosGui.BlockEval."+action),
Expand Down
28 changes: 27 additions & 1 deletion pothos-gui/EvalEngine/BlockEval.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2014-2014 Josh Blum
// Copyright (c) 2014-2015 Josh Blum
// SPDX-License-Identifier: BSL-1.0

#pragma once
Expand Down Expand Up @@ -34,6 +34,8 @@ struct BlockInfo
bool enabled;
QString zone;
std::map<QString, QString> properties;
QStringList constantNames; //preserves order
std::map<QString, QString> constants;
std::map<QString, Poco::JSON::Object::Ptr> paramDescs;
Poco::JSON::Object::Ptr desc;
};
Expand Down Expand Up @@ -131,6 +133,24 @@ private slots:
//! detect a change in properties before vs after
bool didPropKeyHaveChange(const QString &key) const;

/*!
* Detect a change in an expression
* accounting for the constants dependency tree.
*/
bool didExprHaveChange(const QString &expr) const;

/*!
* Is this constant used in any of the properties.
* Use this logic to skip registering unused constants.
*/
bool isConstantUsed(const QString &name) const;

/*!
* Determine all constants used by this expression
* The depth parameter prevents infinite recursion.
*/
QStringList getConstantsUsed(const QString &expr, const size_t depth = 0) const;

/*!
* Create the remote block evaluator if needed.
* Call evalProperty on all properties.
Expand All @@ -140,6 +160,12 @@ private slots:
*/
bool updateAllProperties(void);

/*!
* Apply constants to the evaluator.
* \return true for success, false for error
*/
bool applyConstants(void);

/*!
* The main evaluation procedure for dealing with changes.
* Return true for success and false for failure.
Expand Down
8 changes: 8 additions & 0 deletions pothos-gui/EvalEngine/EvalEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#include "EvalEngine.hpp"
#include "EvalEngineImpl.hpp"
#include "GraphObjects/GraphBlock.hpp"
#include "GraphEditor/GraphDraw.hpp"
#include "GraphEditor/GraphEditor.hpp"
#include "AffinitySupport/AffinityZonesDock.hpp"
#include <Poco/Logger.h>
#include <QSignalMapper>
Expand Down Expand Up @@ -55,6 +57,12 @@ static BlockInfo blockToBlockInfo(GraphBlock *block)
blockInfo.enabled = block->isEnabled();
blockInfo.zone = block->getAffinityZone();
blockInfo.desc = block->getBlockDesc();
const auto editor = block->draw()->getGraphEditor();
blockInfo.constantNames = editor->listGlobals();
for (const auto &name : blockInfo.constantNames)
{
blockInfo.constants[name] = editor->getGlobalExpression(name);;
}
for (const auto &propKey : block->getProperties())
{
blockInfo.properties[propKey] = block->getPropertyValue(propKey);
Expand Down
10 changes: 5 additions & 5 deletions pothos-gui/GraphEditor/GraphDraw.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2013-2014 Josh Blum
// Copyright (c) 2013-2015 Josh Blum
// SPDX-License-Identifier: BSL-1.0

#include "PothosGuiUtils.hpp" //action and object map
Expand Down Expand Up @@ -53,8 +53,8 @@ GraphDraw::GraphDraw(QWidget *parent):

connect(this, SIGNAL(customContextMenuRequested(const QPoint &)),
this, SLOT(handleCustomContextMenuRequested(const QPoint &)));
connect(this, SIGNAL(modifyProperties(GraphObject *)),
getObjectMap()["propertiesPanel"], SLOT(handleGraphModifyProperties(GraphObject *)));
connect(this, SIGNAL(modifyProperties(QObject *)),
getObjectMap()["propertiesPanel"], SLOT(handleGraphModifyProperties(QObject *)));
connect(this->scene(), SIGNAL(selectionChanged(void)), this, SLOT(updateEnabledActions(void)));

//debug view - connect and initialize
Expand Down Expand Up @@ -148,7 +148,7 @@ void GraphDraw::keyPressEvent(QKeyEvent *event)
{
if (event->key() == Qt::Key_Plus) getActionMap()["increment"]->activate(QAction::Trigger);
if (event->key() == Qt::Key_Minus) getActionMap()["decrement"]->activate(QAction::Trigger);
if (event->key() == Qt::Key_Return) getActionMap()["properties"]->activate(QAction::Trigger);
if (event->key() == Qt::Key_Return) getActionMap()["objectProperties"]->activate(QAction::Trigger);
if (event->key() == Qt::Key_E) getActionMap()["enable"]->activate(QAction::Trigger);
if (event->key() == Qt::Key_D) getActionMap()["disable"]->activate(QAction::Trigger);
if (event->key() == Qt::Key_R) getActionMap()["reeval"]->activate(QAction::Trigger);
Expand All @@ -171,7 +171,7 @@ void GraphDraw::updateEnabledActions(void)
getActionMap()["delete"]->setEnabled(selected);
getActionMap()["rotateLeft"]->setEnabled(selectedNoC);
getActionMap()["rotateRight"]->setEnabled(selectedNoC);
getActionMap()["properties"]->setEnabled(selected);
getActionMap()["objectProperties"]->setEnabled(selected);
getActionMap()["increment"]->setEnabled(selectedBlocks);
getActionMap()["decrement"]->setEnabled(selectedBlocks);
getActionMap()["enable"]->setEnabled(selectedBlocks);
Expand Down
5 changes: 3 additions & 2 deletions pothos-gui/GraphEditor/GraphDraw.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2013-2014 Josh Blum
// Copyright (c) 2013-2015 Josh Blum
// SPDX-License-Identifier: BSL-1.0

#pragma once
Expand Down Expand Up @@ -75,6 +75,7 @@ class GraphDraw : public QGraphicsView
void wheelEvent(QWheelEvent *event);
void mousePressEvent(QMouseEvent *event);
void mouseReleaseEvent(QMouseEvent *event);
void mouseDoubleClickEvent(QMouseEvent *event);
void mouseMoveEvent(QMouseEvent *event);
void showEvent(QShowEvent *event);
void keyPressEvent(QKeyEvent *event);
Expand All @@ -85,7 +86,7 @@ private slots:
void updateEnabledActions(void);

signals:
void modifyProperties(GraphObject *);
void modifyProperties(QObject *);

private:

Expand Down
9 changes: 9 additions & 0 deletions pothos-gui/GraphEditor/GraphDrawSelection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,15 @@ void GraphDraw::mousePressEvent(QMouseEvent *event)
this->render();
}

void GraphDraw::mouseDoubleClickEvent(QMouseEvent *event)
{
QGraphicsView::mouseDoubleClickEvent(event);

//double clicked on graph to edit graph properties when nothing selected
const auto objs = this->getObjectsAtPos(event->pos());
if (objs.empty()) emit this->modifyProperties(this->getGraphEditor());
}

static void handleAutoScroll(QScrollBar *bar, const qreal length, const qreal offset)
{
const qreal delta = offset - bar->value();
Expand Down
44 changes: 42 additions & 2 deletions pothos-gui/GraphEditor/GraphEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ GraphEditor::GraphEditor(QWidget *parent):
connect(getActionMap()["delete"], SIGNAL(triggered(void)), this, SLOT(handleDelete(void)));
connect(getActionMap()["rotateLeft"], SIGNAL(triggered(void)), this, SLOT(handleRotateLeft(void)));
connect(getActionMap()["rotateRight"], SIGNAL(triggered(void)), this, SLOT(handleRotateRight(void)));
connect(getActionMap()["properties"], SIGNAL(triggered(void)), this, SLOT(handleProperties(void)));
connect(getActionMap()["objectProperties"], SIGNAL(triggered(void)), this, SLOT(handleObjectProperties(void)));
connect(getActionMap()["graphProperties"], SIGNAL(triggered(void)), this, SLOT(handleGraphProperties(void)));
connect(getActionMap()["zoomIn"], SIGNAL(triggered(void)), this, SLOT(handleZoomIn(void)));
connect(getActionMap()["zoomOut"], SIGNAL(triggered(void)), this, SLOT(handleZoomOut(void)));
connect(getActionMap()["zoomOriginal"], SIGNAL(triggered(void)), this, SLOT(handleZoomOriginal(void)));
Expand Down Expand Up @@ -679,14 +680,20 @@ void GraphEditor::handleRotateRight(void)
handleStateChange(GraphState("object-rotate-right", tr("Rotate %1 right").arg(draw->getSelectionDescription(~GRAPH_CONNECTION))));
}

void GraphEditor::handleProperties(void)
void GraphEditor::handleObjectProperties(void)
{
if (not this->isVisible()) return;
auto draw = this->getCurrentGraphDraw();
const auto objs = draw->getObjectsSelected();
if (not objs.isEmpty()) emit draw->modifyProperties(objs.at(0));
}

void GraphEditor::handleGraphProperties(void)
{
if (not this->isVisible()) return;
emit this->getCurrentGraphDraw()->modifyProperties(this);
}

void GraphEditor::handleZoomIn(void)
{
if (not this->isVisible()) return;
Expand Down Expand Up @@ -1043,3 +1050,36 @@ void GraphEditor::makeDefaultPage(void)
{
this->insertTab(0, new GraphDraw(this), tr("Main"));
}


void GraphEditor::clearGlobals(void)
{
_globalNames.clear();
_globalExprs.clear();
}

void GraphEditor::reorderGlobals(const QStringList &names)
{
_globalNames = names;
}

void GraphEditor::setGlobalExpression(const QString &name, const QString &expression)
{
if (_globalExprs.count(name) == 0) _globalNames.push_back(name);
_globalExprs[name] = expression;
}

const QString &GraphEditor::getGlobalExpression(const QString &name) const
{
return _globalExprs.at(name);
}

const QStringList &GraphEditor::listGlobals(void) const
{
return _globalNames;
}

void GraphEditor::commitGlobalsChanges(void)
{
this->updateExecutionEngine();
}
Loading

0 comments on commit 5f519b6

Please sign in to comment.