mirror of
https://github.com/leozide/leocad
synced 2024-12-26 21:58:44 +01:00
Added serialization helper functions.
This commit is contained in:
parent
ff313d4675
commit
c2199eb6b0
5 changed files with 129 additions and 189 deletions
|
@ -142,20 +142,9 @@ void lcCamera::SaveLDraw(QTextStream& Stream) const
|
||||||
|
|
||||||
Stream << QLatin1String("0 !LEOCAD CAMERA FOV ") << m_fovy << QLatin1String(" ZNEAR ") << m_zNear << QLatin1String(" ZFAR ") << m_zFar << LineEnding;
|
Stream << QLatin1String("0 !LEOCAD CAMERA FOV ") << m_fovy << QLatin1String(" ZNEAR ") << m_zNear << QLatin1String(" ZFAR ") << m_zFar << LineEnding;
|
||||||
|
|
||||||
if (mPositionKeys.GetSize() > 1)
|
SaveAttribute(Stream, mPosition, mPositionKeys, "CAMERA", "POSITION");
|
||||||
mPositionKeys.SaveKeysLDraw(Stream, "CAMERA POSITION_KEY ");
|
SaveAttribute(Stream, mTargetPosition, mTargetPositionKeys, "CAMERA", "TARGET_POSITION");
|
||||||
else
|
SaveAttribute(Stream, mUpVector, mUpVectorKeys, "CAMERA", "UP_VECTOR");
|
||||||
Stream << QLatin1String("0 !LEOCAD CAMERA POSITION ") << mPosition[0] << ' ' << mPosition[1] << ' ' << mPosition[2] << LineEnding;
|
|
||||||
|
|
||||||
if (mTargetPositionKeys.GetSize() > 1)
|
|
||||||
mTargetPositionKeys.SaveKeysLDraw(Stream, "CAMERA TARGET_POSITION_KEY ");
|
|
||||||
else
|
|
||||||
Stream << QLatin1String("0 !LEOCAD CAMERA TARGET_POSITION ") << mTargetPosition[0] << ' ' << mTargetPosition[1] << ' ' << mTargetPosition[2] << LineEnding;
|
|
||||||
|
|
||||||
if (mUpVectorKeys.GetSize() > 1)
|
|
||||||
mUpVectorKeys.SaveKeysLDraw(Stream, "CAMERA UP_VECTOR_KEY ");
|
|
||||||
else
|
|
||||||
Stream << QLatin1String("0 !LEOCAD CAMERA UP_VECTOR ") << mUpVector[0] << ' ' << mUpVector[1] << ' ' << mUpVector[2] << LineEnding;
|
|
||||||
|
|
||||||
Stream << QLatin1String("0 !LEOCAD CAMERA ");
|
Stream << QLatin1String("0 !LEOCAD CAMERA ");
|
||||||
|
|
||||||
|
@ -176,7 +165,7 @@ bool lcCamera::ParseLDrawLine(QTextStream& Stream)
|
||||||
Stream >> Token;
|
Stream >> Token;
|
||||||
|
|
||||||
if (Token == QLatin1String("HIDDEN"))
|
if (Token == QLatin1String("HIDDEN"))
|
||||||
SetHidden(true);
|
SetHidden(true);
|
||||||
else if (Token == QLatin1String("ORTHOGRAPHIC"))
|
else if (Token == QLatin1String("ORTHOGRAPHIC"))
|
||||||
SetOrtho(true);
|
SetOrtho(true);
|
||||||
else if (Token == QLatin1String("FOV"))
|
else if (Token == QLatin1String("FOV"))
|
||||||
|
@ -185,27 +174,12 @@ bool lcCamera::ParseLDrawLine(QTextStream& Stream)
|
||||||
Stream >> m_zNear;
|
Stream >> m_zNear;
|
||||||
else if (Token == QLatin1String("ZFAR"))
|
else if (Token == QLatin1String("ZFAR"))
|
||||||
Stream >> m_zFar;
|
Stream >> m_zFar;
|
||||||
else if (Token == QLatin1String("POSITION"))
|
else if (LoadAttribute(Stream, Token, mPosition, mPositionKeys, "POSITION"))
|
||||||
{
|
continue;
|
||||||
Stream >> mPosition[0] >> mPosition[1] >> mPosition[2];
|
else if (LoadAttribute(Stream, Token, mTargetPosition, mTargetPositionKeys, "TARGET_POSITION"))
|
||||||
mPositionKeys.ChangeKey(mPosition, 1, true);
|
continue;
|
||||||
}
|
else if (LoadAttribute(Stream, Token, mUpVector, mUpVectorKeys, "UP_VECTOR"))
|
||||||
else if (Token == QLatin1String("TARGET_POSITION"))
|
continue;
|
||||||
{
|
|
||||||
Stream >> mTargetPosition[0] >> mTargetPosition[1] >> mTargetPosition[2];
|
|
||||||
mTargetPositionKeys.ChangeKey(mTargetPosition, 1, true);
|
|
||||||
}
|
|
||||||
else if (Token == QLatin1String("UP_VECTOR"))
|
|
||||||
{
|
|
||||||
Stream >> mUpVector[0] >> mUpVector[1] >> mUpVector[2];
|
|
||||||
mUpVectorKeys.ChangeKey(mUpVector, 1, true);
|
|
||||||
}
|
|
||||||
else if (Token == QLatin1String("POSITION_KEY"))
|
|
||||||
mPositionKeys.LoadKeysLDraw(Stream);
|
|
||||||
else if (Token == QLatin1String("TARGET_POSITION_KEY"))
|
|
||||||
mTargetPositionKeys.LoadKeysLDraw(Stream);
|
|
||||||
else if (Token == QLatin1String("UP_VECTOR_KEY"))
|
|
||||||
mUpVectorKeys.LoadKeysLDraw(Stream);
|
|
||||||
else if (Token == QLatin1String("NAME"))
|
else if (Token == QLatin1String("NAME"))
|
||||||
{
|
{
|
||||||
mName = Stream.readAll().trimmed();
|
mName = Stream.readAll().trimmed();
|
||||||
|
|
142
common/light.cpp
142
common/light.cpp
|
@ -144,52 +144,33 @@ void lcLight::SaveLDraw(QTextStream& Stream) const
|
||||||
const float Numbers[12] = { Matrix[12], -Matrix[14], Matrix[13], Matrix[0], -Matrix[8], Matrix[4], -Matrix[2], Matrix[10], -Matrix[6], Matrix[1], -Matrix[9], Matrix[5] };
|
const float Numbers[12] = { Matrix[12], -Matrix[14], Matrix[13], Matrix[0], -Matrix[8], Matrix[4], -Matrix[2], Matrix[10], -Matrix[6], Matrix[1], -Matrix[9], Matrix[5] };
|
||||||
|
|
||||||
if (mPositionKeys.GetSize() > 1)
|
if (mPositionKeys.GetSize() > 1)
|
||||||
mPositionKeys.SaveKeysLDraw(Stream, "LIGHT POSITION_KEY ");
|
mPositionKeys.SaveKeysLDraw(Stream, "LIGHT", "POSITION");
|
||||||
else
|
else
|
||||||
Stream << QLatin1String("0 !LEOCAD LIGHT POSITION ") << Numbers[0] << ' ' << Numbers[1] << ' ' << Numbers[2] << LineEnding;
|
Stream << QLatin1String("0 !LEOCAD LIGHT POSITION ") << Numbers[0] << ' ' << Numbers[1] << ' ' << Numbers[2] << LineEnding;
|
||||||
|
|
||||||
if (!IsPointLight())
|
if (!IsPointLight())
|
||||||
{
|
{
|
||||||
if (mRotationKeys.GetSize() > 1)
|
if (mRotationKeys.GetSize() > 1)
|
||||||
mRotationKeys.SaveKeysLDraw(Stream, "LIGHT ROTATION_KEY ");
|
mRotationKeys.SaveKeysLDraw(Stream, "LIGHT", "ROTATION");
|
||||||
else
|
else
|
||||||
Stream << QLatin1String("0 !LEOCAD LIGHT ROTATION ") << Numbers[3] << ' ' << Numbers[4] << ' ' << Numbers[5] << ' ' << Numbers[6] << ' ' << Numbers[7] << ' ' << Numbers[8] << ' ' << Numbers[9] << ' ' << Numbers[10] << ' ' << Numbers[11] << LineEnding;
|
Stream << QLatin1String("0 !LEOCAD LIGHT ROTATION ") << Numbers[3] << ' ' << Numbers[4] << ' ' << Numbers[5] << ' ' << Numbers[6] << ' ' << Numbers[7] << ' ' << Numbers[8] << ' ' << Numbers[9] << ' ' << Numbers[10] << ' ' << Numbers[11] << LineEnding;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mColorKeys.GetSize() > 1)
|
SaveAttribute(Stream, mColor, mColorKeys, "LIGHT", "COLOR");
|
||||||
mColorKeys.SaveKeysLDraw(Stream, "LIGHT COLOR_KEY ");
|
SaveAttribute(Stream, mSize, mSizeKeys, "LIGHT", "SIZE");
|
||||||
else
|
SaveAttribute(Stream, mPower, mPowerKeys, "LIGHT", "POWER");
|
||||||
Stream << QLatin1String("0 !LEOCAD LIGHT COLOR ") << mColor[0] << ' ' << mColor[1] << ' ' << mColor[2] << LineEnding;
|
|
||||||
|
|
||||||
if (mSizeKeys.GetSize() > 1)
|
|
||||||
mSizeKeys.SaveKeysLDraw(Stream, "LIGHT SIZE_KEY ");
|
|
||||||
else
|
|
||||||
Stream << QLatin1String("0 !LEOCAD LIGHT SIZE ") << mSize[0] << mSize[1] << LineEnding;
|
|
||||||
|
|
||||||
if (!mPOVRayLight)
|
if (!mPOVRayLight)
|
||||||
{
|
{
|
||||||
if (mLightDiffuseKeys.GetSize() > 1)
|
SaveAttribute(Stream, mLightDiffuse, mLightDiffuseKeys, "LIGHT", "DIFFUSE");
|
||||||
mLightDiffuseKeys.SaveKeysLDraw(Stream, "LIGHT DIFFUSE_KEY ");
|
SaveAttribute(Stream, mLightSpecular, mLightSpecularKeys, "LIGHT", "SPECULAR");
|
||||||
else
|
|
||||||
Stream << QLatin1String("0 !LEOCAD LIGHT DIFFUSE ") << mLightDiffuse << LineEnding;
|
|
||||||
|
|
||||||
if (mLightSpecularKeys.GetSize() > 1)
|
|
||||||
mLightSpecularKeys.SaveKeysLDraw(Stream, "LIGHT SPECULAR_KEY ");
|
|
||||||
else
|
|
||||||
Stream << QLatin1String("0 !LEOCAD LIGHT SPECULAR ") << mLightSpecular << LineEnding;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mSpotExponentKeys.GetSize() > 1)
|
// SaveAttribute(Stream, (mPOVRayLight ? mPOVRayExponent : mSpotExponent), mSpotExponentKeys, "LIGHT", "POWER");
|
||||||
mSpotExponentKeys.SaveKeysLDraw(Stream, "LIGHT POWER_KEY ");
|
|
||||||
else
|
|
||||||
Stream << QLatin1String("0 !LEOCAD LIGHT POWER ") << (mPOVRayLight ? mPOVRayExponent : mSpotExponent) << LineEnding;
|
|
||||||
|
|
||||||
if (mEnableCutoff && !mPOVRayLight)
|
if (mEnableCutoff && !mPOVRayLight)
|
||||||
{
|
{
|
||||||
if (mSpotCutoffKeys.GetSize() > 1)
|
SaveAttribute(Stream, mSpotCutoff, mSpotCutoffKeys, "LIGHT", "CUTOFF_DISTANCE");
|
||||||
mSpotCutoffKeys.SaveKeysLDraw(Stream, "LIGHT CUTOFF_DISTANCE_KEY ");
|
|
||||||
else
|
|
||||||
Stream << QLatin1String("0 !LEOCAD LIGHT CUTOFF_DISTANCE ") << mSpotCutoff << LineEnding;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (mLightType)
|
switch (mLightType)
|
||||||
|
@ -199,39 +180,18 @@ void lcLight::SaveLDraw(QTextStream& Stream) const
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case lcLightType::Spot:
|
case lcLightType::Spot:
|
||||||
if (mSpotConeAngleKeys.GetSize() > 1)
|
SaveAttribute(Stream, mSpotConeAngle, mSpotConeAngleKeys, "LIGHT", "SPOT_CONE_ANGLE");
|
||||||
mSpotConeAngleKeys.SaveKeysLDraw(Stream, "LIGHT SPOT_CONE_ANGLE_KEY ");
|
SaveAttribute(Stream, mSpotPenumbraAngle, mSpotPenumbraAngleKeys, "LIGHT", "SPOT_PENUMBRA_ANGLE");
|
||||||
else
|
SaveAttribute(Stream, mSpotTightness, mSpotTightnessKeys, "LIGHT", "SPOT_TIGHTNESS");
|
||||||
Stream << QLatin1String("0 !LEOCAD LIGHT SPOT_CONE_ANGLE ") << mSpotConeAngle << LineEnding;
|
|
||||||
|
|
||||||
if (mSpotPenumbraAngleKeys.GetSize() > 1)
|
|
||||||
mSpotPenumbraAngleKeys.SaveKeysLDraw(Stream, "LIGHT SPOT_PENUMBRA_ANGLE_KEY ");
|
|
||||||
else
|
|
||||||
Stream << QLatin1String("0 !LEOCAD LIGHT SPOT_PENUMBRA_ANGLE ") << mSpotPenumbraAngle << LineEnding;
|
|
||||||
|
|
||||||
if (mSpotTightnessKeys.GetSize() > 1)
|
|
||||||
mSpotTightnessKeys.SaveKeysLDraw(Stream, "SPOT_TIGHTNESS_KEY ");
|
|
||||||
else
|
|
||||||
Stream << QLatin1String("0 !LEOCAD LIGHT SPOT_TIGHTNESS ") << mSpotTightness << LineEnding;
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case lcLightType::Directional:
|
case lcLightType::Directional:
|
||||||
if (mSpotExponentKeys.GetSize() > 1)
|
SaveAttribute(Stream, mSpotExponent, mSpotExponentKeys, "LIGHT", "STRENGTH");
|
||||||
mSpotExponentKeys.SaveKeysLDraw(Stream, "LIGHT STRENGTH_KEY ");
|
|
||||||
else
|
|
||||||
Stream << QLatin1String("0 !LEOCAD LIGHT STRENGTH ") << mSpotExponent << LineEnding;
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case lcLightType::Area:
|
case lcLightType::Area:
|
||||||
if (mPOVRayLight)
|
if (mPOVRayLight)
|
||||||
{
|
SaveAttribute(Stream, mAreaGrid, mAreaGridKeys, "LIGHT", "AREA_GRID");
|
||||||
if (mAreaGridKeys.GetSize() > 1)
|
|
||||||
mAreaGridKeys.SaveKeysLDraw(Stream, "LIGHT AREA_GRID_KEY ");
|
|
||||||
else
|
|
||||||
Stream << QLatin1String("0 !LEOCAD LIGHT AREA_ROWS ") << mAreaGrid[0] << QLatin1String(" AREA_COLUMNS ") << mAreaGrid[1] << LineEnding;
|
|
||||||
}
|
|
||||||
|
|
||||||
Stream << QLatin1String("0 !LEOCAD LIGHT AREA_SHAPE ") << gLightAreaShapes[static_cast<int>(mAreaShape)] << LineEnding;
|
Stream << QLatin1String("0 !LEOCAD LIGHT AREA_SHAPE ") << gLightAreaShapes[static_cast<int>(mAreaShape)] << LineEnding;
|
||||||
|
|
||||||
|
@ -344,35 +304,18 @@ bool lcLight::ParseLDrawLine(QTextStream& Stream)
|
||||||
}
|
}
|
||||||
else if (Token == QLatin1String("ROTATION_KEY"))
|
else if (Token == QLatin1String("ROTATION_KEY"))
|
||||||
mRotationKeys.LoadKeysLDraw(Stream); // todo: convert from ldraw
|
mRotationKeys.LoadKeysLDraw(Stream); // todo: convert from ldraw
|
||||||
else if (Token == QLatin1String("COLOR"))
|
else if (LoadAttribute(Stream, Token, mColor, mColorKeys, "COLOR"))
|
||||||
{
|
continue;
|
||||||
Stream >> mColor[0] >> mColor[1] >> mColor[2];
|
else if (LoadAttribute(Stream, Token, mSize, mSizeKeys, "SIZE"))
|
||||||
mColorKeys.ChangeKey(mColor, 1, true);
|
continue;
|
||||||
}
|
else if (LoadAttribute(Stream, Token, mPower, mPowerKeys, "POWER"))
|
||||||
else if (Token == QLatin1String("COLOR_KEY"))
|
continue;
|
||||||
mColorKeys.LoadKeysLDraw(Stream);
|
else if (LoadAttribute(Stream, Token, mSpotConeAngle, mSpotConeAngleKeys, "SPOT_CONE_ANGLE"))
|
||||||
else if (Token == QLatin1String("SPOT_CONE_ANGLE"))
|
continue;
|
||||||
{
|
else if (LoadAttribute(Stream, Token, mSpotPenumbraAngle, mSpotPenumbraAngleKeys, "SPOT_PENUMBRA_ANGLE"))
|
||||||
Stream >> mSpotConeAngle;
|
continue;
|
||||||
mSpotConeAngleKeys.ChangeKey(mSpotConeAngle, 1, true);
|
else if (LoadAttribute(Stream, Token, mSpotTightness, mSpotTightnessKeys, "SPOT_TIGHTNESS"))
|
||||||
}
|
continue;
|
||||||
else if (Token == QLatin1String("SPOT_CONE_ANGLE_KEY"))
|
|
||||||
mSpotConeAngleKeys.LoadKeysLDraw(Stream);
|
|
||||||
else if (Token == QLatin1String("SPOT_PENUMBRA_ANGLE"))
|
|
||||||
{
|
|
||||||
Stream >> mSpotPenumbraAngle;
|
|
||||||
mSpotPenumbraAngleKeys.ChangeKey(mSpotPenumbraAngle, 1, true);
|
|
||||||
}
|
|
||||||
else if (Token == QLatin1String("SPOT_PENUMBRA_ANGLE_KEY"))
|
|
||||||
mSpotPenumbraAngleKeys.LoadKeysLDraw(Stream);
|
|
||||||
else if (Token == QLatin1String("SPOT_TIGHTNESS"))
|
|
||||||
{
|
|
||||||
mPOVRayLight = true;
|
|
||||||
Stream >> mSpotTightness;
|
|
||||||
mSpotTightnessKeys.ChangeKey(mSpotTightness, 1, true);
|
|
||||||
}
|
|
||||||
else if (Token == QLatin1String("SPOT_TIGHTNESS_KEY"))
|
|
||||||
mSpotTightnessKeys.LoadKeysLDraw(Stream);
|
|
||||||
else if (Token == QLatin1String("AREA_SHAPE"))
|
else if (Token == QLatin1String("AREA_SHAPE"))
|
||||||
{
|
{
|
||||||
QString AreaShape;
|
QString AreaShape;
|
||||||
|
@ -387,27 +330,20 @@ bool lcLight::ParseLDrawLine(QTextStream& Stream)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (Token == QLatin1String("SIZE"))
|
|
||||||
{
|
|
||||||
Stream >> mSize[0] >> mSize[1];
|
|
||||||
mSizeKeys.ChangeKey(mSize, 1, true);
|
|
||||||
}
|
|
||||||
else if (Token == QLatin1String("SIZE_KEY"))
|
|
||||||
mSizeKeys.LoadKeysLDraw(Stream);
|
|
||||||
|
|
||||||
else if (Token == QLatin1String("POWER") || Token == QLatin1String("STRENGTH"))
|
// else if (Token == QLatin1String("POWER") || Token == QLatin1String("STRENGTH"))
|
||||||
{
|
// {
|
||||||
if (mPOVRayLight)
|
// if (mPOVRayLight)
|
||||||
{
|
// {
|
||||||
Stream >> mPOVRayExponent;
|
// Stream >> mPOVRayExponent;
|
||||||
mSpotExponentKeys.ChangeKey(mPOVRayExponent, 1, true);
|
// mSpotExponentKeys.ChangeKey(mPOVRayExponent, 1, true);
|
||||||
}
|
// }
|
||||||
else
|
// else
|
||||||
{
|
// {
|
||||||
Stream >> mSpotExponent;
|
// Stream >> mSpotExponent;
|
||||||
mSpotExponentKeys.ChangeKey(mSpotExponent, 1, true);
|
// mSpotExponentKeys.ChangeKey(mSpotExponent, 1, true);
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
else if (Token == QLatin1String("AREA_ROWS"))
|
else if (Token == QLatin1String("AREA_ROWS"))
|
||||||
{
|
{
|
||||||
mPOVRayLight = true;
|
mPOVRayLight = true;
|
||||||
|
|
|
@ -1,6 +1,22 @@
|
||||||
#include "lc_global.h"
|
#include "lc_global.h"
|
||||||
#include "object.h"
|
#include "object.h"
|
||||||
|
|
||||||
|
#define LC_OBJECT_ATTRIBUTE(T) \
|
||||||
|
template void lcObjectKeyArray<T>::SaveKeysLDraw(QTextStream& Stream, const char* ObjectName, const char* VariableName) const; \
|
||||||
|
template void lcObjectKeyArray<T>::LoadKeysLDraw(QTextStream& Stream); \
|
||||||
|
template const T& lcObjectKeyArray<T>::CalculateKey(lcStep Step) const; \
|
||||||
|
template void lcObjectKeyArray<T>::ChangeKey(const T& Value, lcStep Step, bool AddKey); \
|
||||||
|
template void lcObjectKeyArray<T>::InsertTime(lcStep Start, lcStep Time); \
|
||||||
|
template void lcObjectKeyArray<T>::RemoveTime(lcStep Start, lcStep Time); \
|
||||||
|
template void lcObject::SaveAttribute<T>(QTextStream& Stream, const T& Variable, const lcObjectKeyArray<T>& Keys, const char* ObjectName, const char* VariableName) const; \
|
||||||
|
template bool lcObject::LoadAttribute<T>(QTextStream& Stream, const QString& Token, T& Variable, lcObjectKeyArray<T>& Keys, const char* VariableName)
|
||||||
|
|
||||||
|
LC_OBJECT_ATTRIBUTE(float);
|
||||||
|
LC_OBJECT_ATTRIBUTE(lcVector2);
|
||||||
|
LC_OBJECT_ATTRIBUTE(lcVector3);
|
||||||
|
LC_OBJECT_ATTRIBUTE(lcVector4);
|
||||||
|
LC_OBJECT_ATTRIBUTE(lcMatrix33);
|
||||||
|
|
||||||
lcObject::lcObject(lcObjectType ObjectType)
|
lcObject::lcObject(lcObjectType ObjectType)
|
||||||
: mObjectType(ObjectType)
|
: mObjectType(ObjectType)
|
||||||
{
|
{
|
||||||
|
@ -10,59 +26,32 @@ lcObject::~lcObject()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
template void lcObjectKeyArray<float>::SaveKeysLDraw(QTextStream& Stream, const char* KeyName) const;
|
|
||||||
template void lcObjectKeyArray<float>::LoadKeysLDraw(QTextStream& Stream);
|
|
||||||
template const float& lcObjectKeyArray<float>::CalculateKey(lcStep Step) const;
|
|
||||||
template void lcObjectKeyArray<float>::ChangeKey(const float& Value, lcStep Step, bool AddKey);
|
|
||||||
template void lcObjectKeyArray<float>::InsertTime(lcStep Start, lcStep Time);
|
|
||||||
template void lcObjectKeyArray<float>::RemoveTime(lcStep Start, lcStep Time);
|
|
||||||
|
|
||||||
template void lcObjectKeyArray<lcVector3>::SaveKeysLDraw(QTextStream& Stream, const char* KeyName) const;
|
|
||||||
template void lcObjectKeyArray<lcVector3>::LoadKeysLDraw(QTextStream& Stream);
|
|
||||||
template const lcVector3& lcObjectKeyArray<lcVector3>::CalculateKey(lcStep Step) const;
|
|
||||||
template void lcObjectKeyArray<lcVector3>::ChangeKey(const lcVector3& Value, lcStep Step, bool AddKey);
|
|
||||||
template void lcObjectKeyArray<lcVector3>::InsertTime(lcStep Start, lcStep Time);
|
|
||||||
template void lcObjectKeyArray<lcVector3>::RemoveTime(lcStep Start, lcStep Time);
|
|
||||||
|
|
||||||
template void lcObjectKeyArray<lcVector4>::SaveKeysLDraw(QTextStream& Stream, const char* KeyName) const;
|
|
||||||
template void lcObjectKeyArray<lcVector4>::LoadKeysLDraw(QTextStream& Stream);
|
|
||||||
template const lcVector4& lcObjectKeyArray<lcVector4>::CalculateKey(lcStep Step) const;
|
|
||||||
template void lcObjectKeyArray<lcVector4>::ChangeKey(const lcVector4& Value, lcStep Step, bool AddKey);
|
|
||||||
template void lcObjectKeyArray<lcVector4>::InsertTime(lcStep Start, lcStep Time);
|
|
||||||
template void lcObjectKeyArray<lcVector4>::RemoveTime(lcStep Start, lcStep Time);
|
|
||||||
|
|
||||||
template void lcObjectKeyArray<lcMatrix33>::SaveKeysLDraw(QTextStream& Stream, const char* KeyName) const;
|
|
||||||
template void lcObjectKeyArray<lcMatrix33>::LoadKeysLDraw(QTextStream& Stream);
|
|
||||||
template const lcMatrix33& lcObjectKeyArray<lcMatrix33>::CalculateKey(lcStep Step) const;
|
|
||||||
template void lcObjectKeyArray<lcMatrix33>::ChangeKey(const lcMatrix33& Value, lcStep Step, bool AddKey);
|
|
||||||
template void lcObjectKeyArray<lcMatrix33>::InsertTime(lcStep Start, lcStep Time);
|
|
||||||
template void lcObjectKeyArray<lcMatrix33>::RemoveTime(lcStep Start, lcStep Time);
|
|
||||||
|
|
||||||
template void lcObjectKeyArray<int>::SaveKeysLDraw(QTextStream& Stream, const char* KeyName) const;
|
|
||||||
template void lcObjectKeyArray<int>::LoadKeysLDraw(QTextStream& Stream);
|
|
||||||
template const int& lcObjectKeyArray<int>::CalculateKey(lcStep Step) const;
|
|
||||||
template void lcObjectKeyArray<int>::ChangeKey(const int& Value, lcStep Step, bool AddKey);
|
|
||||||
template void lcObjectKeyArray<int>::InsertTime(lcStep Start, lcStep Time);
|
|
||||||
template void lcObjectKeyArray<int>::RemoveTime(lcStep Start, lcStep Time);
|
|
||||||
|
|
||||||
template void lcObjectKeyArray<lcVector2>::SaveKeysLDraw(QTextStream& Stream, const char* KeyName) const;
|
|
||||||
template void lcObjectKeyArray<lcVector2>::LoadKeysLDraw(QTextStream& Stream);
|
|
||||||
template const lcVector2& lcObjectKeyArray<lcVector2>::CalculateKey(lcStep Step) const;
|
|
||||||
template void lcObjectKeyArray<lcVector2>::ChangeKey(const lcVector2& Value, lcStep Step, bool AddKey);
|
|
||||||
template void lcObjectKeyArray<lcVector2>::InsertTime(lcStep Start, lcStep Time);
|
|
||||||
template void lcObjectKeyArray<lcVector2>::RemoveTime(lcStep Start, lcStep Time);
|
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
void lcObjectKeyArray<T>::SaveKeysLDraw(QTextStream& Stream, const char* KeyName) const
|
static void SaveFloatValue(QTextStream& Stream, const T& Value)
|
||||||
{
|
{
|
||||||
constexpr int Count = sizeof(T) / sizeof(float);
|
constexpr int Count = sizeof(T) / sizeof(float);
|
||||||
|
|
||||||
|
for (int ValueIndex = 0; ValueIndex < Count; ValueIndex++)
|
||||||
|
Stream << ((const float*)&Value)[ValueIndex] << ' ';
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
static void LoadFloatValue(QTextStream& Stream, T& Value)
|
||||||
|
{
|
||||||
|
constexpr int Count = sizeof(T) / sizeof(float);
|
||||||
|
|
||||||
|
for (int ValueIdx = 0; ValueIdx < Count; ValueIdx++)
|
||||||
|
Stream >> ((float*)&Value)[ValueIdx];
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
void lcObjectKeyArray<T>::SaveKeysLDraw(QTextStream& Stream, const char* ObjectName, const char* VariableName) const
|
||||||
|
{
|
||||||
for (const lcObjectKey<T>& Key : mKeys)
|
for (const lcObjectKey<T>& Key : mKeys)
|
||||||
{
|
{
|
||||||
Stream << QLatin1String("0 !LEOCAD ") << KeyName << Key.Step << ' ';
|
Stream << QLatin1String("0 !LEOCAD ") << ObjectName << ' ' << VariableName << "_KEY " << Key.Step << ' ';
|
||||||
|
|
||||||
for (int ValueIdx = 0; ValueIdx < Count; ValueIdx++)
|
SaveFloatValue(Stream, Key.Value);
|
||||||
Stream << ((float*)&Key.Value)[ValueIdx] << ' ';
|
|
||||||
|
|
||||||
Stream << QLatin1String("\r\n");
|
Stream << QLatin1String("\r\n");
|
||||||
}
|
}
|
||||||
|
@ -182,3 +171,39 @@ void lcObjectKeyArray<T>::RemoveTime(lcStep Start, lcStep Time)
|
||||||
KeyIt++;
|
KeyIt++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
void lcObject::SaveAttribute(QTextStream& Stream, const T& Variable, const lcObjectKeyArray<T>& Keys, const char* ObjectName, const char* VariableName) const
|
||||||
|
{
|
||||||
|
if (Keys.GetSize() == 1)
|
||||||
|
{
|
||||||
|
Stream << QLatin1String("0 !LEOCAD ") << ObjectName << ' ' << VariableName << ' ';
|
||||||
|
|
||||||
|
SaveFloatValue(Stream, Variable);
|
||||||
|
|
||||||
|
Stream << QLatin1String("\r\n");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
Keys.SaveKeysLDraw(Stream, ObjectName, VariableName);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
bool lcObject::LoadAttribute(QTextStream& Stream, const QString& Token, T& Variable, lcObjectKeyArray<T>& Keys, const char* VariableName)
|
||||||
|
{
|
||||||
|
if (Token == VariableName)
|
||||||
|
{
|
||||||
|
LoadFloatValue(Stream, Variable);
|
||||||
|
Keys.ChangeKey(Variable, 1, true);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Token.endsWith(QLatin1String("_KEY")) && Token.leftRef(Token.size() - 4) == VariableName)
|
||||||
|
{
|
||||||
|
Keys.LoadKeysLDraw(Stream);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
|
@ -36,7 +36,7 @@ public:
|
||||||
mKeys.clear();
|
mKeys.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void SaveKeysLDraw(QTextStream& Stream, const char* KeyName) const;
|
void SaveKeysLDraw(QTextStream& Stream, const char* ObjectName, const char* VariableName) const;
|
||||||
void LoadKeysLDraw(QTextStream& Stream);
|
void LoadKeysLDraw(QTextStream& Stream);
|
||||||
const T& CalculateKey(lcStep Step) const;
|
const T& CalculateKey(lcStep Step) const;
|
||||||
void ChangeKey(const T& Value, lcStep Step, bool AddKey);
|
void ChangeKey(const T& Value, lcStep Step, bool AddKey);
|
||||||
|
@ -141,7 +141,12 @@ public:
|
||||||
virtual void RemoveKeyFrames() = 0;
|
virtual void RemoveKeyFrames() = 0;
|
||||||
virtual QString GetName() const = 0;
|
virtual QString GetName() const = 0;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
template<typename T>
|
||||||
|
void SaveAttribute(QTextStream& Stream, const T& Variable, const lcObjectKeyArray<T>& Keys, const char* ObjectName, const char* VariableName) const;
|
||||||
|
template<typename T>
|
||||||
|
bool LoadAttribute(QTextStream& Stream, const QString& Token, T& Variable, lcObjectKeyArray<T>& Keys, const char* VariableName);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
lcObjectType mObjectType;
|
lcObjectType mObjectType;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -125,10 +125,10 @@ void lcPiece::SaveLDraw(QTextStream& Stream) const
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mPositionKeys.GetSize() > 1)
|
if (mPositionKeys.GetSize() > 1)
|
||||||
mPositionKeys.SaveKeysLDraw(Stream, "PIECE POSITION_KEY ");
|
mPositionKeys.SaveKeysLDraw(Stream, "PIECE", "POSITION");
|
||||||
|
|
||||||
if (mRotationKeys.GetSize() > 1)
|
if (mRotationKeys.GetSize() > 1)
|
||||||
mRotationKeys.SaveKeysLDraw(Stream, "PIECE ROTATION_KEY ");
|
mRotationKeys.SaveKeysLDraw(Stream, "PIECE", "ROTATION");
|
||||||
|
|
||||||
Stream << "1 " << mColorCode << ' ';
|
Stream << "1 " << mColorCode << ' ';
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue