OpenStructure
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
render_op.py
Go to the documentation of this file.
1 #------------------------------------------------------------------------------
2 # This file is part of the OpenStructure project <www.openstructure.org>
3 #
4 # Copyright (C) 2008-2011 by the OpenStructure authors
5 #
6 # This library is free software; you can redistribute it and/or modify it under
7 # the terms of the GNU Lesser General Public License as published by the Free
8 # Software Foundation; either version 3.0 of the License, or (at your option)
9 # any later version.
10 # This library is distributed in the hope that it will be useful, but WITHOUT
11 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
13 # details.
14 #
15 # You should have received a copy of the GNU Lesser General Public License
16 # along with this library; if not, write to the Free Software Foundation, Inc.,
17 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 #------------------------------------------------------------------------------
19 # -*- coding: utf-8 -*-
20 
21 from ost import info
22 from ost import gfx
23 from PyQt4 import QtGui
24 
25 class RenderOp:
26  RENDERMODE_ATTRIBUTE_NAME = "RenderMode"
27  KEEP_ATTRIBUTE_NAME = "Keep"
28  FLAGS_ATTRIBUTE_NAME = "Flags"
29 
30  def __init__(self, render_mode, selection, flags, keep=False):
31  self.render_mode_ = render_mode
32  self.selection_ = selection
33  self.keep_ = keep
34  self.flags_ = flags
35 
36  def GetName(self):
37  return "Render mode: %s"%str(self.GetRenderMode())
38 
39  def SetRenderMode(self, render_mode):
40  self.render_mode_ = render_mode
41 
42  def GetRenderMode(self):
43  return self.render_mode_
44 
45  def SetSelection(self, selection):
46  self.selection_ = selection
47 
48  def GetSelection(self):
49  return self.selection_
50 
51  def SetSelectionFlags(self, flags):
52  self.flags_ = flags
53 
54  def GetSelectionFlags(self):
55  return self.flags_
56 
57  def SetKeep(self, keep):
58  self.keep_ = keep
59 
60  def IsKept(self):
61  return self.keep_
62 
63  def ApplyOn(self, entity):
64  if (entity is not None) and isinstance(entity, gfx.Entity):
65  entity.SetRenderMode(self.GetRenderMode(),entity.view.Select(self.GetSelection(),self.GetSelectionFlags()),self.IsKept())
66 
67  def ToInfo(self,group):
68  group.SetAttribute(RenderOp.RENDERMODE_ATTRIBUTE_NAME, str(self.GetRenderMode().name))
69  group.SetAttribute(RenderOp.KEEP_ATTRIBUTE_NAME, str(int(self.IsKept())))
70  group.SetAttribute(RenderOp.FLAGS_ATTRIBUTE_NAME, str(self.GetSelectionFlags()))
71  group.SetTextData(str(self.GetSelection()))
72 
73  @staticmethod
74  def FromInfo(group):
75  render_op = None
76  if (group.HasAttribute(RenderOp.RENDERMODE_ATTRIBUTE_NAME)
77  and group.HasAttribute(RenderOp.KEEP_ATTRIBUTE_NAME)):
78  render_mode = getattr(gfx.RenderMode, group.GetAttribute(RenderOp.RENDERMODE_ATTRIBUTE_NAME))
79  keep = bool(int(group.GetAttribute(RenderOp.KEEP_ATTRIBUTE_NAME)))
80  flags=0
81  if group.HasAttribute(RenderOp.FLAGS_ATTRIBUTE_NAME):
82  flags = int(group.GetAttribute(RenderOp.FLAGS_ATTRIBUTE_NAME))
83  selection = group.GetTextData()
84  render_op = RenderOp(render_mode,selection,flags,keep)
85  return render_op
graphical rendering of mol::EntityHandle entites
Definition: entity.hh:63