Beispiel #1
0
QWidget* AutoImportWindow::setupInputFolderContainer() {
    GroupContainer* container = new GroupContainer();
    container->setTitle("Import Folder");

    QFormLayout* layout = new QFormLayout;
    layout->setHorizontalSpacing(10);
    layout->setVerticalSpacing(0);
    layout->setRowWrapPolicy(QFormLayout::DontWrapRows);
    layout->setFieldGrowthPolicy(QFormLayout::ExpandingFieldsGrow);
    layout->setFormAlignment(Qt::AlignHCenter | Qt::AlignTop);
    layout->setLabelAlignment(Qt::AlignLeft);

    BrowserWidget* filesDirBrowser_ = new BrowserWidget(BrowserWidget::BrowseType::DIRECTORY);
    ParametersConfiguration* conf  = projectData.projectParameterData();
    QString importImagesPath = conf->getValue("import_dir");
    filesDirBrowser_->setPath(importImagesPath);
    setupWatcherPaths();
    connect(filesDirBrowser_, &BrowserWidget::pathChanged, [ = ] (const QString & value){
        conf->set("import_dir", value);
        setupWatcherPaths();
        analyzeImport();
    });
    layout->addRow(filesDirBrowser_);

    QLabel* introLabel = new QLabel(introText());
    introLabel->setWordWrap(true);
    QPalette pal = introLabel->palette();
    pal.setColor(QPalette::WindowText, Qt::darkGray);
    introLabel->setPalette(pal);
    layout->addRow(introLabel);

    QCheckBox* restartCheck = new QCheckBox("Import new images in the import folder on start");
    restartCheck->setChecked(ProjectPreferences().importRestartCheck());
    connect(restartCheck, &QCheckBox::toggled, [ = ] (bool check){
        ProjectPreferences().setImportRestartCheck(check);
    });
    layout->addRow(restartCheck);

    
    layout->addRow(continuous);
    
    deleteCheck = new QCheckBox("DELETE the original images in import folder after importing them");
    deleteCheck->setChecked(ProjectPreferences().importDeleteCheck());
    deleteLabel_->setVisible(deleteCheck->isChecked());
    connect(deleteCheck, &QCheckBox::toggled, [ = ] (bool check){
        ProjectPreferences().setImportDeleteCheck(check);
        deleteLabel_->setVisible(check);
    });
    layout->addRow(deleteCheck);
    
    container->setContainerLayout(layout);

    return container;
}
Beispiel #2
0
void AutoImportWindow::importImage() {
    
    if(continuous->isChecked()) {
        analyzeImport(true);
    }
    
    if(toBeImported_.isEmpty()) {
        finishExecution();
        return;
    }

    if (imageExecuting_) {
        QString numberExec = imageExecuting_->directory();
        if (!numberExec.isEmpty()) {
            if (dirToRowNumber_.keys().contains(numberExec)) {
                if (dirToRowNumber_[numberExec] < resultsTable_->rowCount()) {
                    if (resultsTable_->item(dirToRowNumber_[numberExec], 0)) {
                        resultsTable_->item(dirToRowNumber_[numberExec], 0)->setIcon(ApplicationData::icon("process_done"));
                    }
                }
            }
        }
    }
    
    QString number;
    number = toBeImported_.keys().first();

    QStringList files = toBeImported_[number];
    toBeImported_.remove(number);
    
    //Get the original file name used for search
    QString baseName = files.first();
    
    //Deduce parameters from baseName
    QMap<QString, QString> fileNameParams = FileNameParserDialog::parseFileName(baseName);
    
    QString importGroup_ = projectData.projectParameterData()->getValue("import_target_group");
    QString importGroupSuffix = projectData.projectParameterData()->getValue("import_target_group_suffix");
    
    //Add suffix to group name
    QString suffix = "";
    
    //case importGroupSuffix=1 => parameter = specimennumber
    if(importGroupSuffix == "1") { 
        //If the file name contains this param take it from there, otherwise search master.cfg 
        if(fileNameParams.contains("specimennumber")) suffix = fileNameParams["specimennumber"];
        else {
            suffix = projectData.projectParameterData()->getValue("specimennumber");
        }
    }
    
    if(suffix == "-") suffix = "";
    
    importGroup_ = importGroup_ + suffix;
    
    if (dirToRowNumber_.keys().contains(number)) {
        if (dirToRowNumber_[number] < resultsTable_->rowCount()) {
            if(resultsTable_->item(dirToRowNumber_[number], 0)) {
                resultsTable_->item(dirToRowNumber_[number], 0)->setIcon(ApplicationData::icon("process_executing"));
                resultsTable_->scrollToItem(resultsTable_->item(dirToRowNumber_[number], 0));
            }
        }
    }
    
    statusLabel_->setText(QString("Currently importing and %2 are in queue...").arg(toBeImported_.keys().size()));
    projectData.projectParameterData()->set("import_imagenumber", number);
    
    //Create dir
    QDir workingDir = QDir(projectData.projectDir().canonicalPath() + "/" + importGroup_ + "/" + number);
    
    //create import group
    projectData.projectDir().mkpath(importGroup_);
    QFile(projectData.projectDir().absolutePath() + "/merge").link("../2dx_master.cfg", projectData.projectDir().absolutePath() + "/" + importGroup_ + "/2dx_master.cfg");
    
    //create Dir
    projectData.projectDir().mkpath(importGroup_ + "/" + number);
    workingDir.mkpath("proc");
    workingDir.mkpath("LOGS");

    //Copy Config File
    projectData.projectParameterData()->saveAs(workingDir.canonicalPath() + "/2dx_image.cfg", true);

    imageExecuting_ = projectData.addImage(importGroup_, number);
    ParametersConfiguration* conf = imageExecuting_->parameters();
    conf->set("imagenumber", number, false);
    
    bool hasAveraged = false;
    bool hasAligned = false;
    bool hasRaw = false;
    
    //Check for the averaged file
    if(files.size() > 1 && !files[1].isEmpty()) {
        conf->set("imagename", "image_2dx", false);
        conf->set("nonmaskimagename", "image_2dx", false);
        conf->set("imagename_original", files[1], false);
        conf->set("import_original_time", QString::number(QFileInfo(files[1]).created().toMSecsSinceEpoch()), false);
        scriptsToBeExecuted_.append("cp -f " + files[1] + " " + workingDir.canonicalPath() + "/" + "image_2dx.mrc");
        if(deleteCheck->isChecked()) scriptsToBeExecuted_.append("rm -f " + files[1]);
        hasAveraged = true;
    }
    
    //Check for aligned file
    if (files.size() > 2 && !files[2].isEmpty()) {
        conf->set("movie_stackname", "movie_aligned", false);
        conf->set("movie_stackname_original", files[2], false);
        conf->set("import_original_time", QString::number(QFileInfo(files[2]).created().toMSecsSinceEpoch()), false);
        scriptsToBeExecuted_.append("cp -f " + files[2] + " " + workingDir.canonicalPath() + "/" + "movie_aligned.mrcs");
        if(deleteCheck->isChecked()) scriptsToBeExecuted_.append("rm -f " + files[2]);
        hasAligned = true;
    }

    //Check for raw file
    if (files.size() > 3 && !files[3].isEmpty()) {
        int rawOption = conf->getVariant("import_rawstack_type").toInt();
        if(rawOption == 1) {
            conf->set("import_rawstack", baseName + '.' + QFileInfo(files[3]).suffix(), false);
            conf->set("import_rawstack_original", files[3], false);
            conf->set("import_original_time", QString::number(QFileInfo(files[3]).created().toMSecsSinceEpoch()), false);
            scriptsToBeExecuted_.append("cp -f " + files[3] + " " + workingDir.canonicalPath() + "/" + baseName + '.' + QFileInfo(files[3]).suffix());
            if(deleteCheck->isChecked()) scriptsToBeExecuted_.append("rm -f " + files[3]);
            hasRaw = true;
        } else if (rawOption == 2) {
            conf->set("import_rawstack", baseName + '.' + QFileInfo(files[3]).suffix(), false);
            conf->set("import_rawstack_original", files[3], false);
            conf->set("raw_gaincorrectedstack", "raw_gaincorrectedstack", false);
            conf->set("raw_gaincorrectedstack_original", files[3], false);
            conf->set("import_original_time", QString::number(QFileInfo(files[3]).created().toMSecsSinceEpoch()), false);
            scriptsToBeExecuted_.append("cp -f " + files[3] + " " + workingDir.canonicalPath() + "/" + "raw_gaincorrectedstack.mrcs");
            if(deleteCheck->isChecked()) scriptsToBeExecuted_.append("rm -f " + files[3]);
            hasRaw = true;
        }
    }

    //Check for defects list file
    QString defectsFile = conf->getValue("import_defects_original");
    if(QFileInfo(defectsFile).exists()) {
        conf->set("import_defects", "../" + QFileInfo(defectsFile).fileName(), false);
        scriptsToBeExecuted_.append("rsync -auvP " + defectsFile + " " + workingDir.canonicalPath() + "/../" + QFileInfo(defectsFile).fileName());
    }
    
    //Check for gain reference file
    QString gainRefFile = conf->getValue("import_gainref_original");
    if(QFileInfo(gainRefFile).exists()) {
        conf->set("import_gainref", "../" + QFileInfo(gainRefFile).fileName(), false);
        scriptsToBeExecuted_.append("rsync -auvP " + gainRefFile + " " + workingDir.canonicalPath() + "/../" + QFileInfo(gainRefFile).fileName());
    }
    
    //Set the parameters from filename
    for(QString param : fileNameParams.keys()) {
        if(parameterMaster.containsParameter(param)) {
            conf->set(param, fileNameParams[param], false);
            //qDebug() << "Parameter set: " << param << " => " << fileNameParams[param];
        }
    }
    
    conf->setModified(true);
    
    //Write to status folder if required
    if(userPreferenceData.get("status_folder_update") == "y" && QFileInfo(userPreferenceData.get("status_folder")).isDir()) {
        long currentMSecs = conf->getValue("import_original_time").toLong();
        
        //Write the last imported data
        QFile saveFile(userPreferenceData.get("status_folder") + "/last.txt");
        long lastMSecs = 0;
        if(saveFile.exists()) {
            if (saveFile.open(QIODevice::ReadOnly | QIODevice::Text)) {
                while (!saveFile.atEnd()) {
                    lastMSecs = QString(saveFile.readLine().simplified()).toLong();
                }
		saveFile.close();
            }
            saveFile.remove();
        }
        
	QString toBeWritten;
        if(currentMSecs >= lastMSecs) toBeWritten = QString::number(currentMSecs);
        else toBeWritten = QString::number(lastMSecs);
        if (saveFile.open(QIODevice::WriteOnly | QIODevice::Text)) {
            saveFile.write(toBeWritten.toLatin1());
        }
        saveFile.close();
        
        //Write the time stamp in the last hour processed data
        ProjectData::writeStatisticsToStatusFolder("last_recorded.txt", currentMSecs);
        ProjectData::writeStatisticsToStatusFolder("last_imported.txt");
    }
     
    //register that this image was imported
    ImportFolderSettings(QDir(conf->getValue("import_dir"))).addImportedImage(baseName, importGroup_ + "/" + number, hasAveraged, hasAligned, hasRaw);
    
    //Add the scripts to be executed during import
    QStringList scripts = importSelectorDialog.scriptPaths(ProjectPreferences().scripts("import"));
    for(QString script : scripts) {
        if(!script.isEmpty()) scriptsToBeExecuted_.append("SCRIPT:" + script);
    }
    continueExecution();
}