Example #1
1
void aSquare()
{
	
	AsdkSquare* mySquare = new AsdkSquare();

	if( !mySquare ) {
		acutPrintf("\n Memory allocation error.");
		return;
	}

	ads_point pt1, pt2, pt3;
	struct resbuf UCS, WCS;
	
	WCS.restype = RTSHORT;
	WCS.resval.rint = 0;

	UCS.restype = RTSHORT;
	UCS.resval.rint = 1;

	acedGetPoint(NULL, "\nPick a point for the center: ", pt1);
	acedGetPoint(pt1, "\nPick a direction for corner and size: ", pt2);

	pt2[X] = pt2[X] - pt1[X];
	pt2[Y] = pt2[Y] - pt1[Y];
	pt2[Z] = pt2[Z] - pt1[Z];

	pt3[X] = pt3[Y] = 0.0;
	pt3[Z] = 1.0;

	acedTrans(pt1, &UCS, &WCS, 0, pt1);
	acedTrans(pt2, &UCS, &WCS, 1, pt2);
	acedTrans(pt3, &UCS, &WCS, 1, pt3);

	mySquare->setSquareCenter(AcGePoint3d(pt1[X],pt1[Y],pt1[Z]));
	mySquare->setSquareOrient(AcGeVector3d(pt2[X],pt2[Y],pt2[Z]));	
	mySquare->setSquareNormal(AcGeVector3d(pt3[X],pt3[Y],pt3[Z]));

	append(mySquare);

	mySquare->close();

	return;

}
	AcDbIntArray &   geomIds) const
#else
Acad::ErrorStatus PDSphere::getOsnapPoints(
	AcDb::OsnapMode       osnapMode,
	int                   gsSelectionMark,
	const AcGePoint3d&    pickPoint,
	const AcGePoint3d&    lastPoint,
	const AcGeMatrix3d&   viewXform,
	AcGePoint3dArray&     snapPoints,
	AcDbIntArray&         geomIds) const
