!680 面域的导出

pull/680/MERGE
肖诗雅 5 years ago committed by ChenX
parent 37b343af68
commit 660aca1769

@ -6,13 +6,14 @@ import { Entitys2Data } from "./ExportData";
import pako from "pako";
import { HotCMD } from "../Hot/HotCommand";
import { CURRENT_HOST } from "../Common/HostUrl";
import { Region } from "../DatabaseServices/Entity/Region";
@HotCMD
export class Command_ExportView implements Command
{
async exec()
{
let ssRes = await app.Editor.GetSelection({ Filter: { filterTypes: [Board] } });
let ssRes = await app.Editor.GetSelection({ Filter: { filterTypes: [Board, Region] } });
if (ssRes.Status !== PromptStatus.OK) return;
let ents = ssRes.SelectSet.SelectEntityList;

@ -8,8 +8,10 @@ import { Curve } from "../DatabaseServices/Entity/Curve";
import { Entity } from "../DatabaseServices/Entity/Entity";
import { ExtrudeSolid } from "../DatabaseServices/Entity/Extrude";
import { Polyline } from "../DatabaseServices/Entity/Polyline";
import { Region } from "../DatabaseServices/Entity/Region";
import { ObjectId } from "../DatabaseServices/ObjectId";
import { PhysicalMaterialRecord } from "../DatabaseServices/PhysicalMaterialRecord";
import { Shape } from "../DatabaseServices/Shape";
import { TextureTableRecord } from "../DatabaseServices/Texture";
import { Command } from "../Editor/CommandMachine";
import { PromptStatus } from "../Editor/PromptResult";
@ -41,6 +43,8 @@ export function Entitys2Data(ents: Entity[])
}
else if (e instanceof SweepSolid)
d.Entitys.push(ConverSweep2Data(e));
else if (e instanceof Region)
d.Entitys.push(ConveRegion2Data(e));
}
if (materials.size > 0)
{
@ -107,6 +111,23 @@ function ConverSweep2Data(e: SweepSolid)
return ed;
}
function ConveRegion2Data(e: Region)
{
let reg: any = {};
reg.Type = "Region";
reg.Shapes = e.ShapeManager.ShapeList.map(ConverShape2Data);
reg.OCS = e.OCS.toArray();
return reg;
}
function ConverShape2Data(e: Shape)
{
let d = {} as any;
d.Contour = Curve2Data(e.Outline.Curve);
d.Holes = e.Holes.map(c => Curve2Data(c.Curve));
return d;
}
function ConverMaterial(material: PhysicalMaterialRecord)
{
let d: any = {};

@ -16,7 +16,7 @@ let cache = new WeakMap();
export class Contour
{
private m_Curve: Polyline | Circle;
private _Curve: Polyline | Circle;
protected SetCurve(cu: Polyline | Circle)
{
@ -25,7 +25,7 @@ export class Contour
if (cu.Area2 < 0)
cu.Reverse();
}
this.m_Curve = cu;
this._Curve = cu;
}
static CreateContour(cus: Curve[] | Polyline | Circle, needLink = true)
@ -57,15 +57,15 @@ export class Contour
}
get Curve(): Polyline | Circle
{
return this.m_Curve;
return this._Curve;
}
get Area()
{
return this.m_Curve.Area;
return this._Curve.Area;
}
get BoundingBox()
{
return this.m_Curve.BoundingBox;
return this._Curve.BoundingBox;
}
/**
*
@ -75,7 +75,7 @@ export class Contour
*/
UnEqualProportionScale(ref: number, dist: number, dir: "x" | "y")
{
let cu = this.m_Curve;
let cu = this._Curve;
if (cu instanceof Polyline)
{
let lineData = cu.LineData;
@ -97,7 +97,7 @@ export class Contour
}
Clone()
{
return Contour.CreateContour([this.m_Curve.Clone()]);
return Contour.CreateContour([this._Curve.Clone()]);
}
//交集:结果数组为空则失败
IntersectionBoolOperation(target: Contour): Contour[]
@ -190,7 +190,7 @@ export class Contour
let intersectionList: Curve[] = [];
let unionList: Curve[] = [];
let sourceOutline = this.m_Curve;
let sourceOutline = this._Curve;
let targetOutline = target.Curve;
let interPts = sourceOutline.IntersectWith(targetOutline, IntersectOption.OnBothOperands);
@ -282,7 +282,7 @@ export class Contour
}
GetSubtractList(target: Contour)
{
let sourceOutline = this.m_Curve as Polyline;
let sourceOutline = this._Curve as Polyline;
let targetOutline = target.Curve as Polyline;
let interPts = sourceOutline.IntersectWith(targetOutline, IntersectOption.OnBothOperands, 1e-3);
@ -403,15 +403,15 @@ export class Contour
}
get Shape(): THREE.Shape
{
return this.m_Curve.Shape;
return this._Curve.Shape;
}
CuInOutline(targetCur: Curve)
{
return isTargetCurInOrOnSourceCur(this.m_Curve, targetCur);
return isTargetCurInOrOnSourceCur(this._Curve, targetCur);
}
Equal(tar: Contour)
{
return equalCurve(this.m_Curve, tar.m_Curve);
return equalCurve(this._Curve, tar._Curve);
}
}

