Пример #1
0
 void buttonDown(Gosu::Button btn) noexcept override
 {
     if (btn == Gosu::kbEscape) {
        close();
     } else if (btn == Gosu::msLeft) {
         auto selected = selectNode();
         if (selected) {
             if (input().down(Gosu::kbLeftShift)) {
                 // dragl
                 grabbedNode = selected;
             }
         } else {
             auto nearest = graph.getNearestNode(mousePosition());
             auto node = graph.createNode(mousePosition());
             nodeOwner[node] = game.getCurrentPlayer();
             node -> connect(nearest);
             onGraphChanged();
             game.endTurn();
         }
     } else if (btn == Gosu::msRight) {
         auto selected = selectNode();
         if (selected) {
             connectingNode = selected;
         }
     }
 }
Пример #2
0
void NodeGraphDisplay::onControlClick(NodeControl *nc)
{
	if(stickySelect())
		selectNode(nc, true);
	else if(toggleStickySelect())
		selectNodeToggle(nc);
	else
	{
		clearSelected();
		selectNode(nc, true);
	}
}
Пример #3
0
void TestRouting::TestNoDest()
{
    initRoutes();
    for (Long n = 1; n <= elementsof(nodes); n++)
        for (Long i = 1; i <= elementsof(nodes); i++) {
            selectNode(n);
            if (i != n)
                sendPacket(GET_VERSION, i+4);
        }
    runNodes(SFP_SPS_TIME/2);
//    networkStats();

    QCOMPARE(nodeStat(2,getGoodFrame), (Long)0);
    QCOMPARE(nodeStat(1,getGoodFrame), (Long)0);
    QCOMPARE(nodeStat(3,getGoodFrame), (Long)0);
    QCOMPARE(nodeStat(4,getGoodFrame), (Long)0);

    QCOMPARE(nodeStat(2,getReRouted), (Long)0);
    QCOMPARE(nodeStat(1,getReRouted), (Long)0);
    QCOMPARE(nodeStat(3,getReRouted), (Long)0);
    QCOMPARE(nodeStat(4,getReRouted), (Long)0);

    QCOMPARE(nodeStat(2,getNoDest), (Long)3);
    QCOMPARE(nodeStat(1,getNoDest), (Long)3);
    QCOMPARE(nodeStat(3,getNoDest), (Long)3);
    QCOMPARE(nodeStat(4,getNoDest), (Long)3);
}
Пример #4
0
void NodeGraphDisplay::selectNodeToggle(NodeControl *nc)
{
	if(nc->selected)
		deselectNode(nc);
	else
		selectNode(nc, (selectedControls.size() > 0));
}
Пример #5
0
void WVuMeter::setup(QDomNode node)
{
    // Set pixmaps
    bool bHorizontal = false;
    if (!selectNode(node, "Horizontal").isNull() &&
        selectNodeQString(node, "Horizontal")=="true")
        bHorizontal = true;

    setPixmaps(getPath(selectNodeQString(node, "PathBack")),
               getPath(selectNodeQString(node, "PathVu")), bHorizontal);

    m_iPeakHoldSize = selectNodeInt(node, "PeakHoldSize");
    if(m_iPeakHoldSize < 0 || m_iPeakHoldSize > 100)
        m_iPeakHoldSize = DEFAULT_HOLDSIZE;

    m_iPeakFallStep = selectNodeInt(node, "PeakFallStep");
    if(m_iPeakFallStep < 1 || m_iPeakFallStep > 1000)
        m_iPeakFallStep = DEFAULT_FALLSTEP;

    m_iPeakHoldTime = selectNodeInt(node, "PeakHoldTime");
    if(m_iPeakHoldTime < 1 || m_iPeakHoldTime > 3000)
        m_iPeakHoldTime = DEFAULT_HOLDTIME;

    m_iPeakFallTime = selectNodeInt(node, "PeakFallTime");
    if(m_iPeakFallTime < 1 || m_iPeakFallTime > 1000)
        m_iPeakFallTime = DEFAULT_FALLTIME;
}
Пример #6
0
void WTime::setTimeFormat(QDomNode node) {
    // if a custom format is defined, all other formatting flags are ignored
    if (selectNode(node, "CustomFormat").isNull()) {
        // check if seconds should be shown
        QString secondsFormat = selectNodeQString(node, "ShowSeconds");
       if(secondsFormat == "true" || secondsFormat == "yes") {
           m_sTimeFormat = "h:mm:ss";
           m_iInterval = s_iSecondInterval;
       } else {
           m_sTimeFormat = "h:mm";
           m_iInterval = s_iMinuteInterval;
       }
       // check if 24 hour format or 12 hour format is selected
       QString clockFormat = selectNodeQString(node, "ClockFormat");
       if (clockFormat == "24" || clockFormat == "24hrs") {
       } else if (clockFormat == "12" ||
                  clockFormat == "12hrs" ||
                  clockFormat == "12ap") {
           m_sTimeFormat += " ap";
       } else if (clockFormat == "12AP") {
           m_sTimeFormat += " AP";
       } else {
           qDebug() << "WTime: Unknown clock format: " << clockFormat;
       }
    } else {
        // set the time format to the custom format
        m_sTimeFormat = selectNodeQString(node, "CustomFormat");
    }
}
Пример #7
0
PixmapSource SkinContext::getPixmapSource(const QDomNode& pixmapNode) const {
    PixmapSource source;

    const SvgParser svgParser(*this);

    if (!pixmapNode.isNull()) {
        QDomNode svgNode = selectNode(pixmapNode, "svg");
        if (!svgNode.isNull()) {
            // inline svg
            const QByteArray rslt = svgParser.saveToQByteArray(
                svgParser.parseSvgTree(svgNode, m_xmlPath));
            source.setSVG(rslt);
        } else {
            // filename
            QString pixmapName = nodeToString(pixmapNode);
            if (!pixmapName.isEmpty()) {
                source.setPath(getSkinPath(pixmapName));
                if (source.isSVG()) {
                    const QByteArray rslt = svgParser.saveToQByteArray(
                            svgParser.parseSvgFile(source.getPath()));
                    source.setSVG(rslt);
                }
            }
        }
    }

    return source;
}
Пример #8
0
void GGraph::selectOneNode( GNode* n)
{    
    emptySelection();
    selectNode( n);
    n->item()->highlight();
    n->item()->update();
}
	void TreeView::onMouseDown(const EventArgs& args)
	{
		const MouseEventArgs& mea = dynamic_cast<const MouseEventArgs&>(args);

		if(mea.button == MB_Left)
			selectNode(NULL);
	}
Пример #10
0
void WNumber::setup(QDomNode node)
{
    // Number of digits
    setNumDigits(selectNodeInt(node, "NumberOfDigits"));

    // Colors
    QPalette palette = m_pLabel->palette(); //we have to copy out the palette to edit it since it's const (probably for threadsafety)
    if (!WWidget::selectNode(node, "BgColor").isNull()) {
        m_qBgColor.setNamedColor(WWidget::selectNodeQString(node, "BgColor"));
        palette.setColor(this->backgroundRole(), WSkinColor::getCorrectColor(m_qBgColor));
        m_pLabel->setAutoFillBackground(true);
    }
    m_qFgColor.setNamedColor(WWidget::selectNodeQString(node, "FgColor"));
    palette.setColor(this->foregroundRole(), WSkinColor::getCorrectColor(m_qFgColor));
    m_pLabel->setPalette(palette);

    // Text
    if (!selectNode(node, "Text").isNull())
        m_qsText = selectNodeQString(node, "Text");

    // FWI: Begin of font size patch
    if (!selectNode(node, "FontSize").isNull()) {
        int fontsize = 9;
        fontsize = selectNodeQString(node, "FontSize").toInt();
        m_pLabel->setFont( QFont("Helvetica",fontsize,QFont::Normal) );
    }
    // FWI: End of font size patch

    // Alignment
    if (!selectNode(node, "Alignment").isNull())
    {
        if (selectNodeQString(node, "Alignment")=="right")
            m_pLabel->setAlignment(Qt::AlignRight|Qt::AlignVCenter);
        // FWI: Begin of font alignment patch
        else if (selectNodeQString(node, "Alignment")=="center")
            m_pLabel->setAlignment(Qt::AlignHCenter|Qt::AlignVCenter);
        // FWI: End of font alignment patch
    }

    // Constant factor
    if (!selectNode(node, "ConstFactor").isNull())
    {
        m_dConstFactor = selectNodeQString(node, "ConstFactor").toDouble();
        setValue(0.);
    }
}
Пример #11
0
void
NodeGraph::setSelection(const NodesGuiList& nodes)
{
    clearSelection();
    for (NodesGuiList::const_iterator it = nodes.begin(); it != nodes.end(); ++it) {
        selectNode(*it, true);
    }
}
Пример #12
0
bool SkinContext::hasNodeSelectString(const QDomNode& node,
                                      const QString& nodeName, QString *value) const {
    QDomNode child = selectNode(node, nodeName);
    if (!child.isNull()) {
        *value = nodeToString(child);
        return true;
    }
    return false;
}
Пример #13
0
bool SkinContext::hasNodeSelectBool(const QDomNode& node,
                                    const QString& nodeName, bool *value) const {
    QDomNode child = selectNode(node, nodeName);
    if (!child.isNull()) {
         QString stringValue = nodeToString(child);
        *value = stringValue.contains("true", Qt::CaseInsensitive);
        return true;
    }
    return false;
}
Пример #14
0
QString WWidget::selectNodeQString(const QDomNode &nodeHeader, const QString sNode)
{
    QString ret;
    QDomNode node = selectNode(nodeHeader, sNode);
    if (!node.isNull())
        ret = node.toElement().text();
    else
        ret = "";
    return ret;
}
Пример #15
0
int WWidget::selectNodeInt(const QDomNode &nodeHeader, const QString sNode)
{
    QString text = selectNode(nodeHeader, sNode).toElement().text();
    bool ok;
    int conv = text.toInt(&ok, 0);
    if (ok) {
        return conv;
    } else {
        return 0;
    }
}
Пример #16
0
node_t* findMember(tree_t* userInfoTree, char* str)
{
	char inputStr[BUFFERSIZE] = { 0, };
	int idx = 0;
	int input = 0;
	node_t* resultNodeArr[BUFFERSIZE] = { 0, };
	
	if (!userInfoTree)
	{
		return -1;
	}

	while (1)
	{
		system("cls");
		printf("=============================================================================\n");
		printf("%34s할 %s\t\n", str, "회원 검색");
		printf("=============================================================================\n");
		printf("\n\t%3s", "1. ID로 검색\n");
		printf("\n\t%3s", "2. 이름으로 검색\n");
		printf("\n\t%3s", "3. 주소로 검색\n");
		printf("\n\t%3s", "4. 전화 번호로 검색\n");
		printf("\n\t%3s", "0. 종료\n");
		printf("\n\t실행할 번호를 입력하세요: ");
		scanf_s("\n%d", &input);

		switch (input)
		{
		case 1:
			getUserId(inputStr);
			//ID는 한개만 있으므로 바로 키값처럼 검색해서 리턴
			resultNodeArr[idx] = searchBSTbyUserIdWithNode(userInfoTree->root, atoi(inputStr));
			break;
		case 2:
			getUserName(inputStr);
			searchBSTbyNameWithNode(userInfoTree->root, inputStr, resultNodeArr, &idx);
			break;
		case 3:
			getUserAddress(inputStr);
			searchBSTbyAddressWithNode(userInfoTree->root, inputStr, resultNodeArr, &idx);
			break;
		case 4:
			getPhoneNumber(inputStr);
			searchBSTbyPhoneWithNode(userInfoTree->root, inputStr, resultNodeArr, &idx);
			break;
		case 0:
			return (node_t*)NULL;
		default:
			break;
		}
		printArrData(resultNodeArr, inputStr);
		return selectNode(resultNodeArr);
	}
}
Пример #17
0
void WKnobComposed::setup(QDomNode node) {
    clear();

    // Set background pixmap if available
    if (!selectNode(node, "BackPath").isNull()) {
        setPixmapBackground(getPath(selectNodeQString(node, "BackPath")));
    }

    // Set background pixmap if available
    if (!selectNode(node, "Knob").isNull()) {
        setPixmapKnob(getPath(selectNodeQString(node, "Knob")));
    }

    if (!selectNode(node, "MinAngle").isNull()) {
        m_dMinAngle = selectNodeDouble(node, "MinAngle");
    }

    if (!selectNode(node, "MaxAngle").isNull()) {
        m_dMaxAngle = selectNodeDouble(node, "MaxAngle");
    }
}
Пример #18
0
/*
 * Free the pre-allocated node, called when tree is empty.  This avoids
 * leaving any used pages in DataMemory.
 */
