Made light type editable.

This commit is contained in:
Leonardo Zide 2023-09-01 20:46:29 -07:00
parent 9d60160f6a
commit 7d289f2cfe
6 changed files with 99 additions and 21 deletions

View file

@ -3113,6 +3113,16 @@ void lcModel::SetCameraName(lcCamera* Camera, const QString& Name)
gMainWindow->UpdateCameraMenu();
}
void lcModel::SetLightType(lcLight* Light, lcLightType LightType)
{
Light->SetLightType(LightType);
Light->UpdatePosition(mCurrentStep);
SaveCheckpoint(tr("Changing Light Type"));
gMainWindow->UpdateSelectedObjects(false);
UpdateAllViews();
}
void lcModel::SetLightColor(lcLight* Light, const lcVector3& Color)
{
if (Light->GetColor() == Color)
@ -4190,6 +4200,9 @@ void lcModel::BeginDirectionalLightTool(const lcVector3& Position, const lcVecto
case lcLightType::Area:
SaveCheckpoint(tr("New Area Light"));
break;
case lcLightType::Count:
break;
}
}

View file

@ -368,6 +368,7 @@ public:
void SetCameraZFar(lcCamera* Camera, float ZFar);
void SetCameraName(lcCamera* Camera, const QString& Name);
void SetLightType(lcLight* Light, lcLightType LightType);
void SetLightColor(lcLight* Light, const lcVector3& Color);
void SetLightName(lcLight* Light, const QString& Name);
void UpdateLight(lcLight* Light, const lcLightProperties Props, int Property);

View file

@ -17,7 +17,7 @@
#define LC_LIGHT_POSITION_EDGE 7.5f
static const std::array<QLatin1String, 4> gLightTypes = { QLatin1String("POINT"), QLatin1String("SPOT"), QLatin1String("DIRECTIONAL"), QLatin1String("AREA") };
static const std::array<QLatin1String, static_cast<int>(lcLightType::Count)> gLightTypes = { QLatin1String("POINT"), QLatin1String("SPOT"), QLatin1String("DIRECTIONAL"), QLatin1String("AREA") };
lcLight::lcLight(const lcVector3& Position, const lcVector3& TargetPosition, lcLightType LightType)
: lcObject(lcObjectType::Light), mLightType(LightType)
@ -78,6 +78,29 @@ lcLight::lcLight(const lcVector3& Position, const lcVector3& TargetPosition, lcL
UpdatePosition(1);
}
QString lcLight::GetLightTypeString(lcLightType LightType)
{
switch (LightType)
{
case lcLightType::Point:
return QT_TRANSLATE_NOOP("Light Names", "Point Light");
case lcLightType::Spot:
return QT_TRANSLATE_NOOP("Light Names", "Spotlight");
case lcLightType::Directional:
return QT_TRANSLATE_NOOP("Light Names", "Directional Light");
case lcLightType::Area:
return QT_TRANSLATE_NOOP("Light Names", "Area Light");
case lcLightType::Count:
break;
}
return QString();
}
void lcLight::SaveLDraw(QTextStream& Stream) const
{
const QLatin1String LineEnding("\r\n");
@ -142,6 +165,9 @@ void lcLight::SaveLDraw(QTextStream& Stream) const
switch (mLightType)
{
case lcLightType::Count:
break;
case lcLightType::Point:
if (!mPOVRayLight)
{
@ -225,6 +251,7 @@ void lcLight::SaveLDraw(QTextStream& Stream) const
Stream << QLatin1String("0 !LEOCAD LIGHT SHAPE ");
QString Shape = QLatin1String("UNDEFINED ");
switch (mLightShape)
{
case LC_LIGHT_SHAPE_SQUARE:
@ -275,7 +302,7 @@ void lcLight::CreateName(const lcArray<lcLight*>& Lights)
switch (mLightType)
{
case lcLightType::Point:
Prefix = QLatin1String("Pointlight ");
Prefix = QLatin1String("Point Light ");
break;
case lcLightType::Spot:
@ -283,11 +310,14 @@ void lcLight::CreateName(const lcArray<lcLight*>& Lights)
break;
case lcLightType::Directional:
Prefix = QLatin1String("Directionallight ");
Prefix = QLatin1String("Directional Light ");
break;
case lcLightType::Area:
Prefix = QLatin1String("Arealight ");
Prefix = QLatin1String("Area Light ");
break;
case lcLightType::Count:
break;
}
@ -522,6 +552,9 @@ bool lcLight::ParseLDrawLine(QTextStream& Stream)
}
}
break;
case lcLightType::Count:
break;
}
return true;
@ -831,6 +864,14 @@ void lcLight::MoveSelected(lcStep Step, bool AddKey, const lcVector3& Distance)
}
}
void lcLight::SetLightType(lcLightType LightType)
{
if (static_cast<int>(LightType) < 0 || LightType >= lcLightType::Count)
return;
mLightType = LightType;
}
void lcLight::SetColor(const lcVector3& Color, lcStep Step, bool AddKey)
{
mColorKeys.ChangeKey(Color, Step, AddKey);
@ -948,6 +989,9 @@ void lcLight::DrawInterface(lcContext* Context, const lcScene& Scene) const
case lcLightType::Area:
DrawAreaLight(Context);
break;
case lcLightType::Count:
break;
}
}

