Ejemplo n.º 1
0
	def _doPlaneAutospin(self, trigger, xform, frameNumber):
		clipModel = getClipModel()
		if not clipModel:
			return
		p = clipModel.clipPlane
		p.xformNormal(xform)
		clipModel.clipPlane = p
Ejemplo n.º 2
0
 def _doPlaneAutospin(self, trigger, xform, frameNumber):
     clipModel = getClipModel()
     if not clipModel:
         return
     p = clipModel.clipPlane
     p.xformNormal(xform)
     clipModel.clipPlane = p
Ejemplo n.º 3
0
def clip_selected_models():
    'Toggle per-model clipping for selected models'
    from chimera import selection, openModels
    mlist = [m for m in selection.currentGraphs() if m.display]
    if len(mlist) == 0:
        mlist = [m for m in openModels.list() if m.display and m.useClipPlane]
        if len(mlist) == 0:
            mlist = [m for m in openModels.list() if m.display]
            if len(mlist) == 0:
                return

    from chimera import tkgui
    for m in mlist:
        if m.useClipPlane:
            m.useClipPlane = False
        elif m.bbox()[0]:
            tkgui.setClipModel(m)  # Set initial clip plane placement.

    # Turn off clip adjust mouse mode.
    cm = tkgui.getClipModel()
    if cm is None or not cm.useClipPlane:
        from chimera import dialogs
        import ModelClip
        cd = dialogs.find(ModelClip.ClipDialog.name)
        if cd:
            cd.stopMouseClip()
Ejemplo n.º 4
0
 def _planeRot(self, viewer, event):
     xf = viewer.vsphere(event.time, event.x, event.y, event.state % 2 == 1)
     if xf.isIdentity():
         return
     clipModel = getClipModel()
     if not clipModel:
         return
     p = clipModel.clipPlane
     axis, angle = clipModel.openState.xform.getRotation()
     mxf = chimera.Xform.rotation(axis, angle)
     mxfinv = chimera.Xform.rotation(axis, -angle)
     mxfinv.multiply(xf)
     mxfinv.multiply(mxf)
     p.xformNormal(mxfinv)
     clipModel.clipPlane = p
Ejemplo n.º 5
0
def clip_adjust():
    'Toggle mouse modes to move per-model clip plane of selected model'
    from chimera import selection, openModels, tkgui
    mlist = [
        m for m in selection.currentGraphs() if m.useClipPlane and m.display
    ]
    if len(mlist) == 0:
        mlist = [m for m in openModels.list() if m.useClipPlane and m.display]
    if clip_adjust_enabled():
        if len(mlist) == 0 or tkgui.getClipModel() in mlist:
            enable_clip_adjust(False)
        else:
            tkgui.setClipModel(mlist[0])
    elif mlist:
        enable_clip_adjust(mlist[0])
Ejemplo n.º 6
0
	def _planeRot(self, viewer, event):
		xf = viewer.vsphere(event.time, event.x, event.y,
							event.state % 2 == 1)
		if xf.isIdentity():
			return
		clipModel = getClipModel()
		if not clipModel:
			return
		p = clipModel.clipPlane
		axis, angle = clipModel.openState.xform.getRotation()
		mxf = chimera.Xform.rotation(axis, angle)
		mxfinv = chimera.Xform.rotation(axis, -angle)
		mxfinv.multiply(xf)
		mxfinv.multiply(mxf)
		p.xformNormal(mxfinv)
		clipModel.clipPlane = p
Ejemplo n.º 7
0
 def _toggleClip(self):
     if self.clipVar.get():
         try:
             initClip(self.model)
         except ValueError:
             replyobj.error("Model cannot currently be"
                            " clipped [no valid bounding box]\n")
             self.clipVar.set(False)
             return
         self.slabThicknessVar.set(self.model.clipThickness)
         for w in self.clipDependentWidgets:
             w.config(state='normal')
     else:
         self.model.useClipPlane = False
         if getClipModel() == self.model:
             self.clipDialog.stopMouseClip()
             self.mouseVar.set(False)
         for w in self.clipDependentWidgets:
             w.config(state='disabled')
