directpath.py 2.51 KB
Newer Older
1
2
3
4
5
#
#  Copyright (c) CNRS
#  Author: Joseph Mirabel
#

Joseph Mirabel's avatar
Joseph Mirabel committed
6
7
8
9
from PythonQt import QtGui, Qt
import sys
sys.argv = ["none"]

Joseph Mirabel's avatar
Joseph Mirabel committed
10
class DirectPathBox(QtGui.QGroupBox):
Joseph Mirabel's avatar
Joseph Mirabel committed
11
    def __init__ (self, parent, plugin):
Joseph Mirabel's avatar
Joseph Mirabel committed
12
        super(DirectPathBox, self).__init__ ("Direct Path", parent)
Joseph Mirabel's avatar
Joseph Mirabel committed
13
14
        self.fromCfg = []
        self.toCfg = []
Joseph Mirabel's avatar
Joseph Mirabel committed
15
        self.plugin = plugin
Joseph Mirabel's avatar
Joseph Mirabel committed
16
        self.initWidget()
Joseph Mirabel's avatar
Joseph Mirabel committed
17

18
19
    def shootRandom(self):
        q = self.plugin.client.robot.shootRandomConfig()
20
        self.plugin.hppPlugin.setCurrentQtConfig(q)
21

Joseph Mirabel's avatar
Joseph Mirabel committed
22
    def getFrom (self):
23
        self.fromCfg = self.plugin.hppPlugin.getCurrentQtConfig()
Joseph Mirabel's avatar
Joseph Mirabel committed
24
25

    def getTo (self):
26
        self.toCfg = self.plugin.hppPlugin.getCurrentQtConfig()
Joseph Mirabel's avatar
Joseph Mirabel committed
27
28

    def makePath (self):
Joseph Mirabel's avatar
Joseph Mirabel committed
29
30
31
32
33
34
35
36
        n = self.plugin.client.robot.getConfigSize()
        if len(self.fromCfg) == n and len(self.toCfg) == n:
            success, pid, msg = self.plugin.client.problem.directPath (self.fromCfg, self.toCfg, self.validatePath.isChecked())
            if not success:
                self.plugin.main.logError (msg)
            else: # Success
                # It would be nice to have access to the Path Player widget in order to
                # select the good path index...
37
38
39
40
41
                if self.projectPath.isChecked ():
                    success = self.plugin.client.problem.projectPath(pid)
                    if not success:
                        self.plugin.main.logError ("Path could not be projected.")

Joseph Mirabel's avatar
Joseph Mirabel committed
42
43
        else:
            self.plugin.main.logError ("Configuration does not have the good size. Did you save them ?")
Joseph Mirabel's avatar
Joseph Mirabel committed
44

Joseph Mirabel's avatar
Joseph Mirabel committed
45
46
    def initWidget (self):
        box = QtGui.QVBoxLayout(self)
47
48
        random =  QtGui.QPushButton(self)
        box.addWidget(random)
Joseph Mirabel's avatar
Joseph Mirabel committed
49
        setFrom =  QtGui.QPushButton(self)
Joseph Mirabel's avatar
Joseph Mirabel committed
50
        box.addWidget(setFrom)
Joseph Mirabel's avatar
Joseph Mirabel committed
51
        setTo =  QtGui.QPushButton(self)
Joseph Mirabel's avatar
Joseph Mirabel committed
52
        box.addWidget(setTo)
Joseph Mirabel's avatar
Joseph Mirabel committed
53
        self.validatePath = QtGui.QCheckBox(self)
Joseph Mirabel's avatar
Joseph Mirabel committed
54
        box.addWidget(self.validatePath)
55
56
        self.projectPath = QtGui.QCheckBox(self)
        box.addWidget(self.projectPath)
Joseph Mirabel's avatar
Joseph Mirabel committed
57
        makePath = QtGui.QPushButton(self)
Joseph Mirabel's avatar
Joseph Mirabel committed
58
        box.addWidget(makePath)
59
        random.text = "Shoot random config"
Joseph Mirabel's avatar
Joseph Mirabel committed
60
61
62
        setFrom.text = 'Save config as origin'
        setTo.text = 'Save config as destination'
        self.validatePath.text = 'Validate path'
63
        self.projectPath.text = "Project path"
Joseph Mirabel's avatar
Joseph Mirabel committed
64
        makePath.text = 'Create path'
65
        random.connect('clicked()', self.shootRandom)
Joseph Mirabel's avatar
Joseph Mirabel committed
66
67
68
        setFrom.connect('clicked()', self.getFrom)
        setTo.connect('clicked()', self.getTo)
        makePath.connect('clicked()', self.makePath)