Add editable text ability to DrawSymbol

This commit is contained in:
WandererFan 2016-11-08 19:40:30 -05:00 committed by wmayer
parent 140a14c58c
commit eb2490bb33
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();
}

View File

@ -0,0 +1,110 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
version="1.1"
width="20.741266"
height="8.2433271"
viewBox="0 0 20.741266 8.2433267"
id="svg2">
<title
id="title4147">Flatness</title>
<defs
id="defs4" />
<metadata
id="metadata7">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title>Flatness</dc:title>
<dc:creator>
<cc:Agent>
<dc:title>bavariaSHAPE</dc:title>
</cc:Agent>
</dc:creator>
<dc:rights>
<cc:Agent>
<dc:title>bavariaSHAPE</dc:title>
</cc:Agent>
</dc:rights>
<dc:publisher>
<cc:Agent>
<dc:title>bavariaSHAPE</dc:title>
</cc:Agent>
</dc:publisher>
<dc:date>15.10.2016</dc:date>
<dc:description>Geometric dimensioning and tolerancing symbols
All symbols in this repository are licensed under CC-BY 3.0</dc:description>
<dc:identifier />
<dc:coverage />
<cc:license
rdf:resource="http://creativecommons.org/licenses/by/3.0/" />
</cc:Work>
<cc:License
rdf:about="http://creativecommons.org/licenses/by/3.0/">
<cc:permits
rdf:resource="http://creativecommons.org/ns#Reproduction" />
<cc:permits
rdf:resource="http://creativecommons.org/ns#Distribution" />
<cc:requires
rdf:resource="http://creativecommons.org/ns#Notice" />
<cc:requires
rdf:resource="http://creativecommons.org/ns#Attribution" />
<cc:permits
rdf:resource="http://creativecommons.org/ns#DerivativeWorks" />
</cc:License>
</rdf:RDF>
</metadata>
<g
transform="translate(-2.0328137,-1035.8325)"
id="layer1"
style="display:inline">
<g
transform="translate(-6.2371755,-1.2183655e-5)"
id="g3805">
<rect
width="7.1852894"
height="7.1852894"
x="8.8089304"
y="1036.368"
id="rect4136"
style="color:#000000;fill:#ffffff;fill-opacity:1;fill-rule:nonzero;stroke:#000000;stroke-width:0.35964566;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;stroke-dashoffset:0;visibility:visible;display:inline;overflow:visible;enable-background:accumulate" />
<rect
width="3.8867688"
height="3.8123877"
x="685.31183"
y="1237.83"
transform="matrix(1,0,-0.54435264,0.83885648,0,0)"
id="rect4219"
style="color:#000000;fill:#ffffff;fill-opacity:1;fill-rule:nonzero;stroke:#000000;stroke-width:0.39267296;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;stroke-dashoffset:0;visibility:visible;display:inline;overflow:visible;enable-background:accumulate" />
<rect
width="12.462819"
height="7.1683803"
x="16.004406"
y="1036.3766"
id="rect3031"
style="color:#000000;fill:#ffffff;fill-opacity:1;fill-rule:nonzero;stroke:#000000;stroke-width:0.36233681;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;stroke-dashoffset:0;visibility:visible;display:inline;overflow:visible;enable-background:accumulate" />
<text
freecad:editable="flatness"
x="17.047827"
y="1041.8041"
id="text3801"
xml:space="preserve"
style="font-size:5px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;text-indent:0;text-align:start;text-decoration:none;line-height:100%;letter-spacing:0px;word-spacing:0px;text-transform:none;direction:ltr;block-progression:tb;writing-mode:lr-tb;text-anchor:start;baseline-shift:baseline;color:#000000;fill:#000000;fill-opacity:1;fill-rule:evenodd;stroke:none;stroke-width:0.28200001;marker:none;visibility:visible;display:inline;overflow:visible;enable-background:accumulate;font-family:osifont;-inkscape-font-specification:osifont"><tspan
x="17.047827"
y="1041.8041"
id="tspan3803">0.000</tspan></text>
</g>
</g>
<g
transform="translate(-2.0328137,-8.2733795)"
id="layer2" />
</svg>

After

Width:  |  Height:  |  Size: 4.5 KiB

View File