Ejemplo n.º 8
0
	def _toggleClip(self):
		if self.clipVar.get():
			try:
				initClip(self.model)
			except ValueError:
				replyobj.error("Model cannot currently be"
					" clipped [no valid bounding box]\n")
				self.clipVar.set(False)
				return
			self.slabThicknessVar.set(self.model.clipThickness)
			for w in self.clipDependentWidgets:
				w.config(state='normal')
		else:
			self.model.useClipPlane = False
			if getClipModel() == self.model:
				self.clipDialog.stopMouseClip()
				self.mouseVar.set(False)
			for w in self.clipDependentWidgets:
				w.config(state='disabled')
Ejemplo n.º 9
0
    def _planeTrans(self, viewer, event):
        clipModel = getClipModel()
        if not clipModel:
            return
        p = clipModel.clipPlane
        dx, dy = viewer.delta(event.x, event.y, event.state % 2 == 1)
        axis, angle = clipModel.openState.xform.getRotation()
        mxf = chimera.Xform.rotation(axis, angle)
        n = mxf.apply(p.normal)

        # figure out major axis of normal in lab space
        if abs(n.x) >= abs(n.y):
            axis = (0, 1)
        else:
            axis = (1, 0)

        # reassign normal so there are no zeros
        # in mouse adjustment calculation
        def fuzzySign(x):
            if x < -1e-6:
                return -1
            if x > 1e-6:
                return 1
            return 0

        n = [fuzzySign(n.x), fuzzySign(n.y), fuzzySign(n.z)]
        if n[axis[0]] == 0:
            # should never happen with non-zero normal
            n[axis[0]] = 1
        if n[axis[1]] == 0:
            n[axis[1]] = n[axis[0]]  # mimic major axis
        n = chimera.Vector(*n)
        adjust = n.x * dx + n.y * dy

        distance = 2 * viewer.camera.extent * adjust
        p.moveOrigin(distance)
        clipModel.clipPlane = p
Ejemplo n.º 10
0
	def _planeTrans(self, viewer, event):
		clipModel = getClipModel()
		if not clipModel:
			return
		p = clipModel.clipPlane
		dx, dy = viewer.delta(event.x, event.y, event.state % 2 == 1)
		axis, angle = clipModel.openState.xform.getRotation()
		mxf = chimera.Xform.rotation(axis, angle)
		n = mxf.apply(p.normal)

		# figure out major axis of normal in lab space
		if abs(n.x) >= abs(n.y):
			axis = (0, 1)
		else:
			axis = (1, 0)

		# reassign normal so there are no zeros 
		# in mouse adjustment calculation
		def fuzzySign(x):
			if x < -1e-6:
				return -1
			if x > 1e-6:
				return 1
			return 0
		n = [fuzzySign(n.x), fuzzySign(n.y), fuzzySign(n.z)]
		if n[axis[0]] == 0:
			# should never happen with non-zero normal
			n[axis[0]] = 1
		if n[axis[1]] == 0:
			n[axis[1]] = n[axis[0]]		# mimic major axis
		n = chimera.Vector(*n)
		adjust = n.x * dx + n.y * dy

		distance = 2 * viewer.camera.extent * adjust
		p.moveOrigin(distance)
		clipModel.clipPlane = p
