⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tiaoxingunzi.cpp

📁 基于UG平台
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// tiaoxingunzi.cpp : implementation file
//

#include "stdafx.h"
#include "Code.h"
#include "tiaoxingunzi.h"
#include "main.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// Ctiaoxingunzi dialog


Ctiaoxingunzi::Ctiaoxingunzi(CWnd* pParent /*=NULL*/)
	: CDialog(Ctiaoxingunzi::IDD, pParent)
{
	//{{AFX_DATA_INIT(Ctiaoxingunzi)
	m_D = 0.0;
	m_d1 = 0.0;
	m_b = 0.0;
	m_d2 = 0.0;
	m_D2 = 0.0;
	m_r = 0.0;
	//}}AFX_DATA_INIT
}


void Ctiaoxingunzi::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(Ctiaoxingunzi)
	DDX_Control(pDX, IDC_LIST2, m_listctrl2);
	DDX_Control(pDX, IDC_LIST1, m_listctrl1);
	DDX_Control(pDX, IDC_COMBO1, m_list);
	DDX_Text(pDX, IDC_EDIT1, m_D);
	DDX_Text(pDX, IDC_EDIT2, m_d1);
	DDX_Text(pDX, IDC_EDIT3, m_b);
	DDX_Text(pDX, IDC_EDIT4, m_d2);
	DDX_Text(pDX, IDC_EDIT5, m_D2);
	DDX_Text(pDX, IDC_EDIT6, m_r);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(Ctiaoxingunzi, CDialog)
	//{{AFX_MSG_MAP(Ctiaoxingunzi)
	ON_NOTIFY(NM_CLICK, IDC_LIST1, OnClickList1)
	ON_NOTIFY(NM_CLICK, IDC_LIST2, OnClickList2)
	ON_BN_CLICKED(IDOK2, OnHelpBtn)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// Ctiaoxingunzi message handlers

