📄 vc_temp.cpp
字号:
#include <math.h>
#include <stdlib.h>
#include "stdafx.h"
#include "Vc_Temp.h"
#include <afx.h>
//----------
#include "msxml.h"
#include <atlbase.h>
#import "msxml.dll" named_guids
//----------
#include "stdafx.h"
#include <iostream>
using namespace std;
#include <msxml.h>
//----------
#include <stdio.h>
#include <string.h>
#include <uf.h>
#include <uf_ui.h>
#include <uf_modl.h>
#include <uf_assem.h>
#include <uf_object_types.h>
#include <uf_defs.h>
#include <uf_obj.h>
#include <uf_part.h>
#include <uf_cfi.h>
#include <uf_exit.h>
#include <uf_curve.h>
#include <uf_csys.h>
#include <uf_mtx.h>
//----------
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
BEGIN_MESSAGE_MAP(CVc_TempApp, CWinApp)
END_MESSAGE_MAP()
CVc_TempApp::CVc_TempApp()
{
}
CVc_TempApp theApp;//MFC全局变量
FILE* xml=fopen("d:\\save.xml","w");//为了写入同一个xml文件,全局变量
//************************************************创建一条直线的函数
tag_t create_line(double start_x,double start_y,double start_z,double end_x,double end_y,double end_z)
{
UF_CURVE_line_t line_coords;
UF_CURVE_line_p_t p_line_coords=&line_coords;
line_coords.start_point[0]=start_x;
line_coords.start_point[1]=start_y;
line_coords.start_point[2]=start_z;
line_coords.end_point[0]=end_x;
line_coords.end_point[1]=end_y;
line_coords.end_point[2]=end_z;
tag_t line_tag=NULL_TAG;
UF_CURVE_create_line(p_line_coords,&line_tag);
return(line_tag);
}
//************************************************创建一个拉伸特征的函数
uf_list_p_t create_extruded(uf_list_p_t obj_tag_list,char* len_p,char* len_n)
{
char* taper_angle="0.0";//沿轴倾斜的角度
char* limit[2]={len_p,len_n};//拉伸的幅度
double point[3]={0,0,0};//不再使用的参数
double direction[3]={0.0,0.0,1.0};//拉伸的方向向量
UF_FEATURE_SIGN sign=UF_NULLSIGN;
uf_list_t feature_list[1];
feature_list[0].eid=NULL_TAG;
feature_list[0].next=NULL;
uf_list_p_t p_feature_list=feature_list;
int error=UF_MODL_create_extruded(obj_tag_list,taper_angle,limit,point,direction,sign,&p_feature_list);
FILE* fp=fopen("d:\\extruded_test_error.txt","w");
fprintf(fp,"%d",error);
fclose(fp);
return(p_feature_list);
}
//************************************************创建一个固定数据平面特征的函数
tag_t create_fixed_data_plane(double center_point_x,double center_point_y,double center_point_z,
double direction_x,double direction_y,double direction_z)
{
double center_point[3]={center_point_x,center_point_y,center_point_z};
double direction[3]={direction_x,direction_y,direction_z};
tag_t plane_tag=NULL_TAG;
int plane_test_error=UF_MODL_create_fixed_dplane(center_point,direction,&plane_tag);
FILE* fp=fopen("d:\\plane_test_error.txt","w");
fprintf(fp,"%d\n%d",plane_test_error,plane_tag);
fclose(fp);
//----------
fprintf(xml,"<user>\n");
fprintf(xml,"<type>fixed_data_plane</type>\n");
fprintf(xml,"<center_point_x>%f</center_point_x>\n",center_point_x);
fprintf(xml,"<center_point_y>%f</center_point_y>\n",center_point_y);
fprintf(xml,"<center_point_z>%f</center_point_z>\n",center_point_z);
fprintf(xml,"<direction_x>%f</direction_x>\n",direction_x);
fprintf(xml,"<direction_y>%f</direction_y>\n",direction_y);
fprintf(xml,"<direction_z>%f</direction_z>\n",direction_z);
fprintf(xml,"</user>\n");
//----------
return(plane_tag);
}
//************************************************创建一个长方体特征的函数
tag_t create_block(double original_point_x,double original_point_y,double original_point_z,
char* length_x,char* length_y,char* length_z)
{
UF_FEATURE_SIGN sign = UF_NULLSIGN;
tag_t target_tag=NULL_TAG;
double original_point[3]={original_point_x,original_point_y,original_point_z};
char* length[3]={length_x,length_y,length_z};
tag_t blk_obj;
int test_error=UF_MODL_create_block(sign,target_tag,original_point,length,&blk_obj);
FILE* fp=fopen("d:\\block_test_error.txt","w");
fprintf(fp,"%d",test_error);
fclose(fp);
//----------
fprintf(xml,"<user>\n");
fprintf(xml,"<type>block</type>\n");
fprintf(xml,"<original_point_x>%f</original_point_x>\n",original_point_x);
fprintf(xml,"<original_point_y>%f</original_point_y>\n",original_point_y);
fprintf(xml,"<original_point_z>%f</original_point_z>\n",original_point_z);
fprintf(xml,"<length_x>%s</length_x>\n",length_x);
fprintf(xml,"<length_y>%s</length_y>\n",length_y);
fprintf(xml,"<length_z>%s</length_z>\n",length_z);
fprintf(xml,"</user>\n");
//----------
return(blk_obj);
}
//************************************************创建一个打孔特征的函数
tag_t create_simple_hole(tag_t plane_up,tag_t plane_down,tag_t block_tag)
{
double center[3]={75,75,0}; //孔的中心点位置
double direction[3]={0,0,1};//孔的方向向量
char* diameter="10";//孔的直径
char* depth="50";//孔的深度
char* angle="0";//孔的尖端的角度
//----------
tag_t face_li=plane_up;
tag_t face_t1=plane_down;
tag_t feature_obj_id=NULL_TAG;
//----------
int error=UF_MODL_create_simple_hole(center,direction,diameter,depth,angle,
plane_up,plane_down,
&feature_obj_id);
FILE* fp=fopen("d:\\create_simple_hole_test_error.txt","w");
fprintf(fp,"%d",error);
fclose(fp);
//----------
fprintf(xml,"<user>\n");
fprintf(xml,"<type>simple_hole</type>\n");
fprintf(xml,"<hole_center_x>%f</hole_center_x>\n",center[0]);
fprintf(xml,"<hole_center_y>%f</hole_center_y>\n",center[1]);
fprintf(xml,"<hole_center_z>%f</hole_center_z>\n",center[2]);
fprintf(xml,"<direction_x>%f</direction_x>\n",direction[0]);
fprintf(xml,"<direction_y>%f</direction_y>\n",direction[1]);
fprintf(xml,"<direction_z>%f</direction_z>\n",direction[2]);
fprintf(xml,"<diameter>%s</diameter>\n",diameter);
fprintf(xml,"<depth>%s</depth>\n",depth);
fprintf(xml,"<top_angle>%s</top_angle>\n",angle);
fprintf(xml,"</user>\n");
//----------
return(feature_obj_id);
}
//■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
extern DllExport void ufusr(char* parm,int* returnCode,int rlen)
{
int errorCode=UF_initialize();
if(errorCode==0)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
MessageBox(NULL,_T("欢迎使用MFC!"),_T("欢迎使用MFC!"),
MB_OKCANCEL|MB_ICONINFORMATION);
uf_list_p_t list=NULL;
UF_MODL_create_list(&list);
double start_x=0,
start_y=0,
start_z=0,
end_x=0,
end_y=0,
end_z=0;
char* ch1="";
char* ch2="";
LPCTSTR lpszDefExt="xml|zip";
LPCTSTR lpszFileName="user.xml";
DWORD dwFlags=OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT;
LPCTSTR lpszFilter="XML文件(*.xml)|*.xml|压缩文件(*.zip;*.rar)|*.zip;*.rar|文本文件(*.txt)|*.txt|所有文件(*.*)|*.*||";
CWnd* pParentWnd=NULL;
CFileDialog dlg(true,lpszDefExt,lpszFileName,dwFlags,lpszFilter,pParentWnd);
CString FilePathName;
if(dlg.DoModal()==IDOK)
{
FilePathName=dlg.GetPathName();
CComBSTR t(FilePathName);
VARIANT vr;
vr.vt=VT_BSTR;
vr.bstrVal=t.Copy();
CoInitialize(NULL);//初始化XML环境
MSXML::IXMLDOMDocumentPtr xmlDoc;
HRESULT hr=xmlDoc.CreateInstance(__uuidof(MSXML::DOMDocument));
if(hr==S_OK)
{
AfxMessageBox("创建实例成功!");
}
hr=xmlDoc->load(vr);
if(hr!=S_OK)
{
AfxMessageBox("读取*.xml文件失败!");
}
MSXML::IXMLDOMNodeListPtr xmlNodeList=xmlDoc->selectNodes("//user");
//获得所有user节点
FILE* fp=fopen("d:\\user.txt","w");
fprintf(fp,"共有%d个user节点\n%d\n%d\n%d\n%d\n",
xmlNodeList->length,hr,S_OK,S_FALSE,E_INVALIDARG);
MSXML::IXMLDOMNodePtr xmlNode=NULL;
MSXML::IXMLDOMNodePtr xmlChildNode=NULL;
MSXML::IXMLDOMNodeListPtr xmlChildNodeList=NULL;
CComBSTR value=NULL;
CComBSTR name=NULL;
CStdioFile xmlInfo;
CString temp,temp1,temp2;
xmlInfo.Open("D:\\test.txt",CFile::modeWrite|CFile::modeWrite|CFile::modeCreate);
for(int i=1;i<xmlNodeList->length;i++)
{
xmlNodeList->get_item(i,&xmlNode);//获得某一个user节点
xmlNode->get_childNodes(&xmlChildNodeList);//获得某一个user节点的所有子节点
for(int j=0;j<xmlChildNodeList->length;j++)
{
xmlChildNodeList->get_item(j,&xmlChildNode);//获得该user节点某一个子节点
xmlChildNode->get_nodeName(&name);//获得该子节点的名称
if(name=="startx")
{
hr=xmlChildNode->get_text(&value);
temp=value;
start_x=atof(temp);
fprintf(fp,"start_x等于%f\n",start_x);
value=SysAllocString(value);
xmlInfo.Write(_T(value),22);
xmlInfo.Write(_T("\r\n"),2);
}
if(name=="starty")
{
hr=xmlChildNode->get_text(&value);
temp=value;
start_y=atof(temp);
fprintf(fp,"start_y等于%f\n",start_y);
value=SysAllocString(value);
xmlInfo.Write(_T(value),22);
xmlInfo.Write(_T("\r\n"),2);
}
if(name=="startz")
{
hr=xmlChildNode->get_text(&value);
temp=value;
start_z=atof(temp);
fprintf(fp,"start_z等于%f\n",start_z);
value=SysAllocString(value);
xmlInfo.Write(_T(value),22);
xmlInfo.Write(_T("\r\n"),2);
}
if(name=="endx")
{
hr=xmlChildNode->get_text(&value);
temp=value;
end_x=atof(temp);
fprintf(fp,"endx等于%f\n",end_x);
value=SysAllocString(value);
xmlInfo.Write(_T(value),22);
xmlInfo.Write(_T("\r\n"),2);
}
if(name=="endy")
{
hr=xmlChildNode->get_text(&value);
temp=value;
end_y=atof(temp);
fprintf(fp,"start_x等于%f\n",end_y);
value=SysAllocString(value);
xmlInfo.Write(_T(value),22);
xmlInfo.Write(_T("\r\n"),2);
}
if(name=="endz")
{
hr=xmlChildNode->get_text(&value);
temp=value;
end_z=atof(temp);
fprintf(fp,"endz等于%f\n",end_z);
value=SysAllocString(value);
xmlInfo.Write(_T(value),22);
xmlInfo.Write(_T("\r\n"),2);
UF_MODL_put_list_item(list,
create_line(start_x,start_y,start_z,end_x,end_y,end_z));
fprintf(fp,"创建直线的2点坐标是(%f,%f,%f)和(%f,%f,%f)\n",
start_x,start_y,start_z,end_x,end_y,end_z);
}
if(name=="depth")
{
hr=xmlChildNode->get_text(&value);
temp1=value;
ch1=(LPSTR)(LPCTSTR)temp1;
temp2="-"+temp1;
ch2=(LPSTR)(LPCTSTR)temp2;
create_extruded(list,ch2,ch1);
}
}//end "for(int j=0;j<xmlChildNodeList->length;j++)"
fprintf(fp,"xmlChildNodeList->length等于%d\n",xmlChildNodeList->length);
}
fclose(fp);
xmlInfo.Close();
}//end "if(dlg.DoModal()==IDOK)"
/*fprintf(xml,"<root>\n");
create_simple_hole(create_fixed_data_plane(25,25,0,0,0,1),
create_fixed_data_plane(25,25,50,0,0,1),
create_block(50,50,0,"50","50","50"));
fprintf(xml,"</root>");
fclose(xml);
*/
errorCode=UF_terminate();
}
}
int ufusr_ask_unload(void)
{
return (UF_UNLOAD_IMMEDIATELY);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -