void AiMainWindow::deserialize (  )  [private, slot]

deserialize threads (zones) for generator

Definition at line 656 of file aimainwindow.cpp.

00657 {
00658     try
00659     {
00660         //check if threads is running
00661         if( m_threads.size() > 0 )
00662         {
00663             if( m_threads[ 0 ]->isRunning() )
00664             {
00665                 QMessageBox::warning(this, tr("Threads"), tr("Current threads is running, please stop them before running a new deserialization!"), QMessageBox::Ok) ;
00666                 return;
00667             }
00668         }
00669 
00670         if( QMessageBox::Yes != QMessageBox::warning(this, tr("Deserialization...") , tr("Make sure you are choosing right script and composition modes?"), QMessageBox::Yes | QMessageBox::No, QMessageBox::No ) )
00671         {
00672             return;
00673         }
00674 
00675         QString fileName = QFileDialog::getOpenFileName(this, tr("Deserialization..."), "", tr("File (*.adrabi)"));
00676         if( fileName.isNull() || fileName.isEmpty() )
00677         {
00678             return;
00679         }
00680 
00681         //~ Just added for checking
00682         // stoping current threads
00683         for( int index = 0 ; index < m_threads.size() ; index++ )
00684         {
00685             m_threads[ index ]->stop();
00686             m_threads[ index ]->wait();
00687         }
00688         //~ delete them all
00689         for( int index = 0 ; index < m_threads.size() ; index++ )
00690         {
00691             delete m_threads[ index ];
00692         }
00693         m_threads.clear();
00694         //~ Just added for checking
00695 
00696         QFile file( fileName );
00697         file.open(QIODevice::ReadOnly);
00698 
00699         QDataStream stream( &file );
00700         stream.setVersion(QDataStream::Qt_4_6);
00701         QTime time; QDate date;
00702         stream  >> time     // creation time
00703                 >> date     // creation date
00704                 >> m_startedThreads;   // threads count
00705         
00706         //~ start at
00707         this->m_statusbar->start();
00708 
00709         //~ storage
00710         if( m_storage.count() > 0 )
00711         {
00712             m_storage.clear();
00713         }
00714         m_storage = QVector<QImage>( m_startedThreads );
00715 
00716         for( int x = 0 ; x < m_startedThreads ; x++ )
00717         {
00718             AiZone zone (0,0,0,0,0,0,0,0,0,0,0,0,0);
00719             zone.deserialize( stream );  
00720 
00721             //
00722             AiThread * thread = new AiThread( this );
00723             thread->setZone( zone );
00724             thread->scriptFile( "scripts/" + m_config->item( m_selectedFractalIndex ) );
00725 
00726             qRegisterMetaType<AiGenerator::AiZone*>("AiGenerator::AiZone");
00727             this->connect( thread, SIGNAL(completed(AiGenerator::AiZone*)) , this, SLOT(completed(AiGenerator::AiZone*)));
00728             this->connect( thread, SIGNAL(snapshot(AiGenerator::AiZone*)) , this, SLOT(snapshot(AiGenerator::AiZone*)));
00729             //~ for first thread *ONLY*
00730             if( x == 0 )
00731             {
00732                 //# theoretically all threads has started in one time,
00733                 //# with very small deference : T0:0 nanos T1:~+1ns etc...
00734                 //# if first thread is finish all threads finished in one time
00735                 this->connect(thread,SIGNAL(progressStatus(int)), m_statusbar, SLOT(setGenStatus(int)));
00736                 m_zoom = zone.getZoom();
00737                 m_viewX= zone.getViewX();
00738                 m_viewY= zone.getViewY();
00739 
00740                 //~ set old setting
00741                 m_config->setZoneWidth( zone.getZoneWidth() );
00742                 m_config->setZoneHeight( zone.getZoneHeight());
00743                 m_config->setZoneMinX( zone.getX() );
00744                 m_config->setZoneMinY( zone.getY() );
00745                 m_config->setImageWidth( zone.getImageWidth() );
00746                 m_config->setImageHeight( zone.getImageHeight() );
00747                 m_config->setIterations( zone.getIteration() );
00748                 m_config->setThreadsNumber( m_startedThreads );
00749             }
00750 
00751             m_threads.push_back( thread );
00752         }
00753 
00754         for( int x = 0 ; x < m_threads.count() ; x++ )
00755         {
00756             m_threads[ x ]->start();
00757         }
00758 
00759         m_statusbar->startGenerating();
00760         m_statusbar->setInfo(  QString( "[Threads: %1 ]"  ).arg( m_startedThreads ) );
00761 
00762         //# for supporting users *BAD* manipulation =)
00763         this->enabledChilds( false );
00764         this->toolsZoomArea( false );
00765         m_config->disableZoomArea();
00766         //# for supporting users *BAD* manipulation =)
00767     }
00768     catch(const std::exception & exception )
00769     {
00770         QMessageBox::critical(this, tr("Critical Error!"), tr("Please report this problem to adrabi[at]gmail[dot]com =)."));
00771     }
00772 }

 All Classes Namespaces Files Functions Variables Typedefs

Generated on Sat Feb 27 08:33:16 2010 for AiFractals by  doxygen 1.6.1