137 static Comment parseType0Line(const QString& line) |
137 static Comment parseType0Line(const QString& line) |
138 { |
138 { |
139 return {line.mid(1).trimmed()}; |
139 return {line.mid(1).trimmed()}; |
140 } |
140 } |
141 |
141 |
142 static Colored<SubfileReference> parseType1Line(const QStringList& tokens) |
142 static ModelElement parseType1Line(const QStringList& tokens) |
143 { |
143 { |
144 constexpr int colorPosition = 1; |
144 constexpr int colorPosition = 1; |
145 constexpr int positionPosition = 2; // 2..4 |
145 constexpr int positionPosition = 2; // 2..4 |
146 constexpr int transformPosition = 5; // 5..13 |
146 constexpr int transformPosition = 5; // 5..13 |
147 constexpr int namePosition = 14; |
147 constexpr int namePosition = 14; |
150 throw BodyParseError{"wrong amount of tokens in a type-1 line"}; |
150 throw BodyParseError{"wrong amount of tokens in a type-1 line"}; |
151 } |
151 } |
152 const ldraw::Color color = colorFromString(tokens[colorPosition]); |
152 const ldraw::Color color = colorFromString(tokens[colorPosition]); |
153 const glm::mat4 transform = matrixFromStrings(tokens, transformPosition, positionPosition); |
153 const glm::mat4 transform = matrixFromStrings(tokens, transformPosition, positionPosition); |
154 const QString& name = tokens[namePosition]; |
154 const QString& name = tokens[namePosition]; |
|
155 static QRegExp re{R"((?:(\d+)\\)?(\d+)-(\d)+([a-z]+)\.dat)"}; |
|
156 if (re.exactMatch(name)) { |
|
157 const auto p = std::find(std::begin(circularPrimitiveStems), std::end(circularPrimitiveStems), re.cap(4)); |
|
158 const unsigned int divisions = (re.cap(1).isEmpty()) ? 16 : re.cap(1).toUInt(); |
|
159 const unsigned int segments = re.cap(2).toUInt() * divisions / re.cap(3).toUInt(); |
|
160 if (p != std::end(circularPrimitiveStems)) { |
|
161 const auto type = static_cast<CircularPrimitive::Type>(p - std::begin(circularPrimitiveStems)); |
|
162 return Colored<CircularPrimitive>{ |
|
163 CircularPrimitive{ |
|
164 .type = type, |
|
165 .fraction = {segments, divisions}, |
|
166 .transformation = transform, |
|
167 }, |
|
168 color, |
|
169 }; |
|
170 } |
|
171 } |
155 return Colored<SubfileReference>{ |
172 return Colored<SubfileReference>{ |
156 { |
173 { |
157 .name = name, |
174 .name = name, |
158 .transformation = transform, |
175 .transformation = transform, |
159 }, |
176 }, |