Пример #1
0
void expandTree(binaryTreePtr tree)
/* This procedure expands a unique tree for the current game state
 * Pre-condition: the tree has been allocated in memory
 * Post-condition: a tree has been created for the given game state
*/
{
	if (tree != NULL)
	{
		//get the current gamestate for the level in tree we are on
		infoPtr gameInfo = retrieveNodeElm(tree);

		//store the adress of the current node in the tree
		treeNodePtr current;
		current = getCurrentNode(tree);

		//get the root level's game state
		nextNode(tree,TOROOT);
		infoPtr rootInfo = retrieveNodeElm(tree);

		//go back to current level
		setCurrentNode(tree,current);
		//we only extend 2 levels, this counts how many we have done
		int cmpSquares = squaresAvailable(rootInfo) - squaresAvailable(gameInfo);

		//is there any sqaures available?
		if ( (cmpSquares  < 3) && (squaresAvailable(gameInfo) != 0) )
		{
			//generate the next level for the tree
			generateSquares(tree);
			//go back to the node we started with
			setCurrentNode(tree, current);
			//go to the first node on the next level
			nextNode(tree, TOLEFT);
			//set this as the current node
			current = getCurrentNode(tree);
			//call this procedure again, to expand the next level
			expandTree(tree);
			//go back to first node of level we are working with
			setCurrentNode(tree, current);

			//does it have a next node on this level?
			while (existNode(tree, TORIGHT) == 1)
			{
				//then go to the next node
				nextNode(tree, TORIGHT);
				//get node on this level we are working with
				current = getCurrentNode(tree);
				//generate a next level for this node
				expandTree(tree);
				//back to working level
				setCurrentNode(tree, current);
			}
		}
	}
}
Пример #2
0
 void
 TreeCanvas::inspectPath(void) {
   QMutexLocker locker(&mutex);
   setCurrentNode(root);
   if (currentNode->isOnPath()) {
     inspectCurrentNode();
     int nextAlt = currentNode->getPathAlternative(*na);
     while (nextAlt >= 0) {
       setCurrentNode(currentNode->getChild(*na,nextAlt));
       inspectCurrentNode();
       nextAlt = currentNode->getPathAlternative(*na);
     }
   }
   update();
 }
bool BookStoreFileSystemTree::canGoUp()
{
    if (!canGoUp())
    {
        return 0;
    }
    return setCurrentNode(dynamic_cast<ContainerNode *>(current_node_->mutableParent()));
}
Пример #4
0
  void
  TreeCanvas::mousePressEvent(QMouseEvent* event) {
    if (mutex.tryLock()) {
      if (event->button() == Qt::LeftButton) {
        VisualNode* n = eventNode(event);
        if (compareNodes) {
          if (n != NULL && n->getStatus() != UNDETERMINED &&
              currentNode != NULL &&
              currentNode->getStatus() != UNDETERMINED) {
            Space* curSpace = NULL;
            Space* compareSpace = NULL;
            for (int i=0; i<comparators.size(); i++) {
              if (comparators[i].second) {
                if (curSpace == NULL) {
                  curSpace = currentNode->getSpace(*na,curBest,c_d,a_d);

                  if (!compareNodesBeforeFP || n->isRoot()) {
                    compareSpace = n->getSpace(*na,curBest,c_d,a_d);
                  } else {
                    VisualNode* p = n->getParent(*na);
                    compareSpace = p->getSpace(*na,curBest,c_d,a_d);
                    switch (compareSpace->status()) {
                    case SS_SOLVED:
                    case SS_FAILED:
                      break;
                    case SS_BRANCH:
                      compareSpace->commit(*p->getChoice(), 
                                           n->getAlternative(*na));
                      break;
                    default:
                      GECODE_NEVER;
                    }
                  }
                }
                try {
                  comparators[i].first->compare(*curSpace,*compareSpace);
                } catch (Exception& e) {
                  qFatal("Exception in comparator %d: %s.\n Stopping.",
                    i, e.what());
                }
              }
            }
          }
        } else {
          setCurrentNode(n);
        }
        compareNodes = false;
        setCursor(QCursor(Qt::ArrowCursor));
        if (n != NULL) {
          event->accept();
          mutex.unlock();
          return;
        }
      }
      mutex.unlock();
    }
    event->ignore();
  }
