找回密码
 立即注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

楼主: rave

[日积月累]:Arx函数集,网友自制

 火... [复制链接]
发表于 2003-9-6 12:02:28 | 显示全部楼层

我认为PointIsInPolygon函数有问题

根据射线法求交点个数,偶数-区域外,奇数-区域内
但如果射线刚好通过顶点,产生偶数,却在区域内。
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

已领礼包: 1个

财富等级: 恭喜发财

发表于 2003-9-8 08:33:58 | 显示全部楼层
谢谢!你说的很对,可以加一个判断,判断交点的位置,以排除你所说的情况
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

发表于 2003-10-13 11:50:25 | 显示全部楼层

BOOL GetSSExtents(ads_name ss, ads_point &maxpt, ads_point &minpt)

igetGeomExtents(extent)在哪里有定义????


for(int i=0;igetGeomExtents(extent);
                if(pt1[X]extent.minPoint()[X]||pt2[Y]>extent.minPoint()[Y])
                        pt2=extent.minPoint();
                pEnt->close();
        }
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

发表于 2003-10-14 14:46:58 | 显示全部楼层
自己写的小东西,拿来共享。希望对大家有帮助。
//添加Hatch


AcDbObjectId CreateHatch(
AcDbObjectId dbOId,
char cLayer[],
char cPattern[] = "SOLID",
int nColor = 256,
double dAngle = 0.0,
double dScale = 1.0,
AcDbDatabase * pDbDatab = acdbHostApplicationServices()->workingDatabase())
{
        AcCmColor                                CmC;
        AcDbObjectId                        DbOId;
        AcDbObjectIdArray                DbOIdA(0, 2);
        AcDbBlockTable                        * pDbBT;
        AcDbBlockTableRecord        * pDbBTR;
        AcGeVector3d                        normal(0.0, 0.0, 1.0);

        DbOIdA.append(dbOId);

        AcDbHatch* pDbHat = new AcDbHatch();

    pDbHat->setDatabaseDefaults();

    pDbHat->setAssociative(Adesk::kTrue);    // BUG: doesn't do squat! have to set the reactor yourself to get associativity!

    pDbHat->appendLoop(AcDbHatch::kExternal, DbOIdA);

    pDbHat->setPatternScale(dScale);

    pDbHat->setPatternAngle(dAngle);

        pDbHat->setPattern(AcDbHatch::kPreDefined, cPattern);

    pDbHat->setNormal(normal);

        pDbHat->evaluateHatch();        // crucial call or nothing gets displayed!

        pDbDatab->getSymbolTable(pDbBT, AcDb::kForRead);

        pDbBT->getAt(ACDB_MODEL_SPACE, pDbBTR, AcDb::kForWrite);

        pDbBTR->appendAcDbEntity(DbOId, pDbHat);

        pDbHat->setLayer(cLayer);

        CmC.setColorIndex(nColor);

        ((AcDbEntity *)pDbHat)->setColor(CmC);

        pDbBT->close();

        pDbBTR->close();

        pDbHat->close();

        return DbOId;

}
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

发表于 2003-10-18 19:20:35 | 显示全部楼层
这个问题我前些日子遇到的
是初学吗?呵呵
画完最后一个点的时候加个空格就可以了
acedCommand(。。。。。。RTSTR, "",0);
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

发表于 2003-11-15 14:51:38 | 显示全部楼层
以下函数用自己的方法实现了AutoCAD中用:"Donut"命令绘制圆环的功能!

//************************************************************************
//函数名称:drawDonutAtPoint
//函数类型:void
//返回值:
//功能描述:
//函数作者:Darcy
//创建日期:2003-x-x
//参数列表:
//变量名:nPt            变量类型:const AcGePoint2d&         变量说明:中点
//变量名:nRadius     变量类型:const double                     变量说明:半径
//************************************************************************
void drawDonutAtPoint(const AcGePoint2d& nPt,const double nRadius)
{
        AcGePoint2d pt;
        AcDbPolyline * pPline = new AcDbPolyline(2);

        pt = nPt;

        pt.x -= nRadius;

        pPline->addVertexAt( 0 , pt , 1.0 , nRadius*2.0 , nRadius*2.0);

        pt.x += nRadius * 2.0;

        pPline->addVertexAt( 1 , pt , 1.0 , nRadius*2.0 , nRadius*2.0);
       
        pPline->setClosed(Adesk::kTrue);

                     //添加到当前数据库:
        addToCurrentSpaceAndClose(pPline);

}
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

发表于 2003-11-17 19:07:43 | 显示全部楼层
我也跟几贴,得点爱心币,互相交流
//得到指定层上的所有实体
Acad::ErrorStatus CDrawFunction::getAllEntity(AcDbDatabase *pDb,AcDbObjectIdArray& IdArr,
                                                                                          const AcArray<CString>& layerNameArr)
{
        Acad::ErrorStatus es=Acad::eOk;
        ASSERT(pDb);
        if(pDb==NULL)
                return Acad::eInvalidInput;
        AcDbBlockTable *pBlkTable=NULL;
        if((es=pDb->getBlockTable(pBlkTable,AcDb::kForRead))!=Acad::eOk)//打开块表
        {
                acedAlert("打开块表失败");
                return es;
        }
        AcDbBlockTableRecord *pBlkTableRecord=NULL;
        if((es=pBlkTable->getAt(ACDB_MODEL_SPACE,pBlkTableRecord,AcDb::kForRead))!=Acad::eOk)//打开块表记录
        {
                acedAlert("打开块表记录失败");
                pBlkTable->close();
                return es;
        }
        pBlkTable->close();//关闭块表
       
        AcDbBlockTableRecordIterator *pIterator=NULL;                       //创建叠代器
        if((es=pBlkTableRecord->newIterator(pIterator))!=Acad::eOk)
        {
                pBlkTableRecord->close();
                return es;
        }

        CAcModuleResourceOverride resoverride;
        CProgressDlg progress;
        progress.Create();
        progress.SetPos(0);
        progress.SetWindowText("正在检测图形中所有实体...");

        for(pIterator->start();!pIterator->done();pIterator->step())//遍历整个数据库
        {
                AcDbEntity *entity=NULL;
                es=pIterator->getEntity(entity,AcDb::kForRead);        //打开实体

                if(es==Acad::eLockViolation)
                {
                        acedAlert("内存锁定");
                }
                else if(es==Acad::eWasOpenForWrite)
                {
                        acedAlert("实体以写方式打开");
                }
                else if(es==Acad::eWasOpenForRead)
                {
                        acedAlert("实体以读方式打开");
                }
                else
                {       
                        if(layerNameArr.contains(entity->layer()))
                                IdArr.append(entity->objectId());
                        entity->close();
                }
                progress.StepIt();
        }
        delete pIterator;pIterator=NULL;
        pBlkTableRecord->close();
        acutPrintf("eend");
        return es;
}

