mirror of
https://github.com/xibyte/jsketcher
synced 2026-02-14 03:16:22 +01:00
keep all model id generators at same place
This commit is contained in:
parent
10f9a1fd86
commit
de3faed0a2
4 changed files with 16 additions and 10 deletions
|
|
@ -4,6 +4,7 @@ import {MShell} from '../model/mshell';
|
|||
import {MDatum} from '../model/mdatum';
|
||||
import materializeParams from './materializeParams';
|
||||
import CadError from '../../utils/errors';
|
||||
import {MObjectIdGenerator} from '../model/mobject';
|
||||
|
||||
export function activate({streams, services}) {
|
||||
|
||||
|
|
@ -87,8 +88,7 @@ export function activate({streams, services}) {
|
|||
if (isAdditiveChange(prev, curr)) {
|
||||
beginIndex = prev.pointer + 1;
|
||||
} else {
|
||||
MShell.ID_COUNTER = 0;
|
||||
MDatum.ID_COUNTER = 0;
|
||||
MObjectIdGenerator.reset();
|
||||
beginIndex = 0;
|
||||
streams.craft.models.next([]);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,12 +1,11 @@
|
|||
import {MObject} from './mobject';
|
||||
import {MObject, MObjectIdGenerator} from './mobject';
|
||||
|
||||
export class MDatum extends MObject {
|
||||
|
||||
static TYPE = 'datum';
|
||||
static ID_COUNTER = 0; // TODO: reset the counter
|
||||
|
||||
constructor(csys) {
|
||||
super(MDatum.TYPE, 'D:' + (MDatum.ID_COUNTER++));
|
||||
super(MDatum.TYPE, 'D:' + MObjectIdGenerator.next(MDatum.TYPE));
|
||||
this.csys = csys;
|
||||
this.xAxis = new MDatumAxis(this.id + '/X', this.csys.origin, this.csys.x);
|
||||
this.yAxis = new MDatumAxis(this.id + '/Y', this.csys.origin, this.csys.y);
|
||||
|
|
|
|||
|
|
@ -10,6 +10,15 @@ export class MObject {
|
|||
this.TYPE = TYPE;
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
const ID_REGISTRY = new Map();
|
||||
|
||||
export const MObjectIdGenerator = {
|
||||
next: entityType => {
|
||||
const id = ID_REGISTRY.get(entityType) || 0;
|
||||
ID_REGISTRY.set(entityType, id + 1);
|
||||
return id;
|
||||
},
|
||||
reset: () => ID_REGISTRY.clear()
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import {MObject} from './mobject';
|
||||
import {MObject, MObjectIdGenerator} from './mobject';
|
||||
import {MBrepFace, MFace} from './mface';
|
||||
import {MEdge} from './medge';
|
||||
import {MVertex} from './mvertex';
|
||||
|
|
@ -8,10 +8,8 @@ export class MShell extends MObject {
|
|||
|
||||
static TYPE = 'shell';
|
||||
|
||||
static ID_COUNTER = 0;
|
||||
|
||||
constructor() {
|
||||
super(MShell.TYPE, 'S:' + (MShell.ID_COUNTER++))
|
||||
super(MShell.TYPE, 'S:' + MObjectIdGenerator.next(MShell.TYPE))
|
||||
}
|
||||
|
||||
shell;
|
||||
|
|
|
|||
Loading…
Reference in a new issue