Skip to content

Commit

Permalink
ASCII curve export: better defaults
Browse files Browse the repository at this point in the history
see #656
  • Loading branch information
devernay committed Jul 20, 2021
1 parent 41a3a50 commit f064207
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 5 deletions.
6 changes: 6 additions & 0 deletions Gui/CurveWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,12 @@ CurveWidget::~CurveWidget()
makeCurrent();
}

bool
CurveWidget::hasTimeline() const
{
return bool(_imp->_timeline);
}

void
CurveWidget::initializeGL()
{
Expand Down
2 changes: 2 additions & 0 deletions Gui/CurveWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ GCC_DIAG_SUGGEST_OVERRIDE_ON

virtual ~CurveWidget() OVERRIDE;

bool hasTimeline() const;

const QFont & getTextFont() const;

void centerOn(double xmin, double xmax);
Expand Down
33 changes: 30 additions & 3 deletions Gui/CurveWidgetDialogs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ NATRON_NAMESPACE_ENTER
ImportExportCurveDialog::ImportExportCurveDialog(bool isExportDialog,
const std::vector<CurveGuiPtr> & curves,
Gui* gui,
QWidget* parent)
CurveWidget* parent)
: QDialog(parent)
, _gui(gui)
, _isExportDialog(isExportDialog)
Expand Down Expand Up @@ -91,7 +91,34 @@ ImportExportCurveDialog::ImportExportCurveDialog(bool isExportDialog,

bool integerIncrement = false;
double xstart, xend;
gui->getApp()->getProject()->getFrameRange(&xstart, &xend);
QString incr;
if ( parent->hasTimeline() ) {
gui->getApp()->getFrameRange(&xstart, &xend);
incr = QString::fromUtf8("1");
} else {
xstart = std::numeric_limits<double>::infinity();
xend = -std::numeric_limits<double>::infinity();
for (size_t i = 0; i < curves.size(); ++i) {
std::pair<double, double> r = curves[i]->getInternalCurve()->getXRange();
if (r.first < xstart) {
xstart = r.first;
}
if (r.second > xend) {
xend = r.second;
}
}
if ( xstart == std::numeric_limits<double>::infinity() ) {
xstart = 0.;
}
if ( xend == -std::numeric_limits<double>::infinity() ) {
xend = 1.;
}
if (xstart == 0. && xend == 1.) {
incr = QString::fromUtf8("1./255.");
} else {
incr = QString::number(xend - xstart) + QString::fromUtf8("/100.");
}
}
for (size_t i = 0; i < curves.size(); ++i) {
integerIncrement |= curves[i]->areKeyFramesTimeClampedToIntegers();
}
Expand Down Expand Up @@ -135,7 +162,7 @@ ImportExportCurveDialog::ImportExportCurveDialog(bool isExportDialog,
_incrLayout->addWidget(_incrLabel);
_incrLineEdit = new LineEdit(_incrContainer);
if (xstart == 0. && xend == 1.) {
_incrLineEdit->setText(QString::fromUtf8("1"));
_incrLineEdit->setText(incr);
} else {
_incrLineEdit->setText(QString::number(1));
}
Expand Down
2 changes: 1 addition & 1 deletion Gui/CurveWidgetDialogs.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class ImportExportCurveDialog
ImportExportCurveDialog(bool isExportDialog,
const std::vector<CurveGuiPtr> & curves,
Gui* gui,
QWidget* parent = 0);
CurveWidget* parent = 0);

virtual ~ImportExportCurveDialog();
QString getFilePath();
Expand Down
2 changes: 1 addition & 1 deletion Gui/CurveWidgetPrivate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ CurveWidgetPrivate::CurveWidgetPrivate(Gui* gui,
, _selectedKeyFramesCrossVertLine()
, _selectedKeyFramesCrossHorizLine()
, _timeline(timeline)
, _timelineEnabled(false)
, _timelineEnabled(bool(timeline))
, _selectedDerivative()
, _evaluateOnPenUp(false)
, _keyDragLastMovement()
Expand Down

0 comments on commit f064207

Please sign in to comment.