void ItemXML::moveDown() { QDomElement element = node_.toElement(); MIRO_ASSERT(!element.isNull()); QDomNode succ = node_.nextSibling(); while (!succ.isNull()) { QDomElement e = succ.toElement(); if (!e.isNull() && e.tagName() == element.tagName()) { break; } succ = succ.nextSibling(); } if (!succ.isNull()) { Super::moveDown(); node_.parentNode().insertAfter(node_, succ); setModified(); } }
void ItemXML::deleteItem() { // schedule for deletion // this will also remove the listviewitem deleteLater(); // remove this node at the parent node // as this is not taken care of in // the dtor of this class QDomNode n = node_.parentNode(); MIRO_ASSERT(!n.isNull()); n.removeChild(node_); // tell the parent, that he is modified // as he will not be able to ask us about it anymore ItemXML * p = dynamic_cast<ItemXML *>(parent()); if (p != NULL) { p->setModified(); } }
ParameterList::ParameterList(Miro::CFG::Parameter const& _param, QDomNode const& _node, QListView * _list, QListViewItem * _pre, QObject * _parent, const char * _name) : Super(_node, _list, _pre, _parent, _name), param_(_param), type_(typeFromName(_param.type_)) { MIRO_ASSERT(type_ != NONE); if (listViewItem()->listView()->columns() == 2) listViewItem()->setText(2, param_.type_); // get the nested parameter type int len = param_.type_.length(); int vlen = (type_ == VECTOR)? QString("std::vector<").length() : QString("std::set<").length(); len --; // tailing > len -= vlen; nestedTypeName_ = param_.type_.mid(vlen, len); }
void EventView::insertEvent(QString const& _stamp, QString const& _domain, QString const& _type, QString const& _event) { internalSetSelection_ = true; if (list_->selectedItem() == NULL && list_->firstChild() != NULL) { list_->setSelected(list_->firstChild(), true); } // insert at the beginning if (list_->firstChild() == NULL || _stamp < list_->firstChild()->text(0)) { new QListViewItem(list_, _stamp, _domain, _type, _event); list_->setSelected(list_->firstChild(), true); list_->ensureItemVisible(list_->firstChild()); if (last_ == NULL) last_ = list_->firstChild(); } // insert at the end else if (last_->text(0) < _stamp) { last_ = new QListViewItem(list_, last_, _stamp, _domain, _type, _event); list_->setSelected(last_, true); list_->ensureItemVisible(last_); } // insert somewher in between else if (list_->selectedItem() != NULL && list_->selectedItem()->text(0) != _stamp) { QListViewItem * item = list_->selectedItem(); MIRO_ASSERT(item != NULL); // after current selection if(_stamp > item->text(0)) { QListViewItem * prev = item; while (_stamp > item->text(0)) { prev = item; item = item->nextSibling(); } // insert if (_stamp != item->text(0)) { item = new QListViewItem(list_, prev, _stamp, _domain, _type, _event); } } // before current selection else { while (_stamp < item->text(0)) { QListViewItem * prev = list_->firstChild(); while (prev->nextSibling() != item) { prev = prev->nextSibling(); MIRO_ASSERT(prev != NULL); } item = prev; } if (_stamp != item->text(0)) { QListViewItem * prev = list_->firstChild(); while (prev->nextSibling() != item) { prev = prev->nextSibling(); MIRO_ASSERT(prev != NULL); } item = new QListViewItem(list_, prev, _stamp, _domain, _type, _event); } } list_->setSelected(item, true); } pruneHistory(); internalSetSelection_ = false; }
void FaulCanConnection::sendAccVelTicks(short, short) { MIRO_ASSERT(false); }
/** * @param parameter, the parameter description of the type * @param node, the qdom node in the document, containing the node * @param parentItem, the parent item in the list view * @param item, the item itself in the list view * @param parent, the parent widget of the dialog * @param name, the name of the dialog */ SingleParameterDialog:: SingleParameterDialog(Miro::CFG::Parameter const& _parameter, QDomNode const& _node, ItemXML * _parentItem, ItemXML * _item, QWidget * _parent, const char * _name) : Super(_node.parentNode(), _node, _parentItem, _item, _parent, _name), parameter_(_parameter) { MIRO_ASSERT(!_node.isNull()); QGridLayout * gridLayout = new QGridLayout(frame_, 1, 3, 2, 5, "gridLayout"); // add parameter struct: QLabel * name = new QLabel(frame_); QString n = parameter_.name_; n[0] = n[0].upper(); name->setText(n); gridLayout->addWidget(name, 0, 0); // search existing entry QDomNode parameterNode; if (!node_.isNull()) { parameterNode = node_.firstChild(); while(!parameterNode.isNull()) { QDomElement e = parameterNode.toElement(); if (!e.isNull() && e.attribute("name") == n) break; parameterNode = parameterNode.nextSibling(); } } SimpleParameter::Type editType = SimpleParameter::typeFromName(parameter_.type_); MIRO_ASSERT(editType != SimpleParameter::NONE); edit_ = new SimpleParameterEdit(editType, parameter_, parentNode_, node_, parentItem_, item_, frame_, n.latin1()); // add measure QLabel * measure = new QLabel(frame_); if (!parameter_.measure_.isEmpty()) { measure->setText(parameter_.measure_); QToolTip::add(measure, (parameter_.type_ != "angle")? parameter_.type_ : QString("double")); } else measure->setText(parameter_.type_); gridLayout->addWidget(measure, 0, 2); gridLayout->addWidget(edit_->editWidget(), 0, 1); frame_->sizeHint(); groupBox_->sizeHint(); // we need this to get the right size (hutz) groupBox_->setTitle("Parameters"); }
void ParameterDialog::initDialog() { editFelds_.clear(); QGridLayout * gridLayout = new QGridLayout(frame_, params_.size(), 3, 2, 5, "gridLayout"); // add parameter structs: unsigned long i = 0; Miro::CFG::ParameterVector::const_iterator first, last = params_.end(); for (first = params_.begin(); first != last; ++first, ++i) { // name QLabel * name = new QLabel(frame_); QString n = first->name_; n[0] = n[0].upper(); name->setText(n); gridLayout->addWidget(name, i, 0); // search existing entry QDomNode parameterNode; if (!node_.isNull()) { parameterNode = node_.firstChild(); while(!parameterNode.isNull()) { QDomElement e = parameterNode.toElement(); if (!e.isNull() && e.attribute("name") == n) break; parameterNode = parameterNode.nextSibling(); } } // if there is an existing entry // and we know our listview, // get the corresponding listview item ItemXML * childItem = NULL; if (!parameterNode.isNull() && item_ != NULL) { if (item_->children()) { QObjectList childList = *item_->children(); QObject * c = childList.first(); while (c) { childItem = dynamic_cast<ItemXML *>(c); MIRO_ASSERT(childItem != NULL); if (childItem->node().toElement().attribute("name") == n) { break; } childItem = NULL; c = childList.next(); } } } // create the dialog ParameterEdit * value; SimpleParameter::Type editType = SimpleParameter::typeFromName(first->type_); if (editType != SimpleParameter::NONE) { value = new SimpleParameterEdit(editType, *first, node_, parameterNode, item_, childItem, frame_, n.latin1()); // add measure QLabel * measure = new QLabel(frame_); if (!first->measure_.isEmpty()) { measure->setText(first->measure_); QToolTip::add(measure, (first->type_ != "angle")? first->type_ : QString("double")); } else measure->setText(first->type_); gridLayout->addWidget(measure, i, 2); } else { DeferredParameterEdit::EditType deferredEditType = DeferredParameterEdit::editType(first->type_); value = new DeferredParameterEdit(deferredEditType, *first, node_, parameterNode, item_, childItem, frame_, n.latin1()); } gridLayout->addWidget(value->editWidget(), i, 1); editFelds_.push_back(value); } }
void EventView::insertEvent(QString const& _stamp, QString const& _domain, QString const& _type, QString const& _event) { // A new item will be created, and it will become the selected item internalSetSelection_ = true; // Precondition assert(list_ != NULL); // The selected QTreeWidget item(s), if any const QList<QTreeWidgetItem*> selectedItems = list_->selectedItems(); // The root QTreeWidget QTreeWidgetItem * const pRoot = list_->invisibleRootItem(); assert(pRoot != NULL); // The number of items at the top level const int childCount = pRoot->childCount(); // The first item at the top level, if any QTreeWidgetItem * const pFirstTreeWidgetItem = (childCount > 0) ? pRoot->child(0) : NULL; // If no item is selected and there is a top-level item, select it if (selectedItems.isEmpty() && (pFirstTreeWidgetItem != NULL)) { pFirstTreeWidgetItem->setSelected(true); } // Case 1 of 3: insert at the beginning if ( // The QTreeWidget has no children (pFirstTreeWidgetItem == NULL) || // The time stamp is less than that of the earliest child item (_stamp < pRoot->child(0)->text(0))) { // Create the new item QTreeWidget * const pParent = list_; QStringList strings; strings << _stamp << _domain << _type << _event; QTreeWidgetItem * const pNewTreeWidgetItem = new QTreeWidgetItem(pParent, strings); // Insert the new item at the beginning of the list list_->insertTopLevelItem(0, pNewTreeWidgetItem); // Select it pNewTreeWidgetItem->setSelected(true); // Make it visible list_->scrollToItem(pNewTreeWidgetItem); if (last_ == NULL) { // The first one now shall later be last for the times they are a-changin last_ = pNewTreeWidgetItem; } } // Case 2 of 3: Insert at the end (which is distinct from the beginning) // The time stamp is greater than that of the lateest item, which must exist else if (last_->text(0) < _stamp) { // Create the new item QTreeWidget * const pParent = list_; QStringList strings; strings << _stamp << _domain << _type << _event; QTreeWidgetItem * const pNewTreeWidgetItem = new QTreeWidgetItem(pParent, strings); // Insert the new item at the end of the list list_->addTopLevelItem(pNewTreeWidgetItem); last_ = pNewTreeWidgetItem; // Select it pNewTreeWidgetItem->setSelected(true); // Make it visible list_->scrollToItem(pNewTreeWidgetItem); } // Case 3 of 3: Insert relative to the selected item else if ( // An item is selected !list_->selectedItems().isEmpty() && // The (first) selected item does not have the same time stamp (list_->selectedItems()[0]->text(0) != _stamp)) { // Fetch the (first) selected item QTreeWidgetItem * const pSelectedItem = list_->selectedItems()[0]; MIRO_ASSERT(pSelectedItem != NULL); if (_stamp > pSelectedItem->text(0)) { // Case 3a: Insert the new item after the (first) selected item // Find the first item after the selected one later than the time stamp int index = list_->indexOfTopLevelItem(pSelectedItem); while (_stamp > pRoot->child(index)->text(0)) { index++; } QTreeWidgetItem * const pSuccessor = pRoot->child(index); assert(pSuccessor != NULL); assert(_stamp <= pSuccessor->text(0)); assert(index > 0); if (_stamp != pSuccessor->text(0)) { // Create the new item QTreeWidget * const pParent = list_; QStringList strings; strings << _stamp << _domain << _type << _event; QTreeWidgetItem * const pNewItem = new QTreeWidgetItem(pParent, strings); assert(pNewItem != NULL); // Insert it pRoot->insertChild(index - 1, pNewItem); // Select it pNewItem->setSelected(true); } } else { // Case 3b: Insert the new item before the (first) selected item // Find the first item before the selected one later than the time stamp int index = 0; while (_stamp < pRoot->child(index)->text(0)) { index++; } QTreeWidgetItem * const pPredecessor = pRoot->child(index); assert(pPredecessor != NULL); assert(_stamp >= pPredecessor->text(0)); if (_stamp != pPredecessor->text(0)) { // Create the new item QTreeWidget * const pParent = list_; QStringList strings; strings << _stamp << _domain << _type << _event; QTreeWidgetItem * const pNewItem = new QTreeWidgetItem(pParent, strings); assert(pNewItem != NULL); // Insert it pRoot->insertChild(index, pNewItem); // Select it pNewItem->setSelected(true); } } } pruneHistory(); internalSetSelection_ = false; }
int ConstraintArbiter::handle_timeout(const ACE_Time_Value &, const void*) { std::cout << "ConstraintArbiter-handle_timeout before Guard" << std::endl; Miro::Guard guard(mutex_); std::cout << "ConstraintArbiter-handle_timeout after Guard" << std::endl; timing_.start(); ConstraintArbiterParameters * params = const_cast<ConstraintArbiterParameters *> ( dynamic_cast<ConstraintArbiterParameters const *>(params_)); MIRO_ASSERT(params != NULL); Vector2d velocity; // std::FILE *logFile1; typedef std::vector<Behaviour *> BehaviourVector; // preinitialize the velocity space params->velocitySpace.clearAllEvals(); params->velocitySpace.clearCurvatureConstraints(); // let each behaviour calculate its velocity space MessageVector::const_iterator first, last = message_.end(); for(first = message_.begin(); first != last; ++first) { if ((*first)->active){ std::cout << "ConstraintArbiter before addEval" << std::endl; (*first)->id->addEvaluation(¶ms->velocitySpace); std::cout << "ConstraintArbiter after addEval" << std::endl; } } // calculate new velocity using the content of the velocity space std::cout << "ConstraintArbiter before applyFunction" << std::endl; velocity = params->velocitySpace.applyObjectiveFunctionToEval(); std::cout << "ConstraintArbiter after applyFunction" << std::endl; // cout << "LEFT: " << velocity.real() << " ::: " << velocity.imag() << endl; timing_.stop(); // set steering commands pMotion_->setLRVelocity(velocity.real(), velocity.imag()); if (Miro::Log::level() >= Miro::Log::LL_PRATTLE) { TimeStats stats; timing_.eval(stats); MIRO_DBG_OSTR(MIRO, LL_PRATTLE, "ConstraintArbiter eval time: " << std::endl << stats); } // logFile1 = std::fopen("velocityspace.log","a"); // for(int r_index = 0; r_index <= 2*(velocitySpace_.maxVelocity_/velocitySpace_.spaceResolution_)+1; r_index++) { // for(int l_index = 0; l_index <= 2*(velocitySpace_.maxVelocity_/velocitySpace_.spaceResolution_)+1; l_index++) { // fprintf(logFile1, "%d\n", velocitySpace_.velocitySpace_[l_index][r_index]); // } // } // fclose(logFile1); if (pSupplier_ && pSupplier_->subscribed(offerIndex_) && !skipDebug_) { unsigned int const headerSize = 12; unsigned int dataSize = params->velocitySpace.dynamicWindowSize(); unsigned char * buffer = new unsigned char[headerSize + dataSize]; short * h = reinterpret_cast<short *>(buffer); h[0] = 0; // protocol id h[1] = params->velocitySpace.size(); params->velocitySpace.windowBounds(h[2], h[3], h[4], h[5]); unsigned char * p = buffer + headerSize; params->velocitySpace.dumpDynamicWindow(p); Miro::VelocitySpaceIDL * dynamicWindow = new Miro::VelocitySpaceIDL(headerSize + dataSize, headerSize + dataSize, buffer, 1); notifyEvent_.remainder_of_body <<= dynamicWindow; pSupplier_->sendEvent(notifyEvent_); } skipDebug_++; skipDebug_ %= skipMax_; return 0; }
void DeferredParameterEdit::setXML() { QDomNode tmpNode = tmpParentNode_.firstChild(); // no edit -> nothing to be done if (!modified_) return; // delete entry if edit field is empty if (tmpNode.isNull() || tmpNode.firstChild().isNull()) { if (!node_.isNull()) { parentNode_.removeChild(node_); delete item_; } else { modified_ = false; } return; } // crete a node if necessary if (node_.isNull()) { MIRO_ASSERT(!parentNode_.ownerDocument().isNull()); QDomElement e = parentNode_.ownerDocument().createElement(XML_TAG_PARAMETER); e.setAttribute(XML_ATTRIBUTE_KEY, name()); node_ = parentNode_.appendChild(e); MIRO_ASSERT(!node_.isNull()); } //-------------------------------------- // replace node by new content // remember the predecessor QListViewItem * pre = NULL; if (item_) { QListViewItem * parent = item_->listViewItem()->parent(); if (parent != NULL) { pre = parent->firstChild(); while (pre != NULL) { if (pre->nextSibling() == item_->listViewItem()) break; pre = pre->nextSibling(); } } // delete the current content delete item_; } // replace the xml subtree QDomNode node = tmpNode.cloneNode(); node_.parentNode().replaceChild(node, node_); node_ = node; // reconstruct the listview if available if (parentItem_) { item_ = NULL; QString typeName = parameter_.type_; if (type_ == NESTED_PARAMETER) { Miro::CFG::Type const * const parameterType = ConfigFile::instance()->description().getType(typeName); if (parameterType == NULL) { throw QString("Parameter description for " + typeName + " not found.\nCheck whether the relevant description file is loaded."); } item_ = new CompoundParameter(*parameterType, node, parentItem_->listViewItem(), pre, parentItem_, name()); } else if (type_ == VECTOR || type_ == SET) { item_ = new ParameterList(parameter_, node, parentItem_->listViewItem(), pre, parentItem_, name()); } if (item_ != NULL) dynamic_cast<ParameterXML *>(item_)->init(); } }