!911 优化:标注生成时避让

pull/911/MERGE
肖诗雅 4 years ago committed by ChenX
parent 57702ea7ef
commit 43e3e65dd3

@ -230,27 +230,9 @@ export class Command_AutoDimBrs implements Command
let drawY = minY - 20;
let armY = drawY - 90;
let z = useMaxZ ? maxZ : minZ;
let drawYTotal = minY - 230;
let armYTotal = drawYTotal - 80;
//draw总长标注 需要拖拽的FastDim不需要总长 仅有一块板时不需要总长
if (!needJig && brs.length > 1)
{
let alDimTotal = new AlignedDimension(
new Vector3(foots[0], drawYTotal, z),
new Vector3(foots[foots.length - 1], drawYTotal, z),
new Vector3(foots[0], armYTotal, z),
new Vector3(foots[foots.length - 1], armYTotal, z)
);
if (textRotation)
alDimTotal.TextRotation = textRotation;
alDimTotal.LeadOutFlipped = isLeadOutFlipped;
alDimTotal.ApplyMatrix(drawCS);
als.push(alDimTotal);
app.Database.ModelSpace.Append(alDimTotal);
}
let maxOffsetY = 0;
//draw
for (let i = 0; i < foots.length - 1; i++)
{
@ -273,8 +255,48 @@ export class Command_AutoDimBrs implements Command
else
app.Database.ModelSpace.Append(alDim);
if (i > 0)
{
let box = alDim.TextBoundingBox;
//找前4个标注 如果有碰撞就提高一个身位
let q4gAl = als.length > 4 ? als.slice(als.length - 4) : als;//前4个
let lastAl = als[als.length - 1];//前1个标注
for (let al of q4gAl)
{
if (al.TextBoundingBox.intersectsBox(box))
{
alDim.LeadOutOffsetX += lastAl.LeadOutOffsetX;
alDim.LeadOutOffsetY += lastAl.LeadOutOffsetY;
break;
}
}
if (Math.abs(alDim.LeadOutOffsetY) > maxOffsetY)
maxOffsetY = alDim.LeadOutOffsetY;
}
als.push(alDim);
}
//draw总长标注 需要拖拽的FastDim不需要总长 仅有一块板时不需要总长
let drawYTotal = minY - 230 + maxOffsetY;
let armYTotal = drawYTotal - 80 + (maxOffsetY / 2);
if (!needJig && brs.length > 1)
{
let alDimTotal = new AlignedDimension(
new Vector3(foots[0], drawYTotal, z),
new Vector3(foots[foots.length - 1], drawYTotal, z),
new Vector3(foots[0], armYTotal, z),
new Vector3(foots[foots.length - 1], armYTotal, z)
);
if (textRotation)
alDimTotal.TextRotation = textRotation;
alDimTotal.LeadOutFlipped = isLeadOutFlipped;
alDimTotal.ApplyMatrix(drawCS);
als.push(alDimTotal);
app.Database.ModelSpace.Append(alDimTotal);
}
return als;
}