Ejemplo n.º 11
0
    def __init__(self, clipDialog, model):
        from chimera.widgets import ModelOptionMenu
        self.clipDialog = clipDialog
        self.model = model
        self.clipDependentWidgets = []
        Tkinter.Frame.__init__(self, clipDialog.uiMaster())
        interior = self  # used to be a Pmw.Group instead of a Frame!
        self.clipVar = Tkinter.IntVar(interior)
        self.clipVar.set(self.model.useClipPlane)
        Tkinter.Checkbutton(interior,
                            command=self._toggleClip,
                            text="Enable clipping",
                            variable=self.clipVar).grid(row=0, sticky='w')
        slabFrame = Tkinter.Frame(interior)
        slabFrame.grid(row=1, sticky='w')
        self.slabVar = Tkinter.IntVar(interior)
        self.slabVar.set(self.model.useClipThickness)
        cbutton = Tkinter.Checkbutton(slabFrame,
                                      command=self._changeSlab,
                                      text="Use slab mode with thickness",
                                      variable=self.slabVar)
        cbutton.grid(row=0, column=0, sticky='w')
        self.clipDependentWidgets.append(cbutton)
        self.slabThicknessVar = Tkinter.DoubleVar(slabFrame)
        self.slabThicknessVar.set(self.model.clipThickness)
        entry = Tkinter.Entry(slabFrame,
                              width=4,
                              textvariable=self.slabThicknessVar)
        entry.grid(row=0, column=1, sticky='w')
        entry.bind('<KeyPress-Return>', self._changeSlab)
        self.clipDependentWidgets.append(entry)
        butFrame = Tkinter.Frame(interior)
        butFrame.grid(row=2, sticky='w')
        button = Tkinter.Button(
            butFrame,
            pady=0,
            command=lambda: chimera.tkgui.normalizeClipFacing(self.model),
            text="Orient plane")
        button.grid(row=0, column=0, sticky='e')
        self.clipDependentWidgets.append(button)
        label = Tkinter.Label(butFrame, text="perpendicular to line of sight")
        label.grid(row=0, column=1, sticky='w')
        self.clipDependentWidgets.append(label)
        label = Tkinter.Label(butFrame,
                              text="with center of rotation at center of view")
        label.grid(row=1, column=0, columnspan=2)
        self.clipDependentWidgets.append(label)

        butFrame = Tkinter.Frame(interior)
        butFrame.grid(row=3, sticky='w')
        button = Tkinter.Button(butFrame,
                                pady=0,
                                command=clipDialog._flipPlane,
                                text="Flip plane")
        button.grid(row=0, column=0, sticky='e')
        self.clipDependentWidgets.append(button)
        label = Tkinter.Label(butFrame, text="180 degrees")
        label.grid(row=0, column=1, sticky='w')
        self.clipDependentWidgets.append(label)

        butFrame = Tkinter.Frame(interior)
        butFrame.grid(row=4, sticky='w')
        button = Tkinter.Button(
            butFrame,
            pady=0,
            command=lambda: self.clipDialog._align(self.menu.getvalue()),
            text="Align plane")
        button.grid(row=0, column=0, sticky='e')
        self.clipDependentWidgets.append(button)
        self.menu = ModelOptionMenu(butFrame, labelpos='w', label_text="with")

        def kludge(self=self.menu, **kw):
            newKw = {}
            for k, v in kw.items():
                newKw["menubutton_" + k] = v
                newKw["label_" + k] = v
            self.configure(**newKw)

        self.menu.config = kludge
        self.menu.grid(row=0, column=1, sticky='w')
        self.clipDependentWidgets.append(self.menu)
        label = Tkinter.Label(butFrame, text="clip plane")
        label.grid(row=0, column=2, sticky='w')
        self.clipDependentWidgets.append(label)

        self.mouseVar = Tkinter.IntVar(interior)
        self.mouseVar.set(getClipModel() == model)
        self.mouseActiveButton = Tkinter.Checkbutton(
            interior,
            command=self._toggleMouse,
            variable=self.mouseVar,
            text="Adjust clipping with mouse as below")
        self.mouseActiveButton.grid(row=5, sticky='w')
        self.clipDependentWidgets.append(self.mouseActiveButton)

        if not self.clipVar.get():
            for w in self.clipDependentWidgets:
                w.config(state='disabled')
Ejemplo n.º 12
0
 def _planeStart(self, viewer, event, cursor):
     viewer.recordPosition(event.time, event.x, event.y, cursor),
     clipModel = getClipModel()
     if not clipModel:
         return
     viewer.showPlaneModel = clipModel, .5