View file

@ -27,7 +27,8 @@ enum class lcLightType
Point,
Spot,
Directional,
Area
Area,
Count
};
enum lcLightShape
@ -86,6 +87,8 @@ public:
lcLight& operator=(const lcLight&) = delete;
lcLight& operator=(lcLight&&) = delete;
static QString GetLightTypeString(lcLightType LightType);
bool IsPointLight() const
{
return mLightType == lcLightType::Point;
@ -111,6 +114,8 @@ public:
return mLightType;
}
void SetLightType(lcLightType LightType);
int GetLightShape() const
{
return mLightShape;
@ -158,6 +163,9 @@ public:
case lcLightType::Area:
mState |= LC_LIGHT_POSITION_SELECTED | LC_LIGHT_TARGET_SELECTED | LC_LIGHT_UPVECTOR_SELECTED;
break;
case lcLightType::Count:
break;
}
}
else

View file

@ -524,8 +524,21 @@ QWidget *lcQPropertiesTree::createEditor(QWidget *parent, QTreeWidgetItem *item)
return editor;
}
case PropertyStringLightReadOnly:
return nullptr;
case PropertyStringList:
{
QComboBox* editor = new QComboBox(parent);
if (item == mLightTypeItem)
for (int LightTypeIndex = 0; LightTypeIndex < static_cast<int>(lcLightType::Count); LightTypeIndex++)
editor->addItem(lcLight::GetLightTypeString(static_cast<lcLightType>(LightTypeIndex)));
int value = item->data(0, PropertyValueRole).toInt();
editor->setCurrentIndex(value);
connect(editor, SIGNAL(currentIndexChanged(int)), this, SLOT(slotSetValue(int)));
return editor;
}
case PropertyLightFormat:
{
@ -1023,13 +1036,17 @@ void lcQPropertiesTree::slotSetValue(int Value)
else if (mWidgetMode == LC_PROPERTY_WIDGET_LIGHT)
{
lcObject* Focus = Model->GetFocusObject();
lcLight* Light = (Focus && Focus->IsLight()) ? (lcLight*)Focus : nullptr;
if (Light)
{
lcLightProperties Props = Light->GetLightProperties();
if (Item == lightShape)
if (Item == mLightTypeItem)
{
Model->SetLightType(Light, static_cast<lcLightType>(Value));
}
else if (Item == lightShape)
{
Props.mLightShape = static_cast<lcLightShape>(Value);
Model->UpdateLight(Light, Props, LC_LIGHT_SHAPE);
@ -1129,7 +1146,7 @@ QTreeWidgetItem *lcQPropertiesTree::addProperty(QTreeWidgetItem *parent, const Q
newItem->setIcon(0, m_expandIcon);
}
if (propertyType == PropertyStringLightReadOnly || propertyType == PropertyFloatReadOnly)
if (propertyType == PropertyFloatReadOnly)
newItem->setFlags(newItem->flags() & ~Qt::ItemIsEditable);
return newItem;
@ -1193,7 +1210,7 @@ void lcQPropertiesTree::SetEmpty()
lightCutoff = nullptr;
lightEnableCutoff = nullptr;
lightExponent = nullptr;
lightType = nullptr;
mLightTypeItem = nullptr;
lightFactorA = nullptr;
lightFactorB = nullptr;
lightName = nullptr;
@ -1439,7 +1456,6 @@ void lcQPropertiesTree::SetLight(lcObject* Focus)
QString Name = tr("Light");
QString ExponentLabel = tr("Exponent");
QString FactorALabel = QLatin1String("FactorA");
QString Type = QLatin1String("Undefined");
QString Format, Shape, SpotSizeToolTip, ExponentToolTip, FactorAToolTip, FactorBToolTip;
lcLightType LightType = lcLightType::Point;
lcLightShape ShapeIndex = LC_LIGHT_SHAPE_UNDEFINED;
@ -1480,13 +1496,11 @@ void lcQPropertiesTree::SetLight(lcObject* Focus)
switch(LightType)
{
case lcLightType::Point:
Type = tr("Point");
FactorALabel = tr("Radius (m)");
FactorAToolTip = tr("The light size for shadow sampling in metres.");
ExponentLabel = tr("Exponent");
break;
case lcLightType::Spot:
Type = tr("Spot");
FactorBToolTip = tr("The softness of the spotlight edge.");
ExponentLabel = tr("Power");
@ -1506,13 +1520,11 @@ void lcQPropertiesTree::SetLight(lcObject* Focus)
}
break;
case lcLightType::Directional:
Type = tr("Directional");
FactorALabel = tr("Angle (°)");
FactorAToolTip = tr("Angular diamater of the sun as seen from the Earth.");
ExponentLabel = tr("Strength");
break;
case lcLightType::Area:
Type = tr("Area");
ExponentLabel = tr("Power");
if (POVRayLight)
@ -1609,7 +1621,7 @@ void lcQPropertiesTree::SetLight(lcObject* Focus)
// Properties
lightProperties = addProperty(nullptr, tr("Properties"), PropertyGroup);
lightType = addProperty(lightProperties, tr("Type"), PropertyStringLightReadOnly);
mLightTypeItem = addProperty(lightProperties, tr("Type"), PropertyStringList);
lightShadowless = addProperty(lightProperties, tr("Shadowless"), PropertyBool);
lightExponent = addProperty(lightProperties, ExponentLabel, PropertyFloat);
@ -1712,8 +1724,8 @@ void lcQPropertiesTree::SetLight(lcObject* Focus)
lightFormat->setText(1, Format);
lightFormat->setData(0, PropertyValueRole, FormatIndex);
lightType->setText(1, Type);
lightType->setData(0, PropertyValueRole, Type);
mLightTypeItem->setText(1, lcLight::GetLightTypeString(LightType));
mLightTypeItem->setData(0, PropertyValueRole, static_cast<int>(LightType));
lightShadowless->setText(1, Shadowless ? "True" : "False");
lightShadowless->setData(0, PropertyValueRole, Shadowless);

View file

@ -49,7 +49,7 @@ public:
PropertyFloatLightSpotFalloff,
PropertyStep,
PropertyString,
PropertyStringLightReadOnly,
PropertyStringList,
PropertyLightFormat,
PropertyLightShape,
PropertyLightColor,
@ -145,7 +145,7 @@ protected:
QTreeWidgetItem *lightCutoff;
QTreeWidgetItem *lightEnableCutoff;
QTreeWidgetItem *lightExponent;
QTreeWidgetItem *lightType;
QTreeWidgetItem *mLightTypeItem;
QTreeWidgetItem *lightSpotSize;
QTreeWidgetItem *lightShape;
QTreeWidgetItem *lightFactorA;