141 continue; |
141 continue; |
142 |
142 |
143 Primitive info; |
143 Primitive info; |
144 info.name = fname.mid (m_baselen + 1); // make full path relative |
144 info.name = fname.mid (m_baselen + 1); // make full path relative |
145 info.name.replace ('/', '\\'); // use DOS backslashes, they're expected |
145 info.name.replace ('/', '\\'); // use DOS backslashes, they're expected |
146 info.cat = null; |
146 info.category = null; |
147 QByteArray titledata = f.readLine(); |
147 QByteArray titledata = f.readLine(); |
148 |
148 |
149 if (titledata != QByteArray()) |
149 if (titledata != QByteArray()) |
150 info.title = QString::fromUtf8 (titledata); |
150 info.title = QString::fromUtf8 (titledata); |
151 |
151 |
205 |
205 |
206 // ============================================================================= |
206 // ============================================================================= |
207 // |
207 // |
208 PrimitiveCategory::PrimitiveCategory (QString name, QObject* parent) : |
208 PrimitiveCategory::PrimitiveCategory (QString name, QObject* parent) : |
209 QObject (parent), |
209 QObject (parent), |
210 m_Name (name) {} |
210 m_name (name) {} |
211 |
211 |
212 // ============================================================================= |
212 // ============================================================================= |
213 // |
213 // |
214 void PrimitiveCategory::populateCategories() |
214 void PrimitiveCategory::populateCategories() |
215 { |
215 { |
218 |
218 |
219 |
219 |
220 for (Primitive& prim : g_primitives) |
220 for (Primitive& prim : g_primitives) |
221 { |
221 { |
222 bool matched = false; |
222 bool matched = false; |
223 prim.cat = null; |
223 prim.category = null; |
224 |
224 |
225 // Go over the categories and their regexes, if and when there's a match, |
225 // Go over the categories and their regexes, if and when there's a match, |
226 // the primitive's category is set to the category the regex beloings to. |
226 // the primitive's category is set to the category the regex beloings to. |
227 for (PrimitiveCategory* cat : g_PrimitiveCategories) |
227 for (PrimitiveCategory* cat : g_PrimitiveCategories) |
228 { |
228 { |
243 } break; |
243 } break; |
244 } |
244 } |
245 |
245 |
246 if (matched) |
246 if (matched) |
247 { |
247 { |
248 prim.cat = cat; |
248 prim.category = cat; |
249 break; |
249 break; |
250 } |
250 } |
251 } |
251 } |
252 |
252 |
253 // Drop out if a category was decided on. |
253 // Drop out if a category was decided on. |
254 if (prim.cat != null) |
254 if (prim.category != null) |
255 break; |
255 break; |
256 } |
256 } |
257 |
257 |
258 // If there was a match, add the primitive to the category. |
258 // If there was a match, add the primitive to the category. |
259 // Otherwise, add it to the list of unmatched primitives. |
259 // Otherwise, add it to the list of unmatched primitives. |
260 if (prim.cat != null) |
260 if (prim.category != null) |
261 prim.cat->prims << prim; |
261 prim.category->prims << prim; |
262 else |
262 else |
263 g_unmatched->prims << prim; |
263 g_unmatched->prims << prim; |
264 } |
264 } |
265 } |
265 } |
266 |
266 |
563 numer *= factor; |
563 numer *= factor; |
564 denom *= factor; |
564 denom *= factor; |
565 } |
565 } |
566 |
566 |
567 // Compose some general information: prefix, fraction, root, ring number |
567 // Compose some general information: prefix, fraction, root, ring number |
568 QString prefix = (divs == lores) ? "" : fmt ("%1/", divs); |
568 QString prefix = (divs == g_lores) ? "" : fmt ("%1/", divs); |
569 QString frac = fmt ("%1-%2", numer, denom); |
569 QString frac = fmt ("%1-%2", numer, denom); |
570 QString root = g_radialNameRoots[type]; |
570 QString root = g_radialNameRoots[type]; |
571 QString numstr = (type == Ring || type == Cone) ? fmt ("%1", num) : ""; |
571 QString numstr = (type == Ring || type == Cone) ? fmt ("%1", num) : ""; |
572 |
572 |
573 // Truncate the root if necessary (7-16rin4.dat for instance). |
573 // Truncate the root if necessary (7-16rin4.dat for instance). |
602 } |
602 } |
603 else |
603 else |
604 descr = fmt ("%1 %2", primitiveTypeName (type), frac); |
604 descr = fmt ("%1 %2", primitiveTypeName (type), frac); |
605 |
605 |
606 // Prepend "Hi-Res" if 48/ primitive. |
606 // Prepend "Hi-Res" if 48/ primitive. |
607 if (divs == hires) |
607 if (divs == g_hires) |
608 descr.insert (0, "Hi-Res "); |
608 descr.insert (0, "Hi-Res "); |
609 |
609 |
610 LDDocument* f = new LDDocument; |
610 LDDocument* f = new LDDocument; |
611 f->setDefaultName (name); |
611 f->setDefaultName (name); |
612 |
612 |
622 f->addObjects ( |
622 f->addObjects ( |
623 { |
623 { |
624 new LDComment (descr), |
624 new LDComment (descr), |
625 new LDComment (fmt ("Name: %1", name)), |
625 new LDComment (fmt ("Name: %1", name)), |
626 new LDComment (fmt ("Author: %1", author)), |
626 new LDComment (fmt ("Author: %1", author)), |
627 new LDComment (fmt ("!LDRAW_ORG Unofficial_%1Primitive", divs == hires ? "48_" : "")), |
627 new LDComment (fmt ("!LDRAW_ORG Unofficial_%1Primitive", divs == g_hires ? "48_" : "")), |
628 new LDComment (license), |
628 new LDComment (license), |
629 new LDEmpty, |
629 new LDEmpty, |
630 new LDBFC (LDBFC::CertifyCCW), |
630 new LDBFC (LDBFC::CertifyCCW), |
631 new LDEmpty, |
631 new LDEmpty, |
632 }); |
632 }); |
667 |
667 |
668 // ============================================================================= |
668 // ============================================================================= |
669 // |
669 // |
670 void PrimitivePrompt::hiResToggled (bool on) |
670 void PrimitivePrompt::hiResToggled (bool on) |
671 { |
671 { |
672 ui->sb_segs->setMaximum (on ? hires : lores); |
672 ui->sb_segs->setMaximum (on ? g_hires : g_lores); |
673 |
673 |
674 // If the current value is 16 and we switch to hi-res, default the |
674 // If the current value is 16 and we switch to hi-res, default the |
675 // spinbox to 48. |
675 // spinbox to 48. |
676 if (on && ui->sb_segs->value() == lores) |
676 if (on && ui->sb_segs->value() == g_lores) |
677 ui->sb_segs->setValue (hires); |
677 ui->sb_segs->setValue (g_hires); |
678 } |
678 } |
679 |
679 |
680 // ============================================================================= |
680 // ============================================================================= |
681 // |
681 // |
682 DEFINE_ACTION (MakePrimitive, 0) |
682 DEFINE_ACTION (MakePrimitive, 0) |
685 |
685 |
686 if (!dlg->exec()) |
686 if (!dlg->exec()) |
687 return; |
687 return; |
688 |
688 |
689 int segs = dlg->ui->sb_segs->value(); |
689 int segs = dlg->ui->sb_segs->value(); |
690 int divs = dlg->ui->cb_hires->isChecked() ? hires : lores; |
690 int divs = dlg->ui->cb_hires->isChecked() ? g_hires : g_lores; |
691 int num = dlg->ui->sb_ringnum->value(); |
691 int num = dlg->ui->sb_ringnum->value(); |
692 PrimitiveType type = |
692 PrimitiveType type = |
693 dlg->ui->rb_circle->isChecked() ? Circle : |
693 dlg->ui->rb_circle->isChecked() ? Circle : |
694 dlg->ui->rb_cylinder->isChecked() ? Cylinder : |
694 dlg->ui->rb_cylinder->isChecked() ? Cylinder : |
695 dlg->ui->rb_disc->isChecked() ? Disc : |
695 dlg->ui->rb_disc->isChecked() ? Disc : |