122 // ============================================================================= |
122 // ============================================================================= |
123 static void doInline (bool bDeep) { |
123 static void doInline (bool bDeep) { |
124 vector<LDObject*> sel = g_win->sel (); |
124 vector<LDObject*> sel = g_win->sel (); |
125 |
125 |
126 // History stuff |
126 // History stuff |
127 vector<LDSubfile*> paRefs; |
127 vector<LDSubfile*> refs; |
128 vector<ulong> ulaRefIndices, ulaBitIndices; |
128 vector<ulong> refIndices, bitIndices; |
129 |
129 |
130 for (LDObject* obj : sel) { |
130 for (LDObject* obj : sel) { |
131 if (obj->getType() != LDObject::Subfile) |
131 if (obj->getType() != LDObject::Subfile) |
132 continue; |
132 continue; |
133 |
133 |
134 ulaRefIndices.push_back (obj->getIndex (g_curfile)); |
134 refIndices.push_back (obj->getIndex (g_curfile)); |
135 paRefs.push_back (static_cast<LDSubfile*> (obj)->clone ()); |
135 refs.push_back (static_cast<LDSubfile*> (obj)->clone ()); |
136 } |
136 } |
137 |
137 |
138 for (LDObject* obj : sel) { |
138 for (LDObject* obj : sel) { |
139 // Get the index of the subfile so we know where to insert the |
139 // Get the index of the subfile so we know where to insert the |
140 // inlined contents. |
140 // inlined contents. |
151 else |
151 else |
152 continue; |
152 continue; |
153 |
153 |
154 // Merge in the inlined objects |
154 // Merge in the inlined objects |
155 for (LDObject* inlineobj : objs) { |
155 for (LDObject* inlineobj : objs) { |
156 ulaBitIndices.push_back (idx); |
156 bitIndices.push_back (idx); |
157 |
157 |
158 // This object is now inlined so it has no parent anymore. |
158 // This object is now inlined so it has no parent anymore. |
159 inlineobj->parent = null; |
159 inlineobj->parent = null; |
160 |
160 |
161 g_curfile->insertObj (idx++, inlineobj); |
161 g_curfile->insertObj (idx++, inlineobj); |
164 // Delete the subfile now as it's been inlined. |
164 // Delete the subfile now as it's been inlined. |
165 g_curfile->forgetObject (obj); |
165 g_curfile->forgetObject (obj); |
166 delete obj; |
166 delete obj; |
167 } |
167 } |
168 |
168 |
169 History::addEntry (new InlineHistory (ulaBitIndices, ulaRefIndices, paRefs, bDeep)); |
169 History::addEntry (new InlineHistory (bitIndices, refIndices, refs, bDeep)); |
170 g_win->refresh (); |
170 g_win->refresh (); |
171 } |
171 } |
172 |
172 |
173 MAKE_ACTION (inlineContents, "Inline", "inline", "Inline selected subfiles.", CTRL (I)) { |
173 MAKE_ACTION (inlineContents, "Inline", "inline", "Inline selected subfiles.", CTRL (I)) { |
174 doInline (false); |
174 doInline (false); |
178 "down to polygons only.", CTRL_SHIFT (I)) |
178 "down to polygons only.", CTRL_SHIFT (I)) |
179 { |
179 { |
180 doInline (true); |
180 doInline (true); |
181 } |
181 } |
182 |
182 |
183 // ============================================================================= |
183 // ======================================================================================================================================= |
184 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
184 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
185 // ============================================================================= |
185 // ======================================================================================================================================= |
|
186 MAKE_ACTION (radialResolution, "Radial resolution", "radial-resolve", "Resolve radials into primitives.", (0)) { |
|
187 vector<str> fails; |
|
188 vector<LDObject*> sel = g_win->sel (); |
|
189 EditHistory* history = new EditHistory; |
|
190 |
|
191 for (LDObject* obj : sel) { |
|
192 if (obj->getType() != LDObject::Radial) |
|
193 continue; |
|
194 |
|
195 LDRadial* rad = static_cast<LDRadial*> (obj); |
|
196 str name = rad->makeFileName (); |
|
197 |
|
198 OpenFile* file = loadSubfile (name); |
|
199 if (file == null) { |
|
200 fails.push_back (name); |
|
201 continue; |
|
202 } |
|
203 |
|
204 // Create the replacement primitive. |
|
205 LDSubfile* prim = new LDSubfile; |
|
206 memcpy (&prim->vPosition, &rad->vPosition, sizeof rad->vPosition); // inherit position |
|
207 memcpy (&prim->mMatrix, &rad->mMatrix, sizeof rad->mMatrix); // inherit matrix |
|
208 prim->dColor = rad->dColor; // inherit color |
|
209 prim->zFileName = name; |
|
210 prim->pFile = file; |
|
211 |
|
212 // Add the history entry - this must be done while both objects are still valid. |
|
213 history->addEntry (rad, prim); |
|
214 |
|
215 // Replace the radial with the primitive. |
|
216 rad->replace (prim); |
|
217 } |
|
218 |
|
219 // If it was not possible to replace everything, inform the user. |
|
220 if (fails.size() > 0) { |
|
221 str errmsg = fmt ("Couldn't replace %lu radials as replacement subfiles could not be loaded:<br />", (ulong)fails.size ()); |
|
222 |
|
223 for (str& fail : fails) |
|
224 errmsg += fmt ("* %s<br />", fail.chars ()); |
|
225 |
|
226 critical (errmsg); |
|
227 } |
|
228 |
|
229 History::addEntry (history); |
|
230 g_win->refresh (); |
|
231 } |
|
232 |
|
233 // ======================================================================================================================================= |
|
234 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
|
235 // ======================================================================================================================================= |
186 MAKE_ACTION (splitQuads, "Split Quads", "quad-split", "Split quads into triangles.", (0)) { |
236 MAKE_ACTION (splitQuads, "Split Quads", "quad-split", "Split quads into triangles.", (0)) { |
187 vector<LDObject*> objs = g_win->sel (); |
237 vector<LDObject*> objs = g_win->sel (); |
188 |
238 |
189 vector<ulong> ulaIndices; |
239 vector<ulong> ulaIndices; |
190 vector<LDQuad*> paCopies; |
240 vector<LDQuad*> paCopies; |