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

feat: add table entity #157

Merged
merged 1 commit into from
Sep 20, 2023
Merged
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
2 changes: 1 addition & 1 deletion __tests__/blocks/block.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Block, BlockRecordEntry, Handle, TagsManager } from "../../src";
import { Block, BlockRecordEntry, Handle, TagsManager } from "@/index";

describe("Block class", () => {
const handle = new Handle();
Expand Down
2 changes: 1 addition & 1 deletion __tests__/blocks/blocks.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Blocks, Handle, Tables, TagsManager } from "../../src";
import { Blocks, Handle, Tables, TagsManager } from "@/index";

describe("Blocks class", () => {
const handle = new Handle();
Expand Down
2 changes: 1 addition & 1 deletion __tests__/blocks/endblk.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { EndBlk, Handle, TagsManager } from "../../src";
import { EndBlk, Handle, TagsManager } from "@/index";

describe("EndBlk class", () => {
it("should create an endblk instance", () => {
Expand Down
2 changes: 1 addition & 1 deletion __tests__/document.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Document, Units } from "../src";
import { Document, Units } from "@/index";

describe("XDocument class", () => {
it("should create dxf document", () => {
Expand Down
2 changes: 1 addition & 1 deletion __tests__/entities/entities.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Blocks, Entities, Handle, Tables, TagsManager } from "../../src";
import { Blocks, Entities, Handle, Tables, TagsManager } from "@/index";

describe("XEntities class", () => {
const handle = new Handle();
Expand Down
2 changes: 1 addition & 1 deletion __tests__/entities/line.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Handle, Line, TagsManager, point } from "../../src";
import { Handle, Line, TagsManager, point } from "@/index";

describe("XLine class", () => {
it("should create a line entity", () => {
Expand Down
2 changes: 1 addition & 1 deletion __tests__/entities/manager.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
Handle,
TagsManager,
point,
} from "../../src";
} from "@/index";

describe("EntitiesManager class", () => {
const handle = new Handle();
Expand Down
2 changes: 1 addition & 1 deletion __tests__/entities/xdata.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { TagsManager, XData, point } from "../../src";
import { TagsManager, XData, point } from "@/index";

describe("XData class", () => {
it("should create an empty xdata", () => {
Expand Down
2 changes: 1 addition & 1 deletion __tests__/header/header.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Handle, Header, TagsManager } from "../../src";
import { Handle, Header, TagsManager } from "@/index";

describe("XHeader class", () => {
it("should create a header section with defaults", () => {
Expand Down
2 changes: 1 addition & 1 deletion __tests__/header/variable.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { TagsManager, Variable } from "../../src";
import { TagsManager, Variable } from "@/index";

describe("XVariable class", () => {
it("should create an empty variable", () => {
Expand Down
2 changes: 1 addition & 1 deletion __tests__/objects/object.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Handle, XObject } from "../../src";
import { Handle, XObject } from "@/index";

class DummyObject extends XObject {}

Expand Down
2 changes: 1 addition & 1 deletion __tests__/objects/objects.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Handle, Objects, TagsManager } from "../../src";
import { Handle, Objects, TagsManager } from "@/index";

describe("Objects class", () => {
it("should create an objects section", () => {
Expand Down
2 changes: 1 addition & 1 deletion __tests__/tables/entry.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Entry, Handle } from "../../src";
import { Entry, Handle } from "@/index";

class DummyEntry extends Entry {
constructor() {
Expand Down
2 changes: 1 addition & 1 deletion __tests__/tables/tables.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Handle, Tables, TagsManager } from "../../src";
import { Handle, Tables, TagsManager } from "@/index";

describe("Tables class", () => {
it("should create a tables section", () => {
Expand Down
2 changes: 1 addition & 1 deletion __tests__/utils/application.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AppDefined, TagsManager } from "../../src";
import { AppDefined, TagsManager } from "@/index";

describe("AppDefined class", () => {
it("should create an empty application", () => {
Expand Down
2 changes: 1 addition & 1 deletion __tests__/utils/bbox.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BBox, bbox, point } from "../../src";
import { BBox, bbox, point } from "@/index";

describe("BBox class", () => {
it("should bbox of a line", () => {
Expand Down
2 changes: 1 addition & 1 deletion __tests__/utils/functions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
stringChunksSplit,
tag,
uniformKnots,
} from "../../src";
} from "@/index";

describe("point function", () => {
it("should create a 3d point object", () => {
Expand Down
2 changes: 1 addition & 1 deletion __tests__/utils/tags.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { TagsManager, point, point2d } from "../../src";
import { TagsManager, point, point2d } from "@/index";

describe("TagsManager class", () => {
it("should create an empty mg", () => {
Expand Down
2 changes: 1 addition & 1 deletion __tests__/utils/text.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Colors, StyledText, TextBuilder } from "../../src";
import { Colors, StyledText, TextBuilder } from "@/index";

describe("XStyledText class", () => {
it("should create a styled text", () => {
Expand Down
2 changes: 1 addition & 1 deletion __tests__/writer.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import "../examples";
import { Colors, InvisibleEdge, LWPolylineFlags, Writer, point } from "../src";
import { Colors, InvisibleEdge, LWPolylineFlags, Writer, point } from "@/index";
import { writeFileSync } from "fs";


Expand Down
2 changes: 1 addition & 1 deletion examples/dimension.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Colors, Writer, dline, point } from "../src";
import { Colors, Writer, dline, point } from "@/index";
import { fileURLToPath, save } from "./utils";

const writer = new Writer();
Expand Down
2 changes: 1 addition & 1 deletion examples/hatch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
Writer,
point,
point2d,
} from "../src";
} from "@/index";
import { fileURLToPath, save } from "./utils";

const writer = new Writer();
Expand Down
1 change: 1 addition & 0 deletions examples/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ import "./paper-space";
import "./polyline";
import "./quick-start";
import "./rectangle";
import "./table";
import "./text";
2 changes: 1 addition & 1 deletion examples/leader.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Colors, PathType, Writer, point } from "../src";
import { Colors, PathType, Writer, point } from "@/index";
import { fileURLToPath, save } from "./utils";

const writer = new Writer();
Expand Down
2 changes: 1 addition & 1 deletion examples/lwpolyline.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Colors, LWPolylineFlags, Writer, point } from "../src";
import { Colors, LWPolylineFlags, Writer, point } from "@/index";
import { fileURLToPath, save } from "./utils";

const writer = new Writer();
Expand Down
2 changes: 1 addition & 1 deletion examples/mesh.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Colors, Writer, point } from "../src";
import { Colors, Writer, point } from "@/index";
import { fileURLToPath, save } from "./utils";

const writer = new Writer();
Expand Down
2 changes: 1 addition & 1 deletion examples/mleader.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Colors, TextBuilder, Writer, point } from "../src";
import { Colors, TextBuilder, Writer, point } from "@/index";
import { fileURLToPath, save } from "./utils";

const writer = new Writer();
Expand Down
2 changes: 1 addition & 1 deletion examples/mtext.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Colors, TextBuilder, Writer, point } from "../src";
import { Colors, TextBuilder, Writer, point } from "@/index";
import { fileURLToPath, save } from "./utils";

const writer = new Writer();
Expand Down
2 changes: 1 addition & 1 deletion examples/paper-space.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Colors, TextOptions, Writer, point } from "../src";
import { Colors, TextOptions, Writer, point } from "@/index";
import { fileURLToPath, save } from "./utils";

const writer = new Writer();
Expand Down
2 changes: 1 addition & 1 deletion examples/polyline.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Colors, PolylineFlags, VertexFlags, Writer } from "../src";
import { Colors, PolylineFlags, VertexFlags, Writer } from "@/index";
import { fileURLToPath, save } from "./utils";

const writer = new Writer();
Expand Down
2 changes: 1 addition & 1 deletion examples/quick-start.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Colors, Writer, point } from "../src";
import { Colors, Writer, point } from "@/index";
import { fileURLToPath, save } from "./utils";

const writer = new Writer();
Expand Down
2 changes: 1 addition & 1 deletion examples/rectangle.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Colors, Writer, point } from "../src";
import { Colors, Writer, point } from "@/index";
import { fileURLToPath, save } from "./utils";

const writer = new Writer();
Expand Down
68 changes: 68 additions & 0 deletions examples/table.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import { Colors, TextBuilder, Writer, point } from "@/index";
import { fileURLToPath, save } from "./utils";

const writer = new Writer();
const modelSpace = writer.document.modelSpace;

const green = writer.document.tables.addLayer({
name: "Green",
colorNumber: Colors.Green,
});

const cyan = writer.document.tables.addLayer({
name: "Cyan",
colorNumber: Colors.Cyan,
});

modelSpace.currentLayerName = green.name;

modelSpace.addTable({
cells: [],
columnsCount: 3,
columnsHeight: [],
insertionPoint: point(0, 18),
rowsCount: 2,
rowsHeight: [],
});

const table = modelSpace.addTable({
cells: [],
columnsCount: 10,
columnsHeight: [6],
insertionPoint: point(),
rowsCount: 3,
rowsHeight: [4],
});

const textHeight = 1;

for (let i = 0; i < 30; i++) {
table.add({ text: `${i + 1}`, textHeight });
}

const table2 = modelSpace.addTable({
cells: [],
columnsCount: 10,
columnsHeight: [6],
insertionPoint: point(0, 14),
rowsCount: 3,
rowsHeight: [4],
layerName: cyan.name,
});

for (let i = 0; i < 30; i++) {
if (i > 9) table2.add({ text: `${i + 1}`, textHeight });
else table2.add({});
}

const builder = new TextBuilder();
const txt = builder.add({
value: "Hello World!",
fontFamily: "Arial",
bold: true,
});

table2.cells[0].text = txt.value;
table2.cells[0].textHeight = 2;

save(writer.stringify(), fileURLToPath(import.meta.url));
2 changes: 1 addition & 1 deletion examples/text.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Colors, Writer, point } from "../src";
import { Colors, Writer, point } from "@/index";
import { fileURLToPath, save } from "./utils";

const writer = new Writer();
Expand Down
2 changes: 2 additions & 0 deletions src/entities/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ export * from "./leader";
export * from "./line";
export * from "./lwpolyline";
export * from "./manager";
export * from "./mesh";
export * from "./mleader";
export * from "./mtext";
export * from "./point";
export * from "./polyline";
export * from "./ray";
export * from "./seqend";
export * from "./spline";
export * from "./table";
export * from "./text";
export * from "./vertex";
8 changes: 8 additions & 0 deletions src/entities/manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import { Polyline, PolylineOptions } from "./polyline";
import { Ray, RayOptions } from "./ray";
import { Rectangle, RectangleOptions } from "@/shapes";
import { Spline, SplineOptions } from "./spline";
import { Table, TableOptions } from "./table";
import { Text, TextOptions } from "./text";
import { Taggable } from "@/types";

Expand All @@ -43,6 +44,8 @@ export class EntitiesManager implements Taggable {

currentLayerName: string;

private _tableSeed = 1;

constructor(BlockRecordEntry: BlockRecordEntry, handle: Handle) {
this.blockRecord = BlockRecordEntry;
this.handle = handle;
Expand Down Expand Up @@ -160,6 +163,11 @@ export class EntitiesManager implements Taggable {
return this.add(Spline, options);
}

addTable(options: Omit<TableOptions, "blockName">) {
const blockName = `*T${this._tableSeed++}`;
return this.add(Table, { blockName, ...options });
}

addText(options: TextOptions) {
return this.add(Text, options);
}
Expand Down
Loading