src/parser.cpp

changeset 1398
1c70d3447d20
parent 1397
5d5c11af0268
child 1399
f52ea4078f5d
equal deleted inserted replaced
1397:5d5c11af0268 1398:1c70d3447d20
22 #include "linetypes/conditionaledge.h" 22 #include "linetypes/conditionaledge.h"
23 #include "linetypes/edgeline.h" 23 #include "linetypes/edgeline.h"
24 #include "linetypes/empty.h" 24 #include "linetypes/empty.h"
25 #include "linetypes/quadrilateral.h" 25 #include "linetypes/quadrilateral.h"
26 #include "linetypes/triangle.h" 26 #include "linetypes/triangle.h"
27 #include "linetypes/cylinder.h" 27 #include "linetypes/circularprimitive.h"
28 28
29 /* 29 /*
30 * Constructs an LDraw parser 30 * Constructs an LDraw parser
31 */ 31 */
32 Parser::Parser(QIODevice& device, QObject* parent) : 32 Parser::Parser(QIODevice& device, QObject* parent) :
387 QString referenceName = tokens[14]; 387 QString referenceName = tokens[14];
388 388
389 for (int i = 0; i < 9; ++i) 389 for (int i = 0; i < 9; ++i)
390 transform.value(i) = tokens[i + 5].toDouble(); // 5 - 13 390 transform.value(i) = tokens[i + 5].toDouble(); // 5 - 13
391 391
392 static const QRegExp cylinderRegexp {R"((?:(\d+)\\)?(\d+)-(\d+)cyli\.dat)"}; 392 static const QRegExp circularPrimitiveRegexp {R"((?:(\d+)\\)?(\d+)-(\d+)(cyli|edge)\.dat)"};
393 LDObject* obj; 393 LDObject* obj;
394 394
395 if (cylinderRegexp.exactMatch(referenceName)) 395 if (circularPrimitiveRegexp.exactMatch(referenceName))
396 { 396 {
397 int resolution = MediumResolution; 397 int resolution = MediumResolution;
398 398
399 if (not cylinderRegexp.capturedTexts()[1].isEmpty()) 399 if (not circularPrimitiveRegexp.capturedTexts()[1].isEmpty())
400 resolution = cylinderRegexp.capturedTexts()[1].toInt(); 400 resolution = circularPrimitiveRegexp.capturedTexts()[1].toInt();
401 401
402 int numerator = cylinderRegexp.capturedTexts()[2].toInt(); 402 int numerator = circularPrimitiveRegexp.capturedTexts()[2].toInt();
403 int denominator = cylinderRegexp.capturedTexts()[3].toInt(); 403 int denominator = circularPrimitiveRegexp.capturedTexts()[3].toInt();
404 int segments = (numerator * resolution) / denominator; 404 int segments = (numerator * resolution) / denominator;
405 obj = model.emplaceAt<LDCylinder>(position, segments, resolution, transform, displacement); 405 PrimitiveModel::Type type = PrimitiveModel::Cylinder;
406
407 if (circularPrimitiveRegexp.capturedTexts()[4] == "edge")
408 type = PrimitiveModel::Circle;
409
410 obj = model.emplaceAt<LDCircularPrimitive>(
411 position,
412 type,
413 segments,
414 resolution,
415 transform,
416 displacement
417 );
406 } 418 }
407 else 419 else
408 { 420 {
409 obj = model.emplaceAt<LDSubfileReference>(position, referenceName, transform, displacement); 421 obj = model.emplaceAt<LDSubfileReference>(position, referenceName, transform, displacement);
410 } 422 }

mercurial