6 #include <QElapsedTimer> 11 , _linked_plot_name(snippet.linkedSource.toStdString())
12 , _plot_name(snippet.
name.toStdString())
26 bool newly_added =
false;
29 if (dst_data_it == plotData.
numeric.end())
35 PlotData& dst_data = dst_data_it->second;
46 plotData.
numeric.erase(dst_data_it);
48 std::rethrow_exception(std::current_exception());
60 if (src_data_it == plotData.
numeric.end())
66 const PlotData& src_data = src_data_it->second;
67 if (src_data.
size() == 0)
75 std::vector<const PlotData*> channel_data;
80 auto it = plotData.
numeric.find(channel);
81 if (it == plotData.
numeric.end())
83 throw std::runtime_error(
"Invalid channel name");
85 const PlotData* chan_data = &(it->second);
86 channel_data.push_back(chan_data);
90 if (dst_data->
size() != 0)
92 last_updated_stamp = dst_data->
back().
x;
95 for (
size_t i = 0; i < src_data.
size(); ++i)
97 if (src_data.
at(i).
x > last_updated_stamp)
123 return std::make_unique<LuaCustomFunction>(
snippet);
128 if (xml_text.isEmpty()){
133 QString parseErrorMsg;
135 if (!doc.setContent(xml_text, &parseErrorMsg, &parseErrorLine))
137 QMessageBox::critical(
139 QString(
"Failed to parse snippets (xml), error %1 at line %2").
arg(parseErrorMsg).
arg(parseErrorLine));
144 QDomElement snippets_element = doc.documentElement();
153 for (
auto elem = snippets_element.firstChildElement(
"snippet");
155 elem = elem.nextSiblingElement(
"snippet") )
158 snippets.insert({ snippet.
name, snippet });
166 auto snippets_root = doc.createElement(
"snippets");
168 for (
const auto& it : snippets)
170 const auto&
snippet = it.second;
172 snippets_root.appendChild(element);
174 return snippets_root;
180 snippet.
linkedSource = element.firstChildElement(
"linkedSource").text().trimmed();
181 snippet.
name = element.attribute(
"name");
182 snippet.
globalVars = element.firstChildElement(
"global").text().trimmed();
183 snippet.
function = element.firstChildElement(
"function").text().trimmed();
185 auto additional_el = element.firstChildElement(
"additionalSources");
186 if( !additional_el.isNull() )
189 auto tag_name = QString(
"v%1").arg(count);
190 auto source_el = additional_el.firstChildElement( tag_name );
191 while( !source_el.isNull() )
194 tag_name = QString(
"v%1").arg(++count);
195 source_el = additional_el.firstChildElement( tag_name );
204 auto element = doc.createElement(
"snippet");
206 element.setAttribute(
"name", snippet.
name);
208 auto global_el = doc.createElement(
"global");
209 global_el.appendChild(doc.createTextNode(snippet.
globalVars));
210 element.appendChild(global_el);
212 auto equation_el = doc.createElement(
"function");
213 equation_el.appendChild(doc.createTextNode(snippet.
function));
214 element.appendChild(equation_el);
216 auto linked_el = doc.createElement(
"linkedSource");
217 linked_el.appendChild(doc.createTextNode(snippet.
linkedSource));
218 element.appendChild(linked_el);
222 auto sources_el = doc.createElement(
"additionalSources");
227 auto tag_name = QString(
"v%1").arg(count++);
228 auto source_el = doc.createElement(tag_name);
229 source_el.appendChild(doc.createTextNode(curve_name));
230 sources_el.appendChild(source_el);
233 element.appendChild(sources_el);
const Point & back() const
const Point & at(size_t index) const
std::vector< std::string > _used_channels
std::map< QString, SnippetData > SnippetsMap
std::unordered_map< std::string, PlotData > numeric
SnippetData GetSnippetFromXML(const QDomElement &element)
const std::string & name() const
QDomElement ExportSnippets(const SnippetsMap &snippets, QDomDocument &doc)
double maximumRangeX() const
const std::string & linkedPlotName() const
const std::string _plot_name
void calculate(const PlotDataMapRef &plotData, PlotData *dst_data)
std::shared_ptr< CustomFunction > CustomPlotPtr
void setMaximumRangeX(double max_range)
SnippetsMap GetSnippetsFromXML(const QString &xml_text)
const SnippetData _snippet
virtual size_t size() const
detail::named_arg< Char, T > arg(const Char *name, const T &arg)
static CustomPlotPtr createFromXML(QDomElement &element)
const SnippetData & snippet() const
const std::string _linked_plot_name
QDomElement ExportSnippetToXML(const SnippetData &snippet, QDomDocument &doc)
void pushBack(const Point &p)
virtual PlotData::Point calculatePoint(const PlotData &src_data, const std::vector< const PlotData * > &channels_data, size_t point_index)=0
std::unordered_map< std::string, PlotData >::iterator addNumeric(const std::string &name)
CustomFunction(const SnippetData &snippet)
QStringList additionalSources
QDomElement xmlSaveState(QDomDocument &doc) const
void calculateAndAdd(PlotDataMapRef &plotData)
virtual void initEngine()=0