Skip to content

Commit

Permalink
Add editable text ability to DrawSymbol
Browse files Browse the repository at this point in the history
  • Loading branch information
WandererFan authored and wwmayer committed Nov 18, 2016
1 parent 140a14c commit eb2490b
Show file tree
Hide file tree
Showing 4 changed files with 327 additions and 12 deletions.
19 changes: 7 additions & 12 deletions src/Mod/TechDraw/App/DrawViewSymbol.cpp
Expand Up @@ -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()) {
Expand All @@ -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();
}

Expand Down
110 changes: 110 additions & 0 deletions src/Mod/TechDraw/Gui/Resources/ToleranceSymbols/flatness_editable.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
111 changes: 111 additions & 0 deletions src/Mod/TechDraw/Gui/Resources/ToleranceSymbols/tolerance_editable.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit eb2490b

Please sign in to comment.