From d36498048b733a08994d4bb70c6d5bc28c3a7cf8 Mon Sep 17 00:00:00 2001 From: Val Erastov Date: Sun, 11 Dec 2016 22:49:34 -0800 Subject: [PATCH] indexing children non simple object when serializing deserializing --- web/app/sketcher/io.js | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/web/app/sketcher/io.js b/web/app/sketcher/io.js index 6f4ec1ac..b0d46b7c 100644 --- a/web/app/sketcher/io.js +++ b/web/app/sketcher/io.js @@ -12,7 +12,7 @@ import {HDimension, VDimension, Dimension, DiameterDimension} from './shapes/dim import {Constraints} from './parametric' import Vector from '../math/vector' -var Types = { +const Types = { END_POINT : 'TCAD.TWO.EndPoint', SEGMENT : 'TCAD.TWO.Segment', ARC : 'TCAD.TWO.Arc', @@ -161,6 +161,15 @@ IO.prototype._loadSketch = function(sketch) { layer.objects.push(skobj); skobj.layer = layer; index[obj['id']] = skobj; + + //reindex non point children to recover constraints + const childrenIds = obj['children']; + if (childrenIds) { + const children = nonPointChildren(skobj); + for (let childIdx = 0; childIdx < childrenIds.length; childIdx++) { + index[childrenIds[childIdx]] = children[childIdx]; + } + } } if (boundaryProcessing) { if (_class === T.SEGMENT) this.synchLine(skobj, boundary.lines.shift()); @@ -335,7 +344,11 @@ IO.prototype._serializeSketch = function() { to['flip'] = obj.flip; } else if (obj._class === T.DDIM) { to['obj'] = obj.obj.id; - } + } + const children = nonPointChildren(obj).map(c => c.id); + if (children.length != 0) { + to['children'] = children; + } } } } @@ -358,6 +371,17 @@ IO.prototype._serializeSketch = function() { return sketch; }; +function nonPointChildren(obj){ + const children = []; + obj.accept((o) => { + if (o._class !== Types.END_POINT) { + children.push(o); + } + return true; + }); + return children; +} + IO.prototype.parseConstr = function (c, index) { var name = c[0]; var ps = c[1];