@ -0,0 +1,99 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
version="1.1"
width="8.2535963"
height="8.2535963"
viewBox="0 0 8.2535962 8.2535959"
id="svg2">
<title
id="title4147">Reference</title>
<defs
id="defs4" />
<metadata
id="metadata7">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title>Angularity</dc:title>
<dc:creator>
<cc:Agent>
<dc:title>bavariaSHAPE</dc:title>
</cc:Agent>
</dc:creator>
<dc:rights>
<cc:Agent>
<dc:title>bavariaSHAPE</dc:title>
</cc:Agent>
</dc:rights>
<dc:publisher>
<cc:Agent>
<dc:title>bavariaSHAPE</dc:title>
</cc:Agent>
</dc:publisher>
<dc:date>15.10.2016</dc:date>
<dc:description>Geometric dimensioning and tolerancing symbols
All symbols in this repository are licensed under CC-BY 3.0</dc:description>
<dc:identifier />
<dc:coverage />
<cc:license
rdf:resource="http://creativecommons.org/licenses/by/3.0/" />
</cc:Work>
<cc:License
rdf:about="http://creativecommons.org/licenses/by/3.0/">
<cc:permits
rdf:resource="http://creativecommons.org/ns#Reproduction" />
<cc:permits
rdf:resource="http://creativecommons.org/ns#Distribution" />
<cc:requires
rdf:resource="http://creativecommons.org/ns#Notice" />
<cc:requires
rdf:resource="http://creativecommons.org/ns#Attribution" />
<cc:permits
rdf:resource="http://creativecommons.org/ns#DerivativeWorks" />
</cc:License>
</rdf:RDF>
</metadata>
<g
transform="translate(-8.2747763,-1035.8339)"
id="layer1"
style="display:inline">
<g
transform="translate(-21.608749,-1.2183655e-5)"
id="g4151">
<g
id="g4146">
<rect
width="7.1852894"
height="7.1852894"
x="30.417679"
y="1036.368"
id="rect4136-4"
style="color:#000000;fill:#ffffff;fill-opacity:1;fill-rule:nonzero;stroke:#000000;stroke-width:0.35964566;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;stroke-dashoffset:0;visibility:visible;display:inline;overflow:visible;enable-background:accumulate" />
<text
freecad:editable="reference"
x="33.975941"
y="1041.7771"
id="text5288"
xml:space="preserve"
style="font-size:5.07499981px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:condensed;text-align:center;line-height:100%;letter-spacing:0px;word-spacing:0px;writing-mode:lr-tb;text-anchor:middle;fill:#000000;fill-opacity:1;stroke:none;font-family:Arial Narrow;-inkscape-font-specification:'Arial Narrow, Condensed'"><tspan
x="33.975941"
y="1041.7771"
id="tspan5290"
style="font-size:5.07499981px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:condensed;text-align:center;line-height:100%;writing-mode:lr-tb;text-anchor:middle;font-family:Arial Narrow;-inkscape-font-specification:'Arial Narrow, Condensed'">A</tspan></text>
</g>
</g>
</g>
<g
transform="translate(-8.2747763,-8.2747788)"
id="layer2" />
</svg>

After

Width:  |  Height:  |  Size: 3.7 KiB

View File

@ -0,0 +1,111 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
width="15.491278"
height="8.2412777"
viewBox="0 0 15.491278 8.2412773"
id="svg2"
version="1.1"
inkscape:version="0.48.4 r9939"
sodipodi:docname="_tolerance_editableTD.svg">
<title
id="title5262">Frame 4 Symbol</title>
<defs
id="defs4" />
<sodipodi:namedview
id="base"
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1.0"
inkscape:pageopacity="0.0"
inkscape:pageshadow="2"
inkscape:zoom="16"
inkscape:cx="11.778556"
inkscape:cy="4.6049939"
inkscape:document-units="mm"
inkscape:current-layer="layer1"
showgrid="false"
inkscape:window-width="1366"
inkscape:window-height="694"
inkscape:window-x="0"
inkscape:window-y="25"
inkscape:window-maximized="1"
units="mm"
fit-margin-top="0.1"
fit-margin-left="0.1"
fit-margin-right="0.1"
fit-margin-bottom="0.1" />
<metadata
id="metadata7">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title>Frame 4 Symbol</dc:title>
<dc:creator>
<cc:Agent>
<dc:title>bavariaSHAPE</dc:title>
</cc:Agent>
</dc:creator>
<dc:rights>
<cc:Agent>
<dc:title>bavariaSHAPE</dc:title>
</cc:Agent>
</dc:rights>
<dc:publisher>
<cc:Agent>
<dc:title>bavariaSHAPE</dc:title>
</cc:Agent>
</dc:publisher>
<dc:date>15.10.2016</dc:date>
<dc:description>Geometric dimensioning and tolerancing</dc:description>
</cc:Work>
</rdf:RDF>
</metadata>
<g
inkscape:label="Rahmen"
inkscape:groupmode="layer"
id="layer1"
transform="translate(-4.6494243,-1035.8325)"
style="display:inline">
<g
id="g5909"
transform="translate(-10.808062,-1.6236771e-5)">
<rect
y="1036.3671"
x="15.99638"
height="7.1872506"
width="14.426514"
id="rect4136-0"
style="color:#000000;fill:#ffffff;fill-opacity:1;fill-rule:nonzero;stroke:#000000;stroke-width:0.35811549;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;stroke-dashoffset:0;visibility:visible;display:inline;overflow:visible;enable-background:accumulate" />
<text
freecad:editable="tolerance"
sodipodi:linespacing="100%"
id="text5269"
y="1041.7535"
x="23.514435"
style="font-size:5.07499981px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:condensed;text-align:center;line-height:100%;letter-spacing:0px;word-spacing:0px;writing-mode:lr-tb;text-anchor:middle;fill:#000000;fill-opacity:1;stroke:none;font-family:Arial Narrow;-inkscape-font-specification:'Arial Narrow, Condensed'"
xml:space="preserve"><tspan
style="font-size:5.07499981px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:condensed;text-align:center;line-height:100%;writing-mode:lr-tb;text-anchor:middle;font-family:Arial Narrow;-inkscape-font-specification:'Arial Narrow, Condensed'"
y="1041.7535"
x="23.514435"
id="tspan5271"
sodipodi:role="line">0.01</tspan></text>
</g>
</g>
<g
inkscape:groupmode="layer"
id="layer2"
inkscape:label="Symbol"
transform="translate(-4.6494243,-8.2733706)" />
</svg>

After

Width:  |  Height:  |  Size: 3.9 KiB