mirror of
https://github.com/xibyte/jsketcher
synced 2025-12-16 05:23:19 +01:00
fix reindex sketch bug
This commit is contained in:
parent
4253ae622b
commit
8a5eaf2422
8 changed files with 64 additions and 52 deletions
|
|
@ -1,6 +1,6 @@
|
|||
import {MShell} from '../model/mshell';
|
||||
import {MObject} from "../model/mobject";
|
||||
import {ApplicationContext, CoreContext} from "context";
|
||||
import {ApplicationContext} from "context";
|
||||
import {Stream} from "lstream";
|
||||
import {MFace} from "../model/mface";
|
||||
import {MEdge} from "../model/medge";
|
||||
|
|
@ -19,6 +19,12 @@ export function activate(ctx: ApplicationContext) {
|
|||
return index;
|
||||
}).remember();
|
||||
|
||||
function reindexFace(face: MFace) {
|
||||
face.traverseSketchRelatedEntities(obj => {
|
||||
modelIndex$.value.set(obj.id, obj);
|
||||
})
|
||||
}
|
||||
|
||||
streams.cadRegistry = {
|
||||
shells: shells$, modelIndex: modelIndex$
|
||||
};
|
||||
|
|
@ -69,6 +75,7 @@ export function activate(ctx: ApplicationContext) {
|
|||
|
||||
services.cadRegistry = {
|
||||
getAllShells, findShell, findFace, findEdge, findSketchObject, findEntity, findDatum, findDatumAxis, findLoop, find,
|
||||
reindexFace,
|
||||
get modelIndex() {
|
||||
return streams.cadRegistry.modelIndex.value;
|
||||
},
|
||||
|
|
@ -98,7 +105,7 @@ export interface CadRegistry {
|
|||
modelIndex: Map<String, MObject>;
|
||||
models: MObject[];
|
||||
shells: MObject[];
|
||||
|
||||
reindexFace(face: MFace);
|
||||
}
|
||||
|
||||
declare module 'context' {
|
||||
|
|
|
|||
|
|
@ -21,13 +21,6 @@ export function activate(ctx: CoreContext) {
|
|||
const update$ = stream<void>();
|
||||
const pipelineFailure$ = state<any>(null);
|
||||
|
||||
models$.attach(models => models.forEach(model => model.traverse(m => {
|
||||
if (m instanceof MFace) {
|
||||
let sketch = ctx.sketchStorageService.readSketch(m.defaultSketchId);
|
||||
m.setSketch(sketch);
|
||||
}
|
||||
})));
|
||||
|
||||
let preRun = null;
|
||||
|
||||
function modifyWithPreRun(request, modificationsUpdater, onAccepted, onError) {
|
||||
|
|
|
|||
|
|
@ -64,7 +64,7 @@ export class MFace extends MObject {
|
|||
get isPlaneBased(): boolean {
|
||||
return this.surface.simpleSurface && this.surface.simpleSurface.isPlane;
|
||||
}
|
||||
|
||||
|
||||
evalCSys() {
|
||||
if (!this._csys) {
|
||||
if (this.isPlaneBased) {
|
||||
|
|
@ -72,7 +72,7 @@ export class MFace extends MObject {
|
|||
let [x, y, z] = BasisForPlane(this.surface.simpleSurface.normal, alignCsys.y, alignCsys.z);
|
||||
let proj = z.dot(alignCsys.origin);
|
||||
proj -= this.surface.simpleSurface.w;
|
||||
let origin = alignCsys.origin.minus(z.multiply(proj));
|
||||
let origin = alignCsys.origin.minus(z.multiply(proj));
|
||||
this._csys = new CSys(origin, x, y, z) as CartesianCSys;
|
||||
} else {
|
||||
let origin = this.surface.southWestPoint();
|
||||
|
|
@ -91,24 +91,24 @@ export class MFace extends MObject {
|
|||
this.w = this.csys.w();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
get defaultSketchId() {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
setSketch(sketch) {
|
||||
|
||||
|
||||
if (!this.isPlaneBased) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
this.sketch = sketch;
|
||||
this.sketchObjects = [];
|
||||
|
||||
if (!sketch) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
const addSketchObjects = sketchObjects => {
|
||||
let isConstruction = sketchObjects === sketch.constructionSegments;
|
||||
for (let sketchObject of sketchObjects) {
|
||||
|
|
@ -121,15 +121,15 @@ export class MFace extends MObject {
|
|||
addSketchObjects(sketch.connections);
|
||||
addSketchObjects(sketch.loops);
|
||||
|
||||
|
||||
|
||||
const index = new Map();
|
||||
this.sketchObjects.forEach(o => index.set(o.sketchPrimitive, o));
|
||||
|
||||
|
||||
this.sketchLoops = sketch.fetchContours().map((contour, i) => {
|
||||
let loopSketchObjects = contour.segments.map(s => index.get(s));
|
||||
return new MSketchLoop(this.id + '/L:' + i, this, loopSketchObjects, contour);
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
|
||||
findSketchObjectById(sketchObjectId) {
|
||||
|
|
@ -150,14 +150,14 @@ export class MFace extends MObject {
|
|||
}
|
||||
return this._sketchToWorldTransformation;
|
||||
}
|
||||
|
||||
|
||||
get worldToSketchTransformation(): Matrix3x4 {
|
||||
if (!this._worldToSketchTransformation) {
|
||||
this._worldToSketchTransformation = this.csys.inTransformation;
|
||||
}
|
||||
return this._worldToSketchTransformation;
|
||||
}
|
||||
|
||||
|
||||
get productionInfo() {
|
||||
if (this._productionInfo === undefined) {
|
||||
this._productionInfo = !this.brepFace?.data?.productionInfo ? null :
|
||||
|
|
@ -168,6 +168,10 @@ export class MFace extends MObject {
|
|||
|
||||
traverse(callback: (obj: MObject) => void) {
|
||||
callback(this);
|
||||
this.traverseSketchRelatedEntities(callback);
|
||||
}
|
||||
|
||||
traverseSketchRelatedEntities(callback: (obj: MObject) => void) {
|
||||
this.sketchObjects.forEach(i => i.traverse(callback));
|
||||
this.sketchLoops.forEach(i => i.traverse(callback));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@ import {MShell} from '../model/mshell';
|
|||
import {MDatum} from '../model/mdatum';
|
||||
import DatumView from './views/datumView';
|
||||
import {View} from './views/view';
|
||||
import {SketchingView} from "cad/scene/views/faceView";
|
||||
|
||||
export const ViewSyncPlugin = {
|
||||
|
||||
|
|
@ -38,9 +37,7 @@ export const ViewSyncPlugin = {
|
|||
|
||||
function sceneSynchronizer(ctx) {
|
||||
const {services: {cadScene, cadRegistry, viewer, wizard, action, pickControl}} = ctx;
|
||||
let xxx = 0;
|
||||
return function() {
|
||||
console.log("sceneSynchronizer update" + (xxx++))
|
||||
|
||||
let wgChildren = cadScene.workGroup.children;
|
||||
let existent = new Set();
|
||||
|
|
@ -49,12 +46,12 @@ function sceneSynchronizer(ctx) {
|
|||
let shellView = getAttribute(obj, View.MARKER);
|
||||
if (shellView) {
|
||||
let exists = cadRegistry.modelIndex.has(shellView.model.id);
|
||||
// if (!exists) {
|
||||
if (!exists) {
|
||||
SceneGraph.removeFromGroup(cadScene.workGroup, obj);
|
||||
shellView.dispose();
|
||||
// } else {
|
||||
// existent.add(shellView.model.id);
|
||||
// }
|
||||
} else {
|
||||
existent.add(shellView.model.id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -73,22 +70,6 @@ function sceneSynchronizer(ctx) {
|
|||
} else {
|
||||
console.warn('unsupported model ' + model);
|
||||
}
|
||||
const attrStream = ctx.attributesService.streams.get(model.id);
|
||||
const disposer = attrStream.attach(attrs => {
|
||||
modelView.rootGroup.visible = !attrs.hidden
|
||||
viewer.requestRender();
|
||||
});
|
||||
|
||||
modelView.traverse(view => {
|
||||
if (view instanceof SketchingView) {
|
||||
const stream = ctx.attributesService.streams.get(view.model.id);
|
||||
modelView.addDisposer(stream.attach(attr => {
|
||||
view.setColor(attr.color);
|
||||
viewer.requestRender();
|
||||
}))
|
||||
}
|
||||
});
|
||||
modelView.addDisposer(disposer)
|
||||
SceneGraph.addToGroup(cadScene.workGroup, modelView.rootGroup);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import {setAttribute} from 'scene/objectData';
|
||||
import {brepFaceToGeom, tessDataToGeom} from '../wrappers/brepSceneObject';
|
||||
import {FACE} from '../../model/entities';
|
||||
import {FACE} from 'cad/model/entities';
|
||||
import * as SceneGraph from 'scene/sceneGraph';
|
||||
import {SketchObjectView} from './sketchObjectView';
|
||||
import {View} from './view';
|
||||
|
|
@ -19,6 +19,14 @@ export class SketchingView extends View {
|
|||
this.rootGroup = SceneGraph.createGroup();
|
||||
SceneGraph.addToGroup(this.rootGroup, this.sketchGroup);
|
||||
this.updateSketch();
|
||||
|
||||
const stream = ctx.attributesService.streams.get(this.model.id);
|
||||
this.addDisposer(stream.attach(attr => {
|
||||
if (this.mesh) {
|
||||
this.setColor(attr.color);
|
||||
ctx.viewer.requestRender();
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
updateSketch() {
|
||||
|
|
@ -105,5 +113,5 @@ export function setFacesColor(faces, color) {
|
|||
}
|
||||
}
|
||||
|
||||
export const NULL_COLOR = new THREE.Color();
|
||||
export const NULL_COLOR = new THREE.Color(0xbfbfbf);
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import {setAttribute} from 'scene/objectData';
|
||||
import {FACE, SHELL} from '../../model/entities';
|
||||
import {FACE, SHELL} from 'cad/model/entities';
|
||||
import {SketchingView} from './faceView';
|
||||
import {View} from './view';
|
||||
import {SketchMesh} from './shellView';
|
||||
|
|
|
|||
|
|
@ -29,6 +29,16 @@ export class View {
|
|||
model.ext.view = this;
|
||||
this.marks = [];
|
||||
this.markerTable = createIndex(markerTable, i => i.type);
|
||||
|
||||
if (!parent) {
|
||||
const attrStream = ctx.attributesService.streams.get(model.id);
|
||||
this.addDisposer(attrStream.attach(attrs => {
|
||||
if (this.rootGroup) {
|
||||
this.rootGroup.visible = !attrs.hidden
|
||||
ctx.viewer.requestRender();
|
||||
}
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
setColor(color) {
|
||||
|
|
|
|||
|
|
@ -3,10 +3,10 @@ import {state, stream} from 'lstream';
|
|||
import {InPlaceSketcher} from './inPlaceSketcher';
|
||||
import sketcherUIContrib from './sketcherUIContrib';
|
||||
import initReassignSketchMode from './reassignSketchMode';
|
||||
import {Viewer} from "../../sketcher/viewer2d";
|
||||
import {IO} from "../../sketcher/io";
|
||||
import {Generator} from "../../sketcher/id-generator";
|
||||
import {NOOP} from "gems/func";
|
||||
import {Viewer} from "sketcher/viewer2d";
|
||||
import {IO} from "sketcher/io";
|
||||
import {Generator} from "sketcher/id-generator";
|
||||
import {MFace} from "cad/model/mface";
|
||||
|
||||
export function defineStreams(ctx) {
|
||||
ctx.streams.sketcher = {
|
||||
|
|
@ -111,11 +111,20 @@ export function activate(ctx) {
|
|||
}
|
||||
}
|
||||
|
||||
ctx.craftService.models$.attach(models => models.forEach(model => model.traverse(m => {
|
||||
if (m instanceof MFace) {
|
||||
if (!m.ext.sketchInitialized) {
|
||||
m.ext.sketchInitialized = true;
|
||||
updateSketchForFace(m);
|
||||
}
|
||||
}
|
||||
})));
|
||||
|
||||
function updateSketchForFace(mFace) {
|
||||
let sketch = ctx.sketchStorageService.readSketch(mFace.defaultSketchId);
|
||||
mFace.setSketch(sketch);
|
||||
ctx.craftService.models$.mutate(NOOP);// to reindex all entities
|
||||
streams.sketcher.update.next(mFace);
|
||||
ctx.cadRegistry.reindexFace(mFace);
|
||||
streams.sketcher.update.next(mFace); // updates UI face views
|
||||
}
|
||||
|
||||
function updateAllSketches() {
|
||||
|
|
|
|||
Loading…
Reference in a new issue