-
Notifications
You must be signed in to change notification settings - Fork 0
/
ifc.go
57 lines (51 loc) · 1.09 KB
/
ifc.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package topo
/*
#include <stdlib.h>
#include "ifc_c_api.h"
#cgo CFLAGS: -I ./libs
#cgo linux CXXFLAGS: -I ./libs -std=gnu++14
#cgo darwin CXXFLAGS: -I ./libs -std=gnu++14
#cgo darwin,arm CXXFLAGS: -I ./libs -std=gnu++14
#cgo windows CXXFLAGS: -I ./libs -std=gnu++14
*/
import "C"
import (
"unsafe"
)
func init() {
C.ifc_register_schema()
}
type IfcElementInfo struct {
Shape *Shape
Id int
ParentId int
Name string
Guid string
}
func IfcToTopoShape(f string) []*IfcElementInfo {
fl := C.CString(f)
defer C.free(unsafe.Pointer(fl))
count := 0
sp := []*IfcElementInfo{}
res := C.ifc_get_topo_shapes(fl, (*C.int)(unsafe.Pointer(&count)))
if count == 0 {
return sp
}
defer C.ifc_shapes_free(res)
for i := 0; i < count; i++ {
shp := NewShape(C.ifc_get_topo_shape(res, C.int(i)))
sp = append(sp, &IfcElementInfo{
Shape: shp,
Id: shp.Id(),
ParentId: shp.ParentId(),
Name: shp.Name(),
Guid: shp.Guid(),
})
}
return sp
}
func IsIfc(f string) bool {
fl := C.CString(f)
defer C.free(unsafe.Pointer(fl))
return bool(C.is_ifc_file(fl))
}