ObjectArx-C ++ implementa comandos de edición de pendientes: solicita al usuario que elija otro punto cuando se especifica el punto base

C ++ implementa comandos de edición de pendientes y solicita al usuario que elija un punto cuando se especifica el punto base.

La idea principal es:

  1. Primero dibuja un bloque de pendiente.
  2. Dibuja una línea de referencia, que se puede utilizar para el seguimiento polar.
  3. Para editar la pendiente, seleccione el bloque de pendiente, dibuje una línea de referencia y extienda la longitud de la pendiente de acuerdo con la línea de referencia.

La figura es la siguiente:

ObjectArx-C ++ implementa comandos de edición de pendientes: solicita al usuario que elija otro punto cuando se especifica el punto base

Los ejemplos son los siguientes:

  1. Código de punto de entrada del programa

    `` `c ++
    // dibujo de pendiente zhaoanan
    // - comando zndraw_thslope (no renombrar)
    // dibujo de entidad personalizada pendiente
    static void zndraw_thslope (void)
    {
    AcDbDatabase m_pDb = acdbHostApplicationServices () -> workingDatabase ();
    // Agregar definición de bloque
    acutPrintf (_T ("\ nDibujo en pendiente"));
    CUserSystem
    mysys = new CUserSystem ();
    mysys-> m_pDb = m_pDb;
    // Declare el punto de inserción izquierdo
    ads_point pt_insert;
    AcGePoint3d pt_3d_insert;
    int iOldOsMode = 0;
    BOOL;
    while (bReturn == false)
    {
    int iReturn = acedGetPoint (NULL, _T ("\ n Especifique el punto de inserción de la pendiente:"), pt_insert);
    // int iReturn = acedEntSel (_T ("\ nSeleccione el objeto de entidad"), en, pt);

    if(iReturn == RTNORM)
    {       
        bReturn = true ;
    
        pt_3d_insert =asPnt3d(pt_insert);
    
        acutPrintf(_T("\n坡度插入点坐标:x坐标为:%f,y坐标为:%f"), pt_3d_insert.x, pt_3d_insert.y);
        //实例化轨道坡度对象
        CthRailSlope *cthRailSlope = new CthRailSlope();
        //指定坡度位置为插入点坐标
        cthRailSlope->setPosition(pt_3d_insert);
        //添加坡度组件
        CthComponent *lineCp = new CthComponent();
        //thComponent c = new thComponent();
        //根据插入点,画坡度上面的横线
        lineCp->addLine(AcGePoint3d(-26, 7.5, 0), AcGePoint3d(0, 7.5, 0));
        //根据插入点,画坡度下面的横线
        lineCp->addLine(AcGePoint3d(-26, -7.5, 0), AcGePoint3d(0, -7.5, 0));
        //以插入点横坐标X=-26为基准向上和向下画竖线
        lineCp->addLine(AcGePoint3d(-26, 7.5, 0), AcGePoint3d(-26, -7.5, 0));
        //添加坡度框体中间的文字
        CthText *text = lineCp->addText(_T("坡"), AcGeVector3d(-23, 2.5, 0), 3);
        //指定字体对齐方式
        text->setAlign(AcDbMText::kMiddleCenter);
        text = lineCp->addText(_T("度"), AcGeVector3d(-23, -2.5, 0), 3);
        //指定字体对齐方式
        text->setAlign(AcDbMText::kMiddleCenter);
        //以插入点横坐标X=-20为基准向上和向下画竖线
        lineCp->addLine(AcGePoint3d(-20, 7.5, 0), AcGePoint3d(-20, -7.5, 0));
        //将新建的组件添加到坡度对象
        cthRailSlope->appendComponent(lineCp);
        lineCp = new CthComponent();
        //type=1, 没查到代表什么
        lineCp->setType(1);
        //根据插入点,以插入点为基准向上和向下画竖线
        lineCp->addLine(AcGePoint3d(pt_3d_insert.x, pt_3d_insert.y + 7.5, 0), AcGePoint3d(pt_3d_insert.x, pt_3d_insert.y - 7.5, 0));
        //给新加的竖线添加文字
        text = lineCp->addText(_T(""), AcGeVector3d(pt_3d_insert.x, pt_3d_insert.y, 0), 2.5);
        text->setName(_T("里程"));
        //指定字体旋转角度
        text->setRotation(PI / 2);
        //指定字体对齐方式
        text->setAlign(AcDbMText::kBottomCenter);
        //将新建的组件添加到坡度对象
        cthRailSlope->appendComponent(lineCp);
        //获取devices.xml中的图层信息,给新建坡度对象添加图层
        DTDevice* device = CZnUtility::GetDevice(cthRailSlope);
        //如果获取的devices.xml中的坡度相关图层信息不为空
        if(device != nullptr && (!device->GetLayer().IsEmpty()))
        {
            //将图层信息添加到图层表中
            if (addLayer(device))
            {
                //如果图层信息添加到图层表成功,那么将图层信息赋值给当前坡度图层
                cthRailSlope->setLayer(device->GetLayer());
            }
        }
    
        //将里程实体加入到块表记录中
        //cthRailSlope->AddRailSlope("ZDK1+222.45", "ZDK2+123.11", "20", 20.00, "30", cthRailSlope->position().x + 20, cthRailSlope->position().x + 50, 1);
        AcDbObjectId dimensionId = CDwgDatabaseUtil::PostToModelSpace(cthRailSlope, m_pDb);
    }
    else if (iReturn == RTERROR) 
    {
        bReturn = false ;
    }   
    else if (iReturn == RTCAN) {
        bReturn = true ;
    }

    }
    // Guarda la capa actual, configura la capa que se dibujará
    AcDbObjectId ojbIdLayerOld = m_pDb-> clayer ();

    m_pDb-> setClayer (ojbIdLayerOld); // Restaurar la capa actual
    }

  2. Arrastre y suelte el código del programa. Cuando hay una edición de pendiente, hay una línea de referencia. Cuando se especifica el punto base, se le pide al usuario que elija un punto. El código se da cuenta:

    `` `c ++
    // Actualice la ventana y surta efecto inmediatamente
    int CGetInputUtil :: GetPointReturnCode (const AcGePoint3d & basePoint, const TCHAR * prompt, AcGePoint3d & point)
    {
    // Convierta el punto base a coordenadas UCS
    AcGePoint3d ucsBasePoint = CConvertUtil :: WcsToUcs (basePoint)

    int nReturn = acedGetPoint (asDblArray (ucsBasePoint), indicador, asDblArray (punto));

    if (nReturn == RTNORM)
    {
    // acedGetPoint obtiene las coordenadas UCS y las convierte en WCS
    point = CConvertUtil :: UcsToWcsPoint (point);
    }

    return nReturn;
    }

  3. Código de edición de pendiente

    `` `c ++
    // edición de pendiente zhaoanan
    // - comando zndraw_thslope (no cambiar el nombre)
    // edición de pendiente de entidad personalizada
    vacío estático zndraw_thslopeedit (void)
    {
    AcDbDatabase m_pDb = acdbHostApplicationServices () -> workingDatabase ();
    // Agregar definición de bloque
    acutPrintf (_T ("\ nSlope Edit"));
    CUserSystem
    mysys = nuevo CUserSystem ();
    mysys-> m_pDb = m_pDb;

    // Declare el punto de inserción a la izquierda
    ads_name en;
    ads_point pt;
    BOOL bReturn = false;
    while (bReturn == false)
    {
    int iReturn = acedEntSel (_T ("\ nSeleccione el objeto de entidad de pendiente"), en, pt);

    if(iReturn == RTNORM)
    {       
        bReturn = true ;
    
        AcDbEntity * pEnt = NULL ;
        CthRailSlope * pthEnt = NULL;
        if(mysys->OpenAcDbEntity(en, pEnt, AcDb::kForRead))
        {
            acedUpdateDisplay();
            //指定坡度端点
            if(pEnt->isKindOf(CthRailSlope::desc()))
            {
                pthEnt = CthRailSlope::cast(pEnt) ;
                pthEnt->upgradeOpen();
                //获取里程值
                CthComponent *pCpnt = pthEnt->getComponent(pthEnt->getComponentCount() - 1);
                CthLine* line= (CthLine*)pCpnt->getElement(0);
                AcGePoint3d pt_3d_base(line->startPoint().x, pthEnt->position().y, 0);
                // 左里程
                CString m_left_kmpost = "";
                //进行非空判断,可能为空,没有添加过左公里标时为空
                if (pCpnt != NULL) {
                    CthElement *pElm = pCpnt->getElement(_T("里程"));
                    if (pElm->type() == 32)
                    {
                        CthText* pText = (CthText*)pElm;
                        //更新里程值内容
                        m_left_kmpost = pText->textString();
                    }
                }
                //acutPrintf(_T("\n坡度基准点坐标:x坐标为:%f,y坐标为:%f"), pt_3d_base.x, pt_3d_base.y);
                //画出虚拟参考线
                //声明极轴追踪模式
                int iOldPolarMode = 0;
                //得到原极轴追踪模式
                mysys->GetSysVar(_T("AUTOSNAP"), iOldPolarMode);
                //设置极轴追踪模式,0为不极轴追踪,8为极轴追踪
                mysys->SetSysVar(_T("AUTOSNAP"), 8) ;
                CRailSlopeEditJig *pJig = new CRailSlopeEditJig();
                pJig->DoIt(pt_3d_base);
                //恢复原极轴追踪模式
                mysys->SetSysVar(_T("AUTOSNAP"), iOldPolarMode) ;
                int len = pJig->m_3dPoints.length();
                //打开窗体
                if (len>=2)
                {
                    CAcModuleResourceOverride myResources ; 
                    RailSlopeEditDlg dlg = new RailSlopeEditDlg();
                    //值的初始化
                    dlg.cthRailSlope = pthEnt;
                    dlg.m_left_kmpost = m_left_kmpost;
                    dlg.m_pt3dBasePoint = pthEnt->position();
                    dlg.m_pt3dStartPoint = pJig->m_pt3dStart;
                    dlg.m_pt3dEndPoint = pJig->m_pt3dEnd;
                    int nRet = dlg.DoModal();
                    if (nRet == IDOK)
                    {
                        acutPrintf(_T("\n坡度编辑完成")) ;
                    } else if (nRet == IDCANCEL) {
                        acutPrintf(_T("\n坡度编辑已取消")) ;
                    }
                }
                //获取名称
                pthEnt->downgradeOpen();
            }
            else
            {
                AfxMessageBox(_T("选择的不是坡度实体!")) ;
                bReturn = false ;
            }
            if(pEnt!=NULL)
            {
                pEnt->unhighlight() ;
                pEnt->close();
            }
            acedUpdateDisplay();
    
        }
        //AcDbObjectId dimensionId = CDwgDatabaseUtil::PostToModelSpace(cthRailSlope, m_pDb);
    }
    else if (iReturn == RTERROR) 
    {
        bReturn = false ;
    }   
    else if (iReturn == RTCAN) {
        bReturn = true ;
    }

    }
    // Guarda la capa actual, configura la capa que se dibujará
    AcDbObjectId ojbIdLayerOld = m_pDb-> clayer ();

    m_pDb-> setClayer (ojbIdLayerOld); // Restaurar la capa actual
    }

  4. Comentarios de referencia y dirección web:

    1. https://blog.csdn.net/qq_40416052/article/details/82077497

Supongo que te gusta

Origin blog.51cto.com/zhaoanan/2542630
Recomendado
Clasificación