예제 #1
0
파일: image_mgr.cpp 프로젝트: iliis/Anathea
//------------------------------------------------------------------------------
void
Image::set(ptree pt)
{
    if(pt.get_child_optional("UV"))        this->setUV(Box(pt.get_child("UV")), getBoolFromPT(pt, "UV.normalized", false));
    if(pt.get_child_optional("NinePatch")) this->setNinePatchData(NinePatchData(pt.get_child("NinePatch")));
    if(pt.get_child_optional("color"))     this->color = Color(pt.get("color", "#FFF"));
};
예제 #2
0
//------------------------------------------------------------------------------
void
WText::_set(ptree n)
{
	if(n.get_child_optional("text.content"))
		this->setText(n.get("text.content", this->text));

	if(n.get_child_optional("text.padding"))
		this->padding = n.get<FNumber>("text.padding");

	if(n.get_child_optional("text.font"))
	{
		if(n.get_child_optional("text.font.path") && n.get_child_optional("text.font.size"))
			this->setFont(this->kernel->graphicsMgr->loadFont(
													n.get<string>("text.font.path"),
													n.get<int>  ("text.font.size")));

		else if(n.get_child_optional("text.font.size"))
			this->setFontSize(n.get<int>("text.font.size"));

		else if(n.get_child_optional("text.font.path"))
			this->setFont(this->kernel->graphicsMgr->loadFont(
													n.get<string>("text.font.path"),
													this->font.getSize()));

		if(n.get_child_optional("text.font.color"))
			this->setColor(Color(n.get<string>("text.font.color")));

		if(n.get_child_optional("text.font.background_color"))
			this->setBG(Color(n.get<string>("text.font.background_color")));

		/// TODO: transparent [bool]

		/// TODO: alignment
	}
};
예제 #3
0
//------------------------------------------------------------------------------
void
WTextInput::_set(ptree n)
{
	WText::_set(n);

	if(n.get_child_optional("border_normal"))
		this->setBorderNormal (kernel->graphicsMgr->loadImage(n.get_child("border_normal")));

	if(n.get_child_optional("border_focused"))
		this->setBorderFocused(kernel->graphicsMgr->loadImage(n.get_child("border_focused")));
};
예제 #4
0
		radial_gradient::radial_gradient(element* doc, const ptree& pt)
			: gradient(doc, pt)
		{
			auto attributes = pt.get_child_optional("<xmlattr>");
			if(attributes) {
				auto cx = attributes->get_child_optional("cx");
				auto cy = attributes->get_child_optional("cy");
				auto radius = attributes->get_child_optional("r");
				auto fx = attributes->get_child_optional("fx");
				auto fy = attributes->get_child_optional("fy");
				if(cx) {
					cx_.from_string(cx->data());
				}
				if(cy) {
					cy_.from_string(cy->data());
				}
				if(radius) {
					r_.from_string(radius->data());
				}
				if(fx) {
					fx_.from_string(fx->data());
				}
				if(fy) {
					fy_.from_string(fy->data());
				}
			}
		}
