Ejemplo n.º 1
0
void MolBrowser::update() {
  MoleculeList *mlist = app->moleculeList;
  int nummols = mlist->num();

  char buf[256], molnamebuf[81];
  int need_full_regen = 0;

#if 1
  // If the browser is larger than needed, we have to 
  // re-create it from scratch since some molecule was 
  // potentially deleted from the middle.
  // If the size remains fixed, then we need to regenerate
  // because we are getting called to rename an existing molecule...
  if (size() > nummols || size() == nummols) {
    need_full_regen = 1;
  }
#else
  need_full_regen = 1;
#endif

  if (need_full_regen) {
    clear();

    for (int i=0; i<nummols; i++) {
      Molecule *mol = mlist->molecule(i);

      // prevent string length overflows
      strncpy(molnamebuf, mol->molname(), sizeof(molnamebuf)-1);

      // display state of active/displayed/fixed by toggling the text color
      sprintf(buf, "%d\t%s\t%s\t%s\t%s\t%-13s\t%-9d\t%-7d\t%-3d",
        mol->id(),
        mlist->is_top(i) ? "T" : " ",
        mlist->active(i) ? VMDMENU_MOL_ACTIVE : VMDMENU_MOL_INACTIVE,
        mlist->displayed(i) ? VMDMENU_MOL_DISPLAYED : VMDMENU_MOL_NONDISPLAYED,
        mlist->fixed(i) ? VMDMENU_MOL_FIXED : VMDMENU_MOL_NONFIXED,
        molnamebuf, mol->nAtoms, mol->numframes(), mol->num_volume_data()
      );

      if (i < size()) 
        text(i+1, buf);
      else
        add(buf);
    }
  } else {
    // we just need to add one new molecule...
    int i = nummols - 1;
    Molecule *mol = mlist->molecule(i);

    // prevent string length overflows
    strncpy(molnamebuf, mol->molname(), sizeof(molnamebuf)-1);

    // display state of active/displayed/fixed by toggling the text color
    sprintf(buf, "%d\t%s\t%s\t%s\t%s\t%-13s\t%-9d\t%-7d\t%-3d",
      mol->id(),
      mlist->is_top(i) ? "T" : " ",
      mlist->active(i) ? VMDMENU_MOL_ACTIVE : VMDMENU_MOL_INACTIVE,
      mlist->displayed(i) ? VMDMENU_MOL_DISPLAYED : VMDMENU_MOL_NONDISPLAYED,
      mlist->fixed(i) ? VMDMENU_MOL_FIXED : VMDMENU_MOL_NONFIXED,
      molnamebuf, mol->nAtoms, mol->numframes(), mol->num_volume_data()
    );

    if (i < size())
      text(i+1, buf); // this shouldn't happen here...
    else
      add(buf);
  }
 
  if (mainmenu) mainmenu->update_gui_state();
}
Ejemplo n.º 2
0
void MolBrowser::update() {
  MoleculeList *mlist = app->moleculeList;
  int nummols = mlist->num();

#if 1
  //
  // XXX this code updates the state of all of the molecules reliably, but
  //     creates a huge performance cost when thousands of molecules are 
  //     loaded.  We really need a scheme to create a changelist and apply
  //     the changelist to only those molecule browser lines that need updates.
  //
  if (size() > nummols)
    clear();

  for (int i=0; i<nummols; i++) {
    char buf[256], molnamebuf[81];
    Molecule *mol = mlist->molecule(i);

    // prevent string length overflows
    strncpy(molnamebuf, mol->molname(), sizeof(molnamebuf)-1);

    // display state of active/displayed/fixed by toggling the text color
    sprintf(buf, "%d\t%s\t%s\t%s\t%s\t%-13s\t%-9d\t%-7d\t%-3d",
      mol->id(),
      mlist->is_top(i) ? "T" : " ",
      mlist->active(i) ? VMDMENU_MOL_ACTIVE : VMDMENU_MOL_INACTIVE,
      mlist->displayed(i) ? VMDMENU_MOL_DISPLAYED : VMDMENU_MOL_NONDISPLAYED,
      mlist->fixed(i) ? VMDMENU_MOL_FIXED : VMDMENU_MOL_NONFIXED,
      molnamebuf, mol->nAtoms, mol->numframes(), mol->num_volume_data()
    );

    if (i < size())
      text(i+1, buf); // update existing browser line
    else
      add(buf); // add a new browser line
  }
#else
  //
  // XXX this code addresses the performance issues associated with the
  //     full-update code above, but breaks molecule browser's handling
  //     of operations multi-molecule selections.
  // 
  char buf[256], molnamebuf[81];
  int need_full_regen = 0;

#if 1
  // If the browser is larger than needed, we have to 
  // re-create it from scratch since some molecule was 
  // potentially deleted from the middle.
  // If the size remains fixed, then we need to regenerate
  // because we are getting called to rename an existing molecule...
  if (size() > nummols || size() == nummols) {
    need_full_regen = 1;
  }
#else
  need_full_regen = 1;
#endif

  if (need_full_regen) {
    clear();

    for (int i=0; i<nummols; i++) {
      Molecule *mol = mlist->molecule(i);

      // prevent string length overflows
      strncpy(molnamebuf, mol->molname(), sizeof(molnamebuf)-1);

      // display state of active/displayed/fixed by toggling the text color
      sprintf(buf, "%d\t%s\t%s\t%s\t%s\t%-13s\t%-9d\t%-7d\t%-3d",
        mol->id(),
        mlist->is_top(i) ? "T" : " ",
        mlist->active(i) ? VMDMENU_MOL_ACTIVE : VMDMENU_MOL_INACTIVE,
        mlist->displayed(i) ? VMDMENU_MOL_DISPLAYED : VMDMENU_MOL_NONDISPLAYED,
        mlist->fixed(i) ? VMDMENU_MOL_FIXED : VMDMENU_MOL_NONFIXED,
        molnamebuf, mol->nAtoms, mol->numframes(), mol->num_volume_data()
      );

      if (i < size())
        text(i+1, buf); // update existing browser line
      else
        add(buf); // add a new browser line
    }
  } else {
    // we just need to add one new molecule...
    int i = nummols - 1;
    Molecule *mol = mlist->molecule(i);

    // prevent string length overflows
    strncpy(molnamebuf, mol->molname(), sizeof(molnamebuf)-1);

    // display state of active/displayed/fixed by toggling the text color
    sprintf(buf, "%d\t%s\t%s\t%s\t%s\t%-13s\t%-9d\t%-7d\t%-3d",
      mol->id(),
      mlist->is_top(i) ? "T" : " ",
      mlist->active(i) ? VMDMENU_MOL_ACTIVE : VMDMENU_MOL_INACTIVE,
      mlist->displayed(i) ? VMDMENU_MOL_DISPLAYED : VMDMENU_MOL_NONDISPLAYED,
      mlist->fixed(i) ? VMDMENU_MOL_FIXED : VMDMENU_MOL_NONFIXED,
      molnamebuf, mol->nAtoms, mol->numframes(), mol->num_volume_data()
    );

    if (i < size())
      text(i+1, buf); // update existing browser line
    else
      add(buf); // add a new browser line
  }
#endif
 
  if (mainmenu) mainmenu->update_gui_state();
}