src/linetypes/circularprimitive.cpp

changeset 1399
f52ea4078f5d
parent 1398
1c70d3447d20
child 1400
ae83213bdd63
equal deleted inserted replaced
1398:1c70d3447d20 1399:f52ea4078f5d
15 if (m_divisions != MediumResolution) 15 if (m_divisions != MediumResolution)
16 prefix = QString::number(m_divisions) + '\\'; 16 prefix = QString::number(m_divisions) + '\\';
17 17
18 simplify(numerator, denominator); 18 simplify(numerator, denominator);
19 19
20 switch (m_type) 20 // Ensure that the denominator is at least 4, expand if necessary
21 { 21 if (denominator < 4)
22 case PrimitiveModel::Cylinder: 22 {
23 return format("%1%2-%3cyli.dat", prefix, numerator, denominator); 23 numerator = static_cast<int>(round(numerator * 4.0 / denominator));
24 24 denominator = 4;
25 case PrimitiveModel::Circle: 25 }
26 return format("%1%2-%3edge.dat", prefix, numerator, denominator); 26
27 27 return format("%1%2-%3%4.dat", prefix, numerator, denominator, stem());
28 default:
29 Q_ASSERT(false);
30 return "";
31 }
32 } 28 }
33 29
34 LDCircularPrimitive::LDCircularPrimitive( 30 LDCircularPrimitive::LDCircularPrimitive(
35 PrimitiveModel::Type type, 31 PrimitiveModel::Type type,
36 int segments, 32 int segments,
68 vertices.insert(vertex); 64 vertices.insert(vertex);
69 } 65 }
70 } 66 }
71 } 67 }
72 68
73 bool LDCircularPrimitive::isRasterizable() const { return true; } 69 bool LDCircularPrimitive::isRasterizable() const
70 {
71 return true;
72 }
74 73
75 void LDCircularPrimitive::rasterize( 74 void LDCircularPrimitive::rasterize(
76 DocumentManager* context, 75 DocumentManager* context,
77 Winding /* parentWinding */, 76 Winding /* parentWinding */,
78 Model& model, 77 Model& model,
135 primitive.divisions = m_divisions; 134 primitive.divisions = m_divisions;
136 primitive.ringNumber = 0; 135 primitive.ringNumber = 0;
137 primitive.generateBody(model); 136 primitive.generateBody(model);
138 } 137 }
139 138
139 QString LDCircularPrimitive::stem() const
140 {
141 switch (m_type)
142 {
143 case PrimitiveModel::Cylinder:
144 return "cyli";
145
146 case PrimitiveModel::Circle:
147 return "edge";
148
149 case PrimitiveModel::Disc:
150 return "disc";
151
152 case PrimitiveModel::DiscNegative:
153 return "ndis";
154
155 default:
156 throw std::logic_error("Bad primitive type to LDCircularPrimitive");
157 }
158 }
159
140 QString LDCircularPrimitive::objectListText() const 160 QString LDCircularPrimitive::objectListText() const
141 { 161 {
142 QString result = format( 162 QString result = format(
143 "%1 %2 %3, (", 163 "%1 %2 %3, (",
144 PrimitiveModel::typeName(m_type), 164 PrimitiveModel::typeName(m_type),

mercurial