UNPKG

awv3

Version:
1 lines 7.92 kB
"use strict";function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}exports.__esModule=!0;var _regenerator=require("babel-runtime/regenerator"),_regenerator2=_interopRequireDefault(_regenerator),_asyncToGenerator2=require("babel-runtime/helpers/asyncToGenerator"),_asyncToGenerator3=_interopRequireDefault(_asyncToGenerator2),_classCallCheck2=require("babel-runtime/helpers/classCallCheck"),_classCallCheck3=_interopRequireDefault(_classCallCheck2),_sketch=require("../sketcher/sketch"),_sketch2=_interopRequireDefault(_sketch),_constraint=require("../sketcher/constraint"),_constraint2=_interopRequireDefault(_constraint),_geomobjects=require("../sketcher/geomobjects"),_geomutils=require("../sketcher/geomutils"),_statements=require("../sketcher/statements"),_statements2=_interopRequireDefault(_statements),_three=require("three"),_three2=_interopRequireDefault(_three),FilletProcessor=function(){function e(t,n){(0,_classCallCheck3.default)(this,e),this.sketcher=t,this.sketch=n,this.linearTolerance=.001,this.angularTolerance=.001}return e.prototype.FindPointsAt=function(e,t){var n=function(e,n){return t?e.distanceTo(n)<=t:e.equals(n)},r=this.sketch.getObjectsOnSketch(),s=[];return _sketch2.default.ForObjectsWithChildren(r,function(t){t instanceof _geomobjects.Point&&n(t.position,e)&&s.push(t)}),s},e.prototype.FindConstraintsSymmetric=function(e,t,n){var r=this.sketch.getObjectsOnSketch(),s=r.filter(function(r){return r instanceof _constraint2.default&&r.typename===e[0]&&(r.args[0]==t&&r.args[1]==n||r.args[0]==n&&r.args[1]==t)});return s},e.prototype.FindIncidenceConstraints=function(e,t){return this.FindConstraintsSymmetric(_constraint2.default.Type.INCIDENCE,e,t)},e.prototype.FindTangencyConstraints=function(e,t){return this.FindConstraintsSymmetric(_constraint2.default.Type.TANGENCY,e,t)},e.prototype.RecognizeFilletableAngle=function(e){var t=this,n=this.FindPointsAt(e,this.linearTolerance);if(n=n.filter(function(e){return t.sketch.isOnSketch(e.parent)}),2!==n.length)return null;var r=this.FindIncidenceConstraints(n[0],n[1]);if(1!==r.length)return null;var s=n.map(function(e){return e.parent});if(!s.every(function(e){return e instanceof _geomobjects.Line}))return null;var i=s[0].getTangent(),a=s[1].getTangent(),o=(new _three2.default.Vector3).crossVectors(i,a).z;return Math.abs(o)<=this.angularTolerance?null:{lines:s,lineEnds:n,incidence:r}},e.prototype.GetMaxFilletDistance=function(e){for(var t=(e.vertex?e.vertex:e.lineEnds[0]).position.clone(),n=0,r=0;r<2;r++){var s=e.lines[r].points[0]===e.lineEnds[r]?1:0,i=e.lines[r].points[s].position.distanceTo(t);n=Math.max(n,i)}return i-this.linearTolerance},e.prototype.GetTouchPoints=function(e,t,n){for(var r=[],s=0;s<2;s++)r[s]=e.lines[s].getTangent().clone(),e.lines[s].points[0]!==e.lineEnds[s]&&r[s].negate();var i=r[0].angleTo(r[1]),a=(e.vertex?e.vertex:e.lineEnds[0]).position.clone(),o=void 0!==n?n:t/Math.tan(i/2);if(o>=this.GetMaxFilletDistance(e))return null;for(var c=[],s=0;s<2;s++)c[s]=r[s].clone().multiplyScalar(o).add(a);return c.push(a),c},e.prototype.CalculateFilletParamsByRadius=function(e,t){var n=this.GetTouchPoints(e,t);if(!n)return null;var r=(0,_geomutils.drawArcBy_S_E_CPh)(n[0],n[1],n[2]);return r.control=n[2],r},e.prototype.CalculateChamferParamsByOffset=function(e,t){var n=this.GetTouchPoints(e,void 0,t);if(!n)return null;var r={start:n[0],end:n[1],control:n[2]};return r},e.prototype.CreateNewFillet=function(){function e(e,n){return t.apply(this,arguments)}var t=(0,_asyncToGenerator3.default)(_regenerator2.default.mark(function e(t,n){var r,s,i,a,o,c,l;return _regenerator2.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:for(r=[],s=[n.start,n.end],i=0;i<2;i++)a=t.lines[i].points[0]===t.lineEnds[i]?0:1,t.lines[i].points[a].move(s[i]),r.push(t.lines[i].prepareUpdateToServer(this.sketch));for(o=(0,_geomutils.createGeomObject)(n),c=new _geomobjects.Point,c.position.copy(n.control),l=[],i=0;i<2;i++)l.push(new _constraint2.default(_constraint2.default.Type.INCIDENCE,[c,t.lines[i]])),l.push(new _constraint2.default(_constraint2.default.Type.INCIDENCE,[t.lineEnds[i],o.points[i]])),o instanceof _geomobjects.Arc&&l.push(new _constraint2.default(_constraint2.default.Type.TANGENCY,[o,t.lines[i]]));return e.next=10,this.sketch.removeFromSketch(t.incidence);case 10:return r.push(this.sketch.updateFromServer()),e.next=13,_statements2.default.all(r).execute(this.sketcher.socket);case 13:return e.next=15,this.sketch.addToSketch([o,c]);case 15:return e.next=17,this.sketch.addToSketch(l);case 17:if(e.t0=this.sketcher.data.incrementalLevel,!e.t0){e.next=21;break}return e.next=21,this.sketch.solveConstraints();case 21:this.sketcher.refresh();case 22:case"end":return e.stop()}},e,this)}));return e}(),e.prototype.RecognizeFilletByArcOrEdge=function(e){for(var t=(this.sketch.getObjectsOnSketch(),{obj:e,lines:[],objEnds:[],lineEnds:[],vertex:null}),n=[],r=0;r<2;r++){var s=e.points[r],i=this.FindPointsAt(s.position,this.linearTolerance);if(i=i.filter(function(t){return t.parent!==e&&t.parent instanceof _geomobjects.Line}),1!==i.length)return null;var a=i[0],o=a.parent,c=o.points[0]!==a;if(1!==this.FindIncidenceConstraints(s,a).length)return null;if(e instanceof _geomobjects.Arc&&1!==this.FindTangencyConstraints(e,o).length)return null;var l=o.getTangent();if(c&&l.negate(),e instanceof _geomobjects.Arc){var u=e.getTangent(s.position);if(0===r&&u.negate(),l.distanceTo(u)>this.angularTolerance)return null}t.lines[r]=o,t.lineEnds[r]=a,t.objEnds[r]=s,n[r]=l}if(e instanceof _geomobjects.Arc)var h=Math.PI-e.getAngle();else var h=n[0].angleTo(n[1]);if(h<=this.angularTolerance||h>=Math.PI-this.angularTolerance)return null;var p=(0,_geomutils.intersectLines)(t.lineEnds[0].position,n[0],t.lineEnds[1].position,n[1],this.angularTolerance);if(!p)return null;var f=this.FindPointsAt(p,this.linearTolerance);if(1!==f.length)return null;t.vertex=f[0];for(var r=0;r<2;r++)if(1!==this.FindIncidenceConstraints(t.vertex,t.lines[r]).length)return null;return t},e.prototype.DeleteFillet=function(){function e(e){return t.apply(this,arguments)}var t=(0,_asyncToGenerator3.default)(_regenerator2.default.mark(function e(t){var n,r,s,i,a;return _regenerator2.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:for(n=t.vertex.position.clone(),r=[],s=0;s<2;s++)i=t.lines[s].points[0]===t.lineEnds[s]?0:1,t.lines[s].points[i].move(n),r.push(t.lines[s].prepareUpdateToServer(this.sketch));return a=new _constraint2.default(_constraint2.default.Type.INCIDENCE,[t.lineEnds[0],t.lineEnds[1]]),r.push(this.sketch.updateFromServer()),e.next=7,_statements2.default.all(r).execute(this.sketcher.socket);case 7:return e.next=9,this.sketch.addToSketch(a);case 9:return e.next=11,this.sketch.removeFromSketch([t.obj,t.vertex],{updateSketch:!0});case 11:if(e.t0=this.sketcher.data.incrementalLevel,!e.t0){e.next=15;break}return e.next=15,this.sketch.solveConstraints();case 15:this.sketcher.refresh();case 16:case"end":return e.stop()}},e,this)}));return e}(),e.prototype.ChangeFillet=function(){function e(e,n){return t.apply(this,arguments)}var t=(0,_asyncToGenerator3.default)(_regenerator2.default.mark(function e(t,n){var r,s,i,a;return _regenerator2.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:for(r=[],s=[n.start,n.end],i=0;i<2;i++)a=t.lines[i].points[0]===t.lineEnds[i]?0:1,t.lines[i].points[a].move(s[i]),r.push(t.lines[i].prepareUpdateToServer(this.sketch)),t.obj.points[i].position.copy(s[i]);return t.obj.modify(n.start,n.end,n.center,n.clockwise),r.push(t.obj.prepareUpdateToServer(this.sketch)),r.push(this.sketch.updateFromServer()),e.next=8,_statements2.default.all(r).execute(this.sketcher.socket);case 8:if(e.t0=this.sketcher.data.incrementalLevel,!e.t0){e.next=12;break}return e.next=12,this.sketch.solveConstraints();case 12:this.sketcher.refresh();case 13:case"end":return e.stop()}},e,this)}));return e}(),e}();exports.default=FilletProcessor;