天气与日历 切换到窄版

 找回密码
 立即注册
中国膜结构网
十大进口膜材评选 十大国产膜材评选 十大膜结构设计评选 十大膜结构公司评选
查看: 66|回复: 0

ARX 函数

[复制链接]

该用户从未签到

主题

0

回帖

2912

积分

管理员

积分
2912
发表于 2024-6-22 09:46:18 | 显示全部楼层 |阅读模式
#include "StdAfx.h"
#include "CrpRectangle.h"

CrpRectangle::CrpRectangle(DataMap &tvmap):AcDbPolyline(4)
{
  AcGePoint2d pt;
  double width;
  double height;
  short location;

  tvmap[1000].getPoint2d(pt);
  tvmap[1001].getDouble(width);
  tvmap[1002].getDouble(height);
  tvmap[1003].getShort(location);

  AcGePoint2d pt1 (pt.x + width,pt.y);
  AcGePoint2d pt2 (pt.x + width, pt.y + height);
  AcGePoint2d pt3 (pt.x, pt.y + height);
  if(this->isWriteEnabled())
  {
    this->addVertexAt(0,pt);
    this->addVertexAt(1,pt1);
    this->addVertexAt(2,pt2);
    this->addVertexAt(3,pt3);
    this->setClosed(Adesk::kTrue);
  }
  calcLocation(pt, width, height, (PCode::Location)location);
}

CrpRectangle::CrpRectangle(const AcGePoint2d &pt, double width, double height, PCode::Location loc):AcDbPolyline(4)
{
  AcGePoint2d pt1 (pt.x + width,pt.y);
  AcGePoint2d pt2 (pt.x + width, pt.y + height);
  AcGePoint2d pt3 (pt.x, pt.y + height);
  if(this->isWriteEnabled())
  {
    this->addVertexAt(0,pt);
    this->addVertexAt(1,pt1);
    this->addVertexAt(2,pt2);
    this->addVertexAt(3,pt3);
    this->setClosed(Adesk::kTrue);
  }
  calcLocation(pt, width, height, loc);
}

CrpRectangle::~CrpRectangle(void)
{
}

Acad::ErrorStatus CrpRectangle::getWidth(double &width) const
{
  Acad::ErrorStatus res;
  AcGePoint2d p0;
  AcGePoint2d p1;
  if((res = this->getPointAt(0,p0)) != Acad::eOk)
    return res;
  if((res = this->getPointAt(1,p1)) != Acad::eOk)
    return res;
  width = fabs(p0.x - p1.x);
  return Acad::eOk;
}

Acad::ErrorStatus CrpRectangle::setWidth(double width)
{
  Acad::ErrorStatus res;
  AcGePoint2d p0;
  AcGePoint2d p1;
  AcGePoint2d p2;

  if((res = this->getPointAt(0,p0)) != Acad::eOk)
    return res;

  if((res = this->getPointAt(1,p1)) != Acad::eOk)
    return res;

  if((res = this->getPointAt(2,p2)) != Acad::eOk)
    return res;

  p1.x = p0.x + width;
  p2.x = p0.x + width;

  if(!this->isWriteEnabled())
    return Acad::eNotOpenForWrite;

  if((res = this->setPointAt(1,p1)) != Acad::eOk)
    return res;

  if((res = this->setPointAt(2,p2)) != Acad::eOk)
    return res;

  return Acad::eOk;
}

Acad::ErrorStatus CrpRectangle::getHeight(double &height) const
{
  Acad::ErrorStatus res;
  AcGePoint2d p0;
  AcGePoint2d p4;
  if((res = this->getPointAt(0,p0)) != Acad::eOk)
    return res;
  if((res = this->getPointAt(4,p4)) != Acad::eOk)
    return res;
  height = fabs(p4.y - p0.y);
  return Acad::eOk;
}

Acad::ErrorStatus CrpRectangle::setHeight(double height)
{
  Acad::ErrorStatus res;
  AcGePoint2d p0;
  AcGePoint2d p2;
  AcGePoint2d p3;

  if((res = this->getPointAt(0,p0)) != Acad::eOk)
    return res;

  if((res = this->getPointAt(2,p2)) != Acad::eOk)
    return res;

  if((res = this->getPointAt(3,p3)) != Acad::eOk)
    return res;

  p2.y = p0.y + height;
  p3.y = p0.y + height;

  if(!this->isWriteEnabled())
    return Acad::eNotOpenForWrite;

  if((res = this->setPointAt(2,p2)) != Acad::eOk)
    return res;

  if((res = this->setPointAt(3,p3)) != Acad::eOk)
    return res;

  return Acad::eOk;
}

