#include "lc_global.h" #include "object.h" lcObject::lcObject(lcObjectType ObjectType) : mObjectType(ObjectType) { } lcObject::~lcObject() { } template void lcObjectKeyArray::SaveKeysLDraw(QTextStream& Stream, const char* KeyName) const; template void lcObjectKeyArray::LoadKeysLDraw(QTextStream& Stream); template const float& lcObjectKeyArray::CalculateKey(lcStep Step) const; template void lcObjectKeyArray::ChangeKey(const float& Value, lcStep Step, bool AddKey); template void lcObjectKeyArray::InsertTime(lcStep Start, lcStep Time); template void lcObjectKeyArray::RemoveTime(lcStep Start, lcStep Time); template void lcObjectKeyArray::SaveKeysLDraw(QTextStream& Stream, const char* KeyName) const; template void lcObjectKeyArray::LoadKeysLDraw(QTextStream& Stream); template const lcVector3& lcObjectKeyArray::CalculateKey(lcStep Step) const; template void lcObjectKeyArray::ChangeKey(const lcVector3& Value, lcStep Step, bool AddKey); template void lcObjectKeyArray::InsertTime(lcStep Start, lcStep Time); template void lcObjectKeyArray::RemoveTime(lcStep Start, lcStep Time); template void lcObjectKeyArray::SaveKeysLDraw(QTextStream& Stream, const char* KeyName) const; template void lcObjectKeyArray::LoadKeysLDraw(QTextStream& Stream); template const lcVector4& lcObjectKeyArray::CalculateKey(lcStep Step) const; template void lcObjectKeyArray::ChangeKey(const lcVector4& Value, lcStep Step, bool AddKey); template void lcObjectKeyArray::InsertTime(lcStep Start, lcStep Time); template void lcObjectKeyArray::RemoveTime(lcStep Start, lcStep Time); template void lcObjectKeyArray::SaveKeysLDraw(QTextStream& Stream, const char* KeyName) const; template void lcObjectKeyArray::LoadKeysLDraw(QTextStream& Stream); template const lcMatrix33& lcObjectKeyArray::CalculateKey(lcStep Step) const; template void lcObjectKeyArray::ChangeKey(const lcMatrix33& Value, lcStep Step, bool AddKey); template void lcObjectKeyArray::InsertTime(lcStep Start, lcStep Time); template void lcObjectKeyArray::RemoveTime(lcStep Start, lcStep Time); template void lcObjectKeyArray::SaveKeysLDraw(QTextStream& Stream, const char* KeyName) const { constexpr int Count = sizeof(T) / sizeof(float); for (const lcObjectKey& Key : mKeys) { Stream << QLatin1String("0 !LEOCAD ") << KeyName << Key.Step << ' '; for (int ValueIdx = 0; ValueIdx < Count; ValueIdx++) Stream << ((float*)&Key.Value)[ValueIdx] << ' '; Stream << QLatin1String("\r\n"); } } template void lcObjectKeyArray::LoadKeysLDraw(QTextStream& Stream) { QString Token; Stream >> Token; const int Step = Token.toInt(); T Value; constexpr int Count = sizeof(T) / sizeof(float); for (int ValueIdx = 0; ValueIdx < Count; ValueIdx++) Stream >> ((float*)&Value)[ValueIdx]; ChangeKey(Value, Step, true); } template const T& lcObjectKeyArray::CalculateKey(lcStep Step) const { const lcObjectKey* PreviousKey = &mKeys[0]; for (const lcObjectKey& Key : mKeys) { if (Key.Step > Step) break; PreviousKey = &Key; } return PreviousKey->Value; } template void lcObjectKeyArray::ChangeKey(const T& Value, lcStep Step, bool AddKey) { for (typename std::vector>::iterator KeyIt = mKeys.begin(); KeyIt != mKeys.end(); KeyIt++) { if (KeyIt->Step < Step) continue; if (KeyIt->Step == Step) KeyIt->Value = Value; else if (AddKey) mKeys.insert(KeyIt, lcObjectKey{ Step, Value }); else if (KeyIt == mKeys.begin()) KeyIt->Value = Value; else { KeyIt = KeyIt - 1; KeyIt->Value = Value; } return; } if (AddKey || mKeys.empty()) mKeys.emplace_back(lcObjectKey{ Step, Value }); else mKeys.back().Value = Value; } template void lcObjectKeyArray::InsertTime(lcStep Start, lcStep Time) { bool EndKey = false; for (typename std::vector>::iterator KeyIt = mKeys.begin(); KeyIt != mKeys.end();) { if ((KeyIt->Step < Start) || (KeyIt->Step == 1)) { KeyIt++; continue; } if (EndKey) { KeyIt = mKeys.erase(KeyIt); continue; } if (KeyIt->Step >= LC_STEP_MAX - Time) { KeyIt->Step = LC_STEP_MAX; EndKey = true; } else KeyIt->Step += Time; KeyIt++; } } template void lcObjectKeyArray::RemoveTime(lcStep Start, lcStep Time) { for (typename std::vector>::iterator KeyIt = mKeys.begin(); KeyIt != mKeys.end();) { if ((KeyIt->Step < Start) || (KeyIt->Step == 1)) { KeyIt++; continue; } if (KeyIt->Step < Start + Time) { KeyIt = mKeys.erase(KeyIt); continue; } KeyIt->Step -= Time; KeyIt++; } }