//得到指定层上指定颜色的所有实体
Acad::ErrorStatus CDrawFunction::getAllEntity(AcDbDatabase *pDb,AcDbObjectIdArray& IdArr,
                                                                                          const AcArray<CString>& layerNameArr,Adesk::UInt16 colorIndex)
{
        Acad::ErrorStatus es=Acad::eOk;
        ASSERT(pDb);
        if(pDb==NULL)
                return Acad::eInvalidInput;
        AcDbBlockTable *pBlkTable=NULL;
        if((es=pDb->getBlockTable(pBlkTable,AcDb::kForRead))!=Acad::eOk)//打开块表
        {
                acedAlert("打开块表失败");
                return es;
        }
        AcDbBlockTableRecord *pBlkTableRecord=NULL;
        if((es=pBlkTable->getAt(ACDB_MODEL_SPACE,pBlkTableRecord,AcDb::kForRead))!=Acad::eOk)//打开块表记录
        {
                acedAlert("打开块表记录失败");
                pBlkTable->close();
                return es;
        }
        pBlkTable->close();//关闭块表
       
        AcDbBlockTableRecordIterator *pIterator=NULL;                       //创建叠代器
        if((es=pBlkTableRecord->newIterator(pIterator))!=Acad::eOk)
        {
                pBlkTableRecord->close();
                return es;
        }
       
        CAcModuleResourceOverride resoverride;
        CProgressDlg progress;
        progress.Create();
        progress.SetPos(0);
        progress.SetWindowText("正在检测图形中所有实体...");
       
        for(pIterator->start();!pIterator->done();pIterator->step())//遍历整个数据库
        {
                AcDbEntity *entity=NULL;
                if((es=pIterator->getEntity(entity,AcDb::kForRead))!=Acad::eOk)//打开实体
                {
                        delete pIterator;pIterator=NULL;
                        pBlkTableRecord->close();
                        return es;
                }
                if(layerNameArr.contains(entity->layer())&&entity->colorIndex()==colorIndex)
                        IdArr.append(entity->objectId());
                entity->close();
                progress.StepIt();
        }
        delete pIterator;pIterator=NULL;
        pBlkTableRecord->close();
        return es;
}

//得到图形中所有的层
Acad::ErrorStatus  CDrawFunction::getAllLayerName(AcDbDatabase *pDb,CStringArray& layerArray)
{
        Acad::ErrorStatus es=Acad::eOk;
        if(pDb==NULL)
                return Acad::eInvalidInput;
        layerArray.RemoveAll();
        AcDbLayerTable *pLayerTable=NULL;
        if((es=pDb->getSymbolTable(pLayerTable,AcDb::kForRead))!=Acad::eOk)
        {
                pLayerTable->close();
                return es;
        }
        //创建一个层表迭代器
        AcDbLayerTableIterator *pLayerTableIterator;
        pLayerTable->newIterator(pLayerTableIterator);
        pLayerTable->close();
       
        char *pLayerName=NULL;
        CString name;
        for(int i=0;!pLayerTableIterator->done();pLayerTableIterator->step(),i++)
        {
                AcDbLayerTableRecord *pLayerTableRecord=NULL;
                pLayerTableIterator->getRecord(pLayerTableRecord,AcDb::kForRead);
                pLayerTableRecord->getName(pLayerName);
                name.Format("%s",pLayerName);
                pLayerTableRecord->close();
                layerArray.Add(name);
               
        }
       
        if(pLayerName) acutDelString(pLayerName);
        delete pLayerTableIterator;pLayerTableIterator=NULL;
        return es;
}


//*************根据线形名得到线型ID********************//
//******************************************************//
BOOL  CDrawFunction::getLinetypeIdFromString(const char* str, AcDbObjectId& id)
{
//----查找安装目录----//
        CString AcadInstallPath;
        FindAcadInstallPath(AcadInstallPath);
        CString File=AcadInstallPath+"\\linetype\\user.lin";
//-----查找完毕--------//       
        ASSERT(str!=NULL);
        AcDbLinetypeTable *pLinetypeTable;
    acdbHostApplicationServices()->workingDatabase()->getSymbolTable(pLinetypeTable, AcDb::kForRead);
           Acad::ErrorStatus  mess;
        mess=pLinetypeTable->getAt(str,id);
        if(mess==Acad::eKeyNotFound||mess==Acad::ePermanentlyErased)
        {
                pLinetypeTable->close();
                Acad::ErrorStatus  error;
       
                error=acdbLoadLineTypeFile(str,File.GetBuffer(0),acdbHostApplicationServices()->workingDatabase());
                if(error==Acad::eNullObjectPointer)
                {
                        AcDbLinetypeTable *pLinetypeTable;
                    acdbHostApplicationServices()->workingDatabase()->getSymbolTable(pLinetypeTable, AcDb::kForRead);
                        pLinetypeTable->getAt("CONTINUOUS", id);
                        pLinetypeTable->close();
                        return FALSE;
                }
                else if(error==Acad::eFileSystemErr)
                {
                        AfxMessageBox("the specified file cannot be opened");
                        return FALSE;
                }
                else if(error==Acad::eUndefinedLineType)
                {
                        AcDbLinetypeTable *pLinetypeTable;
                    acdbHostApplicationServices()->workingDatabase()->getSymbolTable(pLinetypeTable, AcDb::kForRead);
                        AfxMessageBox("the linetype name specified by ltname is not found in the file");
                        pLinetypeTable->getAt("CONTINUOUS", id);
                        pLinetypeTable->close();
                        return TRUE;
                }
                AcDbLinetypeTable *pLinetypeTable;
                acdbHostApplicationServices()->workingDatabase()->getSymbolTable(pLinetypeTable, AcDb::kForRead);
                pLinetypeTable->getAt(str,id);
                pLinetypeTable->close();
                return TRUE;
        }
     pLinetypeTable->close();
         return TRUE;
}



void CDrawFunction::FindAcadInstallPath(CString &AcadInstallPath)
{
        //查找样式目录安装路径
        TCHAR AcadPath[255];
        HKEY hKey;
        if(RegOpenKeyEx(HKEY_LOCAL_MACHINE,TEXT("SOFTWARE\\线路处开发组\\RDS2002\\1.00"),0,KEY_QUERY_VALUE,&hKey)!=ERROR_SUCCESS)
        {
                ::AfxMessageBox("注册路径不对");
                return ;
        }
        DWORD dwDataType=REG_SZ;
        DWORD dwLength=255;
        LONG lRet=RegQueryValueEx(hKey,TEXT("path"),NULL,NULL,(LPBYTE)AcadPath,&dwLength);
        RegCloseKey(hKey);
        if(lRet!=ERROR_SUCCESS)
        {
                acutPrintf("Read failed\n");
                return ;
        }
//-----查找完毕--------//
        AcadInstallPath.Format("%s",AcadPath);
}

AcDbObjectId CDrawFunction::createTextStyle(CString fontName,CString bigFontName,CString textStyleName)
{
        AcGiTextStyle *TextStyle=new AcGiTextStyle
                (fontName,
                bigFontName,
                0,
                0.67,
                0,
                0,
                Adesk::kFalse,
                Adesk::kFalse,
                Adesk::kFalse,
                Adesk::kFalse,
                Adesk::kFalse,
                textStyleName);      //字体名
        AcDbObjectId textStyleId;
        toAcDbTextStyle(*TextStyle,textStyleId);
    return textStyleId;
}



