diff --git a/src/Add-on/Stretch.ts b/src/Add-on/Stretch.ts index 2e255e853..d44b8aaa5 100644 --- a/src/Add-on/Stretch.ts +++ b/src/Add-on/Stretch.ts @@ -2,6 +2,7 @@ import { Callback } from 'awesome-typescript-loader/dist/paths-plugin'; import * as THREE from 'three'; import { app } from '../ApplicationServices/Application'; +import { CADFile } from '../DatabaseServices/CADFile'; import { Entity } from '../DatabaseServices/Entity'; import { Command } from '../Editor/CommandMachine'; import { PromptStatus } from '../Editor/PromptResult'; @@ -12,6 +13,8 @@ import { MoveMatrix } from '../Geometry/GeUtils'; export class Stretch implements Command { + + m_CacheEntity: Map = new Map(); async exec(ss: SelectSet) { if (ss.SelectObjectList.length == 0) @@ -39,7 +42,6 @@ export class Stretch implements Command { let v = p.clone().sub(lastP); this.s(data, v); - lastP.copy(p); } }); @@ -47,7 +49,7 @@ export class Stretch implements Command app.m_Editor.m_SelectCtrl.Cancel(); if (p1.Status != PromptStatus.OK) return; - let vec = p2.Value.sub(p1.Value); + this.m_CacheEntity.clear(); } parse(ss: SelectSet): { str: Map>, move: Array } @@ -78,9 +80,14 @@ export class Stretch implements Command { let indexArr = []; stretchPtsIndexMap.set(obj, indexArr); + let en = obj.userData; if (en && en instanceof Entity) { + let f = new CADFile(); + en.WriteFile(f); + this.m_CacheEntity.set(en, f); + let pts = en.GetStretchPoints(); for (let i = pts.length; i--;) { @@ -112,6 +119,9 @@ export class Stretch implements Command { if (obj.userData instanceof Entity) { + let f = this.m_CacheEntity.get(obj.userData); + f.Reset(); + obj.userData.ReadFile(f); obj.userData.MoveStretchPoints(arr, vec); } } diff --git a/src/DatabaseServices/Arc.ts b/src/DatabaseServices/Arc.ts index 1a292ae10..2e8dd9818 100644 --- a/src/DatabaseServices/Arc.ts +++ b/src/DatabaseServices/Arc.ts @@ -430,6 +430,7 @@ export class Arc extends Curve this.m_StartAngle = this.m_EndAngle; this.m_EndAngle = startAngle; } + return this; } /** diff --git a/src/DatabaseServices/Polyline.ts b/src/DatabaseServices/Polyline.ts index 0cd16f6a0..55b7ad329 100644 --- a/src/DatabaseServices/Polyline.ts +++ b/src/DatabaseServices/Polyline.ts @@ -1238,60 +1238,94 @@ export class Polyline extends Curve } GetSnapPoints(): Array { - return this.GetStretchPoints() + let plList: Vector3[] = []; + for (let i = 0; i < this.EndParam; i += 0.5) + { + let p = this.GetPointAtParam(i); + plList.push(p); + } + return plList; } - GetStretchPoints(): Array + MoveSnapPoints(index: number, moveVec: Vector3) { - let ptList = []; - for (let i = 0; i < this.m_LineData.length; i++) + if (index % 2 === 0) + this.MoveStretchPoints([index], moveVec); + else { - let endV = this.m_LineData[i]; - if (i > 0) + let d = this.m_LineData[index - 1]; + if (d.bul == 0) { - let startV = this.m_LineData[i - 1]; - ptList.push(getPtAtCurveParam(startV.pt, endV.pt, startV.bul, 0.5)); + + } + else + { + // 以下代码保证了中心点不变 + // let arcStartPoint = this.GetPointAtParam(index).add(vec); + // let arcMidP = this.GetPointAtParam(index + 0.5); + // let arcEndPoint = this.GetPointAtParam(nextIndex); + + // let arc = new Arc().FromThreePoint(arcStartPoint, arcMidP, arcEndPoint); + // this.m_LineData[index].bul = Math.tan(arc.AllAngle * 0.25) * (equal(arc.StartPoint, arcStartPoint) ? -1 : 1); } - ptList.push(Vec2DTo3D(endV.pt)); } - return ptList; + } + GetStretchPoints(): Array + { + let plList: Vector3[] = []; + for (let i = 0; i < this.m_LineData.length; i++) + { + let p = this.GetPointAtParam(i); + plList.push(p); + } + return plList; } MoveStretchPoints(indexList: Array, vec: Vector3) { let moveVc = new Vector2(vec.x, vec.y); - let ptlist = this.GetStretchPoints(); - if (indexList[0] % 2 === 0) + let ptCout = this.m_LineData.length; + + for (let index of indexList) { - let i = indexList[0] / 2; - if (i === 0) + let frontIndex = index - 1; + let nextIndex = index + 1; + if (this.m_ClosedMark) { - if (this.IsClose) - { - this.m_LineData[this.EndParam].pt.add(moveVc); - } + frontIndex = FixIndex(frontIndex, ptCout); + nextIndex = FixIndex(nextIndex, ptCout); } - //TODO:保持圆弧中点不变 - this.m_LineData[i].pt.add(moveVc); - } - else - { - let startV = this.m_LineData[(indexList[0] - 1) / 2]; - let endV = this.m_LineData[(indexList[0] + 1) / 2]; - let midPt = ptlist[indexList[0]].add(vec); - if (startV.bul !== 0) + const ChangeBul = (notChangeIndex: number, changeBulIndex: number) => { - // 起始点 - let startPt = Vec2DTo3D(startV.pt); - // 终止点 - let endPt = Vec2DTo3D(endV.pt); - startV.bul = Math.tan(getArcAngleBy3Pt(startPt, midPt, endPt) / 4); - } - else - { - startV.pt = startV.pt.add(moveVc); - endV.pt = endV.pt.add(moveVc); + //需要修改的点的数据 + let d = this.m_LineData[changeBulIndex]; + if (d.bul == 0) return; + + //该索引点下一个点或者上一个点,如果不在列表中,就需要更新凸度. + if (notChangeIndex === -1 || notChangeIndex === ptCout || indexList.indexOf(notChangeIndex) === -1) + { + let needChangeP = this.GetPointAtParam(index); + let notChangeP = this.GetPointAtParam(notChangeIndex); + + //原先的弦长的一半 + let OldChordLengthHalf = needChangeP.distanceTo(notChangeP) * 0.5; + + //弓高 + let arcH = OldChordLengthHalf * d.bul; + + needChangeP.add(vec); + + let newChordLengthHalf = (needChangeP.distanceTo(notChangeP) * 0.5); + + d.bul = arcH / newChordLengthHalf; + } } + + ChangeBul(frontIndex, frontIndex); + ChangeBul(nextIndex, index); + + //修改顶点 + this.m_LineData[index].pt.add(Vec3DTo2D(vec)); } this.Update(); } diff --git a/src/GraphicsSystem/GripScene.ts b/src/GraphicsSystem/GripScene.ts index c0bcd0120..7af30f088 100644 --- a/src/GraphicsSystem/GripScene.ts +++ b/src/GraphicsSystem/GripScene.ts @@ -28,7 +28,7 @@ export class GripScene extends THREE.Object3D } if (obj.userData instanceof Entity) { - let pts = obj.userData.GetStretchPoints(); + let pts = obj.userData.GetSnapPoints(); let geom = new THREE.Geometry(); geom.setFromPoints(pts); @@ -83,4 +83,4 @@ export class GripScene extends THREE.Object3D } } } -} \ No newline at end of file +}