Ejemplo n.º 1
0
void OpenSpace::initialize()
{

	maxProgress(200);
	setAllEdges(false);
	world().SetGravity(b2Vec2(0, 10));

	upper = makePlatform(10, -25);
	addProgress(25);
	middle = makePlatform(50, -25);
	addProgress(25);
	
	auto pd = physicsDimensions();

	for(int i = 0; i < 150; ++i)
	{
		polygonDef def;
		def.bodyDef.position.Set(randuniform(pd.x, pd.x + 30), randuniform(-30, pd.y-30));
		def.bodyDef.angle = to_radians(randuniform(0, 360));
		def.bodyDef.type = b2_dynamicBody;
		def.shape.SetAsBox(1, 5);
		def.fixtureDef.restitution = 0.5;
		def.fixtureDef.density = 4;
		bodies.push_back(make_shape(world(), def));
		addProgress(1);
	}
}
Ejemplo n.º 2
0
void TreeSystem::make_ground(
	float thickness,
	float base_angle,
	float delta_angle,
	const sf::Color& base_color,
	const ColorTransform& deltas)
{
	const float density_factor = 1.5;
	const float block_w = 5;
	const float block_h = 1;
	const float block_area = block_w * block_h;
	const float underground_depth = 5;

	auto phys = physicsDimensions();
	auto phys2 = physicsHalfDimensions();
	const float area = (thickness + underground_depth) * phys.x;
	const unsigned density = (area * density_factor) / block_area;

	blocks.reserve(blocks.size() + density + 1);

	polygonDef def;
	def.bodyDef.active = false;
	def.bodyDef.fixedRotation = true;
	def.bodyDef.type = b2_staticBody;
	def.shape.SetAsBox(phys2.x, thickness/2);
	def.bodyDef.angle = 0;
	def.bodyDef.position.Set(phys2.x, phys.y - (thickness/2));

	blocks.emplace_back(
		make_shape(world(), def),
		base_color);
	
	def.shape.SetAsBox(block_w, block_h);
	addProgress(1);

	const b2Vec2 topLeft(0, phys.y - thickness);
	const b2Vec2 bottomRight(phys.x, phys.y + underground_depth);

	maxProgress(blocks.size() + density + 1);
	setProgress(blocks.size());

	for(int i = 0; i < density; ++i)
	{
		def.bodyDef.position = random_in(topLeft, bottomRight);
		def.bodyDef.angle = to_radians(randcentered(base_angle, delta_angle));
		add_block(def, deltas.apply(base_color));
		addProgress(1);
	}
}
Ejemplo n.º 3
0
void MainWindow::onImportDataClicked()
{
    // gets the file that contains the data
    QString file_name = QFileDialog::getOpenFileName(0, QString(), QString(), "*.txt");
    // clear the data from the database before importing starts

    m_workerThread.reset(new QThread);
    m_importer.reset(new DataImporter(file_name));
    // create the dataimporter wrapper
    m_proxy.reset(new DataImporterProxy(m_importer.data(), m_sqlModel));
    m_proxy->moveToThread(m_workerThread.data());
    connect(m_workerThread.data(), SIGNAL(started()), m_proxy.data(), SLOT(proxyStartWork()));
    connect(m_importer.data(), SIGNAL(doneImporting()), m_workerThread.data(), SLOT(quit()));


    if (m_importer->fileOk())
    {
        import_progress = new QProgressBar;
        import_progress->setAttribute(Qt::WA_DeleteOnClose);
        import_progress->setMaximum(34);
        import_progress->setValue(0);
        connect(m_sqlModel, SIGNAL(oneGapTableFinished()), this, SLOT(addProgress()));
        connect(m_importer.data(), SIGNAL(doneImporting()), import_progress, SLOT(close()));
        m_workerThread->start();
        import_progress->show();
    }
}
Ejemplo n.º 4
0
	void initialize() override
	{
		const auto size = windowDimensions();
		linear_scale<float, float> window_scale(0, 1000, 0, size.x);
		linear_scale<float, float> lower_bottom(0, size.x, 5 * size.y / 6, 5 * size.y / 6);
		linear_scale<float, float> lower_top(0, size.x, 2 * size.y / 3, size.y / 6);
		linear_scale<float, float> upper_bottom(0, size.x, size.y / 3, 5 * size.y / 6);
		linear_scale<float, float> upper_top(0, size.x, size.y / 6, size.y / 6);
		linear_scale<float, float> x_scale(0, std::sqrt(size.x), 0, size.x);
		linear_color_scale<float> color_scale(0, size.x, sf::Color(128, 128, 128), sf::Color::Black);
		linear_scale<float, float> size_scale(0, size.x, 1, 6);

		const unsigned num_rects(15);
		sf::RectangleShape rect(sf::Vector2f(window_scale(100), window_scale(20)));
		rect.setOrigin(window_scale(50), window_scale(10));
		rect.setFillColor(sf::Color::Black);
		rect.setOutlineColor(sf::Color::White);
		rect.setOutlineThickness(window_scale(-1));

		sf::Vector2f top_left(0, 0);
		sf::Vector2f bottom_right(std::sqrt(size.x), size.y);
		maxProgress(num_rects);
		for(unsigned i = 0; i < num_rects; ++i)
		{
			float x = x_scale(randuniform(0, std::sqrt(size.x)));
			float scale = size_scale(x);
			rect.setScale(scale, scale);
			rect.setOutlineThickness(window_scale(-1)/scale);
			float y = linear_scale<float, float>(0, size.y, upper_top(x), upper_bottom(x))(randuniform(0, size.y));
			rect.setFillColor(color_scale(x));
			rect.setPosition(x, y);
			rects.push_back(rect);
			addProgress(0.5);
			y = linear_scale<float, float>(0, size.y, lower_top(x), lower_bottom(x))(randuniform(0, size.y));
			rect.setFillColor(sf::Color::Black);
			rect.setPosition(x, y);
			rects.push_back(rect);
			addProgress(0.5);
		}
		std::sort(rects.begin(), rects.end(), [](const sf::RectangleShape& lhs, const sf::RectangleShape& rhs)
		{
			return lhs.getPosition().x > rhs.getPosition().x;
		});

	}
