From 780d13f767672c34b1947728c40812d76a651ae9 Mon Sep 17 00:00:00 2001 From: ChenX Date: Tue, 16 Jan 2018 17:00:39 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20=E7=B2=BE=E7=AE=80?= =?UTF-8?q?=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Add-on/DrawLine.ts | 24 ++++++++---------------- src/DatabaseServices/ObjectCollection.ts | 5 +++++ src/DatabaseServices/Spline.ts | 20 +++++++++++--------- 3 files changed, 24 insertions(+), 25 deletions(-) diff --git a/src/Add-on/DrawLine.ts b/src/Add-on/DrawLine.ts index d42bd8289..ad8d911dd 100644 --- a/src/Add-on/DrawLine.ts +++ b/src/Add-on/DrawLine.ts @@ -288,21 +288,21 @@ export class DrawSpline implements Command { app.m_Editor.m_CommandStore.Prompt("请输入一个点:"); let ptRes = await app.m_Editor.GetPoint({ Msg: "请输入第一个点:" }); - if (ptRes.Status != PromptStatus.OK) - { return; - } - let i = 0; let p1 = ptRes.Value; - let pts = []; let ptLast = new Vector2(p1.x, p1.y); - pts.push(ptLast); + let pts = [ptLast]; let spline = new Spline(pts); + app.m_Database.ModelSpace.Append(spline); + app.m_Editor.AddNoSnapEntity(spline.Draw(RenderType.Wireframe)); + while (true) { + ptLast = ptLast.clone(); + pts.push(ptLast); app.m_Editor.m_CommandStore.Prompt("请输入点2:"); ptRes = await app.m_Editor.GetPoint({ Msg: "请输入点2:", @@ -311,20 +311,14 @@ export class DrawSpline implements Command KeyWordList: [{ msg: "放弃", key: "U" }], Callback: (v) => { - let p = new Vector2(v.x, v.y); - let tmpPts = pts.slice(0); - tmpPts.push(p); - spline.Points = tmpPts; + ptLast.set(v.x, v.y); + spline.Points = pts; } }); if (ptRes.Status == PromptStatus.OK) { - ptLast = new Vector2(ptRes.Value.x, ptRes.Value.y); - app.m_Database.ModelSpace.Append(spline); - pts.push(ptLast); p1 = ptRes.Value; - spline.Points = pts; continue; } else @@ -332,8 +326,6 @@ export class DrawSpline implements Command break; } } - - } } export class DrawTest implements Command diff --git a/src/DatabaseServices/ObjectCollection.ts b/src/DatabaseServices/ObjectCollection.ts index 3f73f6e25..a4b9777c5 100644 --- a/src/DatabaseServices/ObjectCollection.ts +++ b/src/DatabaseServices/ObjectCollection.ts @@ -16,6 +16,11 @@ export class ObjectCollection extends CADObject //添加一个对象进入集合,这个集合存在db中,那么将自动分配id. Append(obj: CADObject) { + if (obj.Id) + { + console.warn("同一个对象不能重复加入图纸!"); + return; + } if (this._db && !obj.Id) { obj.InitObjectId(this._db); diff --git a/src/DatabaseServices/Spline.ts b/src/DatabaseServices/Spline.ts index 335e7f14f..1090b8db8 100644 --- a/src/DatabaseServices/Spline.ts +++ b/src/DatabaseServices/Spline.ts @@ -1,16 +1,19 @@ -import { Entity } from "./Entity"; -import { Vector2, Geometry } from "three"; -import * as THREE from "three"; -import { RenderType } from "../GraphicsSystem/Enum"; -import { ColorMaterial } from "../Common/ColorPalette"; +import { Geometry, Vector2 } from 'three'; +import * as THREE from 'three'; +import { ColorMaterial } from '../Common/ColorPalette'; +import { RenderType } from '../GraphicsSystem/Enum'; +import { Factory } from './CADFactory'; +import { Entity } from './Entity'; + +@Factory export class Spline extends Entity { - m_Points: Vector2[]; - constructor(points: Vector2[]) + private m_Points: Vector2[]; + constructor(points?: Vector2[]) { super(); - this.m_Points = points; + this.m_Points = points || []; } get Points() { @@ -25,7 +28,6 @@ export class Spline extends Entity { let obj = super.Draw(renderType); if (obj) return obj; - // let line = new THREE.Line(geo); let curve = new THREE.SplineCurve(this.Points); let points = curve.getPoints(1000); let geometry = new THREE.Geometry().setFromPoints(points);