bool SketchSolverCircArc::checkPreUpdateValue()
{
	if (NULL == vcsBody())
		return false;
	VCSMMatrix3d vMat = vcsBody()->transform();
	AcGeMatrix3d aMat = GeConv::toAcGeMatrix3d(vMat);

	VCSMCircle3d vcsCir = m_pVcsVarCircle->circle3d();
	double newRadius = vcsCir.radius();
	// No allow degenerated circle during solving
	if (std::fabs(newRadius) <= m_pContext->tol())
		return false;

	//if (std::fabs(newRadius) > 1000.0)
	//	return false;
	// No allow degenerated circle arc
	if (m_geometry->bounded())
	{
		AcGePoint3d startPt = startPoint()->updatedPosition();
		AcGePoint3d endPt = endPoint()->updatedPosition();
		
		if (startPt.isEqualTo(endPt, m_pContext->tolEx()))
			return false;
	}

	return true;
}
Exemple #2
0
Acad::ErrorStatus
AcRectJig::setPlane()
{
    // Acquire current UCS transformation matrix.
    // We save the matrix for later use.
    //
    acdbUcsMatrix(mUcsToWcsMat);
    mWcsToUcsMat = mUcsToWcsMat.inverse();

    // Get data from user coordinate system.
    //
    AcGePoint3d orgPt;
    AcGeVector3d xAxis, yAxis, zAxis;
    mUcsToWcsMat.getCoordSystem(orgPt, xAxis, yAxis, zAxis);

    // Get the current elevation w.r.t current UCS, w.r.t the current space.
    //
    struct resbuf rb;
    ads_getvar(/*MSG0*/"CVPORT", &rb);
    double elev;
    if (rb.resval.rint == 1)
        elev = mpDb->pelevation();  // Paper space
    else
        elev = mpDb->elevation();   // Model space

    // Convert elevation from UCS to WCS.
    //
    orgPt += elev * zAxis;
    mElevation = zAxis.dotProduct(orgPt.asVector());
    mNormal = zAxis;
    mHorizDir = xAxis;
    mVertDir = mNormal.crossProduct(mHorizDir);
    return Acad::eOk;
}
static AcGePoint3d ProjectPointOfTwoLine( const AcGePoint3d& spt1, const AcGePoint3d& ept1,
        const AcGePoint3d& spt2, const AcGePoint3d& ept2,
        const AcGePoint3d& pt )
{
    // 计算点在直线spt1->ept1上的比例关系
    double c = pt.distanceTo( spt1 ) / ept1.distanceTo( spt1 );

    acutPrintf( _T( "\n比例c:%.4f" ), c );
    acutPrintf( _T( "\nspt->(%.3f, %.3f), ept->(%.3f, %.3f)" ), spt2.x, spt2.y, ept2.x, ept2.y );
    AcGeVector3d v = ept2 - spt2;
    return spt2 + v * c;
}
//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
Exemple #5
0
static int extractEntityInfo(struct resbuf *rb,
                             int&          sel_method,
                             ads_name      ename,
                             ads_name      subname,
                             short&	   marker,
                             AcGePoint3d&  pickpnt,
                             AcGeVector3d& pickvec)
{
   if ( rb == NULL || rb->restype != RTLB )
   {
     assert(0);
     return 0;
   }
   
   // Get the selection method.
   //
   rb = rb->rbnext;  // Bump up to the selection method, always after RTLB.
   sel_method = rb->resval.rint;

   // Get the first ename (could be either the actual entity name or
   // subentity name).
   //
   rb = rb->rbnext;  // Bump up to the first name, always after sel method.
   ename[0] = rb->resval.rlname[0];
   ename[1] = rb->resval.rlname[1];
   subname[0] = rb->resval.rlname[0];
   subname[1] = rb->resval.rlname[1];

   // Get marker info.
   //
   rb = rb->rbnext;
   marker = rb->resval.rint;

   // Get the pick location and vector, only for PICK and FENCE.  For FENCE,
   // we take the first intersection with the entity as the pick location.
   //
   if ( sel_method == PICK_METH || 
        sel_method == FENCE_METH)
   {
      rb = rb->rbnext;  // Skip to RTLB for pick location.
      rb = rb->rbnext;  // Skip to point description info.
      rb = rb->rbnext;  // Skip to the pick location.
      pickpnt.set( rb->resval.rpoint[0],
                   rb->resval.rpoint[1],
                   rb->resval.rpoint[2] );

      rb = rb->rbnext;  // Will be normal vector if we're not in XY view.
                        // Otherwise, it'll be an RTLE for pick location.

      if ( rb->restype == RT3DPOINT )
      {
        pickvec.set( rb->resval.rpoint[0],
                     rb->resval.rpoint[1],
                     rb->resval.rpoint[2] );
        rb = rb->rbnext;  // Make it point to the RTLE for the pick location.
      }
   }

   return CONTINUE;
}
Exemple #6
0
//-----------------------------------------------------------------------------
// This function is called by the drag function in order to
// aquire a sample input
//
AcEdJig::DragStatus AsdkRectangleJig::sampler()
{
    DragStatus stat = kNormal;

    setUserInputControls((UserInputControls)
        (   AcEdJig::kNoNegativeResponseAccepted
         |  AcEdJig::kNoZeroResponseAccepted)
        );
   
    setSpecialCursorType(kCrosshair);

    stat = acquirePoint(m_BottomRightCorner, plineInfo.m_topLeftCorner);  

    // Now project the point at the crosshairs to the ECS of the 
    // polyline being drawn.
    //
    AcGePlane planeParallelToUCS(m_TopLeftCorner, m_vecUnitZ);    
    m_BottomRightCorner = m_BottomRightCorner.project(planeParallelToUCS, m_vecUnitZ);

    // If the newly acquired point is the same as it was
    // in the last sample, then we return kNoChange so that
    // AsdkRectangleJig::update() will not be called and the
    // last update call will be able to finish thus allowing
    // the polyline to fully elaborate.
    //
    if (samplerCorner != m_BottomRightCorner) {
        // m_BottomRightCorner will be used to update the remaining corners
        // in AsdkRectangleJig::update() below.
        //
        samplerCorner = m_BottomRightCorner;        
    } else if (stat == AcEdJig::kNormal)
        return AcEdJig::kNoChange;

    return stat;
}
Exemple #7
0
void AcRectangle::list() const
{
    assertReadEnabled();
	AcDbEntity::list();

    AcGeMatrix3d ucsToWcsMat, wcsToUcsMat;
    acdbUcsMatrix(ucsToWcsMat);
    wcsToUcsMat = ucsToWcsMat.inverse();
    AcGePoint3d cenPt = mCenter;
    cenPt.transformBy(wcsToUcsMat);

    acutPrintf(_T("\nWidth:  %f"), mWidth);
    acutPrintf(_T("\nHeight: %f"), mHeight);
    acutPrintf(_T("\nCenter: X= %f, Y= %f, Z= %f"), cenPt.x, cenPt.y, cenPt.z);
    acutPrintf(_T("\nNormal: X= %f, Y= %f, Z= %f"), mNormal.x, mNormal.y, mNormal.z);
    acutPrintf("\n");
}
MaterialJig::MaterialJig(
    const AcGePoint3d& center,
    const AcDbObjectId& materialId)
{
    mpMaterialEnt = (AsdkMaterial*)AsdkMaterial::desc()->create();
    mpMaterialEnt->setDatabaseDefaults();
    mpMaterialEnt->setMaterialId(materialId);

    AcGeMatrix3d translateMat;
    translateMat.setToTranslation(center.asVector());
    mpMaterialEnt->setTransform(translateMat);
}
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
}
Exemple #10
0
AcDbObjectId CArxHelper::CreateText(const CString& strText, const AcGePoint3d& pt1, const AcGePoint3d& pt2, double dDist, BOOL bUp /* = TRUE */)
{
	AcDbObjectId textId = AcDbObjectId::kNull;
	AcGePoint3d pt = (pt1 + pt2.asVector()) / 2.0;
	AcDbMText* pMText = new AcDbMText();
	pMText->setContents(strText);
	pMText->setLocation(pt);

	pMText->setDirection(pt2-pt1);

	textId = AddToCAD(pMText,4);

	AcDbExtents extents;
	pMText->getGeomExtents(extents);
	AcGeVector3d vect = (pt2-pt1).normal() * (extents.maxPoint().x - extents.minPoint().x) / 2.0;
	AcGeMatrix3d xform = AcGeMatrix3d::translation(-vect);
	acdbOpenObject(pMText,textId,AcDb::kForWrite);
	pMText->transformBy(xform);
	pMText->close();
	return textId;
}
void
ArxDbgUtils::getUcsToWcsOriginMatrix(AcGeMatrix3d& m,
                        const AcGePoint3d& wcsBasePt, AcDbDatabase* db)
{
	ASSERT(db != NULL);

    AcGeMatrix3d tmpMat;

	if (acdbUcsMatrix(tmpMat, db)) {
		AcGePoint3d origin;
		AcGeVector3d xDir, yDir, zDir;

		tmpMat.getCoordSystem(origin, xDir, yDir, zDir);
		origin += wcsBasePt.asVector();

	    m.setToAlignCoordSys(origin, xDir, yDir, zDir,
            AcGePoint3d::kOrigin, AcGeVector3d::kXAxis,
            AcGeVector3d::kYAxis, AcGeVector3d::kZAxis);
	}
	else {
		ASSERT(0);
        m = AcGeMatrix3d::kIdentity;
	}
}
Exemple #12
0
static double CaclWSGas( double q, const AcGePoint3d& spt, const AcGePoint3d& ept )
{
    return q / ( spt.distanceTo( ept ) );
}
////////////////////////////////////////////////////////////////////////////////
///////		将球在圆上分成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;
}
void Additional_Class::Get_ArcMiddle( AcDbObjectId PolyLineId, AcGePoint3dArray &Middle_List,AcGePoint3dArray &CenterListInput, LINEINFO &ArcInfoRList, LINEINFO &ArcInfoAList )
{
	double PI=3.1415926535897932384626433832795;
	AcDbEntity *pEnt_Temp = NULL;
	Acad::ErrorStatus es = acdbOpenAcDbEntity(pEnt_Temp, PolyLineId, AcDb::kForRead);
	if (es != Acad::eOk)
	{
		acutPrintf(_T("\nOPEN ENTITY ERROR"));
		return;
	}
	if (!pEnt_Temp->isKindOf(AcDbPolyline::desc()))
	{
		acutPrintf(_T("\nENTITY NOT POLYLINE"));
		return;
	}
	AcDbPolyline *pPolyLine = AcDbPolyline::cast(pEnt_Temp);
	int num = pPolyLine->numVerts();
	AcGePoint3d Start_temp_PT,End_temp_PT;
	AcGePoint3dArray Center_List;
	for (int index=0; index<num; index++)
	{
		if (pPolyLine->segType(index) == AcDbPolyline::kArc)
		{
			AcGeCircArc2d tempArc;
			pPolyLine->getArcSegAt(index,tempArc);
			AcGePoint2d CenterPoint;
			CenterPoint = tempArc.center();
			AcGePoint3d CenterPoint3d;
			CenterPoint3d.set(CenterPoint.x, CenterPoint.y, 0);
			Center_List.append(CenterPoint3d);
			AcGePoint3d Start_temp_PT, End_temp_PT;
			Start_temp_PT.set(tempArc.startPoint().x,tempArc.startPoint().y,0);
			End_temp_PT.set(tempArc.endPoint().x,tempArc.endPoint().y,0);
			AcGeVector3d tempVec;
			tempVec = End_temp_PT - Start_temp_PT;
			double tempVec_Len = tempVec.length();
			tempVec.normalize();
			tempVec = tempVec*(tempVec_Len/2);
			AcGeVector3d CenterVec;
			CenterVec = Start_temp_PT - CenterPoint3d;
			CenterVec = CenterVec + tempVec;
			AcGeLine2d CenterLine2d;
			AcGePoint3d Middle_Pt_OnLine;
			Middle_Pt_OnLine = CenterPoint3d+CenterVec;
			AcGePoint2d middle2d;
			middle2d.set(Middle_Pt_OnLine.x, Middle_Pt_OnLine.y);
			CenterLine2d.set(CenterPoint, middle2d);

			int s;
			AcGePoint2d MiddlePT, pt2;
			tempArc.intersectWith(CenterLine2d, s,  MiddlePT, pt2);
			AcGePoint3d MiddlePoint;
			MiddlePoint.set(MiddlePT.x,MiddlePT.y,0);
			Middle_List.append(MiddlePoint);

			double StartAngle = tempArc.startAng();
			double EndAngle = tempArc.endAng();
			double Angle = EndAngle-StartAngle;
			Angle = (180/PI)*Angle;
			double Radius = tempArc.radius();
			CString tempStr_Angle,tempStr_Radius,sita,du,banjing;
			sita = "θ=";
			du = "°";
			banjing = "R=";
			tempStr_Angle.Format(_T("%.1f"),Angle);
			tempStr_Angle = sita+tempStr_Angle+du;
			tempStr_Radius.Format(_T("%.1f"),Radius);
			tempStr_Radius = banjing + tempStr_Radius;
			ArcInfoRList.push_back(tempStr_Radius);
			ArcInfoAList.push_back(tempStr_Angle);
		}
	}
	CenterListInput = Center_List;
}
void
ArxDbgDbAdeskLogo::drawSingleCaliper(AcGiCommonDraw* drawContext, AcGePoint3d* pts,
                                   ArxDbgDbAdeskLogoStyle* lStyle)
{
	AcGeVector3d viewDir;
	AcGiViewportDraw* vportDraw = AcGiViewportDraw::cast(drawContext);
	if (vportDraw)
		viewDir = vportDraw->viewport().viewDir();
	else {
			// cheat and get viewdir for current viewport from the system variable
		AcGePoint3d tmpPt;
		getSysVar(_T("viewdir"), tmpPt);
		viewDir = tmpPt.asVector();
	}

    if (viewDir == AcGeVector3d::kZAxis) {
            // if solid fill is on we have to save the current state
            // first and then restore it.  If we don't, then if we 
            // are drawn as part of some other entity, we'll mess it up
            // for them.
        if (lStyle && (lStyle->isSolidFill()) && (drawContext->isDragging() == Adesk::kFalse)) {
            AcGiFillType savedFillType = drawContext->subEntityTraits().fillType();
            drawContext->subEntityTraits().setFillType(kAcGiFillAlways);
            drawContext->rawGeometry()->polygon(5, pts);
            drawContext->subEntityTraits().setFillType(savedFillType);
        }
        else {
            drawContext->rawGeometry()->polygon(5, pts);
        }
    }
    else {
        AcGePoint3d allPts[10];
        allPts[0] = pts[0];
        allPts[1] = pts[1];
        allPts[2] = pts[2];
        allPts[3] = pts[3];
        allPts[4] = pts[4];

        allPts[5].set(pts[0].x, pts[0].y, 1.0);
        allPts[6].set(pts[1].x, pts[1].y, 1.0);
        allPts[7].set(pts[2].x, pts[2].y, 1.0);
        allPts[8].set(pts[3].x, pts[3].y, 1.0);
        allPts[9].set(pts[4].x, pts[4].y, 1.0);

        Adesk::Int32 faceList[37];

            // bottom face
        faceList[0]  = 5;   // number of vertices
        faceList[1]  = 0;
        faceList[2]  = 1;
        faceList[3]  = 2;
        faceList[4]  = 3;
        faceList[5]  = 4;

            // top face
        faceList[6]  = 5;   // number of vertices
        faceList[7]  = 5;
        faceList[8]  = 6;
        faceList[9]  = 7;
        faceList[10] = 8;
        faceList[11] = 9;

            // inside left face
        faceList[12] = 4;   // number of vertices
        faceList[13] = 0;
        faceList[14] = 1;
        faceList[15] = 6;
        faceList[16] = 5;

            // inside right face
        faceList[17] = 4;   // number of vertices
        faceList[18] = 1;
        faceList[19] = 2;
        faceList[20] = 7;
        faceList[21] = 6;

            // outside right face
        faceList[22] = 4;   // number of vertices
        faceList[23] = 2;
        faceList[24] = 3;
        faceList[25] = 8;
        faceList[26] = 7;

            // outside top face
        faceList[27] = 4;   // number of vertices
        faceList[28] = 3;
        faceList[29] = 4;
        faceList[30] = 9;
        faceList[31] = 8;

            // outside left face
        faceList[32] = 4;   // number of vertices
        faceList[33] = 4;
        faceList[34] = 0;
        faceList[35] = 5;
        faceList[36] = 9;

        drawContext->rawGeometry()->shell(10, allPts, 37, faceList);
    }
}
double PDEcone::getHeight() const
{
	assertReadEnabled();
	AcGePoint3d orthoPt = getStartPtOrthoInEntPtPlane();
	return orthoPt.distanceTo(m_ptStart);
}