Ejemplo n.º 5
0
void Flat::initialize()
{
	const int num_things = 75;

	maxProgress(num_things * 3);

	for(int i = 0; i < num_things; ++i)
	{
		polygonDef def;
		def.bodyDef.position.Set(randuniform(50, 100), randuniform(0, 80));
		def.bodyDef.angle = 0;
		def.bodyDef.fixedRotation = true;
		def.bodyDef.type = b2_dynamicBody;
		def.shape.SetAsBox(1*1.2, 5*1.2);
		def.fixtureDef.density = 1;
		(make_shape(back1, def));
		addProgress(1);
	}
	for(int i = 0; i < num_things; ++i)
	{
		polygonDef def;
		def.bodyDef.position.Set(randuniform(50, 100), randuniform(0, 80));
		def.bodyDef.angle = to_radians(randuniform(0, 360));
		def.bodyDef.type = b2_dynamicBody;
		def.shape.SetAsBox(1, 5);
		def.fixtureDef.density = 1;
		(make_shape(back2, def));
		addProgress(1);
	}
	for(int i = 0; i < num_things; ++i)
	{
		polygonDef def;
		def.bodyDef.position.Set(randuniform(50, 100), randuniform(0, 80));
		def.bodyDef.angle = 0;
		def.bodyDef.fixedRotation = true;
		def.bodyDef.type = b2_dynamicBody;
		def.shape.SetAsBox(1*0.8, 5*0.8);
		def.fixtureDef.density = 1;
		(make_shape(back3, def));
		addProgress(1);
	}
}
Ejemplo n.º 6
0
/*!
    Takes the \a helpData and generates a new documentation
    set from it. The Qt compressed help file is written to \a
    outputFileName. Returns true on success, otherwise false.
*/
bool QHelpGenerator::generate(QHelpDataInterface *helpData,
                              const QString &outputFileName)
{
    emit progressChanged(0);
    d->error.clear();
    if (!helpData || helpData->namespaceName().isEmpty()) {
        d->error = tr("Invalid help data!");
        return false;
    }

    QString outFileName = outputFileName;
    if (outFileName.isEmpty()) {
        d->error = tr("No output file name specified!");
        return false;
    }

    QFileInfo fi(outFileName);
    if (fi.exists()) {
        if (!fi.dir().remove(fi.fileName())) {
            d->error = tr("The file %1 cannot be overwritten!").arg(outFileName);
            return false;
        }
    }

    setupProgress(helpData);

    emit statusChanged(tr("Building up file structure..."));
    bool openingOk = true;
    {
        QSqlDatabase db = QSqlDatabase::addDatabase(QLatin1String("QSQLITE"), QLatin1String("builder"));
        db.setDatabaseName(outFileName);
        openingOk = db.open();
        if (openingOk)
            d->query = new QSqlQuery(db);
    }

    if (!openingOk) {
        d->error = tr("Cannot open data base file %1!").arg(outFileName);
        cleanupDB();
        return false;
    }

    d->query->exec(QLatin1String("PRAGMA synchronous=OFF"));
    d->query->exec(QLatin1String("PRAGMA cache_size=3000"));

    addProgress(1.0);
    createTables();
    insertFileNotFoundFile();
    insertMetaData(helpData->metaData());

    if (!registerVirtualFolder(helpData->virtualFolder(), helpData->namespaceName())) {
        d->error = tr("Cannot register namespace %1!").arg(helpData->namespaceName());
        cleanupDB();
        return false;
    }
    addProgress(1.0);

    emit statusChanged(tr("Insert custom filters..."));
    foreach (const QHelpDataCustomFilter &f, helpData->customFilters()) {
        if (!registerCustomFilter(f.name, f.filterAttributes, true)) {
            cleanupDB();
            return false;
        }
    }
    addProgress(1.0);

    int i = 1;
    QList<QHelpDataFilterSection>::const_iterator it = helpData->filterSections().constBegin();
    while (it != helpData->filterSections().constEnd()) {
        emit statusChanged(tr("Insert help data for filter section (%1 of %2)...")
            .arg(i++).arg(helpData->filterSections().count()));
        insertFilterAttributes((*it).filterAttributes());
        QByteArray ba;
        QDataStream s(&ba, QIODevice::WriteOnly);
        foreach (QHelpDataContentItem *itm, (*it).contents())
            writeTree(s, itm, 0);
        if (!insertFiles((*it).files(), helpData->rootPath(), (*it).filterAttributes())
            || !insertContents(ba, (*it).filterAttributes())
            || !insertKeywords((*it).indices(), (*it).filterAttributes())) {
            cleanupDB();
            return false;
        }
        ++it;
    }

    cleanupDB();
    emit progressChanged(100);
    emit statusChanged(tr("Documentation successfully generated."));
    return true;
}
Ejemplo n.º 7
0
	void initialize() override
	{
		const float max_depth = 6000;
		const float min_depth = 0;
		const unsigned num_planes = 75;
		const unsigned rects_per_plane = 10;
		const float interval = ((max_depth - min_depth) / num_planes);
		const auto center = windowHalfDimensions();
		const auto dimensions = windowDimensions();

		auto plane = VanishPlane::backPlane(sf::Vector2f(center.x, center.y*1.2), 0);
		planes.reserve(num_planes);

		const sf::Vector2f rect_size(50, 250);
		sf::RectangleShape shape_base(rect_size);
		shape_base.setOrigin(rect_size.x / 2, rect_size.y);
		shape_base.setFillColor(sf::Color::Black);
		shape_base.setOutlineColor(sf::Color::White);
		const unsigned num_points = shape_base.getPointCount();

		const sf::Vector2f ground_size(100000, 100);
		sf::RectangleShape ground(ground_size);
		ground.setOrigin(ground_size.x / 2, 0);
		ground.setPosition(center.x, dimensions.y);
		ground.setFillColor(sf::Color::White);
		ground.setOutlineColor(sf::Color::Transparent);
		
		maxProgress(num_planes * (rects_per_plane+1));

		for(unsigned n_plane = num_planes; n_plane > 0; --n_plane)
		{
			plane.intersect = (n_plane * interval) + min_depth;

			planes.emplace_back();
			auto& rects = planes.back().rects;
			rects.reserve(rects_per_plane);

			if(n_plane == int(num_planes*.6))
			{
				const sf::Vector2f mighty_size(2000, 20000);
				sf::RectangleShape mighty(mighty_size);
				mighty.setOrigin(mighty_size.x / 2, mighty_size.y);
				mighty.setPosition(center.x * 10, dimensions.y);
				mighty.setFillColor(sf::Color::Black);
				mighty.setOutlineColor(sf::Color::White);
				rects.push_back(convertRectToConvex(mighty, plane));
			}


			for(unsigned rect = 0; rect < rects_per_plane; ++rect)
			{
				shape_base.setPosition(
					randcentered(center.x, center.x * sqrt(n_plane) * 5),
					dimensions.y + randuniform(0, 50));
				shape_base.setRotation(randuniform(-30, 30));
				rects.push_back(convertRectToConvex(shape_base, plane));
				addProgress(1);
			}
			rects.push_back(convertRectToConvex(ground, plane));
			addProgress(1);
		}
	}
