Skip to content

Commit

Permalink
Fix model paste when no model is selected. Fixes #4551
Browse files Browse the repository at this point in the history
  • Loading branch information
AzGilrock committed May 7, 2024
1 parent 5867983 commit dd59049
Showing 1 changed file with 22 additions and 19 deletions.
41 changes: 22 additions & 19 deletions xLights/LayoutPanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6979,13 +6979,15 @@ void LayoutPanel::DoPaste(wxCommandEvent& event) {
if (copyData.IsOk())
{
wxXmlNode* nd = copyData.GetBaseObjectXml();
std::string source_model_name = xlEMPTY_STRING;

if (nd != nullptr)
{
auto nda = nd->GetAttribute("DisplayAs");
auto nx = (int)wxAtof(nd->GetAttribute("WorldPosX"));
auto ny = (int)wxAtof(nd->GetAttribute("WorldPosY"));
auto nz = (int)wxAtof(nd->GetAttribute("WorldPosZ"));
source_model_name = nd->GetAttribute("name");

bool moved = true;
while (moved)
Expand Down Expand Up @@ -7067,27 +7069,28 @@ void LayoutPanel::DoPaste(wxCommandEvent& event) {
lastModelName = name;
}


Model* sourceModel = xlights->GetModel(this->selectedBaseObject->name);
auto inModelGroups = sourceModel->GetModelManager().GetGroupsContainingModel(sourceModel);
if (!inModelGroups.empty()) {
if (wxMessageBox("Should I add model to the same group(s) as the original?", "Add to groups?", wxICON_QUESTION | wxYES_NO) == wxYES) {
for (const auto& grp : inModelGroups) {
Model* addToGroup = xlights->GetModel(grp);
if (!addToGroup->IsFromBase()) {
wxXmlNode* node = addToGroup->GetModelXml();
wxArrayString groupModels = wxSplit(node->GetAttribute("models", ""), ',');
int groupItems = groupModels.GetCount(); // we'll keep adding items, keep inital count
for (int i = 0; i < groupItems; i++) {
if (groupModels[i].StartsWith(selectedBaseObject->name)) {
wxString addnew = groupModels[i];
addnew.Replace(selectedBaseObject->name, name);
groupModels.Add(addnew);
Model* sourceModel = xlights->GetModel(source_model_name);
if (sourceModel != nullptr) {
auto inModelGroups = sourceModel->GetModelManager().GetGroupsContainingModel(sourceModel);
if (!inModelGroups.empty()) {
if (wxMessageBox("Should I add model to the same group(s) as the original?", "Add to groups?", wxICON_QUESTION | wxYES_NO) == wxYES) {
for (const auto& grp : inModelGroups) {
Model* addToGroup = xlights->GetModel(grp);
if (!addToGroup->IsFromBase()) {
wxXmlNode* node = addToGroup->GetModelXml();
wxArrayString groupModels = wxSplit(node->GetAttribute("models", ""), ',');
int groupItems = groupModels.GetCount(); // we'll keep adding items, keep inital count
for (int i = 0; i < groupItems; i++) {
if (groupModels[i].StartsWith(source_model_name)) {
wxString addnew = groupModels[i];
addnew.Replace(source_model_name, name);
groupModels.Add(addnew);
}
}
wxString xmlModels = wxJoin(groupModels, ',');
node->DeleteAttribute("models");
node->AddAttribute("models", xmlModels);
}
wxString xmlModels = wxJoin(groupModels, ',');
node->DeleteAttribute("models");
node->AddAttribute("models", xmlModels);
}
}
}
Expand Down

0 comments on commit dd59049

Please sign in to comment.