ContainerNode * BookStoreFileSystemTree::cdContainerNodeWithinTopNode(const string& name)
{
    Node* ptr = root_node_.node(name);
    if (ptr == 0)
    {
        return 0;
    }
    return setCurrentNode(dynamic_cast<ContainerNode *>(ptr));
}
Пример #6
0
void GameControllerAttachment::createNodeAttachment()
{	
	Q_ASSERT(m_currentNode != 0);	
	QDomElement node = m_currentNode->xmlNode().insertBefore(QDomDocument().createElement("Attachment"), QDomNode()).toElement();
	node.setAttribute("type", plugInName());
	node.setAttribute("name", m_currentNode->property("Name").toString() + "_" + m_currentNode->property("ID").toString());
	initNodeAttachment(m_currentNode);
	setCurrentNode(m_currentNode);
}
ContainerNode * BookStoreFileSystemTree::cd(const string& name)
{
    // Get child node.
    NodePtr ptr = current_node_->node(name);
    if (ptr != 0)
    {
        return setCurrentNode(dynamic_cast<ContainerNode *>(ptr));
    }
    return 0;
}
Пример #8
0
void TagAttributeTree::slotDelayedSetCurrentNode()
{
  setCurrentNode(m_newNode);
  if (ViewManager::ref()->activeDocument())
  {
    if (ViewManager::ref()->activeView()->hadLastFocus() == QuantaView::SourceFocus)
      ViewManager::ref()->activeDocument()->view()->setFocus();
    else
      KafkaDocument::ref()->getKafkaWidget()->view()->setFocus();
  }
}
Пример #9
0
bool XMLTokenizer::enterText()
{
#if !USE(QXMLSTREAM)
    ASSERT(m_bufferedText.size() == 0);
#endif
    RefPtr<Node> newNode = new Text(m_doc, "");
    if (!m_currentNode->addChild(newNode.get()))
        return false;
    setCurrentNode(newNode.get());
    return true;
}
Пример #10
0
bool XMLTokenizer::enterText()
{
#if !USE(QXMLSTREAM) && !USE(UTFXML)  // UTFXml is much like QXml: they are a streaming API as opposed to a SAX API.
    ASSERT(m_bufferedText.size() == 0);
#endif
    RefPtr<Node> newNode = new Text(m_doc, "");
    if (!m_currentNode->addChild(newNode.get()))
        return false;
    setCurrentNode(newNode.get());
    return true;
}
NodeImpl *TreeWalkerImpl::nextNode()
{
    NodeImpl *result = 0;
    for (NodeImpl *node = currentNode()->traverseNextNode(); node; node = node->traverseNextNode()) {
        if (acceptNode(node) == NodeFilter::FILTER_ACCEPT && !ancestorRejected(node)) {
            setCurrentNode(node);
            result = node;
            break;
        }
    }
    return result;
}
NodeImpl *TreeWalkerImpl::nextSibling()
{
    NodeImpl *result = 0;
    for (NodeImpl *node = currentNode()->nextSibling(); node; node = node->nextSibling()) {
        if (acceptNode(node) == NodeFilter::FILTER_ACCEPT) {
            setCurrentNode(node);
            result = node;
            break;
        }
    }
    return result;
}
NodeImpl *TreeWalkerImpl::parentNode()
{
    NodeImpl *result = 0;
    for (NodeImpl *node = currentNode()->parentNode(); node && node != root(); node = node->parentNode()) {
        if (acceptNode(node) == NodeFilter::FILTER_ACCEPT) {
            setCurrentNode(node);
            result = node;
            break;
        }
    }
    return result;
}
Пример #14
0
  void
  TreeCanvas::navUp(void) {
    QMutexLocker locker(&mutex);

    VisualNode* p = currentNode->getParent(*na);

    setCurrentNode(p);

    if (p != NULL) {
      centerCurrentNode();
    }
  }
Пример #15
0
QDomNode KGameSvgDocument::elementByUniqueAttributeValue(const QString& attributeName, const QString& attributeValue)
{
    /* DOM is always "live", so there maybe a new root node.  We always have to ask for the
     * root node instead of keeping a pointer to it.
     */
    QDomElement docElem = documentElement();
    QDomNode n = docElem.firstChild();

    QDomNode node = d->findElementById(attributeName, attributeValue, n);
    setCurrentNode(node);
    return node;
}
Пример #16
0
 void
 TreeCanvas::navNextSol(bool back) {
   QMutexLocker locker(&mutex);
   NextSolCursor nsc(currentNode,back,*na);
   PreorderNodeVisitor<NextSolCursor> nsv(nsc);
   nsv.run();
   VisualNode* n = nsv.getCursor().node();
   if (n != root) {
     setCurrentNode(n);
     centerCurrentNode();
   }
 }
