File size: 2,750 Bytes
1dd0e3b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include <iostream>
#include "hhb_cad_c_api.h"

int main() {
    HHBContext context;
    HHBError error;
    char* response = nullptr;

    // 创建上下文
    error = hhb_create_context(&context);
    if (error != HHB_SUCCESS) {
        std::cerr << "Failed to create context: " << error << std::endl;
        return 1;
    }

    // 测试创建螺栓
    std::cout << "Testing create_bolt..." << std::endl;
    const char* create_bolt_command = "{\"action\": \"create_bolt\", \"params\": {\"radius\": 5.0, \"thread_pitch\": 1.2, \"length\": 20.0}}";
    error = hhb_process_command(context, create_bolt_command, &response);
    if (error == HHB_SUCCESS) {
        std::cout << "Response: " << response << std::endl;
        hhb_free_response(response);
    } else {
        std::cerr << "Failed to create bolt: " << error << std::endl;
    }

    // 测试获取实体列表
    std::cout << "\nTesting get_entities..." << std::endl;
    const char* get_entities_command = "{\"action\": \"get_entities\"}";
    error = hhb_process_command(context, get_entities_command, &response);
    if (error == HHB_SUCCESS) {
        std::cout << "Response: " << response << std::endl;
        hhb_free_response(response);
    } else {
        std::cerr << "Failed to get entities: " << error << std::endl;
    }

    // 测试选择实体
    std::cout << "\nTesting select_entity..." << std::endl;
    const char* select_entity_command = "{\"action\": \"select_entity\", \"params\": {\"entity_id\": 0}}";
    error = hhb_process_command(context, select_entity_command, &response);
    if (error == HHB_SUCCESS) {
        std::cout << "Response: " << response << std::endl;
        hhb_free_response(response);
    } else {
        std::cerr << "Failed to select entity: " << error << std::endl;
    }

    // 测试获取选中的实体
    std::cout << "\nTesting get_selected_entity..." << std::endl;
    char* entity_info = nullptr;
    error = hhb_get_selected_entity(context, &entity_info);
    if (error == HHB_SUCCESS) {
        std::cout << "Selected entity: " << entity_info << std::endl;
        hhb_free_response(entity_info);
    } else {
        std::cerr << "Failed to get selected entity: " << error << std::endl;
    }

    // 测试获取干涉点
    std::cout << "\nTesting get_interference_points..." << std::endl;
    char* points_info = nullptr;
    error = hhb_get_interference_points(context, &points_info);
    if (error == HHB_SUCCESS) {
        std::cout << "Interference points: " << points_info << std::endl;
        hhb_free_response(points_info);
    } else {
        std::cerr << "Failed to get interference points: " << error << std::endl;
    }

    // 销毁上下文
    hhb_destroy_context(context);

    return 0;
}