Hi,
I want to share my situation.
I have made some changes to the original SVG Importer in order to adapt it in two ways:
1.- Respect the entities of original file. In order to join spline (bezier) entities, if the import process approximate splines as lines or arcs, the it makes impossible to prepare them to be joint. When joint it could be treated as one entity (and add custom properties) and in the case when they conform a closed path, prepare the resulting one to get the area in other software at the moment (I use Draftsight now and Python for automation in the near future) or to be converted to polyline for this calculation. It could be added in Preference Panel as check box "Approximate Splines" and have the best of both worlds.
2.- Fix some problems importing when importing some closed paths. I think this is a bug, please verify. I have tested the modified code and it works better.
Now I have to change the files in every update.
Thank you,
Javier
-------------------
CHANGES
-------------------
File: SvgImporter.js
/**
* Imports a cubic spline with the given start point, control points and ent point.
* DEACTIVATED -> If the spline is almost exactly resembling an arc, an arc is imported instead.
*/
SvgImporter.prototype.importBezier = function(x1, y1, px1, py1, px2, py2, x2, y2) {
var spline = new RSpline();
spline.setDegree(3);
spline.appendControlPoint(new RVector(x1, y1));
spline.appendControlPoint(new RVector(px1, py1));
spline.appendControlPoint(new RVector(px2, py2));
spline.appendControlPoint(new RVector(x2, y2));
// var shape = ShapeAlgorithms.splineToLineOrArc(spline, 0.1);
// this.importShape(shape);
this.importShape(spline);
};
// ADDED condition for z close path
case 'Z':
x = x0;
y = y0;
// ADDED -> Do not import if start coords are equal to end coords
if (ox==x && oy==y){
} else {
this.importLine(ox,oy, x,y);
}
ox = x;
oy = y;
break;
case 'z':
x = x0;
y = y0;
// ADDED -> Do not import if start coords are equal to end coords
if (ox==x && oy==y){
} else {
this.importLine(ox,oy, x,y);
}
ox = x;
oy = y;
break;
-------------
OPTIONAL: assign a shortcut to SVG Importer
File: SvgImportInit.js
function init(basePath) {
var action = new RGuiAction(qsTranslate("SvgImport", "SVG &Import..."), RMainWindowQt.getMainWindow());
action.setRequiresDocument(true);
action.setScriptFile(basePath + "/SvgImport.js");
action.setIcon(basePath + "/SvgImport.svg");
action.setDefaultShortcut(new QKeySequence("f,v"));
action.setDefaultCommands( [ "svgimport", "fv" ]);
action.setGroupSortOrder(1300);
action.setSortOrder(300);
action.setWidgetNames(["FileMenu", "!FileToolBar", "FileToolsPanel", "FileMatrixPanel"]);
}
SVG Importer
Moderator: andrew
Re: SVG Importer
Thanks for your contribution.
I've added a user preference for the automatic spline to arc / line conversion:
https://github.com/qcad/qcad/commit/cd5 ... 939558d7f5
The check for the last segment of closed paths seems feasible and has been implemented.
Custom shortcuts can be assigned using Edit > Application Preferences > General > Tool Settings.
I've added a user preference for the automatic spline to arc / line conversion:
https://github.com/qcad/qcad/commit/cd5 ... 939558d7f5
The check for the last segment of closed paths seems feasible and has been implemented.
Custom shortcuts can be assigned using Edit > Application Preferences > General > Tool Settings.
Re: SVG Importer
Thank you,
I'm documenting other strange behaviors I will post with screen captures. (Very zoomed start point or end point of some arcs draws with an spike, and scale problem in spine to line or arcs function.)
The recently feature of polyline area as attribute was very important for my workflow. I know your team are working in spline features (area is a must!).
It's a pleasure to contribute to QCad. The possibility of know how the majority of the tools are programmed is more important than to have access to the source code of very complex software where the real options to adapt or make new functionality is very limited to normal users.
Well I don't want to be off topic, I will made a post for every subject.
Regards,
Javier
I'm documenting other strange behaviors I will post with screen captures. (Very zoomed start point or end point of some arcs draws with an spike, and scale problem in spine to line or arcs function.)
The recently feature of polyline area as attribute was very important for my workflow. I know your team are working in spline features (area is a must!).
It's a pleasure to contribute to QCad. The possibility of know how the majority of the tools are programmed is more important than to have access to the source code of very complex software where the real options to adapt or make new functionality is very limited to normal users.
Well I don't want to be off topic, I will made a post for every subject.
Regards,
Javier