Example #1
0
Object* OgrFileImport::importPointGeometry(MapPart* map_part, OGRFeatureH feature, OGRGeometryH geometry)
{
	auto style = OGR_F_GetStyleString(feature);
	auto symbol = getSymbol(Symbol::Point, style);
	if (symbol->getType() == Symbol::Point)
	{
		auto object = new PointObject(symbol);
		object->setPosition(toMapCoord(OGR_G_GetX(geometry, 0), OGR_G_GetY(geometry, 0)));
		map_part->addObject(object);
		return object;
	}
	else if (symbol->getType() == Symbol::Text)
	{
		const auto& description = symbol->getDescription();
		auto length = description.length();
		auto split = description.indexOf(QLatin1Char(' '));
		Q_ASSERT(split > 0);
		Q_ASSERT(split < length);
		
		auto label = description.right(length - split - 1);
		if (label.startsWith('{') && label.endsWith('}'))
		{
			label.remove(0,1);
			label.chop(1);
			int index = OGR_F_GetFieldIndex(feature, label.toLatin1());
			if (index >= 0)
			{
				label = QString(OGR_F_GetFieldAsString(feature, index));
			}
		}
		if (!label.isEmpty())
		{
			auto object = new TextObject(symbol);
			object->setAnchorPosition(toMapCoord(OGR_G_GetX(geometry, 0), OGR_G_GetY(geometry, 0)));
			// DXF observation
			label.replace(QRegularExpression("(\\\\[^;]*;)*", QRegularExpression::MultilineOption), QString::null);
			label.replace(QLatin1String("^I"), "\t");
			object->setText(label);
			
			bool ok;
			auto anchor = QStringRef(&description, 1, 2).toInt(&ok);
			if (ok)
			{
				applyLabelAnchor(anchor, object);
			}
				
			auto angle = QStringRef(&description, 3, split-3).toFloat(&ok);
			if (ok)
			{
				object->setRotation(qDegreesToRadians(angle));
			}
			
			map_part->addObject(object);
			return object;
		}
	}
	
	return nullptr;
}
Example #2
0
void OverlayPanel::setProperties(const QScriptValue &properties) {
    PanelAttachable::setProperties(properties);
    Billboardable::setProperties(properties);

    QScriptValue anchorPosition = properties.property("anchorPosition");
    if (anchorPosition.isValid() &&
        anchorPosition.property("x").isValid() &&
        anchorPosition.property("y").isValid() &&
        anchorPosition.property("z").isValid()) {
        glm::vec3 newPosition;
        vec3FromScriptValue(anchorPosition, newPosition);
        setAnchorPosition(newPosition);
    }

    QScriptValue anchorPositionBinding = properties.property("anchorPositionBinding");
    if (anchorPositionBinding.isValid()) {
        PropertyBinding binding = {};
        propertyBindingFromScriptValue(anchorPositionBinding, binding);
        _anchorPositionBindMyAvatar = binding.avatar == "MyAvatar";
        _anchorPositionBindEntity = binding.entity;
    }

    QScriptValue anchorRotation = properties.property("anchorRotation");
    if (anchorRotation.isValid() &&
        anchorRotation.property("x").isValid() &&
        anchorRotation.property("y").isValid() &&
        anchorRotation.property("z").isValid() &&
        anchorRotation.property("w").isValid()) {
        glm::quat newRotation;
        quatFromScriptValue(anchorRotation, newRotation);
        setAnchorRotation(newRotation);
    }

    QScriptValue anchorRotationBinding = properties.property("anchorRotationBinding");
    if (anchorRotationBinding.isValid()) {
        PropertyBinding binding = {};
        propertyBindingFromScriptValue(anchorPositionBinding, binding);
        _anchorRotationBindMyAvatar = binding.avatar == "MyAvatar";
        _anchorRotationBindEntity = binding.entity;
    }

    QScriptValue anchorScale = properties.property("anchorScale");
    if (anchorScale.isValid()) {
        if (anchorScale.property("x").isValid() &&
            anchorScale.property("y").isValid() &&
            anchorScale.property("z").isValid()) {
            glm::vec3 newScale;
            vec3FromScriptValue(anchorScale, newScale);
            setAnchorScale(newScale);
        } else {
            setAnchorScale(anchorScale.toVariant().toFloat());
        }
    }

    QScriptValue visible = properties.property("visible");
    if (visible.isValid()) {
        setVisible(visible.toVariant().toBool());
    }
}