mirror of https://gitee.com/cf-fz/WebCAD.git
!1543 功能:弧长标注 命令: DimArc
parent
723d580903
commit
60de2ceb6b
@ -0,0 +1,98 @@
|
|||||||
|
import { app } from "../../ApplicationServices/Application";
|
||||||
|
import { Draw } from "../../Common/Append2CurSpace";
|
||||||
|
import { ArcDimension } from "../../DatabaseServices/Dimension/ArcDimension";
|
||||||
|
import { Arc } from "../../DatabaseServices/Entity/Arc";
|
||||||
|
import { Board } from "../../DatabaseServices/Entity/Board";
|
||||||
|
import { Polyline } from "../../DatabaseServices/Entity/Polyline";
|
||||||
|
import { Command } from "../../Editor/CommandMachine";
|
||||||
|
import { JigUtils } from "../../Editor/JigUtils";
|
||||||
|
import { PromptStatus } from "../../Editor/PromptResult";
|
||||||
|
import { HotCMD } from "../../Hot/HotCommand";
|
||||||
|
|
||||||
|
function GetBoardCurve(ent: Board): Arc | undefined
|
||||||
|
{
|
||||||
|
return GetPolylineArc(ent.ContourCurve.Clone().ApplyMatrix(ent.OCSNoClone) as Polyline);
|
||||||
|
}
|
||||||
|
|
||||||
|
function GetPolylineArc(cu: Polyline)
|
||||||
|
{
|
||||||
|
let ucsB = app.Editor.UCSMatrix;
|
||||||
|
app.Editor.UCSMatrix = cu.OCSNoClone;
|
||||||
|
let p = app.Editor.MouseCtrl._CurMousePointWCS;
|
||||||
|
p = cu.GetClosestPointTo(p, false);
|
||||||
|
app.Editor.UCSMatrix = ucsB;
|
||||||
|
if (!p) return undefined;
|
||||||
|
|
||||||
|
let param = cu.GetParamAtPoint(p);
|
||||||
|
let ccu = cu.GetCurveAtParam(param);
|
||||||
|
if (ccu instanceof Arc)
|
||||||
|
return ccu;
|
||||||
|
}
|
||||||
|
|
||||||
|
@HotCMD
|
||||||
|
export class Command_DimArc implements Command
|
||||||
|
{
|
||||||
|
async exec()
|
||||||
|
{
|
||||||
|
let arc: Arc;
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
let enRes = await app.Editor.GetEntity({
|
||||||
|
Msg: "选择圆或者圆弧",
|
||||||
|
Filter: {
|
||||||
|
filterFunction: (obj, ent) =>
|
||||||
|
{
|
||||||
|
if (ent instanceof Arc) return true;
|
||||||
|
|
||||||
|
if (ent instanceof Board)
|
||||||
|
{
|
||||||
|
let ccu = GetBoardCurve(ent);
|
||||||
|
return ccu !== undefined;
|
||||||
|
}
|
||||||
|
else if (ent instanceof Polyline)
|
||||||
|
{
|
||||||
|
let ccu = GetPolylineArc(ent);
|
||||||
|
return ccu !== undefined;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (enRes.Status === PromptStatus.Cancel)
|
||||||
|
return;
|
||||||
|
else if (enRes.Entity)
|
||||||
|
{
|
||||||
|
if (enRes.Entity instanceof Board)
|
||||||
|
arc = GetBoardCurve(enRes.Entity);
|
||||||
|
else if (enRes.Entity instanceof Polyline)
|
||||||
|
arc = GetPolylineArc(enRes.Entity);
|
||||||
|
else
|
||||||
|
arc = enRes.Entity as Arc;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!arc) return;
|
||||||
|
|
||||||
|
let ucsBak = app.Editor.UCSMatrix;
|
||||||
|
|
||||||
|
app.Editor.UCSMatrix = arc.OCSNoClone;
|
||||||
|
|
||||||
|
let dim = new ArcDimension(arc.Center.applyMatrix4(arc.OCSInv), arc.StartAngle, arc.EndAngle, arc.IsClockWise, arc.Radius, 30);
|
||||||
|
dim.OCS = arc.OCSNoClone;
|
||||||
|
|
||||||
|
JigUtils.Draw(dim);
|
||||||
|
let pRes = await app.Editor.GetPoint({
|
||||||
|
Msg: "请点击标注文字的位置:", Callback: p =>
|
||||||
|
{
|
||||||
|
let dist = p.distanceTo(arc.Center);
|
||||||
|
dim.TextRadiusAdd = dist - arc.Radius;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
app.Editor.UCSMatrix = ucsBak;
|
||||||
|
|
||||||
|
if (pRes.Status !== PromptStatus.OK) return;
|
||||||
|
Draw(dim);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,248 @@
|
|||||||
|
import { BufferGeometry, Line, Material, Matrix4, Mesh, Object3D, Vector3 } from "three";
|
||||||
|
import { AddEntityDrawObject } from "../../Common/AddEntityDrawObject";
|
||||||
|
import { FixedNotZero } from "../../Common/Utils";
|
||||||
|
import { BufferGeometryUtils } from "../../Geometry/BufferGeometryUtils";
|
||||||
|
import { AsVector3 } from "../../Geometry/GeUtils";
|
||||||
|
import { RenderType } from "../../GraphicsSystem/RenderType";
|
||||||
|
import { equaln } from "../../Nest/Common/Util";
|
||||||
|
import { Factory } from "../CADFactory";
|
||||||
|
import { CADFiler } from "../CADFiler";
|
||||||
|
import { Arc } from "../Entity/Arc";
|
||||||
|
import { Text, TextAligen } from "../Text/Text";
|
||||||
|
import { Dimension } from "./Dimension";
|
||||||
|
import { GetDimLineMaterial } from "./GetDimLineMaterial";
|
||||||
|
|
||||||
|
@Factory
|
||||||
|
export class ArcDimension extends Dimension
|
||||||
|
{
|
||||||
|
private _Arc = new Arc;
|
||||||
|
protected _Text = new Text();
|
||||||
|
|
||||||
|
constructor(
|
||||||
|
private _Center: Vector3 = new Vector3,
|
||||||
|
private _StartAngle: number = 0,
|
||||||
|
private _EndAngle: number = 1,
|
||||||
|
private _Clockwise = false,
|
||||||
|
private _Radius: number = 1,
|
||||||
|
private _TextRadiusAdd: number = 1,
|
||||||
|
protected _TextString: string = "⌒<>",
|
||||||
|
)
|
||||||
|
{
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
get Text()
|
||||||
|
{
|
||||||
|
if (!this._Text.TextString)
|
||||||
|
{
|
||||||
|
this.PraseArc();
|
||||||
|
this.ParseText();
|
||||||
|
}
|
||||||
|
return this._Text;
|
||||||
|
}
|
||||||
|
|
||||||
|
set TextRadiusAdd(ra: number)
|
||||||
|
{
|
||||||
|
if (equaln(ra, this._TextRadiusAdd)) return;
|
||||||
|
|
||||||
|
this.WriteAllObjectRecord();
|
||||||
|
this._TextRadiusAdd = ra;
|
||||||
|
this.Update();
|
||||||
|
}
|
||||||
|
|
||||||
|
get TextRadiusAdd() { return this._TextRadiusAdd; }
|
||||||
|
|
||||||
|
protected GetString(): string
|
||||||
|
{
|
||||||
|
return FixedNotZero(this._Arc.Length, 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
//#region 拉伸相关
|
||||||
|
GetGripPoints(): Vector3[]
|
||||||
|
{
|
||||||
|
this.PraseArc();
|
||||||
|
let pts = this._Arc.GetGripPoints();
|
||||||
|
for (let p of pts)
|
||||||
|
p.applyMatrix4(this.OCSNoClone);
|
||||||
|
return pts;
|
||||||
|
}
|
||||||
|
MoveGripPoints(indexList: number[], vec: Vector3)
|
||||||
|
{
|
||||||
|
this.WriteAllObjectRecord();
|
||||||
|
vec = vec.clone().applyMatrix4(this.OCSInv.setPosition(0, 0, 0));
|
||||||
|
|
||||||
|
this.PraseArc();
|
||||||
|
this._Arc.MoveGripPoints(indexList, vec);
|
||||||
|
|
||||||
|
this.UpdateArcFromThisArc();
|
||||||
|
this.Update();
|
||||||
|
}
|
||||||
|
|
||||||
|
GetStretchPoints(): Vector3[]
|
||||||
|
{
|
||||||
|
this.PraseArc();
|
||||||
|
let pts = this._Arc.GetStretchPoints();
|
||||||
|
for (let p of pts)
|
||||||
|
p.applyMatrix4(this.OCSNoClone);
|
||||||
|
return pts;
|
||||||
|
}
|
||||||
|
|
||||||
|
MoveStretchPoints(indexList: number[], vec: Vector3)
|
||||||
|
{
|
||||||
|
this.WriteAllObjectRecord();
|
||||||
|
vec = vec.clone().applyMatrix4(this.OCSInv.setPosition(0, 0, 0));
|
||||||
|
|
||||||
|
this.PraseArc();
|
||||||
|
this._Arc.MoveStretchPoints(indexList, vec);
|
||||||
|
|
||||||
|
this.UpdateArcFromThisArc();
|
||||||
|
this.Update();
|
||||||
|
}
|
||||||
|
|
||||||
|
private UpdateArcFromThisArc()
|
||||||
|
{
|
||||||
|
this._Center.copy(this._Arc.Center);
|
||||||
|
this._StartAngle = this._Arc.StartAngle;
|
||||||
|
this._EndAngle = this._Arc.EndAngle;
|
||||||
|
this._Radius = this._Arc.Radius;
|
||||||
|
this._Clockwise = this._Arc.IsClockWise;
|
||||||
|
}
|
||||||
|
//#endregion
|
||||||
|
|
||||||
|
//#region Draw
|
||||||
|
InitDrawObject(renderType: RenderType = RenderType.Wireframe)
|
||||||
|
{
|
||||||
|
let colorMaterial = GetDimLineMaterial(this, renderType);
|
||||||
|
|
||||||
|
let obj = new Object3D();
|
||||||
|
let line = new Line(new BufferGeometry, colorMaterial);
|
||||||
|
obj.add(line);
|
||||||
|
|
||||||
|
let arrow1 = new Mesh(BufferGeometryUtils.ArrowGeometry(), colorMaterial);
|
||||||
|
let arrow2 = new Mesh(BufferGeometryUtils.ArrowGeometry(), colorMaterial);
|
||||||
|
let arrowSize = 10;
|
||||||
|
arrow1.scale.set(arrowSize, arrowSize, arrowSize);
|
||||||
|
arrow2.scale.set(arrowSize, arrowSize, arrowSize);
|
||||||
|
obj.add(arrow1, arrow2);
|
||||||
|
|
||||||
|
this.UpdateDrawObject(renderType, obj);
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
|
||||||
|
UpdateDrawObject(renderType: RenderType, obj: Object3D)
|
||||||
|
{
|
||||||
|
obj.remove(...obj.children.slice(3));
|
||||||
|
|
||||||
|
let [line, arrow1, arrow2] = obj.children as [Line, Mesh, Mesh];
|
||||||
|
let colorMaterial = GetDimLineMaterial(this, renderType);
|
||||||
|
line.material = colorMaterial;
|
||||||
|
arrow1.material = colorMaterial;
|
||||||
|
arrow2.material = colorMaterial;
|
||||||
|
|
||||||
|
this.PraseArc();//半径设置到实际尺寸的位置,获得正确的标注尺寸
|
||||||
|
let startFootPoint = this._Arc.StartPoint;//一定要在这个位置求脚点
|
||||||
|
let endFootPoint = this._Arc.EndPoint;
|
||||||
|
|
||||||
|
this._Text.AutoUpdate = false;
|
||||||
|
|
||||||
|
this._Text.ColorIndex = this.ColorIndex;
|
||||||
|
this.ParseText();
|
||||||
|
|
||||||
|
this._Arc.DeferUpdate();
|
||||||
|
this._Text.DeferUpdate();
|
||||||
|
|
||||||
|
let linePoints: Vector3[] = [startFootPoint];
|
||||||
|
for (let p of this._Arc.Shape.getPoints(8))
|
||||||
|
linePoints.push(AsVector3(p).add(this._Center));
|
||||||
|
linePoints.push(endFootPoint);
|
||||||
|
|
||||||
|
let geo = line.geometry as BufferGeometry;
|
||||||
|
if (!BufferGeometryUtils.UpdatePts(geo, linePoints))
|
||||||
|
{
|
||||||
|
line.geometry.dispose();
|
||||||
|
line.geometry = BufferGeometryUtils.CreateFromPts(linePoints);
|
||||||
|
}
|
||||||
|
|
||||||
|
AddEntityDrawObject(obj, this._Text, renderType);
|
||||||
|
|
||||||
|
//更新箭头的位置和旋转角度
|
||||||
|
arrow1.position.copy(this._Arc.StartPoint);
|
||||||
|
arrow1.rotation.z = this._Arc.GetFistDerivAngle(0) + Math.PI / 2;
|
||||||
|
arrow1.updateMatrix();
|
||||||
|
|
||||||
|
arrow2.position.copy(this._Arc.EndPoint);
|
||||||
|
arrow2.rotation.z = this._Arc.GetFistDerivAngle(1) - Math.PI / 2;
|
||||||
|
arrow2.updateMatrix();
|
||||||
|
}
|
||||||
|
|
||||||
|
private ParseText()
|
||||||
|
{
|
||||||
|
this._Text.TextString = this.TextString;
|
||||||
|
|
||||||
|
this._Arc.Radius = this._Radius + this._TextRadiusAdd; //半径设置到文字的位置,获得文字的位置
|
||||||
|
let textP = this._Arc.GetPointAtParam(0.5);
|
||||||
|
let ang = this._Arc.GetAngleAtParam(0.5);
|
||||||
|
let textOCS = new Matrix4().makeRotationZ(ang + Math.PI * 3 / 2).setPosition(textP);
|
||||||
|
this._Text.TextAligen = TextAligen.Down;
|
||||||
|
this._Text.OCS = textOCS;
|
||||||
|
this._Text.Height = this._TextSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
UpdateDrawObjectMaterial(type: RenderType, obj: Object3D, material?: Material)
|
||||||
|
{
|
||||||
|
let colorMaterial = GetDimLineMaterial(this, type);
|
||||||
|
let count = Math.min(3, obj.children.length);
|
||||||
|
for (let i = 0; i < count; i++)
|
||||||
|
{
|
||||||
|
let l = obj.children[i] as Line;
|
||||||
|
l.material = colorMaterial;
|
||||||
|
}
|
||||||
|
|
||||||
|
this._Text.ColorIndex = this.ColorIndex;
|
||||||
|
this.Text.DeferUpdate();
|
||||||
|
}
|
||||||
|
|
||||||
|
private PraseArc()
|
||||||
|
{
|
||||||
|
this._Arc.AutoUpdate = false;
|
||||||
|
|
||||||
|
this._Arc.Center = this._Center;
|
||||||
|
this._Arc.StartAngle = this._StartAngle;
|
||||||
|
this._Arc.EndAngle = this._EndAngle;
|
||||||
|
this._Arc.IsClockWise = this._Clockwise;
|
||||||
|
this._Arc.Radius = this._Radius;
|
||||||
|
}
|
||||||
|
|
||||||
|
//#endregion
|
||||||
|
|
||||||
|
//#region -------------------------File-------------------------
|
||||||
|
//对象从文件中读取数据,初始化自身
|
||||||
|
protected _ReadFile(file: CADFiler)
|
||||||
|
{
|
||||||
|
let ver = file.Read();
|
||||||
|
super._ReadFile(file);
|
||||||
|
this._Center.fromArray(file.Read());
|
||||||
|
this._Radius = file.Read();
|
||||||
|
this._TextRadiusAdd = file.Read();
|
||||||
|
this._Clockwise = file.Read();
|
||||||
|
this._StartAngle = file.Read();
|
||||||
|
this._EndAngle = file.Read();
|
||||||
|
this._TextString = file.Read();
|
||||||
|
this._TextSize = file.Read();
|
||||||
|
}
|
||||||
|
//对象将自身数据写入到文件.
|
||||||
|
WriteFile(file: CADFiler)
|
||||||
|
{
|
||||||
|
file.Write(1);
|
||||||
|
super.WriteFile(file);
|
||||||
|
file.Write(this._Center.toArray());
|
||||||
|
file.Write(this._Radius);
|
||||||
|
file.Write(this._TextRadiusAdd);
|
||||||
|
file.Write(this._Clockwise);
|
||||||
|
file.Write(this._StartAngle);
|
||||||
|
file.Write(this._EndAngle);
|
||||||
|
file.Write(this._TextString);
|
||||||
|
file.Write(this._TextSize);
|
||||||
|
}
|
||||||
|
//#endregion
|
||||||
|
}
|
@ -0,0 +1,61 @@
|
|||||||
|
import React from "react";
|
||||||
|
import { observer } from "mobx-react";
|
||||||
|
import { observable } from "mobx";
|
||||||
|
import { CommandWrap } from "../../../Editor/CommandMachine";
|
||||||
|
import { Button, Card, Classes } from "@blueprintjs/core";
|
||||||
|
import { AlignedDimension } from "../../../DatabaseServices/Dimension/AlignedDimension";
|
||||||
|
export interface Properties_AlignedDimPanelProps
|
||||||
|
{
|
||||||
|
ents: AlignedDimension[];
|
||||||
|
}
|
||||||
|
|
||||||
|
@observer
|
||||||
|
export class Properties_AlignedDimPanel extends React.Component<Properties_AlignedDimPanelProps, {}>
|
||||||
|
{
|
||||||
|
@observable private dim_TextSize: number = 60;
|
||||||
|
constructor(p)
|
||||||
|
{
|
||||||
|
super(p);
|
||||||
|
|
||||||
|
if (this.props.ents.length > 0)
|
||||||
|
{
|
||||||
|
let numval = this.props.ents[0].TextSize;
|
||||||
|
this.dim_TextSize = numval;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
render()
|
||||||
|
{
|
||||||
|
let ents = this.props.ents;
|
||||||
|
return (
|
||||||
|
<Card className={"dal-editor"}>
|
||||||
|
<ul className={Classes.LIST_UNSTYLED}>
|
||||||
|
<li className="leadout-editor">
|
||||||
|
<span>引线调整: </span>
|
||||||
|
<div>
|
||||||
|
<Button icon="swap-horizontal" text="切换方向" minimal small onClick={() =>
|
||||||
|
{
|
||||||
|
CommandWrap(() =>
|
||||||
|
{
|
||||||
|
for (let al of ents)
|
||||||
|
{
|
||||||
|
al.toggleLeadOutFlipped();
|
||||||
|
}
|
||||||
|
}, "切换标注引线方向");
|
||||||
|
}} />
|
||||||
|
<Button icon="eye-open" text="切换显示" minimal small onClick={() =>
|
||||||
|
{
|
||||||
|
CommandWrap(() =>
|
||||||
|
{
|
||||||
|
for (let al of ents)
|
||||||
|
{
|
||||||
|
al.toggleLeadOutVisible();
|
||||||
|
}
|
||||||
|
}, "切换标注引线显示");
|
||||||
|
}} />
|
||||||
|
</div>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</Card>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in new issue