Author Topic: AcDbGripData::setAppData(void* appData)  (Read 2505 times)

0 Members and 1 Guest are viewing this topic.

It's Alive!

  • BricsCAD
  • Needs a day job
  • Posts: 6940
  • AKA Daniel
AcDbGripData::setAppData(void* appData)
« on: June 03, 2010, 03:29:26 AM »
AcDbGripData::setAppData(void* appData)

What types can appData be? Can it be a class/struct ? Who's responsible for freeing the memory?

Thanks  :-)

It's Alive!

  • BricsCAD
  • Needs a day job
  • Posts: 6940
  • AKA Daniel
Re: AcDbGripData::setAppData(void* appData)
« Reply #1 on: June 03, 2010, 05:35:56 AM »
Nope Acad does not delete the appdata pointer 


It can be anything you want at long as it's not null
Acad does not free the resources, but you can free the items..if needed.. in your custom object's destructor   

It's Alive!

  • BricsCAD
  • Needs a day job
  • Posts: 6940
  • AKA Daniel
Re: AcDbGripData::setAppData(void* appData)
« Reply #2 on: June 03, 2010, 05:57:15 AM »
So this is pretty cool. it's kind of like storing your own custom class inside the grip.  8-)

something simple like
Code: [Select]
//
class MyAppData
{
private:
  int m_val;
public:
  MyAppData (int val): m_val(val){}
  virtual ~MyAppData(){ }
  void printval(void){acutPrintf(_T("\nGrip# %ld"),m_val);}
  int Val() const { return m_val; }
};

then

Code: [Select]

Acad::ErrorStatus ExtCircle::getGripPoints (
AcDbGripDataPtrArray &grips, const double curViewUnitSize, const int gripSize,
const AcGeVector3d &curViewDir, const int bitflags) const
{
assertReadEnabled () ;
  AcDbGripData *pGrpCenter = new AcDbGripData();
  pGrpCenter->setGripPoint(this->center());
  pGrpCenter->setAppData((void*)new MyAppData(100));
  grips.append(pGrpCenter);

  double ang = 0.0;
  for(int idx = 1 ; idx < 33; idx++)
  {
    AcDbGripData *pGrp = new AcDbGripData();

    // My Class
    MyAppData *_data = new MyAppData(idx);
    AcGePoint3d p = this->center();
    p.x += this->radius() *cos(ang);
    p.y += this->radius() *sin(ang);
    ang += 6.28318531 / 32;
    pGrp->setGripPoint(p);

    // give the AcDbGripData a ptr
    pGrp->setAppData((void*)_data);
    pGrp->setAlternateBasePoint(new  AcGePoint3d(this->center()));
    grips.append(pGrp);

    // keep a copy of ptr to free later
    ptrs->push_back(_data);
  }

  return Acad::eOk;
}

then

Code: [Select]
Acad::ErrorStatus ExtCircle::moveGripPointsAt (
const AcDbVoidPtrArray &gripAppData, const AcGeVector3d &offset,
const int bitflags) {
    assertWriteEnabled();
    for(int i = 0; i < gripAppData.length() ; i++)
    {
      // got my stuff back
      MyAppData *p = (MyAppData*)gripAppData.at(i);
      if(!p)
        continue;
      switch (p->Val())
      {
      case 100:
          transformBy(AcGeMatrix3d::translation(offset));
        break;
      default:
        this->setRadius(offset.length());
      }
      // run a method from the class
      p->printval();
    }
    return Acad::eOk;
}

« Last Edit: June 03, 2010, 06:00:29 AM by Daniel »