#endif
{
	assertReadEnabled();

	if(!hasSnap())
		return Acad::eOk;

	if(gsSelectionMark == 0)
		return Acad::eOk;

	AcGeVector3d viewDir(viewXform(Z, 0), viewXform(Z, 1),
		viewXform(Z, 2));

	switch(osnapMode)
	{
	case AcDb::kOsModeEnd:
		break;
	case AcDb::kOsModeMid:
		break;
	case AcDb::kOsModeCen:
		snapPoints.append(m_ptCenter);
		break;
	case AcDb::kOsModeQuad:
		{
			AcGeCubicSplineCurve3d varcur;
			AcGeCubicSplineCurve3d varcurs[7];
			switch(gsSelectionMark)
			{
			case 1:
				varcur = AcGeCubicSplineCurve3d(AcGeCircArc3d(m_ptCenter, AcGeVector3d(1, 0, 0), m_dRadius));
				break;
			case 2:
				varcur = AcGeCubicSplineCurve3d(AcGeCircArc3d(m_ptCenter, AcGeVector3d(1, 1, 0), m_dRadius));
				break;
			case 3:
				varcur = AcGeCubicSplineCurve3d(AcGeCircArc3d(m_ptCenter, AcGeVector3d(0, 1, 0), m_dRadius));
				break;
			case 4:
				varcur = AcGeCubicSplineCurve3d(AcGeCircArc3d(m_ptCenter, AcGeVector3d(-1, 1, 0), m_dRadius));
				break;
			case 5:
				varcur = AcGeCubicSplineCurve3d(AcGeCircArc3d(m_ptCenter, AcGeVector3d(0, 0, 1), m_dRadius));
				break;
			case 6:
				varcur = AcGeCubicSplineCurve3d(AcGeCircArc3d(m_ptCenter - AcGeVector3d(0, 0, 1) * m_dRadius *  cos(PI / 4.0), AcGeVector3d(0, 0, 1), m_dRadius * sin(PI / 4.0)));
				break;
			case 7:
				varcur = AcGeCubicSplineCurve3d(AcGeCircArc3d(m_ptCenter + AcGeVector3d(0, 0, 1) * m_dRadius * cos(PI / 4.0), AcGeVector3d(0, 0, 1), m_dRadius * sin(PI / 4.0)));
				break;
			//定义球面象限点的捕捉方式
			//added by szw 2009.11.18 : begin
			case 8:
				varcurs[0] = AcGeCubicSplineCurve3d(AcGeCircArc3d(m_ptCenter, AcGeVector3d(1, 0, 0), m_dRadius));
				varcurs[1] = AcGeCubicSplineCurve3d(AcGeCircArc3d(m_ptCenter, AcGeVector3d(1, 1, 0), m_dRadius));
				varcurs[2] = AcGeCubicSplineCurve3d(AcGeCircArc3d(m_ptCenter, AcGeVector3d(0, 1, 0), m_dRadius));
				varcurs[3] = AcGeCubicSplineCurve3d(AcGeCircArc3d(m_ptCenter, AcGeVector3d(-1, 1, 0), m_dRadius));
				varcurs[4] = AcGeCubicSplineCurve3d(AcGeCircArc3d(m_ptCenter, AcGeVector3d(0, 0, 1), m_dRadius));
				varcurs[5] = AcGeCubicSplineCurve3d(AcGeCircArc3d(m_ptCenter - AcGeVector3d(0, 0, 1) * m_dRadius *  cos(PI / 4.0), AcGeVector3d(0, 0, 1), m_dRadius * sin(PI / 4.0)));
				varcurs[6] = AcGeCubicSplineCurve3d(AcGeCircArc3d(m_ptCenter + AcGeVector3d(0, 0, 1) * m_dRadius * cos(PI / 4.0), AcGeVector3d(0, 0, 1), m_dRadius * sin(PI / 4.0)));
				break;
			default:
				break;
			//added by szw 2009.11.18 : end
			}
			if(gsSelectionMark < 8)
			{
				double fromParam = varcur.startParam();
				double toParam = varcur.endParam();
				double delta = (toParam - fromParam) / 4.0;
				for(int i = 0; i < 4; i++)
					snapPoints.append(varcur.evalPoint(fromParam + i * delta));
			}
			//定义球面象限点的捕捉方式
			//added by szw 2009.11.18 : begin
			else if(gsSelectionMark == 8)
			{
				for(int j = 0; j < 7; ++j)
				{
					double fromParam = varcurs[j].startParam();
					double toParam = varcurs[j].endParam();
					double delta = (toParam - fromParam) / 4.0;
					for(int i = 0; i < 4; i++)
						snapPoints.append(varcurs[j].evalPoint(fromParam + i * delta));
				}
			}
			//added by szw 2009.11.18 : end
		}
		break;
	case AcDb::kOsModeNode:
		break;
	case AcDb::kOsModeIns:
		snapPoints.append(m_ptCenter);
		break;
	case AcDb::kOsModePerp:
		{
			AcGeCircArc3d cir;
			AcGeCircArc3d cirs[7];
			switch(gsSelectionMark)
			{
			case 1:
				cir.set(m_ptCenter, AcGeVector3d(1, 0, 0), m_dRadius);
				break;
			case 2:
				cir.set(m_ptCenter, AcGeVector3d(1, 1, 0), m_dRadius);
				break;
			case 3:
				cir.set(m_ptCenter, AcGeVector3d(0, 1, 0), m_dRadius);
				break;
			case 4:
				cir.set(m_ptCenter, AcGeVector3d(-1, 1, 0), m_dRadius);
				break;
			case 5:
				cir.set(m_ptCenter, AcGeVector3d(0, 0, 1), m_dRadius);
				break;
			case 6:
				cir.set(m_ptCenter - AcGeVector3d(0, 0, 1) * m_dRadius * cos(PI / 4.0), AcGeVector3d(0, 0, 1), m_dRadius *sin(PI / 4.0));
				break;
			case 7:
				cir.set(m_ptCenter + AcGeVector3d(0, 0, 1) * m_dRadius * cos(PI / 4.0), AcGeVector3d(0, 0, 1), m_dRadius * sin(PI / 4.0));
				break;
			//定义球面垂直正交点的捕捉方式
			//added by szw 2009.11.18 : begin
			case 8:
				cirs[0].set(m_ptCenter, AcGeVector3d(1, 0, 0), m_dRadius);
				cirs[1].set(m_ptCenter, AcGeVector3d(1, 1, 0), m_dRadius);
				cirs[2].set(m_ptCenter, AcGeVector3d(0, 1, 0), m_dRadius);
				cirs[3].set(m_ptCenter, AcGeVector3d(-1, 1, 0), m_dRadius);
				cirs[4].set(m_ptCenter, AcGeVector3d(0, 0, 1), m_dRadius);
				cirs[5].set(m_ptCenter - AcGeVector3d(0, 0, 1) * m_dRadius * cos(PI / 4.0), AcGeVector3d(0, 0, 1), m_dRadius *sin(PI / 4.0));
				cirs[6].set(m_ptCenter + AcGeVector3d(0, 0, 1) * m_dRadius * cos(PI / 4.0), AcGeVector3d(0, 0, 1), m_dRadius * sin(PI / 4.0));
				break;
			default:
				break;
			//added by szw 2009.11.18 : end
			}
			if(gsSelectionMark < 8)
			{
				AcGePoint3d pt;
				pt = cir.closestPointTo(lastPoint);
				snapPoints.append(pt);
			}
			//定义球面垂直正交点的捕捉方式
			//added by szw 2009.11.18 : begin
			else if(gsSelectionMark == 8)
			{
				for(int i = 0; i < 7; ++i)
				{
					AcGePoint3d pt;
					pt = cirs[i].closestPointTo(lastPoint);
					snapPoints.append(pt);
				}
			}
			//added by szw 2009.11.18 : end
		}
		break;
	case AcDb::kOsModeTan:
		break;
	case AcDb::kOsModeNear:
		{
			AcGePoint3d pt;
			AcGeCircArc3d cir;
			AcGeCircArc3d cirs[7];
			switch(gsSelectionMark)
			{
			case 1:
				cir.set(m_ptCenter, AcGeVector3d(1, 0, 0), m_dRadius);
				break;
			case 2:
				cir.set(m_ptCenter, AcGeVector3d(1, 1, 0), m_dRadius);
				break;
			case 3:
				cir.set(m_ptCenter, AcGeVector3d(0, 1, 0), m_dRadius);
				break;
			case 4:
				cir.set(m_ptCenter, AcGeVector3d(-1, 1, 0), m_dRadius);
				break;
			case 5:
				cir.set(m_ptCenter, AcGeVector3d(0, 0, 1), m_dRadius);
				break;
			case 6:
				cir.set(m_ptCenter - AcGeVector3d(0, 0, 1) * m_dRadius * cos(PI / 4.0), AcGeVector3d(0, 0, 1), m_dRadius *sin(PI / 4.0));
				break;
			case 7:
				cir.set(m_ptCenter + AcGeVector3d(0, 0, 1) * m_dRadius * cos(PI / 4.0), AcGeVector3d(0, 0, 1), m_dRadius * sin(PI / 4.0));
				break;
			//定义球面垂直正交点的捕捉方式
			//added by szw 2009.11.18 : begin
			case 8:
				cirs[0].set(m_ptCenter, AcGeVector3d(1, 0, 0), m_dRadius);
				cirs[1].set(m_ptCenter, AcGeVector3d(1, 1, 0), m_dRadius);
				cirs[2].set(m_ptCenter, AcGeVector3d(0, 1, 0), m_dRadius);
				cirs[3].set(m_ptCenter, AcGeVector3d(-1, 1, 0), m_dRadius);
				cirs[4].set(m_ptCenter, AcGeVector3d(0, 0, 1), m_dRadius);
				cirs[5].set(m_ptCenter - AcGeVector3d(0, 0, 1) * m_dRadius * cos(PI / 4.0), AcGeVector3d(0, 0, 1), m_dRadius *sin(PI / 4.0));
				cirs[6].set(m_ptCenter + AcGeVector3d(0, 0, 1) * m_dRadius * cos(PI / 4.0), AcGeVector3d(0, 0, 1), m_dRadius * sin(PI / 4.0));
				break;
			default:
				break;
			//added by szw 2009.11.18 : end
			}
			if(gsSelectionMark < 8)
			{
				pt = cir.projClosestPointTo(pickPoint, viewDir);
				snapPoints.append(pt);
			}
			//定义球面垂直正交点的捕捉方式
			//added by szw 2009.11.18 : begin
			else if(gsSelectionMark == 8)
			{
				for(int i = 0; i < 7; ++i)
				{
					pt = cirs[i].projClosestPointTo(pickPoint, viewDir);
					snapPoints.append(pt);
				}
			}
			//added by szw 2009.11.18 : end
		}
		break;
	default:
		break;
	}

	return Acad::eOk;
}
AcDbObjectId Additional_Class::Creat_Table(AcGePoint3d TablePoint, vector<CString> Title, double ColWidth, double RowHeight, double TextHeight)
{
	AcDbTable *pTable = new AcDbTable();
	AcDbObjectId TableID;
	pTable->setNumColumns(Title.size());
	pTable->setNumRows(1);
	pTable->setColumnWidth(ColWidth);
	pTable->setRowHeight(RowHeight);
	pTable->setDirection(AcGeVector3d(1,0,0));
	pTable->setNormal(AcGeVector3d(0,0,1));
	
	pTable->setPosition(TablePoint);
	AcDbBlockTable *pBlockTable;
	AcDbBlockTableRecord *pBlockTableRecord;
	acdbHostApplicationServices()->workingDatabase()->getBlockTable(pBlockTable, AcDb::kForRead);
	pBlockTable->getAt(ACDB_MODEL_SPACE,pBlockTableRecord,AcDb::kForWrite);
	pBlockTableRecord->appendAcDbEntity(TableID, pTable);
	//pBlockTable->close();
	pBlockTableRecord->close();
	//pTable->setTextString(0,0, "桩 号");
	//pTable->setTextHeight(0,0,10);
	//pTable->setTextString(0,1, "X坐标值");
	//pTable->setTextHeight(0,1,10);
	//pTable->setTextString(0,2, "Y坐标值");
	//pTable->setTextHeight(0,2,10);
	//pTable->setTextString(0,3, "特性值");
	//pTable->setTextHeight(0,3,10);
	//pTable->setTextString(0,4, "长 度");
	//pTable->setTextHeight(0,4,10);
	pTable->close();
	return TableID;
}
Acad::ErrorStatus PDSphere::subGetGeomExtents(AcDbExtents& extents) const
#else
Acad::ErrorStatus PDSphere::getGeomExtents(AcDbExtents& extents) const
#endif
{
	assertReadEnabled();
	extents.set(m_ptCenter - AcGeVector3d(1, 1, 1) * m_dRadius, 
		m_ptCenter + AcGeVector3d(1, 1, 1) * m_dRadius);
	return Acad::eOk;
}
Example #5
0
//----- worldDraw
Adesk::Boolean OarxEmployee::worldDraw (AcGiWorldDraw *mode) {
	//----- Make sure the object is open is read mode
	assertReadEnabled () ;
	//----- Draw the entity
	mode->geometry ().circle (center (), 1.0, AcGeVector3d (0.0, 0.0, 1.0)) ;
	//----- Write the Employee ID and Name
	char buffer [255] ;
	sprintf (buffer, "%d", mID) ;
	mode->geometry ().text (center (), AcGeVector3d (0, 0, 1), AcGeVector3d (1, 0, 0), 0.5, 1.0, 0.0, buffer) ;
	sprintf (buffer, "%s %s", mFirstName, mLastName) ;
	mode->geometry ().text (center () - AcGeVector3d (0, 0.5, 0), AcGeVector3d (0, 0, 1), AcGeVector3d (1, 0, 0), 0.5, 1.0, 0.0, buffer) ;
	//----- Returns Adesk::kTrue to not call viewportDraw()
	return (Adesk::kTrue) ;
}
Example #6
0
Acad::ErrorStatus
AsdkSmiley::dxfOutFields(AcDbDxfFiler *filer) const
{
    assertReadEnabled();

    AcDbEntity::dxfOutFields( filer );

    filer->writeItem( AcDb::kDxfSubclass, kClassName );
    // Write version number
    filer->writeItem( AcDb::kDxfReal, kCurrentVersionNumber );
    filer->writeItem( AcDb::kDxfXCoord, center() );
    filer->writeItem( AcDb::kDxfReal+1, radius() );
    if( filer->includesDefaultValues()
        || mnormal != AcGeVector3d( 0, 0, 1 ))
    {
        filer->writeItem( AcDb::kDxfNormalX, mnormal );
    }
    filer->writeItem( AcDb::kDxfReal+2, meyesapart );
    filer->writeItem( AcDb::kDxfReal+3, meyesheight );
    filer->writeItem( AcDb::kDxfReal+4, meyesize );
    filer->writeItem( AcDb::kDxfXCoord+1, mouthLeft() );
    filer->writeItem( AcDb::kDxfXCoord+2, mouthBottom() );
    filer->writeItem( AcDb::kDxfXCoord+3, mouthRight() );

    return filer->filerStatus();
}
Example #7
0
Acad::ErrorStatus
AsdkSmiley::transformBy(const AcGeMatrix3d& xform)
{
    assertWriteEnabled();

    // Transform the center point and get the translation vector
    AcGePoint3d oldCenter( center() ),
                newCenter( center() );
    newCenter.transformBy( xform );
    AcGeVector3d transVec = newCenter - center();

    // Get the equivalent transformation
    AcGeMatrix3d newXform;
    newXform.setToTranslation( transVec );

    // Only translate the face and mouth - do not transform!
    mfacecircle.transformBy( newXform );
    mmoutharc.transformBy( newXform );

    // Get the point at a quadrant, transform it..
    AcGePoint3d oldXquad = center() + AcGeVector3d( radius(), 0, 0 ),
                newXquad( oldXquad );
    newXquad.transformBy( xform );

    // ... then scale the Smiley accordingly
    if ( Adesk::kFalse == xform.isEqualTo( AcGeMatrix3d::kIdentity ))
        scaleRadius( radius() * newCenter.distanceTo( newXquad ) / oldCenter.distanceTo( oldXquad ));

    return Acad::eOk;
}
Example #8
0
void DrawCmd::DrawWindLibrary( void )
{
	AcDbObjectId objId = ArxUtilHelper::SelectObject( _T( "请选择一条巷道:" ) );
	if( objId.isNull() ) return;
	if( !ArxUtilHelper::IsEqualType( _T( "LinkedGE" ), objId ) ) return;


	AcGePoint3d pt,insertPt;

	double angle;

	if( !ArxUtilHelper::PromptPt( _T( "\n请指定风库的插入点坐标:" ), pt ) ) return;

	if( !GetClosePtAndAngle( objId, pt, angle ) ) return;

	AcGeVector3d v = AcGeVector3d(AcGeVector3d::kXAxis);
	v.rotateBy(angle - PI/2,AcGeVector3d::kZAxis);
	v.normalize();

	insertPt = pt + v * 60;

	WindLibrary* pWindLib = new WindLibrary( insertPt, angle ); 	
	if( pWindLib == 0 ) return;


	pWindLib->setRelatedGE( objId ); // 关联巷道

	// 初始化并提交到数据库
	if( !ArxUtilHelper::PostToModelSpace( pWindLib ) ) delete pWindLib;

}
Example #9
0
//----- EXPLODE command
Acad::ErrorStatus OarxEmployee::explode (AcDbVoidPtrArray &entitySet) const {
	//----- Make sure the object is open is read mode
	assertReadEnabled () ;

	AcDbCircle *pCircle =NULL ;
	AcDbText *pText =NULL ;

	try {
		//----- Create the circle
		pCircle =new AcDbCircle (center (), AcGeVector3d (0.0, 0.0, 1.0), 1.0) ;
		if ( pCircle == NULL )
			throw Acad::eOutOfMemory ;
		//----- Create the text
		char buffer [255] ;
		sprintf (buffer, "%d\n%s %s", mID, mFirstName, mLastName) ;
		pText =new AcDbText (center (), buffer, AcDbObjectId::kNull, 0.5, 0.0) ;
		if ( pText == NULL )
			throw Acad::eOutOfMemory ;
		//----- Add the 2 new entities in the array
		entitySet.append (pCircle) ;
		entitySet.append (pText) ;

		return (Acad::eOk) ;

	} catch (const Acad::ErrorStatus es) {
		if ( pCircle != NULL )
			delete pCircle ;
		if ( pText != NULL )
			delete pText ;

		return (es) ;
	}
}
PDEcone::PDEcone(const AcGePoint3d &ptStart, const AcGePoint3d &ptEnd, 
            double Diameter1, double Diameter2, const AcGeVector3d &vect, 
            int Precision/* = PRIMARY3D_DEFAULT_PRECISION*/, 
            bool HasSnap/* = false*/) : PDPrimary3D(HasSnap)
{
	m_ptStart = ptStart;
	m_ptEnd = ptEnd;
	
	if (m_ptStart.isEqualTo(m_ptEnd))
		m_ptEnd=m_ptStart+AcGeVector3d(0,0,1);

	m_dDiameter1 =fabs(Diameter1) ;
	if(m_dDiameter1==0)
		m_dDiameter1=1;
	m_dDiameter2 =fabs(Diameter2) ;
	
	m_vect = vect.normal();
    if(Precision > 2)
	    m_dDividPrecision = Precision;
    else
        m_dDividPrecision = PRIMARY3D_DEFAULT_PRECISION;

    CalActParameter();
#ifdef _USEAMODELER_
    createBody();
#endif
}//added by linlin 20050929
Acad::ErrorStatus PDEcone::setParameters(const AcGePoint3d &ptStart, 
                                         const AcGePoint3d &ptEnd, 
                                         double d1, 
                                         double d2, 
                                         const AcGeVector3d &vect, 
                                         int Precision/* = PRIMARY3D_DEFAULT_PRECISION*/)
{
	assertWriteEnabled();
	m_ptStart = ptStart;
	m_ptEnd = ptEnd;
   
	if(m_ptStart.isEqualTo(m_ptEnd))
		m_ptEnd=m_ptStart+AcGeVector3d(0,0,1);

	m_dDiameter1 =fabs(d1) ;
	if(m_dDiameter1==0)
		m_dDiameter1=1;
	m_dDiameter2 =fabs(d2) ;
	
	m_vect = vect.normal();
    if(Precision > 2)
	    m_dDividPrecision = Precision;
    else
        m_dDividPrecision = PRIMARY3D_DEFAULT_PRECISION;

	CalActParameter();

#ifdef _USEAMODELER_
    createBody();
#endif
	return Acad::eOk;
}//added by linlin 20050929
Example #12
0
asdkBolt::asdkBolt()
{
	//{{AFX_ARX_DATA_INIT(asdkBolt)
	//}}AFX_ARX_DATA_INIT

	pHead=NULL;
	pShaft=NULL;
	alignment=AcGeVector3d(0,0,1);
	position=AcGePoint3d(0,0,0);

	pHead=new AcDb3dSolid;
	pShaft=new AcDb3dSolid;

	// Default Values...
	headSides=6;
	headHeight=2.0f;
	shaftLength=10.0f;
	threadLength=3.0f;
	threadWidth=.2f;
	headDiameter=5.0f;
	shaftDiameter=3.0f;

	createSolids();

}
Example #13
0
// -----------------------------------------------------------------------------
Acad::ErrorStatus DbValve::transformBy(const AcGeMatrix3d & xform)
{
	Acad::ErrorStatus retCode =AcDbPolyline::transformBy (xform) ;
	AcGeVector3d vecZ = AcGeVector3d(0, 0, 1);
	double elev = 0.0;
	const AcGeMatrix2d & xform2d = xform.convertToLocal(vecZ, elev);
	m_center.transformBy(xform2d);
	return (retCode) ;
}
Example #14
0
void createDatabase()
{
	// Create a new Database.
	AcDbDatabase *pDb = new AcDbDatabase();

	// Get the BlockTable.
	AcDbBlockTable *pBTable = NULL;
	pDb->getSymbolTable(pBTable, AcDb::kForRead);

	// Get the ModelSpace.
	AcDbBlockTableRecord *pRecord = NULL;
	pBTable->getAt(ACDB_MODEL_SPACE, pRecord, AcDb::kForWrite);
	pBTable->close();

	// Create a new Circle.
	AcDbCircle *pCircle1 = new AcDbCircle(AcGePoint3d(100,100,0),
		AcGeVector3d(0,0,1),
		50.0);
	// Create another new Circle.
	AcDbCircle *pCircle2 = new AcDbCircle(AcGePoint3d(200,200,0),
		AcGeVector3d(0,0,1),
		30.0);

	// Append Circle1 to ModelSpace
	pRecord->appendAcDbEntity(pCircle1);
	pCircle1->close();

	// Append Circle2 to ModelSpace
	pRecord->appendAcDbEntity(pCircle2);
	pCircle2->close();

	pRecord->close();

	// Save to file
	// MUST append a DWG file extension.
	acutPrintf(_T("\nSave file to \"d:\\temp\\testfile.dwg\"."));
	pDb->saveAs(_T("d:\\temp\\testfile.dwg"));

	delete pDb;
}
Example #15
0
void generateCutRegion(AcDb3dSolid* pSolid, int offset, int direction)
{
	//创建切面
	AcGePlane plane;

	if( direction == 1)
		plane.set(AcGePoint3d(offset,0,0),AcGeVector3d(1,0,0));
	else if( direction == 2)
		plane.set(AcGePoint3d(0,offset,0),AcGeVector3d(0,1,0));
	else if( direction == 3)
		plane.set(AcGePoint3d(0,0,offset),AcGeVector3d(0,0,1));

	//得到实体与切面相切的截面
	AcDbRegion *pSelectionRegion = NULL;
	pSolid->getSection(plane, pSelectionRegion);

	//将其移动到YZ平面
	//moveToBottom(pSelectionRegion);

	//将截面加入到模型空间
	PostToModelSpace(pSelectionRegion);
}
Example #16
0
void asdkBolt::createSolids()
{
	Acad::ErrorStatus es;
	if(pHead) {
		delete pHead;
		pHead = new AcDb3dSolid;
	}
	if(pShaft) {
		delete pShaft;
		pShaft = new AcDb3dSolid;
	}

	pHead->setDatabaseDefaults();
	pShaft->setDatabaseDefaults();
	
	// Create the Bolt Head
	// Perimeter = 2n r sin(Pi/n)=2n r tan(Pi/n)
	double edgeLength=(2*headSides * headDiameter * sin(PI/headSides))/headSides;
	double inscribedDiameter=sqrt(pow(edgeLength/2,2)+pow(headDiameter/2,2));
	double vertexAngle=PI2/headSides;

	AcDb3dPolyline *pPoly=new AcDb3dPolyline;
	pPoly->setDatabaseDefaults();
	double startAngle=vertexAngle/2;
	for(int c=0;c<headSides;c++)
	{
		AcDb3dPolylineVertex *pVertex=new AcDb3dPolylineVertex(AcGePoint3d(sin(startAngle)*inscribedDiameter,cos(startAngle)*inscribedDiameter,0));
		pPoly->appendVertex(pVertex);
		startAngle+=vertexAngle;
	}
	pPoly->makeClosed();
	
	AcDbVoidPtrArray curves,regions,shaftRegions,shaftCurves;
	curves.append(pPoly);

	// Error here!!
	es=AcDbRegion::createFromCurves(curves,regions);// Create the region...note:	static member function.
	es=pHead->extrude((AcDbRegion*)(regions[0]),headHeight,0);
	//delete regions[0];
	delete pPoly;
		
	// Now make the shaft...
	AcDbCircle *pCircle=new AcDbCircle(AcGePoint3d(0,0,headHeight),AcGeVector3d(0,0,1),shaftDiameter/2);
	shaftCurves.append(pCircle);
	es=AcDbRegion::createFromCurves(shaftCurves,shaftRegions);// Create the region...note:	static member function.
	es=pShaft->extrude((AcDbRegion*)(shaftRegions[0]),shaftLength,0);
	//delete shaftRegions[0];
	delete pCircle;
}
Example #17
0
void CreatePipe( const AcGePoint3d& start, const AcGePoint3d& end, const double& radius)
{
	acutPrintf(L"开始绘制管体\n");

	//得到线段的长度
	double length = start.distanceTo(end);
	if( length < 0.1 )
		return;

	acutPrintf(L"得到管体高度%lf\n",length);

	//绘制圆柱体
	AcDb3dSolid* p3dPipe = CreateCylinder(radius,length);
	if( p3dPipe == NULL )
		return;

	//得到线段与Z轴的垂直向量
	AcGeVector3d line3dVector(end.x - start.x,end.y - start.y, end.z-start.z);
	AcGeVector3d rotateVctor = line3dVector.crossProduct(AcGeVector3d::kZAxis);

	//得到旋转的角度
	double angle = -line3dVector.angleTo(AcGeVector3d::kZAxis);
	acutPrintf(L"得到旋转角度%lf\n",angle);

	//进行旋转
	AcGeMatrix3d rotateMatrix = AcGeMatrix3d::rotation( angle, rotateVctor, AcGePoint3d::kOrigin);
	p3dPipe->transformBy(rotateMatrix);
	
	//得到线段的中心点
	AcGePoint3d center(start.x + end.x, start.y + end.y, start.z + end.z); 
	center /= 2;
	acutPrintf(L"得到中心点[%lf][%lf][%lf]\n",center.x,center.y,center.z);

	//进行偏移
	AcGeMatrix3d moveMatrix;
	moveMatrix.setToTranslation(AcGeVector3d(center.x,center.y,center.z));

	p3dPipe->transformBy(moveMatrix);

	//加入到3D模型中
	PostToModelSpace(p3dPipe);

#ifdef DEBUG
	acutPrintf(L"插入中心线,用于矫正");

	AcDbLine *pLine = new AcDbLine(start, end);
    PostToModelSpace(pLine);
#endif
}
//addded by linlin 20050819
Acad::ErrorStatus  PDSphere::getVertices(int Precision, AcGePoint3dArray& vertexArray, AcGeVector3dArray &vertexNors) const
{  
	assertReadEnabled();

	int actPrecision__1 = Precision + 1;   
	int actPrecision___2__1 = Precision * 2 + 1;   
	vertexArray.setLogicalLength(actPrecision__1*actPrecision___2__1);
	vertexNors.setLogicalLength(actPrecision__1*actPrecision___2__1);


	AcGePoint3d varPt = m_ptCenter;        //变截面的中心点
	double varR = 0;
	double deltaAngle = PI / Precision;

	/////////////////////////////////////////////////////////////
	///////		begin the division						/////////
	AcGePoint3d point;

	for(int i = 0; i < actPrecision__1; ++i)
	{
		varPt.z=m_ptCenter.z- m_dRadius*cos(deltaAngle*i);

		varR = m_dRadius * sin(deltaAngle * i);
		int j;
		for(j = 0; j <actPrecision___2__1; ++j)
		{		  
			if(i == 0)
			{
				point = m_ptCenter;
				point.z -= m_dRadius;
			}
			else	 if(i == actPrecision__1)
			{ 
				point = m_ptCenter;
				point.z += m_dRadius;
			}         
			else
			{ 
				point=varPt;
				point.x += varR;
				point.rotateBy(deltaAngle * j, AcGeVector3d(0, 0, 1), varPt);
			}  	
			vertexArray[i*actPrecision___2__1+j]=point;
			vertexNors[i*actPrecision___2__1+j] = point - m_ptCenter;
		}
	}
	return Acad::eOk;
}//addded by linlin 20050819
// The following defines the constructor that accepts a point to be used as the
// centerpoint of the ellipse and the current UCS normal
// vector to be used as the normal for the ellipse.  It
// also initializes the radius ratio to a small value so
// that during selection of the major axis, the ellipse
// will appear as a line.  The prompt counter is also
// initialized to 0.
//
AsdkEllipseJig::AsdkEllipseJig(
    const AcGePoint3d& pt,
    const AcGeVector3d& normal)
