ground objects concept

This commit is contained in:
Val Erastov (xibyte) 2020-05-14 22:50:06 -07:00
parent 0a937e1d09
commit 71d171898b
7 changed files with 82 additions and 20 deletions

View file

@ -4,6 +4,7 @@
"sourceMap": true,
"jsx": "react",
"esModuleInterop": true,
"allowJs": true,
"allowSyntheticDefaultImports": true,
"target": "ES5",
"baseUrl": ".",

View file

@ -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);
}

View file

@ -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) => {
}
};

View file

@ -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();
}

View file

@ -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<any> = 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;
}

View file

@ -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;

View file

@ -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 () {