Skip to content

Commit de58a64

Browse files
authored
feat: add TEXTSTYLE/OSMODE system vars and standardize default text style (#32)
1 parent dbddd0d commit de58a64

File tree

13 files changed

+105
-20
lines changed

13 files changed

+105
-20
lines changed

.github/workflows/ci.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,16 @@ jobs:
5454
run: pnpm doc
5555

5656
- name: Setup Pages
57+
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
5758
uses: actions/configure-pages@v5
5859

5960
- name: Upload artifact
61+
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
6062
uses: actions/upload-pages-artifact@v3
6163
with:
6264
path: './docs/'
6365

6466
- name: Deploy to GitHub Pages
6567
id: deployment
68+
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
6669
uses: actions/deploy-pages@v4

packages/data-model/src/converter/AcDbDxfConverter.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import {
3939
AcDbDatabaseConverter
4040
} from '../database/AcDbDatabaseConverter'
4141
import { AcDbAttribute, AcDbBlockReference, AcDbEntity } from '../entity'
42+
import { DEFAULT_TEXT_STYLE } from '../misc'
4243
import { AcDbBatchProcessing } from './AcDbBatchProcessing'
4344
import { AcDbDxfParser } from './AcDbDxfParser'
4445
import { AcDbEntityConverter } from './AcDbEntitiyConverter'
@@ -436,8 +437,10 @@ export class AcDbDxfConverter extends AcDbDatabaseConverter<ParsedDxf> {
436437
if (header['$EXTMAX']) db.extmax = header['$EXTMAX']
437438
if (header['$EXTMIN']) db.extmin = header['$EXTMIN']
438439
if (header['$INSUNITS'] != null) db.insunits = header['$INSUNITS']
440+
db.osmode = header['$OSMODE'] || 0
439441
db.pdmode = header['$PDMODE'] || 0
440442
db.pdsize = header['$PDSIZE'] || 0.0
443+
db.textstyle = header['$TEXTSTYLE'] || DEFAULT_TEXT_STYLE
441444
}
442445

443446
/**
@@ -800,7 +803,7 @@ export class AcDbDxfConverter extends AcDbDatabaseConverter<ParsedDxf> {
800803
dimfit: item.DIMFIT || 0,
801804
dimupt: item.DIMUPT,
802805
dimatfit: item.DIMATFIT,
803-
dimtxsty: item.DIMTXSTY || 'Standard',
806+
dimtxsty: item.DIMTXSTY || DEFAULT_TEXT_STYLE,
804807
dimldrblk: item.DIMLDRBLK || '',
805808
dimblk: item.DIMBLK || '',
806809
dimblk1: item.DIMBLK1 || '',

packages/data-model/src/database/AcDbDatabase.ts

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,12 @@ import {
99
AcDbFileType
1010
} from './AcDbDatabaseConverterManager'
1111
import { AcDbEntity } from '../entity'
12-
import { AcDbAngleUnits, AcDbDataGenerator, AcDbUnitsValue } from '../misc'
12+
import {
13+
AcDbAngleUnits,
14+
AcDbDataGenerator,
15+
AcDbUnitsValue,
16+
DEFAULT_TEXT_STYLE
17+
} from '../misc'
1318
import {
1419
AcDbDictionary,
1520
AcDbLayoutDictionary,
@@ -276,6 +281,8 @@ export class AcDbDatabase extends AcDbObject {
276281
private _celweight: AcGiLineWeight
277282
/** Current layer for the database */
278283
private _clayer: string
284+
/** Current text style name for the database */
285+
private _textstyle: string
279286
/** The extents of current Model Space */
280287
private _extents: AcGeBox3d
281288
/** Insertion units for the database */
@@ -288,6 +295,8 @@ export class AcDbDatabase extends AcDbObject {
288295
private _pdmode: number
289296
/** Point display size */
290297
private _pdsize: number
298+
/** Running object snap mode bitmask */
299+
private _osmode: number
291300
/** Tables in the database */
292301
private _tables: AcDbTables
293302
/** Nongraphical objects in the database */
@@ -342,13 +351,15 @@ export class AcDbDatabase extends AcDbObject {
342351
this._cecolor = new AcCmColor()
343352
this._celweight = AcGiLineWeight.ByLayer
344353
this._clayer = '0'
354+
this._textstyle = DEFAULT_TEXT_STYLE
345355
this._extents = new AcGeBox3d()
346356
// TODO: Default value is 1 (imperial) or 4 (metric)
347357
this._insunits = AcDbUnitsValue.Millimeters
348358
this._ltscale = 1
349359
this._lwdisplay = true
350360
this._pdmode = 0
351361
this._pdsize = 0
362+
this._osmode = 0
352363
this._tables = {
353364
appIdTable: new AcDbRegAppTable(this),
354365
blockTable: new AcDbBlockTable(this),
@@ -642,7 +653,7 @@ export class AcDbDatabase extends AcDbObject {
642653
this._cecolor,
643654
value || 0,
644655
nextValue => {
645-
this._cecolor = nextValue
656+
this._cecolor = nextValue.clone()
646657
}
647658
)
648659
}
@@ -700,6 +711,23 @@ export class AcDbDatabase extends AcDbObject {
700711
)
701712
}
702713

714+
/**
715+
* The text style name for new text objects.
716+
*/
717+
get textstyle(): string {
718+
return this._textstyle
719+
}
720+
set textstyle(value: string) {
721+
this.updateSysVar(
722+
AcDbSystemVariables.TEXTSTYLE,
723+
this._textstyle,
724+
value ?? DEFAULT_TEXT_STYLE,
725+
nextValue => {
726+
this._textstyle = nextValue
727+
}
728+
)
729+
}
730+
703731
/**
704732
* The zero (0) base angle with respect to the current UCS in radians.
705733
*/
@@ -820,6 +848,23 @@ export class AcDbDatabase extends AcDbObject {
820848
)
821849
}
822850

851+
/**
852+
* Running Object Snap (OSNAP) mode bitmask.
853+
*/
854+
get osmode(): number {
855+
return this._osmode
856+
}
857+
set osmode(value: number) {
858+
this.updateSysVar(
859+
AcDbSystemVariables.OSMODE,
860+
this._osmode,
861+
value ?? 0,
862+
nextValue => {
863+
this._osmode = nextValue
864+
}
865+
)
866+
}
867+
823868
/**
824869
* Reads drawing data from a string or ArrayBuffer.
825870
*

packages/data-model/src/database/AcDbDimStyleTableRecord.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { defaults } from '@mlightcad/common'
22

3+
import { DEFAULT_TEXT_STYLE } from '../misc'
34
import {
45
AcDbSymbolTableRecord,
56
AcDbSymbolTableRecordAttrs
@@ -309,7 +310,7 @@ export class AcDbDimStyleTableRecord extends AcDbSymbolTableRecord<AcDbDimStyleT
309310
dimfit: 0,
310311
dimupt: 0,
311312
dimatfit: 3,
312-
dimtxsty: 'Standard',
313+
dimtxsty: DEFAULT_TEXT_STYLE,
313314
dimldrblk: '',
314315
dimblk: '',
315316
dimblk1: '',

packages/data-model/src/database/AcDbSysVarManager.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { AcCmColor, AcCmColorMethod, AcCmEventManager } from '@mlightcad/common'
22
import { AcGePointLike } from '@mlightcad/geometry-engine'
33
import { AcGiLineWeight } from '@mlightcad/graphic-interface'
44

5+
import { DEFAULT_TEXT_STYLE } from '../misc'
56
import type { AcDbDatabase } from './AcDbDatabase'
67
import { AcDbSystemVariables } from './AcDbSystemVariables'
78

@@ -116,6 +117,12 @@ export class AcDbSysVarManager {
116117
isDbVar: true,
117118
defaultValue: '0'
118119
})
120+
this.registerVar({
121+
name: AcDbSystemVariables.TEXTSTYLE,
122+
type: 'string',
123+
isDbVar: true,
124+
defaultValue: DEFAULT_TEXT_STYLE
125+
})
119126
/**
120127
* Color theme of UI elements
121128
* - 0: Dark theme
@@ -133,6 +140,16 @@ export class AcDbSysVarManager {
133140
isDbVar: true,
134141
defaultValue: false
135142
})
143+
/**
144+
* Running Object Snap (OSNAP) modes stored as a bitcode value.
145+
* Each snap type corresponds to a bit, and the values are added together.
146+
*/
147+
this.registerVar({
148+
name: AcDbSystemVariables.OSMODE,
149+
type: 'number',
150+
isDbVar: true,
151+
defaultValue: 0
152+
})
136153
/**
137154
* Represents the half-size of the pickbox in pixels
138155
*/

packages/data-model/src/database/AcDbSystemVariables.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ export const AcDbSystemVariables = {
3131
CELWEIGHT: 'CELWEIGHT',
3232
/** Current layer name used when creating new entities. */
3333
CLAYER: 'CLAYER',
34+
/** Current text style name used when creating new text entities. */
35+
TEXTSTYLE: 'TEXTSTYLE',
3436
/** UI color theme selector used by the application shell or viewer integration. */
3537
COLORTHEME: 'COLORTHEME',
3638
/** Upper-right corner of the model-space drawing extents. */
@@ -43,6 +45,8 @@ export const AcDbSystemVariables = {
4345
LTSCALE: 'LTSCALE',
4446
/** Flag indicating whether lineweights are displayed in the editor/viewer. */
4547
LWDISPLAY: 'LWDISPLAY',
48+
/** Running object snap mode bitmask (OSNAP settings). */
49+
OSMODE: 'OSMODE',
4650
/** Point display style bitmask that controls how POINT entities are drawn. */
4751
PDMODE: 'PDMODE',
4852
/** Point display size, expressed as an absolute value or viewport percentage. */

packages/data-model/src/entity/AcDbMText.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212
AcGiMTextFlowDirection
1313
} from '@mlightcad/graphic-interface'
1414

15-
import { AcDbOsnapMode } from '../misc'
15+
import { AcDbOsnapMode, DEFAULT_TEXT_STYLE } from '../misc'
1616
import { AcDbEntity } from './AcDbEntity'
1717
import { AcDbEntityProperties } from './AcDbEntityProperties'
1818

@@ -573,8 +573,8 @@ export class AcDbMText extends AcDbEntity {
573573
const textStyleTable = this.database.tables.textStyleTable
574574
let style = textStyleTable.getAt(this.styleName)
575575
if (!style) {
576-
style = (textStyleTable.getAt('STANDARD') ||
577-
textStyleTable.getAt('Standard'))!
576+
style = (textStyleTable.getAt(DEFAULT_TEXT_STYLE) ||
577+
textStyleTable.getAt(DEFAULT_TEXT_STYLE))!
578578
}
579579
return style.textStyle
580580
}

packages/data-model/src/entity/AcDbTable.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
} from '@mlightcad/graphic-interface'
1414

1515
import { AcDbTextStyleTableRecord } from '../database'
16+
import { DEFAULT_TEXT_STYLE } from '../misc'
1617
import { AcDbBlockReference } from './AcDbBlockReference'
1718
import { AcDbEntityProperties } from './AcDbEntityProperties'
1819

@@ -563,8 +564,8 @@ export class AcDbTable extends AcDbBlockReference {
563564
style = textStyleTable.getAt(cell.textStyle)
564565
}
565566
if (!style) {
566-
style = (textStyleTable.getAt('STANDARD') ||
567-
textStyleTable.getAt('Standard'))!
567+
style = (textStyleTable.getAt(DEFAULT_TEXT_STYLE) ||
568+
textStyleTable.getAt(DEFAULT_TEXT_STYLE))!
568569
}
569570
return style.textStyle
570571
}

