OpenStructure
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
visibility_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 
25  VISIBLE_ATTRIBUTE_NAME = "Visible"
26  FLAGS_ATTRIBUTE_NAME = "Flags"
27 
28  def __init__(self, selection, flags, visible=False):
29  self.selection_ = selection
30  self.visible_ = visible
31  self.flags_ = flags
32 
33  def GetName(self):
34  return "Visible: %s"%str(self.IsVisible())
35 
36  def SetSelection(self, selection):
37  self.selection_ = selection
38 
39  def GetSelection(self):
40  return self.selection_
41 
42  def SetVisible(self, visible):
43  self.visible_ = visible
44 
45  def SetSelectionFlags(self, flags):
46  self.flags_ = flags
47 
48  def GetSelectionFlags(self):
49  return self.flags_
50 
51  def IsVisible(self):
52  return self.visible_
53 
54  def ApplyOn(self, entity):
55  if (entity is not None) and isinstance(entity, gfx.Entity):
56  entity.SetVisible(entity.view.Select(self.GetSelection(),self.GetSelectionFlags()),self.IsVisible())
57 
58  def ToInfo(self,group):
59  group.SetAttribute(VisibilityOp.VISIBLE_ATTRIBUTE_NAME, str(int(self.IsVisible())))
60  group.SetAttribute(VisibilityOp.FLAGS_ATTRIBUTE_NAME, str(self.GetSelectionFlags()))
61  group.SetTextData(str(self.GetSelection()))
62 
63  @staticmethod
64  def FromInfo(group):
65  visible_op = None
66  if group.HasAttribute(VisibilityOp.VISIBLE_ATTRIBUTE_NAME):
67  visible = bool(int(group.GetAttribute(VisibilityOp.VISIBLE_ATTRIBUTE_NAME)))
68  flags = 0
69  if group.HasAttribute(VisibilityOp.FLAGS_ATTRIBUTE_NAME):
70  flags = int(group.GetAttribute(VisibilityOp.FLAGS_ATTRIBUTE_NAME))
71  selection = group.GetTextData()
72  visible_op = VisibilityOp(selection,flags,visible)
73  return visible_op
graphical rendering of mol::EntityHandle entites
Definition: entity.hh:63