Ejemplo n.º 1
0
AMScanConfiguration* AMBeamlineScanAction::cfg() const {
    if(cfg_)
        return cfg_;

    // turn off automatic raw-day loading for scans... This will make loading the scan to access it's config much faster.
    bool scanAutoLoadingOn = AMScan::autoLoadData();
    AMScan::setAutoLoadData(false);
    // Dynamically create and load a detailed subclass of AMDbObject from the database... whatever type it is.
    AMDbObject* dbo = AMDbObjectSupport::s()->createAndLoadObjectAt(AMDatabase::database("user"), AMDbObjectSupport::s()->tableNameForClass<AMScan>(), scanID_);
    if(!dbo)
        return 0; //NULL
    // restore AMScan's auto-loading of data to whatever it was before.
    AMScan::setAutoLoadData(scanAutoLoadingOn);
    // Is it a scan?
    AMScan* scan = qobject_cast<AMScan*>( dbo );
    if(!scan) {
        delete dbo;
        return 0; //NULL
    }
    // Does the scan have a configuration?
    AMScanConfiguration* config = scan->scanConfiguration();
    if(!config) {
        scan->release();
        return 0; //NULL
    }
    // need to create a copy of the config so we can delete the scan (and hence the config instance owned by the scan). The view will take ownership of the copy.
    config = config->createCopy();
    scan->release();
    if(!config)
        return 0; //NULL
    cfg_ = config;
    return cfg_;
}
Ejemplo n.º 2
0
AMScanConfiguration *AMScanActionInfo::getConfigurationFromDb() const
{
    // no need to bother if we don't have a scan id to use
    if(scanID_ == -1)
        return 0; //NULL

    // turn off automatic raw-data loading for scans... This will make loading the scan to access it's config much faster.
    bool scanAutoLoadingOn = AMScan::autoLoadData();
    AMScan::setAutoLoadData(false);
    // Dynamically create and load a detailed subclass of AMDbObject from the database... whatever type it is.
    AMDbObject* dbo = AMDbObjectSupport::s()->createAndLoadObjectAt(AMDatabase::database("user"), AMDbObjectSupport::s()->tableNameForClass<AMScan>(), scanID_);
    if(!dbo) {

        AMErrorMon::alert(this, AMSCANACTIONINFO_CANNOT_LOAD_FROM_DB, "Could not load scan from the database.");
        return 0; //NULL
    }

    // restore AMScan's auto-loading of data to whatever it was before.
    AMScan::setAutoLoadData(scanAutoLoadingOn);
    // Is it a scan?
    AMScan* scan = qobject_cast<AMScan*>( dbo );
    if(!scan) {

        AMErrorMon::alert(this, AMSCANACTIONINFO_DB_OBJECT_NOT_A_SCAN, "Object loaded from the database was not a scan.");
        dbo->deleteLater();
        return 0; //NULL
    }
    // Does the scan have a configuration?
    AMScanConfiguration* config = scan->scanConfiguration();
    if(!config) {

        AMErrorMon::alert(this, AMSCANACTIONINFO_SCAN_HAS_NO_CONFIGURATION, "Scan does not have a valid scan configuration.");
        scan->deleteLater();
        return 0; //NULL
    }
    // need to create a copy of the config so we can delete the scan (and hence the config instance owned by the scan). The view will take ownership of the copy.
    config = config->createCopy();
    scan->deleteLater();

    if(!config) {

        AMErrorMon::alert(this, AMSCANACTIONINFO_CREATE_CONFIGURATION_COPY_FAILED, "Failed to create a copy of the scan configuration.");
    }

    return config;
}
Ejemplo n.º 3
0
void AMScanAction::autoExportScan()
{
	// If we managed to save the scan to the database, we should check if the scan should be auto exported, and if it should - export it.
	if (controller_->scan()->database()){

		// Save the finished scan to the database.
		if (controller_->scan()->storeToDb(controller_->scan()->database())){

			AMScanConfiguration *config = controller_->scan()->scanConfiguration();

			if (config->autoExportEnabled()){

				AMExportController *exportController = new AMExportController(QList<AMScan *>() << controller_->scan(), this);
				exportController->setDefaultDestinationFolderPath();
				AMExporter *autoExporter = AMAppControllerSupport::createExporter(config);

				if(!autoExporter){

					AMErrorMon::alert(this, AMSCANACTION_NO_REGISTERED_EXPORTER, "No exporter registered for this scan type.");
					return;
				}

				exportController->chooseExporter(autoExporter->metaObject()->className());

				// This next creation involves a loadFromDb ... I tested it and it seems fast (milliseconds) ... if that's a Mac only thing then we can figure out a caching system, let me know I have a few ideas
				AMExporterOption *autoExporterOption = AMAppControllerSupport::createExporterOption(config);
				if(!autoExporterOption){

					AMErrorMon::alert(this, AMSCANACTION_NO_REGISTERED_EXPORTER_OPTION, "No exporter option registered for this scan type.");
					return;
				}

				exportController->setOption(autoExporterOption);
				exportController->start(true);
			}
		}

		else
			AMErrorMon::alert(this, AMSCANACTION_CANT_SAVE_TO_DB, "The scan action was unable to update the scan in the database.");
	}

	else
		AMErrorMon::alert(this, AMSCANACTION_DATABASE_NOT_FOUND, "Could not find the database associated with this scan.");
}
Ejemplo n.º 4
0
void AMAppController::launchScanConfigurationFromDb(const QUrl &url)
{
	// turn off automatic raw-day loading for scans... This will make loading the scan to access it's config much faster.
	bool scanAutoLoadingOn = AMScan::autoLoadData();
	AMScan::setAutoLoadData(false);

	AMScan* scan = AMScan::createFromDatabaseUrl(url, true);

	// restore AMScan's auto-loading of data to whatever it was before.
	AMScan::setAutoLoadData(scanAutoLoadingOn);

	if(!scan)
		return;


	// need to check that this scan actually has a valid config. This hasn't always been guaranteed, especially when scans move between beamlines.
	AMScanConfiguration* config = scan->scanConfiguration();
	if(!config) {
		scan->deleteLater();
		return;
	}
	// need to create a copy of the config so we can delete the scan (and hence the config instance owned by the scan). The view will take ownership of the copy.
	config = config->createCopy();
	scan->deleteLater();
	if(!config)
		return;

	AMScanConfigurationView *view = config->createView();
	if(!view) {
		config->deleteLater();
		AMErrorMon::report(AMErrorReport(this, AMErrorReport::Alert, -401, "Unable to create view from the scan configuration loaded from the database.  Contact Acquaman developers."));
		return;
	}

	// This is Actions3 stuff.
	AMScanConfigurationViewHolder3 *viewHolder = new AMScanConfigurationViewHolder3(view);
	viewHolder->setAttribute(Qt::WA_DeleteOnClose, true);
	viewHolder->show();
}
AMScanConfiguration *SXRMB2DMapScanConfiguration::createCopy() const
{
	AMScanConfiguration *configuration = new SXRMB2DMapScanConfiguration(*this);
	configuration->dissociateFromDb(true);
	return configuration;
}
AMScanConfiguration* SGMXASScanConfiguration2013::createCopy() const
{
	AMScanConfiguration *configuration = new SGMXASScanConfiguration2013(*this);
	configuration->dissociateFromDb(true);
	return configuration;
}
AMScanConfiguration *VESPERS2DScanConfiguration::createCopy() const
{
	AMScanConfiguration *configuration = new VESPERS2DScanConfiguration(*this);
	configuration->dissociateFromDb(true);
	return configuration;
}