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

📄 basearx.cpp

📁 ObjectARX 2004开发的气阀参数化设计
💻 CPP
字号:

#include "StdAfx.h"
#include "Stdio.h"
#include "basearx.h"

CBaseArx::CBaseArx(void)
{
}

CBaseArx::~CBaseArx(void)
{
}

 // 创建曲线
AcDbObjectId CBaseArx::CreateSpline(AcGePoint3dArray& points)
{
	
	AcDbObjectId id;
   AcDbSpline *pSpline=new AcDbSpline(points,4, 0.0);
  //AcGePoint2dArray  gept2dar.h 
	id=this->AppendToDB((AcDbEntity*)pSpline);
    pSpline->close();
	return id;

}

// 创建圆弧
AcDbObjectId CBaseArx::CreateArc(AcGePoint3d  &center,double a1,double a2, double radius)
{   
	AcDbObjectId id;
//	a1=3.1415926*a1/180;a2=3.1415926*a2/180;
	AcDbArc *pArc=new AcDbArc(center,radius,a1,a2);
	//AcDbArc(const AcGePoint3d& center,double radius,double startAngle,double endAngle);
	id=this->AppendToDB((AcDbEntity*)pArc);
    pArc->close();
	return id;

}
// 创建直线
AcDbObjectId CBaseArx::CreateLine(AcGePoint3d  & st, AcGePoint3d  & ed)
{
	
	AcDbObjectId id;
	AcDbLine *pLine = new AcDbLine( st, ed);
	id=this->AppendToDB((AcDbEntity*)pLine);
    pLine->close();
	return id;

}

AcDbObjectId CBaseArx::AppendToDB(AcDbEntity* pEntity)
{
	AcDbBlockTable *pBlockTable;
	acdbHostApplicationServices()->workingDatabase()
		->getSymbolTable(pBlockTable, AcDb::kForRead);

	AcDbBlockTableRecord *pBlockTableRecord;
	pBlockTable->getAt(ACDB_MODEL_SPACE, pBlockTableRecord,
		AcDb::kForWrite);
	pBlockTable->close();

	AcDbObjectId EntityId;
	pBlockTableRecord->appendAcDbEntity(EntityId, pEntity);

	pBlockTableRecord->close();
	
	return EntityId;
}



void CBaseArx::MakeValue()
{   Origin.x=0;Origin.y=0;Origin.z=0;
    for(int i=0;i<12;i++){P[i].z=0;}
    double LL,XX;

	P[1].x=Origin.x+L2;P[1].y=Origin.y;
	P[2].x=P[1].x;P[2].y=P[1].y+H2;
	P[3].x=P[2].x+R1-R1*sin(A);P[3].y=P[2].y+R1*cos(A);
	P[6].x=Origin.x+L2/2+L1/2;P[6].y=Origin.y+H1;
	LL=(P[6].x-P[3].x)/cos(A)-R2*tan(PI/4-A/2);
	P[4].x=P[3].x+LL*cos(A);P[4].y=P[3].y+LL*sin(A);
	P[5].x=P[6].x;P[5].y=P[3].y+(P[6].x-P[3].x)*tan(A)+R2*tan(PI/4-A/2);
    XX=Origin.x+L2/2;
	P[7].x=2*XX-P[6].x;P[7].y=P[6].y;
	P[8].x=2*XX-P[5].x;P[8].y=P[5].y;
	P[9].x=2*XX-P[4].x;P[9].y=P[4].y;
	P[10].x=2*XX-P[3].x;P[10].y=P[3].y;
	P[11].x=Origin.x;P[11].y=Origin.y+H2;
}

void CBaseArx::DrawQifa()
{   AcGePoint3d O[4];
    O[0].z=0;O[1].z=0;O[2].z=0;O[3].z=0;
    O[0].x=P[2].x+R1;O[0].y=P[2].y;
	O[1].x=P[5].x-R2;O[1].y=P[5].y;
	O[2].x=2*(Origin.x+L2/2)-O[1].x;O[2].y=O[1].y;
	O[3].x=2*(Origin.x+L2/2)-O[0].x;O[3].y=O[0].y;

	this->CreateLine(Origin,P[1]);
	this->CreateLine(P[1],P[2]);
	this->CreateArc(O[0],PI/2+A,PI,R1);
	this->CreateLine(P[3],P[4]);
	this->CreateArc(O[1],A-PI/2,0,R2);
    this->CreateLine(P[5],P[6]);
	this->CreateLine(P[6],P[7]);
	this->CreateLine(P[7],P[8]);
	this->CreateArc(O[2],PI,PI+PI/2-A,R2);
	this->CreateLine(P[9],P[10]);
	this->CreateArc(O[3],0,PI/2-A,R1);
	this->CreateLine(P[11],Origin);
    
	AcGePoint3d P01,P02;
	P01.x=P[7].x-20;P01.y=P[7].y+20;P01.z=0;
	P02.x=P[6].x+20;P02.y=P[1].y-20;P02.z=0;
//	acedCommand(RTSTR, "zoom", RTSTR, "W",RT3DPOINT,P01, RT3DPOINT,P02,RTNONE);
    FILE *fp;
	fp=fopen("C:\\output.txt","w+");

	fprintf(fp,"N0 G90 G00 X10 Y10 Z10;\n");
	fprintf(fp,"N1 G00 G42 X0 Y0 D01;\n");
	fprintf(fp,"N2 G01 Z-5 F150;\n");
	fprintf(fp,"N3 X%f;\n",P[1].x);
	fprintf(fp,"N4 Y%f;\n",P[2].y);
	fprintf(fp,"N5 G02 X%f Y%f R%f;\n",P[3].x,P[3].y,R1);
	fprintf(fp,"N6 G01 X%f Y%f;\n",P[4].x,P[4].y);
	fprintf(fp,"N7 G03 X%f Y%f R%f;\n",P[5].x,P[5].y,R2);
	fprintf(fp,"N8 G01 Y%f;\n",P[6].y);
	fprintf(fp,"N9 X%f;\n",P[7].x);
	fprintf(fp,"N10 Y%f;\n",P[8].y);
	fprintf(fp,"N11 G03 X%f Y%f R%f;\n",P[9].x,P[9].y,R2);
	fprintf(fp,"N12 G01 X%f Y%f;\n",P[10].x,P[10].y);
	fprintf(fp,"N13 G02 X%f Y%f R%f;\n",P[11].x,P[11].y,R1);
	fprintf(fp,"N14 G01 Y%f;\n",Origin.y);
	fprintf(fp,"N15 G00 G40 Z50;\n");
	fprintf(fp,"N16 M30;\n");

	fclose(fp);
}



⌨️ 快捷键说明

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