From 71d171898bd7bf4939db5be6651b844ce10998dd Mon Sep 17 00:00:00 2001 From: "Val Erastov (xibyte)" Date: Thu, 14 May 2020 22:50:06 -0700 Subject: [PATCH] ground objects concept --- tsconfig.json | 1 + .../sketcher/generators/boundaryGenerator.js | 6 +-- .../generators/groundObjectsGenerator.ts | 44 +++++++++++++++++++ web/app/sketcher/io.ts | 6 ++- web/app/sketcher/shapes/sketch-object.ts | 15 +++++-- web/app/sketcher/tools/drag.js | 15 ++++++- web/app/sketcher/viewer2d.ts | 15 +++---- 7 files changed, 82 insertions(+), 20 deletions(-) create mode 100644 web/app/sketcher/generators/groundObjectsGenerator.ts diff --git a/tsconfig.json b/tsconfig.json index 4675429d..95ad091f 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -4,6 +4,7 @@ "sourceMap": true, "jsx": "react", "esModuleInterop": true, + "allowJs": true, "allowSyntheticDefaultImports": true, "target": "ES5", "baseUrl": ".", diff --git a/web/app/sketcher/generators/boundaryGenerator.js b/web/app/sketcher/generators/boundaryGenerator.js index 290e9756..c180715c 100644 --- a/web/app/sketcher/generators/boundaryGenerator.js +++ b/web/app/sketcher/generators/boundaryGenerator.js @@ -1,7 +1,5 @@ import {NoIcon} from "../icons/NoIcon"; -import {NOOP} from "../../../../modules/gems/func"; import {Arc} from "../shapes/arc"; -import {EndPoint} from "../shapes/point"; import {Circle} from "../shapes/circle"; import {NurbsObject} from "../shapes/nurbsObject"; import NurbsCurve from "../../brep/geom/curves/nurbsCurve"; @@ -41,9 +39,7 @@ export const BoundaryGeneratorSchema = { let i, obj; function process(obj) { - obj.visitParams(param => { - param.set = NOOP; - }); + obj.freeze(); out.push(obj); } diff --git a/web/app/sketcher/generators/groundObjectsGenerator.ts b/web/app/sketcher/generators/groundObjectsGenerator.ts new file mode 100644 index 00000000..286b5e7b --- /dev/null +++ b/web/app/sketcher/generators/groundObjectsGenerator.ts @@ -0,0 +1,44 @@ +import {NoIcon} from "../icons/NoIcon"; +import {NOOP} from "../../../../modules/gems/func"; +import {Arc} from "../shapes/arc"; +import {EndPoint} from "../shapes/point"; +import {Circle} from "../shapes/circle"; +import {NurbsObject} from "../shapes/nurbsObject"; +import NurbsCurve from "../../brep/geom/curves/nurbsCurve"; +import {Segment} from "../shapes/segment"; + +export const GroundObjectsGeneratorSchema = { + + id: 'GroundObjects', + title: 'Ground Objects', + description: 'Ground like origin which are always on sketch but not being saved with', + internal: true, + icon: NoIcon, + persistGeneratedObjects: false, + + + params: [ + ], + + sourceObjects: () => { + }, + + removeObject(params, generatedObjects, object, destroy, fullDestroy) { + }, + + initiateState: state => { + }, + + generate: (params, state) => { + const generated = [ + new EndPoint(0, 0, 'ground/ORIGIN') + ]; + generated.forEach(g => g.freeze()); + return generated; + }, + + regenerate: (params, generatedObjects, viewer, state) => { + } + +}; + diff --git a/web/app/sketcher/io.ts b/web/app/sketcher/io.ts index 7d451300..3914517c 100644 --- a/web/app/sketcher/io.ts +++ b/web/app/sketcher/io.ts @@ -42,7 +42,10 @@ export interface SketchFormat_V3 { }[]; constraints: { - typeId: string + typeId: string, + objects: string[], + constants: {[key: string]: string}, + annotations: any }[]; }[]; @@ -193,6 +196,7 @@ export class IO { } } finally { + this.viewer.createGroundObjects(); this.viewer.parametricManager.finishTransaction(); this.viewer.parametricManager.notify(); } diff --git a/web/app/sketcher/shapes/sketch-object.ts b/web/app/sketcher/shapes/sketch-object.ts index 49f6d51e..e9834e92 100644 --- a/web/app/sketcher/shapes/sketch-object.ts +++ b/web/app/sketcher/shapes/sketch-object.ts @@ -3,6 +3,7 @@ import {Shape} from './shape' import {Styles} from "../styles"; import {NoIcon} from "../icons/NoIcon"; import {Layer, Viewer} from "../viewer2d"; +import {NOOP} from "gems/func"; export abstract class SketchObject extends Shape { @@ -19,9 +20,9 @@ export abstract class SketchObject extends Shape { generators: Set = new Set(); _stage: any = null; - constructor(id: string) { + protected constructor(id: string) { super(); - this.ref= Generator.genID(); + this.ref= Generator.genID() + ''; this.id = id || this.ref; } @@ -143,12 +144,12 @@ export abstract class SketchObject extends Shape { const productionKind = this.classify(); if (this.markers.length !== 0) { return this.markers[0]; + } else if (this.isGenerated) { + return Styles.GENERATED; } else if (productionKind === PAST) { return Styles.PAST; } else if (productionKind === FUTURE) { return Styles.FUTURE; - } else if (this.isGenerated) { - return Styles.GENERATED; } else if (this.fullyConstrained) { return Styles.FULLY_CONSTRAINED; } else { @@ -245,6 +246,12 @@ export abstract class SketchObject extends Shape { return NoIcon; } + freeze() { + this.visitParams(param => { + param.set = NOOP; + }); + } + abstract write(): SketchObjectSerializationData; } diff --git a/web/app/sketcher/tools/drag.js b/web/app/sketcher/tools/drag.js index 05f03324..23056004 100644 --- a/web/app/sketcher/tools/drag.js +++ b/web/app/sketcher/tools/drag.js @@ -14,6 +14,11 @@ export class DragTool extends Tool { } mousemove(e) { + if (this.generatedCaptured) { + toast("You cannot drag generated object. To move them, drag the objects they are generated off of ") + this.viewer.toolManager.releaseControl(); + return; + } let x = this._point.x; let y = this._point.y; this.viewer.screenToModel2(e.offsetX, e.offsetY, this._point); @@ -33,8 +38,9 @@ export class DragTool extends Tool { } mousedown(e) { - if (this.obj.isGenerated) { - toast("You cannot drag generated object. To move them, drag the objects they are generated off of ") + this.generatedCaptured = this.obj.isGenerated; + if (this.generatedCaptured) { + return; } this.origin.x = e.offsetX; this.origin.y = e.offsetY; @@ -46,6 +52,11 @@ export class DragTool extends Tool { } mouseup(e) { + if (this.generatedCaptured) { + this.viewer.toolManager.releaseControl(); + return; + } + if (this.obj.constraints.length !== 0) { this.viewer.parametricManager.solve(false); this.viewer.parametricManager.algNumSystem.controlBounds = false; diff --git a/web/app/sketcher/viewer2d.ts b/web/app/sketcher/viewer2d.ts index f26ff439..01c16755 100644 --- a/web/app/sketcher/viewer2d.ts +++ b/web/app/sketcher/viewer2d.ts @@ -17,6 +17,8 @@ import {Shape} from "./shapes/shape"; import {SketchObject} from "./shapes/sketch-object"; import {Styles} from './styles'; import {Dimension} from "./shapes/dim"; +import {GroundObjectsGeneratorSchema} from "./generators/groundObjectsGenerator"; +import {SketchGenerator} from "./generators/sketchGenerator"; export class Viewer { @@ -237,17 +239,14 @@ export class Viewer { // layer.objects.push(new Point(0, 0, 2)); layer.objects.push(this.referencePoint); layer.objects.push(new BasisOrigin(null, this)); - - const origin = new EndPoint(0, 0); - origin.id = 'ORIGIN'; - layer.objects.push(origin); - origin.stage = this.parametricManager.groundStage; - origin.visitParams(param => { - param.set = NOOP; - }); return [layer]; }; + createGroundObjects() { + const groundObjectsGenerator = new SketchGenerator({}, GroundObjectsGeneratorSchema); + this.parametricManager.addGeneratorToStage(groundObjectsGenerator, this.parametricManager.groundStage); + } + refresh() { const viewer = this; window.requestAnimationFrame(function () {