00001
00042 #include "aithread.hpp"
00043
00044 using namespace AiGenerator;
00045
00046 AiThread::AiThread( QObject * parent )
00047 : QThread( parent ), m_zone(this,0,0,0,0,0,0,0,0,0,0,0,0), m_file()
00048 {
00049 }
00050
00051 void AiThread::makeZone(double x , double y ,
00052 double zoneWidth , double zoneHeight ,
00053 int imageWidth , int imageHeight ,
00054 int startPoint, int increment , int iteration,
00055 double zoom, double viewx, double viewy)
00056 {
00057
00058 m_zone = AiZone(this ,
00059 x, y ,
00060 zoneWidth, zoneHeight ,
00061 imageWidth, imageHeight ,
00062 startPoint, increment ,
00063 iteration,
00064 zoom, viewx, viewy
00065 );
00066 }
00067
00068 void AiThread::start()
00069 {
00070 this->connect( &m_zone, SIGNAL(progressStatus(int)), this, SIGNAL(progressStatus(int)));
00071
00072 qRegisterMetaType<AiGenerator::AiZone*>("AiGenerator::AiZone");
00073 this->connect( &m_zone, SIGNAL(snapshot(AiGenerator::AiZone *)), this, SIGNAL(snapshot(AiGenerator::AiZone *)));
00074 QThread::start(QThread::LowPriority);
00075 }
00076
00077 void AiThread::scriptFile(const QString &file)
00078 {
00079 m_file = file;
00080 }
00081
00082 void AiThread::run()
00083 {
00084 {
00085 QString script;
00086
00087 {
00088 QFile file(m_file);
00089 file.open(QIODevice::ReadOnly);
00090 script = file.readAll();
00091 file.close();
00092 }
00093
00094 QScriptEngine engine;
00095 QScriptValue zone = engine.newQObject( &m_zone );
00096 engine.globalObject().setProperty( "zone" , zone );
00097
00098 engine.evaluate( script );
00099
00100 }
00101 emit completed( &m_zone );
00102 }
00103
00104 void AiThread::stop()
00105 {
00106 m_zone.status = true;
00107 }
00108
00109 AiZone * AiThread::getZone()
00110 {
00111 return &m_zone;
00112 }
00113
00114 void AiThread::setZone(AiZone &zone)
00115 {
00116 m_zone = zone;
00117 }
00118
00119 AiThread::~AiThread()
00120 {
00121
00122 }