Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implementation of simplify script #7

Merged
merged 19 commits into from
Jun 20, 2020
Merged

Implementation of simplify script #7

merged 19 commits into from
Jun 20, 2020

Conversation

LoveMHz
Copy link
Owner

@LoveMHz LoveMHz commented Jun 12, 2020

Here's the initial go at creating a script to address the need of simplifying SVGs and preparing them for GIT consumption.

This should address issue #2

  • Removes unneeded attributes from all elements while keeping compatibility.
  • Removes incremental IDs placed by Inkscape in favor of UUIDs.
  • Orders attributes and elements in a predictable manner.

Sample output

<?xml version="1.0" encoding="UTF-8"?>
<svg height="2470.1499mm" viewBox="0 0 2222.5 2470.1499" width="2222.5mm" xmlns:cc="http://creativecommons.org/ns#" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" xmlns:pcbre="https://github.com/LoveMHz/xbox-board-re/namespaces/pcbre" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" xmlns:svg="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
	<g inkscape:groupmode="layer" inkscape:label="Board Bottom" pcbre:uuid="10000000-0000-0000-0000-000000000000" sodipodi="true" style="display:inline" transform="translate(1005.4167,1086.2416)">
		<path height="2470.1499" pcbre:uuid="5970a9f4-21c6-467c-bbd3-0d373485ec38" preserveAspectRatio="none" width="2222.5" x="-1005.4167" xlink:href="board_1_6_bottom.png" y="-1086.2416"/>
	</g>
	<g inkscape:groupmode="layer" inkscape:label="Board Top" pcbre:uuid="10000000-0000-0000-0000-000000000001" sodipodi="true" style="display:inline" transform="translate(1005.4167,1086.2416)">
		<path height="2470.1499" pcbre:uuid="750ae726-a798-484d-b36e-8373915822c8" preserveAspectRatio="none" width="2222.5" x="-1005.4167" xlink:href="board_1_6_top.png" y="-1086.2416"/>
	</g>
	<g inkscape:groupmode="layer" inkscape:label="Bottom Zones" pcbre:uuid="10000000-0000-0000-0000-000000000002" sodipodi="true" style="display:inline" transform="translate(1005.4167,1086.2416)">
		<path d="m 4326.4844,-750.80859 -15.6582,15.6582 v 422.74805 l 106.1953,113.74609 a 19.115218,19.115218 0 0 1 2.1758,0.0586 19.115218,19.115218 0 0 1 17.2304,20.82618 v 0.0156 a 19.115218,19.115218 0 0 1 -9.4707,14.71484 l 0.039,0.14063 v 2705.6953 l -403.8086,403.8086 v 783.1192 l 75.8868,75.8886 v 119.0703 l 26.3281,26.3282 189.5996,-0.6328 15,-16.7852 1.0723,-148.5723 6.0703,-5.7148 20,0.3574 42.8574,0.3555 12.5,-12.4961 v -48.9297 h -52.8574 l -18.75,-18.75 v -164.1074 l -79.0176,-79.0176 h -24.7324 v -160.9844 h -10.3574 l -47.6778,-47.6777 h -15.5351 l -30.627,-30.625 v -173.4824 l 87.2774,-87.2774 h 278.3496 l 21.0039,-21.0039 V -273.9082 l -59.7871,-59.78907 -2.4903,-417.11132 z m -162.127,4030.21479 a 21.514325,21.514325 0 0 1 1.5156,0.088 21.514325,21.514325 0 0 1 19.3946,23.4414 v 0.016 a 21.514325,21.514325 0 0 1 -23.4511,19.3808 21.514325,21.514325 0 0 1 -19.3848,-23.4472 21.514325,21.514325 0 0 1 21.9277,-19.4786 z m 116.168,231.3243 a 21.514325,21.514325 0 0 1 1.5156,0.09 21.514325,21.514325 0 0 1 19.3945,23.4395 v 0.018 a 21.514325,21.514325 0 0 1 -23.4512,19.3789 21.514325,21.514325 0 0 1 -19.3847,-23.4472 21.514325,21.514325 0 0 1 21.9277,-19.4785 z m -8.5859,79.8027 a 21.514325,21.514325 0 0 1 1.5156,0.088 21.514325,21.514325 0 0 1 19.3945,23.4394 v 0.018 a 21.514325,21.514325 0 0 1 -23.4512,19.3809 21.514325,21.514325 0 0 1 -19.3848,-23.4473 21.514325,21.514325 0 0 1 21.9278,-19.4785 z m 41.416,114.1465 a 21.514325,21.514325 0 0 1 1.5156,0.09 21.514325,21.514325 0 0 1 19.3945,23.4395 v 0.018 a 21.514325,21.514325 0 0 1 -23.4512,19.3789 21.514325,21.514325 0 0 1 -19.3848,-23.4473 21.514325,21.514325 0 0 1 21.9278,-19.4785 z m -167.1797,76.2656 a 21.514325,21.514325 0 0 1 1.5156,0.09 21.514325,21.514325 0 0 1 19.3945,23.4394 v 0.018 a 21.514325,21.514325 0 0 1 -23.4512,19.3789 21.514325,21.514325 0 0 1 -19.3848,-23.4473 21.514325,21.514325 0 0 1 21.9278,-19.4785 z" inkscape:connector-curvature="0" inkscape:label="Copper Fill" pcbre:uuid="06a02822-a00b-4322-8fb3-56cdc6cb6c8d" style="opacity:0.5;fill:#00ffff;stroke:#000000;stroke-width:0.99999994px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" transform="scale(0.26458333)"/>
		<path d="m -121.42485,-128.88467 1.55915,-1.55915 h 5.24442 19.749257 v 3.827 l -2.396485,1.38362 v 10.33365 h -9.698752 l -1.97929,1.14274 -4.21193,-4.21194 v -3.73437 h -8.17188 z" inkscape:connector-curvature="0" inkscape:label="Copper Fill" pcbre:uuid="1140ae62-0742-4a51-bca9-4318f0f029d1" style="opacity:0.5;fill:#00ffff;stroke:#000000;stroke-width:0.99999994px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"/>
	</g>
	<g inkscape:groupmode="layer" inkscape:label="Top Zones" pcbre:uuid="10000000-0000-0000-0000-000000000003" sodipodi="true" style="display:inline" transform="translate(1005.4167,1086.2416)">
		<path d="m -1481.7852,-2049.623 -595.5937,0.2636 -28.2832,34.3457 h -171.7266 l -37.9843,30.8086 v 287.9981 l 33.2304,33.2304 v 365.1387 h 10.3574 l 7.8575,10.3574 -1.0723,95.7149 36.4277,30.4453 h 208.125 l 123.8399,123.8398 v 79.46488 l 29.4648,29.46484 h 194.2852 l 14.7324,20.35547 v 225.98242 l 19.1973,19.19727 h 168.75 l 13.75,-13.75 -0.7149,-24.64258 -2.3144,-345.9336 a 20.503911,20.503911 0 0 1 -17.4805,7.0586 20.503911,20.503911 0 0 1 -18.4746,-22.3457 20.503911,20.503911 0 0 1 12.0449,-16.7559 20.503911,20.503911 0 0 1 -14.1875,-21.459 20.503911,20.503911 0 0 1 12.5332,-16.9785 20.503911,20.503911 0 0 1 -10.3906,-19.8066 20.503911,20.503911 0 0 1 12.3301,-16.8867 20.503911,20.503911 0 0 1 -11.2598,-20.2559 20.503911,20.503911 0 0 1 22.3438,-18.4785 20.503911,20.503911 0 0 1 11.5976,5.0332 l -0.2363,-35.4648 a 20.503911,20.503911 0 0 1 -15.2305,4.8281 20.503911,20.503911 0 0 1 -18.4746,-22.3477 20.503911,20.503911 0 0 1 22.3438,-18.4785 20.503911,20.503911 0 0 1 11.1503,4.6289 l -0.1523,-22.8515 a 20.503911,20.503911 0 0 1 -17.0098,6.5488 20.503911,20.503911 0 0 1 -18.4746,-22.3477 20.503911,20.503911 0 0 1 22.3438,-18.4785 20.503911,20.503911 0 0 1 12.9531,6.3359 l -0.1758,-26.3183 a 20.503911,20.503911 0 0 1 -15.9316,5.4512 20.503911,20.503911 0 0 1 -18.4746,-22.3457 20.503911,20.503911 0 0 1 22.3418,-18.4786 20.503911,20.503911 0 0 1 11.8632,5.2754 l -0.3339,-50.1015 a 20.503911,20.503911 0 0 1 -15.7539,5.2929 20.503911,20.503911 0 0 1 -18.4747,-22.3457 20.503911,20.503911 0 0 1 22.3438,-18.4785 20.503911,20.503911 0 0 1 11.6797,5.1074 l -3.9688,-593.2656 z m -667.7285,230.2168 v 0 a 20.503911,20.503911 0 0 1 1.4414,0.084 20.503911,20.503911 0 0 1 18.4844,22.3399 v 0.016 a 20.503911,20.503911 0 0 1 -22.3516,18.4707 20.503911,20.503911 0 0 1 -18.4727,-22.3477 20.503911,20.503911 0 0 1 20.8965,-18.5624 z m 383.0098,56.4628 a 106.81984,106.81984 0 0 1 7.5254,0.4454 106.81984,106.81984 0 0 1 96.293,116.3789 l -0.01,0.086 a 106.81984,106.81984 0 0 1 -116.4394,96.2207 106.81984,106.81984 0 0 1 -96.2442,-116.418 106.81984,106.81984 0 0 1 108.8731,-96.7129 z m -470.1543,20.6797 a 20.503911,20.503911 0 0 1 1.4453,0.084 20.503911,20.503911 0 0 1 18.4824,22.3399 v 0.016 a 20.503911,20.503911 0 0 1 -22.3515,18.4707 20.503911,20.503911 0 0 1 -18.4727,-22.3477 20.503911,20.503911 0 0 1 20.8965,-18.5625 z m 776.4629,584.6172 a 20.503911,20.503911 0 0 1 -5.6504,3.6289 20.503911,20.503911 0 0 1 5.7031,4.2129 z m 0.2402,35.8457 a 20.503911,20.503911 0 0 1 -7.1679,5.0196 20.503911,20.503911 0 0 1 7.246,6.8281 z m 0.2246,33.6699 a 20.503911,20.503911 0 0 1 -9.0449,7.9141 20.503911,20.503911 0 0 1 9.1387,5.9805 z" inkscape:connector-curvature="0" inkscape:label="Copper Fill" pcbre:uuid="02eb68c8-1ea3-4add-b500-6d3201b9c6e6" style="opacity:0.5;fill:#00ffff;stroke:#000000;stroke-width:0.99999994px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" transform="scale(0.26458333)"/>
		<path d="m 1759.6855,-4062.123 -5.2832,6.8984 c 39.791,50.1979 58.6607,113.8224 52.6719,177.5976 l -0.02,0.2012 c -13.0005,136.6039 -134.2645,236.8138 -270.8711,223.8418 -25.7249,-2.4857 -50.9046,-8.9692 -74.6309,-19.2168 l -2.9804,3.8926 v 417.9727 l 145.1269,145.1269 h 243.086 l 85.5937,85.5938 v 189.5195 l -35.4746,35.4746 0.9531,238.8125 28.9278,32.5 v 18.9277 l -11.4278,11.4297 h -17.5 v 35.7129 l 29.3223,50.7891 v 198.498 l 32.1055,46.4278 c 0,0 6.7854,12.5002 -7.8575,25.3574 -28.1536,17.024 -33.873,-9.875 -33.873,-9.875 l -10.7695,-0.125 0.8886,41.3437 100.5098,1.0098 35.3555,-37.8809 c 0,0 77.7195,-144.2072 183.3418,-9.0918 l 65.1543,-1.0097 c 0,0 41.9224,-59.599 88.8945,0 h 87.8828 c 0,0 34.3451,-61.1143 86.873,0 h 84.8536 9.1152 c 7.4233,-15.3782 23.6206,-24.5247 40.623,-22.9395 14.2348,1.3616 26.7244,10.06 32.9375,22.9395 h 11.0704 81.4296 11.4239 c 7.5916,-14.9748 23.5649,-23.7879 40.2812,-22.2246 13.9624,1.3256 26.2714,9.7142 32.6113,22.2246 h 9.9688 92.2168 c 6.8642,-16.5957 23.7531,-26.7706 41.6328,-25.0821 15.075,1.4373 28.1215,11.0879 33.9082,25.0821 h 80.2324 l 63.1328,-63.1348 h 403.5567 l 242.5644,-242.5645 -2.9589,-792.957 16.0722,-13.9297 v -797.1425 h -472.9492 c 40.972,51.3285 60.4286,116.5527 54.2734,181.9394 l -0.019,0.2051 c -13.2641,139.381 -136.9932,241.6284 -276.3769,228.3926 -139.3838,-13.2365 -241.6558,-136.9456 -228.4473,-276.3321 4.7244,-49.0808 23.6572,-95.7191 54.4805,-134.205 z m 959.0586,211.7929 v 0 c 0.4363,0.011 0.8721,0.037 1.3066,0.078 10.2044,0.9647 17.6953,10.0181 16.7325,20.2227 v 0.014 c -0.9707,10.2039 -10.0285,17.6895 -20.2325,16.7207 -10.2046,-0.9687 -17.6921,-10.0258 -16.7246,-20.2305 0.9193,-9.6972 9.1781,-17.0342 18.916,-16.8047 z m -117.1777,0.5059 v 0 c 0.4363,0.01 0.8721,0.035 1.3066,0.076 10.2043,0.9648 17.6951,10.0181 16.7324,20.2226 v 0.016 c -0.9716,10.2031 -10.0291,17.6876 -20.2324,16.7188 -10.2037,-0.9687 -17.691,-10.0246 -16.7246,-20.2285 0.9193,-9.6972 9.1781,-17.0342 18.916,-16.8047 z m 58.084,0.5039 v 0 c 0.4363,0.011 0.8722,0.037 1.3067,0.078 10.2044,0.9648 17.6952,10.0181 16.7324,20.2227 v 0.016 c -0.9717,10.203 -10.0291,17.6875 -20.2324,16.7187 -10.2037,-0.9687 -17.691,-10.0246 -16.7246,-20.2285 0.9183,-9.6979 9.1774,-17.036 18.916,-16.8066 z m 60.1035,54.043 v 0 c 0.4363,0.011 0.8721,0.037 1.3066,0.078 10.2043,0.9648 17.6951,10.0181 16.7324,20.2226 v 0.016 c -0.9717,10.203 -10.0291,17.6875 -20.2324,16.7187 -10.2037,-0.9687 -17.691,-10.0246 -16.7246,-20.2285 0.9183,-9.6979 9.1774,-17.036 18.916,-16.8066 z m -117.6816,4.041 v 0 c 0.4357,0.011 0.8709,0.037 1.3047,0.078 10.2044,0.9648 17.6952,10.0181 16.7324,20.2227 v 0.014 c -0.9707,10.2038 -10.0284,17.6894 -20.2324,16.7207 -10.2038,-0.9697 -17.6902,-10.0264 -16.7227,-20.2304 0.9193,-9.6972 9.1781,-17.0342 18.9161,-16.8047 z m -504.5352,38.5273 v 0 c 0.9607,0.023 1.9203,0.079 2.877,0.1699 22.4805,2.1254 38.9833,22.0698 36.8632,44.5508 v 0.033 c -2.1391,22.4796 -22.0941,38.9704 -44.5742,36.836 -22.4802,-2.1342 -38.9753,-22.0858 -36.8457,-44.5664 2.0247,-21.3651 20.221,-37.5301 41.6758,-37.0235 z m -253.2519,0.9434 h 77.1425 v 77.8574 h -77.1425 z m 873.9668,14.5722 c 0.4369,0.011 0.8734,0.037 1.3085,0.078 10.2044,0.9647 17.6952,10.018 16.7325,20.2226 v 0.016 c -0.9716,10.2031 -10.0291,17.6876 -20.2325,16.7188 -10.2037,-0.9687 -17.691,-10.0246 -16.7246,-20.2285 0.9183,-9.698 9.1774,-17.0361 18.9161,-16.8067 z m -116.6856,1.5157 v 0 c 0.4363,0.011 0.8721,0.037 1.3066,0.078 10.2043,0.9648 17.6951,10.0181 16.7324,20.2226 v 0.014 c -0.9707,10.2038 -10.0284,17.6894 -20.2324,16.7207 -10.2045,-0.9687 -17.6921,-10.0258 -16.7246,-20.2304 0.9193,-9.6972 9.1781,-17.0342 18.916,-16.8047 z m -206.6641,5.1777 c 0.4363,0.01 0.8722,0.035 1.3067,0.076 10.2043,0.9648 17.6951,10.0181 16.7324,20.2226 v 0.016 c -0.9717,10.203 -10.0291,17.6875 -20.2324,16.7187 -10.2037,-0.9687 -17.691,-10.0246 -16.7246,-20.2285 0.9193,-9.6979 9.1792,-17.0352 18.9179,-16.8047 z m 264.7481,51.8965 v 0 c 0.4363,0.01 0.8722,0.035 1.3067,0.076 10.2043,0.9648 17.6951,10.0181 16.7324,20.2226 v 0.016 c -0.9707,10.2038 -10.0284,17.6894 -20.2324,16.7207 -10.2045,-0.9687 -17.6921,-10.0258 -16.7246,-20.2304 0.9193,-9.6972 9.1781,-17.0342 18.916,-16.8047 z m 60.1035,0.5039 v 0 c 0.4363,0.011 0.8721,0.037 1.3066,0.078 10.2044,0.9648 17.6952,10.0181 16.7324,20.2227 v 0.016 c -0.9717,10.203 -10.0291,17.6875 -20.2324,16.7187 -10.2037,-0.9687 -17.691,-10.0246 -16.7246,-20.2285 0.9183,-9.6979 9.1774,-17.036 18.916,-16.8066 z m -118.6777,0.5058 c 0.4363,0.011 0.8721,0.037 1.3066,0.078 10.2043,0.9648 17.6951,10.0181 16.7324,20.2226 v 0.014 c -0.9707,10.2038 -10.0284,17.6894 -20.2324,16.7207 -10.2046,-0.9687 -17.6921,-10.0258 -16.7246,-20.2305 0.9193,-9.698 9.1793,-17.0352 18.918,-16.8047 z m -323.4942,27.4278 v 0 c 0.4448,0.011 0.8891,0.038 1.332,0.08 10.4125,0.9843 18.0562,10.222 17.0742,20.6347 v 0.016 c -0.8431,8.7453 -7.5896,15.7626 -16.2949,16.9492 l -36.7851,36.7871 v 379.9433 l -75.0723,73.1504 c 0.3642,1.8015 0.4642,3.6463 0.2969,5.4766 v 0.014 c -0.9902,10.4128 -10.2336,18.0517 -20.6465,17.0625 -10.4119,-0.9892 -18.0514,-10.2304 -17.0645,-20.6426 0.921,-9.599 8.907,-16.9737 18.5489,-17.1289 l 70.2011,-66.1387 v -377.9238 l 40.9824,-40.9824 c -1.553,-3.1439 -2.2028,-6.6571 -1.8769,-10.1485 0.9377,-9.8956 9.3655,-17.3829 19.3027,-17.1484 z m 437.1211,76.1133 v 0 c 0.4363,0.01 0.8721,0.035 1.3066,0.076 10.2044,0.9648 17.6952,10.0181 16.7324,20.2227 v 0.016 c -0.9707,10.2038 -10.0284,17.6894 -20.2324,16.7207 -10.2045,-0.9687 -17.6921,-10.0258 -16.7246,-20.2304 0.9193,-9.6972 9.1781,-17.0342 18.916,-16.8047 z m -288.1933,0.873 c 0.4363,0.011 0.8721,0.037 1.3066,0.078 10.2044,0.9648 17.6952,10.0181 16.7324,20.2227 v 0.014 c -0.9707,10.2038 -10.0284,17.6894 -20.2324,16.7207 -10.2046,-0.9687 -17.6921,-10.0258 -16.7246,-20.2305 0.9193,-9.698 9.1793,-17.0352 18.918,-16.8047 z m 287.4355,53.4219 v 0 c 0.4363,0.011 0.8721,0.037 1.3066,0.078 10.2044,0.9648 17.6952,10.0181 16.7324,20.2227 v 0.014 c -0.9707,10.2038 -10.0284,17.6894 -20.2324,16.7207 -10.2045,-0.9687 -17.6921,-10.0258 -16.7246,-20.2304 0.9193,-9.6972 9.1781,-17.0342 18.916,-16.8047 z m -287.0937,0.5078 v 0 c 0.4363,0.01 0.8722,0.035 1.3067,0.076 10.2043,0.9648 17.6951,10.0181 16.7324,20.2226 v 0.016 c -0.9717,10.203 -10.0291,17.6875 -20.2324,16.7187 -10.2038,-0.9686 -17.6911,-10.0245 -16.7247,-20.2285 0.9193,-9.6972 9.1781,-17.0342 18.9161,-16.8047 z m 287.3476,54.041 v 0 c 0.4357,0.01 0.8708,0.035 1.3047,0.076 10.2043,0.9648 17.6951,10.0181 16.7324,20.2226 v 0.016 c -0.9707,10.2038 -10.0284,17.6894 -20.2324,16.7207 -10.2038,-0.9697 -17.6903,-10.0265 -16.7227,-20.2305 0.9193,-9.6972 9.1781,-17.0342 18.916,-16.8047 z m -287.373,0.5039 c 0.437,0.011 0.8735,0.037 1.3086,0.078 10.2036,0.9658 17.6932,10.0189 16.7304,20.2227 v 0.016 c -0.9716,10.2039 -10.0303,17.6887 -20.2343,16.7188 -10.203,-0.9697 -17.6891,-10.0252 -16.7227,-20.2285 0.9183,-9.6988 9.1786,-17.0372 18.918,-16.8067 z m -705.1602,35.4512 v 0 c 0.962,0.023 1.9228,0.079 2.8808,0.1699 22.4807,2.1263 38.9828,22.0717 36.8614,44.5528 v 0.033 c -2.1402,22.4796 -22.0961,38.9695 -44.5762,36.8339 -22.4794,-2.1352 -38.9735,-22.0865 -36.8438,-44.5664 2.0247,-21.365 20.221,-37.53 41.6758,-37.0234 z m -249.5234,3.2012 h 76.4297 v 79.2871 h -76.4297 z m 1663.9961,2.1582 v 0 c 0.4357,0.011 0.8709,0.037 1.3047,0.078 10.2043,0.9648 17.6951,10.0181 16.7324,20.2226 v 0.016 c -0.9717,10.203 -10.0291,17.6875 -20.2324,16.7187 -10.2029,-0.9697 -17.689,-10.0253 -16.7226,-20.2285 0.9183,-9.6979 9.1774,-17.036 18.916,-16.8066 z m -709.3125,12.7285 c 0.437,0.011 0.8735,0.037 1.3086,0.078 10.2036,0.9658 17.6932,10.0189 16.7304,20.2227 v 0.014 c -0.9706,10.2046 -10.0296,17.6905 -20.2343,16.7207 -10.2038,-0.9697 -17.6902,-10.0264 -16.7227,-20.2304 0.9193,-9.698 9.1793,-17.0352 18.918,-16.8047 z m 287.373,1.0098 v 0 c 0.4357,0.011 0.8709,0.037 1.3047,0.078 10.2043,0.9648 17.6951,10.0181 16.7324,20.2226 v 0.016 c -0.9717,10.203 -10.0291,17.6875 -20.2324,16.7187 -10.203,-0.9697 -17.6891,-10.0252 -16.7227,-20.2285 0.9183,-9.6979 9.1774,-17.036 18.916,-16.8066 z m 0,53.0332 v 0 c 0.4357,0.011 0.8709,0.037 1.3047,0.078 10.2043,0.9648 17.6951,10.0181 16.7324,20.2226 v 0.014 c -0.9707,10.2038 -10.0284,17.6894 -20.2324,16.7207 -10.2038,-0.9697 -17.6903,-10.0265 -16.7227,-20.2305 0.9193,-9.6971 9.1781,-17.0341 18.916,-16.8046 z m -286.8847,0.2519 v 0 c 0.4363,0.011 0.8721,0.037 1.3066,0.078 10.2044,0.9647 17.6953,10.0181 16.7325,20.2227 v 0.016 c -0.9716,10.2031 -10.0291,17.6876 -20.2325,16.7188 -10.2038,-0.9687 -17.691,-10.0246 -16.7246,-20.2286 0.9183,-9.698 9.1775,-17.0361 18.9161,-16.8066 z m 1027.3339,6.9707 v 0 c 0.9607,0.023 1.9203,0.079 2.877,0.1699 22.4814,2.1253 38.9846,22.071 36.8633,44.5528 v 0.033 c -2.1401,22.4788 -22.0949,38.9684 -44.5742,36.834 -22.4794,-2.1352 -38.9735,-22.0865 -36.8438,-44.5665 2.0247,-21.3642 20.2198,-37.529 41.6738,-37.0234 z m -911.2324,45.6211 v 0 c 0.6393,1e-4 1.2835,0.024 1.9336,0.086 10.4125,0.9846 18.0567,10.2221 17.0742,20.6348 v 0.016 c -0.9909,10.4119 -10.2324,18.0494 -20.6446,17.0606 -10.412,-0.9888 -18.053,-10.2303 -17.0664,-20.6426 0.9249,-9.7609 9.1036,-17.0868 18.7012,-17.1543 z m -116.1015,0.6953 v 0 c 0.4363,0.01 0.8721,0.035 1.3066,0.076 10.2044,0.9647 17.6952,10.018 16.7325,20.2226 v 0.016 c -0.9717,10.2031 -10.0292,17.6875 -20.2325,16.7187 -10.2037,-0.9687 -17.691,-10.0246 -16.7246,-20.2285 0.9193,-9.6972 9.1781,-17.0342 18.9161,-16.8047 z m 222.25,0.252 c 0.4369,0.01 0.8734,0.035 1.3085,0.076 10.2036,0.9657 17.6933,10.0188 16.7305,20.2227 v 0.016 c -0.9707,10.2038 -10.0284,17.6894 -20.2324,16.7207 -10.2045,-0.9687 -17.6921,-10.0258 -16.7246,-20.2304 0.9193,-9.698 9.1793,-17.0352 18.918,-16.8047 z m -54.004,0.125 c 0.6399,0 1.2868,0.022 1.9375,0.084 10.4126,0.9845 18.0548,10.2239 17.0723,20.6367 v 0.016 c -0.9909,10.4119 -10.2343,18.0493 -20.6465,17.0605 -10.4121,-0.9888 -18.053,-10.2302 -17.0664,-20.6425 0.925,-9.7616 9.1048,-17.0879 18.7031,-17.1543 z m -105.1113,0.1269 v 0 c 0.4363,0.011 0.8721,0.037 1.3066,0.078 10.2044,0.9648 17.6952,10.0181 16.7324,20.2227 v 0.014 c -0.9707,10.2038 -10.0284,17.6894 -20.2324,16.7207 -10.2046,-0.9687 -17.6921,-10.0258 -16.7246,-20.2305 0.9193,-9.6972 9.1781,-17.0342 18.916,-16.8047 z m 223.4961,0 v 0 c 0.4363,0.011 0.8721,0.037 1.3066,0.078 10.2044,0.9648 17.6952,10.0181 16.7324,20.2227 v 0.016 c -0.9716,10.2031 -10.0291,17.6876 -20.2324,16.7188 -10.2037,-0.9687 -17.691,-10.0246 -16.7246,-20.2285 0.9183,-9.698 9.1774,-17.0361 18.916,-16.8067 z m -165.2832,111.3067 c 0.4461,0.011 0.8917,0.038 1.3359,0.08 3.6186,0.3492 7.0603,1.7323 9.9141,3.9844 l 186.3145,-0.9433 56.3925,58.9179 0.8145,54.3965 h 25.1367 v 72.8574 H 2750 v -72.8574 h 24.625 l -1.0078,-50.5742 -36.2949,-33.7695 -174.459,-1.1602 c -3.9956,4.8814 -10.1593,7.4532 -16.4395,6.8594 -10.4127,-0.9882 -18.0532,-10.2298 -17.0664,-20.6426 0.9377,-9.8964 9.3667,-17.3839 19.3047,-17.1484 z m -794.3359,26.2011 c 0.4454,0.01 0.8904,0.036 1.334,0.078 6.1543,0.5914 11.6326,4.1493 14.6757,9.5312 h 240.2891 l 115.0898,115.0899 h 250.8926 l 109.1074,109.1074 H 2575 v 106.4277 h -105 v -91.7031 l -99.2852,-99.2871 H 2118.543 l -117.4317,-117.4297 h -233.3789 c -4.003,4.3147 -9.7843,6.5233 -15.6445,5.9766 -10.4127,-0.9882 -18.0532,-10.2298 -17.0664,-20.6426 0.9377,-9.8965 9.3667,-17.384 19.3047,-17.1485 z m 1091.3886,90.2344 H 2925 v 22.5 h 13.6543 c 3.693,-4.204 9.056,-6.5598 14.6504,-6.4355 0.4461,0.011 0.8917,0.038 1.3359,0.08 10.4117,0.9853 18.0544,10.2228 17.0723,20.6348 v 0.016 c -0.9911,10.412 -10.2343,18.0498 -20.6465,17.0606 -6.0225,-0.5812 -11.4049,-4.0047 -14.4844,-9.2129 H 2925 v 26.7871 h -27.8574 v 64.2852 h 31.4297 v 141.4277 h -85 v -141.4277 h 29.2851 v -64.2852 h -27.1426 z m 956.2481,75.4238 v 0 c 0.9607,0.023 1.9203,0.079 2.877,0.17 22.4813,2.1254 38.9845,22.071 36.8632,44.5527 v 0.033 c -2.1392,22.4796 -22.0942,38.9703 -44.5742,36.8359 -22.481,-2.1342 -38.9765,-22.087 -36.8457,-44.5683 2.0247,-21.3651 20.221,-37.5301 41.6758,-37.0235 z m -1198.8008,14.1426 h 181.8281 v 233.3457 h -181.8281 z m -454.2344,55.9707 c 28.7981,0 52.1442,23.0242 52.1446,51.4278 -5e-4,28.4036 -23.3466,51.4287 -52.1446,51.4277 -28.7972,-2e-4 -52.142,-23.025 -52.1425,-51.4277 4e-4,-28.4028 23.3452,-51.4276 52.1425,-51.4278 z m 823.2149,88.7481 h 72.1426 v 40.0136 h 15.8457 l 10.7968,10.7969 v 21.6543 l -12.7851,12.7852 h -13.8574 v 0.4648 h -72.1426 z m -635.3477,372.2324 c 0.4363,0.011 0.8722,0.037 1.3067,0.078 10.2044,0.9648 17.6952,10.0181 16.7324,20.2227 v 0.014 c -0.9707,10.2038 -10.0284,17.6894 -20.2324,16.7207 -10.2045,-0.9687 -17.6921,-10.0258 -16.7246,-20.2304 0.9193,-9.6979 9.1792,-17.0352 18.9179,-16.8047 z m 1121.7774,49.9121 h 99.2851 v 99.2852 h -99.2851 z m -193.8243,99.4648 c 0.4363,0.01 0.8722,0.035 1.3067,0.076 10.2044,0.9648 17.6952,10.0181 16.7324,20.2227 v 0.016 c -0.9706,10.2047 -10.0296,17.6906 -20.2344,16.7207 -10.2038,-0.9697 -17.6902,-10.0265 -16.7226,-20.2305 0.9193,-9.6979 9.1792,-17.0352 18.9179,-16.8047 z m -202.8964,5.5489 v 0 c 0.4363,0.011 0.8722,0.037 1.3067,0.078 10.2043,0.9648 17.6951,10.0181 16.7324,20.2226 v 0.016 c -0.9717,10.203 -10.0291,17.6875 -20.2324,16.7187 -10.2038,-0.9686 -17.6911,-10.0245 -16.7247,-20.2285 0.9183,-9.698 9.1775,-17.0361 18.9161,-16.8066 z" inkscape:connector-curvature="0" inkscape:label="Copper Fill" pcbre:uuid="2faa8044-70c0-4da2-9dfe-5aa46b5a47c7" style="opacity:0.5;fill:#00ffff;stroke:#000000;stroke-width:0.99999994px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" transform="scale(0.26458333)"/>
	</g>
	<g inkscape:groupmode="layer" inkscape:label="Top Traces" pcbre:uuid="10000000-0000-0000-0000-000000000004" sodipodi="true" style="display:inline" transform="translate(1005.4167,1086.2416)">
		<path d="m 0.18898809,812.08704 v 4.8192 L -10.914062,828.0093" inkscape:connector-curvature="0" pcbre:uuid="00119687-6d5b-46e3-a37a-02e3c55f714c" style="fill:none;stroke:#ff0000;stroke-width:1.25;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"/>
		<path d="m -601.35642,1165.8932 h 9.75532" inkscape:connector-curvature="0" pcbre:uuid="0078f717-2022-4220-892a-e650e770df81" style="fill:none;stroke:#ff0000;stroke-width:1.25;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"/>
		<path d="m 487.58927,-108.85193 4.63021,3.68526 v 10.110867" inkscape:connector-curvature="0" pcbre:uuid="008b8cf7-770a-4c7b-9948-52534de5d95a" style="fill:none;stroke:#ff0000;stroke-width:1.25;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"/>
	</g>
	<g inkscape:groupmode="layer" inkscape:label="Bottom Traces" pcbre:uuid="10000000-0000-0000-0000-000000000005" sodipodi="true" style="display:inline" transform="translate(1005.4167,1086.2416)">
		<path d="m -727.41521,898.30337 1.63385,6.09769 v 3.7297" inkscape:connector-curvature="0" pcbre:uuid="0061b127-8565-4838-89f7-9fca25676cbd" style="fill:none;stroke:#ff0000;stroke-width:1.25;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"/>
		<path d="m 520.75659,-56.55895 -2.4272,-4.204071 v -22.63222" inkscape:connector-curvature="0" pcbre:uuid="009e7762-1e6a-492e-8c8b-4d7be5957ca7" style="fill:none;stroke:#ff0000;stroke-width:1.25;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"/>
		<path d="m -737.14812,918.05264 4.06326,4.06323 v 3.30729 h 31.27753" inkscape:connector-curvature="0" pcbre:uuid="00e95fa7-0792-4863-a9a9-1ee72d616190" style="fill:none;stroke:#ff0000;stroke-width:1.25;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"/>
	</g>
