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-2020 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 
24 class RenderOp:
25  RENDERMODE_ATTRIBUTE_NAME = "RenderMode"
26  KEEP_ATTRIBUTE_NAME = "Keep"
27  FLAGS_ATTRIBUTE_NAME = "Flags"
28 
29  def __init__(self, render_mode, selection, flags, keep=False):
30  self.render_mode_ = render_mode
31  self.selection_ = selection
32  self.keep_ = keep
33  self.flags_ = flags
34 
35  def GetName(self):
36  return "Render mode: %s"%str(self.GetRenderMode())
37 
38  def SetRenderMode(self, render_mode):
39  self.render_mode_ = render_mode
40 
41  def GetRenderMode(self):
42  return self.render_mode_
43 
44  def SetSelection(self, selection):
45  self.selection_ = selection
46 
47  def GetSelection(self):
48  return self.selection_
49 
50  def SetSelectionFlags(self, flags):
51  self.flags_ = flags
52 
53  def GetSelectionFlags(self):
54  return self.flags_
55 
56  def SetKeep(self, keep):
57  self.keep_ = keep
58 
59  def IsKept(self):
60  return self.keep_
61 
62  def ApplyOn(self, entity):
63  if (entity is not None) and isinstance(entity, gfx.Entity):
64  entity.SetRenderMode(self.GetRenderMode(),entity.view.Select(self.GetSelection(),self.GetSelectionFlags()),self.IsKept())
65 
66  def ToInfo(self,group):
67  group.SetAttribute(RenderOp.RENDERMODE_ATTRIBUTE_NAME, str(self.GetRenderMode().name))
68  group.SetAttribute(RenderOp.KEEP_ATTRIBUTE_NAME, str(int(self.IsKept())))
69  group.SetAttribute(RenderOp.FLAGS_ATTRIBUTE_NAME, str(self.GetSelectionFlags()))
70  group.SetTextData(str(self.GetSelection()))
71 
72  @staticmethod
73  def FromInfo(group):
74  render_op = None
75  if (group.HasAttribute(RenderOp.RENDERMODE_ATTRIBUTE_NAME)
76  and group.HasAttribute(RenderOp.KEEP_ATTRIBUTE_NAME)):
77  render_mode = getattr(gfx.RenderMode, group.GetAttribute(RenderOp.RENDERMODE_ATTRIBUTE_NAME))
78  keep = bool(int(group.GetAttribute(RenderOp.KEEP_ATTRIBUTE_NAME)))
79  flags=0
80  if group.HasAttribute(RenderOp.FLAGS_ATTRIBUTE_NAME):
81  flags = int(group.GetAttribute(RenderOp.FLAGS_ATTRIBUTE_NAME))
82  selection = group.GetTextData()
83  render_op = RenderOp(render_mode,selection,flags,keep)
84  return render_op
graphical rendering of mol::EntityHandle entites
Definition: entity.hh:60