Ejemplo n.º 8
0
SavePRC::SavePRC (std::string type)
  : WEMInspector(type)
{
  // Suppress calls of handleNotification on field changes to
  // avoid side effects during initialization phase.
  handleNotificationOff();

  // Add input fields to the module and set allowed types.
  (_inPointPositionsFld  = addBase("inPointPositions"))->setBaseValueAndAddAllowedType(&_inPointPositions);
  (_inLinePositionsFld   = addBase("inLinePositions"))->setBaseValueAndAddAllowedType(&_inLinePositions);
  (_inLineConnectionsFld = addBase("inLineConnections"))->setBaseValueAndAddAllowedType(&_inLineConnections);

  // Add fields for selecting simple, straightforward mode
  (_simpleModePointSetFld = addBool("simpleModePointSet"))->setBoolValue(false);
  (_simpleModeLineSetFld = addBool("simpleModeLineSet"))->setBoolValue(false);
  (_simpleModeMeshFld = addBool("simpleModeMesh"))->setBoolValue(false);

  // Add fields to the module and set their values.
  (_modelPrefixPointCloudsFld = addString("modelPrefixPointClouds"))->setStringValue("PointSet");
  (_modelPrefixLineSetsFld    = addString("modelPrefixLineSets"))->setStringValue("LineSet");
  (_modelPrefixMeshesFld      = addString("modelPrefixMeshes"))->setStringValue("Mesh");
  //(_modelPrefixGlyphsFld      = addString("modelPrefixGlyphs"))->setStringValue("Glyph");       // Not supported by Acrobat

  (_pointCloudSpecificationFld = addString("pointCloudSpecification"))->setStringValue("");
  (_lineSetSpecificationFld    = addString("lineSetSpecification"))->setStringValue("");
  (_meshSpecificationFld       = addString("meshSpecification"))->setStringValue("");
  //(_glyphSpecificationFld      = addString("glyphSpecification"))->setStringValue("");          // Not supported by Acrobat
  //(_viewsSpecificationFld      = addString("viewsSpecification"))->setStringValue("");
  //(_lightsSpecificationFld     = addString("lightsSpecification"))->setStringValue("");
  //(_metaDataSpecificationFld   = addString("metaDataSpecification"))->setStringValue("");

  //(_defaultViewNameFld     = addString("defaultViewName"))->setStringValue("DefaultView");
  //(_defaultLightNameFld    = addString("defaultLightName"))->setStringValue("DefaultAmbientLight");

  //(_defaultMaterialDiffuseColorFld  = addColor("defaultMaterialDiffuseColor"))->setVector3Value(Vector3(0.65f,0.65f,0.65f));
  //(_defaultMaterialSpecularColorFld = addColor("defaultMaterialSpecularColor"))->setVector3Value(Vector3(0.75f,0.75f,0.75f));
  //(_defaultMaterialAmbientColorFld  = addColor("defaultMaterialAmbientColor"))->setVector3Value(Vector3(0.0f,0.0f,0.0f));
  //(_defaultMaterialEmissiveColorFld = addColor("defaultMaterialEmissiveColor"))->setVector3Value(Vector3(0.0f,0.0f,0.0f));
  //(_defaultMaterialTransparencyFld  = addFloat("defaultMaterialTransparency"))->setFloatValue(0.0f);

  //(_defaultLightColorFld = addColor("defaultLightColor"))->setVector3Value(Vector3(1.0f,1.0f,1.0f));
  //(_defaultLightIntensityFld = addDouble("defaultLightIntensity"))->setDoubleValue(1.0f);

  //(_defaultBoundingBoxMetaDataFld = addBool("defaultBoundingBoxMetaData"))->setBoolValue(true);
  //(_addDefaultViewNodeFld         = addBool("addDefaultViewNode"))->setBoolValue(true);
  //(_addDefaultLightNodeFld        = addBool("addDefaultLightNode"))->setBoolValue(true);

  (_mlFileNameFld = addString("filename"))->setStringValue("");

  _mlSaveFld = addNotify("save");

  (_statusFld     = addString("status"))    ->setStringValue("Idle.");
  (_progressFld   = addProgress("progress"))->setFloatValue(0.0f);

  //-------------------------------------------------------------------
  //! Strings for enum field: specification type 
  //-------------------------------------------------------------------
  const char* const NEW_SPECIFICATION_OBJECTTYPE_STRINGS[mlPDF::NUM_OBJECTTYPES] = {
    "OBJECTTYPE_POINTCLOUD",
    "OBJECTTYPE_LINESET",
    "OBJECTTYPE_MESH",
    "OBJECTTYPE_METADATA"
  };

  //-------------------------------------------------------------------
  //! Strings for enum field: model visibility 
  //-------------------------------------------------------------------
  const char* const NEW_SPECIFICATION_MODELVISIBILITY_STRINGS[mlPDF::NUM_MODELVISIBILITY] = {
    "MODELVISIBILITY_NOTVISIBLE",
    "MODELVISIBILITY_FRONTVISIBLE",
    "MODELVISIBILITY_BACKVISIBLE",
    "MODELVISIBILITY_FRONTANDBACKVISIBLE"
  };

  //! Add fields for Specification Generator
  (_newSpecificationFld                        = addString("newSpecification"))->setStringValue("");
  (_newSpecificationSelectedTabFld             = addInt("selectedTab"))->setIntValue(0);
  (_newSpecificationOutputValidFld             = addBool("newSpecificationOutputValid"))->setBoolValue(false);
  _newSpecificationAddFld                      = addNotify("newSpecificationAdd");
  (_newSpecificationTypeFld                    = addEnum("newSpecificationType", NEW_SPECIFICATION_OBJECTTYPE_STRINGS, mlPDF::NUM_OBJECTTYPES))->setEnumValue(mlPDF::OBJECTTYPE_MESH);
  (_newSpecificationObjectNameFld              = addString("newSpecificationObjectName"))->setStringValue("");
  (_newSpecificationGroupPathFld               = addString("newSpecificationGroupPath"))->setStringValue("");
  (_newSpecificationUseDefaultColorFld         = addBool("newSpecificationUseDefaultColor"))->setBoolValue(true);
  (_newSpecificationUseDefaultSpecularColorFld = addBool("newSpecificationUseDefaultSpecularColor"))->setBoolValue(true);
  (_newSpecificationColorFld                   = addColor("newSpecificationColor"))->setVector3Value(Vector3(0.651f,0.651f,0.651f));
  (_newSpecificationColorAlphaFld              = addFloat("newSpecificationColorAlpha"))->setFloatValue(1.0f);
  (_newSpecificationSpecularColorFld           = addColor("newSpecificationSpecularColor"))->setVector3Value(Vector3(0.75f,0.75f,0.75f));
  (_newSpecificationModelVisibilityFld         = addEnum("newSpecificationModelVisibility", NEW_SPECIFICATION_MODELVISIBILITY_STRINGS, mlPDF::NUM_MODELVISIBILITY))->setEnumValue(mlPDF::MODELVISIBILITY_FRONTANDBACKVISIBLE);
  (_newSpecificationMetaDataKeyFld             = addString("newSpecificationMetaDataKey"))->setStringValue("");
  (_newSpecificationMetaDataValueFld           = addString("newSpecificationMetaDataValue"))->setStringValue("");
  (_newSpecificationWEMLabelFld                = addString("newSpecificationWEMLabel"))->setStringValue("");
  (_newSpecificationPositionTypesFld           = addString("newSpecificationPositionTypes"))->setStringValue("");
  (_newSpecificationConnectionTypesFld         = addString("newSpecificationConnectionTypes"))->setStringValue("");

  // Turn off the automatic saving on all notifications
  _listenToFinishingNotificationsFld       ->setBoolValue(false);
  _listenToRepaintNotificationsFld         ->setBoolValue(false);
  _listenToSelectionChangedNotificationsFld->setBoolValue(false);

  _autoUpdateFld->setBoolValue(false);
  _autoApplyFld->setBoolValue(false);

  // Reactivate calls of handleNotification on field changes.
  handleNotificationOn();
}