Example #1
0
void dataBase::fillFromJson(const QString &path)
{
    QProgressBar bar;
    bar.show();
    QFile file(path);
    if(!file.open(QFile::ReadOnly))
    {
        throw std::runtime_error(("No file "+ path).toStdString());
    }
    bool ok = false;
    QVariantMap map = QtJson::parse(QString::fromUtf8(file.readAll().data()), ok).toMap();
    if(!ok)
    {
        throw std::runtime_error(("Cant parse "+ path).toStdString());
    }
    for(QVariantMap::const_iterator it = map.begin(); it != map.end(); ++it)
    {
        QList<QVariant> list = it.value().toList();
        for(QList<QVariant>::const_iterator list_it = list.begin(); list_it != list.end(); ++list_it)
        {
            bar.setValue(bar.value() >= bar.maximum() ? 0 : bar.value()+1);
            qApp->processEvents();
            QList<QVariant> values = list_it->toList();
            QString q_text = QString("INSERT INTO %1 ( coeff, hrn  ) VALUES ( '%2', '%3' )")
                    .arg(it.key())
                    .arg(values.at(0).toString())
                    .arg(values.at(1).toString());

            query(q_text);
        }
    }
    QList<QVariant> regions = map["regions"].toList();
    for(QList<QVariant>::const_iterator it = regions.begin(); it!= regions.end(); ++it )
    {
        QList<QVariant> towns = it->toList().at(2).toList();
        for(QList<QVariant>::const_iterator town_it = towns.begin(); town_it != towns.end(); ++town_it )
        {
            bar.setValue(bar.value() >= bar.maximum() ? 0 : bar.value()+1);
            qApp->processEvents();
            QList<QVariant> town_desc = town_it->toList();
            QString q_text = QString("INSERT INTO towns VALUES ( %1, '%2', %3, %4, %5)")
                    .arg(town_desc.at(0).toInt())
                    .arg(town_desc.at(1).toString())
                    .arg(town_desc.at(2).toString())
                    .arg(town_desc.at(3).toString())
                    .arg(it->toList().at(0).toInt());
            query(q_text);
        }
    }
    bar.close();
}
void RenderCommand::rasterRender(bool isPreview)
{
	ToonzScene *scene = TApp::instance()->getCurrentScene()->getScene();

	if (isPreview) {
		//Let the PreviewFxManager own the rest. Just pass him the current output node.
		PreviewFxManager::instance()->showNewPreview((TFx *)scene->getXsheet()->getFxDag()->getCurrentOutputFx());
		return;
	}

	string ext = m_fp.getType();

#ifdef WIN32
	if (ext == "avi" && !isPreview) {
		TPropertyGroup *props = scene->getProperties()->getOutputProperties()->getFileFormatProperties(ext);
		string codecName = props->getProperty(0)->getValueAsString();
		TDimension res = scene->getCurrentCamera()->getRes();
		if (!AviCodecRestrictions::canWriteMovie(toWideString(codecName), res)) {
			QString msg(QObject::tr("The resolution of the output camera does not fit with the options chosen for the output file format."));
			MsgBox(WARNING, msg);
			return;
		}
	}
#endif;

	//Extract output properties
	TOutputProperties *prop = isPreview ? scene->getProperties()->getPreviewProperties() : scene->getProperties()->getOutputProperties();

	//Build thread count
	/*-- Dedicated CPUs のコンボボックス (Single, Half, All) --*/
	int index = prop->getThreadIndex();

	const int procCount = TSystem::getProcessorCount();
	const int threadCounts[3] = {1, procCount / 2, procCount};

	int threadCount = threadCounts[index];

	/*-- MovieRendererを作る。Previewの場合はファイルパスは空 --*/
	MovieRenderer movieRenderer(scene, isPreview ? TFilePath() : m_fp, threadCount, isPreview);

	TRenderSettings rs = prop->getRenderSettings();

	//Build raster granularity size
	index = prop->getMaxTileSizeIndex();

	const int maxTileSizes[4] = {
		(std::numeric_limits<int>::max)(),
		TOutputProperties::LargeVal,
		TOutputProperties::MediumVal,
		TOutputProperties::SmallVal};
	rs.m_maxTileSize = maxTileSizes[index];

//Build

#ifdef BRAVODEMO
	rs.m_mark = loadBravo(scene->getCurrentCamera()->getRes());
#endif
	/*-- RenderSettingsをセット --*/
	movieRenderer.setRenderSettings(rs);
	/*-- カメラDPIの取得、セット --*/
	TPointD cameraDpi = isPreview ? scene->getCurrentPreviewCamera()->getDpi() : scene->getCurrentCamera()->getDpi();
	movieRenderer.setDpi(cameraDpi.x, cameraDpi.y);
	movieRenderer.enablePrecomputing(true);

	/*-- プログレス ダイアログの作成 --*/
	RenderListener *listener =
		new RenderListener(movieRenderer.getTRenderer(), m_fp, ((m_numFrames - 1) / m_step) + 1, isPreview);
	QObject::connect(listener, SIGNAL(canceled()), &movieRenderer, SLOT(onCanceled()));
	movieRenderer.addListener(listener);

	bool fieldRendering = rs.m_fieldPrevalence != TRenderSettings::NoField;

	/*-- buildSceneFxの進行状況を表示するプログレスバー --*/
	QProgressBar *buildSceneProgressBar = new QProgressBar(TApp::instance()->getMainWindow());
	buildSceneProgressBar->setAttribute(Qt::WA_DeleteOnClose);
	buildSceneProgressBar->setWindowFlags(Qt::SubWindow | Qt::Dialog | Qt::WindowStaysOnTopHint);
	buildSceneProgressBar->setMinimum(0);
	buildSceneProgressBar->setMaximum(m_numFrames - 1);
	buildSceneProgressBar->setValue(0);
	buildSceneProgressBar->move(600, 500);
	buildSceneProgressBar->setWindowTitle("Building Schematic...");
	buildSceneProgressBar->show();

	for (int i = 0; i < m_numFrames; ++i, m_r += m_stepd) {
		buildSceneProgressBar->setValue(i);

		if (rs.m_stereoscopic)
			scene->shiftCameraX(-rs.m_stereoscopicShift / 2);
		TFxPair fx;
		fx.m_frameA = buildSceneFx(scene, m_r, rs.m_shrinkX, isPreview);

		if (fieldRendering && !isPreview)
			fx.m_frameB = buildSceneFx(scene, m_r + 0.5 / m_timeStretchFactor, rs.m_shrinkX, isPreview);
		else if (rs.m_stereoscopic) {
			scene->shiftCameraX(rs.m_stereoscopicShift);
			fx.m_frameB = buildSceneFx(scene, m_r + 0.5 / m_timeStretchFactor, rs.m_shrinkX, isPreview);
			scene->shiftCameraX(-rs.m_stereoscopicShift / 2);
		} else
			fx.m_frameB = TRasterFxP();
		/*-- movieRendererにフレーム毎のFxを登録 --*/
		movieRenderer.addFrame(m_r, fx);
	}
	/*-- プログレスバーを閉じる --*/
	buildSceneProgressBar->close();

	//resetViewer(); //TODO cancella le immagini dell'eventuale render precedente
	//FileViewerPopupPool::instance()->getCurrent()->onClose();

	movieRenderer.start();
}
Example #3
0
void MetaEditorSupportPlugin::generateEditorWithQrmc()
{
    qrmc::MetaCompiler metaCompiler(*mLogicalRepoApi, ".");

    IdList const metamodels = mLogicalRepoApi->children(Id::rootId());

    QProgressBar *progress = new QProgressBar(mMainWindowInterface->windowWidget());
    progress->show();
    int const progressBarWidth = 240;
    int const progressBarHeight = 20;

    QApplication::processEvents();
    QRect const screenRect = qApp->desktop()->availableGeometry();
    progress->move(screenRect.width() / 2 - progressBarWidth / 2, screenRect.height() / 2 - progressBarHeight / 2);
    progress->setFixedWidth(progressBarWidth);
    progress->setFixedHeight(progressBarHeight);
    progress->setRange(0, 100);

    int forEditor = 60 / metamodels.size();

    foreach (Id const &key, metamodels) {
        QString const objectType = key.element();
        if (objectType == "MetamodelDiagram" && mLogicalRepoApi->isLogicalElement(key)) {
            QString nameOfTheDirectory = mLogicalRepoApi->stringProperty(key, "name of the directory");
            QString nameOfMetamodel = mLogicalRepoApi->stringProperty(key, "name");
            QString nameOfPlugin = nameOfTheDirectory.split("/").last();

            if (QMessageBox::question(mMainWindowInterface->windowWidget()
                                      , tr("loading..")
                                      , QString(tr("Do you want to compile and load editor %1?")).arg(nameOfPlugin)
                                      , QMessageBox::Yes, QMessageBox::No)
                    == QMessageBox::No)
            {
                continue;
            }

            progress->setValue(5);

            const QString normalizedName = nameOfMetamodel.at(0).toUpper() + nameOfMetamodel.mid(1);
            const bool stateOfLoad = mMainWindowInterface->pluginLoaded(normalizedName);
            if (!mMainWindowInterface->unloadPlugin(normalizedName)) {
                progress->close();
                delete progress;
                return;
            }

            if (!metaCompiler.compile(nameOfMetamodel)) { // generating source code for all metamodels
                QMessageBox::warning(mMainWindowInterface->windowWidget()
                                     , tr("error")
                                     , tr("Cannot generate source code for editor ") + nameOfPlugin);
                continue;
            }
            progress->setValue(20);

            QStringList qmakeArgs;
            qmakeArgs.append("CONFIG+=" + mLogicalRepoApi->stringProperty(key, "buildConfiguration"));
            qmakeArgs.append(nameOfMetamodel + ".pro");

            QProcess builder;
            builder.setWorkingDirectory(nameOfTheDirectory);
            const QStringList environment = QProcess::systemEnvironment();
            builder.setEnvironment(environment);
            builder.start(SettingsManager::value("pathToQmake").toString(), qmakeArgs);

            qDebug()  << "qmake";
            if ((builder.waitForFinished()) && (builder.exitCode() == 0)) {
                progress->setValue(40);
                builder.start(SettingsManager::value("pathToMake").toString());

                bool finished = builder.waitForFinished(100000);
                qDebug()  << "make";

                if (finished && (builder.exitCode() == 0)) {
                    if (stateOfLoad) {
                        QMessageBox::warning(mMainWindowInterface->windowWidget()
                                             , tr("Attention!"), tr("Please restart QReal."));
                        progress->close();
                        delete progress;
                        return;
                    }
                    qDebug()  << "make ok";
                    progress->setValue(progress->value() + forEditor / 2);

                    if (!nameOfMetamodel.isEmpty()) {
                        if (!mMainWindowInterface->unloadPlugin(normalizedName)) {
                            QMessageBox::warning(mMainWindowInterface->windowWidget()
                                                 , tr("error")
                                                 , tr("cannot unload plugin ") + normalizedName);
                            progress->close();
                            delete progress;
                            continue;
                        }
                    }

                    QString suffix = "";
                    if (mLogicalRepoApi->stringProperty(key, "buildConfiguration") == "debug") {
                        suffix = "-d";
                    }

                    QString const generatedPluginFileName = SettingsManager::value("prefix").toString()
                                                            + nameOfMetamodel
                                                            + suffix
                                                            + "."
                                                            + SettingsManager::value("pluginExtension").toString()
                                                            ;

                    if (mMainWindowInterface->loadPlugin(generatedPluginFileName, normalizedName)) {
                        progress->setValue(progress->value() + forEditor / 2);
                    }
                }
                progress->setValue(100);
            }
        }
    }