Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

XMLSerializer with visitor WIP #4536

Draft
wants to merge 18 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions xLights/ColorManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,8 @@ class ColorManager
{ ColorManager::ColorNames::COLOR_TEXT_UNSELECTED, "TextUnselected", "Unselected Text", xlLIGHT_GREY, ColorManager::ColorCategory::COLOR_CAT_LAYOUT_TAB },
{ ColorManager::ColorNames::COLOR_TEXT_HIGHLIGHTED, "TextHighlighted", "Highlighted Text", xlBLUE, ColorManager::ColorCategory::COLOR_CAT_LAYOUT_TAB }
};
std::map<std::string, xlColor> GetColors() { return colors; }
std::map<std::string, xlColor> GetDefaultColors() { return colors_default; }

protected:

Expand Down
61 changes: 42 additions & 19 deletions xLights/CustomModelDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
#include "outputs/TwinklyOutput.h"
#include "Discovery.h"
#include "outputs/OutputManager.h"
#include "string.h"

//(*IdInit(CustomModelDialog)
const long CustomModelDialog::ID_SPINCTRL1 = wxNewId();
Expand Down Expand Up @@ -586,6 +587,7 @@ void CustomModelDialog::Setup(CustomModel* m)
lightness = m->GetCustomLightness();
SliderCustomLightness->SetValue(lightness);
std::string data = m->GetCustomData();
bool _hasCM2 = m->hasCM2();