예제 #5
0
// load
void configuration::load(const ptree& in_conf) {
  try {

    settings_ = in_conf.get_child(settings_path_);
    LOG_INFO(settings_path_, "Loading settings");

    auto model = settings_.get_optional<std::string>(model_key_);
    if (!model) {
      throw configuration_error("model descriptor '" + model_key_ +
                                "' has to be set in " + settings_path_);
    }
    defaults_path_ += "." + *model;
    auto def = in_conf.get_child_optional(defaults_path_);
    if (def) {
      LOG_INFO(settings_path_, *model + " defaults found.");
      defaults_ = *def;
    } else {
      LOG_INFO(settings_path_, "No default settings provided for this board.");
    }
  } catch (ptree_bad_path& e) {
    throw path_error(e.path<std::string>());
  } catch (ptree_error& e) {
    // shouldn't happen
    throw configuration_error("Processing error", e.what());
  }
}
예제 #6
0
// save
void configuration::save(ptree& out_conf) const {
  out_conf.put_child(settings_path_, settings_);
  LOG_INFO(settings_path_, "Settings saved.");
  if (!out_conf.get_child_optional(defaults_path_)) {
    out_conf.put_child(defaults_path_, defaults_);
    LOG_INFO(defaults_path_, "Settings saved.");
  }
}
예제 #7
0
		gradient::gradient(element* doc, const ptree& pt)
			: core_attribs(pt),
			coord_system_(GradientCoordSystem::OBJECT_BOUNDING_BOX),
			spread_(GradientSpreadMethod::PAD)
		{
			// Process attributes
			auto attributes = pt.get_child_optional("<xmlattr>");
			if(attributes) {
				auto xlink_href = attributes->get_child_optional("xlink:xref");
				auto transforms = attributes->get_child_optional("gradientTransforms");
				auto units = attributes->get_child_optional("gradientUnits");
				auto spread = attributes->get_child_optional("spreadMethod");

				if(transforms) {
					transforms_ = transform::factory(transforms->data());
				}
				if(xlink_href) {
					xlink_href_ = xlink_href->data();
				}
				if(units) {
					std::string csystem = units->data();
					if(csystem == "userSpaceOnUse") {
						coord_system_ = GradientCoordSystem::USERSPACE_ON_USE;
					} else if(csystem =="objectBoundingBox") {
						coord_system_ = GradientCoordSystem::OBJECT_BOUNDING_BOX;
					} else {
						ASSERT_LOG(false, "Unrecognised 'gradientUnits' value: " << csystem);
					}
				}
				if(spread) {
					std::string spread_val = units->data();
					if(spread_val == "pad") {
						spread_ = GradientSpreadMethod::PAD;
					} else if(spread_val =="reflect") {
						spread_ = GradientSpreadMethod::REFLECT;
					} else if(spread_val =="repeat") {
						spread_ = GradientSpreadMethod::REPEAT;
					} else {
						ASSERT_LOG(false, "Unrecognised 'spreadMethod' value: " << spread_val);
					}
				}

				// Process child elements
				for(auto& v : pt) {
					if(v.first == "stop") {
						stops_.emplace_back(new gradient_stop(doc, v.second));
					} else if(v.first == "<xmlattr>") {
						// ignore
					} else if(v.first == "<xmlcomment>") {
						// ignore
					} else {
						ASSERT_LOG(false, "unexpected child element in gradient stop list: " << v.first);
					}
				}
			}
		}
예제 #8
0
파일: main.cpp 프로젝트: CCJY/coliru
void add_to_data(ptree& pt, const ptree& record)
{
    if(!pt.get_child_optional("data")) {
        ptree arrayPt;
        arrayPt.push_back(make_pair("", record));
        pt.push_back(make_pair("data", arrayPt));
    } else {
        auto& dataPt = pt.get_child("data");
        dataPt.push_back(make_pair("", record));
    }
}
예제 #9
0
	/*
	<scriptComponent>
	    <scriptObject constructor="addPlayer" destructor="removePlayer" />
	    <scriptData actorType="player"/>
	</scriptComponent>
	*/
	bool ScriptComponent::vInit(const ptree componentNode) {
		optional<const ptree&> optScriptObject = componentNode.get_child_optional(SCRIPT_OBJECT_NODE_NAME);
		if (optScriptObject.is_initialized()) {
			bool result = readScriptObjectNode(optScriptObject.get());
			if (!result) {
				return false;
			}
		}

		optional<const ptree&> optScriptData = componentNode.get_child_optional(SCRIPT_DATA_NODE_NAME);
		if (optScriptData.is_initialized()) {
			bool result = readScriptDataNode(optScriptData.get());
			if (!result) {
				return false;
			}
		}


		return true;
	};