void
Dbtux::freePreallocatedNode(Frag& frag)
{
  if (frag.m_freeLoc != NullTupLoc)
  {
    jam();
    NodeHandle node(frag);
    selectNode(node, frag.m_freeLoc);
    freeNode(node);
    frag.m_freeLoc = NullTupLoc;
  }
}
Пример #19
0
/*
 * Set handle to point to new node.  Uses a pre-allocated node.
 */
void
Dbtux::insertNode(NodeHandle& node)
{
  Frag& frag = node.m_frag;
  // unlink from freelist
  selectNode(node, frag.m_freeLoc);
  frag.m_freeLoc = node.getLink(0);
  new (node.m_node) TreeNode();
#ifdef VM_TRACE
  TreeHead& tree = frag.m_tree;
  memset(node.getPref(), DataFillByte, tree.m_prefSize << 2);
  TreeEnt* entList = tree.getEntList(node.m_node);
  memset(entList, NodeFillByte, (tree.m_maxOccup + 1) * (TreeEntSize << 2));
#endif
}
Пример #20
0
void WLabel::setup(QDomNode node)
{
    // Colors
    QPalette palette = m_pLabel->palette(); //we have to copy out the palette to edit it since it's const (probably for threadsafety)
    if (!WWidget::selectNode(node, "BgColor").isNull()) {
        m_qBgColor.setNamedColor(WWidget::selectNodeQString(node, "BgColor"));
        palette.setColor(this->backgroundRole(), WSkinColor::getCorrectColor(m_qBgColor));
        m_pLabel->setAutoFillBackground(true);
    }
    m_qFgColor.setNamedColor(WWidget::selectNodeQString(node, "FgColor"));
    palette.setColor(this->foregroundRole(), WSkinColor::getCorrectColor(m_qFgColor));
    m_pLabel->setPalette(palette);

    // Text
    if (!selectNode(node, "Text").isNull())
        m_qsText = selectNodeQString(node, "Text");
    m_pLabel->setText(m_qsText);

    // Alignment
    if (!selectNode(node, "Alignment").isNull()) {
        if (selectNodeQString(node, "Alignment")=="right")
            m_pLabel->setAlignment(Qt::AlignRight|Qt::AlignVCenter);
    }
}
Пример #21
0
/*
 * Set handle to point to new node.  Uses a pre-allocated node.
 */
