4 raise RuntimeError(
"runtime error in PiVy")
6 def get_writer(parent):
7 class PivyWriter(parent):
9 parent.__init__(self,
"pivy")
11 def _setup_pivy(self):
17 if "DISPLAY" not in os.environ.keys():
18 raise RuntimeError(
"No display variable found")
19 myWindow = pivy.sogui.SoGui.init(sys.argv[0])
21 raise RuntimeError(
"Can't open PiVy window.")
24 scene = pivy.coin.SoSeparator()
27 viewer = pivy.sogui.SoGuiExaminerViewer(myWindow)
30 viewer.setSceneGraph(scene)
32 viewer.setTitle(
"IMP")
37 def handle_color(self, parent, c):
38 color= self.pivy.coin.SoMFColor()
39 color.setValue(c.get_red(), c.get_green(), c.get_blue())
40 myMaterial = self.pivy.coin.SoMaterial()
41 myMaterial.diffuseColor.setValue(color)
42 parent.addChild(myMaterial)
43 def handle_sphere(self, s, c, n):
44 sep = self.pivy.coin.SoSeparator()
45 self.root.addChild(sep)
47 self.handle_color(sep, c)
48 tr= self.pivy.coin.SoTransform()
49 tr.translation.setValue(s.get_geometry().get_center()[0],
50 s.get_geometry().get_center()[1],
51 s.get_geometry().get_center()[2])
52 tr.scaleFactor.setValue(s.get_geometry().get_radius(),
53 s.get_geometry().get_radius(),
54 s.get_geometry().get_radius())
56 sphere=self.pivy.coin.SoSphere()
59 def handle_label(self, s, c, n):
63 sep = self.pivy.coin.SoSeparator()
64 self.handle_color(sep, c)
65 tr= self.pivy.coin.SoTransform()
66 tr.translation.setValue(loc.get_center()[0], loc.get_center()[1], loc.get_center()[2])
68 to= self.pivy.coin.SoText2()
69 to.string.setValue(txt)
72 def handle_cylinder(self, s, c, n):
74 sep = self.pivy.coin.SoSeparator()
75 self.root.addChild(sep)
76 self.handle_color(sep, c)
77 tr= self.pivy.coin.SoTransform()
80 center= seg.get_middle_point()
82 tr.translation.setValue(self.pivy.coin.SbVec3f(center[0], center[1],
85 uv= seg.get_direction().get_unit_vector()
86 tr.rotation.setValue(self.pivy.coin.SbRotation(self.pivy.coin.SbVec3f(0,1,0),
87 self.pivy.coin.SbVec3f(uv[0],uv[1],uv[2])))
92 sphere=self.pivy.coin.SoCylinder()
93 sphere.radius.setValue(cyl.get_radius())
94 sphere.height.setValue(cyl.get_segment().get_length())
99 self.set_was_used(
True)
100 self.pivy.sogui.SoGui.show(self.window)
101 self.pivy.sogui.SoGui.mainLoop()