예제 #10
0
파일: MsgPrinter.cpp 프로젝트: ic-hep/emi3
void MsgPrinter::addToArray(ptree& root, string name, map<string, string>& object) {

	static const string array_sufix = "..";

	optional<ptree&> child = root.get_child_optional(name);
	if (child.is_initialized()) {
		child.get().push_front(
				make_pair("", getItem(object))
			);
	} else {
		put(root, name + array_sufix, object);
	}
}
예제 #11
0
파일: MsgPrinter.cpp 프로젝트: ic-hep/emi3
void MsgPrinter::addToArray(ptree& root, string name, string value) {

	optional<ptree&> child = root.get_child_optional(name);
	if (child.is_initialized()) {
		ptree item;
		item.put("", value);
		child.get().push_front(make_pair("", item));
	} else {
		ptree child, item;
		item.put("", value);
		child.push_front(make_pair("", item));
		root.put_child(name, child);
	}
}
예제 #12
0
		gradient_stop::gradient_stop(element* doc, const ptree& pt)
			: core_attribs(pt), 
			offset_(0.0),
			opacity_(1.0),
			opacity_set_(false)
		{
			auto attributes = pt.get_child_optional("<xmlattr>");
			if(attributes) {
				auto opacity = attributes->get_child_optional("stop-opacity");
				auto color = attributes->get_child_optional("stop-color");
				auto offset = attributes->get_child_optional("offset");

				if(opacity) {
					opacity_set_ = true;
					const std::string alpha = opacity->data();
					try {
						opacity_ = boost::lexical_cast<double>(alpha);
					} catch(const boost::bad_lexical_cast&) {
						ASSERT_LOG(false, "Couldn't convert opacity value to number: " << alpha);
					}
				}

				if(color) {
					color_ = paint::from_string(color->data());
					if(opacity) {
						color_->set_opacity(opacity_);
					}
				}

				ASSERT_LOG(!offset, "No offset field given in gradient color stop");
				const std::string offs = offset->data();
				try {
					offset_ = boost::lexical_cast<double>(offs);
				} catch(const boost::bad_lexical_cast&) {
					ASSERT_LOG(false, "Couldn't convert opacity value to number: " << offs);
				}
				if(offs.find('%') != std::string::npos) {
					offset_ /= 100.0;
				}
				offset_ = std::max(std::min(offset_, 1.0), 0.0);
			}
		}
예제 #13
0
		linear_gradient::linear_gradient(element* doc, const ptree& pt)
			: gradient(doc, pt)
		{
			auto attributes = pt.get_child_optional("<xmlattr>");
			if(attributes) {
				auto x1 = attributes->get_child_optional("x1");
				auto y1 = attributes->get_child_optional("y1");
				auto x2 = attributes->get_child_optional("x2");
				auto y2 = attributes->get_child_optional("y2");
				if(x1) {
					x1_.from_string(x1->data());
				}
				if(y1) {
					y1_.from_string(y1->data());
				}
				if(x2) {
					x2_.from_string(x2->data());
				}
				if(y2) {
					y2_.from_string(y2->data());
				}
			}
		}
예제 #14
0
		core_attribs::core_attribs(const ptree& pt)
		{
			auto attributes = pt.get_child_optional("<xmlattr>");

			if(attributes) {
				auto id = attributes->get_child_optional("id");
				if(id) {
					id_ = id->data();
				}
				auto xml_base = attributes->get_child_optional("xml:base");
				if(xml_base) {
					xml_base_ = xml_base->data();
				}
				auto xml_lang = attributes->get_child_optional("xml:lang");
				if(xml_lang) {
					xml_lang_ = xml_lang->data();
				}
				auto xml_space = attributes->get_child_optional("xml:space");
				if(xml_space) {
					xml_space_ = xml_space->data();
				}
			}
		}
예제 #15
0
/**
 * <Part>からパーツを構築する 
 */
