Re: Picking under a pfSwitch node

New Message Reply Date view Thread view Subject view Author view

Kim Michael Fairchild (fair++at++iss.nus.sg)
Tue, 12 Dec 1995 15:26:11 +0800


Hi,

>>
>> Just wondering.. is there anything special you have to do
>> to enable picking of geometry under pfSwitch nodes?
>>

Had exactly the same problem and reported but didn't have any
responses.

I ended up just writing my own switch using a group. I include my
class Switch here.

class Switch : public TopLevelObject {
private:
  Table* children;
  int switchIndex;

public:
  void* switcher;
  Switch(AutoIconSet*, int, void*);
  void ChangeFavoriteChild(int);
  void AddChild(void*, int);
  void* GetChild(int);
  int GetSwitchIndex();
};

The methods use a simple table class to store the children that I
could send you as well.

// Create a switch that is a group that points to one of several subgroups

Switch::Switch(int length, void* root)
{
#ifdef SGI
  char buf[100];
  static int switchNumber = 0;

  switcher = pfNewGroup();
  children = new Table;
  switchIndex = -1;
  UserData* userData = (UserData *) calloc(sizeof(UserData), 1);

  pfUserData(switcher, userData);
  sprintf(buf, "<Switch %d:%d>", switchNumber++, length + 1);
  pfNodeName(switcher, buf);
  pfAddChild((pfNode *) root, switcher);
// printf("Created a switch: %s\n", pfGetNodeName(switcher));
#else
  (length, length);
  (root, root);
#endif

}

// Change the currently selected Child on a Switch

void Switch::ChangeFavoriteChild(int childPlace)
{
#ifdef SGI
// printf("ChangeFavoriteChild: %d\n", childPlace);
  pfNode* parent = (pfNode *) switcher;
  pfNode* child = (pfNode *) children->GetTableEntry(childPlace);
  int num = pfGetNumChildren(parent);
   
// printf("ChangeFavoriteChild parent %s has %d children\n",
// pfGetNodeName(parent), num);
  if (num)
    pfRemoveChild(parent, pfGetChild(parent, 0));
  else
    if (switchIndex != -1)
      printf("No Group child to remove from %s but want one at %d\n",
             pfGetNodeName(parent), switchIndex);
  if (child)
    {
      pfAddChild(parent, child);
      switchIndex = childPlace;
    }
  else
    printf("No child to select from %s at %d\n", pfGetNodeName(parent), childPlace);
#else
  (childPlace, childPlace);
#endif
}

// Return the currently selected index for the group

int Switch::GetSwitchIndex()
{
  return switchIndex;
}

// Add a new child to the switch

void Switch::AddChild(void* thing, int position)
{
#ifdef SGI
  pfNode* child = (pfNode *) thing;

// printf("Adding a child %s (%x) to position %d\n",
// pfGetNodeName(child), child, position);
  children->TableEntry(position, child);
  if (position == switchIndex)
    {
      printf("child was added at the current position, this is good?\n");
      this->ChangeFavoriteChild(position);
    }
#else
  (thing, thing);
  (position, position);
#endif
};

// Return the child at the given position

void* Switch::GetChild(int position)
{
#ifdef SGI
  void* returnValue = children->GetTableEntry(position);

  if (!returnValue)
    printf("Switch::GetChild is unable to find a child at position %d\n", position);
// printf("Got a child: %s from %d\n", pfGetNodeName((pfNode *) returnValue));
  return returnValue;
#else
  (position, position);
  return NULL;
#endif
}

Kim.


New Message Reply Date view Thread view Subject view Author view

This archive was generated by hypermail 2.0b2 on Mon Aug 10 1998 - 17:52:07 PDT

This message has been cleansed for anti-spam protection. Replace '++at++' in any mail addresses with the '@' symbol.