!92 scale命令,offset命令,GetDistance服务更新

Merge pull request !92 from ChenX/scale
pull/92/MERGE
ChenX 6 years ago
parent 2d200a01e8
commit 5ddd1bc9a8

20
package-lock.json generated

@ -218,9 +218,9 @@
"dev": true
},
"@types/node": {
"version": "10.5.3",
"resolved": "http://r.cnpmjs.org/@types/node/download/@types/node-10.5.3.tgz",
"integrity": "sha1-W8+vCIrReJQjIBKHdmljTAayDMU=",
"version": "10.5.5",
"resolved": "http://r.cnpmjs.org/@types/node/download/@types/node-10.5.5.tgz",
"integrity": "sha1-joTSTols13sNT3PfJ0An4xSewro=",
"dev": true
},
"@types/range-parser": {
@ -2864,7 +2864,7 @@
},
"detect-indent": {
"version": "5.0.0",
"resolved": "https://registry.npmjs.org/detect-indent/-/detect-indent-5.0.0.tgz",
"resolved": "http://r.cnpmjs.org/detect-indent/download/detect-indent-5.0.0.tgz",
"integrity": "sha1-OHHMCmoALow+Wzz38zYmRnXwa50=",
"dev": true
},
@ -5166,9 +5166,9 @@
}
},
"hard-source-webpack-plugin": {
"version": "0.11.2",
"resolved": "http://r.cnpmjs.org/hard-source-webpack-plugin/download/hard-source-webpack-plugin-0.11.2.tgz",
"integrity": "sha1-ezHE+RkqMZ37BHQaEFBmmSiQUDo=",
"version": "0.12.0",
"resolved": "http://r.cnpmjs.org/hard-source-webpack-plugin/download/hard-source-webpack-plugin-0.12.0.tgz",
"integrity": "sha1-6iHwQHU4/LYvaZU3FUG6qwpfZ54=",
"dev": true,
"requires": {
"chalk": "^2.4.1",
@ -11155,9 +11155,9 @@
"dev": true
},
"three": {
"version": "0.94.0",
"resolved": "http://r.cnpmjs.org/three/download/three-0.94.0.tgz",
"integrity": "sha1-TObbfyv795wtc0RKpuPPwIoy12I="
"version": "0.95.0",
"resolved": "http://r.cnpmjs.org/three/download/three-0.95.0.tgz",
"integrity": "sha1-tg6gdroX35+rqehVuGqz9UEomr8="
},
"through": {
"version": "2.3.8",

@ -23,7 +23,7 @@
"@types/hard-source-webpack-plugin": "^0.9.0",
"@types/html-webpack-plugin": "^3.2.0",
"@types/jest": "^23.3.0",
"@types/node": "^10.5.3",
"@types/node": "^10.5.5",
"@types/react": "^16.4.7",
"@types/react-dom": "^16.0.6",
"@types/stats.js": "^0.17.0",
@ -39,7 +39,7 @@
"file-loader": "^1.1.11",
"fork-ts-checker-webpack-plugin": "^0.4.3",
"git-revision-webpack-plugin": "^3.0.3",
"hard-source-webpack-plugin": "^0.11.2",
"hard-source-webpack-plugin": "^0.12.0",
"html-loader": "^0.5.5",
"html-webpack-plugin": "^3.2.0",
"jest": "^23.4.1",
@ -75,7 +75,7 @@
"react-color": "^2.14.1",
"react-dom": "^16.4.1",
"stats.js": "^0.17.0",
"three": "^0.94.0",
"three": "^0.95.0",
"xaop": "^1.3.2"
},
"jest": {

@ -1,11 +1,16 @@
import { Vector3 } from 'three';
import { app } from '../ApplicationServices/Application';
import { GetPointAtCurveDir } from '../Common/CurveUtils';
import { Curve } from '../DatabaseServices/Curve';
import { Command } from '../Editor/CommandMachine';
import { PromptStatus } from '../Editor/PromptResult';
import { Vector3 } from 'three';
import { Jig } from '../Editor/Jig';
import { PromptStatus } from '../Editor/PromptResult';
import { RenderType } from '../GraphicsSystem/Enum';
//获取偏移距离的返回状态.
type GetOffsetStatus = { Status: PromptStatus, offsetDist?: number };
//曲线偏移
export class Command_Offset implements Command
{
offsetDis: number = 1;
@ -13,59 +18,132 @@ export class Command_Offset implements Command
{
let disRes = await app.m_Editor.GetDistance({
Msg: "指定偏移距离:",
KeyWordList: [{ msg: "通过", key: "T" }],
KeyWordList: [{ msg: "通过:", key: "T" }],
Default: this.offsetDis
});
let dyn = false;
if (disRes.Status === PromptStatus.Keyword && disRes.StringResult === "T")
dyn = true;
else if (disRes.Status != PromptStatus.OK)
return;
else
let isDyn = false;//动态偏移.
if (disRes.StringResult === "T")
isDyn = true;
else if (disRes.Status === PromptStatus.OK)
this.offsetDis = disRes.Value;
else
return;
while (true)
{
let enRes = await app.m_Editor.GetEntity({ Msg: "选择要偏移的对象:" });
if (enRes.Status === PromptStatus.Cancel)
break;
else if (enRes.Status !== PromptStatus.OK)
if (enRes.Status === PromptStatus.OK)
{
}
else if (enRes.Status === PromptStatus.None)
continue;
else
break;
let cu = enRes.Entity as Curve;
if (cu instanceof Curve)
{
let ptRes = await app.m_Editor.GetPoint({
Msg: "指定要偏移的那一侧的点",
Callback: dyn ? (p: Vector3) =>
{
Jig.Destroy();
let dir = GetPointAtCurveDir(cu, p) ? 1 : -1
cu.GetOffsetCurves(p.distanceTo(cu.GetClosestPointTo(p, false)) * dir)
.forEach(c => Jig.Draw(c));
} : undefined
});
app.m_Viewer.m_OutlinePass.selectedObjects = [cu.Draw(RenderType.Wireframe)];
let state: GetOffsetStatus;
if (isDyn)
state = await this.GetDynOffsetDist(cu);
else
state = await this.GetOffsetDir(cu);
Jig.End();
if (ptRes.Status === PromptStatus.OK)
if (state.Status === PromptStatus.OK)
this.DrawOffset(cu, state.offsetDist);
else if (state.Status === PromptStatus.None)
continue;
else
break;
}
}
}//end exec
//绘制偏移的对象
DrawOffset(cu: Curve, offsetDist: number)
{
cu.GetOffsetCurves(offsetDist).forEach(c =>
{
app.m_Database.ModelSpace.Append(c);
});
}
//单一对象,已经确定偏移距离的时候,用户选择偏移方向.
async GetOffsetDir(cu: Curve): Promise<GetOffsetStatus>
{
let oldDir = 0;
let ptRes = await app.m_Editor.GetPoint({
Msg: "指定要偏移的那一侧的点",
Callback: (p: Vector3) =>
{
let dir = GetPointAtCurveDir(cu, p) ? 1 : -1;
if (dir !== oldDir)
{
let p = ptRes.Value;
let dir = GetPointAtCurveDir(cu, p) ? 1 : -1;
let offCus: Curve[];
if (dyn)
offCus = cu.GetOffsetCurves(p.distanceTo(cu.GetClosestPointTo(p, false)) * dir);
else
offCus = cu.GetOffsetCurves(this.offsetDis * dir);
offCus.forEach((offCur) =>
{
app.m_Database.ModelSpace.Append(offCur);
})
app.m_Viewer.m_bNeedUpdate = true;
Jig.Destroy();
let offCus = cu.GetOffsetCurves(this.offsetDis * dir);
offCus.forEach(c => { Jig.Draw(c) });
oldDir = dir;
}
}
});
let status = { Status: ptRes.Status, offsetDist: 0 };
if (ptRes.Status === PromptStatus.OK)
{
let dir = GetPointAtCurveDir(cu, ptRes.Value) ? 1 : -1;
status.offsetDist = this.offsetDis * dir;
}
return status;
}
//动态偏移用户点到哪里偏移到哪里.
async GetDynOffsetDist(cu: Curve): Promise<GetOffsetStatus>
{
let basePoint: Vector3 = new Vector3();
let isMulti = false;
while (true)
{
let dir: number = 0;
let distRes = await app.m_Editor.GetDistance(
{
Msg: "指定通过点或输入偏移距离:",
KeyWordList: [{ key: "D", msg: isMulti ? "单个" : "多个" }],
BasePoint: basePoint,
CalcDistance: (p: Vector3) =>
{
basePoint.copy(cu.GetClosestPointTo(p, false));
dir = GetPointAtCurveDir(cu, p) ? 1 : -1;
return p.distanceTo(basePoint) * dir;
},
Callback: (dis: number) =>
{
Jig.Destroy();
cu.GetOffsetCurves(dis).forEach(c => Jig.Draw(c));
}
});
if (distRes.Status === PromptStatus.OK)
{
let offsetDist = distRes.Value;
if (dir !== Math.sign(offsetDist))
offsetDist = -offsetDist;
this.DrawOffset(cu, offsetDist);
if (isMulti)
continue;
else
return;
return { Status: PromptStatus.None, offsetDist: distRes.Value };
}
else if (distRes.StringResult === "D")
{
isMulti = !isMulti;
app.m_Editor.Prompt(`切换成功,当前<${isMulti ? "多个" : "单个"}>`);
}
else
return { Status: distRes.Status, offsetDist: distRes.Value };
}
}
}

@ -1,6 +1,8 @@
import { Matrix4 } from "three";
import { Box3, Vector3 } from "three";
import { app } from "../ApplicationServices/Application";
import { matrixScale } from "../Common/Matrix4Utils";
import { Command } from "../Editor/CommandMachine";
import { Jig } from "../Editor/Jig";
import { PromptStatus } from "../Editor/PromptResult";
export class Command_Scale implements Command
@ -16,18 +18,38 @@ export class Command_Scale implements Command
if (ptRes.Status != PromptStatus.OK)
return;
let scaleRes = await app.m_Editor.GetDistance({ Msg: "请输入缩放比例:" });
let allBox = new Box3();
let allEns = ssRes.SelectSet.SelectEntityList;
let jigEns = allEns.map(e =>
{
allBox.union(e.BoundingBox);
return Jig.Draw(e)
});
let maxSize = Math.max(...allBox.getSize(new Vector3()).toArray()) / 2;
let scaleRes = await app.m_Editor.GetDistance({
BasePoint: ptRes.Value,
Msg: "请输入缩放比例:",
Callback: (sc) =>
{
Jig.Restore();
let scMat = matrixScale(sc, ptRes.Value);
for (let en of jigEns)
{
en.ApplyMatrix(scMat);
}
},
CalcDistance: (p) => p.distanceTo(ptRes.Value) / maxSize
});
Jig.End();
if (scaleRes.Status != PromptStatus.OK)
return;
let scMat4 = new Matrix4();
let sc = scaleRes.Value;
scMat4.makeScale(sc, sc, sc, );
scMat4.setPosition(ptRes.Value);
for (let en of ssRes.SelectSet.SelectEntityList)
let scMat = matrixScale(scaleRes.Value, ptRes.Value);
for (let en of allEns)
{
en.ApplyMatrix(scMat4);
en.ApplyMatrix(scMat);
}
}
}