static shared_ptr<SsPart> readPart(const ptree& pt, textenc::Encoding encoding, int motionEndFrameNo)
{
	do
	{
		shared_ptr<SsPart> part = shared_ptr<SsPart>(new SsPart());

		// 必須パラメータ 
		optional<int> type = pt.get_optional<int>("Type");
		if (!type) break;

		// オプションパラメータ 
		optional<int> root = pt.get_optional<int>("<xmlattr>.Root");
		optional<std::string> name = pt.get_optional<std::string>("Name");
		optional<int> id = pt.get_optional<int>("ID");
		optional<int> parentId = pt.get_optional<int>("ParentID");

		optional<int> picId = pt.get_optional<int>("PicID");
		optional<int> picAreaLeft = pt.get_optional<int>("PictArea.Left");
		optional<int> picAreaTop = pt.get_optional<int>("PictArea.Top");
		optional<int> picAreaRight = pt.get_optional<int>("PictArea.Right");
		optional<int> picAreaBottom = pt.get_optional<int>("PictArea.Bottom");
		optional<int> originX = pt.get_optional<int>("OriginX");
		optional<int> originY = pt.get_optional<int>("OriginY");

		optional<int> transBlendType = pt.get_optional<int>("TransBlendType");	// alpha blend
		optional<int> inheritType = pt.get_optional<int>("InheritType");


		// Rootアトリビュートが1のときはRootパーツとして扱う
		if (root && root.get() == 1)
		{
			part->type = SsPart::TypeRoot;
		}
		else
		{
			part->type = static_cast<SsPart::Type>(type.get());
		}

		if (name)
		{
			std::string n = textenc::convert(name.get(), encoding, textenc::SHIFT_JIS);
			part->name = n;
		}
		if (id) part->id = id.get();
		if (parentId) part->parentId = parentId.get();

		if (picId) part->picId = picId.get();
		if (picAreaLeft && picAreaTop && picAreaRight && picAreaBottom)
		{
			part->picArea = SsRect(
				picAreaLeft.get(), 
				picAreaTop.get(),
				picAreaRight.get(),
				picAreaBottom.get());
		}
		if (transBlendType)
		{
			int blendType = transBlendType.get();
			if (blendType < 0 || blendType >= SsPart::NumAlphaBlend) blendType = 0;
			part->alphaBlend = static_cast<SsPart::AlphaBlend>(blendType);
		}
		if (originX && originY)
		{
			part->origin = SsPoint(
				originX.get(),
				originY.get());
		}
		if (inheritType)
		{
			part->inheritEach = inheritType.get() != 0;
		}

		std::vector<SsAttribute::Ptr> attributes;
		optional<const ptree&> attrs = pt.get_child_optional("Attributes");
		if (attrs)
		{
			BOOST_FOREACH( const ptree::value_type& v2, pt.get_child("Attributes") )
			{
				if (v2.first == "Attribute")
				{
					const ptree& attr = v2.second;
					shared_ptr<SsAttribute> attribute = readAttribute(attr, encoding);
					if (!attribute) continue;
					attributes.push_back(attribute);
				}
			}
		}
		part->attributes = SsAttributes(attributes, motionEndFrameNo);

		return part;

	} while (false);
	return shared_ptr<SsPart>();
}
예제 #16
0
/**
 * <Key>からキーフレームを構築する
 */