if (background_image != "" && FileExists(background_image)) {
bkg_image = new wxImage(background_image);
Expand All @@ -605,29 +607,50 @@ void CustomModelDialog::Setup(CustomModel* m)
}
}
else {
wxArrayString layers = wxSplit(data, '|');
for (auto layer = 0; layer < layers.size(); layer++) {
AddPage();
//ResizeCustomGrid();
auto grid = GetLayerGrid(layer);
wxArrayString rows = wxSplit(layers[layer], ';');
//grid->AppendRows(rows.size() - 1);

for (auto row = 0; row < rows.size(); row++) {
wxArrayString cols = wxSplit(rows[row], ',');
//if (row == 0) {
// grid->AppendCols(cols.size() - 1);
//}
for (auto col = 0; col < cols.size(); col++) {
wxString value = cols[col];
if (!value.IsEmpty() && value != "0") {
grid->SetCellValue(row, col, value);
if (_hasCM2) {
wxArrayString layers = wxSplit(data, '|');
wxArrayString ctrllayers = wxSplit(layers[0], ',');
int type = std::stoi(ctrllayers[0].ToStdString());
int node = 1;
int step = (type == 1 ? 2 : 3);
for (auto layer = 1; layer < layers.size(); layer++) {
AddPage();
// ResizeCustomGrid();
auto grid = GetLayerGrid(layer-1);
wxArrayString data = wxSplit(layers[layer], ',');
for (auto d = 0; d < data.size();d+=step){
if (type == 1) {
grid->SetCellValue(std::stoi(data[d].ToStdString()), std::stoi(data[d + 1].ToStdString()), std::to_string(node));
node++;
} else {
grid->SetCellValue(std::stoi(data[d].ToStdString()), std::stoi(data[d + 1].ToStdString()), data[d + 2]);
}
}

wxFont font = grid->GetDefaultCellFont();
SetGridSizeForFont(font);
}
} else {
wxArrayString layers = wxSplit(data, '|');
for (auto layer = 0; layer < layers.size(); layer++) {
AddPage();
// ResizeCustomGrid();
auto grid = GetLayerGrid(layer);
wxArrayString rows = wxSplit(layers[layer], ';');

for (auto row = 0; row < rows.size(); row++) {
wxArrayString cols = wxSplit(rows[row], ',');
for (auto col = 0; col < cols.size(); col++) {
wxString value = cols[col];
if (!value.IsEmpty() && value != "0") {
grid->SetCellValue(row, col, value);
}
}
}

wxFont font = grid->GetDefaultCellFont();
SetGridSizeForFont(font);
wxFont font = grid->GetDefaultCellFont();
SetGridSizeForFont(font);
}
}
}

Expand Down
1 change: 1 addition & 0 deletions xLights/LayoutGroup.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class PreviewPane;
class LayoutGroup : public wxObject
{
public:
LayoutGroup();
LayoutGroup(const std::string & name, xLightsFrame* xl, wxXmlNode *node);
virtual ~LayoutGroup();

Expand Down
4 changes: 2 additions & 2 deletions xLights/LayoutPanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4952,7 +4952,7 @@ void LayoutPanel::OnPreviewModelPopup(wxCommandEvent& event)
return;
if (md->SupportsVisitors()) {
XmlSerializer serializer;
serializer.SerializeAndSaveModel(*md);
serializer.SerializeAndSaveModel(*md, xlights);
} else {
md->ExportXlightsModel();
}
Expand Down Expand Up @@ -7489,7 +7489,7 @@ void LayoutPanel::OnModelsPopup(wxCommandEvent& event) {
return;
if (md->SupportsVisitors()) {
XmlSerializer serializer;
serializer.SerializeAndSaveModel(*md);
serializer.SerializeAndSaveModel(*md, xlights);
} else {
md->ExportXlightsModel();
}
Expand Down
5 changes: 3 additions & 2 deletions xLights/models/ArchesModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,10 @@ class ArchesModel : public ModelWithScreenLocation<ThreePointScreenLocation>
bool GetZigZag() const { return zigzag; }
int GetHollow() const { return _hollow; }
int GetGap() const { return _gap; }
int GetArc() const { return arc; }

//virtual bool SupportsVisitors() override {return true;}
//void Accept(BaseObjectVisitor &visitor) const override { return visitor.Visit(*this); }
virtual bool SupportsVisitors() override {return true;}
void Accept(BaseObjectVisitor &visitor) const override { return visitor.Visit(*this); }

protected:
virtual void InitModel() override;
Expand Down
44 changes: 38 additions & 6 deletions xLights/models/BaseObjectVisitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,44 @@
**************************************************************/

class ArchesModel;
class CandyCaneModel;
class ChannelBlockModel;
class CircleModel;
class CubeModel;
class CustomModel;
class ImageModel;
class IciclesModel;
class MatrixModel;
class SingleLineModel;
class PolyLineModel;
class SphereModel;
class SpinnerModel;
class StarModel;
class TreeModel;
class WindowFrameModel;
class WreathModel;
class DmxMovingHeadAdv;

struct BaseObjectVisitor
{
virtual void Visit(const ArchesModel &arch) = 0;
virtual void Visit(const DmxMovingHeadAdv &moving_head) = 0;
struct BaseObjectVisitor {
virtual void Visit(const ArchesModel& arch) = 0;
virtual void Visit(const CandyCaneModel& cc) = 0;
virtual void Visit(const ChannelBlockModel& channelblock) = 0;
virtual void Visit(const CircleModel& circle) = 0;
virtual void Visit(const CubeModel& cube) = 0;
virtual void Visit(const CustomModel& custom) = 0;
virtual void Visit(const ImageModel& image) = 0;
virtual void Visit(const IciclesModel& icicles) = 0;
virtual void Visit(const MatrixModel& matrix) = 0;
virtual void Visit(const SingleLineModel& singleline) = 0;
virtual void Visit(const PolyLineModel& polyline) = 0;
virtual void Visit(const SphereModel& sphere) = 0;
virtual void Visit(const SpinnerModel& spinner) = 0;
virtual void Visit(const StarModel& start) = 0;
virtual void Visit(const TreeModel& tree) = 0;
virtual void Visit(const WindowFrameModel& window) = 0;
virtual void Visit(const WreathModel& wreath) = 0;
virtual void Visit(const DmxMovingHeadAdv& moving_head) = 0;

virtual ~BaseObjectVisitor() {}
};
virtual ~BaseObjectVisitor() {
}
};
2 changes: 2 additions & 0 deletions xLights/models/CandyCaneModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,8 @@ static void rotate_point(float cx,float cy, float angle, float &x, float &y)
y = ynew + cy;
}

void CandyCaneModel::ExportXlightsModel() {}

void CandyCaneModel::SetCaneCoord() {

static log4cpp::Category& logger_base = log4cpp::Category::getInstance(std::string("log_base"));
Expand Down
9 changes: 9 additions & 0 deletions xLights/models/CandyCaneModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,20 @@ class CandyCaneModel : public ModelWithScreenLocation<ThreePointScreenLocation>
virtual void AddTypeProperties(wxPropertyGridInterface* grid, OutputManager* outputManager) override;
virtual void UpdateTypeProperties(wxPropertyGridInterface* grid) override;
virtual int OnPropertyGridChange(wxPropertyGridInterface *grid, wxPropertyGridEvent& event) override;
virtual bool SupportsXlightsModel() override { return true; }
virtual void ExportXlightsModel() override;
virtual bool SupportsExportAsCustom() const override { return true; }
virtual bool SupportsWiringView() const override { return true; }
virtual std::string GetDimension() const override;
virtual void AddDimensionProperties(wxPropertyGridInterface* grid) override;

virtual bool SupportsVisitors() override { return true; }
void Accept(BaseObjectVisitor& visitor) const override { return visitor.Visit(*this); }
bool IsReverse() const { return _reverse; }
bool IsSticks() const { return _sticks; }
bool HasAlternateNodes() const { return _alternateNodes; }
float GetCandyCaneHeight() const { return _caneheight; }

protected:
virtual void InitModel() override;
virtual int MapToNodeIndex(int strand, int node) const override;
Expand Down
10 changes: 10 additions & 0 deletions xLights/models/ChannelBlockModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -243,3 +243,13 @@ int ChannelBlockModel::GetNumStrands() const {
int ChannelBlockModel::CalcCannelsPerString() {
return GetNodeChannelCount(StringType);
}
void ChannelBlockModel::ExportXlightsModel() {}

std::vector<std::string> ChannelBlockModel::GetChannelProperies() const {
std::vector<std::string> channelPropColour;
for (auto i = 0; i < GetNumStrands(); i++) {
wxString nm = ChanColorAttrName(i);
channelPropColour.push_back(ModelXml->GetAttribute("ChannelProperties." + nm).ToStdString());
}
return channelPropColour;
}
6 changes: 6 additions & 0 deletions xLights/models/ChannelBlockModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ class ChannelBlockModel : public ModelWithScreenLocation<TwoPointScreenLocation>
virtual int GetNumPhysicalStrings() const override { return 1; }
virtual bool SupportsExportAsCustom() const override { return false; }
virtual bool SupportsWiringView() const override { return false; }
virtual bool SupportsXlightsModel() override { return true; }
virtual void ExportXlightsModel() override;
std::vector<std::string> GetChannelProperies() const;

virtual bool SupportsVisitors() override { return true; }
void Accept(BaseObjectVisitor& visitor) const override { return visitor.Visit(*this); }

protected:
virtual void InitModel() override;
Expand Down
4 changes: 4 additions & 0 deletions xLights/models/CircleModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ class CircleModel : public ModelWithScreenLocation<BoxedScreenLocation>
virtual bool ModelSupportsLayerSizes() const override { return true; }
virtual void OnLayerSizesChange(bool countChanged) override;

virtual bool SupportsVisitors() override { return true; }
void Accept(BaseObjectVisitor& visitor) const override { return visitor.Visit(*this); }
bool IsInsideOut() const { return insideOut; }

protected:
virtual void InitModel() override;

Expand Down
16 changes: 16 additions & 0 deletions xLights/models/CubeModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,22 @@ std::string CubeModel::GetStartLocation() const
return ModelXml->GetAttribute("Start", "") + " " + ModelXml->GetAttribute("Style", "");
}

std::string CubeModel::GetStrandStart() const {
return ModelXml->GetAttribute("Start", "");
}

std::string CubeModel::GetStrandStyle() const {
return ModelXml->GetAttribute("Style", "");
}

std::string CubeModel::GetStrandPerLine() const {
return ModelXml->GetAttribute("StrandPerLine", "");
}

std::string CubeModel::GetStrandPerLayer() const {
return ModelXml->GetAttribute("StrandPerLayer", "");
}

std::vector<std::tuple<int, int, int>> CubeModel::BuildCube() const
{
static log4cpp::Category &logger_base = log4cpp::Category::getInstance(std::string("log_base"));
Expand Down
18 changes: 10 additions & 8 deletions xLights/models/CubeModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,23 @@ class CubeModel : public ModelWithScreenLocation<BoxedScreenLocation>
virtual int GetNumStrands() const override { return _strands; };
virtual int MapToNodeIndex(int strand, int node) const override;
virtual void ExportAsCustomXModel3D() const override;
virtual bool SupportsExportAsCustom3D() const override
{
return true;
}
virtual bool SupportsExportAsCustom() const override
{
return false;
}
virtual bool SupportsExportAsCustom3D() const override { return true; }
virtual bool SupportsExportAsCustom() const override { return false; }
virtual int NodesPerString() const override;

virtual std::string ChannelLayoutHtml(OutputManager * outputManager) override;

virtual void AddTypeProperties(wxPropertyGridInterface* grid, OutputManager* outputManager) override;
virtual int OnPropertyGridChange(wxPropertyGridInterface *grid, wxPropertyGridEvent& event) override;

virtual bool SupportsVisitors() override { return true; }
void Accept(BaseObjectVisitor& visitor) const override { return visitor.Visit(*this); }

std::string GetStrandStyle() const;
std::string GetStrandPerLine() const;
std::string GetStrandPerLayer() const;
std::string GetStrandStart() const;

protected:
int GetStartIndex() const;
int GetStyleIndex() const;
Expand Down
Loading
Loading