Esempio n. 1
0
///// keyPressEvent ///////////////////////////////////////////////////////////
void GLView::keyPressEvent(QKeyEvent* e)
/// Overridden from QGlWidget::mousepressEvent. Handles key presses.
/// \arg <left>         : rotate left
/// \arg <right>        : rotate right
/// \arg <up>           : rotate up
/// \arg <down>         : rotate down
/// \arg <shift>+<left> : rotate counterclockwise
/// \arg <shift>+<right>: rotate clockwise
/// \arg <shift>+<up>   : zoom in
/// \arg <shift>+<down> : zoom out
/// \arg <ctrl>+<left>  : translate left
/// \arg <ctrl>+<right> : translate right
/// \arg <ctrl>+<up>    : translate up
/// \arg <ctrl>+<down>  : translate down
/// \arg <ctrl>+<shift>+<left>: change internal coordinate of selection (smaller). Implementation in GLMoleculeView.
/// \arg <ctrl>+<shift>+<right>: change internal coordinate of selection (larger). Implementation in GLMoleculeView.
{
  switch(e->key())
  {
    case Qt::Key_Left :   if(e->modifiers() & Qt::ShiftModifier)
                            zRot = 5.0f; // rotate counterclockwise
                          else if(e->modifiers() & Qt::ControlModifier)
                            translateXY(-5, 0);
                          else
                            yRot = -5.0f; // rotate left
                          break;

    case Qt::Key_Up     : if(e->modifiers() & Qt::ShiftModifier)
                            translateZ(-5);
                          else if(e->modifiers() & Qt::ControlModifier)
                            translateXY(0, -5);
                          else
                             xRot = -5.0f; // rotate up
                          break;

    case Qt::Key_Right  : if(e->modifiers() & Qt::ShiftModifier)
                            zRot = -5.0f; // rotate clockwise
                          else if(e->modifiers() & Qt::ControlModifier)
                            translateXY(5, 0);
                          else
                            yRot =  5.0f; // rotate right
                          break;

    case Qt::Key_Down   : if(e->modifiers() & Qt::ShiftModifier)
                            translateZ(5);
                          else if(e->modifiers() & Qt::ControlModifier)
                            translateXY(0, 5);
                          else
                            xRot = 5.0f; // rotate down
                          break;

    default:              e->ignore();
                          return;
  }
  setModified();
  updateGL();
}
Esempio n. 2
0
///// wheelEvent //////////////////////////////////////////////////////////////
void GLView::wheelEvent(QWheelEvent* e)
/// Overridden from QGlWidget::wheelEvent. Handles scrolls with the scrollwheel
/// of the mouse. It provides an alternative way of zooming.
{
  translateZ(-e->delta()/4); // abs(e->delta()) is always WHEELDELTA == 120
  setModified();
  updateGL();
  e->accept();
}
Esempio n. 3
0
void Transform::applyAnimationValueTranslationZ(float tz)
{
    if ((_animationPropertyBitFlag & ANIMATION_TRANSLATION_Z_BIT) != ANIMATION_TRANSLATION_Z_BIT)
    {
        _animationPropertyBitFlag |= ANIMATION_TRANSLATION_Z_BIT;
        setTranslationZ(tz);
    }
    else
    {
        translateZ(tz);
    }
}
Esempio n. 4
0
///// mouseMoveEvent //////////////////////////////////////////////////////////
void GLView::mouseMoveEvent(QMouseEvent* e)
/// Overridden from QGlWidget::mouseMoveEvent. Handles left mouse button drags.
{
  if(e->modifiers() & Qt::LeftButton) // only track mousemoves for the left button
  {
    QPoint newPosition = e->pos(); // the mouse moved from mousePosition to newPosition

    if(e->modifiers() & Qt::ShiftModifier) // shift has precedence over control
    {
      ///// LEFTBUTTON + SHIFT
      ///// up/down movement: zooming (z-translation)
      ///// left/right movement: z-rotation
      ///// decoupled
      if(abs(newPosition.y() - mousePosition.y()) > abs(newPosition.x() - mousePosition.x()))
        translateZ(newPosition.y() - mousePosition.y());
      else
        zRot = -180.0f * static_cast<float>(newPosition.x() - mousePosition.x()) / static_cast<float>(width()); // z-rotation of entire system
    }
    else if(e->modifiers() & Qt::ControlModifier)
    {
      ///// LEFTBUTTON + CONTROL
      ///// up/down movement: y-translation
      ///// left/right movement: x-translation
      ///// coupled
      translateXY(newPosition.x() - mousePosition.x(), newPosition.y() - mousePosition.y());
    }
    else
    {
      ///// LEFTBUTTON ONLY
      ///// up/down movement: x-rotation
      ///// left/right movement: y-rotation
      yRot = 180.0f * static_cast<float>(newPosition.x() - mousePosition.x()) / static_cast<float>(width());
      xRot = 180.0f * static_cast<float>(newPosition.y() - mousePosition.y()) / static_cast<float>(height());
    }
    setModified();
    mousePosition = newPosition;
    updateGL();
    startingClick = false;
  }
  else
    e->ignore();
}
Esempio n. 5
0
void StraightRodPair::compressToZ(double z) {

  if (zPlusModules_.empty()) return;

  logINFO("Layer slated for compression");

  auto findMaxZModule = [&]() { return *std::max_element(zPlusModules_.begin(), zPlusModules_.end(), [](const BarrelModule& m1, const BarrelModule& m2) { return m1.planarMaxZ() < m2.planarMaxZ(); }); };
  auto findMinZModule = [&]() { return *std::min_element(zMinusModules_.begin(), zMinusModules_.end(), [](const BarrelModule& m1, const BarrelModule& m2) { return m1.planarMinZ() < m2.planarMinZ(); }); };

  double Deltap =  fabs(z) - findMaxZModule().planarMaxZ();
  double Deltam = -fabs(z) - findMinZModule().planarMinZ();

  logINFO("Rod length cannot exceed " + any2str(z));
  logINFO("  Z+ rod will be compressed by " + any2str(fabs(Deltap)));
  logINFO("  Z- rod will be compressed by " + any2str(fabs(Deltam)));

  if (allowCompressionCuts()) {
    logINFO("Compression algorithm is allowed to cut modules which fall out entirely from the maximum z line");
    int zPlusOrigSize = zPlusModules_.size();
    for (auto it = zPlusModules_.begin(); it != zPlusModules_.end();) {
      if (it->planarMinZ() > z) it = zPlusModules_.erase(it); 
      else ++it;
    }
    logINFO("  " + any2str(zPlusOrigSize - zPlusModules_.size()) + " modules were cut from the Z+ rod");
    if (zPlusOrigSize - zPlusModules_.size()) { 
      Deltap = fabs(z) - findMaxZModule().planarMaxZ();  // we have to use findMaxZModule instead of checking only the last module as there might be inversions at high Z
      logINFO("  Z+ rod now exceeding by " + any2str(fabs(Deltap)));
    }
    int zMinusOrigSize = zMinusModules_.size();
    for (auto it = zMinusModules_.begin(); it != zMinusModules_.end();) {
      if (it->planarMaxZ() < -z) it = zMinusModules_.erase(it); 
      else ++it;
    }
    logINFO("  " + any2str(zMinusOrigSize - zMinusModules_.size()) + " modules were cut from the Z- rod");
    if (zMinusOrigSize - zMinusModules_.size()) { 
      Deltam = -fabs(z) - findMinZModule().planarMinZ(); 
      logINFO("  Z- rod now exceeding by " + any2str(fabs(Deltam)));
    }
  }

  logINFO("Iterative compression of Z+ rod");
  int i;
  static const int maxIterations = 50;
  for (i = 0; fabs(Deltap) > 0.1 && i < maxIterations; i++) {
    double deltap=Deltap/((findMaxZModule().center()).Z());
    std::map<int, double> zGuards;
    zGuards[1] = zGuards[-1] = std::numeric_limits<double>::lowest();
    int parity = zPlusParity();
    for (auto it = zPlusModules_.begin(); it < zPlusModules_.end(); ++it, parity = -parity) {
      double translation = deltap*it->center().Z();
      double minPhysZ = MIN(it->planarMinZ(), it->center().Z() - it->physicalLength()/2);
      if (minPhysZ + translation < zGuards[parity]) 
        translation = zGuards[parity] - minPhysZ;
      it->translateZ(translation); 
      double maxPhysZ = MAX(it->planarMaxZ(), it->center().Z() + it->physicalLength()/2);
      zGuards[parity] = maxPhysZ;
    }
    Deltap =  fabs(z) - findMaxZModule().planarMaxZ();
  }
  if (i == maxIterations) {
    logINFO("Iterative compression didn't terminate after " + any2str(maxIterations) + " iterations. Z+ rod still exceeds by " + any2str(fabs(Deltap))); 
    logWARNING("Failed to compress Z+ rod. Still exceeding by " + any2str(fabs(Deltap)) + ". Check info tab.");
  } else logINFO("Z+ rod successfully compressed after " + any2str(i) + " iterations. Rod now only exceeds by " + any2str(fabs(Deltap)) + " mm.");

  logINFO("Iterative compression of Z- rod");
  for (i = 0; fabs(Deltam) > 0.1 && i < maxIterations; i++) {
    double deltam=Deltam/((findMinZModule().center()).Z()); // this can be optimized
    std::map<int, double> zGuards;
    zGuards[1] = zGuards[-1] = std::numeric_limits<double>::max();
    int parity = -zPlusParity();
    for (auto it = zMinusModules_.begin(); it < zMinusModules_.end(); ++it, parity = -parity) {
      double translation = deltam*it->center().Z();
      double maxPhysZ = MAX(it->planarMaxZ(), it->center().Z() + it->physicalLength()/2);
      if (maxPhysZ + translation > zGuards[parity]) 
        translation = zGuards[parity] - maxPhysZ;
      it->translateZ(translation); 
      double minPhysZ = MIN(it->planarMinZ(), it->center().Z() - it->physicalLength()/2);
      zGuards[parity] = minPhysZ;
    }
    Deltam = -fabs(z) - findMinZModule().planarMinZ(); 
  }  
  if (i == 20) {
    logINFO("Iterative compression didn't terminate after " + any2str(maxIterations) + " iterations. Z- rod still exceeds by " + any2str(fabs(Deltam))); 
    logWARNING("Failed to compress Z- rod. Still exceeding by " + any2str(fabs(Deltam)) + ". Check info tab.");
  } else logINFO("Z- rod successfully compressed after " + any2str(i) + " iterations. Rod now only exceeds by " + any2str(fabs(Deltam)) + " mm.");

}