Skip to content

Added lineWeight support to dxf exporter #624

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

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 23 additions & 3 deletions packages/maker.js/src/core/dxf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,11 @@ namespace MakerJs.exporter {
return textEntity;
}

function layerOut(layerId: string, layerColor: number) {
function layerOut(layerId: string, layerColor: number, layerLineWeight: number) {
const layerEntity: DxfParser.Layer = {
name: layerId,
color: layerColor
color: layerColor,
lineWeight: layerLineWeight
};
return layerEntity;
}
Expand All @@ -195,7 +196,7 @@ namespace MakerJs.exporter {
layerIds.forEach(layerId => {
var layerOptions = colorLayerOptions(layerId);
if (layerOptions) {
layerTable.layers[layerId] = layerOut(layerId, layerOptions.color);
layerTable.layers[layerId] = layerOut(layerId, layerOptions.color, layerOptions.lineWeight);
}
});
const tableName: DxfParser.TableNames = 'layer';
Expand All @@ -207,6 +208,7 @@ namespace MakerJs.exporter {
var units = dxfUnit[opts.units];
doc.header["$INSUNITS"] = units;
}
doc.header["$LWDISPLAY"] = 1;
}

function entities(walkedPaths: IWalkPath[], chains: IChainOnLayer[], captions: (ICaption & { layer?: string })[]) {
Expand Down Expand Up @@ -285,6 +287,7 @@ namespace MakerJs.exporter {

map["LINE"] = function (line: DxfParser.EntityLINE) {
append("0", "LINE",
"370", "-1", // Set line weight to -1 to use the layer's line weight
"8",
line.layer,
"10",
Expand All @@ -300,6 +303,7 @@ namespace MakerJs.exporter {

map["CIRCLE"] = function (circle: DxfParser.EntityCIRCLE) {
append("0", "CIRCLE",
"370", "-1", // Set line weight to -1 to use the layer's line weight
"8",
circle.layer,
"10",
Expand All @@ -313,6 +317,7 @@ namespace MakerJs.exporter {

map["ARC"] = function (arc: DxfParser.EntityARC) {
append("0", "ARC",
"370", "-1", // Set line weight to -1 to use the layer's line weight
"8",
arc.layer,
"10",
Expand Down Expand Up @@ -348,6 +353,7 @@ namespace MakerJs.exporter {

map["POLYLINE"] = function (polyline: DxfParser.EntityPOLYLINE) {
append("0", "POLYLINE",
"370", "-1", // Set line weight to -1 to use the layer's line weight
Copy link
Contributor

Choose a reason for hiding this comment

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

for these 3 "370"s - can we inject only if a layer lineweight exists?

"8",
polyline.layer,
"66",
Expand Down Expand Up @@ -418,6 +424,9 @@ namespace MakerJs.exporter {
"6",
"CONTINUOUS"
);
if (layer.lineWeight) {
append("370", layer.lineWeight);
}
}

function lineTypeOut(lineType: DxfParser.LineType) {
Expand Down Expand Up @@ -523,6 +532,11 @@ namespace MakerJs.exporter {
* Text size for TEXT entities.
*/
fontSize?: number;

/**
* Line weight to control the thickness of the lines drawn.
*/
lineWeight?: number;
}

/**
Expand Down Expand Up @@ -554,3 +568,9 @@ namespace MakerJs.exporter {
layer: string;
}
}

declare namespace DxfParser {
export interface Layer {
lineWeight?: number;
}
}
10 changes: 5 additions & 5 deletions packages/maker.js/test/dxf.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,18 @@ describe('Export DXF', function() {
.addTo(model, 'square');

const expected = [
'0', 'SECTION', '2', 'HEADER', '9', '$INSUNITS', '70', '1', '0', 'ENDSEC',
'0', 'SECTION', '2', 'HEADER', '9', '$INSUNITS', '70', '1', '9', '$LWDISPLAY', '70', '1', '0', 'ENDSEC',
'0', 'SECTION',
'2', 'TABLES',
'0', 'TABLE', '2', 'LTYPE', '0', 'LTYPE', '72', '65', '70', '64', '2', 'CONTINUOUS', '3', '______', '73', '0', '40', '0', '0', 'ENDTAB',
'0', 'TABLE', '2', 'LAYER', '0', 'ENDTAB',
'0', 'ENDSEC',
'0', 'SECTION',
'2', 'ENTITIES',
'0', 'LINE', '8', 'square', '10', '0', '20', '0', '11', '50', '21', '0',
'0', 'LINE', '8', 'square', '10', '50', '20', '0', '11', '50', '21', '50',
'0', 'LINE', '8', 'square', '10', '50', '20', '50', '11', '0', '21', '50',
'0', 'LINE', '8', 'square', '10', '0', '20', '50', '11', '0', '21', '0',
'0', 'LINE', '370', '-1', '8', 'square', '10', '0', '20', '0', '11', '50', '21', '0',
'0', 'LINE', '370', '-1', '8', 'square', '10', '50', '20', '0', '11', '50', '21', '50',
'0', 'LINE', '370', '-1', '8', 'square', '10', '50', '20', '50', '11', '0', '21', '50',
'0', 'LINE', '370', '-1', '8', 'square', '10', '0', '20', '50', '11', '0', '21', '0',
'0', 'TEXT', '10', '25', '20', '25', '11', '25', '21', '25', '40', '4', '1', 'fold here', '50', '45', '8', 'square', '72', '4', '73', '0',
'0', 'ENDSEC',
'0', 'EOF'
Expand Down