194 void LDObject::replace (LDObject* other) { |
194 void LDObject::replace (LDObject* other) { |
195 long idx = getIndex(); |
195 long idx = getIndex(); |
196 assert (idx != -1); |
196 assert (idx != -1); |
197 |
197 |
198 // Replace the instance of the old object with the new object |
198 // Replace the instance of the old object with the new object |
199 LDOpenFile::current()->setObject (idx, other); |
199 LDFile::current()->setObject (idx, other); |
200 |
200 |
201 // Remove the old object |
201 // Remove the old object |
202 delete this; |
202 delete this; |
203 } |
203 } |
204 |
204 |
205 // ============================================================================= |
205 // ============================================================================= |
206 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
206 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
207 // ============================================================================= |
207 // ============================================================================= |
208 void LDObject::swap (LDObject* other) { |
208 void LDObject::swap (LDObject* other) { |
209 for (LDObject*& obj : *LDOpenFile::current()) { |
209 for (LDObject*& obj : *LDFile::current()) { |
210 if (obj == this) |
210 if (obj == this) |
211 obj = other; |
211 obj = other; |
212 elif (obj == other) |
212 elif (obj == other) |
213 obj = this; |
213 obj = this; |
214 } |
214 } |
215 |
215 |
216 LDOpenFile::current()->addToHistory (new SwapHistory (id(), other->id())); |
216 LDFile::current()->addToHistory (new SwapHistory (id(), other->id())); |
217 } |
217 } |
218 |
218 |
219 LDLineObject::LDLineObject (vertex v1, vertex v2) { |
219 LDLineObject::LDLineObject (vertex v1, vertex v2) { |
220 setVertex (0, v1); |
220 setVertex (0, v1); |
221 setVertex (1, v2); |
221 setVertex (1, v2); |
359 LDObject* obj = objs[i]; |
359 LDObject* obj = objs[i]; |
360 |
360 |
361 const long idx = obj->getIndex(), |
361 const long idx = obj->getIndex(), |
362 target = idx + (up ? -1 : 1); |
362 target = idx + (up ? -1 : 1); |
363 |
363 |
364 if ((up && idx == 0) || (!up && idx == (long) (LDOpenFile::current()->objs().size() - 1))) { |
364 if ((up && idx == 0) || (!up && idx == (long) (LDFile::current()->objs().size() - 1))) { |
365 // One of the objects hit the extrema. If this happens, this should be the first |
365 // One of the objects hit the extrema. If this happens, this should be the first |
366 // object to be iterated on. Thus, nothing has changed yet and it's safe to just |
366 // object to be iterated on. Thus, nothing has changed yet and it's safe to just |
367 // abort the entire operation. |
367 // abort the entire operation. |
368 assert (i == start); |
368 assert (i == start); |
369 return; |
369 return; |
370 } |
370 } |
371 |
371 |
372 objsToCompile << obj; |
372 objsToCompile << obj; |
373 objsToCompile << LDOpenFile::current()->obj (target); |
373 objsToCompile << LDFile::current()->obj (target); |
374 |
374 |
375 obj->swap (LDOpenFile::current()->obj (target)); |
375 obj->swap (LDFile::current()->obj (target)); |
376 } |
376 } |
377 |
377 |
378 objsToCompile.makeUnique(); |
378 objsToCompile.makeUnique(); |
379 |
379 |
380 // The objects need to be recompiled, otherwise their pick lists are left with |
380 // The objects need to be recompiled, otherwise their pick lists are left with |
443 // ============================================================================= |
443 // ============================================================================= |
444 LDObject* LDObject::next() const { |
444 LDObject* LDObject::next() const { |
445 long idx = getIndex(); |
445 long idx = getIndex(); |
446 assert (idx != -1); |
446 assert (idx != -1); |
447 |
447 |
448 if (idx == (long) LDOpenFile::current()->numObjs() - 1) |
448 if (idx == (long) LDFile::current()->numObjs() - 1) |
449 return null; |
449 return null; |
450 |
450 |
451 return LDOpenFile::current()->obj (idx + 1); |
451 return LDFile::current()->obj (idx + 1); |
452 } |
452 } |
453 |
453 |
454 // ============================================================================= |
454 // ============================================================================= |
455 LDObject* LDObject::prev() const { |
455 LDObject* LDObject::prev() const { |
456 long idx = getIndex(); |
456 long idx = getIndex(); |
457 assert (idx != -1); |
457 assert (idx != -1); |
458 |
458 |
459 if (idx == 0) |
459 if (idx == 0) |
460 return null; |
460 return null; |
461 |
461 |
462 return LDOpenFile::current()->obj (idx - 1); |
462 return LDFile::current()->obj (idx - 1); |
463 } |
463 } |
464 |
464 |
465 // ============================================================================= |
465 // ============================================================================= |
466 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
466 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
467 // ============================================================================= |
467 // ============================================================================= |
562 if (idx > 0) { |
562 if (idx > 0) { |
563 LDBFCObject* bfc = dynamic_cast<LDBFCObject*> (prev()); |
563 LDBFCObject* bfc = dynamic_cast<LDBFCObject*> (prev()); |
564 |
564 |
565 if (bfc && bfc->type == LDBFCObject::InvertNext) { |
565 if (bfc && bfc->type == LDBFCObject::InvertNext) { |
566 // This is prefixed with an invertnext, thus remove it. |
566 // This is prefixed with an invertnext, thus remove it. |
567 LDOpenFile::current()->forgetObject (bfc); |
567 LDFile::current()->forgetObject (bfc); |
568 delete bfc; |
568 delete bfc; |
569 return; |
569 return; |
570 } |
570 } |
571 } |
571 } |
572 |
572 |
573 // Not inverted, thus prefix it with a new invertnext. |
573 // Not inverted, thus prefix it with a new invertnext. |
574 LDBFCObject* bfc = new LDBFCObject (LDBFCObject::InvertNext); |
574 LDBFCObject* bfc = new LDBFCObject (LDBFCObject::InvertNext); |
575 LDOpenFile::current()->insertObj (idx, bfc); |
575 LDFile::current()->insertObj (idx, bfc); |
576 } |
576 } |
577 |
577 |
578 static void invertLine (LDObject* line) { |
578 static void invertLine (LDObject* line) { |
579 // For lines, we swap the vertices. I don't think that a |
579 // For lines, we swap the vertices. I don't think that a |
580 // cond-line's control points need to be swapped, do they? |
580 // cond-line's control points need to be swapped, do they? |
636 if (obj->file() && (idx = obj->getIndex()) != -1) { |
636 if (obj->file() && (idx = obj->getIndex()) != -1) { |
637 str before = obj->raw(); |
637 str before = obj->raw(); |
638 *ptr = val; |
638 *ptr = val; |
639 str after = obj->raw(); |
639 str after = obj->raw(); |
640 |
640 |
641 LDOpenFile::current()->addToHistory (new EditHistory (idx, before, after)); |
641 LDFile::current()->addToHistory (new EditHistory (idx, before, after)); |
642 } else |
642 } else |
643 *ptr = val; |
643 *ptr = val; |
644 } |
644 } |
645 |
645 |
646 READ_ACCESSOR (short, LDObject::color) { |
646 READ_ACCESSOR (short, LDObject::color) { |