You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
380 lines
7.6 KiB
C++
380 lines
7.6 KiB
C++
#pragma once
|
|
//全局类型定义
|
|
|
|
using namespace std;/*使用标准库的名字空间*/
|
|
//STL 标准头文件
|
|
#include <set>
|
|
#include <vector>
|
|
#include <list>
|
|
#include <iostream>
|
|
#include <fstream>
|
|
#include <string>
|
|
#include <utility>
|
|
#include <map>
|
|
#include <deque>
|
|
#include <algorithm>
|
|
|
|
//屏蔽编译警告
|
|
#pragma warning(disable : 4800)
|
|
#pragma warning(disable : 4244)
|
|
#pragma warning(disable : 4996)
|
|
#pragma warning(disable : 4018)
|
|
|
|
#define PI 3.14159265358979323846
|
|
//#define COORD_EPS 0.001 //坐标误差精度(0.001 表示在坐标比较中,两个点的距离小于1um 就认为是相等)
|
|
#define COORD_EPS 0.00001
|
|
|
|
#define RGB_WHITE RGB(255,255,255) //白色
|
|
#define RGB_BLACK RGB(0,0,0) //黑色
|
|
#define RGB_GREEN RGB(0,255,0) //绿色
|
|
#define RGB_GREEN1 RGB(29,241,135) //绿色
|
|
|
|
#define RGB_RED RGB(255,0,0) //红色
|
|
#define RGB_PINK RGB(255,55,120) //粉红色
|
|
#define RGB_PINK1 RGB(231,61,175) //粉红色
|
|
|
|
#define RGB_YELLOW RGB(255,255,0) //黄色
|
|
#define RGB_BLUE RGB(0,0,255) //蓝色
|
|
#define RGB_BLUE1 RGB(153,217,234) //天蓝色
|
|
|
|
#define RGB_NODE_BLUE RGB(0,63,255) //节点蓝色
|
|
#define RGB_PURPLE RGB(163,73,164) //紫色
|
|
#define RGB_GRAY RGB(240,240,240) //灰色
|
|
#define RGB_GRAY1 RGB(160,160,160) //灰色
|
|
|
|
|
|
|
|
#define STR_NULL ""
|
|
#define STR_INPUT_ERROR "无效指令: "
|
|
#define STR_INPUT_SYMBOL '>'
|
|
|
|
|
|
//鼠标工具的类型
|
|
enum MOUSE_TOOL
|
|
{
|
|
_TOOL_POINT=0,
|
|
_TOOL_RECT,
|
|
_TOOL_LINE,
|
|
_TOOL_PLINE,//多线段
|
|
_TOOL_CIRCLE,
|
|
_TOOL_MOVE,
|
|
_TOOL_MOVE2,//指定基点移动
|
|
_TOOL_ROTATO,
|
|
_TOOL_COPY,
|
|
_TOOL_MEASURE,//测量
|
|
_TOOL_ZOOM,//缩放
|
|
_TOOL_CUT,//修剪
|
|
_TOOL_ADD_NODE,//添加节点
|
|
_TOOL_DEL_NODE,//删除节点
|
|
_TOOL_BREAK_NODE,//打断节点
|
|
_TOOL_MOVE_NODE,//移动节点
|
|
_TOOL_TEXT,//文字
|
|
_TOOL_BARCODE,//条码
|
|
_TOOL_ONE_POINT,//一个点
|
|
_TOOL_STRETCH,//拉伸工具
|
|
_TOOL_PT_MOVE_TO_CCD,//设置特定用途的点
|
|
_TOOL_SET_MARK_PT,//手动指定定位点
|
|
};
|
|
enum OBJ_TYPE
|
|
{
|
|
_TYPE_BASE = 0,
|
|
_TYPE_PLINE,//多线段1
|
|
_TYPE_POINT,//点2
|
|
_TYPE_CIRCLE,//圆3
|
|
_TYPE_COMPOSITE,//一般组合类型4
|
|
_TYPE_TXT,//字符串5
|
|
_TYPE_BARCODE,//条码6
|
|
_TYPE_STR,//string 7
|
|
_TYPE_CHAR,//字符8
|
|
|
|
};
|
|
enum X_OR_Y
|
|
{
|
|
_X=0,
|
|
_Y,
|
|
_XY,
|
|
};
|
|
|
|
enum CATCH_PT_TYPE//抓取点的类型
|
|
{
|
|
_CATCH_NODE = 0,//结点
|
|
_CATCH_INTERSECT,//线段的交点
|
|
_CATCH_ORTHO,//正交
|
|
_CATCH_CUT_TRACK,//元件切割道交点
|
|
};
|
|
enum STATUS//鼠标工具的状态值,用于确定每一步做什么事情
|
|
{
|
|
_STATUS_1 = 0,
|
|
_STATUS_2,
|
|
_STATUS_3,
|
|
_STATUS_4,
|
|
_STATUS_5,
|
|
_STATUS_6,
|
|
_STATUS_END
|
|
};
|
|
enum OBJ_OP_TYPR
|
|
{
|
|
_OP_MOVE = 0,
|
|
_OP_ROTATO,
|
|
_OP_MIRROR,
|
|
_OP_STRETCH,//拉伸
|
|
_OP_REVERSE,//反转数据点
|
|
_OP_SCALE,//按比例缩放
|
|
};
|
|
|
|
inline bool IsDbEqual(double a,double b)
|
|
{
|
|
if((abs(a-b))<COORD_EPS)
|
|
return true;
|
|
else
|
|
return false;
|
|
}
|
|
//浮点型的xy 组合,单位毫米
|
|
class Dbxy
|
|
{
|
|
friend bool operator==(const Dbxy &lhs, const Dbxy &rhs);
|
|
friend bool operator!=(const Dbxy &lhs, const Dbxy &rhs);
|
|
friend Dbxy operator+(const Dbxy &lhs, const Dbxy &rhs);
|
|
friend Dbxy operator-(const Dbxy &lhs, const Dbxy &rhs);
|
|
public:
|
|
Dbxy(double _x,double _y):x(_x),y(_y){};
|
|
Dbxy()
|
|
{
|
|
x= y =0;
|
|
};
|
|
bool Equal(Dbxy &pt)
|
|
{
|
|
if(IsDbEqual(x,pt.x) && IsDbEqual(y,pt.y))
|
|
return true;
|
|
else
|
|
return false;
|
|
}
|
|
public:
|
|
double x;
|
|
double y;
|
|
};
|
|
inline bool operator==(const Dbxy &lhs, const Dbxy &rhs)
|
|
{
|
|
return (IsDbEqual(lhs.x,rhs.x) && IsDbEqual(lhs.y,rhs.y));
|
|
}
|
|
inline bool operator!=(const Dbxy &lhs, const Dbxy &rhs)
|
|
{
|
|
return ((!IsDbEqual(lhs.x, rhs.x)) || (!IsDbEqual(lhs.y, rhs.y)));
|
|
}
|
|
inline Dbxy operator+(const Dbxy &lhs, const Dbxy &rhs)
|
|
{
|
|
return Dbxy((lhs.x+ rhs.x),(lhs.y+ rhs.y));
|
|
}
|
|
inline Dbxy operator-(const Dbxy &lhs, const Dbxy &rhs)
|
|
{
|
|
return Dbxy((lhs.x - rhs.x), (lhs.y - rhs.y));
|
|
}
|
|
//抓取点的类型
|
|
class CCatchPoint :public Dbxy
|
|
{
|
|
public:
|
|
CCatchPoint(double _x,double _y,CATCH_PT_TYPE type):Dbxy(_x,_y),m_type(type){};
|
|
CCatchPoint()
|
|
{
|
|
Dbxy::Dbxy();
|
|
};
|
|
CATCH_PT_TYPE GetType(){return m_type;};
|
|
public:
|
|
CATCH_PT_TYPE m_type;
|
|
};
|
|
|
|
class DbSize
|
|
{
|
|
public:
|
|
DbSize(double _w,double _h):w(_w),h(_h){};
|
|
DbSize()
|
|
{
|
|
w= h =0;
|
|
};
|
|
public:
|
|
double w;
|
|
double h;
|
|
};
|
|
|
|
class IntXY
|
|
{
|
|
friend bool operator==(const IntXY &lhs, const IntXY &rhs);
|
|
public:
|
|
IntXY(int _x,int _y):x(_x),y(_y){};
|
|
IntXY()
|
|
{
|
|
x = y =0;
|
|
};
|
|
public:
|
|
int x;
|
|
int y;
|
|
};
|
|
inline bool operator==(const IntXY &lhs, const IntXY &rhs)
|
|
{
|
|
return (lhs.x == rhs.x && lhs.y == rhs.y);
|
|
}
|
|
|
|
#if 1
|
|
class DbRect
|
|
{
|
|
public:
|
|
DbRect(double _L,double _R,double _T,double _B):L(_L),R(_R),T(_T),B(_B){};
|
|
DbRect(Dbxy pt1,Dbxy pt2){Creat(pt1,pt2);}
|
|
DbRect(Dbxy pt,double size){Creat(pt,size);}//size 是rect 的半径
|
|
DbRect(Dbxy pt,DbSize size)//根据中心点和尺寸来创建
|
|
{
|
|
Creat(pt,size);
|
|
};
|
|
DbRect(){Reset();};
|
|
void Creat(Dbxy pt1,Dbxy pt2);
|
|
void Creat(Dbxy pt,double size);
|
|
void Creat(Dbxy pt,DbSize size);
|
|
void Reset();
|
|
bool IsZero();
|
|
DbSize GetSize();
|
|
Dbxy GetCenterPt();
|
|
Dbxy GetBottomCenterPt();
|
|
double Width();
|
|
double Height();
|
|
public:
|
|
double L;
|
|
double R;
|
|
double T;
|
|
double B;
|
|
};
|
|
inline void DbRect::Reset()
|
|
{
|
|
L= B = 0.1;
|
|
R = T = 0;
|
|
}
|
|
inline void DbRect::Creat(Dbxy pt1,Dbxy pt2)
|
|
{
|
|
if(pt1.x < pt2.x)
|
|
{
|
|
L = pt1.x;
|
|
R = pt2.x;
|
|
}
|
|
else
|
|
{
|
|
L = pt2.x;
|
|
R = pt1.x;
|
|
}
|
|
if(pt2.y<pt1.y)
|
|
{
|
|
T = pt1.y;
|
|
B = pt2.y;
|
|
}
|
|
else
|
|
{
|
|
T = pt2.y;
|
|
B = pt1.y;
|
|
}
|
|
}
|
|
inline void DbRect::Creat(Dbxy pt,double size)
|
|
{
|
|
L = pt.x-size;
|
|
R = pt.x+size;
|
|
T = pt.y+size;
|
|
B = pt.y-size;
|
|
}
|
|
inline void DbRect::Creat(Dbxy pt,DbSize size)
|
|
{
|
|
L = pt.x-size.w/2;
|
|
R = pt.x+size.w/2;
|
|
T = pt.y+size.h/2;
|
|
B = pt.y-size.h/2;
|
|
}
|
|
inline bool DbRect::IsZero()
|
|
{
|
|
if(L<R || B<T)
|
|
return false;
|
|
else
|
|
return true;
|
|
}
|
|
inline Dbxy DbRect::GetCenterPt()
|
|
{
|
|
Dbxy pt;
|
|
if(L<=R)
|
|
{
|
|
pt.x = (L+R)/2;
|
|
}
|
|
if(T>=B)
|
|
{
|
|
pt.y = (T+B)/2;
|
|
}
|
|
return pt;
|
|
}
|
|
inline DbSize DbRect::GetSize()
|
|
{
|
|
DbSize size;
|
|
size.w = R - L;
|
|
size.h = T - B;
|
|
if(size.w<0)
|
|
size.w = 0;
|
|
if(size.h<0)
|
|
size.h = 0;
|
|
return size;
|
|
}
|
|
//底部中心点
|
|
inline Dbxy DbRect::GetBottomCenterPt()
|
|
{
|
|
Dbxy pt;
|
|
pt.x = (L+R)/2;
|
|
pt.y = B;
|
|
return pt;
|
|
}
|
|
inline double DbRect::Width()
|
|
{
|
|
return R-L;
|
|
}
|
|
inline double DbRect::Height()
|
|
{
|
|
return T-B;
|
|
}
|
|
#endif
|
|
|
|
//封装所有对象操作的参数,便于统一发送格式
|
|
struct SObjOperatePar{
|
|
SObjOperatePar()
|
|
{
|
|
MoveX = MoveY = 0;
|
|
Angle = 0;
|
|
OldSize = NewSize = Diff = 0;
|
|
Scale = 1;
|
|
}
|
|
OBJ_OP_TYPR OpType;//操作类型
|
|
X_OR_Y xy;//标识xy 方向
|
|
Dbxy BasePt;//基准点
|
|
double MoveX;//移动量
|
|
double MoveY;
|
|
double Angle;//360 度角
|
|
double OldSize;
|
|
double NewSize;
|
|
double Diff;
|
|
double Scale;//缩放比例
|
|
};
|
|
|
|
typedef pair<CPoint,bool> PointType;
|
|
|
|
//创建圆的参数
|
|
class CCirclePar
|
|
{
|
|
public:
|
|
CCirclePar(void)
|
|
{
|
|
Radius = 1;
|
|
DEdgeCnt = 32;
|
|
bMerge = true;
|
|
StartAng = 0;
|
|
EndAng = 360;
|
|
}
|
|
public:
|
|
Dbxy CenterPt;//圆心
|
|
double Radius;//半径
|
|
int DEdgeCnt;//边数
|
|
bool bMerge;//是否合并
|
|
double StartAng;//起始角度360 度角
|
|
double EndAng;//结束角度
|
|
};
|
|
|