@ -45,7 +45,7 @@ export interface GetPointPrompt extends GetAnyPrompt
//基点
BasePoint?: Vector3;
//当鼠标移动时,回调该函数.
Callback?: (pt: THREE.Vector3) => void
Callback?: (pt: Vector3) => void;
//绘制橡皮筋(必须指定基点)
AllowDrawRubberBand?: Boolean;
//不显示动态提示
@ -56,9 +56,10 @@ export interface GetPointPrompt extends GetAnyPrompt
export interface GetDistendPrompt extends GetAnyPrompt
{
BasePoint?: Vector3
Callback?: (pt: number) => void
Default?: number
BasePoint?: Vector3;
Callback?: (dist: number, pt?: Vector3) => void;
CalcDistance?: (pt: Vector3) => number;
Default?: number;
}
export interface GetEntityPrompt extends GetAnyPrompt

@ -57,3 +57,12 @@ export function matrixIsCoplane(matrixFrom: Matrix4, matrixTo: Matrix4): boolean
return equaln(pt.z, 0);
}
//构造缩放矩阵
export function matrixScale(scale: number, center?: Vector3)
{
let scaleMat = new Matrix4().makeScale(scale, scale, scale);
if (center)
scaleMat.setPosition(center.clone().multiplyScalar(1 - scale));
return scaleMat;
}