//*******************wuweifan2002.12.12*************************//
//********************插入多行文本***************************//
//************************************************************//
AcDbObjectId CDrawFunction::createMutiText(AcGePoint3d BasePoint,AcDb::TextHorzMode hMode,AcDb::TextVertMode vMode,CString Text,double texthight,double widthfactor,double angle,int color,CString smallFontName,CString bigFontName,CString layerName)
{
        ASSERT(Text!=NULL);
        AcDbMText *pMText=new AcDbMText();
        if(pMText==NULL)
                throw Acad::eOutOfMemory;
        AcDbObjectId TextStyleId;
        TextStyleId=createTextStyle(smallFontName,bigFontName,"xianlu");
        pMText->setTextStyle(TextStyleId);
        pMText->setContents(Text.GetBuffer(Text.GetLength()));
        pMText->setTextHeight(texthight);
        pMText->setRotation(angle);
        pMText->setLineSpacingFactor(0.8);
        pMText->setColorIndex(color);
        if(layerName!="")
                pMText->setLayer(layerName.GetBuffer(0));
        AcDbObjectId MTextId;
        addToModelSpace(MTextId, pMText);
        pMText->close();
        return MTextId;
}

//********************插入单行文本***************************//
//************************************************************//
AcDbObjectId CDrawFunction::createtextAll(AcGePoint3d pt,char *text,AcDb::TextHorzMode hMode,AcDb::TextVertMode vMode,double hight,double widthFactor,double rotation,int color,CString smallFontName,CString bigFontName,CString layerName)
{
        ASSERT(text!=NULL);
        AcDbText *pText=NULL;
        pText=new AcDbText;
        if(pText==NULL)
                throw Acad::eOutOfMemory;
        AcDbObjectId textId;
        textId=createTextStyle(smallFontName,bigFontName,"xianlu");
        pText->setTextStyle(textId);
        pText->setTextString(text);
        pText->setHeight(hight);
        pText->setColorIndex(color);
        pText->setRotation(rotation);
        pText->setWidthFactor(widthFactor);
        pText->setPosition(pt);
        if(layerName!="")
                pText->setLayer(layerName.GetBuffer(0));
        addToModelSpace(textId, pText);
    pText->close();
        return textId;
}

//设置尺寸文本样式
void CDrawFunction::setDimTextStyle(AcDbObjectId dimId,AcDbObjectId textStyleId,
                                                        int colorIndex,double textHeight,double textScator,
                                                        double textGap,bool align)
{
        AcDbDimension *dimText;
        acdbOpenObject(dimText,dimId,AcDb::kForWrite);
        dimText->setDimtxsty(textStyleId);  //文本字体DIMTXSTY
        AcCmColor color;
        color.setColorIndex(colorIndex);
        dimText->setDimclrt(color);//文本颜色DIMCLRT
        dimText->setDimtxt(textHeight); //文本高度DIMTXT
        dimText->setDimtfac(textScator);//文本高宽比DIMTFAC
        dimText->setDimgap(textGap);//文本距尺寸距离DIMGAP
        dimText->setDimtoh(align);//文本标注DIMTOH
        dimText->close();
}

//设置尺寸延伸线类型
Acad::ErrorStatus CDrawFunction::setextensionlineStyle(AcDbObjectId dimId,int colorIndex,double length,
                                                                  double offLength,bool v1,bool v2)
{
        Acad::ErrorStatus es=Acad::eOk;
        AcDbDimension *dimText=NULL;
        if((es=acdbOpenObject(dimText,dimId,AcDb::kForWrite))!=Acad::eOk)
                return es;
        AcCmColor color;
        if((es=color.setColorIndex(colorIndex))!=Acad::eOk)
        {
                dimText->close();return es;
        }
        dimText->setDimclre(color);//设置颜色DIMCLRE
        dimText->setDimexe(length);//设置超出长度DIMEXE
        dimText->setDimexo(offLength);//尺寸偏离长度DIMEXO
        dimText->setDimse1(v1);//是否注第一条线DIMSE1
        dimText->setDimse2(v2);//是否注第二条线DIMSE2
        dimText->close();
        return es;
}
//绘制对齐尺寸线
AcDbObjectId  CDrawFunction::drawDimension(AcGePoint3d xLine1Point,AcGePoint3d xLine2Point,
                        double fwj,int direction,double distance,CString dimText,CString m_cLayerName)
{

        AcDbAlignedDimension *dimension=new AcDbAlignedDimension;
        AcGePoint3d dimLinePoint;
//        CCalcuMethod *calcu=new CCalcuMethod();
//        calcu->calEndZbSelf(xLine2Point,distance*direction,fwj,dimLinePoint);
//        delete calcu;calcu=NULL;
        dimension->setXLine1Point(xLine1Point);
        dimension->setDimLinePoint(dimLinePoint);
        dimension->setXLine2Point(xLine2Point);
        dimension->setDimensionText(dimText.GetBuffer(0));
        dimension->setLayer(m_cLayerName.GetBuffer(0));
        AcDbObjectId dimId;
        addToModelSpace(dimId,dimension);
        dimension->close();
        return dimId;
}

Acad::ErrorStatus CDrawFunction::createLine(AcDbObjectId &lineId,AcGePoint3d startPt,AcGePoint3d endPt,int color,CString Layer,char *linetype)
{
        Acad::ErrorStatus es=Acad::eOk;
        ASSERT(linetype!=NULL);
        AcDbLine *pLine = new AcDbLine(startPt, endPt);
        if((es=pLine->setColorIndex(color))!=Acad::eOk)
        {
                pLine->close();return es;
        }
        if(Layer!="")
        {
                if(pLine->setLayer(Layer)==Acad::eKeyNotFound  \
                        ||pLine->setLayer(Layer)==Acad::eDeletedEntry )
                {
                        createNewLayer(Layer);
                        if((es=pLine->setLayer(Layer.GetBuffer(0)))!=Acad::eOk)
                        {
                                pLine->close();return es;
                        }
                }
        }
        if(linetype!=NULL)
        {
                AcDbObjectId lineTypeId;
                if(getLinetypeIdFromString(linetype,lineTypeId))
                {
                        if((es=pLine->setLinetype(lineTypeId))!=Acad::eOk)
                        {
                                pLine->close();return es;
                        }
                        if((es=pLine->setLinetypeScale(1))!=Acad::eOk)
                        {
                                pLine->close();return es;
                        }
                }
        }
        es=addToModelSpace(lineId,pLine);
        return es;
}

Acad::ErrorStatus CDrawFunction::createCircle(AcDbObjectId& circleId,AcGePoint3d center,double radius,int color,CString layer)
{
        Acad::ErrorStatus es=Acad::eOk;
        AcGeVector3d normal(0,0,1);
        AcDbCircle *circle=new AcDbCircle(center,normal,radius);
        if((es=circle->setColorIndex(color))!=Acad::eOk)
        {
                circle->close();return es;
        }
        if(layer!="")
        {
                if(circle->setLayer(layer)==Acad::eKeyNotFound  \
                        ||circle->setLayer(layer)==Acad::eDeletedEntry )
                {
                        createNewLayer(layer);
                        if((es=circle->setLayer(layer.GetBuffer(0)))!=Acad::eOk)
                        {
                                circle->close();return es;
                        }
                }
        }
        es=addToModelSpace(circleId,circle);
        return es;
}