packages/data-model/src/entity/AcDbText.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212
AcGiTextStyle
1313
} from '@mlightcad/graphic-interface'
1414

15-
import { AcDbOsnapMode } from '../misc'
15+
import { AcDbOsnapMode, DEFAULT_TEXT_STYLE } from '../misc'
1616
import { AcDbEntity } from './AcDbEntity'
1717
import { AcDbEntityProperties } from './AcDbEntityProperties'
1818

@@ -392,7 +392,7 @@ export class AcDbText extends AcDbEntity {
392392
*
393393
* @example
394394
* ```typescript
395-
* text.styleName = "Standard";
395+
* text.styleName = DEFAULT_TEXT_STYLE;
396396
* ```
397397
*/
398398
set styleName(value: string) {
@@ -616,8 +616,8 @@ export class AcDbText extends AcDbEntity {
616616
const textStyleTable = this.database.tables.textStyleTable
617617
let style = textStyleTable.getAt(this.styleName)
618618
if (!style) {
619-
style = (textStyleTable.getAt('STANDARD') ||
620-
textStyleTable.getAt('Standard'))!
619+
style = (textStyleTable.getAt(DEFAULT_TEXT_STYLE) ||
620+
textStyleTable.getAt(DEFAULT_TEXT_STYLE))!
621621
}
622622
return style.textStyle
623623
}

packages/data-model/src/misc/AcDbConstants.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@
66
*/
77
export const DEFAULT_LINE_TYPE = 'Continuous'
88

9+
/**
10+
* Default text style name used when no specific text style is specified.
11+
*
12+
* This constant represents the standard text style used in AutoCAD drawings.
13+
*/
14+
export const DEFAULT_TEXT_STYLE = 'Standard'
15+
916
/**
1017
* Special line type value that indicates the entity should use
1118
* the line type of its layer.

0 commit comments

Comments
 (0)