void test01(){ // Prepare the vector. QVector<int> vector; for (int i = 0; i < iterations; ++i) vector.append(i); // Create a progress dialog. QProgressDialog dialog; dialog.setLabelText(QString("Progressing using %1 thread(s)...").arg(QThread::idealThreadCount())); // Create a QFutureWatcher and connect signals and slots. QFutureWatcher<void> futureWatcher; QObject::connect(&futureWatcher, SIGNAL(finished()), &dialog, SLOT(reset())); QObject::connect(&dialog, SIGNAL(canceled()), &futureWatcher, SLOT(cancel())); QObject::connect(&futureWatcher, SIGNAL(progressRangeChanged(int,int)), &dialog, SLOT(setRange(int,int))); QObject::connect(&futureWatcher, SIGNAL(progressValueChanged(int)), &dialog, SLOT(setValue(int))); // Start the computation. futureWatcher.setFuture(QtConcurrent::map(vector, spin)); // Display the dialog and start the event loop. dialog.exec(); futureWatcher.waitForFinished(); // Query the future to check if was canceled. qDebug() << "Canceled?" << futureWatcher.future().isCanceled(); }
sqlqueryresultlist searchhandler::perform_grep(QString searchtxt, sqlqueryresultlist searchlist, bool exactmatch) { QVector<QString> strvec; sqlqueryresultlist resultlist; QFutureWatcher<sqlqueryresultlist> futureWatcher; QProgressDialog dialog; unsigned int n = searchlist.resultlist.size(); if (n == 0) return resultlist; strvec.resize(n); for (unsigned int i=0; i < n; i++) { strvec.replace(i, str2qt(searchlist.resultlist[i].filepath)); } dialog.setAutoReset(false); dialog.setLabelText(QString("Grep ").append(QString(tr("in progress"))).append(QString(" ..."))); dialog.setCancelButtonText(tr("Cancel")); QObject::connect(&futureWatcher, SIGNAL(finished()), &dialog, SLOT(reset())); QObject::connect(&dialog, SIGNAL(canceled()), &futureWatcher, SLOT(cancel())); QObject::connect(&futureWatcher, SIGNAL(progressRangeChanged(int,int)), &dialog, SLOT(setRange(int,int))); QObject::connect(&futureWatcher, SIGNAL(progressValueChanged(int)), &dialog, SLOT(setValue(int))); m_grepExactMatch = exactmatch; (*m_grepRegExp) = QRegExp(searchtxt.toAscii().data(), Qt::CaseInsensitive); m_grepRegExp->setPatternSyntax(QRegExp::RegExp2); futureWatcher.setFuture(QtConcurrent::mappedReduced(strvec, doGrep, collateGrep, QtConcurrent::SequentialReduce)); dialog.exec(); futureWatcher.waitForFinished(); if (futureWatcher.isCanceled() == false) resultlist = futureWatcher.result(); return resultlist; }
void UIMemoryEditor::on_pbSearchMemory_clicked() { UIMemorySearch memorySearch( this ); if (searchStartAddress == 0 && searchEndAddress == 0) { UIHexEditorWnd *hexEditorWnd=(UIHexEditorWnd *)saMemoryEditor->currentWidget(); searchStartAddress = hexEditorWnd->getStartAddress(); searchEndAddress = hexEditorWnd->getEndAddress(); } memorySearch.setParameters(searchType, searchString, searchStartAddress, searchEndAddress); if (memorySearch.exec() == QDialog::Accepted) { MemorySearch search( &memorySearch ); QProgressDialog progress; progress.setLabelText("Searching memory..."); connect(&search, SIGNAL(searchResult(bool, bool, u32)), this, SLOT(searchResult(bool, bool, u32))); connect(this, SIGNAL(killProgressDialog()), &progress, SLOT(accept())); connect(&progress, SIGNAL(canceled()), &search, SLOT(cancel())); connect(&search, SIGNAL(setBarValue(int)), &progress, SLOT(setValue(int))); connect(&search, SIGNAL(setBarRange(int, int)), &progress, SLOT(setRange(int, int))); search.start(); progress.exec(); }
void MainWindow::LoadFile() { if (FileFormatPluginList.size()) { QString FileName = QFileDialog::getOpenFileName(this, tr("Open File"), "", FileFormatPluginList[0]->getFormatDescription()); //test(); // Create a progress dialog. QProgressDialog dialog; dialog.setLabelText(QString("Загрузка данных из файла")); // Create a QFutureWatcher and connect signals and slots. QFutureWatcher<void> futureWatcher; QTimer timer; connect(&timer, SIGNAL(timeout()), this, SLOT(updateProgress())); timer.start(1000); QObject::connect(&futureWatcher, SIGNAL(finished()), &dialog, SLOT(reset())); QObject::connect(&dialog, SIGNAL(canceled()), SLOT(cancelOperation())); QObject::connect(&dialog, SIGNAL(canceled()), &futureWatcher, SLOT(cancel())); QObject::connect(this, SIGNAL(progressValueChanged(int)), &dialog, SLOT(setValue(int))); //extern void FileFormatPluginList[0]->getDataFromChannel(channel,(qint8*)data); QFuture<void> future = QtConcurrent::run(FileFormatPluginList[0], &FileReadInterface::LoadFile, FileName); // Start the computation. futureWatcher.setFuture(future); // Display the dialog and start the event loop. dialog.exec(); futureWatcher.waitForFinished(); dialog.setValue(100); dialog.hide(); timer.stop(); cube= FileFormatPluginList[0]->getCube(); QList<double> list = cube->GetListOfChannels(); foreach(double l , list) { ui->ChannelListWidget->addItem(QString("%1").arg(l)); }
void MainWindow::OnImportNANDBackup() { auto response = QMessageBox::question( this, tr("Question"), tr("Merging a new NAND over your currently selected NAND will overwrite any channels " "and savegames that already exist. This process is not reversible, so it is " "recommended that you keep backups of both NANDs. Are you sure you want to " "continue?")); if (response == QMessageBox::No) return; QString file = QFileDialog::getOpenFileName(this, tr("Select the save file"), QDir::currentPath(), tr("BootMii NAND backup file (*.bin);;" "All Files (*)")); if (file.isEmpty()) return; QProgressDialog* dialog = new QProgressDialog(this); dialog->setMinimum(0); dialog->setMaximum(0); dialog->setLabelText(tr("Importing NAND backup")); dialog->setCancelButton(nullptr); auto beginning = QDateTime::currentDateTime().toMSecsSinceEpoch(); auto result = std::async(std::launch::async, [&] { DiscIO::NANDImporter().ImportNANDBin( file.toStdString(), [&dialog, beginning] { QueueOnObject(dialog, [&dialog, beginning] { dialog->setLabelText( tr("Importing NAND backup\n Time elapsed: %1s") .arg((QDateTime::currentDateTime().toMSecsSinceEpoch() - beginning) / 1000)); }); }, [this] { return RunOnObject(this, [this] { return QFileDialog::getOpenFileName(this, tr("Select the keys file (OTP/SEEPROM dump)"), QDir::currentPath(), tr("BootMii keys file (*.bin);;" "All Files (*)")) .toStdString(); }); }); QueueOnObject(dialog, &QProgressDialog::close); }); dialog->exec(); result.wait(); m_menu_bar->UpdateToolsMenu(Core::IsRunning()); }
void DatabaseWidget::readCsvBase(QString openFilename) { // QString currTime=QDateTime::currentDateTime().toString("dd.MM.yyyy hh:mm:ss.zzz"); // qDebug().noquote() << "readCsvBase BEGIN" // << currTime // << this->thread()->currentThreadId(); emit toDebug(objectName(), QString("Открывается файл '%1'.").arg(openFilename)); QString name = QFileInfo(openFilename).fileName(); if(!QFileInfo(openFilename).exists()) { emit toDebug(objectName(), QString("Файл '%1' не найден").arg(openFilename)); return; } QProgressDialog *dialog = new QProgressDialog; dialog->setWindowTitle(trUtf8("Обработка базы (1/3)")); dialog->setLabelText(trUtf8("Открывается файл \"%1\". \nОжидайте ...") .arg(name)); dialog->setCancelButtonText(trUtf8("Отмена")); QObject::connect(dialog, SIGNAL(canceled()), &_futureWatcher, SLOT(cancel())); QObject::connect(&_futureWatcher, SIGNAL(progressRangeChanged(int,int)), dialog, SLOT(setRange(int,int))); QObject::connect(&_futureWatcher, SIGNAL(progressValueChanged(int)), dialog, SLOT(setValue(int))); QObject::connect(&_futureWatcher, SIGNAL(finished()), dialog, SLOT(deleteLater())); QObject::connect(&_futureWatcher, SIGNAL(finished()), dialog, SLOT(hide())); QFuture<ListAddress> f1 = QtConcurrent::run( readFile, openFilename, MAX_OPEN_ROWS); // Start the computation. _futureWatcher.setFuture(f1); dialog->exec(); // currTime=QDateTime::currentDateTime().toString("dd.MM.yyyy hh:mm:ss.zzz"); // qDebug().noquote() << "readCsvBase END" // << currTime // << this->thread()->currentThreadId(); }
void DatabaseWidget::onProcessOfOpenFinished() { if(_futureWatcher.isFinished() && !_futureWatcher.isCanceled()) { _paddr.reset(new ListAddress(_futureWatcher.future().result())); emit toDebug(objectName(), QString("Открытие файла успешно завершено. Прочитано строк = %1") .arg(_paddr.data()->size())); if(!_paddr.data()->isEmpty()) { // QString currTime=QDateTime::currentDateTime().toString("dd.MM.yyyy hh:mm:ss.zzz"); // qDebug().noquote() << "onProcessOfOpenFinished BEGIN" // << currTime // << this->thread()->currentThreadId(); emit toDebug(objectName(), QString("Начало обработки прочитанной базы.")); QProgressDialog *dialog = new QProgressDialog; dialog->setWindowTitle(trUtf8("Обработка базы (2/3)")); dialog->setLabelText(trUtf8("Обрабатывается файл. Строк: \"%1\". \nОжидайте ...") .arg(_paddr.data()->size())); dialog->setCancelButtonText(trUtf8("Отмена")); QObject::connect(dialog, SIGNAL(canceled()), &_futureWatcherParser, SLOT(cancel())); QObject::connect(&_futureWatcherParser, SIGNAL(progressRangeChanged(int,int)), dialog, SLOT(setRange(int,int))); QObject::connect(&_futureWatcherParser, SIGNAL(progressValueChanged(int)), dialog, SLOT(setValue(int))); QObject::connect(&_futureWatcherParser, SIGNAL(finished()), dialog, SLOT(deleteLater())); QFuture<void> f1 = QtConcurrent::map(*_paddr, parsingAddress ); // Start the computation. _futureWatcherParser.setFuture(f1); dialog->exec(); // currTime=QDateTime::currentDateTime().toString("dd.MM.yyyy hh:mm:ss.zzz"); // qDebug().noquote() << "onProcessOfOpenFinished END" // << currTime // << this->thread()->currentThreadId(); }
int main(int argc, char **argv) { QApplication app(argc, argv); QVector<int> vector; for (int i=0; i<iterations; ++i) vector.append(i); QProgressDialog dialog; dialog.setLabelText(QString("Progressing using %1 thraed(s)...").arg(QThread::idealThreadCount())); QFutureWatcher<void> futureWatcher; QObject::connect(&futureWatcher, SIGNAL(finished()), &dialog, SLOT(reset())); QObject::connect(&dialog, SIGNAL(canceled()), &futureWatcher, SLOT(cancel())); QObject::connect(&futureWatcher, SIGNAL(progressRangeChanged(int, int)), &dialog, SLOT(setRange(int, int))); QObject::connect(&futureWatcher, SIGNAL(progressValueChanged(int)), &dialog, SLOT(setValue(int))); futureWatcher.setFuture(QtConcurrent::map(vector, spin)); dialog.exec(); futureWatcher.waitForFinished(); qDebug() << "Canceled ?" << futureWatcher.future().isCanceled(); }
void MainWindow::launchInstance(InstancePtr instance, AuthSessionPtr session, BaseProfilerFactory *profiler) { Q_ASSERT_X(instance != NULL, "launchInstance", "instance is NULL"); Q_ASSERT_X(session.get() != nullptr, "launchInstance", "session is NULL"); QString launchScript; if(!instance->prepareForLaunch(session, launchScript)) return; MinecraftProcess *proc = new MinecraftProcess(instance); proc->setLaunchScript(launchScript); proc->setWorkdir(instance->minecraftRoot()); this->hide(); console = new ConsoleWindow(proc); connect(console, SIGNAL(isClosing()), this, SLOT(instanceEnded())); proc->setLogin(session); proc->arm(); if (profiler) { QString error; if (!profiler->check(&error)) { QMessageBox::critical(this, tr("Error"), tr("Couldn't start profiler: %1").arg(error)); proc->abort(); return; } BaseProfiler *profilerInstance = profiler->createProfiler(instance, this); QProgressDialog dialog; dialog.setMinimum(0); dialog.setMaximum(0); dialog.setValue(0); dialog.setLabelText(tr("Waiting for profiler...")); connect(&dialog, &QProgressDialog::canceled, profilerInstance, &BaseProfiler::abortProfiling); dialog.show(); connect(profilerInstance, &BaseProfiler::readyToLaunch, [&dialog, this, proc](const QString &message) { dialog.accept(); QMessageBox msg; msg.setText(tr("The launch of Minecraft itself is delayed until you press the " "button. This is the right time to setup the profiler, as the " "profiler server is running now.\n\n%1").arg(message)); msg.setWindowTitle(tr("Waiting")); msg.setIcon(QMessageBox::Information); msg.addButton(tr("Launch"), QMessageBox::AcceptRole); msg.exec(); proc->launch(); }); connect(profilerInstance, &BaseProfiler::abortLaunch, [&dialog, this, proc](const QString &message) { dialog.accept(); QMessageBox msg; msg.setText(tr("Couldn't start the profiler: %1").arg(message)); msg.setWindowTitle(tr("Error")); msg.setIcon(QMessageBox::Critical); msg.addButton(QMessageBox::Ok); msg.exec(); proc->abort(); }); profilerInstance->beginProfiling(proc); dialog.exec(); } else { proc->launch(); } }
/* * Fun flux analysis */ void FluxAnalysis::RunFluxAnalysis( QString nodeURL, QString surfaceSide, unsigned long nOfRays, bool increasePhotonMap, int heightDivisions, int widthDivisions ) { m_surfaceURL = nodeURL; m_surfaceSide = surfaceSide; //Delete a photonCounts if( m_photonCounts && m_photonCounts != 0 ) { for( int h = 0; h < m_heightDivisions; h++ ) { delete[] m_photonCounts[h]; } delete[] m_photonCounts; } m_photonCounts = 0; m_heightDivisions = heightDivisions; m_widthDivisions = widthDivisions; //Check if there is a scene if ( !m_pCurrentScene ) return; //Check if there is a transmissivity defined TTransmissivity* transmissivity = 0; if ( !m_pCurrentScene->getPart( "transmissivity", false ) ) transmissivity = 0; else transmissivity = static_cast< TTransmissivity* > ( m_pCurrentScene->getPart( "transmissivity", false ) ); //Check if there is a rootSeparator InstanceNode if( !m_pRootSeparatorInstance ) return; InstanceNode* sceneInstance = m_pRootSeparatorInstance->GetParent(); if ( !sceneInstance ) return; //Check if there is a light and is properly configured if ( !m_pCurrentScene->getPart( "lightList[0]", false ) )return; TLightKit* lightKit = static_cast< TLightKit* >( m_pCurrentScene->getPart( "lightList[0]", false ) ); InstanceNode* lightInstance = sceneInstance->children[0]; if ( !lightInstance ) return; if( !lightKit->getPart( "tsunshape", false ) ) return; TSunShape* sunShape = static_cast< TSunShape * >( lightKit->getPart( "tsunshape", false ) ); if( !lightKit->getPart( "icon", false ) ) return; TLightShape* raycastingSurface = static_cast< TLightShape * >( lightKit->getPart( "icon", false ) ); if( !lightKit->getPart( "transform" ,false ) ) return; SoTransform* lightTransform = static_cast< SoTransform * >( lightKit->getPart( "transform" ,false ) ); //Check if there is a random generator is defined. if( !m_pRandomDeviate || m_pRandomDeviate== 0 ) return; //Check if the surface and the surface side defined is suitable if( CheckSurface() == false || CheckSurfaceSide() == false ) return; //Create the photon map where photons are going to be stored if( !m_pPhotonMap || !increasePhotonMap ) { if( m_pPhotonMap ) m_pPhotonMap->EndStore( -1 ); delete m_pPhotonMap; m_pPhotonMap = new TPhotonMap(); m_pPhotonMap->SetBufferSize( HUGE_VAL ); m_tracedRays = 0; m_wPhoton = 0; m_totalPower = 0; } QVector< InstanceNode* > exportSuraceList; QModelIndex nodeIndex = m_pCurrentSceneModel->IndexFromNodeUrl( m_surfaceURL ); if( !nodeIndex.isValid() ) return; InstanceNode* surfaceNode = m_pCurrentSceneModel->NodeFromIndex( nodeIndex ); if( !surfaceNode || surfaceNode == 0 ) return; exportSuraceList.push_back( surfaceNode ); //UpdateLightSize(); TSeparatorKit* concentratorRoot = static_cast< TSeparatorKit* >( m_pCurrentScene->getPart( "childList[0]", false ) ); if ( !concentratorRoot ) return; SoGetBoundingBoxAction* bbAction = new SoGetBoundingBoxAction( SbViewportRegion() ) ; concentratorRoot->getBoundingBox( bbAction ); SbBox3f box = bbAction->getXfBoundingBox().project(); delete bbAction; bbAction = 0; BBox sceneBox; if( !box.isEmpty() ) { sceneBox.pMin = Point3D( box.getMin()[0], box.getMin()[1], box.getMin()[2] ); sceneBox.pMax = Point3D( box.getMax()[0], box.getMax()[1], box.getMax()[2] ); if( lightKit ) lightKit->Update( sceneBox ); } m_pCurrentSceneModel->UpdateSceneModel(); //Compute bounding boxes and world to object transforms trf::ComputeSceneTreeMap( m_pRootSeparatorInstance, Transform( new Matrix4x4 ), true ); m_pPhotonMap->SetConcentratorToWorld( m_pRootSeparatorInstance->GetIntersectionTransform() ); QStringList disabledNodes = QString( lightKit->disabledNodes.getValue().getString() ).split( ";", QString::SkipEmptyParts ); QVector< QPair< TShapeKit*, Transform > > surfacesList; trf::ComputeFistStageSurfaceList( m_pRootSeparatorInstance, disabledNodes, &surfacesList ); lightKit->ComputeLightSourceArea( m_sunWidthDivisions, m_sunHeightDivisions, surfacesList ); if( surfacesList.count() < 1 ) return; QVector< long > raysPerThread; int maximumValueProgressScale = 100; unsigned long t1 = nOfRays/ maximumValueProgressScale; for( int progressCount = 0; progressCount < maximumValueProgressScale; ++ progressCount ) raysPerThread<< t1; if( ( t1 * maximumValueProgressScale ) < nOfRays ) raysPerThread<< ( nOfRays - ( t1* maximumValueProgressScale) ); Transform lightToWorld = tgf::TransformFromSoTransform( lightTransform ); lightInstance->SetIntersectionTransform( lightToWorld.GetInverse() ); // Create a progress dialog. QProgressDialog dialog; dialog.setLabelText( QString("Progressing using %1 thread(s)..." ).arg( QThread::idealThreadCount() ) ); // Create a QFutureWatcher and conncect signals and slots. QFutureWatcher< void > futureWatcher; QObject::connect(&futureWatcher, SIGNAL(finished()), &dialog, SLOT(reset())); QObject::connect(&dialog, SIGNAL(canceled()), &futureWatcher, SLOT(cancel())); QObject::connect(&futureWatcher, SIGNAL(progressRangeChanged(int, int)), &dialog, SLOT(setRange(int, int))); QObject::connect(&futureWatcher, SIGNAL(progressValueChanged(int)), &dialog, SLOT(setValue(int))); QMutex mutex; QMutex mutexPhotonMap; QFuture< void > photonMap; if( transmissivity ) photonMap = QtConcurrent::map( raysPerThread, RayTracer( m_pRootSeparatorInstance, lightInstance, raycastingSurface, sunShape, lightToWorld, transmissivity, *m_pRandomDeviate, &mutex, m_pPhotonMap, &mutexPhotonMap, exportSuraceList ) ); else photonMap = QtConcurrent::map( raysPerThread, RayTracerNoTr( m_pRootSeparatorInstance, lightInstance, raycastingSurface, sunShape, lightToWorld, *m_pRandomDeviate, &mutex, m_pPhotonMap, &mutexPhotonMap, exportSuraceList ) ); futureWatcher.setFuture( photonMap ); // Display the dialog and start the event loop. dialog.exec(); futureWatcher.waitForFinished(); m_tracedRays += nOfRays; double irradiance = sunShape->GetIrradiance(); double inputAperture = raycastingSurface->GetValidArea(); m_wPhoton = double ( inputAperture * irradiance ) / m_tracedRays; UpdatePhotonCounts(); }
void QTAIMCriticalPointLocator::locateElectronDensitySinks() { QString temporaryFileName=QTAIMCriticalPointLocator::temporaryFileName(); QList<QList<QVariant> > inputList; qreal xmin,ymin,zmin; qreal xmax,ymax,zmax; qreal xstep,ystep,zstep; // TODO: if only we were using Eigen data structures... QList<qreal> xNuclearCoordinates; QList<qreal> yNuclearCoordinates; QList<qreal> zNuclearCoordinates; for( qint64 i=0; i < m_wfn->numberOfNuclei() ; ++i ) { xNuclearCoordinates.append( m_wfn->xNuclearCoordinate(i) ); yNuclearCoordinates.append( m_wfn->yNuclearCoordinate(i) ); zNuclearCoordinates.append( m_wfn->zNuclearCoordinate(i) ); } xmin=xNuclearCoordinates.first(); xmax=xNuclearCoordinates.first(); for( qint64 i=1 ; i < m_wfn->numberOfNuclei() ; ++i) { if( xNuclearCoordinates.at(i) < xmin ) { xmin=xNuclearCoordinates.at(i); } if( xNuclearCoordinates.at(i) > xmax ) { xmax=xNuclearCoordinates.at(i); } } ymin=yNuclearCoordinates.first(); ymax=yNuclearCoordinates.first(); for( qint64 i=1 ; i < yNuclearCoordinates.count() ; ++i) { if( yNuclearCoordinates.at(i) < ymin ) { ymin=yNuclearCoordinates.at(i); } if( yNuclearCoordinates.at(i) > ymax ) { ymax=yNuclearCoordinates.at(i); } } zmin=zNuclearCoordinates.first(); zmax=zNuclearCoordinates.first(); for( qint64 i=1 ; i < zNuclearCoordinates.count() ; ++i) { if( zNuclearCoordinates.at(i) < zmin ) { zmin=zNuclearCoordinates.at(i); } if( zNuclearCoordinates.at(i) > zmax ) { zmax=zNuclearCoordinates.at(i); } } xmin= -2.0 + xmin; ymin= -2.0 + ymin; zmin= -2.0 + zmin; xmax = 2.0 + xmax; ymax = 2.0 + ymax; zmax = 2.0 + zmax; xstep=ystep=zstep= 0.5; for( qreal x=xmin ; x < xmax+xstep ; x=x+xstep) { for( qreal y=ymin ; y < ymax+ystep ; y=y+ystep) { for( qreal z=zmin ; z < zmax+zstep ; z=z+zstep) { QList<QVariant> input; input.append( temporaryFileName ); // input.append( n ); input.append( x ); input.append( y ); input.append( z ); inputList.append(input); } } } m_wfn->saveToBinaryFile(temporaryFileName); QProgressDialog dialog; dialog.setWindowTitle("QTAIM"); dialog.setLabelText(QString("Electron Density Sinks Search")); QFutureWatcher<void> futureWatcher; QObject::connect(&futureWatcher, SIGNAL(finished()), &dialog, SLOT(reset())); QObject::connect(&dialog, SIGNAL(canceled()), &futureWatcher, SLOT(cancel())); QObject::connect(&futureWatcher, SIGNAL(progressRangeChanged(int,int)), &dialog, SLOT(setRange(int,int))); QObject::connect(&futureWatcher, SIGNAL(progressValueChanged(int)), &dialog, SLOT(setValue(int))); QFuture<QList<QVariant> > future=QtConcurrent::mapped(inputList, QTAIMLocateElectronDensitySink ); futureWatcher.setFuture(future); dialog.exec(); futureWatcher.waitForFinished(); QList<QList<QVariant> > results; if( futureWatcher.future().isCanceled() ) { results.clear(); } else { results=future.results(); } QFile file; file.remove(temporaryFileName); for( qint64 n=0 ; n < results.length() ; ++n ) { qint64 counter=0; bool correctSignature = results.at(n).at(counter).toBool(); counter++; if( correctSignature ) { qreal x=results.at(n).at(counter).toReal(); counter++; qreal y=results.at(n).at(counter).toReal(); counter++; qreal z=results.at(n).at(counter).toReal(); counter++; if( (xmin < x && x < xmax) && (ymin < y && y < ymax) && (zmin < z && z < zmax) ) { QVector3D result(x,y,z); qreal smallestDistance=HUGE_REAL_NUMBER; for(qint64 i=0 ; i < m_electronDensitySinks.length() ; ++i ) { Matrix<qreal,3,1> a(x,y,z); Matrix<qreal,3,1> b(m_electronDensitySinks.at(i).x(), m_electronDensitySinks.at(i).y(), m_electronDensitySinks.at(i).z()); qreal distance=QTAIMMathUtilities::distance(a,b); if( distance < smallestDistance ) { smallestDistance=distance; } } if( smallestDistance > 1.e-2 ) { m_electronDensitySinks.append( result ); } } } } // qDebug() << "SINKS" << m_electronDensitySinks; }
void QTAIMCriticalPointLocator::locateBondCriticalPoints() { if( m_nuclearCriticalPoints.length() < 1 ) { return; } const qint64 numberOfNuclei = m_wfn->numberOfNuclei(); if( numberOfNuclei < 2) { return; } QString temporaryFileName=QTAIMCriticalPointLocator::temporaryFileName(); QString nuclearCriticalPointsFileName=QTAIMCriticalPointLocator::temporaryFileName(); QFile nuclearCriticalPointsFile(nuclearCriticalPointsFileName); nuclearCriticalPointsFile.open(QIODevice::WriteOnly); QDataStream nuclearCriticalPointsOut(&nuclearCriticalPointsFile); nuclearCriticalPointsOut << m_nuclearCriticalPoints; nuclearCriticalPointsFile.close(); QList<QList<QVariant> > inputList; for( qint64 M=0 ; M < numberOfNuclei - 1 ; ++M ) { for( qint64 N=M+1 ; N < numberOfNuclei ; ++N ) { const qreal distanceCutoff = 8.0 ; Matrix<qreal,3,1> a; Matrix<qreal,3,1> b; a << m_wfn->xNuclearCoordinate(M), m_wfn->yNuclearCoordinate(M), m_wfn->zNuclearCoordinate(M) ; b << m_wfn->xNuclearCoordinate(N), m_wfn->yNuclearCoordinate(N), m_wfn->zNuclearCoordinate(N) ; if( QTAIMMathUtilities::distance(a,b) < distanceCutoff ) { QVector3D x0y0z0( ( m_wfn->xNuclearCoordinate(M) + m_wfn->xNuclearCoordinate(N) ) / 2.0 , ( m_wfn->yNuclearCoordinate(M) + m_wfn->yNuclearCoordinate(N) ) / 2.0, ( m_wfn->zNuclearCoordinate(M) + m_wfn->zNuclearCoordinate(N) ) / 2.0 ); QList<QVariant> input; input.append( temporaryFileName ); input.append( nuclearCriticalPointsFileName ); input.append( M ); input.append( N ); input.append( x0y0z0.x() ); input.append( x0y0z0.y() ); input.append( x0y0z0.z() ); inputList.append(input); } } // end N } // end M m_wfn->saveToBinaryFile(temporaryFileName); QProgressDialog dialog; dialog.setWindowTitle("QTAIM"); dialog.setLabelText(QString("Bond Critical Points Search")); QFutureWatcher<void> futureWatcher; QObject::connect(&futureWatcher, SIGNAL(finished()), &dialog, SLOT(reset())); QObject::connect(&dialog, SIGNAL(canceled()), &futureWatcher, SLOT(cancel())); QObject::connect(&futureWatcher, SIGNAL(progressRangeChanged(int,int)), &dialog, SLOT(setRange(int,int))); QObject::connect(&futureWatcher, SIGNAL(progressValueChanged(int)), &dialog, SLOT(setValue(int))); QFuture<QList<QVariant> > future=QtConcurrent::mapped(inputList, QTAIMLocateBondCriticalPoint);; futureWatcher.setFuture(future); dialog.exec(); futureWatcher.waitForFinished(); QList<QList<QVariant> > results; if( futureWatcher.future().isCanceled() ) { results.clear(); } else { results=future.results(); } QFile file; file.remove(temporaryFileName); file.remove(nuclearCriticalPointsFileName); for( qint64 i=0 ; i < results.length() ; ++i ) { QList<QVariant> thisCriticalPoint=results.at(i); bool success=thisCriticalPoint.at(0).toBool(); if(success) { QPair<qint64,qint64> bondedAtoms; bondedAtoms.first=thisCriticalPoint.at(1).toInt(); bondedAtoms.second=thisCriticalPoint.at(2).toInt(); m_bondedAtoms.append( bondedAtoms ); QVector3D coordinates(thisCriticalPoint.at(3).toReal(), thisCriticalPoint.at(4).toReal(), thisCriticalPoint.at(5).toReal()); m_bondCriticalPoints.append( coordinates ); m_laplacianAtBondCriticalPoints.append(thisCriticalPoint.at(6).toReal()); m_ellipticityAtBondCriticalPoints.append(thisCriticalPoint.at(7).toReal()); qint64 pathLength=thisCriticalPoint.at(8).toInt(); QList<QVector3D> bondPath; for( qint64 i=0 ; i < pathLength ; ++i ) { QVector3D pathPoint(thisCriticalPoint.at(9 + i ).toReal(), thisCriticalPoint.at(9 + i + pathLength ).toReal(), thisCriticalPoint.at(9 + i + 2*pathLength ).toReal()); bondPath.append(pathPoint); } m_bondPaths.append(bondPath); } } }
void QTAIMCriticalPointLocator::locateNuclearCriticalPoints() { QString temporaryFileName=QTAIMCriticalPointLocator::temporaryFileName(); QList<QList<QVariant> > inputList; const qint64 numberOfNuclei = m_wfn->numberOfNuclei(); for( qint64 n=0 ; n < numberOfNuclei ; ++n) { QList<QVariant> input; input.append( temporaryFileName ); input.append( n ); input.append( m_wfn->xNuclearCoordinate(n) ); input.append( m_wfn->yNuclearCoordinate(n) ); input.append( m_wfn->zNuclearCoordinate(n) ); inputList.append(input); } m_wfn->saveToBinaryFile(temporaryFileName); QProgressDialog dialog; dialog.setWindowTitle("QTAIM"); dialog.setLabelText(QString("Nuclear Critical Points Search")); QFutureWatcher<void> futureWatcher; QObject::connect(&futureWatcher, SIGNAL(finished()), &dialog, SLOT(reset())); QObject::connect(&dialog, SIGNAL(canceled()), &futureWatcher, SLOT(cancel())); QObject::connect(&futureWatcher, SIGNAL(progressRangeChanged(int,int)), &dialog, SLOT(setRange(int,int))); QObject::connect(&futureWatcher, SIGNAL(progressValueChanged(int)), &dialog, SLOT(setValue(int))); QFuture<QList<QVariant> > future=QtConcurrent::mapped(inputList, QTAIMLocateNuclearCriticalPoint); futureWatcher.setFuture(future); dialog.exec(); futureWatcher.waitForFinished(); QList<QList<QVariant> > results; if( futureWatcher.future().isCanceled() ) { results.clear(); } else { results=future.results(); } QFile file; file.remove(temporaryFileName); for( qint64 n=0 ; n < results.length() ; ++n ) { bool correctSignature = results.at(n).at(0).toBool(); if (correctSignature) { QVector3D result( results.at(n).at(1).toReal(), results.at(n).at(2).toReal(), results.at(n).at(3).toReal() ); m_nuclearCriticalPoints.append( result ); } } }