Skip to content

Commit

Permalink
don't show transform in the selector that are invalid
Browse files Browse the repository at this point in the history
  • Loading branch information
facontidavide committed Jan 8, 2019
1 parent 1ec3087 commit d6a306d
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 19 deletions.
21 changes: 18 additions & 3 deletions plotter_gui/plotwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1281,8 +1281,24 @@ void PlotWidget::on_customTransformsDialog()
updateAvailableTransformers();

QStringList available_trans;
for (const auto& it: _snippets) {
available_trans.push_back( it.first );
for (const auto& it: _snippets)
{
bool valid = true;
QStringList required_channels = CustomFunction::getChannelsFromFuntion( it.second.equation );
for (const auto& channel: required_channels)
{
if( _mapped_data.numeric.count( channel.toStdString() ) == 0)
{
valid = false;
break;
}
}
valid = valid && it.second.equation.contains("value");

if( valid )
{
available_trans.push_back( it.first );
}
}

TransformSelector dialog( builtin_trans, available_trans,
Expand All @@ -1295,7 +1311,6 @@ void PlotWidget::on_customTransformsDialog()
}

transformCustomCurves();

zoomOut(false);
replot();
}
Expand Down
36 changes: 22 additions & 14 deletions plotter_gui/transforms/custom_function.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,28 @@ CustomFunction::CustomFunction(const std::string &linkedPlot,
{
}

QStringList CustomFunction::getChannelsFromFuntion(const QString& function)
{
QStringList output;
int offset = 0;
while(true)
{
int pos1 = function.indexOf("$$", offset);
if(pos1 == -1){
break;
}

int pos2 = function.indexOf("$$", pos1+2);
if(pos2 == -1)
{
return {};
}
output.push_back( function.mid(pos1+2, pos2-pos1-2) );
offset = pos2+2;
}
return output;
}

CustomFunction::CustomFunction(const std::string &linkedPlot,
const std::string &plotName,
const QString &globalVars,
Expand Down Expand Up @@ -171,19 +193,6 @@ void CustomFunction::calculate(const PlotDataMapRef &plotData, PlotData* dst_dat
_last_updated_timestamp = dst_data->back().x;
}

bool CustomFunction::isValid(const PlotDataMapRef &plotData) const
{
for(const auto& channel: _used_channels)
{
if(plotData.numeric.count(channel) == 0)
{
return false;
}
}
return true;
}


const std::string &CustomFunction::name() const
{
return _plot_name;
Expand Down Expand Up @@ -236,7 +245,6 @@ CustomPlotPtr CustomFunction::createFromXML(QDomElement &element)
return std::make_shared<CustomFunction>(linkedPlot, name, globalVars, calcEquation );
}


std::map<QString, SnippetData> GetSnippetsFromXML(const QString& xml_text)
{
std::map<QString, SnippetData> snippets;
Expand Down
4 changes: 2 additions & 2 deletions plotter_gui/transforms/custom_function.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ class CustomFunction

void calculate(const PlotDataMapRef &plotData, PlotData *dst_data);

bool isValid(const PlotDataMapRef &plotData) const;

const std::string& name() const;

const std::string& linkedPlotName() const;
Expand All @@ -50,6 +48,8 @@ class CustomFunction

static CustomPlotPtr createFromXML(QDomElement &element );

static QStringList getChannelsFromFuntion(const QString& function);

private:
void initJsEngine();

Expand Down

0 comments on commit d6a306d

Please sign in to comment.