@ -1,12 +1,12 @@
import * as THREE from 'three';
import { Box3, EllipseCurve, Geometry, Object3D, Vector3, Shape, Quaternion } from 'three';
import { Box3, EllipseCurve, Geometry, Matrix4, Object3D, Shape, Vector3 } from 'three';
import { arrayLast, arrayRemoveDuplicateBySort } from '../Common/ArrayExt';
import { ColorMaterial } from '../Common/ColorPalette';
import { clamp } from '../Common/Utils';
import { Arc } from './Arc';
import { MoveMatrix, angle, equaln, polar } from '../Geometry/GeUtils';
import { angle, equaln, MoveMatrix, polar } from '../Geometry/GeUtils';
import { RenderType } from '../GraphicsSystem/Enum';
import { IntersectCircleAndArc, IntersectCircleAndCircle, IntersectLineAndCircle, IntersectOption, IntersectPolylineAndCurve, reverseIntersectOption } from '../GraphicsSystem/IntersectWith';
import { Arc } from './Arc';
import { Factory } from './CADFactory';
import { CADFile } from './CADFile';
import { Curve } from './Curve';
@ -51,6 +51,15 @@ export class Circle extends Curve
this.m_Radius = clamp(v, 1e-9, 1e19);
this.Update();
}
protected ApplyScaleMatrix(m: Matrix4): this
{
this.WriteAllObjectRecord();
this.Center = this.Center.applyMatrix4(m);
this.Radius = this.Radius * m.getMaxScaleOnAxis();
return this;
}
//******************** Curve function start*****************//
get StartPoint(): Vector3

