void Falcon::SetOutputs(ModelManager* allmodels, OutputManager* outputManager, std::list<int>& selected, wxWindow* parent) { //ResetStringOutputs(); // this shouldnt be used normally static log4cpp::Category &logger_base = log4cpp::Category::getInstance(std::string("log_base")); logger_base.debug("Falcon Outputs Upload: Uploading to %s", (const char *)_ip.c_str()); // build a list of models on this controller std::list<Model*> models; std::list<std::string> protocolsused; std::list<Model*> warnedmodels; int maxport = 0; // Get universes based on IP std::list<Output*> outputs = outputManager->GetAllOutputs(_ip); // get outputs based on selected std::list<Output*> o2 = outputManager->GetAllOutputs(selected); // now merge them together and eleminate the duplicates outputs.merge(o2); outputs.sort(); outputs.unique(); for (auto ito = outputs.begin(); ito != outputs.end(); ++ito) { // this universe is sent to the falcon // find all the models in this range for (auto it = allmodels->begin(); it != allmodels->end(); ++it) { if (it->second->GetDisplayAs() != "ModelGroup") { int modelstart = it->second->GetNumberFromChannelString(it->second->ModelStartChannel); int modelend = modelstart + it->second->GetChanCount() - 1; if ((modelstart >= (*ito)->GetStartChannel() && modelstart <= (*ito)->GetEndChannel()) || (modelend >= (*ito)->GetStartChannel() && modelend <= (*ito)->GetEndChannel())) { //logger_base.debug("Model %s start %d end %d found on controller %s output %d start %d end %d.", // (const char *)it->first.c_str(), modelstart, modelend, // (const char *)_ip.c_str(), node, currentcontrollerstartchannel, currentcontrollerendchannel); if (!it->second->IsControllerConnectionValid()) { // only warn if we have not already warned if (std::find(warnedmodels.begin(), warnedmodels.end(), it->second) == warnedmodels.end()) { warnedmodels.push_back(it->second); logger_base.warn("Falcon Outputs Upload: Model %s on controller %s does not have its Controller Connection details completed: '%s'. Model ignored.", (const char *)it->first.c_str(), (const char *)_ip.c_str(), (const char *)it->second->GetControllerConnection().c_str()); wxMessageBox("Model " + it->first + " on controller " + _ip + " does not have its Contoller Connection details completed: '" + it->second->GetControllerConnection() + "'. Model ignored.", "Model Ignored"); } } else { // model uses channels in this universe // check we dont already have this model in our list if (std::find(models.begin(), models.end(), it->second) == models.end()) { logger_base.debug("Falcon Outputs Upload: Uploading Model %s.", (const char *)it->first.c_str()); models.push_back(it->second); if (std::find(protocolsused.begin(), protocolsused.end(), it->second->GetProtocol()) == protocolsused.end()) { protocolsused.push_back(it->second->GetProtocol()); } if (it->second->GetPort() > maxport) { maxport = it->second->GetPort(); } } } } } } } // sort the models by start channel models.sort(compare_startchannel); // get the current config before I start std::string strings = GetURL("/strings.xml"); if (strings == "") { logger_base.error("Falcon Outputs Upload: Falcon would not return strings.xml."); wxMessageBox("Error occured trying to upload to Falcon.", "Error", wxOK, parent); return; } // for each protocol for (auto protocol = protocolsused.begin(); protocol != protocolsused.end(); ++protocol) { std::string sendmessage; int count = 0; bool portdone[100]; memset(&portdone, 0x00, sizeof(portdone)); // all false // for each port ... this is the max of any port type but it should be ok for (int i = 1; i <= maxport; i++) { // find the first and last Model* first = nullptr; Model* last = nullptr; int highestend = 0; long loweststart = 999999999; for (auto model = models.begin(); model != models.end(); ++model) { if ((*model)->GetProtocol() == *protocol && (*model)->GetPort() == i) { int modelstart = (*model)->GetNumberFromChannelString((*model)->ModelStartChannel); int modelend = modelstart + (*model)->GetChanCount() - 1; if (modelstart < loweststart) { loweststart = modelstart; first = *model; } if (modelend > highestend) { highestend = modelend; last = *model; } } } if (first != nullptr) { int portstart = first->GetNumberFromChannelString(first->ModelStartChannel); int portend = last->GetNumberFromChannelString(last->ModelStartChannel) + last->GetChanCount() - 1; int numstrings = first->GetNumStrings(); bool multistringelement = (first->GetDisplayAs() == "Matrix" || first->GetDisplayAs() == "Tree" || first->GetDisplayAs() == "Circle" || first->GetDisplayAs() == "Star" || first->GetDisplayAs() == "Wreath" || first->GetDisplayAs() == "Icicles"); int channelsperstring = first->NodesPerString() * first->GetChanCountPerNode(); // upload it if (DecodeStringPortProtocol(*protocol) >= 0) { if (first == last && numstrings > 1 && multistringelement) { for (int j = 0; j < numstrings; j++) { if (portdone[i+j]) { logger_base.warn("Falcon Outputs Upload: Attempt to upload model %s to string port %d but this string port already has a model on it.", (const char *)first->GetName().c_str(), i +j); wxMessageBox(wxString::Format("Attempt to upload model %s to string port %d but this string port already has a model on it.", (const char *)first->GetName().c_str(), i + j)); } else { portdone[i + j] = true; count++; if (sendmessage != "") sendmessage = sendmessage + "&"; sendmessage = sendmessage + BuildStringPort(strings, i + j, DecodeStringPortProtocol(*protocol), portstart + j * channelsperstring, channelsperstring / 3, first->GetName(), parent); if (count == 40) { UploadStringPort(sendmessage, false); sendmessage = ""; count = 0; } } } } else { if (portdone[i]) { logger_base.warn("Falcon Outputs Upload: Attempt to upload model %s to string port %d but this string port already has a model on it.", (const char *)first->GetName().c_str() , i); wxMessageBox(wxString::Format("Attempt to upload model %s to string port %d but this string port already has a model on it.", (const char *)first->GetName().c_str(), i)); } else { portdone[i] = true; count++; if (sendmessage != "") sendmessage = sendmessage + "&"; sendmessage = sendmessage + BuildStringPort(strings, i, DecodeStringPortProtocol(*protocol), portstart, (portend - portstart + 1) / 3, first->GetName(), parent); if (count == 40) { UploadStringPort(sendmessage, false); sendmessage = ""; count = 0; } } } } else if (DecodeSerialOutputProtocol(*protocol) >= 0) { UploadSerialOutput(i, DecodeSerialOutputProtocol(*protocol), portstart, parent); } else { logger_base.warn("Falcon Outputs Upload: Controller %s protocol %s not supported by this controller.", (const char *)_ip.c_str(), (const char *)protocol->c_str()); wxMessageBox("Controller " + _ip + " protocol " + (*protocol) + " not supported by this controller.", "Protocol Ignored"); } } else { // nothing on this port ... ignore it } } UploadStringPort(sendmessage, true); } }
void addModelElement(Element *elem, std::vector<Row_Information_Struct> &mRowInformation, int &rowIndex, xLightsFrame *xframe, std::vector <Element*> &elements, bool submodel) { if(!elem->GetCollapsed()) { for(int j =0; j<elem->GetEffectLayerCount();j++) { Row_Information_Struct ri; ri.element = elem; ri.displayName = elem->GetName(); ri.Collapsed = elem->GetCollapsed(); ri.Active = elem->GetActive(); ri.colorIndex = 0; ri.layerIndex = j; ri.Index = rowIndex++; ri.submodel = submodel; mRowInformation.push_back(ri); } } else { Row_Information_Struct ri; ri.element = elem; ri.Collapsed = elem->GetCollapsed(); ri.displayName = elem->GetName(); ri.Active = elem->GetActive(); ri.colorIndex = 0; ri.layerIndex = 0; ri.Index = rowIndex++; ri.submodel = submodel; mRowInformation.push_back(ri); } Model *cls = xframe->GetModel(elem->GetName()); if (cls == nullptr) { return; } elem->InitStrands(*cls); if (cls->GetDisplayAs() == "WholeHouse" && elem->ShowStrands()) { wxString models = cls->GetModelXml()->GetAttribute("models"); wxArrayString model=wxSplit(models,','); for(int m=0;m<model.size();m++) { for (int x = 0; x < elements.size(); x++) { if (elements[x]->GetName() == model[m]) { addModelElement(elements[x], mRowInformation, rowIndex, xframe, elements, true); } } } } else if (elem->ShowStrands()) { for (int s = 0; s < elem->getStrandLayerCount(); s++) { StrandLayer * sl = elem->GetStrandLayer(s); if (elem->getStrandLayerCount() > 1) { Row_Information_Struct ri; ri.element = elem; ri.Collapsed = !elem->ShowStrands(); ri.Active = elem->GetActive(); ri.displayName = sl->GetName(); ri.colorIndex = 0; ri.layerIndex = 0; ri.Index = rowIndex++; ri.strandIndex = s; ri.submodel = submodel; mRowInformation.push_back(ri); } if (sl->ShowNodes()) { for (int n = 0; n < sl->GetNodeLayerCount(); n++) { Row_Information_Struct ri; ri.element = elem; ri.Collapsed = sl->ShowNodes(); ri.Active = !elem->GetActive(); ri.displayName = sl->GetNodeLayer(n)->GetName(); ri.colorIndex = 0; ri.layerIndex = 0; ri.Index = rowIndex++; ri.strandIndex = s; ri.nodeIndex = n; ri.submodel = submodel; mRowInformation.push_back(ri); } } } } }