天气与日历 切换到窄版

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

‎在 ObjectARX 中使用 AcEdJig 类夹具多个实体‎

[复制链接]

该用户从未签到

主题

0

回帖

2912

积分

管理员

积分
2912
发表于 2024-6-22 09:46:18 | 显示全部楼层 |阅读模式
[code]#ifndef ASDKMULTIJIG__H

#define ASDKMULTIJIG__H



#endif // ASDKMULTIJIG__H



////////////////////////////////////////////////////////

class asdkEntityList : public AcDbEntity

{

public:



// constructor

asdkEntityList ();

// destructor

~asdkEntityList ();



// flag to indicate that we have

// assigned some entities to the entity list

bool m_calledSetEntityList;



// array of AcDbEntities

AcDbVoidPtrArray m_entities;





typedef Adesk::Boolean (*updateFunction) (int mode,

  asdkEntityList &entityList);

// array of update Functions

AcArray<updateFunction> m_updateFuncs;



// entity input data

AcArray<AcGePoint3d> m_pnts;



// sets what entities are to be jigged

Acad::ErrorStatus setEntityList(

  const AcDbVoidPtrArray &entities);



// loop through m_entities and display the data

virtual Adesk::Boolean subWorldDraw(AcGiWorldDraw *wd);

};



/////////////////////////////////////////////////////////////

class asdkMultiJig : public AcEdJig

{

public:

// constructor

asdkMultiJig ();

// destructor

~asdkMultiJig ();



// mode of input, starts at 0 then

// increments until all entities have been

// input, indexes m_entityList

int m_mode;



// class containing the list of entities to jig

asdkEntityList m_entityList;

ads_real m_distance;

AcGePoint3d m_originalPnt;



typedef AcEdJig::DragStatus

  (*inputFunction) (asdkMultiJig &jig);

// array of input Functions

AcArray<inputFunction> m_inputFuncs;



// get the jig data

virtual AcEdJig::DragStatus sampler();

// return the jig entity

virtual AcDbEntity *entity() const;

// update the sampler data to the jig entity

virtual Adesk::Boolean update();

// add the object to the space

AcDbObjectId append(AcDbDatabase *dwg=NULL,

  const ACHAR *requiredSpace = ACDB_MODEL_SPACE);



private:

};



Implementation of the custom jig and jig custom entity:

#include "StdAfx.h"

#include "StdArx.h"



///////////////////////////////////////////////////////

Acad::ErrorStatus postToDwg (AcDbEntity *pEnt,

AcDbDatabase *pDb=NULL,

const ACHAR *requiredSpace=ACDB_MODEL_SPACE);



///////////////////////////////////////////////////////

// constructor

asdkMultiJig::asdkMultiJig ()

{

m_mode = 0;

m_distance = 0.0;

}

///////////////////////////////////////////////////////

// destructor

asdkMultiJig::~asdkMultiJig ()

{

}

///////////////////////////////////////////////////////

// get the jig data

AcEdJig::DragStatus asdkMultiJig::sampler()

{

// set the cursor to invisible

setSpecialCursorType(AcEdJig::kInvisible);



// call the update function

return ((*this->m_inputFuncs[m_mode])(*this));

}

///////////////////////////////////////////////////////

// return the jig entity

AcDbEntity *asdkMultiJig::entity() const

{

// check to make sure we called setEntityList

if (!m_entityList.m_calledSetEntityList)

  AfxMessageBox (L"Error - You must call setEntityList \

  before calling asdkMultiJig::drag()");



return (const_cast<asdkEntityList *>(&m_entityList));

}



///////////////////////////////////////////////////////

// update the sampler data to the jig entity

Adesk::Boolean asdkMultiJig::update()

{

// call the update function

return ((*m_entityList.m_updateFuncs[m_mode])

  (m_mode, this->m_entityList));

}

///////////////////////////////////////////////////////

// add the object to the space

AcDbObjectId asdkMultiJig::append(AcDbDatabase *dwg,

const ACHAR *requiredSpace)

{

// get the total number of entities registered

int length = m_entityList.m_entities.length ();

// loop round the registered

// entities and add the to the space

for (int i=0; i<length; ++i)

{

  postToDwg ((AcDbEntity *)m_entityList.m_entities[i],

   dwg, requiredSpace);

}



// get the id of the first entity drawn

AcDbObjectId id =

  ((AcDbEntity *)m_entityList.m_entities[0])->id ();



// close the entities added

for (int i=0; i<length; ++i)

  ((AcDbEntity *)m_entityList.m_entities[i])->close ();



// return the object id

return (id);

}



///////////////////////////////////////////////////////

// constructor

asdkEntityList::asdkEntityList ()

{

m_calledSetEntityList = false;

}

///////////////////////////////////////////////////////

// destructor

asdkEntityList::~asdkEntityList ()

{

}

///////////////////////////////////////////////////////

// set what entities are to be jigged

Acad::ErrorStatus asdkEntityList::setEntityList (

const AcDbVoidPtrArray &entities)

{

// record that we have called this function correctly

m_calledSetEntityList = true;



// setup our entity list

m_entities = entities;

// if nothing in there then lets say!

if (m_entities.length() == 0)

  return Acad::eInvalidInput;



// setup our point storage

m_pnts.setLogicalLength (m_entities.length());



// all ok

return Acad::eOk;

}

///////////////////////////////////////////////////////

Adesk::Boolean asdkEntityList::subWorldDraw (AcGiWorldDraw * wd)

{

int length = m_entities.length ();

// loop the number of entities in the entity list

for (int i=0; i<length; ++i)

{

  // lets get the entity out

  AcDbEntity *ent = (AcDbEntity *)m_entities[i];

  // if ok

  if (ent != NULL)

  {

   // then draw it

   wd->geometry ().draw (ent);

  }

}



return (Adesk::kTrue);

}



///////////////////////////////////////////////////////

// adds an entity to the required space...

// default is current dwg and ACDB_MODEL_SPACE.

Acad::ErrorStatus postToDwg (AcDbEntity *pEnt, AcDbDatabase *pDb,

const ACHAR *requiredSpace)

{

// if the default database is to be used

if (pDb == NULL)

  pDb = acdbHostApplicationServices()->workingDatabase ();



AcDbBlockTable *blockTable = NULL;

// get a pointer to the block table

Acad::ErrorStatus es = pDb->getBlockTable (blockTable,

  AcDb::kForRead);

// if it failed then abort

if (es != Acad::eOk)

  return (es);



AcDbBlockTableRecord *blockTableRecord = NULL;

// now get a pointer to the model space entity records

es = blockTable->getAt (requiredSpace,

  blockTableRecord, AcDb::kForWrite);

// can close the block table

// itself as we don't need it anymore

blockTable->close ();

// if it failed then abort

if (es != Acad::eOk)

  return (es);

// otherwise put the entity into the model space

es = blockTableRecord->appendAcDbEntity (pEnt);

// now close it up

blockTableRecord->close();



return (es);

}[/code]

 

 

 

 

‎在 ObjectARX 中使用 AcEdJig 类夹具多个实体‎
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

GMT+8, 2024-11-1 13:31 , Processed in 0.174082 second(s), 27 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

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