- 积分
- 2191
- 明经币
- 个
- 注册时间
- 2022-4-4
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
本帖最后由 枫叶棋语 于 2025-6-28 10:31 编辑
 - //////////////////////////////////////////////////////////////////////////////
- //
- // Copyright 2023 Autodesk, Inc. All rights reserved.
- //
- // Use of this software is subject to the terms of the Autodesk license
- // agreement provided at the time of installation or download, or which
- // otherwise accompanies this software in either electronic or hard copy form.
- //
- //////////////////////////////////////////////////////////////////////////////
- //
- #pragma once
- #ifndef _adsdef_h
- #define _adsdef_h 1
- #include "adesk.h"
- #include <AcString.h>
- #include <gepnt2d.h>
- #include <gepnt3d.h>
- #include <gevec2d.h>
- #include <gevec3d.h>
- #define TRUE 1
- #define FALSE 0
- #ifndef EOS
- #define EOS ACRX_T('\0')
- #endif
- #pragma pack(push, 8)
- typedef double ads_real;
- typedef ads_real ads_point[3];
- #if (defined(_MSC_VER) && defined(_WIN64)) || (defined(__clang__) && defined(__LP64__))
- typedef int64_t ads_name[2];
- typedef int64_t* ads_namep;
- #else
- typedef int32_t ads_name[2];
- typedef int32_t* ads_namep;
- #endif
- typedef ads_real ads_matrix[4][4];
- /* When you want something that's explicitly a pointer type and not an array
- type, use ads_pointp and ads_namep. Remember that if your function takes an
- *array* of points, it still declares ads_point[] foo; */
- typedef ads_real* ads_pointp;
- /* To protect macro-redefinition of the X, Y, Z, and T enumerated
- constants by legacy #define's, we remove their definition. */
- #ifdef X
- #undef X
- #endif
- #ifdef Y
- #undef Y
- #endif
- #ifdef Z
- #undef Z
- #endif
- #ifdef T
- #undef T
- #endif
- #ifndef _XYZT_DEFINED
- #define _XYZT_DEFINED
- enum { X = 0, Y = 1, Z = 2 }; /* The coordinates of a point. */
- enum { T = 3 }; /* The translation vector of a 3D matrix */
- #endif // !_XYZT_DEFINED
- /* The PAUSE token for ads_command and ads_cmd
- */
- #define PAUSE ACRX_T("\")
- /* The ADS_INITGET control bits
- */
- enum {
- RSG_NONULL = 0x0001, // Disallow null input
- RSG_NOZERO = 0x0002, // Disallow zero input
- RSG_NONEG = 0x0004, // Disallow negative input
- RSG_NOLIM = 0x0008, // Do not check limits
- RSG_GETZ = 0x0010, // Get Z coordinate
- RSG_DASH = 0x0020, // Draw dashed rubber band/box
- // (not a GEDIT control bit)
- RSG_2D = 0x0040, // Restrict (getdist) to 2D (causes the
- // UD_GETZ control bit to be cleared)
- RSG_OTHER = 0x0080, // Return input string if unknown
- RSG_DDISTFIRST = 0x0100, // Give DD entry precedence over arbitrary input
- RSG_TRACKUCS = 0x0200, // Allow UCS tracking for faces
- // (causes the UD_TRACKUCS control bit to be set)
- RSG_NOORTHOZ = 0x0400, // Disables polar/ortho tracking in the Z direction
- // (causes the UD_NOORTHOZ control bit to be set)
- RSG_NOOSNAP = 0x0800, // Disables object snaps
- RSG_NODDIST = 0x1000, // No direct distance
- };
- /* The following control bits are the old names for the RSG_
- control bits above. These names are provided for
- backward compatibility. You should use the RSG_ names
- above.
- */
- enum {
- INP_NNULL = RSG_NONULL,
- INP_NZERO = RSG_NOZERO,
- INP_NNEG = RSG_NONEG,
- INP_NLIM = RSG_NOLIM,
- INP_DASH = RSG_DASH,
- INP_NZCOORD = RSG_2D
- };
- enum SelectorType {
- SELECT_TYPE_FREE = 0,
- SELECT_TYPE_PICK,
- SELECT_TYPE_WPOLY,
- SELECT_TYPE_CPOLY,
- SELECT_TYPE_FENCE,
- SELECT_TYPE_SUBENTITY,
- SELECT_TYPE_BAG,
- SELECT_TYPE_LAST,
- SELECT_TYPE_LEAF,
- SELECT_TYPE_GROUP,
- SELECT_TYPE_PASTE,
- SELECT_TYPE_HATCHASC,
- SELECT_TYPE_NRVP,
- SELECT_TYPE_OCCLASS
- };
- /* Binary data stream structure
- */
- struct ads_binary { // Binary data chunk structure
- int clen; // length of chunk in bytes (change to int?)
- char* buf; // binary data
- };
- union ads_u_val {
- //------------------------------
- // 基础成员 (保持现有结构)
- //------------------------------
- wchar_t* rstring;
- double rreal;
- double rpoint[3];
- short rint;
- int64_t rlname[2];
- int64_t mnLongPtr;
- int32_t rlong;
- int64_t mnInt64;
- uint64_t mn64data;
- struct ads_binary rbinary;
- uint8_t ihandle[8];
- //------------------------------
- // 赋值方法集合
- //------------------------------
- //字符串赋值
- void setString(const wchar_t* str) {
- rstring = copyString(str);
- }
- //ads_binary赋值
- void setBinary(const ads_binary& bin) {
- rbinary = copyBinary(bin);
- }
- //double arr[3] 赋值,包括坐标,向量
- void setArray(double x, double y, double z) {
- rpoint[0] = x;
- rpoint[1] = y;
- rpoint[2] = z;
- }
- // 句柄赋值,可以先转为64无符号整型
- void setHandle(uint64_t handle) {
- mn64data = handle;
- }
- // 32位整数
- void setInt32(int32_t value) {
- rlong = value;
- }
- // 16位短整数
- void setShort(short value) {
- rint = value;
- }
- // 64位浮点数
- void setDouble(double value) {
- rreal = value;
- }
- private:
- //------------------------------
- // 深拷贝工具函数
- //------------------------------
- static wchar_t* copyString(const wchar_t* src) {
- if (!src) return nullptr;
- const size_t len = wcslen(src) + 1;
- wchar_t* dst = new wchar_t[len];
- wcscpy_s(dst, len, src);
- return dst;
- }
- static ads_binary copyBinary(const ads_binary& bin) {
- // 有效性简写检查
- const bool is_valid_input =
- (bin.clen >= 0) && ((bin.buf == nullptr) == (bin.clen == 0)); // buf空时长度必须为0
- if (!is_valid_input) {
- return { 0, nullptr }; // 输入非法时返回无害空数据
- }
- // 无数据可直接返回
- if (bin.clen == 0) {
- return { 0, nullptr };
- }
- // 执行深拷贝
- char* dst = new char[bin.clen];
- memcpy(dst, bin.buf, bin.clen);
- return { bin.clen, dst };
- }
- public:
- //------------------------------
- // 释放方法 (根据需求调用)
- //------------------------------
- void releaseString() {
- if (rstring) {
- delete[] rstring;
- rstring = nullptr;
- }
- }
- void releaseBinary() {
- if (rbinary.buf) {
- delete[] rbinary.buf;
- rbinary.buf = nullptr;
- rbinary.clen = 0;
- }
- }
- };
- struct resbuf {
- struct resbuf* rbnext; // Allows them to be "linked"
- short restype;
- union ads_u_val resval;
- // 设置字符串
- void setValue(const wchar_t* str) {
- resval.setString(str);
- }
- void setValue(AcString str) {
- resval.setString(str);
- }
- // 设置二进制数据(参数匹配 ads_binary 结构)
- void setValue(ads_binary bin) {
- resval.setBinary(bin);
- }
- // 设置三维点(初始化 rpoint 数组)
- void setValue(double x, double y, double z) {
- resval.setArray(x, y, z);
- }
- void setValue(AcGePoint3d pt3d) {
- resval.setArray(pt3d.x, pt3d.y, pt3d.z);
- }
- void setValue(AcGeVector3d vec3d) {
- resval.setArray(vec3d.x, vec3d.y, vec3d.z);
- }
- //设置二维点(z 设置为0)
- void setValue(AcGePoint2d pt2d) {
- resval.setArray(pt2d.x, pt2d.y, 0.0);
- }
- void setValue(AcGeVector2d vec2d) {
- resval.setArray(vec2d.x, vec2d.y, 0);
- }
- // 设置 64 位句柄数值(对应 mn64data)
- void setValue(uint64_t handleValue) {
- resval.setHandle(handleValue);
- }
- // 设置 32 位整数(对应 rlong)
- void setValue(int32_t num) {
- resval.setInt32(num);
- }
- // 设置 16 位短整数(对应 rint)
- void setValue(short num) {
- resval.setShort(num);
- }
- // 设置双精度浮点数(对应 rreal)
- void setValue(double num) {
- resval.setDouble(num);
- }
- void releaseString() {
- resval.releaseString();
- }
- void releaseBinary() {
- resval.releaseBinary();
- }
- };
- typedef struct resbuf* pResbuf;
- typedef const struct resbuf* kpResbuf; // for declarations
- #pragma pack(pop)
- #endif
|
|