listjointconstraint.cc 2.4 KB
Newer Older
1
2
3
4
5
//
// Copyright (c) CNRS
// Authors: Heidy Dallard
//

6
7
#include "listjointconstraint.hh"

8
9
10
11
12
#include <QVBoxLayout>
#include <QWidget>
#include <QLabel>
#include <QListWidget>

13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
namespace hpp {
  namespace gui {
    ListJointConstraint::ListJointConstraint(HppWidgetsPlugin *plugin)
    {
      plugin_ = plugin;
      widget_ = new QWidget;
      QVBoxLayout* layout = new QVBoxLayout(widget_);
      jointList_ = new QListWidget(widget_);

      layout->addWidget(jointList_);
      jointList_->setSelectionMode(QAbstractItemView::ExtendedSelection);
    }

    ListJointConstraint::~ListJointConstraint()
    {
      delete widget_;
    }

    QWidget* ListJointConstraint::getWidget() const
    {
      return widget_;
    }

    void ListJointConstraint::reload()
    {
      hpp::Names_t_var joints = plugin_->client()->robot()->getAllJointNames();

      jointList_->clear();
      for (unsigned i = 0; i < joints->length(); i++) {
        jointList_->addItem(joints[i].in());
      }
    }

    LockedJointConstraint::LockedJointConstraint(HppWidgetsPlugin *plugin)
        : ListJointConstraint(plugin)
    {
      widget_->layout()->addWidget(new QLabel("The joints will be locked in their current position.", widget_));
    }

    LockedJointConstraint::~LockedJointConstraint()
    {
    }

    QString LockedJointConstraint::getName() const
    {
      return "Lock joints";
    }

Joseph Mirabel's avatar
Joseph Mirabel committed
61
    void LockedJointConstraint::operator ()(QString const&)
62
63
    {
      QList<QListWidgetItem *> selected = jointList_->selectedItems();
64
65
      std::size_t len (0);
      std::vector <std::string> lockedJointName;
66
      foreach(QListWidgetItem* item, selected) {
67
68
69
70
71
72
73
74
75
76
77
78
        std::string jointName = item->text().toStdString();
        lockedJointName.push_back (std::string ("locked_") + jointName);
        hpp::floatSeq_var config =
          plugin_->client ()->robot ()->getJointConfig (jointName.c_str ());
        plugin_->client()->problem()->createLockedJoint
          (lockedJointName.back ().c_str (), jointName.c_str (), config.in());
        ++len;
      }
      char** nameList = hpp::Names_t::allocbuf((CORBA::ULong) len);
      Names_t names ((CORBA::ULong) len, (CORBA::ULong) len, nameList);
      for (std::size_t i=0; i < len; ++i) {
        nameList[i] = const_cast <char*> (lockedJointName [i].c_str ());
79
      }
80
81
82
      plugin_->client()->problem()->setLockedJointConstraints
        ("config-projector", names);
      delete nameList;
83
84
85
    }
  }
}