void
Dbtux::insertNode(NodeHandle& node)
{
  Frag& frag = node.m_frag;
  // use up pre-allocated node
  selectNode(node, frag.m_freeLoc);
  frag.m_freeLoc = NullTupLoc;
  new (node.m_node) TreeNode();
#ifdef VM_TRACE
  TreeHead& tree = frag.m_tree;
  memset(node.getPref(), DataFillByte, tree.m_prefSize << 2);
  TreeEnt* entList = tree.getEntList(node.m_node);
  memset(entList, NodeFillByte, tree.m_maxOccup * (TreeEntSize << 2));
#endif
}
Пример #22
0
void planMaps(t_job *job) {
	log_info(logger, "|JOB %d| Planning", job->id);
	int filesAvailables = 1;
	void requestBlocks(t_file *file) {
		if (!requestFileBlocks(file))
			filesAvailables = 0;
	}
	list_iterate(job->files, (void *) requestBlocks);

	void fileMap(t_file *file) {
		void mapPlanning(t_list *copies) {
			t_node* selectedNode = NULL;
			uint16_t numBlock;

			void selectNodeToMap(t_copy *copy) {
				selectNode(copy, &selectedNode, &numBlock);
			}
Пример #23
0
void RangeImpl::surroundContents(DOM_Node& newParent)
{
    if (newParent==null) return;

    //check for elimination criteria
    if( fDetached) {
        throw DOM_DOMException(
            DOM_DOMException::INVALID_STATE_ERR, null);
    }

    if (newParent.getOwnerDocument() !=fDocument) {
        throw DOM_DOMException(
            DOM_DOMException::WRONG_DOCUMENT_ERR, null);
    }

    int type = newParent.getNodeType();
    if ( !isLegalContainedNode(newParent)
            || type == DOM_Node::DOCUMENT_TYPE_NODE)
    {
        throw DOM_RangeException(
            DOM_RangeException::INVALID_NODE_TYPE_ERR, null);
    }

    DOM_Node root = getCommonAncestorContainer();

    DOM_Node realStart = fStartContainer;
    DOM_Node realEnd = fEndContainer;

    if (fStartContainer.getNodeType() == DOM_Node::TEXT_NODE) {
        realStart = fStartContainer.getParentNode();
    }
    if (fEndContainer.getNodeType() == DOM_Node::TEXT_NODE) {
        realEnd = fEndContainer.getParentNode();
    }

    if (realStart != realEnd) {
        throw DOM_RangeException(
            DOM_RangeException::BAD_BOUNDARYPOINTS_ERR, null);
    }

    DOM_DocumentFragment frag = extractContents();
    insertNode(newParent);
    newParent.appendChild(frag);
    selectNode(newParent);
}
Пример #24
0
void NodeGraphDisplay::onDrag(APoint m_pos, AVec d_pos)
{
	if(valid(Mouse::getButtonStates() & NODEGRAPH_MOVE_OFFSET_BTN))
	{
		moveViewOffset(-absoluteToVirtualVec(d_pos));
	}
	else if(selectionRect.space != TSpace::INVALID)
	{
		//Adjust selectionRect
		if(selectionPivot.x > m_pos.x)
		{
			selectionRect.pos.x = m_pos.x;
			selectionRect.size.x = selectionPivot.x - m_pos.x;
		}
		else
		{
			selectionRect.pos.x = selectionPivot.x;
			selectionRect.size.x = m_pos.x - selectionPivot.x;
		}

		if(selectionPivot.y > m_pos.y)
		{
			selectionRect.pos.y = m_pos.y;
			selectionRect.size.y = selectionPivot.y - m_pos.y;
		}
		else
		{
			selectionRect.pos.y = selectionPivot.y;
			selectionRect.size.y = m_pos.y - selectionPivot.y;
		}

		//Clamp selection rect within absolute bounds
		Rect bounds = Rect(APoint(0, 0), size);
		selectionRect = Rect::findIntersection(selectionRect, absoluteToVirtualRect(bounds));
		
		if(!stickySelect())
			clearSelected();

		for(auto c : nodeControls)
		{
			if((c->selected && stickySelect()) || Rect::intersects(c->getRect(), selectionRect))
				selectNode(c, false);
		}
	}
}
Пример #25
0
PixmapSource SkinContext::getPixmapSource(const QDomNode& pixmapNode) const {
    if (!pixmapNode.isNull()) {
        QDomNode svgNode = selectNode(pixmapNode, "svg");
        if (!svgNode.isNull()) {
            // inline svg
            SvgParser svgParser(*this);
            const QByteArray rslt = svgParser.saveToQByteArray(
                    svgParser.parseSvgTree(svgNode, m_xmlPath));
            PixmapSource source;
            source.setSVG(rslt);
            return source;
        } else {
            // filename.
            return getPixmapSourceInner(nodeToString(pixmapNode));
        }
    }

    return PixmapSource();
}
Пример #26
0
nsIContent* nsHTMLSelectOptionAccessible::GetSelectState(PRUint32* aState,
                                                         PRUint32* aExtraState)
{
  nsCOMPtr<nsIContent> content(do_QueryInterface(mDOMNode));
  while (content && content->Tag() != nsAccessibilityAtoms::select) {
    content = content->GetParent();
  }

  nsCOMPtr<nsIDOMNode> selectNode(do_QueryInterface(content));
  if (selectNode) {
    nsCOMPtr<nsIAccessibilityService> accService = GetAccService();
    if (accService) {
      nsCOMPtr<nsIAccessible> selAcc;
      accService->GetAccessibleFor(selectNode, getter_AddRefs(selAcc));
      if (selAcc) {
        selAcc->GetState(aState, aExtraState);
        return content;
      }
    }
  }
  return nsnull; 
}
Пример #27
0
 void buttonUp(Gosu::Button btn) noexcept override
 {
     if (btn == Gosu::msLeft) {
         // release any currently dragged node
         grabbedNode.clear();
     } else if (btn == Gosu::msRight) {
         if (connectingNode) {
             auto selected = selectNode();
             if (selected && (selected != connectingNode)) {
                 // check for a connection first
                 if (!selected->getEdge(connectingNode)) {
                     selected->connect(connectingNode);
                     onGraphChanged();
                     game.endTurn();
                 }
             }
             // release edge
             connectingNode.clear();
         }
     } else if (btn == Gosu::kbLeftShift) {
         grabbedNode.clear();
     }
 }
Пример #28
0
void TestRouting::TestNoRoutes()
{
    Long numnodes = elementsof(nodes);

    initRoutes();
    for (Long n = 1; n <= numnodes; n++) // Have every node send to all other nodes with a nonroutable frame
        for (Long i = 1; i <= numnodes; i++) {
            selectNode(n);
            if (i != n)
                sendPacket(CONFIG_PID, i);
        }
    runNodes(SFP_SPS_TIME/2);
//    networkStats();

    QCOMPARE(nodeStat(2,getGoodFrame), (Long)1);
    QCOMPARE(nodeStat(1,getGoodFrame), (Long)numnodes+1);
    QCOMPARE(nodeStat(3,getGoodFrame), (Long)numnodes+1);
    QCOMPARE(nodeStat(4,getGoodFrame), (Long)1);

    QCOMPARE(nodeStat(2,getSendFrame), (Long)numnodes-1);
    QCOMPARE(nodeStat(1,getSendFrame), (Long)numnodes-1);
    QCOMPARE(nodeStat(3,getSendFrame), (Long)numnodes-1);
    QCOMPARE(nodeStat(4,getSendFrame), (Long)numnodes-1);
}
Пример #29
0
ompl::base::PlannerStatus ompl::control::SST::solve(const base::PlannerTerminationCondition &ptc)
{
    checkValidity();
    base::Goal                   *goal = pdef_->getGoal().get();
    base::GoalSampleableRegion *goal_s = dynamic_cast<base::GoalSampleableRegion*>(goal);

    while (const base::State *st = pis_.nextStart())
    {
        Motion *motion = new Motion(siC_);
        si_->copyState(motion->state_, st);
        siC_->nullControl(motion->control_);
        nn_->add(motion);
        motion->accCost_ = opt_->identityCost();
        findClosestWitness(motion);
    }

    if (nn_->size() == 0)
    {
        OMPL_ERROR("%s: There are no valid initial states!", getName().c_str());
        return base::PlannerStatus::INVALID_START;
    }

    if (!sampler_)
        sampler_ = si_->allocStateSampler();
    if (!controlSampler_)
        controlSampler_ = siC_->allocControlSampler();

    OMPL_INFORM("%s: Starting planning with %u states already in datastructure\n", getName().c_str(), nn_->size());

    Motion *solution  = NULL;
    Motion *approxsol = NULL;
    double  approxdif = std::numeric_limits<double>::infinity();
    bool sufficientlyShort = false;

    Motion      *rmotion = new Motion(siC_);
    base::State  *rstate = rmotion->state_;
    Control       *rctrl = rmotion->control_;
    base::State  *xstate = si_->allocState();

    unsigned iterations = 0;

    while (ptc == false)
    {

        /* sample random state (with goal biasing) */
        if (goal_s && rng_.uniform01() < goalBias_ && goal_s->canSample())
            goal_s->sampleGoal(rstate);
        else
            sampler_->sampleUniform(rstate);

        /* find closest state in the tree */
        Motion *nmotion = selectNode(rmotion);



        /* sample a random control that attempts to go towards the random state, and also sample a control duration */
        controlSampler_->sample(rctrl);
        unsigned int cd = rng_.uniformInt(siC_->getMinControlDuration(),siC_->getMaxControlDuration());
        unsigned int propCd = siC_->propagateWhileValid(nmotion->state_,rctrl,cd,rstate);


        if (propCd == cd)
        {
            base::Cost incCost = opt_->motionCost(nmotion->state_, rstate);
            base::Cost cost = opt_->combineCosts(nmotion->accCost_, incCost);
            Witness* closestWitness = findClosestWitness(rmotion);


            if (closestWitness->rep_ == rmotion || opt_->isCostBetterThan(cost,closestWitness->rep_->accCost_))
            {
                Motion* oldRep = closestWitness->rep_;
                /* create a motion */
                Motion *motion = new Motion(siC_);
                motion->accCost_ = cost;
                si_->copyState(motion->state_, rmotion->state_);
                siC_->copyControl(motion->control_, rctrl);
                motion->steps_ = cd;
                motion->parent_ = nmotion;
                nmotion->numChildren_++;
                closestWitness->linkRep(motion);

                nn_->add(motion);
                double dist = 0.0;
                bool solv = goal->isSatisfied(motion->state_, &dist);
                if (solv && opt_->isCostBetterThan(motion->accCost_,prevSolutionCost_))
                {
                    approxdif = dist;
                    solution = motion;

                    for (unsigned int i = 0 ; i < prevSolution_.size() ; ++i)
                        if (prevSolution_[i])
                            si_->freeState(prevSolution_[i]);
                    prevSolution_.clear();
                    for (unsigned int i = 0 ; i < prevSolutionControls_.size() ; ++i)
                        if (prevSolutionControls_[i])
                            siC_->freeControl(prevSolutionControls_[i]);
                    prevSolutionControls_.clear();
                    prevSolutionSteps_.clear();


                    Motion* solTrav = solution;
                    while(solTrav->parent_!=NULL)
                    {
                        prevSolution_.push_back(si_->cloneState(solTrav->state_) );
                        prevSolutionControls_.push_back(siC_->cloneControl(solTrav->control_) );
                        prevSolutionSteps_.push_back(solTrav->steps_ );
                        solTrav = solTrav->parent_;
                    }
                    prevSolution_.push_back(si_->cloneState(solTrav->state_) );
                    prevSolutionCost_ = solution->accCost_;




                    OMPL_INFORM("Found solution with cost %.2f",solution->accCost_.value());
                    sufficientlyShort = opt_->isSatisfied(solution->accCost_);
                    if (sufficientlyShort)
                        break;
                }
                if (solution==NULL && dist < approxdif)
                {
                    approxdif = dist;
                    approxsol = motion;



                    for (unsigned int i = 0 ; i < prevSolution_.size() ; ++i)
                        if (prevSolution_[i])
                            si_->freeState(prevSolution_[i]);
                    prevSolution_.clear();
                    for (unsigned int i = 0 ; i < prevSolutionControls_.size() ; ++i)
                        if (prevSolutionControls_[i])
                            siC_->freeControl(prevSolutionControls_[i]);
                    prevSolutionControls_.clear();
                    prevSolutionSteps_.clear();

                    Motion *solTrav = approxsol;
                    while (solTrav->parent_!=NULL)
                    {
                        prevSolution_.push_back(si_->cloneState(solTrav->state_) );
                        prevSolutionControls_.push_back(siC_->cloneControl(solTrav->control_) );
                        prevSolutionSteps_.push_back(solTrav->steps_ );
                        solTrav = solTrav->parent_;
                    }
                    prevSolution_.push_back(si_->cloneState(solTrav->state_) );
                }

                if (oldRep != rmotion)
                {
                    oldRep->inactive_ = true;
                    nn_->remove(oldRep);
                    while (oldRep->inactive_ && oldRep->numChildren_==0)
                    {
                        if (oldRep->state_)
                            si_->freeState(oldRep->state_);
                        if (oldRep->control_)
                            siC_->freeControl(oldRep->control_);

                        oldRep->state_=NULL;
                        oldRep->control_=NULL;
                        oldRep->parent_->numChildren_--;
                        Motion* oldRepParent = oldRep->parent_;
                        delete oldRep;
                        oldRep = oldRepParent;
                    }
                }

            }
        }
        iterations++;
    }

    bool solved = false;
    bool approximate = false;
    if (solution == NULL)
    {
        solution = approxsol;
        approximate = true;
    }

    if (solution != NULL)
    {
        /* set the solution path */
        PathControl *path = new PathControl(si_);
        for (int i = prevSolution_.size() - 1 ; i >= 1 ; --i)
            path->append(prevSolution_[i], prevSolutionControls_[i-1], prevSolutionSteps_[i-1] * siC_->getPropagationStepSize());
        path->append(prevSolution_[0]);
        solved = true;
        pdef_->addSolutionPath(base::PathPtr(path), approximate, approxdif, getName());
    }

    si_->freeState(xstate);
    if (rmotion->state_)
        si_->freeState(rmotion->state_);
    if (rmotion->control_)
        siC_->freeControl(rmotion->control_);
    delete rmotion;

    OMPL_INFORM("%s: Created %u states in %u iterations", getName().c_str(), nn_->size(),iterations);

    return base::PlannerStatus(solved, approximate);
}
Пример #30
0
float WWidget::selectNodeFloat(const QDomNode &nodeHeader, const QString sNode)
{
    return selectNode(nodeHeader, sNode).toElement().text().toFloat();
}