@ -1,13 +1,14 @@
import * as THREE from 'three';
import { Box3, Geometry, Matrix4, Object3D, Vector3 } from 'three';
import { DisposeThreeObj } from '../Common/Dispose';
import { matrixIsCoplane } from '../Common/Matrix4Utils';
import { equaln } from '../Geometry/GeUtils';
import { RenderType } from '../GraphicsSystem/Enum';
import { IntersectOption } from '../GraphicsSystem/IntersectWith';
import { Factory } from './CADFactory';
import { CADFile } from './CADFile';
import { CADObject } from './CADObject';
import { ObjectId } from './ObjectId';
import { DisposeThreeObj } from '../Common/Dispose';
/**
* Entity ,.
@ -238,17 +239,28 @@ export class Entity extends CADObject
}
/**
* 使.
* .
*
* @param {Matrix4} m
* @memberof Entity
*/
* 使.
* .
*
* @param {Matrix4} m
* @memberof Entity
*/
ApplyMatrix(m: Matrix4): this
{
this.WriteAllObjectRecord();
this.m_Matrix.multiplyMatrices(m, this.m_Matrix);
this.Update();
if (equaln(m.getMaxScaleOnAxis(), 1))
{
this.m_Matrix.multiplyMatrices(m, this.m_Matrix);
this.Update();
}
else
{
this.ApplyScaleMatrix(m);
}
return this;
}
protected ApplyScaleMatrix(m: Matrix4): this
{
return this;
}

