コード例 #1
0
QVector<tIDataStorage*> UBTeacherGuideResourceEditionWidget::save(int pageIndex)
{
    QVector<tIDataStorage*> result;

    if(pageIndex == 0 || pageIndex != UBApplication::boardController->currentPage())
        return result;

    QList<QTreeWidgetItem*> children;

    children << getChildrenList(mpAddAMediaItem);
    foreach(QTreeWidgetItem* widgetItem, children) {
        tUBGEElementNode* node = dynamic_cast<iUBTGSaveData*>(mpTreeWidget->itemWidget( widgetItem, 0))->saveData();
        if (node) {
            tIDataStorage *data = new tIDataStorage(node->name, eElementType_UNIQUE);

            foreach(QString currentKey, node->attributes.keys())
                data->attributes.insert(currentKey, node->attributes.value(currentKey));

            result << data;
        }
    }
コード例 #2
0
void
DepthFirstStateAction::pushChildren(const NodePtr &pNode, ResultE result)
{
    if(result & (NewActionTypes::Skip  |
                 NewActionTypes::Break |
                 NewActionTypes::Quit   ))
    {
        setChildrenListEnabled(false);
        setNumPasses          (1    );

        getExtraChildrenList().clear();

        return;
    }

    ChildrenList      &cl  = getChildrenList     ();
    ExtraChildrenList &ecl = getExtraChildrenList();

    if(getChildrenListEnabled() == true)
    {
        for(UInt32 i = 0, size = cl.getSize(); i < size; ++i)
        {
            if(( cl.getActive(i)                                 == true  ) &&
               ( cl.getChild (i)                                 != NullFC) &&
               ((cl.getChild (i)->getTravMask() & getTravMask()) != 0     )   )
            {
                // gained refs: child
                incRefCount(_itActiveState);

                _nodeStack.push_back(
                    NodeStackEntry(cl.getChild(i), _itActiveState, 1));
            }
        }
    }
    else
    {
        MFNodePtr::const_iterator itChildren  = pNode->getMFChildren()->begin();
        MFNodePtr::const_iterator endChildren = pNode->getMFChildren()->end  ();

        for(; itChildren != endChildren; ++itChildren)
        {
            if((  *itChildren                                  != NullFC) &&
               (((*itChildren)->getTravMask() & getTravMask()) != 0     )   )
            {
                // gained refs: child
                incRefCount(_itActiveState);

                _nodeStack.push_back(
                    NodeStackEntry(*itChildren, _itActiveState, 1));
            }
        }
    }

    for(UInt32 i = 0, size = ecl.getSize(); i < size; ++i)
    {
        if(( ecl.getActive(i)                                 == true  ) &&
           ( ecl.getChild (i)                                 != NullFC) &&
           ((ecl.getChild (i)->getTravMask() & getTravMask()) != 0     )   )
        {
            // gained refs: extra child
            incRefCount(_itActiveState);

            _nodeStack.push_back(
                NodeStackEntry(ecl.getChild(i), _itActiveState, 1));
        }
    }

    setChildrenListEnabled(false);
    ecl.clear             (     );
    setNumPasses          (1    );
}
コード例 #3
0
DepthFirstStateAction::ResultE
DepthFirstStateAction::traverseEnterLeave(void)
{
    ResultE              result          = NewActionTypes::Continue;
    Int32                nodePass;        // pass over current node
    UInt32               multiPasses;     // requested passes over current node
    NodePtr              pNode;
    StateRefCountStoreIt itStateRefCount;

    while((_nodeStack.empty() == false) && !(result & NewActionTypes::Quit))
    {
        pNode           = _nodeStack.back().getNode         ();
        nodePass        = _nodeStack.back().getPassCount    ();
        itStateRefCount = _nodeStack.back().getStateRefCount();

        if(itStateRefCount != _itActiveState)
        {
#ifdef OSG_NEWACTION_STATISTICS
            getStatistics()->getElem(statStateRestores)->inc();
#endif /* OSG_NEWACTION_STATISTICS */

            setState(itStateRefCount);

            // gained refs: active
            incRefCount(itStateRefCount);

            // lost refs: active
            decRefCount(_itActiveState);

            _itActiveState = itStateRefCount;
        }

        getChildrenList().setParentNode(pNode);

        if(nodePass > 0)
        {
            // positive pass -> enter node
            
#ifdef OSG_NEWACTION_STATISTICS
            getStatistics()->getElem(statNodesEnter)->inc();
#endif /* OSG_NEWACTION_STATISTICS */
            
            _stateClonedFlag = false;

            result      = enterNode   (pNode, static_cast<UInt32>(nodePass - 1));
            multiPasses = getNumPasses(                                        );

            // only initial pass (nodePass == 1) can request multiPass.
            if((nodePass == 1) && (multiPasses > 1))
            {
                // remove current node from stack
                _nodeStack.pop_back();
                
                for(; multiPasses > 1; -- multiPasses)
                {
                    // gained refs: addtional passs
                    incRefCount(_itActiveState);
                    
                    _nodeStack.push_back(
                        NodeStackEntry(pNode, _itActiveState, multiPasses));
                }
                
                // readd current node - with negative pass -> leave
                _nodeStack.push_back(
                    NodeStackEntry(pNode, _itActiveState, -nodePass));
            }
            else
            {
                // change current node passCount to negative -> leave
                _nodeStack.back().setPassCount(-nodePass);
            }
            
            pushChildren(pNode, result);
        }
        else
        {
            // negative pass -> leave node

#ifdef OSG_NEWACTION_STATISTICS
            getStatistics()->getElem(statNodesLeave)->inc();
#endif /* OSG_NEWACTION_STATISTICS */
            
            _stateClonedFlag = true;

            result = leaveNode(pNode, static_cast<UInt32>(-nodePass - 1));

            _nodeStack.pop_back();

            // lost refs: current node
            decRefCount(_itActiveState);
        }
    }

    return result;
}
コード例 #4
0
DepthFirstStateAction::ResultE
DepthFirstStateAction::traverseEnter(void)
{
    ResultE              result          = NewActionTypes::Continue;
    NodePtr              pNode;
    Int32                nodePass;        // pass over current node
    UInt32               multiPasses;     // requested passes over current node
    StateRefCountStoreIt itStateRefCount; // state for current node

    while((_nodeStack.empty() == false) && !(result & NewActionTypes::Quit))
    {
        pNode           = _nodeStack.back().getNode         ();
        nodePass        = _nodeStack.back().getPassCount    ();
        itStateRefCount = _nodeStack.back().getStateRefCount();

#ifdef OSG_NEWACTION_STATISTICS
        getStatistics()->getElem(statNodesEnter)->inc();
#endif /* OSG_NEWACTION_STATISTICS */

        if(itStateRefCount != _itActiveState)
        {
#ifdef OSG_NEWACTION_STATISTICS
            getStatistics()->getElem(statStateRestores)->inc();
#endif /* OSG_NEWACTION_STATISTICS */

            setState(itStateRefCount);

            // gained refs: active
            incRefCount(itStateRefCount);

            // lost refs: active
            decRefCount(_itActiveState);

            _itActiveState = itStateRefCount;
        }

        _stateClonedFlag = false;

        getChildrenList().setParentNode(pNode);

        result      = enterNode   (pNode, static_cast<UInt32>(nodePass - 1));
        multiPasses = getNumPasses(                                        );

        _nodeStack.pop_back();

        // only initial pass (nodePass == 1) can request multiPasses
        if((nodePass == 1) && (multiPasses > 1))
        {
            for(; multiPasses > 1; --multiPasses)
            {
                // gained refs: additional pass
                incRefCount(_itActiveState);
                
                _nodeStack.push_back(
                    NodeStackEntry(pNode, _itActiveState, multiPasses));
            }
        }
        
        pushChildren(pNode, result);

        // lost refs: current node
        decRefCount(_itActiveState);
    }

    return result;
}
コード例 #5
0
    children << getChildrenList(mpAddAMediaItem);
    foreach(QTreeWidgetItem* widgetItem, children) {
        tUBGEElementNode* node = dynamic_cast<iUBTGSaveData*>(mpTreeWidget->itemWidget( widgetItem, 0))->saveData();
        if (node) {
            tIDataStorage *data = new tIDataStorage(node->name, eElementType_UNIQUE);

            foreach(QString currentKey, node->attributes.keys())
                data->attributes.insert(currentKey, node->attributes.value(currentKey));

            result << data;
        }
    }

    //For the links and files, we have to add the "student" attribute
    children = getChildrenList(mpAddALinkItem);
    children << getChildrenList(mpAddAFileItem); //Issue 1716 - ALTI/AOU - 20140128
    foreach(QTreeWidgetItem* widgetItem, children) {
        tUBGEElementNode* node = dynamic_cast<iUBTGSaveData*>(mpTreeWidget->itemWidget( widgetItem, 0))->saveData();
        if (node) {
            tIDataStorage *data = new tIDataStorage(node->name, eElementType_UNIQUE);

            foreach(QString currentKey, node->attributes.keys())
                data->attributes.insert(currentKey, node->attributes.value(currentKey));

            data->attributes.insert("student", "true");

            result << data;
        }
    }
コード例 #6
0
ファイル: FindPath.cpp プロジェクト: JaffeLiu/MoDouClient
  void FindPath::getPath(TmxMap *map,
			 int sx,
			 int sy,
			 int ex,
			 int ey,
			 std::list< XTilePoint* > &path)
  {
    XTilePoint *start_point, *end_point;

    start_point = new XTilePoint();
    end_point = new XTilePoint();

    start_point->x = (sx + mapTileSize - 1) / mapTileSize;
    start_point->y = (sy + mapTileSize - 1) / mapTileSize;
    start_point->mparent = NULL;

    end_point->x = (ex + mapTileSize - 1) / mapTileSize;
    end_point->y = (ey + mapTileSize - 1) / mapTileSize;

    if (map->isBlock(end_point->x, end_point->y)) {
      delete(start_point);
      delete(end_point);
      return;
    }

    std::list< XTilePoint* > openList, childrenList;
    std::list< XTilePoint* >::iterator it;
    XTilePoint *tmpPoint, *findOpenPoint, *findClosePoint;


    openList.push_back(start_point);

    while(openList.size() != 0) {
      tmpPoint = getBestPoint(openList);
      openList.remove(tmpPoint);
      path.push_back(tmpPoint);
      if (tmpPoint->x == end_point->x &&
	  tmpPoint->y == end_point->y) {
	std::cout << "find it open lise size: " << openList.size() <<  ", closed list size: " << path.size() <<  std::endl;
	break;
      }
      childrenList.clear();
      getChildrenList(map, tmpPoint, childrenList);
      for(it = childrenList.begin(); it != childrenList.end(); it++) {
	(*it)->calcF(end_point);
	findOpenPoint = pointInList(*it, openList);
	findClosePoint = pointInList(*it, path);

	if (findOpenPoint == NULL && findClosePoint == NULL) {
	  openList.push_back(*it);
	} else if (findOpenPoint != NULL) {
	  if ((*it)->G < findOpenPoint->G) {
	    findOpenPoint->G = (*it)->G;
	    findOpenPoint->calcF(end_point);
	    findOpenPoint->mparent = tmpPoint;
	  }
	  delete(*it);
	} else if (findClosePoint != NULL) {
	  delete(*it);
	  continue;
	  // if ((*it)->F < findClosePoint->F) {
	  //   findClosePoint->F = (*it)->F;
	  //   findClosePoint->mparent = tmpPoint;
	  // }
	}
      }// end for
    }// end while
    // start point and some of children point has been added to open list or path list. So we delete end point and some
    // of children point.
    delete(end_point);
    for(it = openList.begin(); it != openList.end(); it++) {
      delete(*it);
    }
    openList.clear();
  }