Example #1
0
void xLightsFrame::UpdateModelsList()
{
    std::string name, start_channel;
    int end_channel;
    wxArrayString model_names;
    Model *model;
	ListBoxElementList->DeleteAllItems();
    PreviewModels.clear();
    AllModels.clear();
    wxString msg;
    int num_group_models = 0;
	int itemCount = 0;

    // Set models in selected modelgroups as part of display.
    for(wxXmlNode* e=ModelGroupsNode->GetChildren(); e!=NULL; e=e->GetNext() )
    {
        if (e->GetName() == "modelGroup")
        {
            if(e->GetAttribute("selected") == "1")
            {
                wxArrayString ModelsInGroup=wxSplit(e->GetAttribute("models"),',');
                for(int i=0;i<ModelsInGroup.size();i++)
                {
                    for(wxXmlNode* e=ModelsNode->GetChildren(); e!=NULL; e=e->GetNext() )
                    {
                        if (e->GetName() == "model")
                        {
                            name=e->GetAttribute("name");
                            if (name == ModelsInGroup[i])
                            {
                                bool model_already_added = false;
                                for(int k = 0; k < model_names.size(); k++)
                                {
                                    if( model_names[k] == name )
                                    {
                                        model_already_added = true;
                                        break;
                                    }
                                }
                                if( !model_already_added )
                                {
                                    model = AllModels.createModel(e, NetInfo);

                                    if (model->GetLastChannel() >= NetInfo.GetTotChannels()) {
                                        msg += wxString::Format("%s - last channel: %u\n",name, model->GetLastChannel());
                                    }
                                    if (Model::IsMyDisplay(e))
                                    {
                                        long itemIndex = ListBoxElementList->InsertItem(ListBoxElementList->GetItemCount(),name);
                                        start_channel = e->GetAttribute("StartChannel");
                                        model->SetModelStartChan(start_channel);
                                        wxString string_type = e->GetAttribute("StringType");
                                        int parm1 = wxAtoi(e->GetAttribute("parm1"));
                                        int parm2 = wxAtoi(e->GetAttribute("parm2"));
                                        wxString display_as = e->GetAttribute("DisplayAs");
                                        end_channel = model->GetLastChannel()+1;
                                        ListBoxElementList->SetItem(itemIndex,1,start_channel);
                                        ListBoxElementList->SetItem(itemIndex,2, wxString::Format(wxT("%i"),end_channel));
                                        ListBoxElementList->SetItemPtrData(itemIndex,(wxUIntPtr)model);
                                        PreviewModels.push_back(model);
                                    }
                                    model_names.push_back(name);
                                    num_group_models++;
                                }
                            }
                        }
                    }
                }
            }
        }
    }

    if( num_group_models == 0 )
    {
        for(wxXmlNode* e=ModelsNode->GetChildren(); e!=NULL; e=e->GetNext() )
        {
            if (e->GetName() == "model")
            {
                name=e->GetAttribute("name");
                if (!name.empty())
                {
                    model = AllModels.createModel(e, NetInfo);

                    if (model->GetLastChannel() >= NetInfo.GetTotChannels()) {
                        msg += wxString::Format("%s - last channel: %u\n",name, model->GetLastChannel());
                    }
                    if (Model::IsMyDisplay(e))
                    {
                        long itemIndex = ListBoxElementList->InsertItem(ListBoxElementList->GetItemCount(),name);
                        start_channel = e->GetAttribute("StartChannel");
                        model->SetModelStartChan(start_channel);
                        wxString string_type = e->GetAttribute("StringType");
                        int parm1 = wxAtoi(e->GetAttribute("parm1"));
                        int parm2 = wxAtoi(e->GetAttribute("parm2"));
                        wxString display_as = e->GetAttribute("DisplayAs");
                        end_channel = model->GetLastChannel()+1;
                        ListBoxElementList->SetItem(itemIndex,1,start_channel);
                        ListBoxElementList->SetItem(itemIndex,2, wxString::Format(wxT("%i"),end_channel));
                        ListBoxElementList->SetItemPtrData(itemIndex,(wxUIntPtr)model);
                        PreviewModels.push_back(model);
                    }
                }
            }
        }
    }
    ListBoxElementList->SortItems(MyCompareFunction,0);
    ListBoxElementList->SetColumnWidth(0,wxLIST_AUTOSIZE);
    ListBoxElementList->SetColumnWidth(1,wxLIST_AUTOSIZE);
    ListBoxElementList->SetColumnWidth(2,wxLIST_AUTOSIZE);
    if (msg != "") {
        wxMessageBox(wxString::Format("These models extends beyond the number of configured channels (%u):\n", NetInfo.GetTotChannels()) + msg);
    }
}