static shared_ptr<SsKeyframe> readKey(const ptree& pt, const SsAttributeTag::Tag& tag, textenc::Encoding encoding)
{
	do
	{
		// 必須パラメータ 
		optional<int> time = pt.get_optional<int>("<xmlattr>.Time");
		if (!time) break;

		boost::shared_ptr<SsValue> ssValue;
		if (tag == SsAttributeTag::VERT)
		{
			// 頂点変形
			optional<int> topLeftX = pt.get_optional<int>("TopLeft.X");
			optional<int> topLeftY = pt.get_optional<int>("TopLeft.Y");
			optional<int> topRightX = pt.get_optional<int>("TopRight.X");
			optional<int> topRightY = pt.get_optional<int>("TopRight.Y");
			optional<int> bottomLeftX = pt.get_optional<int>("BottomLeft.X");
			optional<int> bottomLeftY = pt.get_optional<int>("BottomLeft.Y");
			optional<int> bottomRightX = pt.get_optional<int>("BottomRight.X");
			optional<int> bottomRightY = pt.get_optional<int>("BottomRight.Y");
			if (!topLeftX || !topLeftY) break;
			if (!topRightX || !topRightY) break;
			if (!bottomLeftX || !bottomLeftY) break;
			if (!bottomRightX || !bottomRightY) break;
			
			SsVertex4Value* value = new SsVertex4Value();
			value->v[SS_VERTEX_TOP_LEFT].x = topLeftX.get();
			value->v[SS_VERTEX_TOP_LEFT].y = topLeftY.get();
			value->v[SS_VERTEX_TOP_RIGHT].x = topRightX.get();
			value->v[SS_VERTEX_TOP_RIGHT].y = topRightY.get();
			value->v[SS_VERTEX_BOTTOM_LEFT].x = bottomLeftX.get();
			value->v[SS_VERTEX_BOTTOM_LEFT].y = bottomLeftY.get();
			value->v[SS_VERTEX_BOTTOM_RIGHT].x = bottomRightX.get();
			value->v[SS_VERTEX_BOTTOM_RIGHT].y = bottomRightY.get();
			
			ssValue = boost::shared_ptr<SsValue>(value);
		}
		else if (tag == SsAttributeTag::PCOL)
		{
			// カラーブレンド
			optional<int> type = pt.get_optional<int>("Type");
			optional<int> blend = pt.get_optional<int>("Blend");
			if (!type || !blend) break;
			if (type.get() < 0 || type.get() >= SsColorBlendValue::END_OF_TYPE) break;
			if (blend.get() < 0 || blend.get() >= SsColorBlendValue::END_OF_BLEND) break;

			SsColorBlendValue value;
			value.type = static_cast<SsColorBlendValue::Type>(type.get());
			value.blend = static_cast<SsColorBlendValue::Blend>(SsColorBlendValue::BLEND_MIX + blend.get());
			
			if (value.type == SsColorBlendValue::TYPE_COLORTYPE_PARTS)
			{
				// 単色
				optional<const ptree&> v = pt.get_child_optional("Value");
				if (!v) break;

				bool result = readColors(value.colors[0], v.get());
				if (!result) break;
				// 後の処理で扱いやすいように他の頂点ワークにも同じ値を設定しておく
				readColors(value.colors[1], v.get());
				readColors(value.colors[2], v.get());
				readColors(value.colors[3], v.get());
			}
			else if (value.type == SsColorBlendValue::TYPE_COLORTYPE_VERTEX)
			{
				// 頂点カラー
				optional<const ptree&> tl = pt.get_child_optional("TopLeft");
				optional<const ptree&> tr = pt.get_child_optional("TopRight");
				optional<const ptree&> bl = pt.get_child_optional("BottomLeft");
				optional<const ptree&> br = pt.get_child_optional("BottomRight");
				if (!tl || !tr || !bl || !br) break;

				bool result;
				result = readColors(value.colors[SS_VERTEX_TOP_LEFT], tl.get());
				if (!result) break;
				result = readColors(value.colors[SS_VERTEX_TOP_RIGHT], tr.get());
				if (!result) break;
				result = readColors(value.colors[SS_VERTEX_BOTTOM_LEFT], bl.get());
				if (!result) break;
				result = readColors(value.colors[SS_VERTEX_BOTTOM_RIGHT], br.get());
				if (!result) break;
			}
			else if (value.type == SsColorBlendValue::TYPE_COLORTYPE_NONE)
			{
				// カラー指定無し
				value.colors[0] =
				value.colors[1] =
				value.colors[2] =
				value.colors[3] = SsColor(0, 0, 0, 0);
			}
			else
			{
				throw std::logic_error("Not support color type");
			}
			
			ssValue = boost::shared_ptr<SsValue>(new SsColorBlendValue(value));
		}
		else if (tag == SsAttributeTag::UDAT)
		{
			// ユーザーデータ
			SsUserDataValue value;
			
			// Number
			optional<long> number = pt.get_optional<long>("Number");
			if (number)
			{
				int n = number.get() >= INT_MAX ? INT_MAX : static_cast<int>(number.get());
				value.number = n;
			}

			// Rect
			optional<const ptree&> rectPt = pt.get_child_optional("Rect");
			if (rectPt)
			{
				SsRect rect;
				if (readRect(rect, rectPt.get(), false))	// 座標の正規化は行わない
				{
					value.rect = rect;
				}
			}

			// Point
			optional<const ptree&> pointPt = pt.get_child_optional("Point");
			if (pointPt)
			{
				SsPoint point;
				if (readPoint(point, pointPt.get()))
				{
					value.point = point;
				}
			}

			// String
			optional<std::string> str = pt.get_optional<std::string>("String");
			if (str)
			{
				std::string s = textenc::convert(str.get(), encoding, textenc::SHIFT_JIS);
				value.str = s;
			}
		
			ssValue = boost::shared_ptr<SsValue>(new SsUserDataValue(value));
		}
		else
		{
			optional<float> value = pt.get_optional<float>("Value");
			if (!value) break;
			
			float v = value.get();

			// 回転角は度で定義されているが、内部ではラジアンで持つ
			if (tag == SsAttributeTag::ANGL)
			{
				v = mathutil::degreeToRadian(v);
			}

			ssValue = boost::shared_ptr<SsValue>(new SsFloatValue(v));
		}
		if (!ssValue) break;
		

		// CurveTypeアトリビュート、無ければデフォルトはNone
		SsCurve::Type curveType = SsCurve::None;
		optional<int> curveTypeValue = pt.get_optional<int>("<xmlattr>.CurveType");
		if (curveTypeValue)
		{
            int type = curveTypeValue.get();
            if (type < 0 || type >= SsCurve::END_OF_TYPE) type = SsCurve::Linear;   // 不正値
			curveType = static_cast<SsCurve::Type>(type);
		}

		optional<float> curveStartT = pt.get_optional<float>("<xmlattr>.CurveStartT");
		optional<float> curveStartV = pt.get_optional<float>("<xmlattr>.CurveStartV");
		optional<float> curveEndT = pt.get_optional<float>("<xmlattr>.CurveEndT");
		optional<float> curveEndV = pt.get_optional<float>("<xmlattr>.CurveEndV");
        
		return shared_ptr<SsKeyframe>(
			curveStartT ?
			new SsKeyframe(time.get(), ssValue, curveType, curveStartT.get(), curveStartV.get(), curveEndT.get(), curveEndV.get()):
			new SsKeyframe(time.get(), ssValue, curveType)
		);

	} while (false);
	return shared_ptr<SsKeyframe>();
}
예제 #17
0
//------------------------------------------------------------------------------
void
WImage::_set(ptree n)
{
	if(n.get_child_optional("image"))
		this->setImage(kernel->graphicsMgr->loadImage(n.get_child("image")));
};
예제 #18
0
Option PipelineReader::parseElement_Option(const ptree& tree)
{
    // cur is an option element, such as this:
    //     <option>
    //       <name>myname</name>
    //       <description>my descr</description>
    //       <value>17</value>
    //     </option>
    // this function will process the element and return an Option from it

    map_t attrs;
    collect_attributes(attrs, tree);

    std::string name = attrs["name"];
    std::string value = tree.get_value<std::string>();
    boost::algorithm::trim(value);
    Option option(name, value);

    boost::optional<ptree const&> moreOptions =
        tree.get_child_optional("Options");

    if (moreOptions)
    {
        ptree::const_iterator iter = moreOptions->begin();

        Options options;
        while (iter != moreOptions->end())
        {
            if (iter->first == "Option")
            {
                Option o2 = parseElement_Option(iter->second);
                options.add(o2);
            }
            ++iter;
        }
        option.setOptions(options);
    }

    // filenames in the XML are fixed up as follows:
    //   - if absolute path, leave it alone
    //   - if relative path, make it absolute using the XML file's directory
    // The toAbsolutePath function does exactly that magic for us.
    if (option.getName() == "filename")
    {
        std::string path = option.getValue<std::string>();
#ifndef PDAL_PLATFORM_WIN32
        wordexp_t result;
        if (wordexp(path.c_str(), &result, 0) == 0)
        {
            if (result.we_wordc == 1)
                path = result.we_wordv[0];
        }
        wordfree(&result);
#endif
        if (!FileUtils::isAbsolutePath(path))
        {
            std::string abspath = FileUtils::toAbsolutePath(m_inputXmlFile);
            std::string absdir = FileUtils::getDirectory(abspath);
            path = FileUtils::toAbsolutePath(path, absdir);

            assert(FileUtils::isAbsolutePath(path));
        }
        option.setValue(path);
    }
    return option;
}