Skip to content

Commit

Permalink
Fix ASCII curve import
Browse files Browse the repository at this point in the history
fixes #656
  • Loading branch information
devernay committed Jul 20, 2021
1 parent 4b3e108 commit 41a3a50
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 39 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
- Fix multi-dimensional parameter linking (bug introduced in 2.4.0 #594). #631
- Fix bug where any argument containing an integer between commas would be interpreted as a frame range. #644
- Python: `app.saveProject` and `app.saveProjectAs` now do project variable substitution, as in `app.saveProjectAs("[Variable]/output.ntp")`.
- Fix ASCII curve import. #656

### Plugins

Expand Down
33 changes: 6 additions & 27 deletions Gui/CurveWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2212,36 +2212,15 @@ CurveWidget::importCurveFromAscii()
std::map<CurveGuiPtr, std::vector<double> > curvesValues;
///scan the file to get the curve values
while ( !ts.atEnd() ) {
QString line = ts.readLine();
if ( line.isEmpty() ) {
QString line = ts.readLine().simplified();
if ( line.isEmpty() || line[0] == QLatin1Char('#') ) {
continue;
}
int i = 0;
std::vector<double> values;

///read the line to extract all values
while ( i < line.size() ) {
QString value;
while ( i < line.size() && line.at(i) != QLatin1Char('_') ) {
value.push_back( line.at(i) );
++i;
}
if ( i < line.size() ) {
if ( line.at(i) != QLatin1Char('_') ) {
Dialogs::errorDialog( tr("Curve Import").toStdString(), tr("The file could not be read.").toStdString() );

return;
}
++i;
}
bool ok;
double v = value.toDouble(&ok);
if (!ok) {
Dialogs::errorDialog( tr("Curve Import").toStdString(), tr("The file could not be read.").toStdString() );

return;
}
values.push_back(v);
QStringList valuesStr = line.split( QLatin1Char(' ') );
std::vector<double> values;
Q_FOREACH(const QString& v, valuesStr) {
values.push_back( v.toDouble() );
}
///assert that the values count is greater than the number of curves provided by the user
if ( values.size() < columns.size() ) {
Expand Down
18 changes: 6 additions & 12 deletions Gui/CurveWidgetDialogs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ GCC_DIAG_UNUSED_PRIVATE_FIELD_ON
#include "Gui/SequenceFileDialog.h" // SequenceFileDialog
#include "Gui/GuiApplicationManager.h"
#include "Gui/Label.h" // Label
#include "Gui/Gui.h" // Gui
#include "Gui/GuiAppInstance.h"
#include "Engine/Project.h"

NATRON_NAMESPACE_ENTER

Expand Down Expand Up @@ -87,19 +90,10 @@ ImportExportCurveDialog::ImportExportCurveDialog(bool isExportDialog,
assert( qApp && qApp->thread() == QThread::currentThread() );

bool integerIncrement = false;
double xstart = -std::numeric_limits<double>::infinity();
double xend = std::numeric_limits<double>::infinity();
double xstart, xend;
gui->getApp()->getProject()->getFrameRange(&xstart, &xend);
for (size_t i = 0; i < curves.size(); ++i) {
integerIncrement |= curves[i]->areKeyFramesTimeClampedToIntegers();
std::pair<double,double> xrange = curves[i]->getInternalCurve()->getXRange();
xstart = std::max(xstart, xrange.first);
xend = std::min(xend, xrange.second);
}
if (xstart == -std::numeric_limits<double>::infinity()) {
xstart = std::min(0., xend - 1.);
}
if (xend == std::numeric_limits<double>::infinity()) {
xend = std::max(xstart + 1., 1.);
}
_mainLayout = new QVBoxLayout(this);
_mainLayout->setContentsMargins(0, 3, 0, 0);
Expand Down Expand Up @@ -141,7 +135,7 @@ ImportExportCurveDialog::ImportExportCurveDialog(bool isExportDialog,
_incrLayout->addWidget(_incrLabel);
_incrLineEdit = new LineEdit(_incrContainer);
if (xstart == 0. && xend == 1.) {
_incrLineEdit->setText(QString::fromUtf8("1./255"));
_incrLineEdit->setText(QString::fromUtf8("1"));
} else {
_incrLineEdit->setText(QString::number(1));
}
Expand Down

0 comments on commit 41a3a50

Please sign in to comment.