Ejemplo n.º 13
0
	def __init__(self, clipDialog, model):
		from chimera.widgets import ModelOptionMenu
		self.clipDialog = clipDialog
		self.model = model
		self.clipDependentWidgets = []
		Tkinter.Frame.__init__(self, clipDialog.uiMaster())
		interior = self # used to be a Pmw.Group instead of a Frame!
		self.clipVar = Tkinter.IntVar(interior)
		self.clipVar.set(self.model.useClipPlane)
		Tkinter.Checkbutton(interior, command=self._toggleClip,
			text="Enable clipping", variable=self.clipVar).grid(
			row=0, sticky='w')
		slabFrame = Tkinter.Frame(interior)
		slabFrame.grid(row=1, sticky='w')
		self.slabVar = Tkinter.IntVar(interior)
		self.slabVar.set(self.model.useClipThickness)
		cbutton = Tkinter.Checkbutton(slabFrame,
				    command=self._changeSlab,
				    text="Use slab mode with thickness",
				    variable=self.slabVar)
		cbutton.grid(row=0, column=0, sticky='w')
		self.clipDependentWidgets.append(cbutton)
		self.slabThicknessVar = Tkinter.DoubleVar(slabFrame)
		self.slabThicknessVar.set(self.model.clipThickness)
		entry = Tkinter.Entry(slabFrame, width=4,
				      textvariable=self.slabThicknessVar)
		entry.grid(row=0, column=1, sticky='w')
		entry.bind('<KeyPress-Return>', self._changeSlab)
		self.clipDependentWidgets.append(entry)
		butFrame = Tkinter.Frame(interior)
		butFrame.grid(row=2, sticky='w')
		button = Tkinter.Button(butFrame, pady=0, command=lambda:
				chimera.tkgui.normalizeClipFacing(self.model),
				text="Orient plane")
		button.grid(row=0, column=0, sticky='e')
		self.clipDependentWidgets.append(button)
		label = Tkinter.Label(butFrame,
					text="perpendicular to line of sight")
		label.grid(row=0, column=1, sticky='w')
		self.clipDependentWidgets.append(label)
		label = Tkinter.Label(butFrame,
			text="with center of rotation at center of view")
		label.grid(row=1, column=0, columnspan=2)
		self.clipDependentWidgets.append(label)

		butFrame = Tkinter.Frame(interior)
		butFrame.grid(row=3, sticky='w')
		button = Tkinter.Button(butFrame, pady=0, command=
				clipDialog._flipPlane, text="Flip plane")
		button.grid(row=0, column=0, sticky='e')
		self.clipDependentWidgets.append(button)
		label = Tkinter.Label(butFrame, text="180 degrees")
		label.grid(row=0, column=1, sticky='w')
		self.clipDependentWidgets.append(label)

		butFrame = Tkinter.Frame(interior)
		butFrame.grid(row=4, sticky='w')
		button = Tkinter.Button(butFrame, pady=0, command=lambda :
				self.clipDialog._align(self.menu.getvalue()),
				text="Align plane")
		button.grid(row=0, column=0, sticky='e')
		self.clipDependentWidgets.append(button)
		self.menu = ModelOptionMenu(butFrame, labelpos='w',
							label_text="with")
		def kludge(self=self.menu, **kw):
			newKw = {}
			for k, v in kw.items():
				newKw["menubutton_" + k] = v
				newKw["label_" + k] = v
			self.configure(**newKw)
		self.menu.config = kludge
		self.menu.grid(row=0, column=1, sticky='w')
		self.clipDependentWidgets.append(self.menu)
		label = Tkinter.Label(butFrame, text="clip plane")
		label.grid(row=0, column=2, sticky='w')
		self.clipDependentWidgets.append(label)

		self.mouseVar = Tkinter.IntVar(interior)
		self.mouseVar.set(getClipModel() == model)
		self.mouseActiveButton = Tkinter.Checkbutton(interior,
			command=self._toggleMouse, variable=self.mouseVar,
			text="Adjust clipping with mouse as below")
		self.mouseActiveButton.grid(row=5, sticky='w')
		self.clipDependentWidgets.append(self.mouseActiveButton)

		if not self.clipVar.get():
			for w in self.clipDependentWidgets:
				w.config(state='disabled')
Ejemplo n.º 14
0
	def _planeStart(self, viewer, event, cursor):
		viewer.recordPosition(event.time, event.x, event.y, cursor),
		clipModel = getClipModel()
		if not clipModel:
			return
		viewer.showPlaneModel = clipModel, .5
Ejemplo n.º 15
0
def clip_adjust_enabled():

    if clip_dialog().normMouse:
        from chimera import tkgui
        return tkgui.getClipModel()
    return None