</svg>

The code is not ready to be merged at this time.

Element was incorrectly being created with a path tag
scripts/simplify.py Outdated Show resolved Hide resolved
scripts/simplify.py Outdated Show resolved Hide resolved
sort_element_attr(new_layer)

# Sub elements of current layer
if layer.getAttribute('inkscape:label') in ['Board Bottom', 'Board Top']:
Copy link

@JayFoxRox JayFoxRox Jun 12, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should not depend on inkscape features as some people might want to use other tools (we don't know how large this project will eventually get, especially if we might do other revisions of the motherboard or other PCBs in general).
Making the tool generic will also help with making a generic workflow that other communities can re-use.

A solution would be to have 1 file per layer, or check if SVG has some layer support itself.

We could also have some preprocessor / postprocessor which splits or combines the different files into one file for inkscape. However, I don't think that's necessary anyway, as people can work top and bottom independently.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should not depend on inkscape features as some people might want to use other tools (we don't know how large this project will eventually get, especially if we might do other revisions of the motherboard or other PCBs in general).
Making the tool generic will also help with making a generic workflow that other communities can re-use.

Fixed in f327736

This commit removes all of the namespaces expect for xlink which is used for linking an external image to an element.

Instead of using Inkscape labels we are now using the element ID attribute. This appears to work correctly in Inkscape as the label for the object.

Also, removed 'inkscape:groupmode'. The side-effect of this that there are no longer 'Layers' in Inkscape, but the same functionality exists in 'Objects'.

The attribute 'inkscape:connector-curvature' was removed. I did not spend a lot of time investing this, but it appears to have no ill-effect on the output.

A solution would be to have 1 file per layer, or check if SVG has some layer support itself.
We could also have some preprocessor / postprocessor which splits or combines the different files into one file for inkscape. However, I don't think that's necessary anyway, as people can work top and bottom independently.

I feel like this outside of the scope this pull request and should be addressed in #8. I will keep this into consideration though.


# Add UUID if needed
if not element.getAttribute('pcbre:uuid'):
element.setAttribute('pcbre:uuid', str(uuid.uuid4()))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm worried about some tools eating custom tags (I'm not sure how/if SVG enables extensions and if all tools support it properly?) and would have abused the ID tag with a suffix (also because editors will display it then, so we can find it in the file if we generate a warning).

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using the id attribute appears to be the correct way to implement this functionality.
https://www.w3.org/TR/SVG2/struct.html#Core.attrib

Tested with Inkscape and it appears to work correctly.

Fixed as a side effect of f327736 though not finalized as it's more directly addressed in another comment.

scripts/simplify.py Outdated Show resolved Hide resolved
scripts/simplify.py Outdated Show resolved Hide resolved
# Sort elements
new_layer.childNodes.sort(key=lambda x: x.getAttribute('pcbre:uuid'))

def process_zones_layer(xml, layer, new_layer):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a bunch of common code that could be factored out into something like new_element = process_svg_element(old_element, allowed_attribs, default_attribs, sorted=True, ensure_uuid=True)

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed 9c7fd82

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you should keep wrappers, to make the code more readable:

def process_zones_layer(xml, layer): 
  return format_group_elements(xml, layer, element_format_rules['zones'])

Maybe also process_zone_elements(xml) (as I'm still against keeping layers at all).
You could even check if the path is filled or not (to be fair: a bit tricky due to loose SVG definition of the "style" attribute) to decide if it has to be a zone or a path.
Then you could even turn this into simplify_path_elements(xml).

new_image = xml.createElement('image')

# Recreate each allowed attribute in the newly created element
for allowed_attr in image_allowed_attrs:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should probably warn about dropped attributes (even if there might be a lot of log spam).


# Add UUID if needed
if not new_trace.getAttribute('pcbre:uuid'):
new_trace.setAttribute('pcbre:uuid', str(uuid.uuid4()))
Copy link

@JayFoxRox JayFoxRox Jun 12, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of uuid, I'd just pick the first N comma-separated symbols of the d attribute, and hash them or spit out their numbers in some form. Usually a path starts with m <x>,<y>, so this would be the start location of the path.

If the path has been re-imported into the users SVG editor, this is irrelevant, because it will already have it's uuid (wether it's a hash, or some location we once chose).

But if the users working copy does not have the hashes (because they never re-imported after our tool generated hashes), the generated hashes should still match, unless the trace was modified (like movement). If you use the position (instead of a random hash), then it would even be stable if it was moved, as long as it wasn't moved too much. If you quantize the position to some integer then this would probably improve stability and readability of the SVG.

Copy link

@JayFoxRox JayFoxRox Jun 12, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We probably don't even have to embed the hash/uuid/location in the file explicitly. We'd just have to specify this as sorting criteria (and use the existing d attribute).

(Edit: This actually wouldn't resolve conflicts. However, we could still do this to separate the conflict and sorting issue)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ignore this; UUID is probably fine and less error prone.

I'll work on visual conflict resolution in compare.py which will tell us which path of svg_new overlaps with svg_old. If there's too much overlap we can throw away the new trace, even if it has a different name or a different path.

@JayFoxRox
Copy link

JayFoxRox commented Jun 12, 2020

Looks like a very good start; in addition to my feedback above (already communicated via Discord):

  • Don't forget to update the documentation to explain this tool.
  • Don't forget to add additional rules which are not checked by the tool (prefer to keep paths separate; do not use transforms; export a simple SVG as possible to reduce warnings by tool, ...).
  • Add a license to this tool. Done.
  • We might have to fix the coordinate system to avoid jitter in numbers.
  • Tool assumes path nodes not be re-ordered by tools (where a path from A to B would be exported as path from B to A); let's hope this assumption holds.

new_image = xml.createElement('image')

# Recreate each allowed attribute in the newly created element
for allowed_attr in image_allowed_attrs:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In addition to warning, we probably want to explicitly error on certain attributes that we recognize as problematic:

  • allowed attribs: will be kept, anything else is at least a warning.
  • disallowed attribs: will be error.

(Could be extended with something where we set allowed defaults, so we'd tolerate some tags if they have a no-op argument; thereby avoiding errors or warnings)

'opacity': '0.5',
'fill': '#00ffff',
'stroke': '#000000',
'stroke-width': '0.99999994px',

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: 1.0? Close-enough?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed ed2bdbe

default_trace_style = {
'fill': 'none',
'stroke': '#ff0000',
'stroke-width': '1.25',

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No unit? default_zone_style uses pixels.

For compatibility with different files I'd prefer if we could use metric units, then we would have a fixed coordinate system and would only have to scale the images to match it.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've changed this to use '1.25px' so it's not left without a unit of measurement. b84721f

I would rather address units of measurements and everything associated with that in a separate issue.


def main(argv):
# Load and parse SVG
input_xml = minidom.parse(argv[0])

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider using argparse, or use sys.argv directly for readability.
I think argv[0] looks like a bug (implies sys.argv[0]), but it's correct because it's actually sys.argv[1] in this case.

Copy link
Owner Author

@LoveMHz LoveMHz Jun 13, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was mostly a place holder until a better method for handling the command arguments was implemented. I see the need for additional arguments in the future and I would rather we go ahead and choose a library to handle that instead. At this time I don't have any recommendations on what would be the best way to do this.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

scripts/simplify.py Outdated Show resolved Hide resolved
scripts/simplify.py Outdated Show resolved Hide resolved
@LoveMHz
Copy link
Owner Author

LoveMHz commented Jun 13, 2020

Did a partial rewrite 5ff7a98 to address a lot of the outstanding comments by @JayFoxRox

The main difference is the rebuild approach. Instead of creating two different XML/SVG objects, it seemed more straightforward to have a single object. The reason is it was becoming too difficult to track, especially since we'll be adding multiple passes. (Verification, validation, and other command-line options)

remove_none_element_nodes(node.childNodes)

def main(argv):
# Load and parse SVG

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bad indentation. Please check if other instances exist, too.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whoops. Stupid editor :P Fixed and checked the rest of the code.

@JayFoxRox
Copy link

JayFoxRox commented Jun 14, 2020

Instead of creating two different XML/SVG objects [...]

Which 2 XML/SVG objects? Are we talking about layers here? The remainder of this post assuming you meant layers / groups.
I'll also comment on my view about layers.

[...] it seemed more straightforward to have a single object.

Also consider this as a response for #7 (comment):

I think splitting at least different views would make sense, even in this PR. It reduces complexity of this PR. The simplify script doesn't have to care about interactions between layers.

The reason is it was becoming too difficult to track, especially since we'll be adding multiple passes. (Verification, validation, and other command-line options)

We'll need a converter to get a netlist anyway, or to connect different elements. Such tool could just load SVGs in a loop and put each found element into an output SVG / netlist / ..

If we have a single file, we need the # Format groups step, as well as a similar step in any tool loading the SVG (such as verification, validation, ..). So banning groups / layers from our simplified format would be helpful.

Keeping the layer stuff out of the simplification script will reduce complexity:

  • for users working with the SVG (harder to add data to the wrong layer).
  • for developers because scripts don't have to support layers at all (easier to write more scripts).

Edit: Because you can't differentiate zones and paths without the group (yet; see #7 (comment)), you'd have to add a CLI flag so the tool knows what it's processing.

@LoveMHz LoveMHz changed the title Implement of simplify script Implementation of simplify script Jun 20, 2020
@LoveMHz
Copy link
Owner Author

LoveMHz commented Jun 20, 2020

I'm pushing this PR forwards. even though I strongly agree with @JayFoxRox on many of his concerns that are still outstanding.

I feat that if we don't push forwards with the project that it will become stall.

@LoveMHz LoveMHz merged commit 8ed6606 into master Jun 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants