COMPASSi/trunk/code/inc/DataManager/DataManagerInterface/include/SnapCurvePointsState.h

67 lines
2.0 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#ifndef SnapCurvePointsState_H
#define SnapCurvePointsState_H
#include <iostream>
#include <bitset>
#include "DataManagerGlobal.h"
#ifdef __cplusplus
extern "C"
{
#endif
enum DATAMANAGER_DLL_API_EXPORTS SNAP_POINTS_Type
{
SNAP_POINTS_Type_DEFALT =0,
SNAP_POINTS_Type_START = 1, //捕获起点
SNAP_POINTS_Type_END, //捕获终点
SNAP_POINTS_Type_LINE_POINT, //捕获线上点
SNAP_POINTS_Type_ANY_POINT, //捕获任意点
SNAP_POINTS_Type_CROSS_POINT, //捕获交叉点
SNAP_POINTS_Type_SIZE
};
class DATAMANAGER_DLL_API_EXPORTS SnapCurvePointsState
{
private:
unsigned int buttonState; // 用一个 5 位二进制数表示按钮状态
public:
SnapCurvePointsState() : buttonState(0) {} // 初始化时所有按钮状态为 00000从1开始所有不选中
~SnapCurvePointsState()
{
buttonState = 0;
}
// 选择一个按钮,保证互斥性,索引从 1 开始
void selectButton(int buttonIndex) {
if (buttonIndex < 1 || buttonIndex > 5) {
std::cout << "按钮索引超出范围!" << std::endl;
return;
}
// 清除所有按钮的选中状态
buttonState = 0;
// 设置对应按钮的状态为选中
buttonState |= (1 << (buttonIndex - 1)); // 传入的索引减 1 转换为 0-4 范围的索引
}
// 检查某个按钮的状态(是否选中),索引从 1 开始
bool isSelected(int buttonIndex) const {
if (buttonIndex < 1 || buttonIndex > 5) {
std::cout << "按钮索引超出范围!" << std::endl;
return false;
}
return (buttonState >> (buttonIndex - 1)) & 1; // 判断该按钮是否被选中
}
// 输出当前按钮状态的二进制形式
void printButtonState() const {
std::bitset<5> bs(buttonState); // 使用 bitset 显示二进制状态
std::cout << "按钮状态: " << bs << std::endl;
}
};
#ifdef __cplusplus
}
#endif
#endif