📄 myasmdlg.cpp
字号:
// MyAsmDlg.cpp : implementation file
//
#include "stdafx.h"
#include "AutoASM.h"
#include "MyAsmDlg.h"
#include <uf.h>
#include <uf_exit.h>
#include <uf_ui.h>
#include <uf_mb.h>
#include <uf_assem.h>
#include <uf_part.h>
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// MyAsmDlg dialog
MyAsmDlg::MyAsmDlg(CWnd* pParent /*=NULL*/)
: CDialog(MyAsmDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(MyAsmDlg)
//}}AFX_DATA_INIT
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void MyAsmDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(MyAsmDlg)
DDX_Control(pDX, IDC_TREE1, m_Tree);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(MyAsmDlg, CDialog)
//{{AFX_MSG_MAP(MyAsmDlg)
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BTN_REFRESHTREE, OnBtnRefreshtree)
ON_WM_PAINT()
ON_BN_CLICKED(IDC_LOADASMFROMXML, OnLoadAsmFromXML)
ON_BN_CLICKED(IDC_BTN_ASM, OnBtnAsm)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// MyAsmDlg message handlers
BOOL MyAsmDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
m_asm_ImList.Create(16, 16, TRUE,1, 0);
HICON hIcon = NULL;
hIcon = (HICON)::LoadImage(::AfxGetInstanceHandle(),
MAKEINTRESOURCE(IDI_ICON_ASM), IMAGE_ICON, 16, 16, 0);
m_asm_ImList.Add(hIcon);
hIcon = (HICON)::LoadImage(::AfxGetInstanceHandle(),
MAKEINTRESOURCE(IDI_ICON_PART), IMAGE_ICON, 16, 16, 0);
m_asm_ImList.Add(hIcon);
m_Tree.SetImageList ( &m_asm_ImList,TVSIL_NORMAL );
SetIcon(m_hIcon, TRUE); // Set big icon
//SetIcon(m_hIcon, FALSE); // Set small icon
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void MyAsmDlg::PostNcDestroy()
{
// TODO: Add your specialized code here and/or call the base class
CDialog::PostNcDestroy();
delete this;
}
void MyAsmDlg::OnOK()
{
// TODO: Add extra validation here
CDialog::OnOK();
DestroyWindow();
}
HCURSOR MyAsmDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
//-------------------------------------------------
//刷新树控件,填充
//遍历当前装配空间,获取所有零部件,以树形方式显示。可在任意装配文件中使用
//
//--------------------------------------------------
void MyAsmDlg::OnBtnRefreshtree()
{
m_Tree.DeleteAllItems();
//UF_PART_OPEN()
tag_t displayPart=UF_PART_ask_display_part();
if(displayPart==0) //如果没有打开任何图形,则给出提示后退出//
{
AfxMessageBox("打开装配文件");
return;
}
tag_t root_part_occ=UF_ASSEM_ask_root_part_occ(displayPart);
if(root_part_occ==NULL_TAG) //是装配体的情况//
MessageBox("没有装配体,请打开一装配图");
else
{
AddToTree(root_part_occ,0);
}
UpdateData(FALSE);
}
//-------------------------------------------------
//
//遍历所有节点
//递归
//--------------------------------------------------
void MyAsmDlg::AddToTree(tag_t child_tag,HTREEITEM faItem)
{
tag_t *child_part_occs;
int i,partNum;
char part_name[132+1];
char refset_name[30+1];
char instance_name[50+1];
double origin[3];
double csys_matrix[9];
double transform[4][4];
HTREEITEM NewItem;
UF_ASSEM_ask_component_data(child_tag,part_name,refset_name,instance_name,origin,csys_matrix,transform);
partNum=UF_ASSEM_ask_part_occ_children(child_tag,&child_part_occs);
if(partNum>0)
NewItem = m_Tree.InsertItem(part_name,1,1, faItem);
else
NewItem = m_Tree.InsertItem(part_name,0,0, faItem);
for(i=0;i<partNum;i++)
{
//if(UF_ASSEM_ask_part_occ_children(child_part_occs[i],&sub_pt_occs)>0)
AddToTree(child_part_occs[i],NewItem);
}
UF_free(child_part_occs);
}
void MyAsmDlg::OnPaint()
{
CPaintDC dc(this); // device context for painting
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
// Do not call CDialog::OnPaint() for painting messages
}
void MyAsmDlg::OnLoadAsmFromXML()
{
// TODO: Add your control notification handler code here
m_xml.Load("E:\\UG\\application\\ASM_test.xml", "root", true);
}
void MyAsmDlg::OnBtnAsm()
{
// TODO: Add your control notification handler code here
m_xml.MakeAssembly(m_xml.RootNode->GetfirstChild());
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -