8 changes: 7 additions & 1 deletion src/libkst/objectstore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ const PrimitiveList ObjectStore::getFramePrimitives() const {
DataVectorList data_vectors = getObjects<DataVector>();
VScalarList vscalars = getObjects<VScalar>();
DataMatrixList data_matrixes = getObjects<DataMatrix>();
DataStringList data_strings = getObjects<DataString>();


foreach (DataVectorPtr dv, data_vectors) {
Expand All @@ -225,8 +226,13 @@ const PrimitiveList ObjectStore::getFramePrimitives() const {
foreach (VScalarPtr vs, vscalars) {
primitives.append(vs);
}
foreach (DataStringPtr ds, data_strings) {
if (ds->isStream()) {
primitives.append(ds);
}
}
foreach (DataMatrixPtr dm, data_matrixes) {
if (dm->hasStream()) {
if (dm->isStream()) {
primitives.append(dm);
}
}
Expand Down
4 changes: 3 additions & 1 deletion src/libkst/stringfactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ PrimitivePtr DataStringFactory::generatePrimitive(ObjectStore *store, QXmlStream
Q_ASSERT(store);

QString file, field;
int frame=0;

while (!xml.atEnd()) {
const QString n = xml.name().toString();
Expand All @@ -105,6 +106,7 @@ PrimitivePtr DataStringFactory::generatePrimitive(ObjectStore *store, QXmlStream

file = DataPrimitive::readFilename(attrs);
field = attrs.value("field").toString();
frame = attrs.value("frame").toString().toInt();

if (!store->override.fileName.isEmpty()) {
file = store->override.fileName;
Expand Down Expand Up @@ -141,7 +143,7 @@ PrimitivePtr DataStringFactory::generatePrimitive(ObjectStore *store, QXmlStream
DataStringPtr dataString = store->createObject<DataString>();

dataString->writeLock();
dataString->change(dataSource, field);
dataString->change(dataSource, field, frame);

dataString->setDescriptiveName(descriptiveName);
dataString->registerChange();
Expand Down
2 changes: 1 addition & 1 deletion src/libkst/stringscriptinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ QString StringDataSI::doCommand(QString x) {
DataSourcePtr ds = DataSourcePluginManager::findOrLoadSource(
str->store(), p.at(0));
str->writeLock();
str->change(ds,p.at(1));
str->change(ds,p.at(1), p.at(2).toInt());
str->unlock();
return "Done";
} else if (x.startsWith(QLatin1String("value()"))) {
Expand Down
11 changes: 11 additions & 0 deletions src/libkst/vscalar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,17 @@ int VScalar::F0() const {
return _f0;
}


int VScalar::fileLength() {

if (dataSource()) {
return dataSource()->vector().dataInfo(_field).frameCount-1;
}

return 0;
}


/** Save data scalar information */
void VScalar::save(QXmlStreamWriter &s) {
if (dataSource()) {
Expand Down
3 changes: 3 additions & 0 deletions src/libkst/vscalar.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ class KSTCORE_EXPORT VScalar : public Scalar, public DataPrimitive {
/** return sample number */
int F0() const;

/** return file length */
int fileLength();

/** Save scalar information */
virtual void save(QXmlStreamWriter &s);

Expand Down
154 changes: 149 additions & 5 deletions src/libkstapp/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1863,6 +1863,24 @@ void MainWindow::readFromEnd() {
v->unlock();
}

VScalarList vScalars = document()->objectStore()->getObjects<VScalar>();
foreach (VScalarPtr s, vScalars) {
s->readLock();
s->changeFrame(-1);
s->registerChange();
s->unlock();
}

DataStringList dataStrings = document()->objectStore()->getObjects<DataString>();
foreach (DataStringPtr s, dataStrings) {
if (s->isStream()) {
s->readLock();
s->setFrame(-1);
s->registerChange();
s->unlock();
}
}

DataMatrixList dataMatrices = document()->objectStore()->getObjects<DataMatrix>();
foreach (DataMatrixPtr m, dataMatrices) {
m->readLock();
Expand Down Expand Up @@ -1899,6 +1917,24 @@ void MainWindow::readToEnd() {
v->unlock();
}

VScalarList vScalars = document()->objectStore()->getObjects<VScalar>();
foreach (VScalarPtr s, vScalars) {
s->readLock();
s->changeFrame(-1);
s->registerChange();
s->unlock();
}

DataStringList dataStrings = document()->objectStore()->getObjects<DataString>();
foreach (DataStringPtr s, dataStrings) {
if (s->isStream()) {
s->readLock();
s->setFrame(-1);
s->registerChange();
s->unlock();
}
}

DataMatrixList dataMatrices = document()->objectStore()->getObjects<DataMatrix>();
foreach (DataMatrixPtr m, dataMatrices) {
m->readLock();
Expand Down Expand Up @@ -1936,7 +1972,8 @@ void MainWindow::forward() {

DataVectorList dataVectors = document()->objectStore()->getObjects<DataVector>();
DataMatrixList dataMatrices = document()->objectStore()->getObjects<DataMatrix>();

VScalarList vScalars = document()->objectStore()->getObjects<VScalar>();
DataStringList dataStrings = document()->objectStore()->getObjects<DataString>();
QHash<int,int> lastframehash;

foreach (DataVectorPtr v, dataVectors) {
Expand Down Expand Up @@ -1977,8 +2014,59 @@ void MainWindow::forward() {
}
}

foreach (VScalarPtr vs, vScalars) {
int new_frame;
int filelength = vs->fileLength();
if (most_popular_lastF>=0) {
if (most_popular_lastF < filelength) {
new_frame = most_popular_lastF;
} else {
new_frame = filelength-1;
}
} else {
if (vs->F0() < 0) {
new_frame = -1;
} else if (vs->F0()+1 <= filelength) {
new_frame = vs->F0()+1;
} else {
new_frame = filelength-1;
}
}
vs->writeLock();
vs->changeFrame(new_frame);
vs->registerChange();
vs->unlock();
}

foreach (DataStringPtr s, dataStrings) {
if (s->isStream()) {
int new_frame;
int filelength = s->fileLength();
if (most_popular_lastF>=0) {
if (most_popular_lastF < filelength) {
new_frame = most_popular_lastF;
} else {
new_frame = filelength-1;
}
} else {
if (s->frame() < 0) {
new_frame = -1;
} else if (s->frame()+1 < filelength) {
new_frame = s->frame()+1;
} else {
new_frame = filelength-1;
}
}
s->writeLock();
s->setFrame(new_frame);
s->registerChange();
s->unlock();
}
}


foreach (DataMatrixPtr m, dataMatrices) {
if (m->hasStream()) {
if (m->isStream()) {
int new_frame;
int filelength = m->fileLength();
if (most_popular_lastF>=0) {
Expand All @@ -1988,7 +2076,9 @@ void MainWindow::forward() {
new_frame = filelength-1;
}
} else {
if (m->frame()+1 < filelength) {
if (m->frame() < 0) {
new_frame = -1;
} else if (m->frame()+1 < filelength) {
new_frame = m->frame()+1;
} else {
new_frame = filelength-1;
Expand Down Expand Up @@ -2023,6 +2113,8 @@ void MainWindow::back() {

DataVectorList dataVectors = document()->objectStore()->getObjects<DataVector>();
DataMatrixList dataMatrices = document()->objectStore()->getObjects<DataMatrix>();
VScalarList vScalars = document()->objectStore()->getObjects<VScalar>();
DataStringList dataStrings = document()->objectStore()->getObjects<DataString>();

QHash<int,int> lastframehash;

Expand Down Expand Up @@ -2071,8 +2163,58 @@ void MainWindow::back() {
}
}

foreach (VScalarPtr vs, vScalars) {
int new_frame;
int filelength = vs->fileLength();
if (most_popular_lastF>=0) {
if (most_popular_lastF < filelength) {
new_frame = most_popular_lastF;
} else {
new_frame = filelength-1;
}
} else {
if (vs->F0() < 0) {
new_frame = filelength-1;
} else if (vs->F0()-1 >= 0) {
new_frame = vs->F0()-1;
} else {
new_frame = 0;
}
}
vs->writeLock();
vs->changeFrame(new_frame);
vs->registerChange();
vs->unlock();
}

foreach (DataStringPtr s, dataStrings) {
if (s->isStream()) {
int new_frame;
int filelength = s->fileLength();
if (most_popular_lastF>=0) {
if (most_popular_lastF < filelength) {
new_frame = most_popular_lastF;
} else {
new_frame = filelength-1;
}
} else {
if (s->frame() < 0) {
new_frame = filelength-1;
} else if (s->frame()-1 >= 0) {
new_frame = s->frame()-1;
} else {
new_frame = 0;
}
}
s->writeLock();
s->setFrame(new_frame);
s->registerChange();
s->unlock();
}
}

foreach (DataMatrixPtr m, dataMatrices) {
if (m->hasStream()) {
if (m->isStream()) {
int new_frame;
int filelength = m->fileLength();
if (most_popular_lastF>=0) {
Expand All @@ -2082,7 +2224,9 @@ void MainWindow::back() {
new_frame = filelength-1;
}
} else {
if (m->frame()-1 >= 0) {
if (m->frame() < 0) {
new_frame = filelength-1;
} else if (m->frame()-1 >= 0) {
new_frame = m->frame()-1;
} else {
new_frame = filelength-2;
Expand Down
8 changes: 4 additions & 4 deletions src/libkstapp/matrixdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -549,10 +549,10 @@ void MatrixTab::sourceValid(QString filename, int requestID) {
_field->setEditable(!_dataSource->matrix().isListComplete() && !_dataSource->matrix().list().empty());
_configure->setEnabled(_dataSource->hasConfigWidget());

bool hasImageStream = _dataSource->hasImageStream();
_frame->setVisible(hasImageStream);
_frameLabel->setVisible(hasImageStream);
_lastFrame->setVisible(hasImageStream);
bool isImageStream = _dataSource->isImageStream(_field->currentText());
_frame->setVisible(isImageStream);
_frameLabel->setVisible(isImageStream);
_lastFrame->setVisible(isImageStream);

_dataSource->unlock();

Expand Down
46 changes: 44 additions & 2 deletions src/libkstapp/stringdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,11 @@ StringTab::StringTab(ObjectStore *store, QWidget *parent)
connect(_dataStringGroup, SIGNAL(toggled(bool)), this, SLOT(readFromSourceClicked()));
connect(_stringValue, SIGNAL(textChanged(QString)), this, SLOT(textChanged()));
connect(_fileName, SIGNAL(changed(QString)), this, SLOT(fileNameChanged(QString)));
connect(_field, SIGNAL(currentTextChanged(QString)), this, SLOT(fieldChanged(QString)));
connect(_configure, SIGNAL(clicked()), this, SLOT(showConfigWidget()));
connect(_field, SIGNAL(currentIndexChanged(int)), this, SLOT(textChanged()));
connect(_frame, SIGNAL(valueChanged(int)), this, SLOT(textChanged()));
connect(_lastFrame, SIGNAL(clicked(bool)), this, SLOT(enableFrames()));
}


Expand Down Expand Up @@ -80,6 +83,27 @@ void StringTab::textChanged() {
}


int StringTab::frame() const {
if (_lastFrame->isChecked()) {
return (-1);
} else {
return _frame->value();
}
}


void StringTab::setFrame(int frame) {
if (frame<0) {
_lastFrame->setChecked(true);
_frame->setEnabled(false);
} else {
_lastFrame->setChecked(false);
_frame ->setValue(frame);
_frame->setEnabled(true);
}
}


void StringTab::hideGeneratedOptions() {
_generatedStringGroup->setVisible(false);
_dataStringGroup->setCheckable(false);
Expand Down Expand Up @@ -166,13 +190,23 @@ void StringTab::sourceValid(QString filename, int requestID) {
setField(_current_field);
_field->setEditable(!_dataSource->string().isListComplete());
_configure->setEnabled(_dataSource->hasConfigWidget());

bool isStringStream = _dataSource->isStringStream(_field->currentText());
_frame->setVisible(isStringStream);
_frameLabel->setVisible(isStringStream);
_lastFrame->setVisible(isStringStream);

_dataSource->unlock();

_store->cleanUpDataSourceList();

emit sourceChanged();
}

void StringTab::enableFrames() {
_frame->setEnabled(!_lastFrame->isChecked());
}


void StringTab::fileNameChanged(const QString &file) {
_field->clear();
Expand All @@ -186,6 +220,13 @@ void StringTab::fileNameChanged(const QString &file) {
QThreadPool::globalInstance()->start(validateDSThread);
}

void StringTab::fieldChanged(const QString &field) {
bool isImageStream = _dataSource->isStringStream(field);
_frame->setVisible(isImageStream);
_frameLabel->setVisible(isImageStream);
_lastFrame->setVisible(isImageStream);
}


void StringTab::showConfigWidget() {
QPointer<DataSourceConfigureDialog> dialog = new DataSourceConfigureDialog(dataDialog()->editMode(), _dataSource, this);
Expand Down Expand Up @@ -235,6 +276,7 @@ void StringDialog::configureTab(ObjectPtr object) {
_stringTab->setDataSource(dataString->dataSource());
_stringTab->setField(dataString->field());
_stringTab->hideGeneratedOptions();
_stringTab->setFrame(dataString->frame());
} else if (StringPtr string = kst_cast<String>(object)) { // edit value string
_stringTab->hideDataOptions();
_stringTab->setValue(string->value());
Expand Down Expand Up @@ -310,7 +352,7 @@ ObjectPtr StringDialog::createNewDataString() {
DataStringPtr string = _document->objectStore()->createObject<DataString>();

string->writeLock();
string->change(dataSource, field);
string->change(dataSource, field, _stringTab->frame());

if (DataDialog::tagStringAuto()) {
string->setDescriptiveName(QString());
Expand Down Expand Up @@ -360,7 +402,7 @@ ObjectPtr StringDialog::editExistingDataObject() const {
} else {
string->setDescriptiveName(DataDialog::tagString());
}
string->change(dataSource, field);
string->change(dataSource, field, _stringTab->frame());
string->registerChange();
string->unlock();
dialogDefaults().setValue("String/datasource", _stringTab->file());
Expand Down
6 changes: 6 additions & 0 deletions src/libkstapp/stringdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ class StringTab : public DataTab, Ui::StringTab {
QString field() const;
void setField(const QString &field);

int frame() const;
bool frameDirty() const;
void setFrame(int frame);

void setFieldList(const QStringList &fieldList);

void hideGeneratedOptions();
Expand All @@ -62,8 +66,10 @@ class StringTab : public DataTab, Ui::StringTab {
void generateClicked();
void textChanged();
void fileNameChanged(const QString &file);
void fieldChanged(const QString &field);
void showConfigWidget();
void sourceValid(QString filename, int requestID);
void enableFrames();

private:
void updateDataSource();
Expand Down
89 changes: 59 additions & 30 deletions src/libkstapp/stringtab.ui
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>648</width>
<height>259</height>
<width>387</width>
<height>270</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout">
Expand Down Expand Up @@ -39,33 +39,7 @@
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="Kst::DataSourceSelector" name="_fileName" native="true"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_5">
<property name="text">
<string>Fie&amp;ld:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
<property name="wordWrap">
<bool>false</bool>
</property>
<property name="buddy">
<cstring>_field</cstring>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="Kst::ComboBox" name="_field">
<property name="enabled">
<bool>false</bool>
</property>
</widget>
</item>
<item row="2" column="0" colspan="2">
<item row="4" column="0" colspan="3">
<layout class="QHBoxLayout" name="_3">
<property name="leftMargin">
<number>0</number>
Expand Down Expand Up @@ -117,6 +91,62 @@
</item>
</layout>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_5">
<property name="text">
<string>Fie&amp;ld:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
<property name="wordWrap">
<bool>false</bool>
</property>
<property name="buddy">
<cstring>_field</cstring>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="_frameLabel">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Frame:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QSpinBox" name="_frame">
<property name="maximum">
<number>10000000</number>
</property>
</widget>
</item>
<item row="2" column="2">
<widget class="QCheckBox" name="_lastFrame">
<property name="text">
<string>Last Frame</string>
</property>
</widget>
</item>
<item row="0" column="1" colspan="2">
<widget class="Kst::DataSourceSelector" name="_fileName" native="true"/>
</item>
<item row="1" column="1" colspan="2">
<widget class="Kst::ComboBox" name="_field">
<property name="enabled">
<bool>false</bool>
</property>
</widget>
</item>
</layout>
</widget>
</item>
Expand Down Expand Up @@ -202,7 +232,6 @@
<tabstop>_generatedStringGroup</tabstop>
<tabstop>_stringValue</tabstop>
<tabstop>_dataStringGroup</tabstop>
<tabstop>_field</tabstop>
<tabstop>_connect</tabstop>
<tabstop>_configure</tabstop>
</tabstops>
Expand Down
4 changes: 3 additions & 1 deletion tests/dirfile_maker/dirfile_maker.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,12 @@ int main() {
fprintf(fpf, " LABEL%02d", i);
}
fprintf(fpf, "\n");

fprintf(fpf, "label SINDIR stridx namearray\n");

fclose(fpf);

// SINDIR type
fprintf(fpf, "label SINDIR stridx namearray\n");

printf("starting loop\n");
while (1) {
Expand Down