• 主页

# vc动态数组问题

fuzhishui 南宁企航 创始人  2010-07-17 06:14:42

struct Line
{
CArray <double, double> x;
CArray <double, double> y;
long count;
long M_Count;

Line()
{
x.SetSize(0);
y.SetSize(0);
count = 0;
M_Count = 0;
}
};

struct Line_two
{
CArray <Line, Line> line1;
CArray <Line, Line> line2;
CArray <double, double> h;
CArray <long, long> OfFang;
long count;
long M_Count;

Line_two()
{
line1.SetSize(200);
line2.SetSize(200);
h.SetSize(0);
OfFang.SetSize(0);
count = 0;
M_Count = 0;
}
};

Line_two Max_line;

Line line;
this->Max_line.line1.InsertAt(lLen + 1, line, 10);

...全文
106 点赞 收藏 2

2 条回复

fuzhishui 2010-07-17

//-----------------------------------------------------------------------------
//----- TriangleNetContourDlg.cpp : Implementation of CTriangleNetContourDlg
//-----------------------------------------------------------------------------
#include "StdAfx.h"
#include "resource.h"
#include "TriangleNetContourDlg.h"

//-----------------------------------------------------------------------------

/// <summary>
/// 控件与函数绑定
/// </summary>
ON_BN_CLICKED(IDC_BUTTON_OK, &CTriangleNetContourDlg::OnBnClickedButtonOk)
ON_BN_CLICKED(IDC_BUTTON_CANCEL, &CTriangleNetContourDlg::OnBnClickedButtonCancel)
END_MESSAGE_MAP()

//-----------------------------------------------------------------------------
/// <summary>
/// 构造函数
/// </summary>
CTriangleNetContourDlg::CTriangleNetContourDlg (CWnd *pParent /*=NULL*/, HINSTANCE hInstance /*=NULL*/)
, m_strEdit_Interval(_T(""))
, m_strEdit_IdHeight(_T(""))
, m_strEdit_MaxSide(_T(""))
, m_strEdit_MaxCon(_T(""))
, m_strEdit_MinCon(_T(""))
{
this->k = 0;
this->dInterval = 1; // 等高距
this->dMaxSide = 100 ; // 最大边长
this->dIdHeigh = 1; // 序号文本高度
this->max_N = 0;
}

//-----------------------------------------------------------------------------
/// <summary>
/// 数据交换
/// </summary>
void CTriangleNetContourDlg::DoDataExchange (CDataExchange *pDX)
{
DDX_Control(pDX, IDC_EDIT_NOTE_ID_HEIGHT, m_Edit_IdHeight);
DDX_Control(pDX, IDC_EDIT_MAX_SIDE, m_Edit_MaxSide);
DDX_Control(pDX, IDC_CHECK_BUILD_TRIANGLE_NET, m_Button_BuildTriNet);
DDX_Control(pDX, IDC_CHECK_BUILD_CONTOUR, m_Button_BuildContour);
DDX_Control(pDX, IDC_EDIT_INTERVAL, m_Edit_Interval);
DDX_Control(pDX, IDC_EDIT_NOTE_CONTOUR_HEIGHT, m_Edit_ConHeight);
DDX_Control(pDX, IDC_EDIT_MAX_CONTOUR, m_Edit_MaxCon);
DDX_Control(pDX, IDC_EDIT_MIN_CONTOUR, m_Edit_MinCon);
DDX_Text(pDX, IDC_EDIT_INTERVAL, m_strEdit_Interval);
DDX_Text(pDX, IDC_EDIT_NOTE_ID_HEIGHT, m_strEdit_IdHeight);
DDX_Text(pDX, IDC_EDIT_MAX_SIDE, m_strEdit_MaxSide);
DDX_Control(pDX, IDC_CHECK_SHOW_TRIA_NET_ID, m_Button_ShowTriId);
DDX_Control(pDX, IDC_CHECK_SHOW_TRIANGLE_NET_PROCESS, m_Button_ShowProcess);
DDX_Text(pDX, IDC_EDIT_MAX_CONTOUR, m_strEdit_MaxCon);
DDX_Text(pDX, IDC_EDIT_MIN_CONTOUR, m_strEdit_MinCon);
DDX_Control(pDX, IDC_CHECK_SHOW_CONTOUR_PROCESS, m_Check_ShowCont);
}

//-----------------------------------------------------------------------------
//----- Needed for modeless dialogs to keep focus.
//----- Return FALSE to not keep the focus, return TRUE to keep the focus
{
return (TRUE) ;
}

/// <summary>
/// 初始化对话框
/// </summary>
BOOL CTriangleNetContourDlg::OnInitDialog()
{

// TODO: 在此添加额外的初始化

// 初始化控件状态
this->m_Button_BuildTriNet.SetCheck(BST_CHECKED);
this->m_Button_BuildContour.SetCheck(BST_CHECKED);
this->m_Button_ShowTriId.SetCheck(BST_CHECKED);
this->m_Button_ShowProcess.SetCheck(BST_CHECKED);

// 设置默认值
this->m_Edit_IdHeight.SetWindowTextW(_T("1"));
this->m_Edit_MaxSide.SetWindowTextW(_T("100"));
this->m_Edit_Interval.SetWindowTextW(_T("1"));
this->m_Edit_ConHeight.SetWindowTextW(_T("1"));

return TRUE; // return TRUE unless you set the focus to a control
// 异常: OCX 属性页应返回 FALSE
}