@ -1,9 +1,9 @@
import { BufferGeometry, Line as TLine, Matrix3, Mesh, Object3D, Vector3, Vector2, Material, Matrix4 } from "three";
import { BufferGeometry, Line as TLine, Matrix3, Mesh, Object3D, Vector3, Vector2, Material, Matrix4, Box3 } from "three";
import { ColorMaterial } from "../../Common/ColorPalette";
import { FixedNotZero } from "../../Common/Utils";
import { ObjectSnapMode } from "../../Editor/ObjectSnapMode";
import { BufferGeometryUtils } from "../../Geometry/BufferGeometryUtils";
import { angle, angleAndX, midPoint, ZeroVec, ZAxis, equaln, equalv3 } from "../../Geometry/GeUtils";
import { angle, angleAndX, midPoint, ZeroVec, ZAxis, equaln, equalv3, GetBox } from "../../Geometry/GeUtils";
import { RenderType } from "../../GraphicsSystem/RenderType";
import { Factory } from "../CADFactory";
import { CADFiler } from "../CADFiler";
@ -35,6 +35,7 @@ export class AlignedDimension extends Entity
{
private _Text = new Text(undefined, undefined, "yahei");
private _TextString: string;
private _TextBoundingBox: Box3;
//引线
private _LeadOutLine = new TLine();
private _LeadOutOffsetY = 72;
@ -123,7 +124,12 @@ export class AlignedDimension extends Entity
if (!equaln(this.m_ArmP1.distanceTo(this.m_ArmP2), 0))
{
let vx = this.m_ArmP2.clone().sub(this.m_ArmP1);
if (this.m_ArmP1.x < this.m_ArmP2.x)
if (equaln(this.m_ArmP1.x, this.m_ArmP2.x))
{
if (this.m_ArmP1.y < this.m_ArmP2.y)
vx.negate();
}
else if (this.m_ArmP1.x < this.m_ArmP2.x)
vx.negate();
let vy = vx.clone().cross(ZAxis);
dalUcs = new Matrix4().makeBasis(vx.normalize(), vy.normalize(), ZAxis.clone().normalize());
@ -180,6 +186,17 @@ export class AlignedDimension extends Entity
}
}
get TextBoundingBox()
{
if (this._TextBoundingBox)
return this._TextBoundingBox;
}
set TextBoundingBox(box: Box3)
{
this._TextBoundingBox = box;
}
set LeadOutVisible(visible: boolean)
{
this.WriteAllObjectRecord();
@ -195,6 +212,11 @@ export class AlignedDimension extends Entity
this.Update();
}
get LeadOutFlipped()
{
return this._LeadOutIsFlipped;
}
toggleLeadOutVisible()
{
this.LeadOutVisible = !this.m_LeadOutVisible;
@ -211,12 +233,22 @@ export class AlignedDimension extends Entity
this.Update();
}
get LeadOutOffsetY()
{
return this._LeadOutOffsetY;
}
set LeadOutOffsetX(size: number)
{
this._LeadOutOffsetX = size;
this.Update();
}
get LeadOutOffsetX()
{
return this._LeadOutOffsetX;
}
set DefaultValue(val: DefaultValue)
{
this._DefaultVal = val;
@ -417,6 +449,18 @@ export class AlignedDimension extends Entity
this._Text.TextRotation = textRo;
this._Text.ColorIndex = this._Color;
this.RepairText();
//更新字体包围盒
let box = this._Text.BoundingBox;
let roMat = new Matrix4().makeRotationAxis(this._Text.Normal, textRo);
box.applyMatrix4(roMat);//
let moveMat = new Matrix4();
let dalUcs = this.DalUcs;
let dalUcsInv = new Matrix4().getInverse(dalUcs);
let cenc = box.getCenter(new Vector3()).applyMatrix4(dalUcs).sub(new Vector3(0, this._Text.Height / 2));//.sub(new Vector3(0, this._Text.Height / 2)); 如果dragpt 的y小于textpos那么sub变为add
moveMat.setPosition(pos.clone().sub(cenc.applyMatrix4(dalUcsInv)));
box.applyMatrix4(moveMat);
box.applyMatrix4(this.OCS);
this.TextBoundingBox = box;
}
GetObjectSnapPoints(

@ -1,4 +1,4 @@
import { MathUtils, Object3D, Vector3, Matrix4, Mesh, Shape, ShapeGeometry } from 'three';
import { MathUtils, Object3D, Vector3, Matrix4, Mesh, Shape, ShapeGeometry, Box3 } from 'three';
import { ColorMaterial } from '../../Common/ColorPalette';
import { setRotationOnAxis } from '../../Common/Matrix4Utils';
import { MoveMatrix } from '../../Geometry/GeUtils';
@ -22,6 +22,7 @@ export enum TextAligen
export class Text extends Entity
{
private _Align: TextAligen = TextAligen.LeftDown;
private box: Box3;
constructor(pos?: Vector3,
private _TextString: string = "",
public _FontName: string = "songti",
@ -101,6 +102,19 @@ export class Text extends Entity
this.UpdateTranslate();
this.AsyncUpdated();
}
get BoundingBox()
{
if (!this.box)
if (this._TextString)
{
let box: Box3;
//一个汉字宽一个this.Height 一个数字/字母宽半个Height(大概)
let alllen = (this.TextString.length + (this.TextString.match('/[\u4e00-\u9fa5]/g')?.length ?? 0)) / 2;
box = new Box3(new Vector3(), new Vector3((alllen * this._Height), this._Height));
this.box = box.applyMatrix4(this.OCS);
}
return this.box;
}
UpdateTranslate()
{
@ -111,6 +125,7 @@ export class Text extends Entity
let mesh = obj.children[0] as Mesh;
let box = mesh.geometry.boundingBox;
this.box = box.clone().applyMatrix4(this.OCS);
let p = new Vector3();
if (this._Align & TextAligen.LeftMid)

Loading…
Cancel
Save