Skip to content

Commit

Permalink
since the Moving Head Update, "old" Moving Head Model Import was brok…
Browse files Browse the repository at this point in the history
…en, Rewrite to use XmlSerializer instead.
  • Loading branch information
computergeek1507 committed Oct 4, 2024
1 parent 900accf commit 29fb000
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 12 deletions.
1 change: 1 addition & 0 deletions xLights/LayoutPanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3673,6 +3673,7 @@ void LayoutPanel::FinalizeModel()

// Models that support visitors don't use the ImportXlightsModel method
// If there are import issues we need to try to fix them inside the XmlSerializer
// XmlSerializer::IsXmlSerializerFormat is not working as I expect here, the XML already has the type parameter removed
if (!_newModel->SupportsVisitors() || !XmlSerializer::IsXmlSerializerFormat(_newModel->GetModelXml())) {
xlights->AddTraceMessage("LayoutPanel::FinalizeModel Do the import. " + _lastXlightsModel);
xlights->AddTraceMessage("LayoutPanel::FinalizeModel Model type " + _newModel->GetDisplayAs());
Expand Down
2 changes: 2 additions & 0 deletions xLights/models/BaseObjectVisitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@
**************************************************************/

class ArchesModel;
class DmxMovingHead;
class DmxMovingHeadAdv;

struct BaseObjectVisitor
{
virtual void Visit(const ArchesModel &arch) = 0;
virtual void Visit(const DmxMovingHeadAdv &moving_head) = 0;
virtual void Visit(const DmxMovingHead& moving_head) = 0;

virtual ~BaseObjectVisitor() {}
};
8 changes: 7 additions & 1 deletion xLights/models/DMX/DmxMovingHead.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include "../../xLightsVersion.h"
#include "../../xLightsMain.h"
#include "../../UtilFunctions.h"
#include "../XmlSerializer.h"

DmxMovingHead::DmxMovingHead(wxXmlNode *node, const ModelManager &manager, bool zeroBased) :
DmxMovingHeadComm(node, manager, zeroBased), hide_body(false), style_changed(false), dmx_style("Moving Head Top"),
Expand Down Expand Up @@ -1172,7 +1173,8 @@ void DmxMovingHead::Draw3DDMXHead(xlVertexColorAccumulator& va, const xlColor& c

void DmxMovingHead::ExportXlightsModel()
{
wxString name = ModelXml->GetAttribute("name");
wxASSERT(false);//shouldnt be used anymore
/* wxString name = ModelXml->GetAttribute("name");
wxLogNull logNo; //kludge: avoid "error 0" message from wxWidgets after new file is written
wxString filename = wxFileSelector(_("Choose output file"), wxEmptyString, name, wxEmptyString, "Custom Model files (*.xmodel)|*.xmodel", wxFD_SAVE | wxFD_OVERWRITE_PROMPT);
if (filename.IsEmpty())
Expand Down Expand Up @@ -1246,10 +1248,14 @@ void DmxMovingHead::ExportXlightsModel()
//ExportDimensions(f);
f.Write("</dmxmodel>");
f.Close();
*/
}

bool DmxMovingHead::ImportXlightsModel(wxXmlNode* root, xLightsFrame* xlights, float& min_x, float& max_x, float& min_y, float& max_y)
{
if (XmlSerializer::IsXmlSerializerFormat(root)) {
return true;
}
if (root->GetName() == "dmxmodel") {
if (!ImportBaseParameters(root))
return false;
Expand Down
14 changes: 10 additions & 4 deletions xLights/models/DMX/DmxMovingHead.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,16 @@ class DmxMovingHead : public DmxMovingHeadComm, public DmxDimmerAbility
void EnableFixedChannels(xlColorVector& pixelVector) const override;
[[nodiscard]] std::vector<std::string> GenerateNodeNames() const override;

DmxMotorBase* GetPanMotor() const override { return pan_motor.get(); }
DmxMotorBase* GetTiltMotor() const override { return tilt_motor.get(); }

uint32_t GetMHDimmerChannel() const override {return GetDimmerChannel();}
[[nodiscard]] DmxMotorBase* GetPanMotor() const override { return pan_motor.get(); }
[[nodiscard]] DmxMotorBase* GetTiltMotor() const override { return tilt_motor.get(); }

[[nodiscard]] uint32_t GetMHDimmerChannel() const override {return GetDimmerChannel();}
[[nodiscard]] std::string const& GetDMXStyle() const { return dmx_style; }
[[nodiscard]] float GetBeamLength() const { return beam_length; }
[[nodiscard]] float GetBeamWidth() const { return beam_width; }
[[nodiscard]] bool GetHideBody() const { return hide_body; }
[[nodiscard]] virtual bool SupportsVisitors() override { return true; }
void Accept(BaseObjectVisitor &visitor) const override { return visitor.Visit(*this); }

protected:
void Draw3DDMXBaseLeft(xlVertexColorAccumulator &va, const xlColor& c, float pan_angle);
Expand Down
53 changes: 46 additions & 7 deletions xLights/models/XmlSerializer.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "DMX/DmxDimmerAbility.h"
#include "DMX/DmxShutterAbility.h"
#include "DMX/DmxMovingHeadAdv.h"
#include "DMX/DmxMovingHead.h"
#include "DMX/Mesh.h"
#include "ThreePointScreenLocation.h"

Expand Down Expand Up @@ -108,6 +109,9 @@ constexpr auto DmxFixturelAttribute = "DmxFixture";
constexpr auto DmxColorTypeAttribute = "DmxColorType";
constexpr auto DmxBeamYOffsetAttribute = "DmxBeamYOffset";
constexpr auto DmxBeamLengthAttribute = "DmxBeamLength";
constexpr auto DmxBeamWidthAttribute = "DmxBeamWidth";//old MH model
constexpr auto DmxStyleAttribute = "DmxStyle"; // old MH model
constexpr auto HideBodyAttribute = "HideBody"; // old MH model

// DmxMotor Attributes
constexpr auto ChannelCoarseAttribute = "ChannelCoarse";
Expand Down Expand Up @@ -147,6 +151,7 @@ constexpr auto BrightnessAttribute = "Brightness";
// Model Types
constexpr auto ArchesType = "Arches";
constexpr auto DmxMovingHeadAdvType = "DmxMovingHeadAdv";
constexpr auto DmxMovingHeadType = "DmxMovingHead";

};

Expand Down Expand Up @@ -355,6 +360,25 @@ struct XmlSerializingVisitor : BaseObjectVisitor
AddPresetAttributes(moving_head.GetPresetAbility(), mhNode);
parentNode->AddChild(mhNode);
}

void Visit(const DmxMovingHead& moving_head) override {
wxXmlNode* mhNode = new wxXmlNode(wxXML_ELEMENT_NODE, XmlNodeKeys::ModelNodeName);
AddBaseObjectAttributes(moving_head, mhNode);
AddCommonModelAttributes(moving_head, mhNode);
AddModelScreenLocationAttributes(moving_head, mhNode);
AddColorAttributes(moving_head, mhNode);
mhNode->AddAttribute(XmlNodeKeys::DmxFixturelAttribute, moving_head.GetFixture());
mhNode->AddAttribute(XmlNodeKeys::DmxStyleAttribute, moving_head.GetDMXStyle());
mhNode->AddAttribute(XmlNodeKeys::DmxBeamLengthAttribute, std::to_string(moving_head.GetBeamLength()));
mhNode->AddAttribute(XmlNodeKeys::DmxBeamWidthAttribute, std::to_string(moving_head.GetBeamWidth()));
mhNode->AddAttribute(XmlNodeKeys::HideBodyAttribute, std::to_string(moving_head.GetHideBody()));
AddDmxMotorAttributes(reinterpret_cast<DmxMotor*>(moving_head.GetPanMotor()), mhNode);
AddDmxMotorAttributes(reinterpret_cast<DmxMotor*>(moving_head.GetTiltMotor()), mhNode);
AddDimmerAbilityAttributes(moving_head, mhNode);
AddShutterAbilityAttributes(moving_head, mhNode);
AddPresetAttributes(moving_head.GetPresetAbility(), mhNode);
parentNode->AddChild(mhNode);
}
};

struct XmlDeserializingObjectFactory
Expand All @@ -363,13 +387,12 @@ struct XmlDeserializingObjectFactory
{
auto type = node->GetAttribute(XmlNodeKeys::DisplayAsAttribute);

if (type == XmlNodeKeys::ArchesType)
{
if (type == XmlNodeKeys::ArchesType) {
return DeserializeArches(new wxXmlNode(*node), xlights);
}
else if (type == XmlNodeKeys::DmxMovingHeadAdvType)
{
} else if (type == XmlNodeKeys::DmxMovingHeadAdvType) {
return DeserializeDmxMovingHeadAdv(new wxXmlNode(*node), xlights);
} else if (type == XmlNodeKeys::DmxMovingHeadType) {
return DeserializeDmxMovingHead(new wxXmlNode(*node), xlights);
}

throw std::runtime_error("Unknown object type: " + type);
Expand All @@ -391,8 +414,24 @@ struct XmlDeserializingObjectFactory

Model* DeserializeDmxMovingHeadAdv(wxXmlNode *node, xLightsFrame* xlights)
{
Model *model;
model = new DmxMovingHeadAdv(node, xlights->AllModels, false);
Model *model = new DmxMovingHeadAdv(node, xlights->AllModels, false);

std::string name = node->GetAttribute("name");
wxString newname = xlights->AllModels.GenerateModelName(name);
model->SetProperty("name", newname, true);

// TODO: I'd like to get rid of this whole ImportModelChildren call but left it in the flow for now
float min_x = (float)(model->GetBaseObjectScreenLocation().GetLeft());
float max_x = (float)(model->GetBaseObjectScreenLocation().GetRight());
float min_y = (float)(model->GetBaseObjectScreenLocation().GetBottom());
float max_y = (float)(model->GetBaseObjectScreenLocation().GetTop());
model->ImportModelChildren(node, xlights, newname, min_x, max_x, min_y, max_y);

return model;
}

Model* DeserializeDmxMovingHead(wxXmlNode* node, xLightsFrame* xlights) {
Model* model = new DmxMovingHead(node, xlights->AllModels, false);

std::string name = node->GetAttribute("name");
wxString newname = xlights->AllModels.GenerateModelName(name);
Expand Down

0 comments on commit 29fb000

Please sign in to comment.