spring_ai_rs/ai_interface/callback/drawer/
figure.rs1use spring_ai_sys::COMMAND_TO_ID_ENGINE;
2
3use crate::ai_interface::callback::{
4 command::{
5 command_data::{
6 drawer::{
7 CreateLineFigureDrawerCommandData, CreateSplineFigureDrawerCommandData,
8 DeleteFigureDrawerCommandData, SetColorFigureDrawerCommandData,
9 },
10 CommandData,
11 },
12 command_topic::CommandTopic,
13 },
14 engine::handle_command,
15};
16
17pub struct Figure {
18 pub ai_id: i32,
19}
20
21impl Figure {
22 pub fn create_line(
23 &self,
24 position_1: [f32; 3],
25 position_2: [f32; 3],
26 width: f32,
27 arrow: bool,
28 lifetime: i32,
29 figure_group_id: i32,
30 ) -> Result<(), String> {
31 let mut command_c_data = CreateLineFigureDrawerCommandData {
32 position_1,
33 position_2,
34 width,
35 arrow,
36 lifetime,
37 figure_group_id,
38 }
39 .c_data();
40
41 handle_command(
42 self.ai_id,
43 COMMAND_TO_ID_ENGINE,
44 -1,
45 CommandTopic::DrawerFigureCreateLine.into(),
46 &mut command_c_data,
47 )?;
48
49 Ok(())
50 }
51 pub fn create_spline(
52 &self,
53 position_1: [f32; 3],
54 position_2: [f32; 3],
55 position_3: [f32; 3],
56 position_4: [f32; 3],
57 width: f32,
58 arrow: bool,
59 lifetime: i32,
60 figure_group_id: i32,
61 ) -> Result<(), String> {
62 let mut command_c_data = CreateSplineFigureDrawerCommandData {
63 position_1,
64 position_2,
65 position_3,
66 position_4,
67 width,
68 arrow,
69 lifetime,
70 figure_group_id,
71 }
72 .c_data();
73
74 handle_command(
75 self.ai_id,
76 COMMAND_TO_ID_ENGINE,
77 -1,
78 CommandTopic::DrawerFigureCreateSpline.into(),
79 &mut command_c_data,
80 )?;
81
82 Ok(())
83 }
84 pub fn delete(&self, figure_group_id: i32) -> Result<(), String> {
85 let mut command_c_data = DeleteFigureDrawerCommandData { figure_group_id }.c_data();
86
87 handle_command(
88 self.ai_id,
89 COMMAND_TO_ID_ENGINE,
90 -1,
91 CommandTopic::DrawerFigureDelete.into(),
92 &mut command_c_data,
93 )?;
94
95 Ok(())
96 }
97 pub fn set_color(
98 &self,
99 figure_group_id: i32,
100 color: [i16; 3],
101 alpha: i16,
102 ) -> Result<(), String> {
103 let mut command_c_data = SetColorFigureDrawerCommandData {
104 figure_group_id,
105 color,
106 alpha,
107 }
108 .c_data();
109
110 handle_command(
111 self.ai_id,
112 COMMAND_TO_ID_ENGINE,
113 -1,
114 CommandTopic::DrawerFigureSetColor.into(),
115 &mut command_c_data,
116 )?;
117
118 Ok(())
119 }
120}