@ -122,11 +122,16 @@ export class Editor
return null;
}
/**
* ,
* @returns {Promise<PromptEntityResult>} Ok: None: Other: Canel:Esc.
* @memberof Editor
*/
GetEntity(prompt?: GetEntityPrompt): Promise<PromptEntityResult>
{
return this.m_GetEntitytServices.Start(prompt);
}
async GetSelection(prompt?: GetSelectionPrompt): Promise<PromptSsgetResult>
GetSelection(prompt?: GetSelectionPrompt): Promise<PromptSsgetResult>
{
return this.m_SsgetServices.Start(prompt);
}

@ -66,14 +66,21 @@ export class GetDistanceServices
dynInput.SetPostion(app.m_Editor.m_MouseCtrl.m_CurMousePointVCS);
dynInput.ValuePostion = midp;
dynInput.Value = p1.distanceTo(p);
if (prompt.CalcDistance)
dynInput.Value = prompt.CalcDistance(p);
else
dynInput.Value = p1.distanceTo(p);
if (prompt.Callback)
prompt.Callback(dynInput.Value);
}
});
if (ptRes.Status == PromptStatus.OK)
this._return(p1.distanceTo(ptRes.Value));
if (ptRes.Status === PromptStatus.OK)
if (prompt.CalcDistance)
this._return(prompt.CalcDistance(ptRes.Value))
else
this._return(p1.distanceTo(ptRes.Value));
else if (ptRes.Status === PromptStatus.Keyword)
{
this._return(ptRes.StringResult);
@ -105,6 +112,13 @@ export class GetDistanceServices
this._return(cmd);
return;
}
else if (cmd === "")
{
if (prompt.Default)
this._return(prompt.Default);
else
this._return(cmd);
}
}
let v = dynInput.Value;
if (!isNaN(v))
@ -157,11 +171,15 @@ export class GetDistanceServices
res.Value = v as number;
res.Status = PromptStatus.OK;
}
else
else if (v !== "")
{
res.Status = PromptStatus.Keyword;
res.StringResult = v;
}
else
{
res.Status = PromptStatus.None;
}
let promisResFunc = this.promisResolve;
this.promisResolve = undefined; //先将回调函数设置为空,避免对GetPoint取消时重复触发本函数

@ -1,5 +1,4 @@
import { begin, end } from 'xaop';
import { end } from 'xaop';
import { GetEntityPrompt, InputState } from '../Common/InputState';
import { KeyBoard, MouseKey } from '../Common/KeyEnum';
import { Entity } from '../DatabaseServices/Entity';

@ -3,6 +3,7 @@ import { Vector3 } from 'three';
import * as xaop from 'xaop';
import { end } from 'xaop';
import { app } from '../ApplicationServices/Application';
import { DisposeThreeObj } from '../Common/Dispose';
import { GetPointPrompt, InputState } from '../Common/InputState';
import { KeyBoard, MouseKey } from '../Common/KeyEnum';
import { DynamicInputManage } from '../UI/DynamicPrompt/DynamicInputManage';
@ -170,6 +171,7 @@ export class GetPointServices implements EditorService
this.removeCalls.push(
() =>
{
DisposeThreeObj(line);
preView.Scene.remove(line);
},
xaop.end(this, this.UpdateCurPointEvent, () =>

@ -15,11 +15,22 @@ export enum PromptStatus
Error = -2
}
// export enum Errno 未来某一天我们可能需要这个东西
// {
// Space = 0,
// Enter = 1,
// Esc = 2,
// Left = 3,
// Right = 4,
// }
export class PromptResult
{
Status: PromptStatus = PromptStatus.None;
StringResult?: string;
//当用户选择失败的时候,提供当前选择失败的原因
// Errno?: Errno;
}
export class PromptPointResult extends PromptResult

Loading…
Cancel
Save