/// 开始
void CTriangleNetContourDlg::OnBnClickedButtonOk()
{
int nLen = -1;
struct resbuf *rb;

CString strLayName = _T("三角网"); // 图层名称
CString strObjType = _T("INSERT,POINT"); // 图元类型
CString strFilLaye = _T("高程点,水深点,GCD"); // 图元所在图层名称

// 获取对话框数据
this->UpdateData(TRUE);

this->dInterval = _wtof(this->m_strEdit_Interval); // 等高距
this->dMaxSide = _wtof(this->m_strEdit_MaxSide); // 最大边长
this->dIdHeigh = _wtof(this->m_strEdit_IdHeight); // 序号文本高度

#pragma region 图面框选高程点

{
// 隐藏对话框将控制权交给编辑器
BeginEditorCommand();

// 检测图层, 若锁住则打开

rb = acutBuildList(RTDXF0, strObjType, // 图元类型
8, strFilLaye, // 图元所在图层
RTNONE);

// 创建带有过滤器的窗口选取选择集

// 检测选择集中的实体个数
if (this->L >= 3)
{
// 创建选择集的顶点链表
}
else
{

// 如选点不成功，返还到对话框
CompleteEditorCommand(1);

return;
}
}
#pragma endregion

// 根据选择的高程点数量, 确定数组大小并分配内存
this->Side.SetSize(this->L);

double temp_L = 0.0; // 临时循环变量

long a = 0; // 点A
long b = 0; // 点B
long bb = 0; // 临时点B

// 变量初始化
a = 0; // 第一个点
double Bian_a = LIMIT_DISTANCE; // A边长 初始一边为最长

this->Max_line.count = -1;
this->max_N = 0;
this->abc_Max[0];
this->abc_Max[this->max_N].n = -1;

for (b = 0; b <= this->L; b++) // 最短两点,开始搜索的边
{
if (a != b)
{
temp_L = sqrt(pow((this->Cass_xyz.at(a).x - this->Cass_xyz.at(b).x), 2) + pow((this->Cass_xyz.at(a).y - this->Cass_xyz.at(b).y), 2));

if (temp_L < Bian_a)
{
Bian_a = temp_L;
bb = b;
}
}
}

b = bb; // 第二个点

long ab_Count = 0;
AcGePoint3dArray ab;

if (this->Cass_xyz.at(a).z != this->Cass_xyz.at(b).z)
{
// 求最短边内插点的坐标数组和个数
this->abc2(a, b, &ab_Count, &ab);
}

// 检测 "三角网" 图层

//
this->abc(a, b, 0, 0, 0, &ab_Count, &ab);

long t = 0; // 临时变量

ag:
this->max_N = this->max_N + 1;
this->abc_Max[this->max_N].n = -1;

long l_long = 0; // 临时循环变量

for (l_long = this->abc_Max[max_N - 1].n; l_long > 0; l_long--)
{
t = this->Get_Link_On(this->abc_Max[max_N - 1].abc2[l_long].a, this->abc_Max[max_N - 1].abc2[l_long].b);

if (t < 2)
{
this->abc(this->abc_Max[max_N - 1].abc2[l_long].a, this->abc_Max[max_N - 1].abc2[l_long].b, this->abc_Max[max_N - 1].abc2[l_long].OK, this->abc_Max[max_N - 1].abc2[l_long].k, 0, &(this->abc_Max[max_N - 1].abc2[l_long].ab_Count), &(this->abc_Max[max_N - 1].abc2[l_long].ab));
}
}

if (this->abc_Max[this->max_N].n > 0)
{
goto ag;
}

#pragma region 检测是否画等高线

if (this->m_Button_BuildContour.GetCheck() == BST_CHECKED)
{
long T2 = 0; // 临时变量
long L_M = 0; // 等高线数

// 检测 "等高线" 图层

for (t = 0; t <= this->Max_line.count; t++)
{
if (this->Max_line.OfFang[t] > -1)
{
AcGePoint3d conVert;
AcGePoint3dArray conVertArry3d;

L_M = L_M + 1; // 等高线数

for (T2 = this->Max_line.line2[t].count; T2 >= 0; T2--)
{
conVert.x = this->Max_line.line2[t].x[T2];
conVert.y = this->Max_line.line2[t].y[T2];
conVert.z = this->Max_line.h[t];

conVertArry3d.append(conVert);
}

for (T2 = 0; T2 <= this->Max_line.line1[t].count; T2++)
{
conVert.x = this->Max_line.line1[t].x[T2];
conVert.y = this->Max_line.line1[t].y[T2];
conVert.z = this->Max_line.h[t];

conVertArry3d.append(conVert);
}

// 绘制等高线

// 检测是否显示等高线生成过程
if (this->m_Check_ShowCont.GetCheck() == BST_CHECKED)
{
// 刷新显示屏幕
actrTransactionManager->flushGraphics();
acedUpdateDisplay();
}
}
}

// 关闭三角网图层
}
#pragma endregion

// 如选点不成功，返还到对话框
CompleteEditorCommand(1);
}