@ -9,84 +9,84 @@ import { Polyline } from './Entity/Polyline';
export class Shape
{
private m_Outline: Contour;
private m_Holes: Contour[] = [];
private m_Shape: TShape = new TShape();
private _Outline: Contour;
private _Holes: Contour[] = [];
private _Shape: TShape = new TShape();
constructor(out?: Contour, hols?: Contour[])
{
this.m_Outline = out || new Contour();
hols && this.m_Holes.push(...hols);
this._Outline = out || new Contour();
hols && this._Holes.push(...hols);
}
get Outline()
{
return this.m_Outline;
return this._Outline;
}
get Holes()
{
return this.m_Holes;
return this._Holes;
}
get Area()
{
let outlineArea = this.m_Outline.Area;
let holeArea = this.m_Holes.map(l => l.Area).reduce((a1, a2) => a1 + a2, 0);
let outlineArea = this._Outline.Area;
let holeArea = this._Holes.map(l => l.Area).reduce((a1, a2) => a1 + a2, 0);
return outlineArea - holeArea;
}
get BoundingBox()
{
return this.m_Outline.BoundingBox;
return this._Outline.BoundingBox;
}
set Outline(cus: Contour)
{
this.m_Outline = cus;
this._Outline = cus;
this.UpdateShape();
}
set Holes(cus: Contour[])
{
this.m_Holes = cus;
this._Holes = cus;
this.UpdateShape();
}
get Shape()
{
this.UpdateShape();
return this.m_Shape;
return this._Shape;
}
get Position()
{
return this.m_Outline.Curve.Position;
return this._Outline.Curve.Position;
}
set Position(p: Vector3)
{
let vec = p.clone().sub(this.m_Outline.Curve.Position);
this.m_Outline.Curve.Position = p;
for (let h of this.m_Holes)
let vec = p.clone().sub(this._Outline.Curve.Position);
this._Outline.Curve.Position = p;
for (let h of this._Holes)
h.Curve.Position = h.Curve.Position.add(vec);
}
Z0()
{
this.m_Outline.Curve.Z0();
for (let h of this.m_Holes)
this._Outline.Curve.Z0();
for (let h of this._Holes)
h.Curve.Z0();
}
MatrixPlanarizere()
{
this.m_Outline.Curve.MatrixPlanarizere();
for (let h of this.m_Holes)
this._Outline.Curve.MatrixPlanarizere();
for (let h of this._Holes)
h.Curve.MatrixPlanarizere();
}
ApplyMatrix(m: Matrix4)
{
this.m_Outline.Curve.ApplyMatrix(m);
this.m_Holes.forEach(h => h.Curve.ApplyMatrix(m));
this._Outline.Curve.ApplyMatrix(m);
this._Holes.forEach(h => h.Curve.ApplyMatrix(m));
return this;
}
ApplyScaleMatrix(m: Matrix4): this
{
let cu = this.Outline.Curve;
let cus = this.m_Holes.map(h => h.Curve);
let cus = this._Holes.map(h => h.Curve);
cus.unshift(cu);
for (let c of cus)
{
@ -100,7 +100,7 @@ export class Shape
Explode()
{
let cus: Curve[] = [];
let contours: Contour[] = [this.m_Outline, ...this.m_Holes];
let contours: Contour[] = [this._Outline, ...this._Holes];
for (let con of contours)
{
if (con.Curve instanceof Polyline)
@ -113,14 +113,14 @@ export class Shape
Clone()
{
let shape = new Shape();
shape.Outline = this.m_Outline.Clone();
shape.Outline = this._Outline.Clone();
shape.Holes = this.Holes.map(h => h.Clone());
return shape;
}
SetColor(color: number)
{
this.m_Outline.Curve.ColorIndex = color;
this.m_Holes.forEach(h => h.Curve.ColorIndex = color);
this._Outline.Curve.ColorIndex = color;
this._Holes.forEach(h => h.Curve.ColorIndex = color);
}
GetObjectSnapPoints(
snapMode: ObjectSnapMode,
@ -140,8 +140,8 @@ export class Shape
case ObjectSnapMode.Per:
case ObjectSnapMode.Tan:
{
let cus: Curve[] = [this.m_Outline.Curve];
for (let h of this.m_Holes)
let cus: Curve[] = [this._Outline.Curve];
for (let h of this._Holes)
{
cus.push(h.Curve);
}
@ -160,7 +160,7 @@ export class Shape
GetGripPoints()
{
let pts = this.Outline.Curve.GetGripPoints();
for (let h of this.m_Holes)
for (let h of this._Holes)
{
pts.push(...h.Curve.GetGripPoints());
}
@ -169,13 +169,13 @@ export class Shape
MoveGripPoints(indexList: Array<number>, vec: Vector3)
{
let i = indexList[0];
let outlineIndex = this.m_Outline.Curve.GetGripPoints().length;
let outlineIndex = this._Outline.Curve.GetGripPoints().length;
let cu = this.m_Outline.Curve;
let cu = this._Outline.Curve;
if (i >= outlineIndex)
{
for (let h of this.m_Holes)
for (let h of this._Holes)
{
let len = h.Curve.GetGripPoints().length;
if (indexList[0] < outlineIndex + len)
@ -192,7 +192,7 @@ export class Shape
GetStretchPoints()
{
let pts = this.Outline.Curve.GetStretchPoints();
for (let h of this.m_Holes)
for (let h of this._Holes)
{
pts.push(...h.Curve.GetStretchPoints());
}
@ -201,7 +201,7 @@ export class Shape
MoveStretchPoints(indexList: Array<number>, vec: Vector3)
{
let outlen = 0;
for (let cu of [this.m_Outline.Curve, ...this.m_Holes.map(h => h.Curve)])
for (let cu of [this._Outline.Curve, ...this._Holes.map(h => h.Curve)])
{
let count = cu.GetStretchPoints().length;
let refIndex = outlen + count;
@ -224,15 +224,15 @@ export class Shape
//交集 如果成功返回一个面域 失败返回0个
IntersectionBoolOperation(targetShape: Shape): Shape[]
{
let resOutlines = this.m_Outline.IntersectionBoolOperation(targetShape.m_Outline);
let cus = this.targetOutlineSubHoleOutline(resOutlines, Shape.mergeContours([...this.m_Holes, ...targetShape.m_Holes]));
let resOutlines = this._Outline.IntersectionBoolOperation(targetShape._Outline);
let cus = this.targetOutlineSubHoleOutline(resOutlines, Shape.mergeContours([...this._Holes, ...targetShape._Holes]));
return Shape.pairHoleAndOutline(cus);
}
//并集,如果成功返回1个形状,不成功返回2个形状
UnionBoolOperation(targetShape: Shape): Shape[]
{
let resOutlines = this.m_Outline.UnionBoolOperation(targetShape.m_Outline);
let resOutlines = this._Outline.UnionBoolOperation(targetShape._Outline);
let shapes: Shape[] = [];
//提取出所有的孔洞, 目标线段孔洞和原线段差,如果孔洞和目标相减后有被包围轮廓,应把这个单独提取出来作为形状
@ -256,11 +256,11 @@ export class Shape
});
};
pickUpHoleOrShape(targetShape.m_Holes, this.m_Holes, this.m_Outline);
pickUpHoleOrShape(this.m_Holes, targetShape.m_Holes, targetShape.m_Outline);
targetShape.m_Holes.forEach(cu =>
pickUpHoleOrShape(targetShape._Holes, this._Holes, this._Outline);
pickUpHoleOrShape(this._Holes, targetShape._Holes, targetShape._Outline);
targetShape._Holes.forEach(cu =>
{
this.m_Holes.forEach(c =>
this._Holes.forEach(c =>
{
unionHoles.push(...c.IntersectionBoolOperation(cu));
});
@ -273,28 +273,28 @@ export class Shape
//如果完全被减掉,就返回0个.其他的返回1个或者n个
SubstactBoolOperation(targetShape: Shape): Shape[]
{
let resOutlines = this.m_Outline.SubstactBoolOperation(targetShape.m_Outline);
let resOutlines = this._Outline.SubstactBoolOperation(targetShape._Outline);
let shapes: Shape[] = [];
//如果相减,则需要取出被减面域和减数面域的洞的交集,结果还需减去被减面域的全部孔洞
targetShape.m_Holes.forEach(cu =>
targetShape._Holes.forEach(cu =>
{
let tmpInterList = cu.IntersectionBoolOperation(this.m_Outline);
let tmpInterList = cu.IntersectionBoolOperation(this._Outline);
shapes.push(...Shape.pairHoleAndOutline(this.targetOutlineSubHoleOutline(tmpInterList, this.m_Holes)));
shapes.push(...Shape.pairHoleAndOutline(this.targetOutlineSubHoleOutline(tmpInterList, this._Holes)));
});
let fCus = this.targetOutlineSubHoleOutline(resOutlines, Shape.mergeContours([...this.m_Holes, ...targetShape.m_Holes]));
let fCus = this.targetOutlineSubHoleOutline(resOutlines, Shape.mergeContours([...this._Holes, ...targetShape._Holes]));
shapes.push(...Shape.pairHoleAndOutline(fCus));
return shapes;
}
Equal(targetShape: Shape)
{
if (this.m_Outline.Equal(targetShape.m_Outline))
if (this._Outline.Equal(targetShape._Outline))
{
return this.m_Holes.length === targetShape.m_Holes.length
&& this.m_Holes.every(h1 =>
targetShape.m_Holes.some(h2 => h1.Equal(h2))
return this._Holes.length === targetShape._Holes.length
&& this._Holes.every(h1 =>
targetShape._Holes.some(h2 => h1.Equal(h2))
);
}
return false;
@ -428,13 +428,13 @@ export class Shape
}
UpdateShape()
{
this.m_Shape = this.Outline.Shape;
this._Shape = this.Outline.Shape;
this.Holes.forEach(h =>
{
if (h.Curve instanceof Polyline)
h.Curve.UpdateMatrixTo(this.Outline.Curve.OCS);
});
this.m_Shape.holes.push(...this.m_Holes.map(
this._Shape.holes.push(...this._Holes.map(
h =>
{
if (h.Curve instanceof Circle)
@ -452,12 +452,12 @@ export class Shape
ReadFile(file: CADFiler)
{
let ver = file.Read();//1
this.m_Outline = Contour.CreateContour([file.ReadObject() as Curve]);
this._Outline = Contour.CreateContour([file.ReadObject() as Curve]);
let count = file.Read();
for (let i = 0; i < count; i++)
{
this.m_Holes.push(
this._Holes.push(
Contour.CreateContour([file.ReadObject() as Curve])
);
}
@ -467,8 +467,8 @@ export class Shape
WriteFile(file: CADFiler)
{
file.Write(1);//ver
file.WriteObject(this.m_Outline.Curve);
file.Write(this.m_Holes.length);
this.m_Holes.forEach(h => file.WriteObject(h.Curve));
file.WriteObject(this._Outline.Curve);
file.Write(this._Holes.length);
this._Holes.forEach(h => file.WriteObject(h.Curve));
}
}

@ -6,27 +6,27 @@ import { Matrix4 } from 'three';
export class ShapeManager
{
private m_ShapeList: Shape[] = [];
private _ShapeList: Shape[] = [];
get ShapeList()
{
return this.m_ShapeList.slice();
return this._ShapeList.slice();
}
get ShapeCount()
{
return this.m_ShapeList.length;
return this._ShapeList.length;
}
get ShapeArea()
{
return this.m_ShapeList.map(s => s.Area).reduce((a1, a2) => a1 + a2, 0);
return this._ShapeList.map(s => s.Area).reduce((a1, a2) => a1 + a2, 0);
}
AppendShapeList(shapes: Shape | Shape[])
{
Array.isArray(shapes) ? this.m_ShapeList.push(...shapes) : this.m_ShapeList.push(shapes);
Array.isArray(shapes) ? this._ShapeList.push(...shapes) : this._ShapeList.push(shapes);
return this;
}
Clear()
{
this.m_ShapeList.length = 0;
this._ShapeList.length = 0;
}
BoolOper(otherMg: ShapeManager, booltype: BoolOpeartionType)
{
@ -44,24 +44,24 @@ export class ShapeManager
IntersectionBoolOperation(target: ShapeManager)
{
let shapes: Shape[] = [];
for (let srcShape of this.m_ShapeList)
for (let srcShape of this._ShapeList)
{
for (let tarShape of target.m_ShapeList)
for (let tarShape of target._ShapeList)
{
let tmpShapes = srcShape.IntersectionBoolOperation(tarShape);
shapes.push(...tmpShapes);
}
}
this.Clear();
this.m_ShapeList = shapes;
return this.m_ShapeList.length > 0;
this._ShapeList = shapes;
return this._ShapeList.length > 0;
}
//并集,如果有一个形状并集成功,就成功
UnionBoolOperation(targetMg: ShapeManager)
{
let isSuccess = false;
let srcShapes = this.m_ShapeList;
let tarShapes = targetMg.m_ShapeList;
let srcShapes = this._ShapeList;
let tarShapes = targetMg._ShapeList;
let alones: Shape[] = [];//孤立的形状
for (let src of srcShapes)
@ -89,23 +89,23 @@ export class ShapeManager
alones.push(src);//它是孤独的一个形状
}
this.m_ShapeList = alones.concat(tarShapes);
this._ShapeList = alones.concat(tarShapes);
return isSuccess;
}
SubstactBoolOperation(target: ShapeManager)
{
//减数形状
for (let subtrahendShape of target.m_ShapeList)
for (let subtrahendShape of target._ShapeList)
{
let tmpShapes: Shape[] = [];
//被减形状
for (let minuendShape of this.m_ShapeList)
for (let minuendShape of this._ShapeList)
{
let operatedShapes = minuendShape.SubstactBoolOperation(subtrahendShape);
tmpShapes.push(...operatedShapes);
}
//迭代this形状列表,每次赋予新的结果
this.m_ShapeList = tmpShapes;
this._ShapeList = tmpShapes;
}
return true;
}
@ -120,7 +120,7 @@ export class ShapeManager
*/
ApplyMatrix(mat4: Matrix4)
{
for (let s of this.m_ShapeList)
for (let s of this._ShapeList)
{
s.Outline.Curve.ApplyMatrix(mat4);
s.Holes.forEach(o => o.Curve.ApplyMatrix(mat4));
@ -135,7 +135,7 @@ export class ShapeManager
{
let obj = new Shape();
obj.ReadFile(file);
this.m_ShapeList.push(obj);
this._ShapeList.push(obj);
}
}
WriteFile(file: CADFiler)

Loading…
Cancel
Save