: mCenterPt(pt),
  mNormal(normal),
  mRadiusRatio(0.00001),
  mPromptCounter(0)
{
	// Calculate a proper initial offset for the major axis from the current view extents.
	//
	struct resbuf rb;
	memset (&rb, 0, sizeof (struct resbuf));
	acedGetVar (_T("VIEWSIZE"), &rb);
	double majorAxisInitialOffset = rb.resval.rreal/1000.0;
	mMajorAxis = AcGeVector3d(majorAxisInitialOffset,0,0); // Offset the major axis a bit from the center point.
}
Acad::ErrorStatus PDSphere::getgrippoints(AcGePoint3dArray& gripArray) const
{
	assertReadEnabled();
	gripArray.append(m_ptCenter);

	gripArray.append(m_ptCenter + AcGeVector3d(1,0,0)*m_dRadius);
	gripArray.append(m_ptCenter + AcGeVector3d(0,1,0)*m_dRadius);
	gripArray.append(m_ptCenter + AcGeVector3d(0,0,1)*m_dRadius);

	gripArray.append(m_ptCenter + AcGeVector3d(-1,0,0)*m_dRadius);
	gripArray.append(m_ptCenter + AcGeVector3d(0,-1,0)*m_dRadius);
	gripArray.append(m_ptCenter + AcGeVector3d(0,0,-1)*m_dRadius);

	return Acad::eOk; 
}
Example #21
0
void drawCylinder()
{
	// 创建特定参数的圆柱体(实际上最后一个参数决定了实体是一个圆锥体还是圆柱) 
	AcDb3dSolid *pSolid = new AcDb3dSolid(); 
	pSolid->createFrustum(30, 10, 10, 10);

	// 将圆锥体添加到模型空间
	PostToModelSpace(pSolid);

	//创建切面
	AcGePlane plane;
    plane.set(AcGePoint3d(8,0,0),AcGeVector3d(1,0,0));

	//得到实体与切面相切的截面
	AcDbRegion *pSelectionRegion = NULL;
	pSolid->getSection(plane, pSelectionRegion);

	//将其移动到YZ平面
	moveToBottom(pSelectionRegion);
	
	//将截面加入到模型空间
	PostToModelSpace(pSelectionRegion);
}
/*!
* 根据已经输入到类中的参数,修正终点和偏心方向,使其值正确。
*
* @param none
*
* @return Acad::ErrorStatus  : 永远为Acad::eOk
*/
Acad::ErrorStatus PDEcone::CalActParameter()
{
    assertWriteEnabled();
    AcGeVector3d centerVect = (m_ptEnd - m_ptStart).normalize();
    if(centerVect.isZeroLength() && m_vect.isZeroLength())
    {
        m_ptEnd = m_ptStart + AcGeVector3d(0, 0, 1);
        m_vect.set(1, 0, 0);
    }
    else if(centerVect.isZeroLength())
    {
        AcGeVector3d Wy(0, 1, 0), Wz(0, 0, 1), Ax;// Ay;
        if (fabs(m_vect[X]) <1.0/64 && fabs(m_vect[Y])<1.0/64) 
            Ax = Wy.crossProduct(m_vect);
        else
            Ax = Wz.crossProduct(m_vect);
        Ax.normalize();
        //Ay = vect.crossProduct(Ax);
        //Ay.normalize();

        m_ptEnd = m_ptStart + Ax;
    }
    else if(m_vect.isZeroLength() || m_vect.isParallelTo(centerVect))
    {
        AcGeVector3d Wy(0, 1, 0), Wz(0, 0, 1), Ax;// Ay;
        if (fabs(centerVect[X]) <1.0/64 && fabs(centerVect[Y])<1.0/64) 
            Ax = Wy.crossProduct(centerVect);
        else
            Ax = Wz.crossProduct(centerVect);
        Ax.normalize();
        //Ay = vect.crossProduct(Ax);
        //Ay.normalize();

        m_vect = Ax;
    }
    return Acad::eOk;
}
////////////////////////////////////////////////////////////////////////////////
///////		将球在圆上分成m_nPrecision段,然后求相应处圆的半径	///////
///////		再将此圆分成m_nPrecision份。								////////
///////		所以共 (m_nPrecision+1)*(m_nPrecision+1)个点				////
////////////////////////////////////////////////////////////////////////////////
Acad::ErrorStatus  PDSphere::getVertices(int Precision, AcGePoint3dArray& vertexArray, 
										 AcGeIntArray &stdIdx, int &actPrecision) const

