[vtkusers] Problem with cursoring in vtkImagePlaneWidget + enum news to me

Dean Inglis dean.inglis at camris.ca
Thu Sep 14 12:40:35 EDT 2006


Hi Peter,

>Something I have not mentioned yet, but which may be of importance, is that
>I have to #undef LEFT_BUTTON, RIGHT_BUTTON and MIDDLE_BUTTON before
>including vtkImagePlaneWidget.h to prevent a conflict between
>vtkImagePlaneWidget.h and afxctl.h. I don't have enough experience with VTK
>or C++ to assess what effects this might have.

this is something new to me, but I suspect that this is the root of the
problem.  In your copy of vtkImagePlaneWidget.h and vtkImagePlaneWidget.cxx
what happens if you replace LEFT_BUTTON with VTK_LEFT_BUTTON etc. and
recompile
VTK and your application?

I thought that only global variables declared using #define could be
#undef(ined).
LEFT_BUTTON, RIGHT_BUTTON and MIDDLE_BUTTON are protected enums in
vtkImagePlaneWidget but it appears that enums are treated as #defines. Could
anyone
shed some light on this and what might be going on here?

In the meantime, I wrote this test console app that will NOT compile
(Borland C++)
unless the #defines are undefined...see below

Dean


#include <iostream.h>

#define LEFT_BUTTON 3
#define RIGHT_BUTTON 4
#define MIDDLE_BUTTON 5
/*
#ifdef LEFT_BUTTON
#undef LEFT_BUTTON
#endif
#ifdef RIGHT_BUTTON
#undef RIGHT_BUTTON
#endif
#ifdef MIDDLE_BUTTON
#undef MIDDLE_BUTTON
#endif*/

class myclass{
public:
  myclass(){};
  ~myclass(){};

  int myfunc(const int& i);

protected:
   enum
   {
   LEFT_BUTTON = 1,
   RIGHT_BUTTON = 2,
   MIDDLE_BUTTON = 3
   };
};

int myclass::myfunc(const int& i)
{
  int button = -1;
  switch (i)
    {
    case myclass::LEFT_BUTTON:
         button = myclass::LEFT_BUTTON; break;
    case myclass::RIGHT_BUTTON:
         button = myclass::RIGHT_BUTTON; break;
    case myclass::MIDDLE_BUTTON:
         button = myclass::MIDDLE_BUTTON; break;
    }
  return button;
}

void main(void)
{
  myclass* my = new myclass;
  for(int i = 0; i < 10; ++i )
    {
    int button = my->myfunc( i );
    cout << button << endl;
    }
  delete my;
}







More information about the vtkusers mailing list