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

📄 tiaoxinqiu.cpp

📁 基于UG平台
💻 CPP
字号:
// tiaoxinqiu.cpp : implementation file
//

#include "stdafx.h"
#include "Code.h"
#include "tiaoxinqiu.h"
#include"main.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// Ctiaoxinqiu dialog


Ctiaoxinqiu::Ctiaoxinqiu(CWnd* pParent /*=NULL*/)
	: CDialog(Ctiaoxinqiu::IDD, pParent)
{
	//{{AFX_DATA_INIT(Ctiaoxinqiu)
	m_TCXT = FALSE;
	m_D = 0.0;
	m_B = 0.0;
	m_d2 = 0.0;
	m_D2 = 0.0;
	m_r = 0.0;
	m_d = 0.0;
	//}}AFX_DATA_INIT
}


void Ctiaoxinqiu::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(Ctiaoxinqiu)
	DDX_Control(pDX, IDC_COMBO1, m_list);
	DDX_Control(pDX, IDC_LIST2, m_listctrl2);
	DDX_Control(pDX, IDC_LIST1, m_listctrl1);
	DDX_Check(pDX, IDC_CHECK1, m_TCXT);
	DDX_Text(pDX, IDC_EDIT1, m_D);
	DDX_Text(pDX, IDC_EDIT2, m_B);
	DDX_Text(pDX, IDC_EDIT3, m_d2);
	DDX_Text(pDX, IDC_EDIT4, m_D2);
	DDX_Text(pDX, IDC_EDIT5, m_r);
	DDX_Text(pDX, IDC_EDIT6, m_d);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(Ctiaoxinqiu, CDialog)
	//{{AFX_MSG_MAP(Ctiaoxinqiu)
	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()

