Skip to content

Commit 559fd52

Browse files
author
aninggo
committed
u
1 parent a7e3db4 commit 559fd52

File tree

6 files changed

+103
-5
lines changed

6 files changed

+103
-5
lines changed

primitives.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2290,6 +2290,45 @@ func CreateStubTubeWithPlace(params StubTubeParams, position Point3, normal Dir3
22902290
return s
22912291
}
22922292

2293+
type CableWireParams struct {
2294+
Points []Point3 // 电缆路径点集
2295+
OutsideDiameter float32 // 电缆外径(mm)
2296+
}
2297+
2298+
func (p *CableWireParams) to_struct() C.cable_wire_params_t {
2299+
var c C.cable_wire_params_t
2300+
c.numPoints = C.int(len(p.Points))
2301+
c.outsideDiameter = C.double(p.OutsideDiameter)
2302+
2303+
if len(p.Points) > 0 {
2304+
c.points = (*C.pnt3d_t)(C.malloc(C.size_t(len(p.Points)) * C.sizeof_pnt3d_t))
2305+
for i, pt := range p.Points {
2306+
*(*C.pnt3d_t)(unsafe.Pointer(uintptr(unsafe.Pointer(c.points)) + uintptr(i)*C.sizeof_pnt3d_t)) = pt.val
2307+
}
2308+
}
2309+
return c
2310+
}
2311+
2312+
func CreateCableWire(params CableWireParams) *Shape {
2313+
cParams := params.to_struct()
2314+
defer C.free(unsafe.Pointer(cParams.points))
2315+
2316+
shp := C.create_cable_wire(cParams)
2317+
s := &Shape{inner: &innerShape{val: shp}}
2318+
runtime.SetFinalizer(s.inner, (*innerShape).free)
2319+
return s
2320+
}
2321+
2322+
func CreateCableWireWithPlace(params CableWireParams, position Point3, direction Dir3, upDirection Dir3) *Shape {
2323+
cParams := params.to_struct()
2324+
defer C.free(unsafe.Pointer(cParams.points))
2325+
2326+
shp := C.create_cable_wire_with_place(cParams, position.val, direction.val, upDirection.val)
2327+
s := &Shape{inner: &innerShape{val: shp}}
2328+
runtime.SetFinalizer(s.inner, (*innerShape).free)
2329+
return s
2330+
}
2331+
22932332
type PoleTowerNode struct {
22942333
ID string
22952334
Position Point3

src/primitives.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7933,7 +7933,7 @@ TopoDS_Shape create_cable_wire(const cable_wire_params &params) {
79337933
if (params.points.size() < 2) {
79347934
throw Standard_ConstructionError("At least 2 points are required");
79357935
}
7936-
if (params.outside_diameter <= 0.0) {
7936+
if (params.outsideDiameter <= 0.0) {
79377937
throw Standard_ConstructionError("Outside diameter must be positive");
79387938
}
79397939

@@ -7988,7 +7988,7 @@ TopoDS_Shape create_cable_wire(const cable_wire_params &params) {
79887988
gp_Ax2 sectionAxes(gp::Origin(), initNormal, refDir);
79897989

79907990
// 创建圆形截面(直径方向始终垂直于路径)
7991-
gp_Circ circle(sectionAxes, params.outside_diameter / 2);
7991+
gp_Circ circle(sectionAxes, params.outsideDiameter / 2);
79927992
TopoDS_Wire profile =
79937993
BRepBuilderAPI_MakeWire(BRepBuilderAPI_MakeEdge(circle).Edge()).Wire();
79947994

src/primitives.hh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1287,7 +1287,7 @@ TopoDS_Shape create_stub_tube(const stub_tube_params &params,
12871287

12881288
struct cable_wire_params {
12891289
std::vector<gp_Pnt> points; // 电缆路径点集
1290-
double outside_diameter; // 电缆外径(mm)
1290+
double outsideDiameter; // 电缆外径(mm)
12911291
};
12921292

12931293
TopoDS_Shape create_cable_wire(const cable_wire_params &params);

src/primitives_c_api.cc

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2052,6 +2052,54 @@ create_stub_tube_with_place(stub_tube_params_t params, pnt3d_t position,
20522052
}
20532053
}
20542054

2055+
PRIMCAPICALL topo_shape_t *create_cable_wire(cable_wire_params_t params) {
2056+
try {
2057+
// 将C数组转换为C++ vector
2058+
std::vector<gp_Pnt> points;
2059+
for (int i = 0; i < params.numPoints; ++i) {
2060+
points.push_back(
2061+
gp_Pnt(params.points[i].x, params.points[i].y, params.points[i].z));
2062+
}
2063+
2064+
// 创建C++参数结构
2065+
cable_wire_params cpp_params{.points = points,
2066+
.outsideDiameter = params.outsideDiameter};
2067+
2068+
return new topo_shape_t{
2069+
.shp = std::make_shared<shape>(create_cable_wire(cpp_params))};
2070+
} catch (...) {
2071+
return nullptr;
2072+
}
2073+
}
2074+
2075+
PRIMCAPICALL topo_shape_t *
2076+
create_cable_wire_with_place(cable_wire_params_t params, pnt3d_t position,
2077+
dir3d_t direction, dir3d_t upDirection) {
2078+
try {
2079+
// 将C数组转换为C++ vector
2080+
std::vector<gp_Pnt> points;
2081+
for (int i = 0; i < params.numPoints; ++i) {
2082+
points.push_back(
2083+
gp_Pnt(params.points[i].x, params.points[i].y, params.points[i].z));
2084+
}
2085+
2086+
// 创建C++参数结构
2087+
cable_wire_params cpp_params{.points = points,
2088+
.outsideDiameter = params.outsideDiameter};
2089+
2090+
// 转换位置和方向参数
2091+
gp_Pnt cpp_position(position.x, position.y, position.z);
2092+
gp_Dir cpp_direction(direction.x, direction.y, direction.z);
2093+
gp_Dir cpp_upDirection(upDirection.x, upDirection.y, upDirection.z);
2094+
2095+
return new topo_shape_t{
2096+
.shp = std::make_shared<shape>(create_cable_wire(
2097+
cpp_params, cpp_position, cpp_direction, cpp_upDirection))};
2098+
} catch (...) {
2099+
return nullptr;
2100+
}
2101+
}
2102+
20552103
PRIMCAPICALL topo_shape_t *create_pole_tower(pole_tower_params_t params) {
20562104
pole_tower_params cpp_params;
20572105

src/primitives_c_api.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1051,6 +1051,17 @@ PRIMCAPICALL topo_shape_t *
10511051
create_stub_tube_with_place(stub_tube_params_t params, pnt3d_t position,
10521052
dir3d_t normal, dir3d_t xDir);
10531053

1054+
typedef struct {
1055+
pnt3d_t *points; // 电缆路径点集
1056+
int numPoints; // 点数量
1057+
double outsideDiameter; // 电缆外径(mm)
1058+
} cable_wire_params_t;
1059+
1060+
PRIMCAPICALL topo_shape_t *create_cable_wire(cable_wire_params_t params);
1061+
PRIMCAPICALL topo_shape_t *
1062+
create_cable_wire_with_place(cable_wire_params_t params, pnt3d_t position,
1063+
dir3d_t direction, dir3d_t upDirection);
1064+
10541065
typedef enum {
10551066
MEMBER_TYPE_ANGLE = 1, // 角钢
10561067
MEMBER_TYPE_TUBE = 2, // 等径钢管

src/primitives_test.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2392,7 +2392,7 @@ void test_make_cable_wire() {
23922392
std::vector<gp_Pnt> straightPoints = {gp_Pnt(0, 0, 0), gp_Pnt(100, 0, 0)};
23932393

23942394
auto shp1 = create_cable_wire(
2395-
cable_wire_params{.points = straightPoints, .outside_diameter = 10.0});
2395+
cable_wire_params{.points = straightPoints, .outsideDiameter = 10.0});
23962396

23972397
if (shp1.IsNull()) {
23982398
std::cerr << "Error: Failed to create straight cable wire" << std::endl;
@@ -2406,7 +2406,7 @@ void test_make_cable_wire() {
24062406
gp_Pnt(150, 0, 100)};
24072407

24082408
auto shp2 = create_cable_wire(
2409-
cable_wire_params{.points = curvedPoints, .outside_diameter = 8.0});
2409+
cable_wire_params{.points = curvedPoints, .outsideDiameter = 8.0});
24102410

24112411
if (shp2.IsNull()) {
24122412
std::cerr << "Error: Failed to create curved cable wire" << std::endl;

0 commit comments

Comments
 (0)