{  assertReadEnabled();

while(!vertexArray.isEmpty())
vertexArray.removeLast();

AcGeDoubleArray dividDbl;
getActDivid(Precision, dividDbl, stdIdx);

int actPrecision__1 = dividDbl.length();
int actPrecision___2__1 = (dividDbl.length() - 1) * 2 + 1;
actPrecision = actPrecision__1 - 1;
vertexArray.setLogicalLength(actPrecision__1*actPrecision___2__1);


AcGePoint3d varPt = m_ptCenter;        //变截面的中心点
double varR = 0;
double deltaAngle = PI / Precision;

/////////////////////////////////////////////////////////////
///////		begin the division						/////////
AcGeCubicSplineCurve3d varcur;
AcGePoint3d point;

for(int i = 0; i < actPrecision__1; ++i)
{
	varPt.z=m_ptCenter.z- m_dRadius*cos(deltaAngle*dividDbl[i]);

	double tt = m_dRadius * m_dRadius - (m_ptCenter.z - varPt.z) * 
		(m_ptCenter.z - varPt.z);
	if(tt < 0)
		tt = 0;
	varR = sqrt(tt);

	int j;
	for(j = 0; j <actPrecision__1; ++j)
	{		  
		if(i == 0)
		{
			point = m_ptCenter - AcGeVector3d(0, 0, 1) * m_dRadius;
			vertexArray[i*actPrecision___2__1+j]=point;
		}
		else if(i == actPrecision__1)
		{ 
			point = m_ptCenter + AcGeVector3d(0, 0, 1) * m_dRadius;
			vertexArray[i*actPrecision___2__1+j]=point;
		}         
		else
		{ 
			point=varPt + AcGeVector3d(1, 0, 0) * varR;
			point.rotateBy(deltaAngle * dividDbl[j], AcGeVector3d(0, 0, 1), varPt);
			vertexArray[i*actPrecision__1+j]=point;
		}  	
	}
	for(j = 1; j <actPrecision__1; ++j)
	{		  
		if(i == 0)
		{
			point = m_ptCenter - AcGeVector3d(0, 0, 1) * m_dRadius;
			vertexArray[i*actPrecision__1 + j + actPrecision]=point;
		}
		else if(i == actPrecision__1)
		{ 
			point = m_ptCenter + AcGeVector3d(0, 0, 1) * m_dRadius;
			vertexArray[i*actPrecision__1 + j + actPrecision]=point;
		}         
		else
		{ 
			point=varPt + AcGeVector3d(1, 0, 0) * varR;
			point.rotateBy(deltaAngle * dividDbl[j] + PI, AcGeVector3d(0, 0, 1), varPt);
			vertexArray[i*actPrecision__1 + j + actPrecision]=point;
		}  	
	}
}

return Acad::eOk;
}
Adesk::Boolean PDSphere::worldDraw(AcGiWorldDraw* mode)
#endif
{
	assertReadEnabled();
	//if(acdbHostApplicationServices()->workingDatabase()->useri1() == 1)
	//	return Adesk::kTrue;

#ifdef _USEAMODELER_
#ifdef _OBJECTARX2010_
	PDPrimary3D::subWorldDraw(mode);
#else
	PDPrimary3D::worldDraw(mode);
#endif
#endif
	if (mode->regenAbort()) {
		return Adesk::kTrue;
	}
#ifndef _USEAMODELER_
	int Precision = m_dDividPrecision;
	Adesk::Int16 nRating = getCalMaxPrecision();

	if(nRating == PRIMARY3D_SIMPLIZE_RATE1 ||
		nRating == PRIMARY3D_SIMPLIZE_RATE2)
	{
		Precision = (int)	(PI / acos(1.0 - mode->deviation(kAcGiMaxDevForCircle, m_ptCenter) / m_dRadius));
		if(Precision < PRIMARY3D_SIMPLIZE_SCALE)
		{
			if (nRating == PRIMARY3D_SIMPLIZE_RATE2)
			{
				AcGePoint3d pts[2];
				pts[0] = pts[1] = m_ptCenter;
				mode->geometry().polyline(2,pts);
			}
			else if (nRating == PRIMARY3D_SIMPLIZE_RATE1)
			{
				//Precision = PRIMARY3D_WIREFRAME_LINENUM4;
				//getVertices(Precision, pArray, vertexNors);
				//actPrecision__1 = Precision + 1;
				if(mode -> geometry().circle( m_ptCenter,m_dRadius,AcGeVector3d(1,0,0)))
					return Adesk::kTrue;
				if(mode -> geometry().circle( m_ptCenter,m_dRadius,AcGeVector3d(1,1,0)))
					return Adesk::kTrue;
				if(mode -> geometry().circle( m_ptCenter,m_dRadius,AcGeVector3d(0,1,0)))
					return Adesk::kTrue;
				if(mode -> geometry().circle( m_ptCenter,m_dRadius,AcGeVector3d(-1,1,0)))
				{
					return Adesk::kTrue;
				}
				if(mode -> geometry().circle( m_ptCenter,m_dRadius,AcGeVector3d(0,0,1)))
				{
					return Adesk::kTrue;
				}
				if(mode -> geometry().circle( m_ptCenter - AcGeVector3d(0, 0, 1) * m_dRadius * cos(PI / 4.0),m_dRadius * sin(PI / 4.0),AcGeVector3d(0,0,1)))
				{
					return Adesk::kTrue;
				}
				mode -> geometry().circle( m_ptCenter + AcGeVector3d(0, 0, 1) * m_dRadius *  cos(PI / 4.0),m_dRadius * sin(PI / 4.0),AcGeVector3d(0,0,1));
			}
			Adesk::kTrue;
		}
	}
#ifndef _ALWAYSSHOWWIRE_	
	switch(mode->regenType())
	{
	case kAcGiHideOrShadeCommand:
	case kAcGiRenderCommand:
#endif
		{
			int PreStep = 1;	
			AcGePoint3dArray pArray;
			AcGeVector3dArray vertexNors;
			int actPrecision__1 = Precision + 1;
			if(Precision < PRIMARY3D_WIREFRAME_LINENUM * 2)
				Precision = PRIMARY3D_WIREFRAME_LINENUM;
			else
			{
				if(Precision > m_dDividPrecision)
					Precision = m_dDividPrecision;
				PreStep = Precision / PRIMARY3D_WIREFRAME_LINENUM;
				Precision = PreStep * PRIMARY3D_WIREFRAME_LINENUM;
			}
			getVertices(Precision, pArray, vertexNors);
			actPrecision__1 = Precision + 1;
			AcGiEdgeData edgeData;
			int edgeDataLen = Precision * 2 * (actPrecision__1)* 2;
			Adesk::UInt8* edgeVisibility = new Adesk::UInt8[edgeDataLen];
			int i, j;
			for(i = 0; i < edgeDataLen; ++i)
				edgeVisibility[i] = kAcGiInvisible;//kAcGiSilhouette;

// 			int actPrecision___2 = Precision * 2;
// 			for (i =0; i < actPrecision__1; i += PreStep )
// 			{
// 				for(j = 0; j < actPrecision___2; j++)
// 				{
// 					edgeVisibility[i * actPrecision___2 + j] = kAcGiVisible;
// 				}
// 			}
// 			int PrecisionArc___Cir = actPrecision__1 * Precision * 2;
// 			for (i = 0; i < actPrecision___2; i += PreStep)
// 			{	
// 				for(j = 0; j < Precision;  j ++)
// 				{
// 					edgeVisibility[PrecisionArc___Cir + i * Precision + j] = kAcGiVisible;
// 				}
// 			}
			int actPrecision___2 = Precision * 2;
 			for (i = Precision / 4; i < Precision; i += Precision / 4 )
 			{
				for(j = 0; j < actPrecision___2; j++)
				{
					edgeVisibility[i * actPrecision___2 + j] = kAcGiVisible;
				}
 			}
			int PrecisionArc___Cir = actPrecision__1 * Precision * 2;
			for (i = 0; i < actPrecision___2; i += actPrecision___2 / 8)
			{	
				for(j = 0; j < Precision;  j ++)
				{
					edgeVisibility[PrecisionArc___Cir + i * Precision + j] = kAcGiVisible;
				}
			}

			edgeData.setVisibility(edgeVisibility);

			// 因为下面代码会导致球体的render效果图不正确,所以将其注释。
			//AcGiVertexData vertexData;
			//vertexData.setNormals(vertexNors.asArrayPtr());
			//vertexData.setOrientationFlag(kAcGiCounterClockwise);
			
			//添加球面的GS标记,与线框模型的GS标记分开处理
			//added by szw 2009.11.18 : begin
			int gsIndex = 8;
			mode->subEntityTraits().setSelectionMarker(gsIndex);
			//added by szw 2009.11.18 : end

			mode->geometry().mesh(actPrecision__1,actPrecision___2 + 1,pArray.asArrayPtr(),&edgeData/*, NULL, &vertexData*/);
			delete [] edgeVisibility;
		}
#ifndef _ALWAYSSHOWWIRE_
		break;
	case kAcGiStandardDisplay:
	case kAcGiSaveWorldDrawForR12:
	case kAcGiSaveWorldDrawForProxy:
#endif
		{
			//Precision = PRIMARY3D_WIREFRAME_LINENUM;
			//getVertices(Precision, pArray, vertexNors);
			//actPrecision__1 = Precision + 1;
			int gsIndex = 0;
			mode->subEntityTraits().setSelectionMarker(++gsIndex);
			if(mode -> geometry().circle( m_ptCenter,m_dRadius,AcGeVector3d(1,0,0)))
				return Adesk::kTrue;
			mode->subEntityTraits().setSelectionMarker(++gsIndex);
			if(mode -> geometry().circle( m_ptCenter,m_dRadius,AcGeVector3d(1,1,0)))
				return Adesk::kTrue;
			mode->subEntityTraits().setSelectionMarker(++gsIndex);
			if(mode -> geometry().circle( m_ptCenter,m_dRadius,AcGeVector3d(0,1,0)))
				return Adesk::kTrue;
			mode->subEntityTraits().setSelectionMarker(++gsIndex);
			if(mode -> geometry().circle( m_ptCenter,m_dRadius,AcGeVector3d(-1,1,0)))
			{
				return Adesk::kTrue;
			}
			mode->subEntityTraits().setSelectionMarker(++gsIndex);
			if(mode -> geometry().circle( m_ptCenter,m_dRadius,AcGeVector3d(0,0,1)))
			{
				return Adesk::kTrue;
			}
			mode->subEntityTraits().setSelectionMarker(++gsIndex);
			if(mode -> geometry().circle( m_ptCenter - AcGeVector3d(0, 0, 1) * m_dRadius * cos(PI / 4.0),m_dRadius * sin(PI / 4.0),AcGeVector3d(0,0,1)))
			{
				return Adesk::kTrue;
			}
			mode->subEntityTraits().setSelectionMarker(++gsIndex);
			mode -> geometry().circle( m_ptCenter + AcGeVector3d(0, 0, 1) * m_dRadius *  cos(PI / 4.0),m_dRadius * sin(PI / 4.0),AcGeVector3d(0,0,1));
		}
#ifndef _ALWAYSSHOWWIRE_
		break;
	default:
		break;
	}
#endif
#endif
	return Adesk::kTrue;
}//added by linlin 20050819
Example #25
0
//-----------------------------------------------------------------------------
// This function uses the AcEdJig mechanism to create and
// drag the polyline entity.  
//
void createRect()
{
    // First have the user select the first corner point.
    // We don't use the Jig for this because there is
    // nothing to see yet.
    //
    int stat, oldOrthoMode;
    int terminated = FALSE;
    char keyWord[10];

    plineInfo.m_elevHandSet = plineInfo.m_elev != 0.0; 

    // Since it looks quite strange to have orthomode on while trying to draw a
    // rectangle, we'll temporarily turn it off. Remembering the current setting
    // and resetting it when we leave.
    //
    oldOrthoMode = getIntSysVar(/*NOXLATE*/"ORTHOMODE");
    setIntSysVar(/*NOXLATE*/"ORTHOMODE", 0);

    // Flip to the graphic screen
    //
    acedGraphScr();

    // Add value line.
    if ((plineInfo.m_first != 0.0 && plineInfo.m_second != 0 && plineInfo.m_radius == 0.0) ||
        (plineInfo.m_elev != 0) ||(plineInfo.m_radius != 0)||(plineInfo.m_thick != 0) ||
        (plineInfo.m_width != 0))
    {
        acutPrintf("\nRectangle modes:  ");
        if (plineInfo.m_first != 0.0 && plineInfo.m_second != 0.
            && plineInfo.m_radius == 0.0)
        {
            acutPrintf("Chamfer=%.16q0 x %.16q0 ",
                plineInfo.m_first, plineInfo.m_second);
        }
        if (plineInfo.m_elev != 0.)
            acutPrintf("Elevation=%.16q0  ", plineInfo.m_elev);
        if (plineInfo.m_radius != 0.)
            acutPrintf("Fillet=%.16q0  ", plineInfo.m_radius);
        if (plineInfo.m_thick != 0.)
            acutPrintf("Thickness=%.16q0  ", plineInfo.m_thick);
        if (plineInfo.m_width != 0.)
            acutPrintf("Width=%.16q0  ", plineInfo.m_width);
        acutPrintf("\n");
    }

    while(!terminated) {
        // Main prompt for user input.
        //
        acedInitGet(RSG_NONULL, "Chamfer Elevation Fillet Thickness Width");
        if ((stat = acedGetPoint(NULL,
            "\nChamfer/Elevation/Fillet/Thickness/Width/<First corner>: ",
            asDblArray(plineInfo.m_topLeftCorner)))== RTKWORD)
        {
            acedGetInput(keyWord);
        }
        else {
            if (stat == RTCAN)
                terminated = TRUE;
            break;
        }
        switch(indexOfKeyWord(keyWord,
            "Chamfer Elevation Fillet Thickness Width"))
        {
    // Chamfer;
        case 0:
            // Retrieve the first chamfer distance. 
            //
            acutPrintf("\nFirst chamfer distance for rectangles <%.16q0>: ", 
                plineInfo.m_first == 0.0
                ? plineInfo.m_radius : plineInfo.m_first);
            if ((stat = acedGetDist(NULL, NULL, &plineInfo.m_first)) == RTCAN)
            {
                terminated = TRUE;
                break;
            } else if (stat == RTNONE && plineInfo.m_first == 0.0)
                plineInfo.m_second = plineInfo.m_radius;

            // Retrieve the second chamfer distance. 
            //
            acutPrintf("\nSecond chamfer distance for rectangles <%.16q0>: ", 
                plineInfo.m_second == 0.0
                ? plineInfo.m_first : plineInfo.m_second);
            if ((stat = acedGetDist(NULL, NULL, &plineInfo.m_second)) == RTCAN)
            {
                plineInfo.m_first = 0.0;
                plineInfo.m_second= 0.0;
                terminated = TRUE;
            } else {
                if (stat == RTNONE && plineInfo.m_second == 0.0)
                    plineInfo.m_second = plineInfo.m_first;
                // If we actually set the chamfer distances, then zero out the
                // radius and bulge.
                //
                plineInfo.m_radius = 0.0;
                plineInfo.m_bulge  = 0.0;
            }
            break;
    // Elevation;
        case 1:
            // Retrieve the radius to apply to the filleting of the corners. 
            // 
            acutPrintf("\nElevation for rectangles <%.16q0>: ",
                plineInfo.m_elev);
            if ((stat = acedGetDist(NULL, NULL, &plineInfo.m_elev)) == RTCAN)
                terminated = TRUE;
            plineInfo.m_elevHandSet = (plineInfo.m_elev == 0.0) ? FALSE : TRUE;
            break;
    // Fillet;
        case 2:
            // Retrieve the radius to apply to the filleting of the corners. 
            // If the user has previously used the chamfer, then use the 
            // first disance as the default for the radius.
            //
            acutPrintf("\nFillet radius for rectangles <%.16q0>: ", 
                plineInfo.m_radius == 0.0
                ? plineInfo.m_first : plineInfo.m_radius);
            if ((stat = acedGetDist(NULL, NULL, &plineInfo.m_radius)) == RTCAN)
            {
                terminated = TRUE;
            } else {
                if (stat == RTNONE && plineInfo.m_radius == 0.0)
                    plineInfo.m_radius = plineInfo.m_first;

                plineInfo.m_second = plineInfo.m_first = plineInfo.m_radius;

                // Bulge is tangent of 1/4 of the included angle.
                // We'll assume normal[Z] > 0. & clock wise for now, 
                // hence the '-'.
                plineInfo.m_bulge = -tan(PI / 8.0);
            }
            break;
    // Thickness;
        case 3:
            // Retrieve the thickness to apply to the polyline. 
            // 
            acutPrintf("\nThickness for rectangles <%.16q0>: ",
                plineInfo.m_thick);
            if ((stat = acedGetDist(NULL, NULL, &plineInfo.m_thick)) == RTCAN)
            {
                terminated = TRUE;
            }
            break;
    // Width;
        case 4:
            // Retrieve the width to apply to the polyline. 
            // 
            acutPrintf("\nWidth for rectangles <%.16q0>: ",
                plineInfo.m_width);
            if ((stat = acedGetDist(NULL, NULL, &plineInfo.m_width)) == RTCAN)
            {
                terminated = TRUE;
            }
            break;
    // Just in case;
        default:
              terminated = TRUE;
              break;
        }
    } 

    if (!terminated) {
        if (plineInfo.m_first != 0.0) {
            // If we are treating the corners, then calculate the unit vector
            // of the corners. Note for filleting the angle is 45 degrees. 
            //
            plineInfo.m_chamfDirUnitVec = AcGeVector3d(plineInfo.m_second,
                plineInfo.m_first, plineInfo.m_elev);
            univec(plineInfo.m_chamfDirUnitVec, plineInfo.m_chamfDirUnitVec);
        }
        // Create an AsdkRectangleJig object passing in the CRectInfo sturcture
        // filled during the users input
        //
        AsdkRectangleJig* pJig = new AsdkRectangleJig();

        // Now start up the jig to interactively get the opposite corner.
        //
        pJig->doRectangle();

        // Now delete the jig object since it's no longer needed
        //
        delete pJig;
    }

    // Be nice and reset it now.
    //
    setIntSysVar(/*NOXLATE*/"ORTHOMODE", oldOrthoMode);

    return;
}
Example #26
0
Acad::ErrorStatus
AsdkSmiley::moveGripPointsAt(
    const AcDbIntArray& indices,
    const AcGeVector3d& offset)
{
    assertWriteEnabled();

    AcGePoint3dArray eyearray;
    AcGePoint3d oldquad, newquad, newmouthcenter, newmouthbottom,
                smilecen, startpt, endpt, midpt, newpt;
    AcGeVector3d vecstart(0,0,0), vecend(0,0,0), newvec(0,0,0);

    eyes( eyearray );
    for( int i = 0; i < indices.length(); i++ ) {
        int idx = indices[i];
        switch( idx ) {

        // Stretch smiley center
        //
        case 0:
            setCenter( center() + offset );
            continue;

        // Stretch smiley radius
        //
        case 1:
            oldquad = center() + AcGeVector3d( radius(), 0, 0 );
            break;
        case 2:
            oldquad = center() + AcGeVector3d( 0, radius(), 0 );
            break;
        case 3:
            oldquad = center() - AcGeVector3d( radius(), 0, 0 );
            break;
        case 4:
            oldquad = center() - AcGeVector3d( 0, radius(), 0 );
            break;

        // Stretch smiley mouth
        //
        case 5:
            // Left hand edge of mouth
            //
            setMouthLeft( mouthLeft() + offset );
            ensureRadius();

            continue;

        case 6:
            // Right hand edge of mouth
            //
            setMouthRight( mouthRight() + offset );
            ensureRadius();

            continue;

        case 7:
            // Middle mouth chord
            //
            setMouth( mouthLeft() + offset, mouthBottom() + offset, mouthRight() + offset );
            ensureRadius();

            continue;

        case 8:
            // Bottom of mouth arc
            //
            setMouthBottom( mouthBottom() + offset );
            ensureRadius();

            continue;

        // Stretch smiley eyes
        //
        default:
            if(( eyearray.length() * 5 ) + 9 > idx ){
                
                // Get eye number, extracting it from the array
                //
                int eyepos = (int)(( idx - 9 ) / 5 );
                AcGePoint3d eyecen = eyearray.at( eyepos );
                
                // Handle the grip for the eye
                //
                int subidx = idx - 9;
                while ( subidx >= 5 ){ subidx -= 5; }
                switch( subidx ){

                // Stretch eye center
                //
                case 0:
                    // Keep the minimum eye height at zero
                    //
                    if( meyesheight+offset[Y] < 0 )
                        setEyesHeight( 0 );
                    else
                        setEyesHeight( meyesheight + offset[Y] );

                    // Keep the eyes from overlapping
                    //
                    if( eyecen[X] < center()[X] ){    // left eye
                        if( meyesapart - ( offset[X] * 2 ) < meyesize * 2 )
                            setEyesApart( meyesize * 2 );
                        else
                            setEyesApart( meyesapart - ( offset[X] * 2 ));
                    }
                    else {                          // right eye
                        if( meyesapart + ( offset[X] * 2 ) < meyesize * 2 )
                            setEyesApart( meyesize * 2 );
                        else
                            setEyesApart( meyesapart + ( offset[X] * 2));
                    }
                    ensureRadius();
                    continue;

                // Stretch eye radius
                //
                case 1:
                    oldquad = eyecen + AcGeVector3d( meyesize, 0, 0 );
                    break;
                case 2:
                    oldquad = eyecen + AcGeVector3d( 0, meyesize, 0 );
                    break;
                case 3:
                    oldquad = eyecen - AcGeVector3d( meyesize, 0, 0 );
                    break;
                case 4:
                    oldquad = eyecen - AcGeVector3d( 0, meyesize, 0 );
                    break;
                }
                newquad = oldquad + offset;
                
                // Keep eyes from touching
                //
                if( newquad.distanceTo( eyecen ) > meyesapart / 2 )
                    setEyeSize( meyesapart / 2 );
                else
                    setEyeSize( newquad.distanceTo( eyecen ));
                ensureRadius();
            }
            continue;
        }
        newquad = oldquad + offset;
        scaleRadius( newquad.distanceTo( center() ));
    }

    return Acad::eOk;
}
Example #27
0
Acad::ErrorStatus
AsdkSmiley::dxfInFields(AcDbDxfFiler *filer)
{
    assertWriteEnabled();

    struct resbuf rb;
    AcGePoint3d center, mouthleftpt, mouthbottompt, mouthrightpt;
    double radius;

    Acad::ErrorStatus es = AcDbEntity::dxfInFields( filer );

    if( Acad::eOk != es ) {
        return es;
    }

    // Check that we are at the correct subclass data
    //
    if( !filer->atSubclassData( kClassName )) {
        return Acad::eBadDxfSequence;
    }

    // First piece of data MUST be the version number
    if( Acad::eOk != ( es = filer->readItem( &rb ))) {
        return es;
    }

    if ( AcDb::kDxfReal != rb.restype ){
        ads_printf( "\nNo version information found in object definition." );
        return Acad::eMakeMeProxy;
    }

    // Check version first
    if ( rb.resval.rreal > 1.0 ){
        ads_printf( "\nNew version of AsdkSmiley object found (version %.1f): upgrade your Smiley.dbx to enable these objects.", rb.resval.rreal );
        return Acad::eMakeMeProxy;
    }

    // Set the normal's default value in case it's not in the
    // DXF information coming in
    //
    mnormal = AcGeVector3d( 0, 0, 1 ); // set default value:

    while( Acad::eOk == es ) {
        if( Acad::eOk == ( es = filer->readItem( &rb ))) {
            switch( rb.restype ) {
            case AcDb::kDxfXCoord:
                center.set( rb.resval.rpoint[X],
                            rb.resval.rpoint[Y],
                            rb.resval.rpoint[Z]);
                setCenter( center );
                break;
            case AcDb::kDxfReal+1:
                radius = rb.resval.rreal;
                setRadius( radius );
                break;
            case AcDb::kDxfNormalX:
                mnormal.set( rb.resval.rpoint[X],
                             rb.resval.rpoint[Y],
                             rb.resval.rpoint[Z]);
            case AcDb::kDxfReal+2:
                meyesapart = rb.resval.rreal;
                break;
            case AcDb::kDxfReal+3:
                meyesheight = rb.resval.rreal;
                break;
            case AcDb::kDxfReal+4:
                meyesize = rb.resval.rreal;
                break;
            case AcDb::kDxfXCoord+1:
                mouthleftpt.set( rb.resval.rpoint[X],
                                 rb.resval.rpoint[Y],
                                 rb.resval.rpoint[Z]);
                setMouthLeft( mouthleftpt );
                break;
            case AcDb::kDxfXCoord+2:
                mouthbottompt.set( rb.resval.rpoint[X],
                                   rb.resval.rpoint[Y],
                                   rb.resval.rpoint[Z]);
                setMouthBottom( mouthbottompt );
                break;
            case AcDb::kDxfXCoord+3:
                mouthrightpt.set( rb.resval.rpoint[X],
                                  rb.resval.rpoint[Y],
                                  rb.resval.rpoint[Z]);
                setMouthRight( mouthrightpt );
                break;
            }
        }
    }

    return filer->filerStatus();
}
void