BOOL Ctiaoxingunzi::OnInitDialog() 
{
	CDialog::OnInitDialog();

	m_list.InsertString(0,"调心滚子轴承(圆柱孔)");

	m_list.InsertString(1,"调心滚子轴承(圆锥孔)");
	m_list.SetCurSel(0);

		try{	
		m_ADODatabase.SetConnectionString(_T("Provider=SQLOLEDB.1;Password=00;User ID=david;Initial Catalog=chuandong;Data Source=acer"));
		m_ADODatabase.Open();
		BOOL b = m_ADODatabase.IsOpen(); 
	    this->m_ADORecordset.Open(this->m_ADODatabase.GetActiveConnection(), _T("select * from ZGB_d where [Z_tiaoxin] like 'Z_tiaoxin'"));

		CString d1;
	    int i=0;
		m_listctrl1.InsertColumn(0,_T("d"),LVCFMT_LEFT,50);
		m_listctrl2.InsertColumn(0,_T("型号"),LVCFMT_LEFT,50);
		m_listctrl2.InsertColumn(1,_T("dd"),LVCFMT_LEFT,50);
	    m_listctrl2.InsertColumn(2,_T("D"),LVCFMT_LEFT,50);       	
        m_listctrl2.InsertColumn(3,_T("B"),LVCFMT_LEFT,50);
	    m_listctrl2.InsertColumn(4,_T("d2"),LVCFMT_LEFT,50);
	    m_listctrl2.InsertColumn(5,_T("D2"),LVCFMT_LEFT,50);
	    m_listctrl2.InsertColumn(6,_T("r"),LVCFMT_LEFT,50);		
        
	    
		while(!this->m_ADORecordset.IsEof())
		{
			this->m_ADORecordset.GetFieldValue("d", d1);	
      		m_listctrl1.InsertItem(i,d1);
			this->m_ADORecordset.MoveNext();
			i=i+1;
		}
   }
	catch (_com_error e)
		{
		AfxMessageBox(CString(e.ErrorMessage()));
		}
  		UpdateData(false);	
    
	
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

double Ctiaoxingunzi::strtodouble(CString pp1)
	{
		double xpp;
		char   *pszTemp=pp1.GetBuffer(0);
		int   nLength   =   strlen(pszTemp);  
		char   *xp   =   new   char[nLength   +   1]; 
		strcpy(xp,   pszTemp);  
		xp[nLength]   =   '\0';
		xpp=atof(xp);
		return xpp;
	}


void Ctiaoxingunzi::OnClickList1(NMHDR* pNMHDR, LRESULT* pResult) 
{
	CString D,daihao,dd1,D1,B1,dd21,D21,r1,dda1,Da1,ra1,Cr1,C0r1,Dw1,Z1,d,b;
    int j=0,k;
	int  nItemCount=m_listctrl2.GetItemCount();
	for(k=nItemCount-1;k>=0;k--)
	{
        m_listctrl2.DeleteItem(k);  
	}
    	int list=m_list.GetCurSel();
	for(int i=0;i<m_listctrl1.GetItemCount();i++)
	{
		if(m_listctrl1.GetItemState(i,LVIS_SELECTED)==LVIS_SELECTED)
		{
            D=m_listctrl1.GetItemText(i,0);	
	        if(list==0) 
		   {
		    this->m_ADORecordset.Open(this->m_ADODatabase.GetActiveConnection(), _T("select * from Z_tiaoxingunzi where dd like '"+D+"'and [zhukong] is not NULL"));
            while(!this->m_ADORecordset.IsEof()) 
			{
               	this->m_ADORecordset.GetFieldValue("zhukong", daihao);	
				
				this->m_ADORecordset.GetFieldValue("dd", dd1);	
				this->m_ADORecordset.GetFieldValue("D", D1);	
				this->m_ADORecordset.GetFieldValue("B", B1);	
				this->m_ADORecordset.GetFieldValue("dd2", dd21);	
				this->m_ADORecordset.GetFieldValue("D2", D21);	
				this->m_ADORecordset.GetFieldValue("r", r1);	
	
						
             	m_listctrl2.InsertItem(j,daihao);
			    m_listctrl2.SetItemText(j,2,D1);
				m_listctrl2.SetItemText(j,3,B1);
			    m_listctrl2.SetItemText(j,4,dd21);	
				m_listctrl2.SetItemText(j,5,D21);
		    	m_listctrl2.SetItemText(j,6,r1);
		        m_listctrl2.SetItemText(j,1,dd1);

		    	this->m_ADORecordset.MoveNext();
				j=j+1;
			} 
		   }
		  if(list==1) 
		   {
		    this->m_ADORecordset.Open(this->m_ADODatabase.GetActiveConnection(), _T("select * from Z_tiaoxingunzi where dd like '"+D+"'and [zhuikong] is not NULL"));
            while(!this->m_ADORecordset.IsEof()) 
			{
               	this->m_ADORecordset.GetFieldValue("zhuikong", daihao);	
				
				this->m_ADORecordset.GetFieldValue("dd", dd1);	
				this->m_ADORecordset.GetFieldValue("D", D1);	
				this->m_ADORecordset.GetFieldValue("B", B1);	
				this->m_ADORecordset.GetFieldValue("dd2", dd21);	
				this->m_ADORecordset.GetFieldValue("D2", D21);	
				this->m_ADORecordset.GetFieldValue("r", r1);	
	
					
             	m_listctrl2.InsertItem(j,daihao);
			    m_listctrl2.SetItemText(j,2,D1);
				m_listctrl2.SetItemText(j,3,B1);
			    m_listctrl2.SetItemText(j,4,dd21);	
				m_listctrl2.SetItemText(j,5,D21);
		    	m_listctrl2.SetItemText(j,6,r1);
		        m_listctrl2.SetItemText(j,1,dd1);

		    	this->m_ADORecordset.MoveNext();
				j=j+1;
			} 
		   }
		  	}
	}

  	 UpdateData(false);

	
	*pResult = 0;
}

void Ctiaoxingunzi::OnClickList2(NMHDR* pNMHDR, LRESULT* pResult) 
{
	 m_listctrl2.SetExtendedStyle(LVS_EX_FULLROWSELECT); 
  for(int m=0;m<m_listctrl2.GetItemCount();m++)
  {
    if(m_listctrl2.GetItemState(m,LVIS_SELECTED)==LVIS_SELECTED)
	{
      m_D=strtodouble(m_listctrl2.GetItemText(m,2));
	  m_d1=strtodouble(m_listctrl2.GetItemText(m,1));
	  m_b=strtodouble(m_listctrl2.GetItemText(m,3));
	  m_d2=strtodouble(m_listctrl2.GetItemText(m,4));
	  m_D2=strtodouble(m_listctrl2.GetItemText(m,5));
	  m_r=strtodouble(m_listctrl2.GetItemText(m,6));
	 
	}
  }	
    UpdateData(false);	
	
	*pResult = 0;
}

void Ctiaoxingunzi::OnOK() 
{
	
	CDialog::OnOK();
	int err=UF_initialize();
	int nlist=m_list.GetCurSel();
	double m_d=m_d1,m_dd=m_D,m_i=12,r;
	double rd=2*3.1415926/m_i;
    double aa,a1,dd;
	aa=(m_dd-m_d)/2;
	r=m_dd/2-aa/4;
	dd=asin((m_b/6)/r);
	a1=atan((m_b/3)/(m_dd/2));
	double l;
	 l=(m_b/2)/tan(a1);
	if(err==0&&nlist==0)
	{

	UF_CURVE_line_t dline1,dline2,dline3;
     tag_t line1,line3,line4;
	 
	
	 dline1.start_point[0]=-m_b/2;
	 dline1.start_point[1]=m_dd/2;
	 dline1.start_point[2]=0.0;
	 dline1.end_point[0]=m_b/2;
	 dline1.end_point[1]=m_dd/2;
	 dline1.end_point[2]=0.0;
	 UF_CALL(UF_CURVE_create_line(&dline1,&line1));

	 int object;
	 tag_t *sum,*sum1;
	 UF_MODL_SWEEP_TRIM_object_p_t trim_date=NULL;
	 char *limit[2]={"0.0","360.0"};
	 char *offset[2]={"0.0","0.0"};
	 double region[3]={0.0,0.0,0.0};
	 double axis_point[3]={0.0,0.0,0.0};
	 double direction[3]={1.0,0.0,0.0};
	 UF_FEATURE_SIGN sign=UF_NULLSIGN;
	 UF_CALL(UF_MODL_create_revolution(&line1,1,trim_date,limit,offset,
		 region,false,true,axis_point,direction,sign,&sum1,&object));

	 int flag=1;
	 double first[3]={-m_b/2,sqrt(r*r-m_b*m_b/4),0.0};
	 double second[3]={0.0,r,0.0};
	 double third[3]={m_b/2,sqrt(r*r-m_b*m_b/4),0.0};
	 tag_t arc, arc1,arc2;
  
	 UF_CALL(UF_CURVE_create_arc_thru_3pts(flag,first,second,third,&arc));
     UF_FEATURE_SIGN sign1=UF_NEGATIVE;
     UF_CALL(UF_MODL_create_revolution(&arc,1,trim_date,limit,offset,
		 region,false,true,axis_point,direction,sign1,&sum1,&object));
   
	 double first1[3]={-m_b/2,m_d/2+aa/4,0.0};
	 double second1[3]={sin(a1)*r-m_b/2,l-cos(a1)*r,0.0};
	 double third1[3]={sin(a1+dd)*r-m_b/2,l-cos(a1+dd)*r,0.0};
     UF_CALL(UF_CURVE_create_arc_thru_3pts(flag,first1,second1,third1,&arc1));
	 double first3[3]={m_b/2,m_d/2+aa/4,0.0};
	 double second3[3]={-sin(a1)*r+m_b/2,l-cos(a1)*r,0.0};
	 double third3[3]={-sin(a1+dd)*r+m_b/2,l-cos(a1+dd)*r,0.0};
     UF_CALL(UF_CURVE_create_arc_thru_3pts(flag,first3,second3,third3,&arc2));
	 dline3.start_point[0]=sin(a1+dd)*r-m_b/2;
	 dline3.start_point[1]=l-cos(a1+dd)*r;
	 dline3.start_point[2]=0.0;
	 dline3.end_point[0]=m_b/2-sin(a1+dd)*r;
	 dline3.end_point[1]=l-cos(a1+dd)*r;
	 dline3.end_point[2]=0.0;
	 UF_CALL(UF_CURVE_create_line(&dline3,&line4));
	 tag_t add[3];
	 add[0]=arc1;
	 add[1]=line4;
	 add[2]=arc2;

     UF_CALL(UF_MODL_create_revolution(add,3,trim_date,limit,offset,
		 region,false,true,axis_point,direction,sign,&sum,&object));
	 
	 dline2.start_point[0]=-m_b/2;
	 dline2.start_point[1]=m_d/2;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -