Skip to content

Commit

Permalink
Import Effects add option to convert to 'Per Model' #2787
Browse files Browse the repository at this point in the history
  • Loading branch information
derwin12 committed Feb 4, 2025
1 parent ac7692b commit e024707
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 17 deletions.
48 changes: 37 additions & 11 deletions xLights/SeqFileUtilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1056,8 +1056,9 @@ void xLightsFrame::OnMenuItemImportEffects(wxCommandEvent& event)
}
}

void MapXLightsEffects(EffectLayer* target, EffectLayer* src, std::vector<EffectLayer*>& mapped, bool eraseExisting, SequencePackage& xsqPkg, bool lock, const std::map<std::string, std::string>& mapping)
{
void MapXLightsEffects(EffectLayer* target, EffectLayer* src, std::vector<EffectLayer*>& mapped,
bool eraseExisting, SequencePackage& xsqPkg,
bool lock, const std::map<std::string, std::string>& mapping, bool convertRender) {
if (eraseExisting)
target->DeleteAllEffects();

Expand Down Expand Up @@ -1091,6 +1092,30 @@ void MapXLightsEffects(EffectLayer* target, EffectLayer* src, std::vector<Effect
if (m != nullptr) {
auto mg = dynamic_cast<const ModelGroup*>(m);
if (mg != nullptr) {

if (convertRender) {
Model* sm = src->GetParentElement()->GetSequenceElements()->GetXLightsFrame()->GetModel(src->GetParentElement()->GetModelName());
if (sm != nullptr) {
if (sm->GetDisplayAs() != "ModelGroup") {
auto buffer = ef->GetSettings()["B_CHOICE_BufferStyle"];
if (buffer == "Per Preview" || buffer == "Default" || buffer == "Single Line") {
Replace(settings, "B_CHOICE_BufferStyle=" + buffer,
"B_CHOICE_BufferStyle=Per Model " + buffer);
} else if (buffer.empty()) {
if (Contains(settings, "B_CHOICE_BufferStyle")) {
Replace(settings, "B_CHOICE_BufferStyle=",
"B_CHOICE_BufferStyle=Per Model Default");
} else {
if (!settings.empty()) {
settings += ",";
}
settings += "B_CHOICE_BufferStyle=Per Model Default";
}
}
}
}
}

// so is it a per preview render buffer
auto rb = ef->GetSettings()["B_CHOICE_BufferStyle"];
if (BufferPanel::CanRenderBufferUseCamera(rb)) {
Expand Down Expand Up @@ -1132,7 +1157,7 @@ void MapXLightsStrandEffects(EffectLayer* target, const std::string& name,
std::map<std::string, EffectLayer*>& layerMap,
SequenceElements& seqEl,
std::vector<EffectLayer*>& mapped, bool eraseExisting,
SequencePackage& xsqPkg, bool lock, const std::map<std::string, std::string>& mapping)
SequencePackage& xsqPkg, bool lock, const std::map<std::string, std::string>& mapping, bool convertRender)
{
EffectLayer* src = layerMap[name];
if (src == nullptr) {
Expand All @@ -1144,7 +1169,7 @@ void MapXLightsStrandEffects(EffectLayer* target, const std::string& name,
src = srcEl->GetEffectLayer(0);
}
if (src != nullptr) {
MapXLightsEffects(target, src, mapped, eraseExisting, xsqPkg, lock, mapping);
MapXLightsEffects(target, src, mapped, eraseExisting, xsqPkg, lock, mapping, convertRender);
} else {
printf("Source strand %s doesn't exist\n", name.c_str());
}
Expand All @@ -1156,7 +1181,7 @@ void MapXLightsEffects(Element* target,
std::map<std::string, Element*>& elementMap,
std::map<std::string, EffectLayer*>& layerMap,
std::vector<EffectLayer*>& mapped, bool eraseExisting,
SequencePackage& xsqPkg, bool lock, const std::map<std::string, std::string>& mapping)
SequencePackage& xsqPkg, bool lock, const std::map<std::string, std::string>& mapping, bool convertRender)
{
static log4cpp::Category& logger_base = log4cpp::Category::getInstance(std::string("log_base"));
if (target->GetType() == ElementType::ELEMENT_TYPE_STRAND) {
Expand All @@ -1170,7 +1195,7 @@ void MapXLightsEffects(Element* target,
Element* el = elementMap[name];

if (src != nullptr) {
MapXLightsEffects(target->GetEffectLayer(0), src, mapped, eraseExisting, xsqPkg, lock, mapping);
MapXLightsEffects(target->GetEffectLayer(0), src, mapped, eraseExisting, xsqPkg, lock, mapping, convertRender);
return;
}

Expand All @@ -1189,7 +1214,7 @@ void MapXLightsEffects(Element* target,
}
for (size_t x = 0; x < el->GetEffectLayerCount(); ++x) {
target->GetEffectLayer(x)->SetLayerName(el->GetEffectLayer(x)->GetLayerName());
MapXLightsEffects(target->GetEffectLayer(x), el->GetEffectLayer(x), mapped, eraseExisting, xsqPkg, lock, mapping);
MapXLightsEffects(target->GetEffectLayer(x), el->GetEffectLayer(x), mapped, eraseExisting, xsqPkg, lock, mapping, convertRender);
}
}

Expand Down Expand Up @@ -1352,6 +1377,7 @@ void xLightsFrame::ImportXLights(SequenceElements& se, const std::vector<Element
}

bool lock = dlg.IsLockEffects();
bool convertRender = dlg.IsConvertRenderStyle();

// if the user is importing at least one timing element and the current sequence only has one timing track called New Timing with no timing marks in it ...
if (dlg.TimingTrackListBox->GetCount() > 0 && _sequenceElements.GetNumberOfTimingElements() == 1 && _sequenceElements.GetTimingElement("New Timing") != nullptr && !_sequenceElements.GetTimingElement("New Timing")->HasEffects()) {
Expand Down Expand Up @@ -1393,7 +1419,7 @@ void xLightsFrame::ImportXLights(SequenceElements& se, const std::vector<Element
}
EffectLayer* dst = target->GetEffectLayer(l);
std::vector<EffectLayer*> mapped2;
MapXLightsEffects(dst, src, mapped2, dlg.CheckBox_EraseExistingEffects->GetValue(), xsqPkg, lock, mapping);
MapXLightsEffects(dst, src, mapped2, dlg.CheckBox_EraseExistingEffects->GetValue(), xsqPkg, lock, mapping, convertRender);
}
}
}
Expand All @@ -1415,7 +1441,7 @@ void xLightsFrame::ImportXLights(SequenceElements& se, const std::vector<Element
if (model == nullptr) {
logger_base.error("Attempt to add model %s during xLights import failed.", (const char*)modelName.c_str());
} else {
MapXLightsEffects(model, m->_mapping, se, elementMap, layerMap, mapped, dlg.CheckBox_EraseExistingEffects->GetValue(), xsqPkg, lock, mapping);
MapXLightsEffects(model, m->_mapping, se, elementMap, layerMap, mapped, dlg.CheckBox_EraseExistingEffects->GetValue(), xsqPkg, lock, mapping, convertRender);
}
}

Expand All @@ -1432,7 +1458,7 @@ void xLightsFrame::ImportXLights(SequenceElements& se, const std::vector<Element
} else {
SubModelElement* ste = model->GetSubModel(str);
if (ste != nullptr) {
MapXLightsEffects(ste, s->_mapping, se, elementMap, layerMap, mapped, dlg.CheckBox_EraseExistingEffects->GetValue(), xsqPkg, lock, mapping);
MapXLightsEffects(ste, s->_mapping, se, elementMap, layerMap, mapped, dlg.CheckBox_EraseExistingEffects->GetValue(), xsqPkg, lock, mapping, convertRender);
}
}
}
Expand All @@ -1450,7 +1476,7 @@ void xLightsFrame::ImportXLights(SequenceElements& se, const std::vector<Element
if (stre != nullptr) {
NodeLayer* nl = stre->GetNodeLayer(n, true);
if (nl != nullptr) {
MapXLightsStrandEffects(nl, ns->_mapping, layerMap, se, mapped, dlg.CheckBox_EraseExistingEffects->GetValue(), xsqPkg, lock, mapping);
MapXLightsStrandEffects(nl, ns->_mapping, layerMap, se, mapped, dlg.CheckBox_EraseExistingEffects->GetValue(), xsqPkg, lock, mapping, convertRender);
}
}
}
Expand Down
14 changes: 11 additions & 3 deletions xLights/wxsmith/xLightsImportChannelMapDialog.wxs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
<title>Map Channels</title>
<id_arg>0</id_arg>
<style>wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER|wxMAXIMIZE_BOX|wxFULL_REPAINT_ON_RESIZE</style>
<handler function="OnInit" entry="EVT_INIT_DIALOG" />
<handler function="OnClose" entry="EVT_CLOSE" />
<object class="wxFlexGridSizer" variable="OldSizer" member="yes">
<cols>1</cols>
Expand Down Expand Up @@ -65,7 +64,7 @@
</object>
<object class="sizeritem">
<object class="wxFlexGridSizer" variable="FlexGridSizer11" member="yes">
<cols>2</cols>
<cols>3</cols>
<growablecols>0</growablecols>
<object class="sizeritem">
<object class="wxCheckBox" name="ID_CHECKBOX11" variable="CheckBox_EraseExistingEffects" member="yes">
Expand All @@ -84,6 +83,16 @@
<border>5</border>
<option>1</option>
</object>
<object class="sizeritem">
<object class="wxCheckBox" name="ID_CHECKBOX5" variable="CheckBox_ConvertRenderStyle" member="yes">
<label>Convert Render Style</label>
<tooltip>When mapping model to group, convert render styles to &apos;Per Model&apos; when applicable</tooltip>
<handler function="OnCheckBox_ConvertRenderStyleClick" entry="EVT_CHECKBOX" />
</object>
<flag>wxALL|wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL</flag>
<border>5</border>
<option>1</option>
</object>
</object>
<flag>wxALL|wxEXPAND</flag>
<border>1</border>
Expand Down Expand Up @@ -147,7 +156,6 @@
<object class="sizeritem">
<object class="wxCheckListBox" name="ID_CHECKLISTBOX1" variable="TimingTrackListBox" member="yes">
<style>wxLB_MULTIPLE|wxVSCROLL</style>
<handler function="OnTimingTrackListBoxToggled" entry="EVT_CHECKLISTBOX" />
</object>
<flag>wxALL|wxEXPAND</flag>
<option>1</option>
Expand Down
22 changes: 21 additions & 1 deletion xLights/xLightsImportChannelMapDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,7 @@ const wxWindowID xLightsImportChannelMapDialog::ID_SPINCTRL1 = wxNewId();
const wxWindowID xLightsImportChannelMapDialog::ID_CHECKBOX1 = wxNewId();
const wxWindowID xLightsImportChannelMapDialog::ID_CHECKBOX11 = wxNewId();
const wxWindowID xLightsImportChannelMapDialog::ID_CHECKBOX4 = wxNewId();
const wxWindowID xLightsImportChannelMapDialog::ID_CHECKBOX5 = wxNewId();
const wxWindowID xLightsImportChannelMapDialog::ID_CHECKBOX2 = wxNewId();
const wxWindowID xLightsImportChannelMapDialog::ID_STATICTEXT_BLEND_TYPE = wxNewId();
const wxWindowID xLightsImportChannelMapDialog::ID_CHECKBOX3 = wxNewId();
Expand Down Expand Up @@ -526,14 +527,18 @@ xLightsImportChannelMapDialog::xLightsImportChannelMapDialog(wxWindow* parent, c
CheckBox_MapCCRStrand->SetValue(false);
FlexGridSizer1->Add(CheckBox_MapCCRStrand, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
Sizer1->Add(FlexGridSizer1, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 1);
FlexGridSizer11 = new wxFlexGridSizer(0, 2, 0, 0);
FlexGridSizer11 = new wxFlexGridSizer(0, 3, 0, 0);
FlexGridSizer11->AddGrowableCol(0);
CheckBox_EraseExistingEffects = new wxCheckBox(Panel1, ID_CHECKBOX11, _("Erase existing effects on imported models"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_CHECKBOX11"));
CheckBox_EraseExistingEffects->SetValue(false);
FlexGridSizer11->Add(CheckBox_EraseExistingEffects, 1, wxALL|wxEXPAND, 5);
CheckBox_LockEffects = new wxCheckBox(Panel1, ID_CHECKBOX4, _("Lock effects on import"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_CHECKBOX4"));
CheckBox_LockEffects->SetValue(true);
FlexGridSizer11->Add(CheckBox_LockEffects, 1, wxALL|wxEXPAND, 5);
CheckBox_ConvertRenderStyle = new wxCheckBox(Panel1, ID_CHECKBOX5, _("Convert Render Style"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_CHECKBOX5"));
CheckBox_ConvertRenderStyle->SetValue(false);
CheckBox_ConvertRenderStyle->SetToolTip(_("When mapping model to group, convert render styles to \'Per Model\' when applicable"));
FlexGridSizer11->Add(CheckBox_ConvertRenderStyle, 1, wxALL|wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL, 5);
Sizer1->Add(FlexGridSizer11, 1, wxALL|wxEXPAND, 1);
FlexGridSizer_Blend_Mode = new wxFlexGridSizer(0, 2, 0, 0);
CheckBox_Import_Blend_Mode = new wxCheckBox(Panel1, ID_CHECKBOX2, _("Import Model Blend Mode"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_CHECKBOX2"));
Expand Down Expand Up @@ -616,6 +621,7 @@ xLightsImportChannelMapDialog::xLightsImportChannelMapDialog(wxWindow* parent, c
OldSizer->SetSizeHints(this);

Connect(ID_CHECKBOX1, wxEVT_COMMAND_CHECKBOX_CLICKED, (wxObjectEventFunction)&xLightsImportChannelMapDialog::OnCheckBox_MapCCRStrandClick);
Connect(ID_CHECKBOX5, wxEVT_COMMAND_CHECKBOX_CLICKED, (wxObjectEventFunction)&xLightsImportChannelMapDialog::OnCheckBox_ConvertRenderStyleClick);
Connect(ID_CHECKBOX3, wxEVT_COMMAND_CHECKBOX_CLICKED, (wxObjectEventFunction)&xLightsImportChannelMapDialog::OnCheckBoxImportMediaClick);
Connect(ID_BUTTON_IMPORT_OPTIONS, wxEVT_COMMAND_BUTTON_CLICKED, (wxObjectEventFunction)&xLightsImportChannelMapDialog::OnButtonImportOptionsClick);
Connect(ID_TEXTCTRL2, wxEVT_COMMAND_TEXT_UPDATED, (wxObjectEventFunction)&xLightsImportChannelMapDialog::OnTextCtrl_FindToText);
Expand Down Expand Up @@ -663,6 +669,7 @@ xLightsImportChannelMapDialog::xLightsImportChannelMapDialog(wxWindow* parent, c

wxConfigBase* config = wxConfigBase::Get();
CheckBox_LockEffects->SetValue(config->ReadBool("ImportEffectsLocked", false));
CheckBox_ConvertRenderStyle->SetValue(config->ReadBool("ImportEffectsRenderStyle", false));

EnsureWindowHeaderIsOnScreen(this);
}
Expand Down Expand Up @@ -916,6 +923,15 @@ bool xLightsImportChannelMapDialog::IsLockEffects() const
return b;
}

bool xLightsImportChannelMapDialog::IsConvertRenderStyle() const
{
wxConfigBase* config = wxConfigBase::Get();
bool b = CheckBox_ConvertRenderStyle->IsChecked();
config->Write("ImportEffectsRenderStyle", b);
config->Flush();
return b;
}

void xLightsImportChannelMapDialog::SetXsqPkg(SequencePackage* xsqPkg) {
_xsqPkg = xsqPkg;
}
Expand Down Expand Up @@ -2814,3 +2830,7 @@ void xLightsImportChannelMapDialog::OnClose(wxCloseEvent& event)
EndDialog(wxID_CANCEL);
}
}

void xLightsImportChannelMapDialog::OnCheckBox_ConvertRenderStyleClick(wxCommandEvent& event)
{
}
8 changes: 6 additions & 2 deletions xLights/xLightsImportChannelMapDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,8 @@ class xLightsImportChannelMapDialog: public wxDialog
bool InitImport(std::string checkboxText = "");
void SetModelBlending(bool enabled);
[[nodiscard]] bool GetImportModelBlending() const;
[[nodiscard]] bool IsLockEffects() const;
[[nodiscard]] bool IsLockEffects() const;
[[nodiscard]] bool IsConvertRenderStyle() const;
void SetXsqPkg(SequencePackage* xsqPkg);
[[nodiscard]] std::vector<std::string> const GetChannelNames() const;
[[nodiscard]] ImportChannel* GetImportChannel(std::string const& name) const;
Expand All @@ -399,6 +400,7 @@ class xLightsImportChannelMapDialog: public wxDialog
wxButton* Button_Ok;
wxButton* Button_UpdateAliases;
wxCheckBox* CheckBoxImportMedia;
wxCheckBox* CheckBox_ConvertRenderStyle;
wxCheckBox* CheckBox_EraseExistingEffects;
wxCheckBox* CheckBox_Import_Blend_Mode;
wxCheckBox* CheckBox_LockEffects;
Expand Down Expand Up @@ -444,6 +446,7 @@ class xLightsImportChannelMapDialog: public wxDialog
static const wxWindowID ID_CHECKBOX1;
static const wxWindowID ID_CHECKBOX11;
static const wxWindowID ID_CHECKBOX4;
static const wxWindowID ID_CHECKBOX5;
static const wxWindowID ID_CHECKBOX2;
static const wxWindowID ID_STATICTEXT_BLEND_TYPE;
static const wxWindowID ID_CHECKBOX3;
Expand Down Expand Up @@ -488,7 +491,7 @@ class xLightsImportChannelMapDialog: public wxDialog
void OnListCtrl_AvailableColumnClick(wxListEvent& event);
void OnCheckBox_MapCCRStrandClick(wxCommandEvent& event);
void OnButton_AutoMapClick(wxCommandEvent& event);
void OnButton_AutoMapSelClick(wxCommandEvent& event);
void OnButton_AutoMapSelClick(wxCommandEvent& event);
void OnListCtrl_AvailableItemActivated(wxListEvent& event);
void OnButtonImportOptionsClick(wxCommandEvent& event);
void OnCheckBoxImportMediaClick(wxCommandEvent& event);
Expand All @@ -497,6 +500,7 @@ class xLightsImportChannelMapDialog: public wxDialog
void OnButton_UpdateAliasesClick(wxCommandEvent& event);
void OnClose(wxCloseEvent& event);
void OnInit(wxInitDialogEvent& event);
void OnCheckBox_ConvertRenderStyleClick(wxCommandEvent& event);
//*)

void RightClickTimingTracks(wxContextMenuEvent& event);
Expand Down

0 comments on commit e024707

Please sign in to comment.