Exemplo n.º 1
0
 def move_by(self, relindex):
     # don't i recall code similar to this somewhere? yes, BaseIterator.py - stub, not yet used
     self.index += self.direction * relindex
     self.off_end = False # be optimistic, we might be back on if we were off
     assert 0 # LOGIC BUG: if rail dirs alternate as we move, then the following conds alternate too --
             # we're not always in the same loop below!! (better find out if i need to write it this way
             # or only as the scanner which yields the atoms -- might be easier that way) ### DECIDE
     while self.index < 0 and not self.off_end:
         self._move_to_prior_rail(sign(relindex))
     while self.index >= len(self.rail) and not self.off_end:
         self._move_to_next_rail(sign(relindex))
     return
Exemplo n.º 2
0
def sign_with_threshhold( num, thresh ):
    """
    Return -1, 0, or 1 as num is << 0, close to 0, or >> 0,
    where "close to 0" means abs(num) <= thresh.
    """
    if abs(num) <= thresh:
        return 0
    return sign(num)
Exemplo n.º 3
0
def sign_with_threshhold(num, thresh):
    """
    Return -1, 0, or 1 as num is << 0, close to 0, or >> 0,
    where "close to 0" means abs(num) <= thresh.
    """
    if abs(num) <= thresh:
        return 0
    return sign(num)
    def leftDragRotation(self, event):
        """
        Rotate the selected object(s) or slide and rotate along the an axis

        @param event: The mouse left drag event.
        @type  event: QMouseEvent object
        @see: self.leftDrag
        """

        if self.command and self.command.propMgr and \
           hasattr(self.command.propMgr, 'rotateComboBox'):
            if self.command.propMgr.rotateComboBox.currentText() != "Free Drag":
                return

        if self.rotateOption == 'ROTATEDEFAULT':
            self.leftDragFreeRotation(event)
            return

        if self.rotateOption == 'ROT_TRANS_ALONG_AXIS':
            try:
                self.leftADrag(event)
            except:
                print_compact_traceback(" error doing leftADrag")

            return

        #Rotate section
        w=self.o.width+0.0
        h=self.o.height+0.0

        deltaMouse = V(event.pos().x() - self.o.MousePos[0],
                       self.o.MousePos[1] - event.pos().y())

        a =  dot(self.Zmat, deltaMouse)
        dx,dy =  a * V(self.o.scale/(h*0.5), 2*math.pi/w)

        if self.rotateOption == 'ROTATEX':
            ma = V(1,0,0) # X Axis
        elif self.rotateOption == 'ROTATEY':
            ma = V(0,1,0) # Y Axis
        elif self.rotateOption == 'ROTATEZ':
            ma = V(0,0,1) # Z Axis
        else:
            print "rotateChunks_GraphicsMode.leftDrag Error: unknown rotateOption value:",\
                  self.rotateOption
            return

        qrot = Q(ma,-dy) # Quat for rotation delta.
        # Increment rotation delta (and convert to degrees)
        self.rotDelta += qrot.angle *180.0/math.pi * sign(dy)

        if self.command and self.command.propMgr and \
           hasattr(self.command.propMgr, 'updateRotationDeltaLabels'):
            self.command.propMgr.updateRotationDeltaLabels(self.rotateOption,
                                                   self.rotDelta)

        self.win.assy.rotateSpecifiedMovables(qrot,
                                              movables = self._leftDrag_movables)

        # Print status bar msg indicating the current rotation delta.
        if self.o.assy.selmols:
            msg = "%s delta: [0 Angstroms] [%.2f Degrees]" % (self.axis,
                                                              self.rotDelta)
            env.history.statusbar_msg(msg)

        # common finished code
        self.dragdist += vlen(deltaMouse)
        self.o.SaveMouse(event)
        self.o.gl_update()

        #End of Rotate Section
        return