Commit c2e945e3 authored by Joseph Mirabel's avatar Joseph Mirabel

Fix compatibility with Python 3.

parent 88c380e0
from plugin import Plugin from .plugin import Plugin
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
from PythonQt import QtGui, Qt from PythonQt import QtGui, Qt
import xml.etree.ElementTree as ET import xml.etree.ElementTree as ET
from itertools import izip
import re import re
def _makeCheckBox(active): def _makeCheckBox(active):
...@@ -113,7 +113,7 @@ class CollisionPairs(QtGui.QWidget): ...@@ -113,7 +113,7 @@ class CollisionPairs(QtGui.QWidget):
def configValidation(self): def configValidation(self):
collide = self.plugin.client.robot.autocollisionCheck() collide = self.plugin.client.robot.autocollisionCheck()
for p, c in izip(self.orderedPairs, collide): for p, c in zip(self.orderedPairs, collide):
if c: if c:
self.pairToRow[p][self.CURRENT_CONFIG].setText("Collision") self.pairToRow[p][self.CURRENT_CONFIG].setText("Collision")
else: else:
...@@ -121,7 +121,7 @@ class CollisionPairs(QtGui.QWidget): ...@@ -121,7 +121,7 @@ class CollisionPairs(QtGui.QWidget):
def setCollisionPair(self, r, l1, l2, active, reason): def setCollisionPair(self, r, l1, l2, active, reason):
pair = _Pair(l1, l2) pair = _Pair(l1, l2)
if self.pairToRow.has_key(pair): if pair in self.pairToRow:
self.pairToRow[pair][self.ACTIVE].checked = active self.pairToRow[pair][self.ACTIVE].checked = active
self.pairToRow[pair][self.REASON].setText(reason) self.pairToRow[pair][self.REASON].setText(reason)
return return
...@@ -149,15 +149,15 @@ class CollisionPairs(QtGui.QWidget): ...@@ -149,15 +149,15 @@ class CollisionPairs(QtGui.QWidget):
ncfg = int(pow(10, self.sliderRandomCfg.value / 10)) ncfg = int(pow(10, self.sliderRandomCfg.value / 10))
nbCol = [0] * len(self.pairToRow) nbCol = [0] * len(self.pairToRow)
r = self.plugin.client.robot r = self.plugin.client.robot
for i in xrange(ncfg): for i in range(ncfg):
cfg = r.shootRandomConfig() cfg = r.shootRandomConfig()
r.setCurrentConfig(cfg) r.setCurrentConfig(cfg)
collide = r.autocollisionCheck() collide = r.autocollisionCheck()
for i in xrange(len(collide)): for i in range(len(collide)):
if collide[i]: if collide[i]:
nbCol[i] += 1 nbCol[i] += 1
for p, n in izip(self.orderedPairs, nbCol): for p, n in zip(self.orderedPairs, nbCol):
self.pairToRow[p][self.PERCENTAGE].setData(Qt.Qt.DisplayRole, n * 100. / ncfg) self.pairToRow[p][self.PERCENTAGE].setData(Qt.Qt.DisplayRole, n * 100. / ncfg)
def refresh(self): def refresh(self):
...@@ -169,7 +169,7 @@ class CollisionPairs(QtGui.QWidget): ...@@ -169,7 +169,7 @@ class CollisionPairs(QtGui.QWidget):
inner, outer, active = self.plugin.client.robot.autocollisionPairs() inner, outer, active = self.plugin.client.robot.autocollisionPairs()
self.table.sortingEnabled = False self.table.sortingEnabled = False
self.table.setRowCount(len(inner)) self.table.setRowCount(len(inner))
for r, l1, l2, a in izip(xrange(len(inner)), inner, outer, active): for r, l1, l2, a in zip(range(len(inner)), inner, outer, active):
self.setCollisionPair(r, l1, l2, a, "From SRDF") self.setCollisionPair(r, l1, l2, a, "From SRDF")
self.table.sortingEnabled = True self.table.sortingEnabled = True
print(time.time() - start_time) print(time.time() - start_time)
...@@ -195,12 +195,12 @@ class CollisionPairs(QtGui.QWidget): ...@@ -195,12 +195,12 @@ class CollisionPairs(QtGui.QWidget):
p = _Pair(dc.attrib["link1"], dc.attrib["link2"]) p = _Pair(dc.attrib["link1"], dc.attrib["link2"])
pairsInFile[p] = dc pairsInFile[p] = dc
for p, row in self.pairToRow.iteritems(): for p, row in self.pairToRow.items():
if row[self.ACTIVE].checked: if row[self.ACTIVE].checked:
continue continue
reason = str(row[self.REASON].text()) reason = str(row[self.REASON].text())
pp = _Pair(_(p.l1), _(p.l2)) pp = _Pair(_(p.l1), _(p.l2))
if pairsInFile.has_key(pp): if pp in pairsInFile:
dc.attrib["reason"] = reason dc.attrib["reason"] = reason
else: else:
attrib = dict() attrib = dict()
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
# Author: Joseph Mirabel # Author: Joseph Mirabel
# #
from __future__ import print_function
from PythonQt import QtGui, Qt from PythonQt import QtGui, Qt
import numpy as np import numpy as np
from gepetto import Quaternion, Color from gepetto import Quaternion, Color
...@@ -76,7 +77,7 @@ class GraspFinder(QtGui.QWidget): ...@@ -76,7 +77,7 @@ class GraspFinder(QtGui.QWidget):
def optimize(self): def optimize(self):
n = len(self.P) n = len(self.P)
if not n == len(self.Q): if not n == len(self.Q):
print "P and Q must be of the same size" print("P and Q must be of the same size")
return return
P = np.array(self.P).transpose() P = np.array(self.P).transpose()
Q = np.array(self.Q).transpose() Q = np.array(self.Q).transpose()
...@@ -91,11 +92,11 @@ class GraspFinder(QtGui.QWidget): ...@@ -91,11 +92,11 @@ class GraspFinder(QtGui.QWidget):
T = [0,0,0,1,0,0,0] T = [0,0,0,1,0,0,0]
T[0:3] = t.tolist() T[0:3] = t.tolist()
T[3:7] = Quaternion(R).toTuple() T[3:7] = Quaternion(R).toTuple()
print self.names[0], T print(self.names[0], T)
self.instructions.text = "Current transform of\n" + self.names[0] + "\nis\n" + str(T) + "\n\nSelect a fixed point." self.instructions.text = "Current transform of\n" + self.names[0] + "\nis\n" + str(T) + "\n\nSelect a fixed point."
self.plugin.gui.gui.applyConfiguration(self.names[0], T) self.plugin.gui.gui.applyConfiguration(self.names[0], T)
self.plugin.gui.gui.refresh() self.plugin.gui.gui.refresh()
for i in xrange(n): for i in range(n):
self.setLineTransform(i) self.setLineTransform(i)
self.plugin.gui.gui.refresh() self.plugin.gui.gui.refresh()
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
# Author: Joseph Mirabel # Author: Joseph Mirabel
# #
from __future__ import print_function
from PythonQt import QtGui, Qt, QtCore from PythonQt import QtGui, Qt, QtCore
from hpp import Transform from hpp import Transform
from numpy import array from numpy import array
...@@ -60,14 +61,14 @@ class InspectBodies(QtGui.QWidget): ...@@ -60,14 +61,14 @@ class InspectBodies(QtGui.QWidget):
self.pointLabel ["global"].text = vec2str(vec(event.point (False))) self.pointLabel ["global"].text = vec2str(vec(event.point (False)))
self.normalLabel["global"].text = vec2str(vec(event.normal(False))) self.normalLabel["global"].text = vec2str(vec(event.normal(False)))
if len(self.refName.text) == 0: if len(self.refName.text) == 0:
print self.refName.text print(self.refName.text)
else: else:
T = Transform(self.plugin.client.robot.getJointPosition(str(self.refName.text))).inverse() T = Transform(self.plugin.client.robot.getJointPosition(str(self.refName.text))).inverse()
try: try:
self.pointLabel ["reference"].text = vec2str(T.transform( vec(event.point (False)))) self.pointLabel ["reference"].text = vec2str(T.transform( vec(event.point (False))))
self.normalLabel["reference"].text = vec2str(T.quaternion.transform(vec(event.normal(False)))) self.normalLabel["reference"].text = vec2str(T.quaternion.transform(vec(event.normal(False))))
except ValueError as e: except ValueError as e:
print e print(e)
print event.point(False) print(event.point(False))
print vec(event.point(False)) print(vec(event.point(False)))
event.done() event.done()
...@@ -3,14 +3,15 @@ ...@@ -3,14 +3,15 @@
# Author: Joseph Mirabel and Heidy Dallard # Author: Joseph Mirabel and Heidy Dallard
# #
from __future__ import print_function
from PythonQt import QtGui, Qt from PythonQt import QtGui, Qt
from hpp.corbaserver import Client from hpp.corbaserver import Client
from hpp.corbaserver.robot import Robot from hpp.corbaserver.robot import Robot
from gepetto.corbaserver import Client as GuiClient from gepetto.corbaserver import Client as GuiClient
from directpath import DirectPathBox from .directpath import DirectPathBox
from findGrasp import GraspFinder from .findGrasp import GraspFinder
from inspector import InspectBodies from .inspector import InspectBodies
from collision_pairs import CollisionPairs from .collision_pairs import CollisionPairs
from .parameters import Parameters from .parameters import Parameters
class _PathTab(QtGui.QWidget): class _PathTab(QtGui.QWidget):
...@@ -64,14 +65,14 @@ class _PathManagement(QtGui.QWidget): ...@@ -64,14 +65,14 @@ class _PathManagement(QtGui.QWidget):
if (len(selected) > 1): if (len(selected) > 1):
first = int(selected[0].text()) first = int(selected[0].text())
for i in range(1, len(selected)): for i in range(1, len(selected)):
print "Concatenate %s and %s" % (first, int(selected[i].text())) print("Concatenate %s and %s" % (first, int(selected[i].text())))
self.plugin.client.problem.concatenatePath(first, int(selected[i].text())) self.plugin.client.problem.concatenatePath(first, int(selected[i].text()))
def erase(self): def erase(self):
selected = self.paths.selectedItems() selected = self.paths.selectedItems()
if (len(selected) > 0): if (len(selected) > 0):
for i in range(len(selected) - 1, -1, -1): for i in range(len(selected) - 1, -1, -1):
print "erase path %s " % (int(selected[i].text())) print("erase path %s " % (int(selected[i].text())))
self.plugin.client.problem.erasePath(int(selected[i].text())) self.plugin.client.problem.erasePath(int(selected[i].text()))
self.refresh() self.refresh()
...@@ -152,7 +153,7 @@ class _StepByStepSolverTab(QtGui.QWidget): ...@@ -152,7 +153,7 @@ class _StepByStepSolverTab(QtGui.QWidget):
self.plugin.main.log ("Problem is solved") self.plugin.main.log ("Problem is solved")
def executeOneStep(self): def executeOneStep(self):
for i in xrange(self.stepCount.value): for i in range(self.stepCount.value):
if self.plugin.client.problem.executeOneStep(): if self.plugin.client.problem.executeOneStep():
self.plugin.main.log ("Problem is solved") self.plugin.main.log ("Problem is solved")
break break
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment