Skip to content

Commit 36ace45

Browse files
committed
✨ feat: add measure tools
1 parent d29e5f9 commit 36ace45

File tree

19 files changed

+511
-18
lines changed

19 files changed

+511
-18
lines changed

cpp/src/shape.cpp

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <BRepBuilderAPI_MakeFace.hxx>
1313
#include <BRepExtrema_ExtCC.hxx>
1414
#include <BRepFeat_SplitShape.hxx>
15+
#include <BRepGProp.hxx>
1516
#include <BRepGProp_Face.hxx>
1617
#include <BRepOffsetAPI_MakeOffset.hxx>
1718
#include <BRepTools.hxx>
@@ -23,6 +24,7 @@
2324
#include <Geom_OffsetCurve.hxx>
2425
#include <Geom_TrimmedCurve.hxx>
2526
#include <GeomAbs_JoinType.hxx>
27+
#include <GProp_GProps.hxx>
2628
#include <ShapeAnalysis.hxx>
2729
#include <ShapeFix_Shape.hxx>
2830
#include <TopExp.hxx>
@@ -214,8 +216,9 @@ class Edge {
214216
}
215217

216218
static double curveLength(const TopoDS_Edge& edge) {
217-
BRepAdaptor_Curve curve(edge);
218-
return GCPnts_AbscissaPoint::Length(curve);
219+
GProp_GProps props;
220+
BRepGProp::LinearProperties(edge, props);
221+
return props.Mass();
219222
}
220223

