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 1 commit
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
4 changes: 2 additions & 2 deletions xLights/models/ArchesModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ class ArchesModel : public ModelWithScreenLocation<ThreePointScreenLocation>
int GetHollow() const { return _hollow; }
int GetGap() const { return _gap; }

//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
5 changes: 5 additions & 0 deletions xLights/models/CandyCaneModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,16 @@ 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); }

protected:
virtual void InitModel() override;
virtual int MapToNodeIndex(int strand, int node) const override;
Expand Down
3 changes: 3 additions & 0 deletions xLights/models/CircleModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ 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); }

protected:
virtual void InitModel() override;

Expand Down
4 changes: 2 additions & 2 deletions xLights/models/ModelGroup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ bool ModelGroup::ContainsModelOrSubmodel(Model* m) const
return found;
}

bool ModelGroup::ContainsModel(Model* m) const
bool ModelGroup::ContainsModel(const Model* m) const
{
wxASSERT(m->GetDisplayAs() != "ModelGroup");

Expand Down Expand Up @@ -227,7 +227,7 @@ bool ModelGroup::ContainsModel(Model* m) const
return found;
}

bool ModelGroup::ContainsModel(Model* m, std::list<const Model*>& visited) const
bool ModelGroup::ContainsModel(const Model* m, std::list<const Model*>& visited) const
{
visited.push_back(this);

Expand Down
4 changes: 2 additions & 2 deletions xLights/models/ModelGroup.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ class ModelGroup : public ModelWithScreenLocation<BoxedScreenLocation>
bool ContainsModelGroup(ModelGroup* mg, std::set<Model*>& visited);
bool DirectlyContainsModel(Model* m) const;
bool DirectlyContainsModel(std::string const& m) const;
bool ContainsModel(Model* m) const;
bool ContainsModel(Model* m, std::list<const Model*>& visited) const;
bool ContainsModel(const Model* m) const;
bool ContainsModel(const Model* m, std::list<const Model*>& visited) const;
bool ContainsModelOrSubmodel(Model* m) const;
bool ContainsModelOrSubmodel(Model* m, std::list<const Model*>& visited) const;
bool OnlyContainsModel(const std::string& name) const;
Expand Down
15 changes: 14 additions & 1 deletion xLights/models/ModelManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1700,7 +1700,7 @@ std::string ModelManager::GetModelsOnChannels(uint32_t start, uint32_t end, int
return res;
}

std::vector<std::string> ModelManager::GetGroupsContainingModel(Model* model) const
std::vector<std::string> ModelManager::GetGroupsContainingModel(const Model* model) const
{
std::vector<std::string> res;
for (const auto& it : *this) {
Expand Down Expand Up @@ -1742,6 +1742,19 @@ std::vector<std::string> ModelManager::GetGroupsContainingModelOrSubmodel(Model*
return res;
}

std::vector<Model*> ModelManager::GetModelGroups(const Model* model) const {
std::vector<Model*> res;
for (const auto& it : *this) {
if (it.second->GetDisplayAs() == "ModelGroup") {
auto mg = dynamic_cast<ModelGroup*>(it.second);
if (mg->ContainsModel(model)) {
res.push_back(mg);
}
}
}
return res;
}

std::string ModelManager::GenerateNewStartChannel(const std::string& lastModel) const
{
std::string startChannel = "1";
Expand Down
3 changes: 2 additions & 1 deletion xLights/models/ModelManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,9 @@ class ModelManager : public ObjectManager
bool IsValidControllerModelChain(Model* m, std::string& tip) const;
Model *createAndAddModel(wxXmlNode *node, int previewW, int previewH);
std::string GetModelsOnChannels(uint32_t start, uint32_t end, int perLine) const;
std::vector<std::string> GetGroupsContainingModel(Model* model) const;
std::vector<std::string> GetGroupsContainingModel(const Model* model) const;
std::vector<std::string> GetGroupsContainingModelOrSubmodel(Model* model) const;
std::vector<Model*> GetModelGroups(const Model* model) const;
std::string GenerateNewStartChannel(const std::string& lastModel = "") const;

int GetPreviewWidth() const { return previewWidth; }
Expand Down
Loading
Loading