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

📄 hellor14.cpp

📁 本原代码集合了树形控件
💻 CPP
字号:
#include "stdafx.h"
#include <stdlib.h>
#include <string.h>
#include <rxobject.h>
#include <rxregsvc.h>
#include <aced.h>
#include <math.h>
#include <dbsymtb.h>
#include <dbents.h>
#include "acestext.h"

#include "aced.h"
#include "RESOURCEHELPER.H"
#include "hellor14.h"

// new added! yb 2004,4,17
#include "math.h"
#include "afxinet.h" //for internet
#include <sqlext.h>

#include <afxdb.h>

// #include "TolInput.h"  for tolerance inquiry! yb
#include "Tol.h"
#include "autotol.h"

void         initApp();
void         unloadApp();

extern "C"
AcRx::AppRetCode acrxEntryPoint(AcRx::AppMsgCode, void*);

extern "C" HINSTANCE _hdllInstance;
extern BOOL InitModule(HINSTANCE, DWORD, LPVOID);
static AFX_EXTENSION_MODULE arxmfcDLL;

void InitMFC();
void EndMFC();

//new added! yb 2004,4,17

void autoTolCal(double dimCls,double dievTop,double dievBottom,
	AcDbVoidPtrArray &wwgListBaseDim,
	AcDbVoidPtrArray &wwgListLoopStyle,AcDbVoidPtrArray &wwgListResult)
{
	AcDbVoidPtrArray wwgListITData;
	//AcDbVoidPtrArray wwgListResult;
	double wwgITData[20];
	AcDbVoidPtrArray wwgListITGrad;
	double m_dbNum=0.0,m_dbCoef=0.0,m_dbTolCls,m_dbDimAdjust=0.0,dbCal=0.0,dbCal2=0.0;
	int easiest;
	m_dbTolCls=dievTop-dievBottom;
	
	for(int i=0;i<LEN;i++) //零件数量循环
	{
		for(int j=0;j<13;j++)//对公差单位进行循环
		{
			double* BaseDim1=(double*)wwgListBaseDim.at(i);
			if(*BaseDim1>=m_nBsDimGrad[j]&&*BaseDim1<m_nBsDimGrad[j+1])
			{
				//根据《机械精度设计》155页公式(4-54),先求分母
        		m_dbCoef+=pow(m_nTolDanwei[j],2);
				break;
			}
		}
	}
	m_dbCoef=1000.0*m_dbTolCls/sqrt(m_dbCoef);
    //设置循环判断各组成环公差等级系数更靠近哪一个公差等级系数并记录在数组中 
	CString kk;
	kk.Format("%8.4f",m_dbCoef);
	AfxMessageBox(kk);
    //设置循环判断各组成环公差等级系数更靠近哪一个公差等级系数并记录在数组中 
	for(int k=0;k<LEN;k++)
	{
		if(k>1)
		{
			double* BaseDim2=(double*)wwgListBaseDim.at(k);
			ads_printf("\n%f",*BaseDim2);
			double* BaseDim3=(double*)wwgListBaseDim.at(k-1);
			if(*BaseDim2>*BaseDim3)    
				easiest=k;	
		}
		if(m_dbCoef>=m_nTolGradCoef[14])
		{
			int *data=new int;
			*data=14;
			wwgListITGrad.append(data);  
		}
		else
		{
			for(int m_nITGradi=0;m_nITGradi<14;m_nITGradi++)
			{
				if (m_dbCoef>=m_nTolGradCoef[m_nITGradi]&&m_dbCoef<m_nTolGradCoef[m_nITGradi+1])
				{
					int *data=new int;
					*data=m_nITGradi;
					wwgListITGrad.append(data);  
					break;
				}
			}
		}
	}
	
 /////////////////////////////////////////////访问数据库部分
	CString strDataName="Tol";
	CDatabase db;
	CTol* pMasterSet = NULL;
	CString m_column;
	double min=0.0,max=1000.0;
	double m_ComposedIT[16];//
	try                                  
	{
		if (db.Open(strDataName))
		{
			pMasterSet = new CTol();
			pMasterSet->Open();
			for(int i=0;i<LEN;i++)   //设置循环查询各组成环标准公差    
			{
				for(int zz=0;zz<LEN;zz++)
				double* BaseDim4=(double*)wwgListBaseDim.at(i);
				double basedim=0;//
				int *itGrad=(int*)wwgListITGrad.at(i);//
				ads_printf("\n *itGrad=%d",*itGrad);
				pMasterSet->MoveFirst();//   
				while (!pMasterSet->IsEOF())
				{	
					double *BaseDim4=(double*)wwgListBaseDim.at(i);
					m_column = pMasterSet->m_columnRecord;
					if(*BaseDim4>basedim)
					{
						if (*BaseDim4<=atof(m_column))
						{
							if(*itGrad==0)
							{
								m_ComposedIT[i]=0;
								ads_alert("该公差精度等级低于五级!");
							}
							else if(*itGrad==1)
								m_ComposedIT[i]=(pMasterSet->m_IT5 )/1000.0;
							else if(*itGrad==2)
								m_ComposedIT[i]=(pMasterSet->m_IT6 )/1000.0;
							else if(*itGrad==3)
								m_ComposedIT[i]=(pMasterSet->m_IT7 )/1000.0;
							else if(*itGrad==4)
								m_ComposedIT[i]=(pMasterSet->m_IT8 )/1000.0;
							else if(*itGrad==5)
								m_ComposedIT[i]=(pMasterSet->m_IT9 )/1000.0;
							else if(*itGrad==6)
								m_ComposedIT[i]=(pMasterSet->m_IT10 )/1000.0;
							else if(*itGrad==7)
								m_ComposedIT[i]=(pMasterSet->m_IT11 )/1000.0;
							else if(*itGrad==8)
								m_ComposedIT[i]=(pMasterSet->m_IT12 )/1000.0;
							else if(*itGrad==9)
								m_ComposedIT[i]=(pMasterSet->m_IT13 )/1000.0;
							else if(*itGrad==10)
								m_ComposedIT[i]=(pMasterSet->m_IT14 )/1000.0;
							else if(*itGrad==11)
								m_ComposedIT[i]=(pMasterSet->m_IT15 )/1000.0;
							else if(*itGrad==12)
								m_ComposedIT[i]=(pMasterSet->m_IT16 )/1000.0;
							else if(*itGrad==13)
								m_ComposedIT[i]=(pMasterSet->m_IT17 )/1000.0;
							else if(*itGrad==14)
								m_ComposedIT[i]=(pMasterSet->m_IT18 )/1000.0;
							else 
								m_ComposedIT[i]=1000.0;
							break;
						}
						basedim=atof(m_column);
					}
					pMasterSet->MoveNext();   //没有查到则查询下一记录
				}
			}
			pMasterSet->Close();
			delete pMasterSet;
			db.Close();
		}
				////////////////////////
	}
	catch(CDBException* pe)
	{   
		AfxMessageBox(pe->m_strError);			
		if (pMasterSet)
		{
			if (pMasterSet->IsOpen())
			{
				pMasterSet->Close();
			}
			delete pMasterSet;
		}
		if (db.IsOpen())
		{
			db.Close(); 
		}
		pe->Delete();
	}
	for(int m=0;m<LEN;m++)
	{
		//计算出除协调环外各组成环公差平方之合
		wwgITData[m]=m_ComposedIT[m];//
		m_dbDimAdjust+=pow(m_ComposedIT[m],2.0);//
	}
 /////////////////////计算需要调整的公差 部分/////////
//	double dbCal1;//zying delete
	if (!(m_dbDimAdjust>pow(m_dbTolCls,2)))
		;
/*	else if(m_dbDimAdjust>=pow(m_dbTolCls,2))
	{
		double* itData2=(double*)wwgListITData.at(easiest);
		m_dbDimAdjust=m_dbDimAdjust-pow(*itData2,2);
		dbCal1=sqrt(pow(m_dbTolCls,2)-m_dbDimAdjust);
		for(int i=0;i<=13;i++)
		{
			if(((m_ComposedIT[easiest][i+2]+m_ComposedIT[easiest][i+1])/2.0)>=dbCal1
				&&dbCal1>=(m_ComposedIT[easiest][i]+m_ComposedIT[easiest][i+1])/2.0)
			{
				//输出大于等于计算公差的标准公差的最小值
				void* aaa=&m_ComposedIT[easiest][i+1];
				wwgListITData.insertAt(easiest,aaa);
				int a=i+1;
				void* b=&a;
				wwgListITGrad.insertAt(easiest,b);
				break;
			}
		}
		
	}*/
    ///////////////计算极限偏差部分//////////////
	double *data;
	for(int q=0;q<LEN;q++)
	{
		data= new double;
		*data=wwgITData[q]/2;
		wwgListResult.append(data);
		double* w=(double*)wwgListResult.at(q);
		ads_printf("\n%f\n",*w); 
	}
}    
void autoTolMain()
{
	double dbTest[3]={12.0,74.5};    //,84.7};
	int    intTest[3]={DECLOOP,INCLOOP};       //DECLOOP,INCLOOP};
	ads_alert("0001");
	AcDbVoidPtrArray wwgListBaseDim;
	AcDbVoidPtrArray wwgListLoopStyle;		
//	AcDbVoidPtrArray wwgListResult1;
	AcDbVoidPtrArray wwgListResult;
//	wwgListResult.append(10);
ads_alert("0002");
	for(int i=0;i<2;i++)
	{
		void* dbData=&dbTest[i];
		void* intData=&intTest[i];
		wwgListBaseDim.append(dbData);
		wwgListLoopStyle.append(intData);
	}
ads_alert("0003");
	autoTolCal(0.2,0.2,-0.2,wwgListBaseDim,wwgListLoopStyle,wwgListResult);
	ads_printf("\nwwgListResult.length()==%d",wwgListResult.length());
//	ads_printf("\nwwgListResult=======%f",(double*)wwgListResult[0]);
	for(int ii=0;ii<wwgListResult.length();ii++)
	{

		double *w=(double*)wwgListResult.at(ii);
//		ads_alert("11");//zying delete
///		wwgListResult.removeLast();
		ads_printf("\n%f\n",*w);
	
		ads_printf("\n%d",LEN);
	}
}