fuzhishui 2010-07-17

//-----------------------------------------------------------------------------
//----- TriangleNetContourDlg.h : Declaration of the CTriangleNetContourDlg
//-----------------------------------------------------------------------------
#pragma once

//-----------------------------------------------------------------------------
#include "afxwin.h"
#include <afxtempl.h>

//-----------------------------------------------------------------------------
{
DECLARE_DYNAMIC (CTriangleNetContourDlg)

public:
CTriangleNetContourDlg (CWnd *pParent =NULL, HINSTANCE hInstance =NULL) ;

enum { IDD = IDD_TRIANGLENETCONTOUR_DLG} ;

protected:
virtual void DoDataExchange (CDataExchange *pDX) ;
afx_msg LRESULT OnAcadKeepFocus (WPARAM, LPARAM) ;

DECLARE_MESSAGE_MAP()

public:

// 初始化对话框
virtual BOOL OnInitDialog();

// 确定
afx_msg void OnBnClickedButtonOk();

// 取消
afx_msg void OnBnClickedButtonCancel();

///
int Fang(double x, double y, double x1, double y1, double x2, double y2);

///
void abc(long a, long b, long OK, long Old_K, long abc_Num, long *ab_Count, AcGePoint3dArray *ab);

///
void abc2(long a, long b, long *ab_Count, AcGePoint3dArray *ab);

///

///

/// <summary>
/// 将相邻边上高程相同的内插点写入等高线数组
/// </summary>
/// <param name="x1">ab边上同高程内插点 X 坐标</param>
/// <param name="y1">ab边上同高程内插点 Y 坐标</param>
/// <param name="x2">ac边上同高程内插点 X 坐标</param>
/// <param name="y2">ac边上同高程内插点 Y 坐标</param>
/// <param name="h ">两边上内插点同高程 H 坐标</param>
void AddLineMain(double x1, double y1, double x2, double y2, double h);

///
void AddLineMain2(double x, double y, double h, long T_long2, long T2);

/// 第一段正向加一个点
void AddLine1Piont(double x, double y, long t);

/// 第二段反向加一个点
void AddLine2Piont(double x, double y, long t);

///
void AddLine(double x1, double y1, double x2, double y2, double h);

public:
CEdit m_Edit_IdHeight;
CEdit m_Edit_MaxSide;
CEdit m_Edit_Interval;
CEdit m_Edit_ConHeight;
CEdit m_Edit_MaxCon;
CEdit m_Edit_MinCon;

CButton m_Button_BuildTriNet;
CButton m_Button_BuildContour;
CButton m_Button_ShowTriId;
CButton m_Button_ShowProcess;
CButton m_Check_ShowCont;

CString m_strEdit_Interval;
CString m_strEdit_IdHeight;
CString m_strEdit_MaxSide;
CString m_strEdit_MaxCon;
CString m_strEdit_MinCon;

public:
double dMaxSide, dIdHeigh, dInterval;

static const int L_Const = 1000; // 堆栈深度
static const int M_Count_Const = 100; // 初始分配内存
static const int M_Point_Const = 20; // 初始两排点分配内存

AcGePoint3dArray Cass_xyz;

long L; // 点数总数
long k; // 存储三角形编号

// 有关三角形边的变量定义
struct Side_2_Point
{
CArray <long, long> a;
long count;

Side_2_Point()
{
a.SetSize(10000);
count = 0;
}
};

CArray <Side_2_Point, Side_2_Point> Side;

// 有关等高线的变量定义
struct Line
{
CArray <double, double> x;
CArray <double, double> y;
long count;
long M_Count;

Line()
{
x.SetSize(0);
y.SetSize(0);
count = 0;
M_Count = 0;
}
};

struct Line_two
{
CArray <Line, Line> line1;
CArray <Line, Line> line2;
CArray <double, double> h;
CArray <long, long> OfFang;
long count;
long M_Count;

Line_two()
{
line1.SetSize(200);
line2.SetSize(200);
h.SetSize(0);
OfFang.SetSize(0);
count = 0;
M_Count = 0;
}
};

Line_two Max_line;
//CArray <Line_two, Line_two> Max_line;
long count;

struct two_abc
{
long a;
long b;
long OK;
long k;
long ab_Count;
AcGePoint3dArray ab;

two_abc()
{
a = 0;
b = 0;
OK = 0;
k = 0;
ab_Count = 0;
}
};

struct Max_abc
{
long n;
two_abc abc2[10];

Max_abc()
{
n = 0;
}
};

Max_abc abc_Max[10];
//CArray <Max_abc, Max_abc> abc_Max;

long max_N;
} ;

VC/MFC

1.5w+

VC/MFC相关问题讨论