void CrpRectangle::calcLocation( const AcGePoint2d &startPoint, double width,
                                 double height, PCode::Location loc )
{
  AcGePoint2d point;
  switch ((int)loc)
  {
  case (int)PCode::kLowerLeft:
    {
      point = startPoint;
    }
    break;
  case (int)PCode::kLowerMid:
    {
      point = AcGePoint2d((startPoint[0] - (width / 2)), startPoint[1]);
    }
    break;
  case (int)PCode::kLowerRight:
    {
      point = AcGePoint2d((startPoint[0] - width), startPoint[1]);
    }
    break;
  case (int)PCode::kRightMid:
    {
      point = AcGePoint2d((startPoint[0] - width), (startPoint[1] - (height / 2)));
    }
    break;
  case (int)PCode::kUpperRight:
    {
      point = AcGePoint2d((startPoint[0] - width), (startPoint[1] - height));
    }
    break;
  case (int)PCode::kUpperMid:
    {
      point = AcGePoint2d((startPoint[0] - (width / 2)), (startPoint[1] - height));
    }
    break;
  case (int)PCode::kUpperLeft:
    {
      point = AcGePoint2d(startPoint[0], (startPoint[1] - height));
    }
    break;
  case (int)PCode::kLeftMid:
    {
      point = AcGePoint2d(startPoint[0], (startPoint[1] - (height / 2)));
    }
    break;
  }
  drawFrom(point);
}

Acad::ErrorStatus CrpRectangle::drawFrom( const AcGePoint3d &point )
{
  return drawFrom(AcGePoint2d(point.x,point.y));
}

Acad::ErrorStatus CrpRectangle::drawFrom( const AcGePoint2d &point )
{
  return drawFrom(point.asVector());
}

Acad::ErrorStatus CrpRectangle::drawFrom( const AcGeVector2d &vec )
{
  Acad::ErrorStatus res;

  if(!this->isWriteEnabled())
    return Acad::eNotOpenForWrite;

  AcGePoint2d pt0;
  AcGePoint2d pt1;
  AcGePoint2d pt2;
  AcGePoint2d pt3;

ISEOK(this->getPointAt(0,pt0));
ISEOK(this->getPointAt(1,pt1));
ISEOK(this->getPointAt(2,pt2));
ISEOK(this->getPointAt(3,pt3));
ISEOK(this->setPointAt(0, pt0 + vec));
ISEOK(this->setPointAt(1, pt1 + vec));
ISEOK(this->setPointAt(2, pt2 + vec));
ISEOK(this->setPointAt(3, pt3 + vec));

return Acad::eOk;
}

AcGePoint2d CrpRectangle::getPt1(void) const
{
  AcGePoint2d pt;
  this->getPointAt(0,pt);
  return pt;
}

AcGePoint2d CrpRectangle::getPt2(void) const
{
  AcGePoint2d pt;
  this->getPointAt(1,pt);
  return pt;
}

AcGePoint2d CrpRectangle::getPt3(void) const
{
  AcGePoint2d pt;
  this->getPointAt(2,pt);
  return pt;
}

AcGePoint2d CrpRectangle::getPt4(void) const
{
  AcGePoint2d pt;
  this->getPointAt(3,pt);
  return pt;
}

AcGePoint2d CrpRectangle::getMPB() const
{
  AcGePoint2d pt0;
  this->getPointAt(0,pt0);
  AcGePoint2d pt1;
  this->getPointAt(1,pt1);
  return AcGePoint2d((pt1[0] - pt0[0]) / 2.0, pt0[1]);
}

AcGePoint2d CrpRectangle::getMPL() const
{
  AcGePoint2d pt1;
  this->getPointAt(0,pt1);
  AcGePoint2d pt4;
  this->getPointAt(3,pt4);
  return AcGePoint2d(pt1[0], (pt4[1] - pt1[1]) / 2.0);
}

AcGePoint2d CrpRectangle::getMPR() const
{
  AcGePoint2d pt2;
  this->getPointAt(1,pt2);
  AcGePoint2d pt3;
  this->getPointAt(2,pt3);
  return AcGePoint2d(pt2[0], (pt3[1] - pt2[1]) / 2.0);
}

AcGePoint2d CrpRectangle::getMPT() const
{
  AcGePoint2d pt3;
  this->getPointAt(2,pt3);
  AcGePoint2d pt4;
  this->getPointAt(3,pt4);
  return AcGePoint2d((pt3[0] - pt4[0]) / 2.0, pt3[1]);
}

AcGePoint2d CrpRectangle::getCenter() const
{
  AcGePoint2d pt1;
  this->getPointAt(0,pt1);
  AcGePoint2d pt2;
  this->getPointAt(1,pt2);
  AcGePoint2d pt4;
  this->getPointAt(3,pt4);
  return AcGePoint2d((pt2[0] - pt1[0]) / 2.0, (pt4[1] - pt1[1]) / 2.0);
}

 

 

 

 

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

本版积分规则

QQ|Archiver|中国膜结构网|中国膜结构协会|进口膜材|国产膜材|ETFE|PVDF|PTFE|设计|施工|安装|车棚|看台|污水池|中国膜结构网_中国空间膜结构协会

GMT+8, 2024-11-1 15:32 , Processed in 0.161238 second(s), 27 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

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