5 raise RuntimeError(
"runtime error in PiVy")
8 def get_writer(parent):
9 class PivyWriter(parent):
12 parent.__init__(self,
"pivy")
15 def _setup_pivy(self):
21 if "DISPLAY" not in os.environ.keys():
22 raise RuntimeError(
"No display variable found")
23 myWindow = pivy.sogui.SoGui.init(sys.argv[0])
25 raise RuntimeError(
"Can't open PiVy window.")
26 self.window = myWindow
28 scene = pivy.coin.SoSeparator()
31 viewer = pivy.sogui.SoGuiExaminerViewer(myWindow)
34 viewer.setSceneGraph(scene)
36 viewer.setTitle(
"IMP")
42 def handle_color(self, parent, c):
43 color = self.pivy.coin.SoMFColor()
44 color.setValue(c.get_red(), c.get_green(), c.get_blue())
45 myMaterial = self.pivy.coin.SoMaterial()
46 myMaterial.diffuseColor.setValue(color)
47 parent.addChild(myMaterial)
49 def handle_sphere(self, s, c, n):
50 sep = self.pivy.coin.SoSeparator()
51 self.root.addChild(sep)
53 self.handle_color(sep, c)
54 tr = self.pivy.coin.SoTransform()
55 tr.translation.setValue(s.get_geometry().get_center()[0],
56 s.get_geometry().get_center()[1],
57 s.get_geometry().get_center()[2])
58 tr.scaleFactor.setValue(s.get_geometry().get_radius(),
59 s.get_geometry().get_radius(),
60 s.get_geometry().get_radius())
62 sphere = self.pivy.coin.SoSphere()
66 def handle_label(self, s, c, n):
68 loc = s.get_location()
70 sep = self.pivy.coin.SoSeparator()
71 self.handle_color(sep, c)
72 tr = self.pivy.coin.SoTransform()
73 tr.translation.setValue(
78 to = self.pivy.coin.SoText2()
79 to.string.setValue(txt)
83 def handle_cylinder(self, s, c, n):
85 sep = self.pivy.coin.SoSeparator()
86 self.root.addChild(sep)
87 self.handle_color(sep, c)
88 tr = self.pivy.coin.SoTransform()
89 cyl = s.get_geometry()
90 seg = cyl.get_segment()
91 center = seg.get_middle_point()
93 tr.translation.setValue(
94 self.pivy.coin.SbVec3f(center[0], center[1],
99 self.pivy.coin.SbRotation(self.pivy.coin.SbVec3f(0, 1, 0),
100 self.pivy.coin.SbVec3f(uv[0], uv[1], uv[2])))
105 sphere = self.pivy.coin.SoCylinder()
106 sphere.radius.setValue(cyl.get_radius())
107 sphere.height.setValue(cyl.get_segment().get_length())
113 self.set_was_used(
True)
114 self.pivy.sogui.SoGui.show(self.window)
115 self.pivy.sogui.SoGui.mainLoop()
VT get_unit_vector(VT vt)
Returns a unit vector pointing at the same direction as this vector.
void show(Hierarchy h, std::ostream &out=std::cout)
Print out a molecular hierarchy.