Add editable text ability to DrawSymbol

This commit is contained in:
WandererFan
2016-11-08 19:40:30 -05:00
committed by wmayer
parent 93fd19ada8
commit b6448d26d0
4 changed files with 327 additions and 12 deletions

View File

@@ -65,6 +65,8 @@ void DrawViewSymbol::onChanged(const App::Property* prop)
{
if (prop == &Symbol) {
if (!isRestoring()) {
//this pulls the initial values from svg into editabletexts
// should only happen first time?? extra loop onChanged->execute->onChanged
std::vector<string> eds;
std::string svg = Symbol.getValue();
if (!svg.empty()) {
@@ -89,34 +91,27 @@ App::DocumentObjectExecReturn *DrawViewSymbol::execute(void)
std::string svg = Symbol.getValue();
const std::vector<std::string>& editText = EditableTexts.getValues();
//this pushes the editabletexts into the svg
std::string newsvg = svg;
if (!editText.empty()) {
//TODO: has this ever been run?
boost::regex e1 ("<text.*?freecad:editable=\"(.*?)\".*?<tspan.*?>(.*?)</tspan>");
string::const_iterator begin, end;
begin = svg.begin();
end = svg.end();
boost::match_results<std::string::const_iterator> what;
std::size_t count = 0;
std::string newsvg;
newsvg.reserve(svg.size());
while (boost::regex_search(begin, end, what, e1)) {
if (count < editText.size()) {
// change values of editable texts. Also strip the "freecad:editable"
// attribute so it isn't detected by the page
boost::regex e2 ("(<text.*?)(freecad:editable=\""+what[1].str()+"\")(.*?<tspan.*?)>(.*?)(</tspan>)");
std::back_insert_iterator<std::string> out(newsvg);
boost::regex_replace(out, begin, what[0].second, e2, "$1$3>"+editText[count]+"$5");
boost::regex e2 ("(<text.*?freecad:editable=\"" + what[1].str() + "\".*?<tspan.*?)>(.*?)(</tspan>)");
newsvg = boost::regex_replace(newsvg, e2, "$1>" + editText[count] + "$3");
}
count++;
begin = what[0].second;
}
// now copy the rest
newsvg.insert(newsvg.end(), begin, end);
svg = newsvg;
}
//TODO: shouldn't there be a Symbol.setValue(svg) here??? -wf
Symbol.setValue(newsvg);
return DrawView::execute();
}