/////////////试验调用函数部分///////////////////////////////////////////
/*
void autoTolMain()
{
	double dbTest[3]={12.0,74.5,84.7};
	int    intTest[3]={DECLOOP,DECLOOP,INCLOOP};
	for(int i=0;i<=2;i++)
	{
		dbListWwg[BASEDIM].addTo(i,&dbTest[i]);
		intListWwg[LOOPSTYLE].insertAt(i,intTest[i]);
	}
	autoTolCal(0.2,0.1,-0.3,dbListWwg[BASEDIM],intListWwg[LOOPSTYLE]);
	ads_printf("\n%f",GetStandardTol(50.0,8));
}
*/


void hello()
{
	int i;
	i=10;
	HelloDlg Hellor14dlg;
	Hellor14dlg.DoModal();
	ads_printf("\nThis is my first AutoCADR14 program.");
}

void
initApp()
{
	InitMFC();
    acedRegCmds->addCommand("HELLO",
        "_hello", "hello", ACRX_CMD_MODAL,
        hello);
	acedRegCmds->addCommand("MProduct_CMDS", "autotol", "autotol",
        ACRX_CMD_MODAL, autoTolMain);
}

void
unloadApp()
{
    acedRegCmds->removeGroup("HELLO");
	EndMFC();
}