/////////////////////////////////////////////////////////////////////////////
// Ctiaoxinqiu message handlers
BOOL Ctiaoxinqiu::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
    m_list.InsertString(0,"调心球轴承");
	m_list.InsertString(1,"调心球轴承10000k");
	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_10000K] like 'Z_10000K'"));

		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("D"),LVCFMT_LEFT,50);
        m_listctrl2.InsertColumn(2,_T("B"),LVCFMT_LEFT,50);
	    m_listctrl2.InsertColumn(3,_T("d2"),LVCFMT_LEFT,50);
	    m_listctrl2.InsertColumn(4,_T("D2"),LVCFMT_LEFT,50);
	    m_listctrl2.InsertColumn(5,_T("r"),LVCFMT_LEFT,50);
	    m_listctrl2.InsertColumn(6,_T("Cr"),LVCFMT_LEFT,50);
	    m_listctrl2.InsertColumn(7,_T("Da"),LVCFMT_LEFT,50);
        m_listctrl2.InsertColumn(8,_T("ra"),LVCFMT_LEFT,50);
        m_listctrl2.InsertColumn(9,_T("Cr"),LVCFMT_LEFT,50);
        m_listctrl2.InsertColumn(10,_T("Cor"),LVCFMT_LEFT,50);
	    m_listctrl2.InsertColumn(11,_T("Dw"),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
 
	
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

double Ctiaoxinqiu::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 Ctiaoxinqiu::OnClickList1(NMHDR* pNMHDR, LRESULT* pResult) 
{
		CString D,daihao,dd1,D1,B1,dd21,D21,r1,dda1,Da1,ra1,Cr1,C0r1,Dw1,Z1;
    int j=0,k;
	int  nItemCount=m_listctrl2.GetItemCount();
	for(k=nItemCount-1;k>=0;k--)
	{
        m_listctrl2.DeleteItem(k);  
	}

	for(int i=0;i<m_listctrl1.GetItemCount();i++)
	{
		if(m_listctrl1.GetItemState(i,LVIS_SELECTED)==LVIS_SELECTED)
		{
            D=m_listctrl1.GetItemText(i,0);	
			m_d=strtodouble(D);
		    this->m_ADORecordset.Open(this->m_ADODatabase.GetActiveConnection(), _T("select * from Z_10000K where dd like '"+D+"'"));
            while(!this->m_ADORecordset.IsEof())
			{
               	this->m_ADORecordset.GetFieldValue("ID_10000K", 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);	
				this->m_ADORecordset.GetFieldValue("dda", dda1);	
				this->m_ADORecordset.GetFieldValue("Da", Da1);	
		    	this->m_ADORecordset.GetFieldValue("ra", ra1);	
		
				
               	m_listctrl2.InsertItem(j,daihao);
			    m_listctrl2.SetItemText(j,1,D1);
				m_listctrl2.SetItemText(j,2,B1);
			    m_listctrl2.SetItemText(j,3,dd21);
		     	m_listctrl2.SetItemText(j,4,D21);
		    	m_listctrl2.SetItemText(j,5,r1);
		    	m_listctrl2.SetItemText(j,6,dda1);
		    	m_listctrl2.SetItemText(j,7,Da1);
		    	m_listctrl2.SetItemText(j,8,ra1);
		
		    	this->m_ADORecordset.MoveNext();
				j=j+1;
			}       
		}
	}
	 UpdateData(false);
	
	*pResult = 0;
}

void Ctiaoxinqiu::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,1));
	  m_B=strtodouble(m_listctrl2.GetItemText(m,2));
      m_d2=strtodouble(m_listctrl2.GetItemText(m,3));
	  m_D2=strtodouble(m_listctrl2.GetItemText(m,4));
	  m_r=strtodouble(m_listctrl2.GetItemText(m,5));
	}
  }	
    UpdateData(false);	
	
	*pResult = 0;
	

}
void Ctiaoxinqiu::OnOK() 
{
	UpdateData(true);	
	double m_b=m_B,m_dd=m_D;
 	int m_i=12;
	int col=m_list.GetCurSel();
	if(col==0)
	{

	int i;
    double a,r,r1;
	a=(m_dd-m_d)/2;
	r1=sqrt((a/6)*(a/6)+(m_d/2+a/2)*(m_d/2+a/2))+a/6;
    r=sqrt(r1*r1-(m_b/2)*(m_b/2));

	UF_CURVE_line_t sn1,sn2,sn3,sn4,sn5,sn6,sn7;
	tag_t line[4],bn1,bn2,bn3,bn4,bn5,bn6,bn7,line1[4];

	sn1.start_point[0]=m_b/2;
	sn1.start_point[1]=m_d/2;
	sn1.start_point[2]=0.0;
	sn1.end_point[0]=m_b/2;
	sn1.end_point[1]=m_d/2+a/3;
	sn1.end_point[2]=0.0;
	UF_CALL(UF_CURVE_create_line(&sn1,&bn1));

	sn2.start_point[0]=m_b/2;
	sn2.start_point[1]=m_d/2+a/3;
	sn2.start_point[2]=0.0;
	sn2.end_point[0]=-m_b/2;
	sn2.end_point[1]=m_d/2+a/3;
	sn2.end_point[2]=0.0;
	UF_CALL(UF_CURVE_create_line(&sn2,&bn2));

	sn3.start_point[0]=-m_b/2;
	sn3.start_point[1]=m_d/2+a/3;
	sn3.start_point[2]=0.0;
	sn3.end_point[0]=-m_b/2;
	sn3.end_point[1]=m_d/2;
	sn3.end_point[2]=0.0;
	UF_CALL(UF_CURVE_create_line(&sn3,&bn3));

	sn4.start_point[0]=-m_b/2;
	sn4.start_point[1]=m_d/2;
	sn4.start_point[2]=0.0;
	sn4.end_point[0]=m_b/2;
	sn4.end_point[1]=m_d/2;
	sn4.end_point[2]=0.0;
	UF_CALL(UF_CURVE_create_line(&sn4,&bn4));

	sn5.start_point[0]=m_b/2;
	sn5.start_point[1]=r;
	sn5.start_point[2]=0.0;
	sn5.end_point[0]=m_b/2;
	sn5.end_point[1]=m_dd/2;
	sn5.end_point[2]=0.0;
	UF_CALL(UF_CURVE_create_line(&sn5,&bn5));

	sn6.start_point[0]=m_b/2;
	sn6.start_point[1]=m_dd/2;
	sn6.start_point[2]=0.0;
	sn6.end_point[0]=-m_b/2;
	sn6.end_point[1]=m_dd/2;
	sn6.end_point[2]=0.0;
	UF_CALL(UF_CURVE_create_line(&sn6,&bn6));

	sn7.start_point[0]=-m_b/2;
	sn7.start_point[1]=m_dd/2;
	sn7.start_point[2]=0.0;
	sn7.end_point[0]=-m_b/2;
	sn7.end_point[1]=r;
	sn7.end_point[2]=0.0;
	UF_CALL(UF_CURVE_create_line(&sn7,&bn7));

	int flag=1;
	double first[3]={-m_b/2,r,0.0};
	double second[3]={0.0,r1,0.0};
    double third[3]={m_b/2,r,0.0};
	tag_t arc;
	UF_CURVE_create_arc_thru_3pts(flag,first,second,third,&arc);

	line[0]=bn1;
	line[1]=bn2;
	line[2]=bn3;
	line[3]=bn4;
	line1[0]=bn5;
	line1[1]=bn6;
	line1[2]=bn7;
    line1[3]=arc;

	UF_MODL_SWEEP_TRIM_object_p_t date=NULL;
	char *limit[2]={"0.0","360.0"};
	char *offset[2]={"0.0","0.0"};
	double origin[3]={0.0,0.0,0.0};
	double direction[3]={1.0,0.0,0.0};
	UF_FEATURE_SIGN mode_sign=UF_NULLSIGN;
	int number;
	tag_t *sum;
	UF_MODL_create_revolution(line,4,date,limit,offset,origin,false,true,origin,
		direction,
		mode_sign,&sum,&number);
	UF_MODL_create_revolution(line1,4,date,limit,offset,origin,false,true,origin,
		direction,mode_sign,&sum,&number);

    
	double angle=2*3.1415/m_i;
	double yy,zz;
	char buffer[14];
	_gcvt(a/3,10,buffer);
	
	for(i=0;i<=m_i;i++)
	{
	yy=cos(i*angle)*(m_d/2+a/2);
	zz=sin(i*angle)*(m_d/2+a/2);

	double center[3]={a/6,yy,zz};
	double center1[3]={-a/6,yy,zz};
	
	tag_t id;
	UF_MODL_create_sphere1(mode_sign,center,buffer,&id);
    UF_MODL_create_sphere1(mode_sign,center1,buffer,&id);

	UF_OBJ_set_blank_status(bn1,UF_OBJ_BLANKED);	
	UF_OBJ_set_blank_status(bn2,UF_OBJ_BLANKED);	
	UF_OBJ_set_blank_status(bn3,UF_OBJ_BLANKED);	
	UF_OBJ_set_blank_status(bn4,UF_OBJ_BLANKED);	
	UF_OBJ_set_blank_status(bn5,UF_OBJ_BLANKED);	
	UF_OBJ_set_blank_status(bn6,UF_OBJ_BLANKED);	
	UF_OBJ_set_blank_status(bn7,UF_OBJ_BLANKED);	
	UF_OBJ_set_blank_status(arc,UF_OBJ_BLANKED);
	}
	}

	if(col==1)
	{

	int i;
    double a,r,r1;
	a=(m_dd-m_d)/2;
	r1=sqrt((a/6)*(a/6)+(m_d/2+a/2)*(m_d/2+a/2))+a/6;
    r=sqrt(r1*r1-(m_b/2)*(m_b/2));

	UF_CURVE_line_t sn1,sn2,sn3,sn4,sn5,sn6,sn7;
	tag_t line[4],bn1,bn2,bn3,bn4,bn5,bn6,bn7,line1[4];

	sn1.start_point[0]=m_b/2;
	sn1.start_point[1]=m_d/2;
	sn1.start_point[2]=0.0;
	sn1.end_point[0]=m_b/2;
	sn1.end_point[1]=m_d/2+a/3;
	sn1.end_point[2]=0.0;
	UF_CALL(UF_CURVE_create_line(&sn1,&bn1));

	sn2.start_point[0]=m_b/2;
	sn2.start_point[1]=m_d/2+a/3;
	sn2.start_point[2]=0.0;
	sn2.end_point[0]=-m_b/2;
	sn2.end_point[1]=m_d/2+a/3;
	sn2.end_point[2]=0.0;
	UF_CALL(UF_CURVE_create_line(&sn2,&bn2));

	sn3.start_point[0]=-m_b/2;
	sn3.start_point[1]=m_d/2+a/3;
	sn3.start_point[2]=0.0;
	sn3.end_point[0]=-m_b/2;
	sn3.end_point[1]=m_d/2;
	sn3.end_point[2]=0.0;
	UF_CALL(UF_CURVE_create_line(&sn3,&bn3));

	sn4.start_point[0]=-m_b/2;
	sn4.start_point[1]=m_d/2;
	sn4.start_point[2]=0.0;
	sn4.end_point[0]=m_b/2;
	sn4.end_point[1]=m_d/2;
	sn4.end_point[2]=0.0;
	UF_CALL(UF_CURVE_create_line(&sn4,&bn4));

	sn5.start_point[0]=m_b/2;
	sn5.start_point[1]=r;
	sn5.start_point[2]=0.0;
	sn5.end_point[0]=m_b/2;
	sn5.end_point[1]=m_dd/2;
	sn5.end_point[2]=0.0;
	UF_CALL(UF_CURVE_create_line(&sn5,&bn5));

	sn6.start_point[0]=m_b/2;
	sn6.start_point[1]=m_dd/2;
	sn6.start_point[2]=0.0;
	sn6.end_point[0]=-m_b/2;
	sn6.end_point[1]=m_dd/2;
	sn6.end_point[2]=0.0;
	UF_CALL(UF_CURVE_create_line(&sn6,&bn6));

	sn7.start_point[0]=-m_b/2;
	sn7.start_point[1]=m_dd/2;
	sn7.start_point[2]=0.0;
	sn7.end_point[0]=-m_b/2;
	sn7.end_point[1]=r;
	sn7.end_point[2]=0.0;
	UF_CALL(UF_CURVE_create_line(&sn7,&bn7));

	int flag=1;
	double first[3]={-m_b/2,r,0.0};
	double second[3]={0.0,r1,0.0};
    double third[3]={m_b/2,r,0.0};
	tag_t arc;
	UF_CURVE_create_arc_thru_3pts(flag,first,second,third,&arc);

	line[0]=bn1;
	line[1]=bn2;
	line[2]=bn3;
	line[3]=bn4;
	line1[0]=bn5;
	line1[1]=bn6;
	line1[2]=bn7;
    line1[3]=arc;

	tag_t bn14;
	UF_CURVE_line_t sn14;
	sn14.start_point[0]=-m_b/2;
	sn14.start_point[1]=m_d/2;
	sn14.start_point[2]=0.0;
	sn14.end_point[0]=m_b/2;
	sn14.end_point[1]=m_d/2+m_b/12;
	sn14.end_point[2]=0.0;
	UF_CALL(UF_CURVE_create_line(&sn14,&bn14));
	
	
	UF_MODL_SWEEP_TRIM_object_p_t date=NULL;
	char *limit[2]={"0.0","360.0"};
	char *offset[2]={"0.0","0.0"};
	double origin[3]={0.0,0.0,0.0};
	double direction[3]={1.0,0.0,0.0};
	UF_FEATURE_SIGN mode_sign=UF_NULLSIGN;
	int number;
	tag_t *sum;
	UF_MODL_create_revolution(line,4,date,limit,offset,origin,false,true,origin,
		direction,mode_sign,&sum,&number);
	UF_MODL_create_revolution(&bn14,1,date,limit,offset,origin,false,true,origin,
		direction,UF_NEGATIVE,&sum,&number);
	UF_MODL_create_revolution(line1,4,date,limit,offset,origin,false,true,origin,
		direction,mode_sign,&sum,&number);

    
	double angle=2*3.1415/m_i;
	double yy,zz;

	char buffer[14];
	_gcvt(a/3,10,buffer);



	for(i=0;i<=m_i;i++)
	{
	yy=cos(i*angle)*(m_d/2+a/2);
	zz=sin(i*angle)*(m_d/2+a/2);

	double center[3]={a/6,yy,zz};
	double center1[3]={-a/6,yy,zz};
	
	tag_t id;
	UF_MODL_create_sphere1(mode_sign,center,buffer,&id);
    UF_MODL_create_sphere1(mode_sign,center1,buffer,&id);

	UF_OBJ_set_blank_status(bn1,UF_OBJ_BLANKED);	
	UF_OBJ_set_blank_status(bn2,UF_OBJ_BLANKED);	
	UF_OBJ_set_blank_status(bn3,UF_OBJ_BLANKED);	
	UF_OBJ_set_blank_status(bn4,UF_OBJ_BLANKED);	
	UF_OBJ_set_blank_status(bn5,UF_OBJ_BLANKED);	
	UF_OBJ_set_blank_status(bn6,UF_OBJ_BLANKED);	
	UF_OBJ_set_blank_status(bn7,UF_OBJ_BLANKED);	
	UF_OBJ_set_blank_status(arc,UF_OBJ_BLANKED);
	UF_OBJ_set_blank_status(bn14,UF_OBJ_BLANKED);
	}
	}

	CDialog::OnOK();
}



void Ctiaoxinqiu::OnCancel() 
{
	
	CDialog::OnCancel();
}

void Ctiaoxinqiu::OnHelpBtn() 
{
	AfxMessageBox(_T("请与合肥数字化设计中心联系!"));
}

⌨️ 快捷键说明

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