Acad::ErrorStatus CDrawFunction::DrawPolyline(AcDbObjectId&  polylineId, AcGePoint3dArray ptArr, int Color, double Width,bool IsClose,CString Layer,char *linetype)
{
        Acad::ErrorStatus es=Acad::eOk;       
        AcDb2dPolyline *pNewPline;
        if(IsClose)pNewPline=new AcDb2dPolyline(AcDb::k2dSimplePoly,ptArr,0,Adesk::kTrue,Width,Width);
        else pNewPline=new AcDb2dPolyline(AcDb::k2dSimplePoly,ptArr,0,Adesk::kFalse,Width,Width);
        if((es=pNewPline->setColorIndex(Color))!=Acad::eOk)
        {
                pNewPline->close();return es;
        }
        if(Layer!="")
        {
                if(pNewPline->setLayer(Layer)==Acad::eKeyNotFound  \
                        ||pNewPline->setLayer(Layer)==Acad::eDeletedEntry )
                {
                        createNewLayer(Layer);
                        if((es=pNewPline->setLayer(Layer))!=Acad::eOk)
                        {
                                pNewPline->close();return es;
                        }
                }
        }
        if(linetype!=NULL)
        {
                AcDbObjectId lineTypeId;
                if(getLinetypeIdFromString(linetype,lineTypeId))
                {
                        if((es=pNewPline->setLinetype(lineTypeId))!=Acad::eOk)
                        {
                                        pNewPline->close();return es;
                        }
                        if((es=pNewPline->setLinetypeScale(1))!=Acad::eOk)
                        {
                                        pNewPline->close();return es;
                        }
                }
        }
        if(!pNewPline->isLinetypeGenerationOn())
        {
                if((es=pNewPline->setLinetypeGenerationOn())!=Acad::eOk)
                {
                        pNewPline->close();return es;
                }
        }
        es=addToModelSpace(polylineId,pNewPline);
        return es;
}

Acad::ErrorStatus CDrawFunction::DrawSplinePolyline(AcDbObjectId&  polylineId, AcGePoint3dArray ptArr, int Color, double Width,bool IsClose,CString Layer,char *linetype)
{
        Acad::ErrorStatus es=Acad::eOk;       
        AcDb2dPolyline *pNewPline;
        if(IsClose)pNewPline=new AcDb2dPolyline(AcDb::k2dQuadSplinePoly,ptArr,0,Adesk::kTrue,Width,Width);
        else pNewPline=new AcDb2dPolyline(AcDb::k2dQuadSplinePoly,ptArr,0,Adesk::kFalse,Width,Width);
        if((es=pNewPline->setColorIndex(Color))!=Acad::eOk)
        {
                pNewPline->close();return es;
        }
        if(Layer!="")
        {
                if(pNewPline->setLayer(Layer)==Acad::eKeyNotFound  \
                        ||pNewPline->setLayer(Layer)==Acad::eDeletedEntry )
                {
                        createNewLayer(Layer);
                        if((es=pNewPline->setLayer(Layer))!=Acad::eOk)
                        {
                                pNewPline->close();return es;
                        }
                }
        }
        if(linetype!=NULL)
        {
                AcDbObjectId lineTypeId;
                if(getLinetypeIdFromString(linetype,lineTypeId))
                {
                        if((es=pNewPline->setLinetype(lineTypeId))!=Acad::eOk)
                        {
                                pNewPline->close();return es;
                        }
                        if((es=pNewPline->setLinetypeScale(1))!=Acad::eOk)
                        {
                                pNewPline->close();return es;
                        }
                }
        }
        if(!pNewPline->isLinetypeGenerationOn())
        {
                if((es=pNewPline->setLinetypeGenerationOn())!=Acad::eOk)
                {
                        pNewPline->close();return es;
                }
        }
        es=addToModelSpace(polylineId,pNewPline);
        return es;
}


//得到文本边界
void CDrawFunction::getTextBoundary(AcDbObjectId  objectId,double offset,AcDbObjectId &textBoundaryId)
{
        AcDbExtents Ext;
        AcDbEntity *pEnt;
        acdbOpenObject(pEnt,objectId,AcDb::kForWrite);
        if(pEnt->isKindOf(AcDbText::desc()))
        {
                AcDbText *pText=AcDbText::cast(pEnt);
                AcGePoint3d basePoint;
                basePoint=pText->position();
                double rotateAngle=pText->rotation();
                pText->setRotation(0);
                pText->getGeomExtents(Ext);
                AcGePoint3d minPt,maxPt;
                minPt=Ext.minPoint();
                maxPt=Ext.maxPoint();
                AcGePoint3dArray pointArray;
                AcGePoint3d point1,point2,point3,point4;
                point1.x=minPt.x-offset;point1.y=minPt.y-offset;point1.z=0;
                pointArray.append(point1);
                point2.x=maxPt.x+offset;point2.y=minPt.y-offset;point2.z=0;
                pointArray.append(point2);
                point3.x=maxPt.x+offset;point3.y=maxPt.y+offset;point3.z=0;
                pointArray.append(point3);
                point4.x=minPt.x-offset;point4.y=maxPt.y+offset;point4.z=0;
                pointArray.append(point4);
                DrawPolyline(textBoundaryId,pointArray,1,0,TRUE,"0","CONTINUOUS");
                AcGeMatrix3d matrix;
                AcGeVector3d axis;
                ident_init(matrix);       
                axis.set(0,0,1);
                matrix=matrix.rotation(rotateAngle,axis,basePoint);  //旋转矩阵
                AcDbEntity *BounEnt;
                acdbOpenObject(BounEnt,textBoundaryId,AcDb::kForWrite);
                BounEnt->transformBy(matrix);
                BounEnt->close();
                pText->setRotation(rotateAngle);
        }
        else if(pEnt->isKindOf(AcDbMText::desc()))
        {
                AcDbMText *pMtext=AcDbMText::cast(pEnt);
                AcGePoint3d basePoint;
                basePoint=pMtext->location();
                double rotateAngle=pMtext->rotation();
                pMtext->setRotation(0);
                AcGePoint3dArray pointArray;
                double width=pMtext->actualWidth();
                double height=pMtext->actualHeight();
                AcGePoint3d point1,point2,point3,point4;
                point1.x=basePoint.x-offset;point1.y=basePoint.y+offset;point1.z=0;
                pointArray.append(point1);
                point2.x=basePoint.x+width+offset;point2.y=basePoint.y+offset;point2.z=0;
                pointArray.append(point2);
                point3.x=basePoint.x+width+offset;point3.y=basePoint.y-height-offset;point3.z=0;
                pointArray.append(point3);
                point4.x=basePoint.x-offset;point4.y=basePoint.y-height-offset;point4.z=0;
                pointArray.append(point4);
                DrawPolyline(textBoundaryId,pointArray,1,0,TRUE,"0","CONTINUOUS");
                AcGeMatrix3d matrix;
                AcGeVector3d axis;
                ident_init(matrix);       
                axis.set(0,0,1);
                matrix=matrix.rotation(rotateAngle,axis,basePoint);  //旋转矩阵
                AcDbEntity *BounEnt;
                acdbOpenObject(BounEnt,textBoundaryId,AcDb::kForWrite);
                BounEnt->transformBy(matrix);
                BounEnt->close();
                pMtext->setRotation(rotateAngle);
        }
        pEnt->close();
        return;
}


AcDbObjectId CDrawFunction::createNewLayer(CString LayerName)
{
        AcDbLayerTable *LayerTable;
        acdbHostApplicationServices()->workingDatabase()->getSymbolTable(LayerTable,AcDb::kForWrite);
        AcDbObjectId LayerId;
        if(!LayerTable->has(LayerName))
        {
                AcDbLayerTableRecord *LayerTableRecord=new AcDbLayerTableRecord;
                LayerTableRecord->setName(LayerName);
                LayerTable->add(LayerId,LayerTableRecord);
                LayerTableRecord->close();
        }
        else
        {
                LayerTable->getAt(LayerName,LayerId,FALSE);
        }
        LayerTable->close();
        return LayerId;
}

bool CDrawFunction::insertBlock(AcDbObjectId &newEntId,CString BlockName,double fwj,AcGePoint3d basePoint,double scalex,
                                                CString Text1,CString Text2,CString Text3,
                                                int text1color,int text2color,int text3color,
                                                double text1height,double text2height,double text3height,
                                                double text1scator,double text2scator,double text3scator,
                                                CString littleFont,CString bigFont,CString layerName,double dx,double dy)        //每块可有三个属性定义
{
          AcDbObjectId blockId;
        double x,y;
        x=basePoint[X];
        y=basePoint[Y];
        bool a=AcDbSymbolUtilities::hasBlock(BlockName.GetBuffer(BlockName.GetLength()),acdbHostApplicationServices()->workingDatabase());
        if(!a)return FALSE;
        AcDbSymbolUtilities::getBlockId(blockId,BlockName.GetBuffer(BlockName.GetLength()),acdbHostApplicationServices()->workingDatabase());
        AcDbBlockReference *pBlkRef = new AcDbBlockReference;
//        pBlkRef->treatAsAcDbBlockRefForExplode();///////////
    pBlkRef->setBlockTableRecord(blockId);
        pBlkRef->setLayer(layerName);//设置层/////////////////////////////
    struct resbuf to, from;
    from.restype = RTSHORT;
    from.resval.rint = 1;    // UCS
    to.restype = RTSHORT;
    to.resval.rint = 0;      // WCS
    AcGeVector3d normal(0, 0, 1);
    acedTrans(&(normal.x), &from, &to, Adesk::kTrue,&(normal.x));
        AcGeScale3d scale(scalex,scalex,scalex);
        pBlkRef->setScaleFactors(scale);
        AcGePoint3d insertPoint;
        insertPoint=basePoint;
    pBlkRef->setPosition(basePoint);
    pBlkRef->setRotation(fwj);
    pBlkRef->setNormal(normal);
        pBlkRef->setColorIndex(text1color);//按文本颜色设置改变颜色
        pBlkRef->setLayer(layerName);
        AcDbBlockTable *pBlockTable;
        acdbHostApplicationServices()->workingDatabase()->getBlockTable(pBlockTable,AcDb::kForWrite);
        AcDbBlockTableRecord *pBlockTableRecord;
        pBlockTable->getAt(ACDB_MODEL_SPACE, pBlockTableRecord,AcDb::kForWrite);
        pBlockTableRecord->appendAcDbEntity(newEntId, pBlkRef);
        pBlockTable->close();
        pBlockTableRecord->close();

    acdbOpenObject(pBlockTableRecord, blockId, AcDb::kForRead);
        AcDbBlockTableRecordIterator *pIterator;
    pBlockTableRecord->newIterator(pIterator);
    AcDbEntity *pEnt;
        AcDbAttributeDefinition *pAttdef;
    for (pIterator->start(); !pIterator->done();pIterator->step())
    {
                pIterator->getEntity(pEnt, AcDb::kForWrite);
                //pEnt->setColorIndex(text1color);//按文本颜色设置改变颜色
                //pEnt->setLayer(layerName);//设置层
                if(pEnt->isKindOf(AcDbAttributeDefinition::desc()))
                {
                        pAttdef = AcDbAttributeDefinition::cast(pEnt);
                        if (pAttdef != NULL && !pAttdef->isConstant())
                        {
                                AcDbAttribute *pAtt = new AcDbAttribute();
                                pAtt->setPropertiesFrom(pAttdef);
                                pAtt->setInvisible(pAttdef->isInvisible());
                                AcGePoint3d alignpoint;
                                alignpoint=pAttdef->alignmentPoint();
                                alignpoint+=pBlkRef->position().asVector();
                                AcDbObjectId TextStyleId;
                                TextStyleId=createTextStyle(littleFont,bigFont,"xianlu");
                                pAtt->setTextStyle(TextStyleId);
                                pAtt->setHeight(pAttdef->height());
                                pAtt->setTag("Tag");
                                pAtt->setFieldLength(25);
                                pAtt->setLayer(layerName);
                                char *pStr = pAttdef->tag();
                                pAtt->setTag(pStr);
                                free(pStr);
                                pAtt->setFieldLength(pAttdef->fieldLength());
                                if(strcmp(pAtt->tag(),"标注1")==0)
                                {
                                        AcGePoint3d gg(dx/scalex,0,0);
                                        alignpoint=alignpoint+gg.asVector();
                                        AcGeVector3d vet(0,0,1);
                                        alignpoint=alignpoint.scaleBy(scalex,insertPoint);
                                        alignpoint=alignpoint.rotateBy(fwj,vet,insertPoint);
                                        pAtt->setTextString(Text1.GetBuffer(Text2.GetLength()));
                                        pAtt->setRotation(PI/2+fwj);
                                        pAtt->setHorizontalMode(AcDb::kTextCenter);
                                        pAtt->setVerticalMode(AcDb::kTextBottom);
                                        pAtt->setAlignmentPoint(alignpoint);
                                        pAtt->setColorIndex(text1color);
                                        pAtt->setHeight(text1height*scalex);
                                        pAtt->setWidthFactor(text1scator);
                                }
                                if(strcmp(pAtt->tag(),"标注2")==0)
                                {
                                        AcGePoint3d gg(dx/scalex,0,0);
                                        alignpoint=alignpoint-gg.asVector();
                                        AcGeVector3d vet(0,0,1);
                                        alignpoint=alignpoint.scaleBy(scalex,insertPoint);
                                        alignpoint=alignpoint.rotateBy(fwj,vet,insertPoint);
                                        pAtt->setTextString(Text2.GetBuffer(Text2.GetLength()));
                                        pAtt->setRotation(PI/2+fwj);
                                        pAtt->setHorizontalMode(AcDb::kTextCenter);
                                        pAtt->setVerticalMode(AcDb::kTextBottom);
                                        pAtt->setAlignmentPoint(alignpoint);
                                        pAtt->setColorIndex(text2color);
                                        pAtt->setHeight(text2height*scalex);
                                        pAtt->setWidthFactor(text2scator);
                                }
                                if(strcmp(pAtt->tag(),"标注3")==0)
                                {
                                        AcGePoint3d gg(0,dy/scalex,0);
                                        alignpoint=alignpoint+gg.asVector();
                                        AcGeVector3d vet(0,0,1);
                                        alignpoint=alignpoint.scaleBy(scalex,insertPoint);
                                        alignpoint=alignpoint.rotateBy(fwj,vet,insertPoint);
                                        pAtt->setTextString(Text3.GetBuffer(Text3.GetLength()));
                                        pAtt->setRotation(fwj);
                                        pAtt->setHorizontalMode(AcDb::kTextCenter);
                                        pAtt->setVerticalMode(AcDb::kTextBottom);
                                        pAtt->setAlignmentPoint(alignpoint);
                                        pAtt->setColorIndex(text3color);
                                        pAtt->setHeight(text3height*scalex);
                                        pAtt->setWidthFactor(text3scator);
                                }
                                AcDbObjectId attId;
                                pBlkRef->appendAttribute(attId, pAtt);
                                pAtt->close();
                        }
                }
        //        pEnt->setColorIndex(text1color);//按文本颜色设置改变颜色
        pEnt->close();
    }
    delete pIterator;
        pBlockTableRecord->close();
    pBlkRef->close();
        return TRUE;
}


//遍历多义线顶点坐标
Acad::ErrorStatus CDrawFunction::IteratorPolyline(AcDbObjectId polylineID,AcGePoint3dArray& pointArray)
{
        Acad::ErrorStatus es=Acad::eOk;
        AcDbObject* pObject=NULL;
        AcDbPolyline *pline=NULL;
        if((es=acdbOpenObject(pObject,polylineID,AcDb::kForRead))!=Acad::eOk)
                return es;
        if(!pObject->isKindOf(AcDbPolyline::desc()))
        {
                pObject->close();
                return Acad::eInvalidInput;
        }
        pline=AcDbPolyline::cast(pObject);
        int num=pline->numVerts();
        for (int i=0; i< num; i++)
        {
                AcGePoint3d temPt;
        if((es=pline->getPointAt(i, temPt))!=Acad::eOk)
                {
                        pObject->close();
                        return Acad::eInvalidInput;
                }
                pointArray.append(temPt);
        }
        pObject->close();
        return es;
}


Acad::ErrorStatus CDrawFunction::createGroup(CString groupname,AcDbObjectIdArray IdArray)
{
        Acad::ErrorStatus es=Acad::eOk;
        AcDbDictionary *pGroupDict=NULL;
        AcDbGroup *pGroup=NULL;
        if((es=acdbHostApplicationServices()->workingDatabase()->getGroupDictionary(pGroupDict,AcDb::kForWrite))!=Acad::eOk)
        {
                return es;
        }
        AcDbObjectId groupId;
        es=pGroupDict->getAt(groupname,groupId);
        if(es==Acad::eInvalidKey)
        {
                acutPrintf("\n输入的词典名无效!");
                pGroupDict->close();
                return es;
        }
        else if(es==Acad::eKeyNotFound)
        {
                pGroup=new AcDbGroup("GroupDiscription");
                if((es=pGroupDict->setAt(groupname,pGroup,groupId))!=Acad::eOk)
                {
                        pGroup->close();pGroupDict->close();return es;
                }
        }
        else if(es==Acad::eOk )
        {
                if((es=acdbOpenObject(pGroup,groupId,AcDb::kForWrite))!=Acad::eOk)
                {
                        pGroupDict->close();return es;
                }
        }
        for(int i=0;i<IdArray.length();i++)
                pGroup->append(IdArray);
        pGroup->setSelectable(FALSE);
        pGroupDict->close();
        pGroup->close();
        return es;
}

double CDrawFunction::getTextLength(AcDbObjectId textId)
{
        Acad::ErrorStatus es=Acad::eOk;
        AcDbEntity *pEnt=NULL;
        if((es=acdbOpenObject(pEnt,textId,AcDb::kForRead))!=Acad::eOk)
                return -1;
        AcDbExtents Ext;
        pEnt->getGeomExtents(Ext);
        pEnt->close();
        AcGePoint3d minPt,maxPt;
        minPt=Ext.minPoint();
        maxPt=Ext.maxPoint();
        return acutDistance(asDblArray(minPt),asDblArray(maxPt));
}



void CDrawFunction::highlightEdge(const AcDbObjectId& objId,const int marker)
{
        char dummy[133];
        AcDbEntity *pEnt;
        acdbOpenObject(pEnt,objId,AcDb::kForRead);
        AcGePoint3d pickpnt;
        AcGeMatrix3d xform;
        int numIds;
        AcDbFullSubentPath *subentIds;
        pEnt->getSubentPathsAtGsMarker(AcDb::kEdgeSubentType,marker,pickpnt,xform,numIds,subentIds);
        if(numIds>0)
        {
                pEnt->highlight(subentIds[0]);
                ads_getstring(0,"\npress<return>to continue...",dummy);
                pEnt->unhighlight(subentIds[0]);

        }
        delete []subentIds;
        pEnt->close();
}


Acad::ErrorStatus CDrawFunction::readXrecord(CString dictName,CString xrecordName,CString &message)
{
        AcDbDictionary *pDict=NULL;
        pDict=openDictionaryForRead(dictName,acdbHostApplicationServices()->workingDatabase());
    if(pDict)
    {
                AcDbXrecord *pXrec;
                pDict->getAt(xrecordName, (AcDbObject*&) pXrec,AcDb::kForRead);
                pDict->close();
                struct resbuf *pRbList;
                pXrec->rbChain(&pRbList);
                pXrec->close();
                message=pRbList->resval.rstring;
                acutRelRb(pRbList);
                return Acad::eOk;
    }
        else
        {
                return Acad::eInvalidInput;
        }
}


//**********************扩展记录操作(2002.12.12)***************//
//****************打开扩展记录为写******************************//
//**************************************************************//
AcDbDictionary*  CDrawFunction::openDictionaryForWrite(LPCTSTR dictName,
                                                                                                                 bool createIfNotFound,AcDbDictionary* parentDict)
{
    ASSERT(dictName != NULL);
    ASSERT(parentDict != NULL);
    ASSERT(parentDict->isWriteEnabled());   
    AcDbDictionary* dict = NULL;
    AcDbObject* obj;
    Acad::ErrorStatus es;
    es = parentDict->getAt(dictName, obj, AcDb::kForWrite);
    if (es == Acad::eOk)
        {
        dict = AcDbDictionary::cast(obj);
    }
    else if (es == Acad::eKeyNotFound)
        {
        if (createIfNotFound)
                {
            dict = new AcDbDictionary;
            AcDbObjectId dictId;
            es = parentDict->setAt(dictName, dict, dictId);
            if (es != Acad::eOk)
                        {
                  delete dict;dict = NULL;
            }
        }
    }
    return dict;
}
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

发表于 2003-11-30 20:45:14 | 显示全部楼层
还不错,不过贴的这些东西都太基础了
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

发表于 2003-12-2 15:36:14 | 显示全部楼层
互相交流,是在是太好了。
人人为我,我为人人。
大家共同进步。

  /******************************************************************************/
  /* 関数名   :        SetOSMODE                                                                                                                */
  /* 機能     :        設置OSMODE                                                                                                                */
  /* 入力引数 :        int                                                        OSMODE値                                                        */
  /* 出力引数 :        無                                                                                                                                */
  /* 返り値   :        無                                                                                                                                */
  /* 備考     :        無                                                                                                                                */
   /******************************************************************************/
void SetOSMODE(int nOSMODE)
{
        struct resbuf                rebNewOSMODE;
        rebNewOSMODE.restype = RTSHORT;
        rebNewOSMODE.resval.rint = nOSMODE;
        /*設置系統變量OSNAP的値。*/
        acedSetVar("OSMODE",&rebNewOSMODE);
}

  /******************************************************************************/
  /* 関数名   :        GetCrossPoint                                                                                                        */
  /* 機能     :        得到交叉點的位置和交點坐標。                                                                        */
  /* 入力引数 :        AcGePoint3dArray                                Polyline的點列。                                */
  /*                        AcGePoint3d                                                選擇点。                                                */
  /*                        double                                                        PickBox的長度。                                        */
  /*                        Adesk::Boolean                                        閉合屬性。                                                */
  /* 出力引数 :        int                                                                交叉點的位置(前)。                        */
  /*                        int                                                                交叉點的位置(後)。                        */
  /*                        AcGePoint3d                                                交點坐標                                                */
  /* 返り値   :        TRUE                        正常。                                                                                        */
  /*                        FALSE                        異常。                                                                                        */
  /* 備考     :        無                                                                                                                                */
   /******************************************************************************/
BOOL GetCrossPoint(AcGePoint3dArray gePoi3dA, AcGePoint3d gePoi3d, double dPickLen, int & iCrsID1,
                                   int & iCrsID2, AcGePoint3d & gePoi3dCrs, Adesk::Boolean bIsClosed = Adesk::kTrue)
{
        ads_point                        spt1, spt2, spt3, spt4;
        AcGePoint3d                        GePoi3dStart, GePoi3dNext;
        int                                        iReturn, iNum;
       
        iNum = gePoi3dA.length();
        if (iNum < 2) {
                return FALSE;
        }

        /*得到交叉點的位置*/
        for (int i = 0; i < iNum; i++) {
                iCrsID1 = i;

                //得到前一個點
                asPnt3d(spt3) = gePoi3dA[iCrsID1];

                //得到後一個點
                if (i == iNum - 1) {
                        //實體是否是閉合。
                        if (!bIsClosed)        {
                                break;
                        }
                        else {
                                iCrsID2 = 0;
                        }
                }
                else {
                        iCrsID2 = i + 1;
                }
                asPnt3d(spt4) = gePoi3dA[iCrsID2];
               
                spt3[Z] = 0;
                spt4[Z] = 0;

                /*X方向是否有交叉點。*/
                spt1[X] = gePoi3d.x + (dPickLen / 2);        spt2[X] = gePoi3d.x - (dPickLen / 2);
                spt1[Y] = gePoi3d.y;                                        spt2[Y] = gePoi3d.y;
                spt1[Z] = 0;                                                        spt2[Z] = 0;
                iReturn = acdbInters(spt1, spt2, spt3, spt4, 1, asDblArray(gePoi3dCrs));
                if (iReturn == RTNORM) {
                        return TRUE;
                }

                /*Y方向是否有交叉點。*/
                spt1[X] = gePoi3d.x;                                        spt2[X] = gePoi3d.x;
                spt1[Y] = gePoi3d.y + (dPickLen / 2);        spt2[Y] = gePoi3d.y - (dPickLen / 2);
                spt1[Z] = 0;                                                        spt2[Z] = 0;
                iReturn = acdbInters(spt1, spt2, spt3, spt4, 1, asDblArray(gePoi3dCrs));
                if (iReturn == RTNORM) {
                        return TRUE;
                }
        }
        return FALSE;
}
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

发表于 2003-12-13 11:41:09 | 显示全部楼层
前阵困扰我的问题解决了,现在共享给大家:
//************************************************************************
//函数名称:getPointAtDistInGeCurve
//函数类型:Acad::ErrorStatus
//返回值:
//功能描述:返回曲线上距起点某距离值处的点。
//函数作者:Darcy
//创建日期:2003-XX-XX
//参数列表:
//变量名:pGeCurve       变量类型:const AcGeCurve3d *         变量说明:
//变量名:dist                 变量类型:double                                 变量说明:
//变量名:point               变量类型:AcGePoint3d&                    变量说明:
//备  注:
//************************************************************************
Acad::ErrorStatus getPointAtDistInGeCurve(const AcGeCurve3d * pGeCurve,double dist,AcGePoint3d& point)
{
        Acad::ErrorStatus es = Acad::eOk;

        if ( pGeCurve != NULL )
        {
                AcGePoint3d spt;
                double pa=0.,datumParam=0.;
                                         //距离从起点起算!
                Adesk::Boolean posParamDir=Adesk::kTrue;

                pGeCurve->hasStartPoint(spt);

                datumParam = pGeCurve->paramOf(spt);;

                pa = pGeCurve->paramAtLength(
                                                                         datumParam,
                                                                         dist,
                                                                         posParamDir
                                                                         );

                point=pGeCurve->evalPoint(pa);
        }
        else
                es = Acad::eInvalidInput;

        return es;
}
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

已领礼包: 1个

财富等级: 恭喜发财

发表于 2003-12-19 15:34:16 | 显示全部楼层
///////////////////////////////////
//将点数组转换到链表中
//2002.5.30
///////////////////////////////////
resbuf* ptArrayToResbuf(const AcGePoint3dArray &ptArray)
{
    resbuf* ptList = NULL;        // overall list
    resbuf* lastRb = NULL;        // place holder to end of list
    resbuf* rb;
    int len = ptArray.length();
    for (int i=0;i<len;i++) {
        if ((rb = acutNewRb(RT3DPOINT)) == NULL) {
            acutRelRb(ptList);
            return NULL;
        }
        //copyAdsPt(rb->resval.rpoint, asDblArray(ptArray.at(i)));
                rb->resval.rpoint[X] = ptArray.at(i).x;
                rb->resval.rpoint[Y] = ptArray.at(i).y;
                rb->resval.rpoint[Z] = ptArray.at(i).z;
        if (ptList == NULL) {
            ptList = rb;
            lastRb = rb;
        }
        else {
            lastRb->rbnext = rb;
            lastRb = rb;
        }
    }
    return ptList;
}
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

发表于 2004-1-8 09:49:32 | 显示全部楼层
bool
IsAtLine(CAD_POINT StartPt,CAD_POINT EndPt,CAD_POINT thePt)
/* 判断某点是否在直线上
        StartPt        直线起点       
        EndPt        直线终点
        thePt        所判断点
返回:TRUE__在直线上  FALSE__不在直线上
*/
{
        //为保证计算精度,首先对点的坐标数据降级
        CAD_VECTOR vec(StartPt.x,StartPt.y,StartPt.z);
        StartPt=StartPt-vec;
        EndPt=EndPt-vec;
        thePt=thePt-vec;

//        直线方程系数
        double        A,B,C;
        A = EndPt.y - StartPt.y;
        B = StartPt.x - EndPt.x;
        C = -1.0*(A*StartPt.x+B*StartPt.y);
       
        if(StartPt.x==EndPt.x)
        {
                if(thePt.y>max(StartPt.y,EndPt.y) || thePt.y<min(StartPt.y,EndPt.y))
                        return FALSE;
        }
        else if(StartPt.y==EndPt.y)
        {
                if(thePt.x>max(StartPt.x,EndPt.x) || thePt.x<min(StartPt.x,EndPt.x))
                        return FALSE;
        }
        else
        {
                if( thePt.x>max(StartPt.x,EndPt.x) || thePt.x<min(StartPt.x,EndPt.x) ||
                        thePt.y>max(StartPt.y,EndPt.y) || thePt.y<min(StartPt.y,EndPt.y) )
                        return FALSE;
        }

        if(fabs(A*thePt.x+B*thePt.y+C)>1.0E-6)
        {
                return FALSE;
        }
       
        return TRUE;
}

/*****************************************************/
BOOL
IsAtArc(CAD_POINT firstPt,CAD_POINT secondPt,
                double radius,double direct,int More,CAD_POINT thePt)
/* 判断某点是否在圆弧上
        firstPt                圆弧起点
        secondPt        圆弧终点       
        radius                半径
        direct                偏向( >=0__左偏  <0__右偏 )
        More                (More<0__小圆弧,More>0__大圆弧)
        thePt                判断点
返回:TRUE__在圆弧上  FALSE__不在圆弧上
*/
{
        CAD_POINT centerPt,sectionPt;
        CAD_POINT startPt,endPt;
        double startAngle,endAngle,chordAngle,vertAngle;
        double intLine,chordLine;
/*        centerPt        圆弧圆心
        sectionPt        弦线中心点
        startAngle        圆弧起点切线角度(弧度)
        endAngle        圆弧终点切线角度(弧度)
        chordAngle        弦线角度(弧度)
        vertAngle        与弦线垂直的垂线角度(弧度)
        intLine                弦线中心至圆心距离
        chordLine        弦线长度
*/       
        sectionPt.x = (firstPt.x + secondPt.x)/2;
        sectionPt.y = (firstPt.y + secondPt.y)/2;

        chordLine = sqrt( pow( (secondPt.x-firstPt.x),2 ) + pow( (secondPt.y-firstPt.y),2 ) );
        intLine          = sqrt((radius*radius-chordLine*chordLine/4) );
       
        chordAngle = ads_angle(asDblArray(firstPt),asDblArray(secondPt)); //弦线的角度

        if(direct>=0)//左偏
        {
                startPt=firstPt;
                endPt=secondPt;
                vertAngle=chordAngle+Pai/2;
        }
        else if(direct<0)//右偏
        {
                startPt=secondPt;
                endPt=firstPt;
                vertAngle=chordAngle-Pai/2;
        }

        if(More<=0)//小圆弧
        {
                centerPt.x=sectionPt.x+intLine*cos(vertAngle);
                centerPt.y=sectionPt.y+intLine*sin(vertAngle);
        }
        else//大圆弧
        {
                centerPt.x=sectionPt.x-intLine*cos(vertAngle);
                centerPt.y=sectionPt.y-intLine*sin(vertAngle);
        }
       
        if(fabs(centerPt.distanceTo(thePt)-radius)>1.0E-8)
                return FALSE;
        startAngle = ads_angle(asDblArray(centerPt),asDblArray(startPt));
        endAngle = ads_angle(asDblArray(centerPt),asDblArray(endPt));
       
        AcDbArc *pArc=new AcDbArc(centerPt,radius,startAngle,endAngle);
        AcDbLine *pLine=new AcDbLine(centerPt,thePt);
        AcGePoint3dArray Points;
        pLine->intersectWith(pArc,AcDb::kOnBothOperands,Points);
        if(Points.isEmpty()) return FALSE;

        return TRUE;
}

[你这是数学的方法,在ARX的Ge库中有isOn方法来判断点是否在给定的线或者面上![/COLOR]
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

发表于 2004-2-5 11:14:29 | 显示全部楼层
有时候,你需要这样调用Autocad命令
void SendCommandToAutoCad(CString cmd)
{
        COPYDATASTRUCT cmdMsg;
        cmdMsg.dwData = (DWORD)1;
        cmdMsg.cbData = (DWORD)_tcslen(cmd) + 1;
        cmdMsg.lpData = cmd.GetBuffer(cmd.GetLength()+1) ;
        SendMessage(acedGetAcadFrame()->m_hWnd, WM_COPYDATA, NULL, (LPARAM)&cmdMsg);
}
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

发表于 2004-3-9 12:10:26 | 显示全部楼层

Re: 我认为PointIsInPolygon函数有问题

最初由 lzxlzx 发布
[B]根据射线法求交点个数,偶数-区域外,奇数-区域内
但如果射线刚好通过顶点,产生偶数,却在区域内。 [/B]


=====关键在于pt0点的选择,只要 pt0点在区域外,再判断与ptx的连线是否和polygon有交点,有即说明ptx 点是在区域内的。
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

发表于 2004-4-6 10:03:14 | 显示全部楼层
//向AcDbObject添加扩展数据Xdata

  1. void affixXdata(char *appName, char *xData, AcDbObject *pObj)
  2. {
  3.         //向AcDbObject添加扩展数据Xdata
  4.         struct resbuf *pRb, *pTemp;

  5.         acdbRegApp(appName);
  6.         pRb = acutNewRb(AcDb::kDxfRegAppName);
  7.         pTemp = pRb;
  8.         pTemp->resval.rstring = new char[strlen(appName)+1];
  9.         strcpy(pTemp->resval.rstring, appName);

  10.         pTemp->rbnext = acutNewRb(AcDb::kDxfXdAsciiString);
  11.         pTemp = pTemp->rbnext;
  12.         pTemp->resval.rstring = new char[strlen(xData)+1];
  13.         strcpy(pTemp->resval.rstring, xData);

  14.         pObj->setXData(pRb);
  15.         acutRelRb(pRb);
  16. }
复制代码
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|申请友链|Archiver|手机版|小黑屋|辽公网安备|晓东CAD家园 ( 辽ICP备15016793号 )

GMT+8, 2024-3-29 19:40 , Processed in 0.451526 second(s), 52 queries , Gzip On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表