//////////////////////////////////////////////////////////////
//
// Entry point (1) - gets called first (before acrxEntryPoint)
//
//////////////////////////////////////////////////////////////

extern "C" int APIENTRY
DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
{
	// Remove this if you use lpReserved
	UNREFERENCED_PARAMETER(lpReserved);

	if (dwReason == DLL_PROCESS_ATTACH)
	{
        _hdllInstance =  hInstance;		
		if (!AfxInitExtensionModule(arxmfcDLL, hInstance))
		 return 0;

		// Insert this DLL into the resource chain
		new CDynLinkLibrary(arxmfcDLL);
	}
	else if (dwReason == DLL_PROCESS_DETACH)
      AfxTermExtensionModule(arxmfcDLL);
	return 1;   // ok
}

// ARX entry point
//
AcRx::AppRetCode
acrxEntryPoint(AcRx::AppMsgCode msg, void* pkt)
{
    switch (msg) {
    case AcRx::kInitAppMsg:
        acrxDynamicLinker->unlockApplication(pkt);
        initApp();
        break;
    case AcRx::kUnloadAppMsg:
        unloadApp();
    }
    return AcRx::kRetOK;
}

//////////////////////////////////////////////////////////////
//
// Temporary Resource Override
//
//////////////////////////////////////////////////////////////
HINSTANCE CTemporaryResourceOverride::m_hInstanceDefault = NULL;

void CTemporaryResourceOverride::SetDefaultResource(HINSTANCE hInstDefault)
// For using the default constructor, you've got to use this guy once.
// Typically, you do this once in your DLLMain function....
{
    ASSERT(hInstDefault != NULL);

    m_hInstanceDefault = hInstDefault;
}

void CTemporaryResourceOverride::CommonConstruction(HINSTANCE hInst)
// Handles the various flavors of construction with a common handler
{
    // Here, we scurry away the old resource handle.
    m_hInstanceOld = AfxGetResourceHandle();
    AfxSetResourceHandle(hInst);
}

CTemporaryResourceOverride::CTemporaryResourceOverride(HINSTANCE hInstNew)
// If you have a specific instance in mind, use this variant.
{
    ASSERT(hInstNew != NULL);

    CommonConstruction(hInstNew);
}

CTemporaryResourceOverride::CTemporaryResourceOverride()
// If you're always using the same instance, set the default, and use this variant.
{
    ASSERT(m_hInstanceDefault != NULL);

    CommonConstruction(m_hInstanceDefault);
}

CTemporaryResourceOverride::~CTemporaryResourceOverride()
// And here's where we clean up.  Nice and simple.
{
    AfxSetResourceHandle(m_hInstanceOld);
}

//////////////////////////////////////////////////////////////
//
// MFC Initialization
//
//////////////////////////////////////////////////////////////
void InitMFC()
{
    InitModule(_hdllInstance, DLL_PROCESS_ATTACH, NULL);
}

void EndMFC()
{
    InitModule(_hdllInstance, DLL_PROCESS_DETACH, NULL);
}



extern BOOL 
InitModule(HINSTANCE hInstance, DWORD dwReason, LPVOID)
{
   if (dwReason == DLL_PROCESS_ATTACH)
   {
      // Extension DLL one-time initialization 
      if (!AfxInitExtensionModule(
             arxmfcDLL, hInstance))
         return 0;

      // CTemporaryResourceOverride initialization
      CTemporaryResourceOverride::SetDefaultResource( _hdllInstance);

      // TODO: perform other initialization tasks here
      // ...
      
      // Insert this DLL into current process state.
      new CDynLinkLibrary(arxmfcDLL);

   }
   else if (dwReason == DLL_PROCESS_DETACH)
   {
      // Extension DLL per-process termination
      AfxTermExtensionModule(arxmfcDLL);

      // TODO: perform other cleanup tasks here
   }
   return 1;   // ok
}
/////////////////////////////////////////////////////////////////////////////
// HelloDlg dialog


HelloDlg::HelloDlg(CWnd* pParent /*=NULL*/)
	: CDialog(HelloDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(HelloDlg)
	m_name = _T("");
	//}}AFX_DATA_INIT
}


void HelloDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(HelloDlg)
	DDX_Text(pDX, IDC_EDIT1, m_name);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(HelloDlg, CDialog)
	//{{AFX_MSG_MAP(HelloDlg)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// HelloDlg message handlers

void HelloDlg::OnOK() 
{

	// TODO: Add extra validation here
	UpdateData(TRUE);
	AfxMessageBox("1");
	ads_printf("\nHello,%s!",m_name);
	CDialog::OnOK();
}

⌨️ 快捷键说明

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