Пример #17
0
 void
 TreeCanvas::navRight(void) {
   QMutexLocker locker(&mutex);
   VisualNode* p = currentNode->getParent(*na);
   if (p != NULL) {
     unsigned int alt = currentNode->getAlternative(*na);
     if (alt + 1 < p->getNumberOfChildren()) {
       VisualNode* n = p->getChild(*na,alt+1);
       setCurrentNode(n);
       centerCurrentNode();
     }
   }
 }
Пример #18
0
 void
 TreeCanvas::navLeft(void) {
   QMutexLocker locker(&mutex);
   VisualNode* p = currentNode->getParent(*na);
   if (p != NULL) {
     int alt = currentNode->getAlternative(*na);
     if (alt > 0) {
       VisualNode* n = p->getChild(*na,alt-1);
       setCurrentNode(n);
       centerCurrentNode();
     }
   }
 }
Пример #19
0
KisResourcesSnapshot::KisResourcesSnapshot(KisImageWSP image, KisPostExecutionUndoAdapter *undoAdapter, KoCanvasResourceManager *resourceManager, KisDefaultBoundsBaseSP bounds)
    : m_d(new Private())
{
    m_d->image = image;
    if (!bounds) {
        bounds = new KisDefaultBounds(m_d->image);
    }
    m_d->bounds = bounds;
    m_d->undoAdapter = undoAdapter;

    m_d->currentFgColor = resourceManager->resource(KoCanvasResourceManager::ForegroundColor).value<KoColor>();
    m_d->currentBgColor = resourceManager->resource(KoCanvasResourceManager::BackgroundColor).value<KoColor>();
    m_d->currentPattern = static_cast<KoPattern*>(resourceManager->resource(KisCanvasResourceProvider::CurrentPattern).value<void*>());
    m_d->currentGradient = static_cast<KoAbstractGradient*>(resourceManager->resource(KisCanvasResourceProvider::CurrentGradient).value<void*>());

    m_d->currentPaintOpPreset = resourceManager->resource(KisCanvasResourceProvider::CurrentPaintOpPreset).value<KisPaintOpPresetSP>();
#ifdef HAVE_THREADED_TEXT_RENDERING_WORKAROUND
    KisPaintOpRegistry::instance()->preinitializePaintOpIfNeeded(m_d->currentPaintOpPreset);
#endif /* HAVE_THREADED_TEXT_RENDERING_WORKAROUND */

    m_d->currentExposure = resourceManager->resource(KisCanvasResourceProvider::HdrExposure).toDouble();
    m_d->currentGenerator = static_cast<KisFilterConfiguration*>(resourceManager->resource(KisCanvasResourceProvider::CurrentGeneratorConfiguration).value<void*>());

    m_d->axesCenter = resourceManager->resource(KisCanvasResourceProvider::MirrorAxesCenter).toPointF();
    if (m_d->axesCenter.isNull()){
        QRect bounds = m_d->bounds->bounds();
        m_d->axesCenter = QPointF(0.5 * bounds.width(), 0.5 * bounds.height());
    }

    m_d->mirrorMaskHorizontal = resourceManager->resource(KisCanvasResourceProvider::MirrorHorizontal).toBool();
    m_d->mirrorMaskVertical = resourceManager->resource(KisCanvasResourceProvider::MirrorVertical).toBool();


    qreal normOpacity = resourceManager->resource(KisCanvasResourceProvider::Opacity).toDouble();
    m_d->opacity = quint8(normOpacity * OPACITY_OPAQUE_U8);

    m_d->compositeOpId = resourceManager->resource(KisCanvasResourceProvider::CurrentCompositeOp).toString();
    setCurrentNode(resourceManager->resource(KisCanvasResourceProvider::CurrentKritaNode).value<KisNodeSP>());

    /**
     * Fill and Stroke styles are not a part of the resource manager
     * so the tools should set them manually
     * TODO: port stroke and fill styles to be a part
     *       of the resource manager
     */
    m_d->strokeStyle = KisPainter::StrokeStyleBrush;
    m_d->fillStyle = KisPainter::FillStyleNone;

    m_d->globalAlphaLock = resourceManager->resource(KisCanvasResourceProvider::GlobalAlphaLock).toBool();
    m_d->effectiveZoom = resourceManager->resource(KisCanvasResourceProvider::EffectiveZoom).toDouble();
}
Пример #20
0
void KisLayerBox::setCanvas(KoCanvasBase *canvas)
{

    if (m_canvas) {
        m_canvas->disconnectCanvasObserver(this);
        m_nodeModel->setDummiesFacade(0, 0);

        disconnect(m_image, 0, this, 0);
        disconnect(m_nodeManager, 0, this, 0);
        disconnect(m_nodeModel, 0, m_nodeManager, 0);
        disconnect(m_nodeModel, SIGNAL(nodeActivated(KisNodeSP)), this, SLOT(updateUI()));
    }

    m_canvas = dynamic_cast<KisCanvas2*>(canvas);

    if (m_canvas) {
        m_image = m_canvas->view()->image();

        m_nodeManager = m_canvas->view()->nodeManager();

        KisDummiesFacadeBase *kritaDummiesFacade = dynamic_cast<KisDummiesFacadeBase*>(m_canvas->view()->document()->shapeController());
        m_nodeModel->setDummiesFacade(kritaDummiesFacade, m_image);

        connect(m_image, SIGNAL(sigAboutToBeDeleted()), SLOT(notifyImageDeleted()));

        // cold start
        setCurrentNode(m_nodeManager->activeNode());

        // Connection KisNodeManager -> KisLayerBox
        connect(m_nodeManager, SIGNAL(sigUiNeedChangeActiveNode(KisNodeSP)), this, SLOT(setCurrentNode(KisNodeSP)));

        // Connection KisLayerBox -> KisNodeManager
        // The order of these connections is important! See comment in the ctor
        connect(m_nodeModel, SIGNAL(nodeActivated(KisNodeSP)), m_nodeManager, SLOT(slotUiActivatedNode(KisNodeSP)));
        connect(m_nodeModel, SIGNAL(nodeActivated(KisNodeSP)), SLOT(updateUI()));

        // Node manipulation methods are forwarded to the node manager
        connect(m_nodeModel, SIGNAL(requestAddNode(KisNodeSP, KisNodeSP, KisNodeSP)),
                m_nodeManager, SLOT(addNodeDirect(KisNodeSP, KisNodeSP, KisNodeSP)));
        connect(m_nodeModel, SIGNAL(requestMoveNode(KisNodeSP, KisNodeSP, KisNodeSP)),
                m_nodeManager, SLOT(moveNodeDirect(KisNodeSP, KisNodeSP, KisNodeSP)));

        m_wdgLayerBox->listLayers->expandAll();
        expandNodesRecursively(m_image->rootLayer(), m_nodeModel, m_wdgLayerBox->listLayers);
        m_wdgLayerBox->listLayers->scrollToBottom();

        foreach(KisAction *action, m_actions) {
            m_canvas->view()->actionManager()->addAction(action);
        }
    }
Пример #21
0
void XMLTokenizer::end()
{
    doEnd();
    
    if (m_sawError)
        insertErrorMessageBlock();
    else {
        exitText();
        m_doc->updateStyleSelector();
    }
    
    setCurrentNode(0);
    if (!m_parsingFragment)
        m_doc->finishedParsing();    
}
Пример #22
0
void GameControllerAttachment::removeNodeAttachment()
{
	QDomElement node = m_currentNode->xmlNode().firstChildElement("Attachment");
	unsigned int entityID = GameEngine::entityWorldID( qPrintable(node.attribute("name")) );
	// Reset scene graph component to avoid removement of Horde's scenegraph node
	GameEngine::setEntitySceneGraphID( entityID, 0 );
	m_currentNode->xmlNode().removeChild(node);	
	if( m_currentNode->property("__AttachmentModel").isValid() )
	{
		delete static_cast<AttachmentTreeModel*>(m_currentNode->property("__AttachmentModel").value<void*>());
		m_currentNode->setProperty("__AttachmentModel", QVariant::fromValue<void*>(0));
		GameEngine::removeGameEntity( entityID );
	}
	setCurrentNode(m_currentNode);
}
Пример #23
0
 void
 TreeCanvas::contextMenuEvent(QContextMenuEvent* event) {
   if (mutex.tryLock()) {
     VisualNode* n = eventNode(event);
     if (n != NULL) {
       setCurrentNode(n);
       emit contextMenu(event);
       event->accept();
       mutex.unlock();
       return;
     }
     mutex.unlock();
   }
   event->ignore();
 }
Пример #24
0
 void
 TreeCanvas::navDown(void) {
   QMutexLocker locker(&mutex);
   if (!currentNode->isHidden()) {
     switch (currentNode->getStatus()) {
     case STOP:
     case UNSTOP:
     case BRANCH:
         {
           int alt = std::max(0, currentNode->getPathAlternative(*na));
           VisualNode* n = currentNode->getChild(*na,alt);
           setCurrentNode(n);
           centerCurrentNode();
           break;
         }
     case SOLVED:
     case FAILED:
     case UNDETERMINED:
       break;
     }
   }
 }
Пример #25
0
bool BookStoreFileSystemTree::cdPath(const ModelPath& path)
{
    if (path.size() <= 0)
    {
        return false;
    }

    string root_path = path.front();
    if (root_path != root_node_.absolutePath())
    {
        return false;
    }
    Node* node = &root_node_;
    for (int i = 1; i < path.size(); i++)
    {
        if (node == 0)
        {
            return false;
        }
        ContainerNode* container = dynamic_cast<ContainerNode*>(node);
        if (container != 0)
        {
            node = container->node(path[i]).get();
        }
        else
        {
            return false;
        }
    }

    ContainerNode* current_node = dynamic_cast<ContainerNode*>(node);
    if (current_node != 0)
    {
        setCurrentNode(current_node);
        return true;
    }
    return false;
}
Пример #26
0
void XMLTokenizer::exitText()
{
    if (m_parserStopped)
        return;

    if (!m_currentNode || !m_currentNode->isTextNode())
        return;

#if !USE(QXMLSTREAM) && !USE(UTFXML)  // UTFXml is much like QXml: they are a streaming API as opposed to a SAX API.
    ExceptionCode ec = 0;
    static_cast<Text*>(m_currentNode)->appendData(toString(m_bufferedText.data(), m_bufferedText.size()), ec);
    Vector<xmlChar> empty;
    m_bufferedText.swap(empty);
#endif

    if (m_view && m_currentNode && !m_currentNode->attached())
        m_currentNode->attach();

    // FIXME: What's the right thing to do if the parent is really 0?
    // Just leaving the current node set to the text node doesn't make much sense.
    if (Node* par = m_currentNode->parentNode())
        setCurrentNode(par);
}
void TreeWalkerImpl::setCurrentNode(NodeImpl *node)
{
    assert(node);
    int dummy;
    setCurrentNode(node, dummy);
}
Пример #28
0
BasicBlock* SubCfgBuilderUtils::newBB(void)
{
    BasicBlock* bb = (BasicBlock*)m_subCFG->createBlockNode();
    setCurrentNode(bb);
    return bb;
}
Пример #29
0
void bestMove(binaryTreePtr tree)
/* This procedure will determine the best move available
 * by using a minmax method to either compute the value (on a leaf)
 * or sending it one level up where will be decided if the minimum or the maximum value will be used
 * Pre-condition:none
 * Post-condition: the root of the tree now has the minmax value needed
*/
{
	infoPtr gameInfo,temp;
	treeNodePtr current;
	//retrieve the current node's info
	gameInfo = retrieveNodeElm(tree);

	//is this a leaf?
	if ((existNode(tree,TOLEFT)== -1) )
	{
		//then compute the value of this square
		gameInfo->eval = evaluateSquares(gameInfo);
	}else
	{
		//go down a level, to first node
		nextNode(tree, TOLEFT);
		//get the current node in tree
		current = getCurrentNode(tree);

		//get the info for this node
		temp = retrieveNodeElm(tree);

		//call this procedure again, this will send up a value
		bestMove(tree);

		//go back to first node on the level
		setCurrentNode(tree, current);
		//set the parent level's value to this node's
		gameInfo->eval = temp->eval;

		//is there a next node on this level?
		while (existNode(tree,TORIGHT) == 1)
		{
			//then go to the next node
			nextNode(tree, TORIGHT);

			//set this as the current node on this level
			current = getCurrentNode(tree);

			//get the info for this node
			temp = retrieveNodeElm(tree);

			//call this procedure again, this will send up a value
			bestMove(tree);

			//go back to node on this level we're working on
			setCurrentNode(tree, current);
			//who's turn was it last
			if (gameInfo->turn == COMPUTER)
			{
				//if temp->eval is smaller
				if (gameInfo->eval > temp->eval)
				{
					//this is the new minimum value
					gameInfo->eval = temp->eval;
				}
			}else
			{
				//if temp->eval is bigger
				if (gameInfo->eval < temp->eval)
				{
					//this is the new maximum value
					gameInfo->eval = temp->eval;
				}
			}
		}
	}
}
Пример #30
0
 void
 TreeCanvas::navRoot(void) {
   QMutexLocker locker(&mutex);
   setCurrentNode(root);
   centerCurrentNode();
 }