221224
static Handle_Geom_TrimmedCurve curve(const TopoDS_Edge& edge) {
@@ -292,7 +295,15 @@ class Wire {
292295

293296
class Face {
294297
public:
295-
static TopoDS_Shape offset(const TopoDS_Face& face , double distance, const GeomAbs_JoinType& joinType) {
298+
static double area(const TopoDS_Face &face)
299+
{
300+
GProp_GProps props;
301+
BRepGProp::SurfaceProperties(face, props);
302+
return props.Mass();
303+
}
304+
305+
static TopoDS_Shape offset(const TopoDS_Face &face, double distance, const GeomAbs_JoinType &joinType)
306+
{
296307
BRepOffsetAPI_MakeOffset offsetter(face, joinType);
297308
offsetter.Perform(distance);
298309
if (offsetter.IsDone()) {
@@ -334,6 +345,15 @@ class Face {
334345

335346
};
336347

348+
class Solid {
349+
public:
350+
static double volume(const TopoDS_Solid& solid) {
351+
GProp_GProps props;
352+
BRepGProp::VolumeProperties(solid, props);
353+
return props.Mass();
354+
}
355+
};
356+
337357
EMSCRIPTEN_BINDINGS(Shape) {
338358

339359
class_<Shape>("Shape")
@@ -360,8 +380,7 @@ EMSCRIPTEN_BINDINGS(Shape) {
360380
.class_function("curveLength", &Edge::curveLength)
361381
.class_function("trim", &Edge::trim)
362382
.class_function("intersect", &Edge::intersect)
363-
.class_function("offset", &Edge::offset)
364-
;
383+
.class_function("offset", &Edge::offset);
365384

366385
class_<Wire>("Wire")
367386
.class_function("offset", &Wire::offset)
@@ -370,12 +389,17 @@ EMSCRIPTEN_BINDINGS(Shape) {
370389
;
371390

372391
class_<Face>("Face")
392+
.class_function("area", &Face::area)
373393
.class_function("offset", &Face::offset)
374394
.class_function("outerWire", &Face::outerWire)
375395
.class_function("surface", &Face::surface)
376396
.class_function("normal", &Face::normal)
377397
.class_function("curveOnSurface", &Face::curveOnSurface)
378398
;
379399

400+
class_<Solid>("Solid")
401+
.class_function("volume", &Solid::volume)
402+
;
403+
380404
}
381405

packages/chili-builder/src/ribbon.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,11 @@ export const DefaultRibbon: RibbonTab[] = [
5454
},
5555
{
5656
groupName: "ribbon.group.tools",
57-
items: ["create.section", "create.offset", "create.copySubShape", "create.group"],
57+
items: ["create.group", ["create.section", "create.offset", "create.copyShape"]],
58+
},
59+
{
60+
groupName: "ribbon.group.measure",
61+
items: [["measure.length", "measure.angle", "measure.select"]],
5862
},
5963
{
6064
groupName: "ribbon.group.importExport",

packages/chili-core/src/i18n/en.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ export default {
6161
"command.create.box": "Box",
6262
"command.create.circle": "Circle",
6363
"command.create.cone": "Cone",
64-
"command.create.copySubShape": "SubShape",
64+
"command.create.copyShape": "CopyShape",
6565
"command.create.cylinder": "Cylinder",
6666
"command.create.ellipse": "Ellipse",
6767
"command.create.ellipsoid": "Ellipsoid",
@@ -83,6 +83,9 @@ export default {
8383
"command.edit.undo": "Undo",
8484
"command.file.export": "Export",
8585
"command.file.import": "Import",
86+
"command.measure.angle": "Angle",
87+
"command.measure.length": "Length",
88+
"command.measure.select": "Select",
8689
"command.modify.array": "Array",
8790
"command.modify.break": "Break",
8891
"command.modify.brushAdd": "BrushAdd",
@@ -107,6 +110,7 @@ export default {
107110
"command.workingPlane.set": "Set",
108111
"command.workingPlane.toggleDynamic": "Toggle",
109112
"common.angle": "Angle",
113+
"common.area": "Area",
110114
"common.back": "Back",
111115
"common.cancel": "Cancel",
112116
"common.clone": "Clone",
@@ -121,6 +125,7 @@ export default {
121125
"common.opacity": "Opacity",
122126
"common.thickness": "Thickness",
123127
"common.type": "Type",
128+
"common.volume": "Volume",
124129
"dialog.title.selectWorkingPlane": "Select Working Plane",
125130
"entity.editable": "Editable Entity",
126131
"entity.parameter": "Parameter Entity",
@@ -183,6 +188,7 @@ export default {
183188
"prompt.select.models": "Please select models",
184189
"prompt.select.noModelSelected": "No model selected",
185190
"prompt.select.shape": "Please select shape",
191+
"prompt.select.solids": "Please select solids",
186192
"prompt.select.vertexs": "Please select vertexs",
187193
"prompt.select.wires": "Please select wires",
188194
"toast.snap.notFoundValidPoint": "No valid point",
@@ -197,6 +203,7 @@ export default {
197203
"ribbon.group.converter": "Converter",
198204
"ribbon.group.draw": "Drawing",
199205
"ribbon.group.importExport": "Import/Export",
206+
"ribbon.group.measure": "Measure",
200207
"ribbon.group.modify": "Modify",
201208
"ribbon.group.other": "Other",
202209
"ribbon.group.selection": "Selection",

packages/chili-core/src/i18n/keys.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ const I18N_KEYS = [
5656
"command.create.box",
5757
"command.create.circle",
5858
"command.create.cone",
59-
"command.create.copySubShape",
59+
"command.create.copyShape",
6060
"command.create.cylinder",
6161
"command.create.ellipse",
6262
"command.create.ellipsoid",
@@ -78,6 +78,9 @@ const I18N_KEYS = [
7878
"command.edit.undo",
7979
"command.file.export",
8080
"command.file.import",
81+
"command.measure.angle",
82+
"command.measure.length",
83+
"command.measure.select",
8184
"command.modify.array",
8285
"command.modify.break",
8386
"command.modify.brushAdd",
@@ -102,6 +105,7 @@ const I18N_KEYS = [
102105
"command.workingPlane.set",
103106
"command.workingPlane.toggleDynamic",
104107
"common.angle",
108+
"common.area",
105109
"common.back",
106110
"common.cancel",
107111
"common.clone",
@@ -116,6 +120,7 @@ const I18N_KEYS = [
116120
"common.opacity",
117121
"common.thickness",
118122
"common.type",
123+
"common.volume",
119124
"dialog.title.selectWorkingPlane",
120125
"entity.editable",
121126
"entity.parameter",
@@ -177,6 +182,7 @@ const I18N_KEYS = [
177182
"prompt.select.models",
178183
"prompt.select.noModelSelected",
179184
"prompt.select.shape",
185+
"prompt.select.solids",
180186
"prompt.select.vertexs",
181187
"prompt.select.wires",
182188
"properties.group.transform",
@@ -190,6 +196,7 @@ const I18N_KEYS = [
190196
"ribbon.group.converter",
191197
"ribbon.group.draw",
192198
"ribbon.group.importExport",
199+
"ribbon.group.measure",
193200
"ribbon.group.modify",
194201
"ribbon.group.other",
195202
"ribbon.group.selection",

packages/chili-core/src/i18n/zh-cn.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ export default {
6161
"command.create.box": "立方体",
6262
"command.create.circle": "圆形",
6363
"command.create.cone": "圆锥",
64-
"command.create.copySubShape": "复制子形状",
64+
"command.create.copyShape": "复制形状",
6565
"command.create.cylinder": "圆柱",
6666
"command.create.ellipse": "椭圆",
6767
"command.create.ellipsoid": "椭球体",
@@ -83,6 +83,9 @@ export default {
8383
"command.edit.undo": "撤销",
8484
"command.file.export": "导出",
8585
"command.file.import": "导入",
86+
"command.measure.angle": "角度",
87+
"command.measure.length": "长度",
88+
"command.measure.select": "选择",
8689
"command.modify.array": "阵列",
8790
"command.modify.break": "打断",
8891
"command.modify.brushAdd": "添加画笔",
@@ -107,6 +110,7 @@ export default {
107110
"command.workingPlane.set": "设置",
108111
"command.workingPlane.toggleDynamic": "动态",
109112
"common.angle": "角度",
113+
"common.area": "面积",
110114
"common.back": "返回",
111115
"common.cancel": "取消",
112116
"common.clone": "复制对象",
@@ -121,6 +125,7 @@ export default {
121125
"common.opacity": "不透明度",
122126
"common.thickness": "厚度",
123127
"common.type": "类型",
128+
"common.volume": "体积",
124129
"dialog.title.selectWorkingPlane": "选择工作平面",
125130
"entity.editable": "可编辑实体",
126131
"entity.parameter": "参数化实体",
@@ -182,6 +187,7 @@ export default {
182187
"prompt.select.models": "请选择模型",
183188
"prompt.select.noModelSelected": "未选择任何模型",
184189
"prompt.select.shape": "选择形状",
190+
"prompt.select.solids": "请选择实体",
185191
"prompt.select.vertexs": "请选择点",
186192
"prompt.select.wires": "请选择线",
187193
"toast.snap.notFoundValidPoint": "未找到有效的点",
@@ -196,6 +202,7 @@ export default {
196202
"ribbon.group.converter": "转换",
197203
"ribbon.group.draw": "绘制",
198204
"ribbon.group.importExport": "导入/导出",
205+
"ribbon.group.measure": "测量",
199206
"ribbon.group.modify": "修改",
200207
"ribbon.group.other": "其他",
201208
"ribbon.group.selection": "选择",

packages/chili-core/src/shape/shape.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ export interface IWire extends IShape {
8080
}
8181

8282
export interface IFace extends IShape {
83+
area(): number;
8384
normal(u: number, v: number): [point: XYZ, normal: XYZ];
8485
outerWire(): IWire;
8586
surface(): ISurface;
@@ -93,7 +94,9 @@ export interface IFace extends IShape {
9394

9495
export interface IShell extends IShape {}
9596

96-
export interface ISolid extends IShape {}
97+
export interface ISolid extends IShape {
98+
volume(): number;
99+
}
97100

98101
export interface ICompound extends IShape {}
99102

packages/chili-core/src/visual/view.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ export interface IView extends IPropertyChanged, IDisposable {
2727
get isClosed(): boolean;
2828
get width(): number;
2929
get height(): number;
30+
get dom(): HTMLElement | undefined;
3031
mode: ViewMode;
3132
name: string;
3233
workplane: Plane;

packages/chili-three/src/threeView.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@ export class ThreeView extends Observable implements IView {
7575
this.setProperty("name", value);
7676
}
7777

78+
get dom() {
79+
return this._dom;
80+
}
81+
7882
private _isClosed: boolean = false;
7983
get isClosed(): boolean {
8084
return this._isClosed;
@@ -532,6 +536,10 @@ export class ThreeView extends Observable implements IView {
532536
let { shape, subShape, index, groups, transform } = this.findShapeAndIndex(parent, intersection);
533537
if (!subShape || !shape) return { shape: undefined, indexes: [] };
534538

539+
if (ShapeType.hasSolid(shapeType) && subShape.shapeType === ShapeType.Face) {
540+
let solid = this.getAncestorAndIndex(ShapeType.Solid, subShape, shape, groups);
541+
if (solid.shape) return solid;
542+
}
535543
if (ShapeType.hasShell(shapeType) && subShape.shapeType === ShapeType.Face) {
536544
let shell = this.getAncestorAndIndex(ShapeType.Shell, subShape, shape, groups);
537545
if (shell.shape) return shell;

packages/chili-wasm/lib/chili-wasm.d.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,8 @@ export interface Wire extends ClassHandle {}
509509

510510
export interface Face extends ClassHandle {}
511511

512+
export interface Solid extends ClassHandle {}
513+
512514
export type Domain = {
513515
start: number;
514516
end: number;
@@ -800,12 +802,16 @@ interface EmbindModule {
800802
edgeLoop(_0: TopoDS_Wire): Array<TopoDS_Edge>;
801803
};
802804
Face: {
805+
area(_0: TopoDS_Face): number;
803806
offset(_0: TopoDS_Face, _1: number, _2: GeomAbs_JoinType): TopoDS_Shape;
804807
outerWire(_0: TopoDS_Face): TopoDS_Wire;
805808
surface(_0: TopoDS_Face): Handle_Geom_Surface;
806809
normal(_0: TopoDS_Face, _1: number, _2: number, _3: gp_Pnt, _4: gp_Vec): void;
807810
curveOnSurface(_0: TopoDS_Face, _1: TopoDS_Edge): Domain;
808811
};
812+
Solid: {
813+
volume(_0: TopoDS_Solid): number;
814+
};
809815
Transient: {
810816
isKind(_0: Standard_Transient | null, _1: EmbindString): boolean;
811817
isInstance(_0: Standard_Transient | null, _1: EmbindString): boolean;
-142 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)