createDwg()

{

    AcDbDatabase *pDb = new AcDbDatabase();

  

    AcDbBlockTable *pBtbl;

    pDb->getSymbolTable(pBtbl, AcDb::kForRead);



    AcDbBlockTableRecord *pBtblRcd;

    pBtbl->getAt(ACDB_MODEL_SPACE, pBtblRcd,

        AcDb::kForWrite);

    pBtbl->close();



    AcDbCircle *pCir1 = new AcDbCircle(AcGePoint3d(1,1,1),

                                       AcGeVector3d(0,0,1),

                                       1.0),

               *pCir2 = new AcDbCircle(AcGePoint3d(4,4,4),

                                       AcGeVector3d(0,0,1),

                                       2.0);



    pBtblRcd->appendAcDbEntity(pCir1);

    pCir1->close();

    

    pBtblRcd->appendAcDbEntity(pCir2);

    pCir2->close();

    pBtblRcd->close();



    // AcDbDatabase::saveAs() does NOT automatically

    // append a DWG file extension, so it

    // must be specified.

    //

    pDb->saveAs(_T("./test1.dwg"));

    delete pDb;

}
Example #29
0
AsdkEmployee::AsdkEmployee() : AcDbEllipse (AcGePoint3d (), AcGeVector3d (0, 0, 1), AcGeVector3d (1, 0, 0), 1)
{
	// TODO: do your initialization.
	m_firstName =m_lastName =NULL ;
}
void asdktest3 () {
    //----- Create a line and a circle (memory only)
    AcDbLine *pLine =new AcDbLine (AcGePoint3d (), AcGePoint3d (100, 100, -100)) ;
    AcDbCircle *pCircle =new AcDbCircle (AcGePoint3d (50, 50, 0), AcGeVector3d (0, 0, 1) , 25.0) ;

    //----- Create a region from the circle
    AcDbVoidPtrArray arr1, arr2 ;
    arr1.append (pCircle) ;
    AcDbRegion::createFromCurves (arr1, arr2) ;
    AcDbRegion *pRegion =(AcDbRegion *)arr2.at (0) ;
    delete pCircle ;

    //----- Add the line and the region objects to the collector
    //----- NB: Remember those object are memory objects only
    AsdkHlrCollector collector ;
    collector.setDeleteState (true) ;
    collector.addEntity (pLine) ;
    collector.addEntity (pRegion) ;

    //----- Process hidden line removal
    AsdkHlrEngine hlr (AcGePoint3d (50, 50,0), AcGeVector3d (0, 0, 1), kEntity | kBlock | kShowAll | kProject | kHonorInternals) ;
    hlr.run (collector) ;

    //----- To easily see the result, we do append resulting entities to the current database
    //----- and use the color convention used in command 'TEST1'
    int n =collector.mOutputData.logicalLength () ;
    for ( int i =0 ; i < n ; i++ ) {
        AsdkHlrData *p =collector.mOutputData [i] ;

        AcDbEntity *pEnt =p->getResultEntity () ;
        AsdkHlrData::Visibility vis =p->getVisibility () ;
        if ( vis == AsdkHlrData::kVisible )
            pEnt->setColorIndex (1) ;
        else
            pEnt->setColorIndex (5) ;
        AcDbObjectId id ;
        if ( postToDatabase (NULL, pEnt, id) != Acad::eOk ) {
            acutPrintf (_T("Failed to add entity to current space.\n")) ;
            break ;
        }

        //----- Entity originator path
        AcDbObjectIdArray ids =p->getObjectIds () ;
        if ( ids.logicalLength () > 0 ) {
            acutPrintf (ACRX_T("\n%ld, "), pEnt->objectId ().asOldId ()) ;
            for ( int j =0 ; j < ids.logicalLength () ; j++ ) {
                acutPrintf (ACRX_T("%ld, "), ids.at (j).asOldId ()) ;
            }
        }

        pEnt->close () ;
    }
}