示例#1
0
void BodyStateViewImpl::updateDeviceStates(DevicePtr device, int rowIndex)
{
    if(currentBody){
        StateItem* item = static_cast<StateItem*>(stateTreeWidget.topLevelItem(rowIndex));
        int size = device->stateSize();
        buf.resize(size);
        device->writeState(&buf.front());
        int i;
        for(i=0; i < size; ++i){
            item->setText(i + 1, QString::number(buf[i], 'f', 2));
        }
        for(   ; i < item->lastNumValidColumns; ++i){
            item->setText(i + 1, "");
        }
        item->lastNumValidColumns = size;
    }
}
示例#2
0
void BodyStateViewImpl::updateExtraStates()
{
    if(!currentBody){
        return;
    }
    const int prec = 3;
    
    for(int i=0 ;i < accessors.size(); ++i){
        const ExtraBodyStateAccessor& accessor = *accessors[i];
        const vector<int>& itemMap = extraStateItemMap[i];
        accessor.getState(extraState);
        for(int j=0; j < extraState.size(); ++j){
            const ExtraBodyStateAccessor::Value& s = extraState[j];
            StateItem* item = static_cast<StateItem*>(stateTreeWidget.topLevelItem(itemMap[j]));
            int column = 1;
            switch(s.which()){
            case ExtraBodyStateAccessor::BOOL:
                item->setText(column++, s.getBool() ? _("ON") : _("OFF"));
                break;
            case ExtraBodyStateAccessor::INT:
                item->setText(column++, QString::number(s.getInt(), 'f', prec));
                break;
            case ExtraBodyStateAccessor::DOUBLE:
                item->setText(column++, QString::number(s.getDouble(), 'f', prec));
                break;
            case ExtraBodyStateAccessor::ANGLE:
                item->setText(column++, QString::number(s.getAngle(), 'f', prec));
                break;
            case ExtraBodyStateAccessor::STRING:
                item->setText(column++, s.getString().c_str());
                break;
                /*
                  case ExtraBodyStateAccessor::VECTOR2:
                  {
                  const Vector2& v = get<Vector2>(s);
                  item->setText(column++, QString::number(v[0], 'f', prec));
                  item->setText(column++, QString::number(v[1], 'f', prec));
                  break;
                  }
                */
            case ExtraBodyStateAccessor::VECTOR3:
            {
                const Vector3f& v = s.getVector3f();
                item->setText(column++, QString::number(v[0], 'f', prec));
                item->setText(column++, QString::number(v[1], 'f', prec));
                item->setText(column++, QString::number(v[2], 'f', prec));
                break;
            }
            case ExtraBodyStateAccessor::VECTORX:
            {
                const VectorX& v = s.getVectorX();
                for(int i=0; i < v.size(); ++i){
                    item->setText(column++, QString::number(v[i], 'f', prec));
                }
                break;
            }
            default:
                break;
            }
            for(int i=column; i < item->lastNumValidColumns; ++i){
                item->setText(i, "");
            }
            item->lastNumValidColumns = column;
        }
    }
}
示例#3
0
void BodyStateViewImpl::updateStateList(BodyItem* bodyItem)
{
    stateConnections.disconnect();
    DeviceList<Sensor> devices;

    extraStateItemMap.clear();
    stateTreeWidget.clear();
    int maxNumStateElements = 0;

    if(currentBody){
        devices = currentBody->devices();

        for(int i=0; i < devices.size(); ++i){
            Device* device = devices.get(i);
            StateItem* deviceItem = new StateItem();
        
            deviceItem->setText(0, QString(" %1 ").arg(device->name().c_str()));
            stateTreeWidget.addTopLevelItem(deviceItem);

            if(device->stateSize() > maxNumStateElements){
                maxNumStateElements = device->stateSize();
            }
            stateConnections.add(
                device->sigStateChanged().connect(
                    boost::bind(&BodyStateViewImpl::updateDeviceStates, this, device, i)));
        }

        vector<string> names;
        currentBody->getCaches(accessors, names);
        for(int i=0; i < accessors.size(); ++i){
            ExtraBodyStateAccessor& accessor = *accessors[i];
            vector<int> itemMap;
            accessor.getState(extraState);
            if(!extraState.empty()){
                for(int j=0; j < extraState.size(); ++j){
                    QTreeWidgetItem* stateItem = new StateItem();
                    stateItem->setText(0, QString(" %1 ").arg(accessor.getStateItemLabel(j)));
                    itemMap.push_back(stateTreeWidget.topLevelItemCount());
                    stateTreeWidget.addTopLevelItem(stateItem);
                    int m = ExtraBodyStateAccessor::getNumValueElements(extraState[j]);
                    if(m > maxNumStateElements){
                        maxNumStateElements = m;
                    }
                }
                stateConnections.add(
                    accessor.sigStateChanged().connect(
                        boost::bind(&BodyStateViewImpl::updateExtraStates, this)));
            }
            extraStateItemMap.push_back(itemMap);
        }
    }
    
    int lastColumn = maxNumStateElements + 1;
    stateTreeWidget.setColumnCount(lastColumn + 1);
    stateTreeWidget.setHeaderSectionResizeMode(0, QHeaderView::ResizeToContents);
    for(int i=0; i < maxNumStateElements; ++i){
        stateTreeWidget.setHeaderSectionResizeMode(i+1, QHeaderView::Stretch);
    }
    stateTreeWidget.setHeaderSectionResizeMode(lastColumn, QHeaderView::Fixed);
    stateTreeWidget.header()->resizeSection(lastColumn, 0);

    const int n = stateTreeWidget.topLevelItemCount();
    for(int i=0; i < n; ++i){
        QTreeWidgetItem* item = stateTreeWidget.topLevelItem(i);
        item->setTextAlignment(0, Qt::AlignHCenter);
        for(int j=0; j < maxNumStateElements; ++j){
            //item->setTextAlignment(j + 1, Qt::AlignHCenter);
            item->setTextAlignment(j + 1, Qt::AlignRight);
        }
    }
}