Skip to content

Commit

Permalink
Allow old XML formats to import
Browse files Browse the repository at this point in the history
  • Loading branch information
AzGilrock committed May 12, 2024
1 parent 5f6bab9 commit fa45c66
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion xLights/LayoutPanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3664,7 +3664,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
if (!_newModel->SupportsVisitors()) {
if (!_newModel->SupportsVisitors() && !XmlSerializer::IsXmlSerializerFormat(_newModel->GetModelXml())) {
xlights->AddTraceMessage("LayoutPanel::FinalizeModel Do the import. " + _lastXlightsModel);
xlights->AddTraceMessage("LayoutPanel::FinalizeModel Model type " + _newModel->GetDisplayAs());
_newModel->ImportXlightsModel(_lastXlightsModel, xlights, min_x, max_x, min_y, max_y);
Expand Down
2 changes: 1 addition & 1 deletion xLights/models/Model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6363,7 +6363,7 @@ Model* Model::GetXlightsModel(Model* model, std::string& last_model, xLightsFram
wxXmlNode* root = doc.GetRoot();

// check for XmlSerializer format
if (root->GetAttribute(XmlNodeKeys::TypeAttribute, "") == XmlNodeKeys::ExportedAttribute) {
if (XmlSerializer::IsXmlSerializerFormat(root)) {
// grab the attributes I want to keep
std::string startChannel = model->GetModelXml()->GetAttribute("StartChannel", "1").ToStdString();
auto x = model->GetHcenterPos();
Expand Down
8 changes: 8 additions & 0 deletions xLights/models/XmlSerializer.h
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,14 @@ struct XmlSerializer
{
}

static bool IsXmlSerializerFormat(const wxXmlNode *node)
{
if (node->GetAttribute(XmlNodeKeys::TypeAttribute, "") == XmlNodeKeys::ExportedAttribute) {
return true;
}
return false;
}

// Serializes and Saves a single model into an XML document
void SerializeAndSaveModel(const BaseObject &object)
{
Expand Down

9 comments on commit fa45c66

@cybercop23
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AzGilrock I manually merged these into mine and it doesn't crash like it did on some imports, but I still get no node data. Do you get asctual node data? Here's after my import and saved rgbeffects
image

@AzGilrock
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested the model download function and that worked for the Rosa Grande.

@cybercop23
Copy link
Collaborator

@cybercop23 cybercop23 commented on fa45c66 May 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested the model download function and that worked for the Rosa Grande.

Great... I must have broken something with all my changes to the XMLSerializer. I'll take a look

@AzGilrock
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah but that was importing an old model so it shouldn't be going through any of the XmlSerializer code except that new function that checks the format.

@cybercop23
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah but that was importing an old model so it shouldn't be going through any of the XmlSerializer code except that new function that checks the format.

Ahh ha... if you turn on SupportVisitors() in CustomModel.h you get that I see. If I remove that, I can import it. So when support is turned on it "thinks" it has it and the bumps out still somewhere.

@AzGilrock
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But the change I just committed checks the XML format even if the SupportVisitors is active to make sure the file format is acceptable.

@AzGilrock
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How you trying to import?

@AzGilrock
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change that new line I added to an || instead of an &&

@cybercop23
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yup.. that works now... tried several from diff vendors and all working.

Please sign in to comment.