void MountainViewWidgetPrivate::update_clips_view(SSTimeSeriesWidget *W,SSTimeSeriesView *V,int label)
{
    QProgressDialog dlg;
	dlg.setWindowTitle(QString("Extracting clips for template %1").arg(label));
    dlg.setRange(0,100);
    dlg.show();
	dlg.setLabelText(QString("Extracting clips for template %1...").arg(label));
    dlg.setValue(0); dlg.repaint(); qApp->processEvents();
    Mda clips=extract_clips(m_raw,m_times,m_labels,label);
    dlg.setLabelText("Formatting clips...");
    dlg.setValue(50); dlg.repaint(); qApp->processEvents();
    Mda clips2=format_clips(clips,m_template_view_padding);
    DiskArrayModel *MM=new DiskArrayModel;
    MM->setFromMda(clips2);
    dlg.setLabelText("Initializing...");
    dlg.setValue(75); dlg.repaint(); qApp->processEvents();
    V->setData(MM,true);
    V->initialize();
    W->setClipData(clips);
    W->setWindowTitle(QString("Spike Clips -- template %1 -- %2 spikes").arg(label).arg(clips.N3()));
}
void MVCrossCorrelogramsWidget::updateWidget()
{
	if (d->m_path.isEmpty()) return;

	int k0=d->m_base_unit_num;

	DiskReadMda X;
	X.setPath(d->m_path);

	QProgressDialog dlg;
	dlg.show();
	dlg.setLabelText("Loading cross correlograms...");
	dlg.repaint(); qApp->processEvents();
	QList<FloatList> data0=get_cross_correlogram_datas_2(X,k0);

	int K=data0.count()-1;
	int num_rows=(int)sqrt(K); if (num_rows<1) num_rows=1;
	int num_cols=(K+num_rows-1)/num_rows;
	d->m_num_columns=num_cols;

	QWidget *W=this;
	W->setAttribute(Qt::WA_DeleteOnClose);
	QGridLayout *GL=new QGridLayout;
	GL->setHorizontalSpacing(20); GL->setVerticalSpacing(0);
	GL->setMargin(0);
	W->setLayout(GL);

	for (int k1=1; k1<=K; k1++) {
		HistogramView *HV=new HistogramView;
		HV->setData(data0[k1]);
		HV->autoSetBins(50);
		int k2=k1; if (k0>=1) k2=k0;
		QString title0=QString("%1/%2").arg(k1).arg(k2);
		HV->setTitle(title0);
		GL->addWidget(HV,(k1-1)/num_cols,(k1-1)%num_cols);
		HV->setProperty("unit_number",k1);
		connect(HV,SIGNAL(clicked()),this,SLOT(slot_histogram_view_clicked()));
		connect(HV,SIGNAL(activated()),this,SLOT(slot_histogram_view_activated()));
		d->m_histogram_views << HV;
	}
}
Exemple #3
0
bool AirportsData::import(QProgressDialog &progress, MainObject *mainObject){


    QHash<QString, QString> airports;
    QString msg;
    QTime tm;
    int ms;

    progress.setValue(0);
    progress.setWindowTitle("Scanning Airport Directories");
    progress.setRange(0, 50000);

    int c = 0;
    int found = 0;
    int air_added = 0;
    ms = tm.restart();
	
    // Removing cache file, if exists()
    if (QFile::exists(mainObject->data_file("airports.txt"))) {
            outLog("*** FGx airportsdata reload: cache file exists!");
            QFile::remove(mainObject->data_file("airports.txt"));
            outLog("*** FGx airportsdata reload: REMOVED AIRPORTS CACHE FILE");
    }

    //= Cache File
    QFile cacheFile( mainObject->data_file("airports.txt") );
    if(!cacheFile.open(QIODevice::WriteOnly | QIODevice::Text)){
            //qDebug() << "TODO Open error cachce file=";
            return true;
    }
    QTextStream out(&cacheFile);
    
    msg = "FGx airportsdata reload: Scanning apt.dat.gz in " + mainObject->X->fgroot() + "/Airports/apt.dat.gz";
    outLog(msg);
    airports = getAirportNameMap(mainObject);

    //================================================
    //* Lets Loop the directories
    //* Get out aiports path from setings and get the the subdir also
    QDirIterator loopAirportsFiles( mainObject->X->airports_path(), QDirIterator::Subdirectories );
    QString xFileName;

    msg = "FGx airportsdata reload: Scanning XML files in "+mainObject->X->airports_path();
    outLog(msg);
    progress.setWindowTitle(msg);
    progress.setRange(0, 50000);

    // Check the fgfs additional argument list,
    // and/or any additional scenery path inputs
    // *** take care NOT to duplicate ***
    QStringList fgfs_args = mainObject->X->get_fgfs_args();
    int i, ind;
    QDir d;
    QString path;
#ifdef Q_OS_WIN
    QChar psep(';');
#else
    QChar psep(':');
#endif
	
    // AIIIIII, found the doubler !, said yves very very loud - well done said pete ;-)
    for (i = 0; i < fgfs_args.size(); i++) {
        msg = fgfs_args.at(i);
        ind = msg.indexOf(QChar('"'));
        if (ind == 0)
            msg = msg.mid(1,msg.length()-2);
        if (msg.indexOf("--fg-scenery=") == 0) {
            // got a scenery folder to scan
            msg = msg.mid(13);
            ind = msg.indexOf(QChar('"'));
            if (ind == 0)
                msg = msg.mid(1,msg.length()-2);
            QStringList path_list = msg.split(psep);
            int pathnumber = 0;
            for( QStringList::ConstIterator entry = path_list.begin(); entry != path_list.end(); entry++) {
                path = *entry;
				pathnumber = pathnumber + 1;
                if (d.exists(path)) {
                    // we have a PATH to check, but we are ONLY checking 'Airports'
                    if ( !(path.indexOf(QChar('/')) == (path.size()-1)) &&
                         !(path.indexOf(QChar('\\')) == (path.size()-1)) )
                        path.append("/");
                    path.append("Airports"); // XML is only in here
                    if (!d.exists(path))
                        continue;
                    QDirIterator loopFiles( path, QDirIterator::Subdirectories );
                    while (loopFiles.hasNext()) {

                        //= Get file handle if there is one
                        xFileName = loopFiles.next();

                        //= Check if file entry is a *.threshold.xml - cos this is what we want
                        if(xFileName.endsWith(".threshold.xml") ){

                            //= Split out "CODE.threshold.xml" with a "."
                            QFileInfo fileInfoThreshold(xFileName);
                            QString airport_code = fileInfoThreshold.fileName().split(".").at(0);

                            //* Update progress
                            if(c % 100 == 0){
                                progress.setValue(c);
                                progress.setLabelText(xFileName);
                                progress.repaint();
                            }

                            QString airport_name("");
                            if(airports.contains(airport_code)){
                                airport_name = airports.value(airport_code);
                            }

                            QStringList cols; // missing in middle is description ??
                            cols << airport_code << airport_name << fileInfoThreshold.absoluteDir().absolutePath() << QString::number(pathnumber);

                            out << cols.join("\t").append("\n");
                            air_added++;

                            found++;
                        }

                        if(progress.wasCanceled()){
                            progress.hide();
                            return true;
                        }
                        c++;
                    }
                }
            }
        }
    }


    cacheFile.close();

    msg.sprintf("*** FGx airportsdata reload: Walked %d files, found %d threshold.xml, appended %d to cache",
                c, found, air_added);
    outLog(msg+", in "+getElapTimeStg(tm.elapsed()));
    progress.hide();
    return false;
}
Exemple #4
0
bool AircraftData::import(QProgressDialog &progress, MainObject *mainObject){

	int c = 0;
	int found = 0;

	progress.setRange(0, 2000);
	progress.setWindowTitle("Scanning Aircraft Directories");
	progress.show();
	progress.repaint();

	//= Cache File
	QFile cacheFile( mainObject->data_file("aircraft.txt") );
	if(!cacheFile.open(QIODevice::WriteOnly | QIODevice::Text)){
		//qDebug() << "TODO Open error cachce file=";
		return true;
	}



	QTextStream out(&cacheFile);

	//= Get files Entries from Aircaft/ directory
	QDir aircraftDir( mainObject->X->aircraft_path() );
	aircraftDir.setFilter( QDir::Dirs | QDir::NoSymLinks | QDir::NoDotAndDotDot);

	QStringList entries = aircraftDir.entryList();
	progress.setRange(0, entries.size() + 20);

	for( QStringList::ConstIterator entry=entries.begin(); entry!=entries.end(); ++entry ){

		// Filter out default dir names, should be a QDir name filter?
		if (*entry != "Instruments" &&  *entry != "Instruments-3d" && *entry != "Generic") {

			progress.setValue(c);
			progress.setLabelText(*entry);
			progress.repaint();

			//** get the List of *-set.xml files in dir
			QDir dir( mainObject->X->aircraft_path(*entry) );
			QStringList filters;
			filters << "*-set.xml";
			QStringList list_xml = dir.entryList(filters);

			if(list_xml.count() > 0){ // << Scan MOdels
				QString directory;
				QString description;
				QString author;
				QString fdm;
				QString xml_file;
				QString aero;

				//** Add Path Node
				directory = QString(*entry);
				//** Add Models
				for (int i = 0; i < list_xml.size(); ++i){

					xml_file = QString(list_xml.at(i));
					aero = QString(xml_file);
					aero.chop(8);

					//*=parse the Xml file - f&*& long winded
					QString file_path =  mainObject->X->aircraft_path(*entry);
					file_path.append("/");
					file_path.append(list_xml.at(i));
					QFile xmlFile( file_path);
					if (xmlFile.open(QIODevice::ReadOnly | QIODevice::Text)){

						/* The file content is converted to UTF-8.
							 Some files are Windows, encoding and throw error with QxmlQuery etc
							 Its a hack and don't quite understand whats happening.. said pedro
						*/
						QString xmlString = QString(xmlFile.readAll()).toUtf8();

						QXmlQuery query;
						query.setFocus(xmlString);
						//query.setFocus(&xmlFile); << Because file is not QTF8 using sting instead
						query.setQuery("PropertyList/sim");
						if (query.isValid()){

							QString res;
							query.evaluateTo(&res);
							xmlFile.close();

							QDomDocument dom;
							dom.setContent("" + res + "");
							QDomNodeList nodes = dom.elementsByTagName("sim");

							QDomNode n = nodes.at(0);
							description = n.firstChildElement("description").text();
							author = n.firstChildElement("author").text().trimmed().replace(("\n"),"");
							fdm = n.firstChildElement("flight-model").text();
						} /* !query.isValid() */
					} /*  xmlFile.open() */

					QStringList lines;
					lines  << directory << aero << xml_file << description << fdm << author << file_path;
					out << lines.join("\t") << "\n";

					found++;

					if(progress.wasCanceled()){
						//qDebug() << "Progress cancelled!";
						progress.hide();
						return true;
					}
					c++;
				}

			} /* list_xml.count() > 0 */
		} /* entry != INstruments etc */
	} /* loop entries.() */

	cacheFile.close();
	return false;
}
void MountainViewWidget::slot_cross_correlograms(int k0)
{
    QWidgetList widgets=qApp->allWidgets();
    foreach (QWidget *widget,widgets) {
        if (widget->property("slot_cross_correlograms").toBool()) {
            int kk=widget->property("slot_cross_correlograms_k0").toInt();
            if (kk==k0) {
                widget->raise();
                return;
            }
        }
    }

    if (d->m_cross_correlograms_path.isEmpty()) {
        QMessageBox::information(this,"Unable to open cross-correlograms view","There was a problem opening the cross-correlograms view (empty path).");
        return;
    }
    DiskReadMda X;
    X.setPath(d->m_cross_correlograms_path);

    int K=d->m_templates.N3();
    int num_rows=(int)sqrt(K); if (num_rows<1) num_rows=1;
    int num_cols=(K+num_rows-1)/num_rows;

    QProgressDialog dlg;
    dlg.show();
    dlg.setLabelText("Loading cross correlograms...");
    dlg.repaint(); qApp->processEvents();
    QList<FloatList> data0=get_cross_correlogram_datas(X,k0,K);

    QWidget *W=new QWidget;
    W->setAttribute(Qt::WA_DeleteOnClose);
    QGridLayout *GL=new QGridLayout;
    W->setLayout(GL);

    for (int k1=1; k1<=K; k1++) {
        HistogramView *HV=new HistogramView;
        HV->setData(data0[k1]);
        HV->autoSetBins(50);
        int k2=k1; if (k0>=1) k2=k0;
        QString title0=QString("%1/%2").arg(k1).arg(k2);
        HV->setTitle(title0);
        GL->addWidget(HV,(k1-1)/num_cols,(k1-1)%num_cols);
        HV->setProperty("cross-correlogram-k",k1);
        connect(HV,SIGNAL(clicked()),this,SLOT(slot_cross_correlogram_clicked()));
    }
    W->show();
	//int W0=num_rows*150; if (W0>1500) W0=1500;
	//int H0=num_cols*150; if (H0>1500) H0=1500;
	int W0=1500,H0=1500;
    W->resize(W0,H0);
    if (k0==0) {
        W->move(this->topLevelWidget()->geometry().topRight()+QPoint(300,-100));
    }
    else {
        W->move(this->topLevelWidget()->geometry().bottomLeft()+QPoint(100,100));
    }

    if (k0==0) {
        W->setWindowTitle("Cross-Correlograms (Diagonal)");
    }
    else {
        W->setWindowTitle(QString("Cross-Correlograms (Neuron %1)").arg(k0));
    }

    W->setProperty("slot_cross_correlograms",true);
    W->setProperty("slot_cross_correlograms_k0",k0);
}