src/parser.cpp

changeset 242
16855456992d
parent 206
654661eab7f3
child 259
c27612f0eac0
--- a/src/parser.cpp	Mon Jun 20 22:21:53 2022 +0300
+++ b/src/parser.cpp	Mon Jun 20 22:22:15 2022 +0300
@@ -139,7 +139,7 @@
 	return {line.mid(1).trimmed()};
 }
 
-static Colored<SubfileReference> parseType1Line(const QStringList& tokens)
+static ModelElement parseType1Line(const QStringList& tokens)
 {
 	constexpr int colorPosition = 1;
 	constexpr int positionPosition = 2; // 2..4
@@ -152,6 +152,23 @@
 	const ldraw::Color color = colorFromString(tokens[colorPosition]);
 	const glm::mat4 transform = matrixFromStrings(tokens, transformPosition, positionPosition);
 	const QString& name = tokens[namePosition];
+	static QRegExp re{R"((?:(\d+)\\)?(\d+)-(\d)+([a-z]+)\.dat)"};
+	if (re.exactMatch(name)) {
+		const auto p = std::find(std::begin(circularPrimitiveStems), std::end(circularPrimitiveStems), re.cap(4));
+		const unsigned int divisions = (re.cap(1).isEmpty()) ? 16 : re.cap(1).toUInt();
+		const unsigned int segments = re.cap(2).toUInt() * divisions / re.cap(3).toUInt();
+		if (p != std::end(circularPrimitiveStems)) {
+			const auto type = static_cast<CircularPrimitive::Type>(p - std::begin(circularPrimitiveStems));
+			return Colored<CircularPrimitive>{
+				CircularPrimitive{
+					.type = type,
+					.fraction = {segments, divisions},
+					.transformation = transform,
+				},
+				color,
+			};
+		}
+	}
 	return Colored<SubfileReference>{
 		{
 			.name = name,

mercurial