Ejemplo n.º 1
0
    bool Graph<Node, Edge>::isConnected(const Node &start, const Node &end) const {
        if(!isNode(start) || !isNode(end)) {
            throw std::runtime_error("start or end node did not exist");
        }

        auto nc = std::find_if(nodes.begin(), nodes.end(), [&start] (const NodeContainer nc) {
            return nc.getNode() == start;
        });

        if(nc != nodes.end()) {
            return nc->isConnected(end);
        }
        return false;
    }
Ejemplo n.º 2
0
    void Graph<Node, Edge>::mergeReplace(const Node &destroy, const Node &merge) {
        if(!isNode(destroy) || !isNode(merge)) {
            throw std::runtime_error("Expected the nodes to be defined");
        }
        auto dnc = std::find_if(nodes.begin(), nodes.end(), [&destroy] (const NodeContainer& nc) {
            return nc.getNode() == destroy;
        });

        auto mnc = std::find_if(nodes.begin(), nodes.end(), [&merge] (const NodeContainer& nc) {
            return nc.getNode() == merge;
        });

        mnc->merge(*dnc);

        nodes.erase(dnc);
    }
Ejemplo n.º 3
0
 bool Graph<Node, Edge>::replace(const Node &target, const Node &replacement) {
     if(!isNode(target)) {
         throw std::runtime_error("Expected node to exist");
     }
     if(isNode(replacement)) {
         return false;
     }
     bool found = false;
     for(auto it = nodes.begin(); it != nodes.end() && !found; ++it) {
         if(it->getNode() == target) {
             it->setNode(replacement);
             found = true;
         }
     }
     return found;
 }
Ejemplo n.º 4
0
QVariant ChapterModel::data(const QModelIndex& index, int role) const
{
  if( !index.isValid() ) {
    return QVariant();
  }

  csAbstractTreeItem *item = priv::treeItem(index);
  if(        role == Qt::DisplayRole ) {
    ChapterNode *node = dynamic_cast<ChapterNode*>(priv::treeItem(index));
    if( node != 0  &&  !node->isSource() ) {
      return chapterTitle(node);
    } else {
      return item->data(index.column());
    }
  } else if( role == Qt::EditRole ) {
    if( isNode(item) ) {
      ChapterNode *node = dynamic_cast<ChapterNode*>(item);
      return node->title();
    }
  } else if( role == Qt::DecorationRole ) {
    if( isFile(item) ) {
      ChapterFile *file = dynamic_cast<ChapterFile*>(item);
      if( file->fileName() == _playingFileName ) {
        return QColor(Qt::green);
      }
    }
  }

  return QVariant();
}
Ejemplo n.º 5
0
bool Node::isNeighbor(int neighborID) {
	std::vector<Node>::iterator it = std::find_if (neighbors.begin(), neighbors.end(), isNode(neighborID));
	if(it!=neighbors.end()) { //node found, can be deleted
		return true;
	}
	return false;
}
Ejemplo n.º 6
0
 bool Graph<Node, Edge>::addNode(const Node& node) {
     if(isNode(node)) {
         return false;
     }
     NodeContainer newNode{node};
     nodes.push_back(newNode);
     return true;
 }
Ejemplo n.º 7
0
void IdxData::addChild(IdxData* child)
{
    assert(isNode());                        // child (leaf) cannot accept any child
    assert(child->m_parent == nullptr);      // child should not have parent

    const long pos = findPositionFor(child);
    m_children.insert(m_children.cbegin() + pos, child);
    child->setParent(this);
}
Ejemplo n.º 8
0
void CIniFile::readInfo(void)
{
    m_lstNodeInfo.clear();

    std::fstream inStream(m_strFile.c_str(), std::ios::in);
    if (!inStream.good())
    {
        Q_Printf("open file %s error.", m_strFile.c_str());
        inStream.close();

        return;
    }

    char pBuffer[Q_ONEK];
    std::string strTmp;
    std::string strNode;

    while(inStream.good())
    {
        Q_Zero(pBuffer, sizeof(pBuffer));

        inStream.getline(pBuffer, (std::streamsize)(sizeof(pBuffer) - 1));

        strTmp = std::string(pBuffer);
        strTmp = Q_Trim(strTmp);
        if (strTmp.empty()
            || isNote(strTmp))
        {
            continue;
        }

        //去掉注释
        removeNote(strTmp);
        strTmp = Q_Trim(strTmp);
        if (strTmp.empty())
        {
            continue;
        }

        if (isNode(strTmp))
        {
            strNode = getNode(strTmp);

            continue;
        }

        if (isKey(strTmp))
        {
            setStringValue(strNode.c_str(), getKey(strTmp).c_str(), getVal(strTmp).c_str());
        }
    }

    inStream.close();

    return;
}
Ejemplo n.º 9
0
bool isNode (TreeNode *root, int value)
{
	TreeNode *tmp = root;
	if (tmp == nullptr)
	{
		return false;
	}
	if (tmp->value == value)
	{
		return true;
	}
	if (tmp->value < value)
	{
		isNode(tmp->right, value);
	}
	else 
	{
		isNode(tmp->left, value);
	}
}
Ejemplo n.º 10
0
    typename std::vector<std::pair<Node, Edge>>::const_iterator Graph<Node, Edge>::edgeIteratorBegin(const Node &node) const {
        if(!isNode(node)) {
            throw std::runtime_error("could not find node in graph");
        }
        auto nc = std::find_if(nodes.begin(), nodes.end(), [&node] (const NodeContainer nc) {
            return nc.getNode() == node;
        });

        this->ordered_edges = nc->generateOrder();
        return this->ordered_edges.cbegin();
    }
Ejemplo n.º 11
0
void LazyNode::dump(PrintStream& out) const
{
    if (!*this)
        out.print("LazyNode:0");
    else {
        if (isNode())
            out.print("LazyNode:@", asNode()->index());
        else
            out.print("LazyNode:FrozenValue:", Graph::opName(op()), ", ", pointerDump(asValue()));
        out.print(")");
    }
}
Ejemplo n.º 12
0
    void Graph<Node, Edge>::printEdges(const Node &n) const {
        if(!isNode(n)) {
            throw std::runtime_error("Could not find node");
        }

        auto nc = std::find_if(nodes.cbegin(), nodes.cend(), [&n] (const NodeContainer nc) {
            return nc.getNode() == n;
        });

        if(nc != nodes.cend()) {
            nc->printEdges();
        }
    }
void CloudsVisualSystemLSystem::addBranch(ofMesh &_mesh, int _index, float _relativeTime, float _speed){
    
    int totalPoints = lsysLines[_index].size();
    int drawPoints = 0;
    
    for (int k = 0 ; k < totalPoints-1; k++){
        float thisTime = _speed*(float)k;
        float nextTime = _speed*((float)k+1.0f);
        
        if ( k == totalPoints-1){
            nextTime = thisTime;
        }
        
        if (_relativeTime > thisTime && _relativeTime < nextTime ){
            float part = _relativeTime - thisTime;
            float whole = nextTime - thisTime;
            float pct = part / whole;
            
            ofPoint A = lsysLines[ _index ][k];
            ofPoint B = lsysLines[ _index ][k+1];
            
            // figure out where we are between a and b
            //
            ofPoint pos = (1.0-pct)*A + (pct)*B;
            
            dots.push_back(pos);
            
            _mesh.addVertex(lsysLines[ _index ][k]);
            _mesh.addVertex(pos);
            
        } else if ( _relativeTime > thisTime ){
            ofPoint pos = lsysLines[ _index ][k];
            
            _mesh.addVertex(pos);
            _mesh.addVertex(lsysLines[_index][k+1]);
            
            //  check if pass over a node
            //
            int index = isNode(pos);
            if (index != -1){
                if ( lsysNodes[index].startTime == -1.0 ){
                    lsysNodes[index].startTime = time +lsysGrowingBorn*_speed;
                }
            }
            
        } else {
            break;
        }
    }
}
Ejemplo n.º 14
0
nsresult
nsXPathResult::SetExprResult(txAExprResult* aExprResult, PRUint16 aResultType)
{
    mResultType = aResultType;

    if ((isSnapshot() || isIterator() || isNode()) &&
        aExprResult->getResultType() != txAExprResult::NODESET) {
        return NS_ERROR_DOM_TYPE_ERR;
    }

    if (mDocument) {
        mDocument->RemoveObserver(this);
        mDocument = nsnull;
    }
 
    mResult.set(aExprResult);

    if (!isIterator()) {
        return NS_OK;
    }

    mInvalidIteratorState = PR_FALSE;

    txNodeSet* nodeSet = NS_STATIC_CAST(txNodeSet*, aExprResult);
    nsCOMPtr<nsIDOMNode> node;
    if (nodeSet->size() > 0) {
        nsresult rv = txXPathNativeNode::getNode(nodeSet->get(0),
                                                 getter_AddRefs(node));
        NS_ENSURE_SUCCESS(rv, rv);

        // If we support the document() function in DOM-XPath we need to
        // observe all documents that we have resultnodes in.
        nsCOMPtr<nsIDOMDocument> document;
        node->GetOwnerDocument(getter_AddRefs(document));
        if (document) {
            mDocument = do_QueryInterface(document);
        }
        else {
            mDocument = do_QueryInterface(node);
        }

        NS_ASSERTION(mDocument, "We need a document!");
        if (mDocument) {
            mDocument->AddObserver(this);
        }
    }

    return NS_OK;
}
Ejemplo n.º 15
0
void
MPTreeMgr::readNodeList( ifstream & input )
{
	string temp;
	Token token;

	token.reserve( 8 );
	while ( getline( input , temp ) ) {
		if ( !token.empty() ) token.clear();
		Nz_ParseToken( temp , token );
		if ( token.empty() ) continue;
		if ( isNode( token ) ) readOneNode( token );
		if ( isTerm( token ) ) readOneTerm( token );
	}
}
Ejemplo n.º 16
0
NS_IMETHODIMP
nsXPathResult::GetSingleNodeValue(nsIDOMNode **aSingleNodeValue)
{
    if (!isNode()) {
        return NS_ERROR_DOM_TYPE_ERR;
    }

    txNodeSet *nodeSet = NS_STATIC_CAST(txNodeSet*, mResult.get());
    if (nodeSet->size() > 0) {
        return txXPathNativeNode::getNode(nodeSet->get(0), aSingleNodeValue);
    }

    *aSingleNodeValue = nsnull;

    return NS_OK;
}
Ejemplo n.º 17
0
ConstNodePtr WayLocation::getNode(double epsilon) const
{
  if (!isNode(epsilon))
  {
    throw IllegalArgumentException("getNode() is only valid if WayLocation is on a node.");
  }

  // Round to the appropriate segment index. This may be necessary due to floating point errors.
  if (_segmentFraction >= 0.5)
  {
    return _map->getNode(getWay()->getNodeId(_segmentIndex + 1));
  }
  else
  {
    return _map->getNode(getWay()->getNodeId(_segmentIndex));
  }
}
Ejemplo n.º 18
0
/*
 * TODO:
 * ====
 * - display value of a port (nice to have)
 * - triangle port (nice to have)
 * - mouse over (over a node or port) (nice to have)
 * - round shaped nodes (nice to have)
*/

namespace Magus
{
    //****************************************************************************/
    QtNodeEditor::QtNodeEditor(QWidget* parent) : QWidget(parent)
    {
        QVBoxLayout* mainLayout = new QVBoxLayout;
        mView = new QGraphicsView(this);
        mScene = new QtNodeGraphicsScene();
        mScene->installEventFilter(this);
        mView->setScene(mScene);
        mView->setRenderHint(QPainter::Antialiasing, true);
        mView->setInteractive(true);
        mView->setMouseTracking(true);
        mainLayout->addWidget(mView);
        mLastRemovedNode = 0;
        mRubberBand = 0;
        mZoom = 1.0f;
        mFisheyeViewEnabled = false;
        mFisheyeMaxZoom = 1.0f;
        mFisheyeSteps = 5;
        mHeaderTitleIcon = NODE_HEADER_COMPOUND_ICON;
        mAction1Icon = NODE_HEADER_ACTION1_ICON;
        mAction2Icon = NODE_HEADER_ACTION2_ICON;
        mCompoundNodeDropped = 0;
        mRubberbandSelection = false;
        mContextMenuEnabled = true;
        mContextMenu = new QMenu(this);
        mContextMenu->addAction(new QAction(NODE_ACTION_DELETE, this));
        mContextMenu->addAction(new QAction(NODE_ACTION_CENTER, this));
        mZoomSubMenu = mContextMenu->addMenu(NODE_ACTION_ZOOM);
        QAction* action;
        QActionGroup actionGroupZoom(mZoomSubMenu);
        actionGroupZoom.setExclusive(true);
        action = new QAction(NODE_ACTION_ZOOM_10, this);
        action->setCheckable(true);
        actionGroupZoom.addAction(action);
        action = new QAction(NODE_ACTION_ZOOM_25, this);
        action->setCheckable(true);
        actionGroupZoom.addAction(action);
        action = new QAction(NODE_ACTION_ZOOM_50, this);
        action->setCheckable(true);
        actionGroupZoom.addAction(action);
        action = new QAction(NODE_ACTION_ZOOM_75, this);
        action->setCheckable(true);
        actionGroupZoom.addAction(action);
        action = new QAction(NODE_ACTION_ZOOM_90, this);
        action->setCheckable(true);
        actionGroupZoom.addAction(action);
        action = new QAction(NODE_ACTION_ZOOM_100, this);
        action->setCheckable(true);
        action->setChecked(true);
        actionGroupZoom.addAction(action);
        action = new QAction(NODE_ACTION_ZOOM_150, this);
        action->setCheckable(true);
        actionGroupZoom.addAction(action);
        action = new QAction(NODE_ACTION_ZOOM_200, this);
        action->setCheckable(true);
        actionGroupZoom.addAction(action);
        action = new QAction(NODE_ACTION_ZOOM_250, this);
        action->setCheckable(true);
        actionGroupZoom.addAction(action);
        action = new QAction(NODE_ACTION_ZOOM_300, this);
        action->setCheckable(true);
        actionGroupZoom.addAction(action);
        mZoomSubMenu->addActions(actionGroupZoom.actions());

        mFisheyeViewSubMenu = mContextMenu->addMenu(NODE_ACTION_FISHEY_VIEW);
        QActionGroup actionGroupFisheye(mFisheyeViewSubMenu);
        actionGroupFisheye.setExclusive(true);
        action = new QAction(NODE_ACTION_FISHEYE_DISABLED, this);
        action->setCheckable(true);
        action->setChecked(true);
        actionGroupFisheye.addAction(action);
        action = new QAction(NODE_ACTION_FISHEYE_NORMAL, this);
        action->setCheckable(true);
        actionGroupFisheye.addAction(action);
        action = new QAction(NODE_ACTION_FISHEYE_NORMAL_SUBTLE, this);
        action->setCheckable(true);
        actionGroupFisheye.addAction(action);
        action = new QAction(NODE_ACTION_FISHEYE_LARGE, this);
        action->setCheckable(true);
        actionGroupFisheye.addAction(action);
        action = new QAction(NODE_ACTION_FISHEYE_LARGE_SUBTLE, this);
        action->setCheckable(true);
        actionGroupFisheye.addAction(action);
        mFisheyeViewSubMenu->addActions(actionGroupFisheye.actions());

        mContextMenu->addAction(new QAction(NODE_ACTION_SELECTED_TO_COMPOUND, this));
        mContextMenu->addAction(new QAction(NODE_ACTION_COLLAPSE_ALL, this));
        mContextMenu->addAction(new QAction(NODE_ACTION_EXPAND_ALL, this));
        mContextMenu->addAction(new QAction(NODE_ACTION_EXPAND_COMPOUNDS, this));
        mContextMenu->addAction(new QAction(NODE_ACTION_CENTER, this));

        setMenuZoomEnabled(true);
        setMenuSelectionToCompoundEnabled(true);
        setMenuCollapseExpandEnabled(true);
        setMenuExpandCompoundsEnabled(true);
        setMenuFisheyeViewEnabled(true);
        setContextMenuPolicy(Qt::CustomContextMenu);
        connect(mContextMenu, SIGNAL(triggered(QAction*)), this, SLOT(contextMenuItemSelected(QAction*)));
        setLayout(mainLayout);
    }

    //****************************************************************************/
    QtNodeEditor::~QtNodeEditor(void)
    {
    }

    //****************************************************************************/
    void QtNodeEditor::setContextMenuEnabled(bool enabled)
    {
        mContextMenuEnabled = enabled;
    }

    //****************************************************************************/
    void QtNodeEditor::setCompoundHeaderTitleIcon(const QString& fileNameIcon)
    {
        mHeaderTitleIcon = fileNameIcon;
    }

    //****************************************************************************/
    void QtNodeEditor::setCompoundAction1Icon(const QString& fileNameIcon)
    {
        mAction1Icon = fileNameIcon;
    }

    //****************************************************************************/
    void QtNodeEditor::setCompoundAction2Icon(const QString& fileNameIcon)
    {
        mAction2Icon = fileNameIcon;
    }

    //****************************************************************************/
    bool QtNodeEditor::isContextMenuEnabled(void)
    {
        return mContextMenuEnabled;
    }

    //****************************************************************************/
    void QtNodeEditor::setMenuZoomEnabled(bool enabled)
    {
        mMenuZoomEnabled = enabled;
        QAction* action = getActionFromContextMenu(NODE_ACTION_ZOOM);
        if (action)
            action->setVisible(enabled);
    }

    //****************************************************************************/
    bool QtNodeEditor::isMenuZoomEnabled(void)
    {
        return mMenuZoomEnabled;
    }

    //****************************************************************************/
    void QtNodeEditor::setMenuSelectionToCompoundEnabled(bool enabled)
    {
        mMenuSelectionToCompoundEnabled = enabled;
        QAction* action = getActionFromContextMenu(NODE_ACTION_SELECTED_TO_COMPOUND);
        if (action)
            action->setVisible(enabled);
    }

    //****************************************************************************/
    bool QtNodeEditor::isMenuSelectionToCompoundEnabled(void)
    {
        return mMenuSelectionToCompoundEnabled;
    }

    //****************************************************************************/
    void QtNodeEditor::setMenuCollapseExpandEnabled(bool enabled)
    {
        mMenuCollapseExpandEnabled = enabled;
        QAction* action = getActionFromContextMenu(NODE_ACTION_EXPAND_ALL);
        if (action)
            action->setVisible(enabled);
        action = getActionFromContextMenu(NODE_ACTION_COLLAPSE_ALL);
        if (action)
            action->setVisible(enabled);
    }

    //****************************************************************************/
    bool QtNodeEditor::isMenuCollapseExpandEnabled(void)
    {
        return mMenuCollapseExpandEnabled;
    }

    //****************************************************************************/
    void QtNodeEditor::setMenuExpandCompoundsEnabled(bool enabled)
    {
        mMenuExpandCompoundsEnabled = enabled;
        QAction* action = getActionFromContextMenu(NODE_ACTION_EXPAND_COMPOUNDS);
        if (action)
            action->setVisible(enabled);
    }

    //****************************************************************************/
    bool QtNodeEditor::isMenuExpandCompoundsEnabled(void)
    {
        return mMenuExpandCompoundsEnabled;
    }

    //****************************************************************************/
    void QtNodeEditor::setMenuFisheyeViewEnabled(bool enabled)
    {
        mMenuFisheyeViewEnabled = enabled;
        QAction* action = getActionFromContextMenu(NODE_ACTION_FISHEY_VIEW);
        if (action)
            action->setVisible(enabled);
    }

    //****************************************************************************/
    bool QtNodeEditor::isMenuFisheyeViewEnabled(void)
    {
        return mMenuFisheyeViewEnabled;
    }

    //****************************************************************************/
    void QtNodeEditor::setFisheyeView(bool enabled, qreal maxZoom, unsigned int steps)
    {
        mFisheyeViewEnabled = enabled;
        mFisheyeMaxZoom = maxZoom;
        mFisheyeSteps = steps;
    }

    //****************************************************************************/
    QGraphicsItem* QtNodeEditor::itemAtExceptActiveConnection(const QPointF& pos)
    {
        QList<QGraphicsItem*> items = mScene->items(QRectF(pos - QPointF(1,1), QSize(3,3)));
        bool isActive = isActiveConnection();

        foreach(QGraphicsItem* item, items)
        {
            // If there is an active connection, it is not returned as a selected item
            // Finalized (established) connections are returned
            if (item->isVisible())
            {
                if (isConnection(item))
                {
                    if (!isActive)
                        return item;
                }
                else
                    return item;
            }
        }

        return 0;
    }

    //****************************************************************************/
    QtCompoundNode* QtNodeEditor::nodeOverCompound(QtNode* node)
    {
        if (!node)
            return 0;

        QtCompoundNode* compound;
        QList<QGraphicsItem*> items = mScene->items();
        int subType;
        qreal halfWidth;
        foreach(QGraphicsItem* item, items)
        {
            if (isCompoundNode(item) && item->isVisible())
            {
                compound = static_cast<QtCompoundNode*>(item);
                if (node != compound && !compound->isSelected())
                {
                    halfWidth = 0.5 * compound->getWidth();
                    if (node->scenePos().x() > compound->scenePos().x() - halfWidth &&
                        node->scenePos().x() < compound->scenePos().x() + halfWidth &&
                        node->scenePos().y() > compound->scenePos().y() &&
                        node->scenePos().y() < compound->scenePos().y() + compound->getHeigth())
                    {
                        return compound;
                    }
                }
            }
        }

        return 0;
    }

    //****************************************************************************/
    bool QtNodeEditor::eventFilter(QObject* object, QEvent* event)
    {
        QGraphicsSceneMouseEvent* mouseEvent = (QGraphicsSceneMouseEvent*) event;
        QGraphicsItem* item = 0;
        switch ((int) event->type())
        {
            case QEvent::GraphicsSceneMousePress:
                mouseClickHandler(mouseEvent);
            break;

            case QEvent::GraphicsSceneMouseDoubleClick:
                mouseDoubleClickHandler(mouseEvent);
            break;

            case QEvent::GraphicsSceneMouseMove:
            {
                mouseMoveHandler(mouseEvent);
            }
            break;

            case QEvent::GraphicsSceneMouseRelease:
            {
                mouseReleaseHandler(mouseEvent);
            }
            break;
        }
        return QObject::eventFilter(object, event);
    }

    //****************************************************************************/
    bool QtNodeEditor::mouseClickHandler(QGraphicsSceneMouseEvent* mouseEvent)
    {
        switch ((int) mouseEvent->button())
        {
            case Qt::LeftButton:
            {
                QGraphicsItem* item = itemAtExceptActiveConnection(mouseEvent->scenePos());
                if (!item)
                {
                    // Left-click on the canvas, but no item clicked, so deselect nodes and connections
                    deselectAll();
                    mRubberbandSelection = true;
                    mLastMousePosition.setX(mouseEvent->lastScenePos().x());
                    mLastMousePosition.setY(mouseEvent->lastScenePos().y());
                    return true;
                }
                mRubberbandSelection = false;

                // Delegate to the node; either the node itself is clicked, one of its children or a connection
                QtNode* node;
                int type = 0;
                if (item->data(NODE_KEY_GRAPHIC_ITEM_TYPE).isValid())
                {
                    type = item->data(NODE_KEY_GRAPHIC_ITEM_TYPE).toInt();
                    if (NODE_VALUE_TYPE_CONNECTION == type)
                    {
                        // ======================= Handle selected connection =======================
                        QtConnection* connection = static_cast<QtConnection*>(item);
                        selectConnection(connection);
                    }
                    else if (NODE_VALUE_TYPE_NODE == type)
                    {
                        // ======================= The node itself is clicked =======================
                        node = static_cast<QtNode*>(item);
                        selectNode(node, mouseEvent);
                    }
                    else if (NODE_VALUE_TYPE_HEADER_ICON == type || NODE_VALUE_TYPE_HEADER_TITLE == type)
                    {
                        // ======================= The header title or header icon is clicked =======================
                        node = static_cast<QtNode*>(item->parentItem());
                        selectNode(node, mouseEvent);
                    }
                    else
                    {
                        // A child item of the node is clicked
                        deselectNodes();
                        deselectConnections();
                        node = static_cast<QtNode*>(item->parentItem());

                        if (NODE_VALUE_TYPE_PORT == type)
                        {
                            // ======================= Port is clicked =======================
                            // Either make a connection to another port, or create a new connection
                            QtNode* baseNode = getNodeWithActiveConnection();
                            if (baseNode == 0)
                            {
                                // There is no active connection, so start one
                                node->mouseLeftClickHandler(mouseEvent, item, NODE_ACTION_BASE);
                                setCursor(Qt::ClosedHandCursor);
                            }
                            else if (baseNode != node)
                            {
                                // There is an active connection and the selected port is not part of the baseNode,
                                // so try to establish a connection with the other node
                                if (node->mouseLeftClickHandler(mouseEvent, item, NODE_ACTION_TARGET, baseNode->mActiveConnection))
                                {
                                    // The connection was established, so the active connection on the basenode can be set to 0
                                    baseNode->mActiveConnection = 0;
                                    setCursor(Qt::ArrowCursor);
                                }
                            }
                        }
                        else
                        {
                            node->mouseLeftClickHandler(mouseEvent, item); // Don't do anything with the node after this; it may be deleted
                        }
                    }
                    return true;
                }
            }
            break;

            case Qt::RightButton:
            {
                if (mContextMenuEnabled)
                {
                    QPoint pos;
                    pos.setX(mouseEvent->lastScreenPos().x());
                    pos.setY(mouseEvent->lastScreenPos().y());
                    showContextMenu(pos);
                }
                else
                    deselectAll();

                return true;
            }
            break;
        }

        //mouseEvent->accept();
        return true;
    }

    //****************************************************************************/
    bool QtNodeEditor::mouseDoubleClickHandler(QGraphicsSceneMouseEvent* mouseEvent)
    {
        // Todo
        return true;
    }

    //****************************************************************************/
    bool QtNodeEditor::mouseMoveHandler(QGraphicsSceneMouseEvent* mouseEvent)
    {
        // If a Fisheye view is enabled, apply it
        if (mFisheyeViewEnabled)
        {
            fisheyeZoom(mouseEvent);
        }

        // If there was a rubberband selection started, update its rectangle
        if(mRubberbandSelection && mouseEvent->buttons() & Qt::LeftButton)
        {
            // Rubberband selection
            rubberbandSelection(mouseEvent);
        }

        QtNode* node;
        QList<QGraphicsItem*> items = mScene->items();
        foreach(QGraphicsItem* item, items)
        {
            if (isNode(item) && item->isVisible())
            {
                node = static_cast<QtNode*>(item);
                node->mouseMoveHandler(mouseEvent, item);

                // Only perform drag and drop of a node on a compound when the node is selected
                if (node->isSelected() && mouseEvent->buttons() & Qt::LeftButton)
                {
                    QtCompoundNode* compound = nodeOverCompound(node);
                    if (compound)
                    {
                        //setCursor(Qt::SizeAllCursor); // Indication that the node(s) can be dropped
                        setCursor(Qt::CrossCursor); // Indication that the node(s) can be dropped
                        mCompoundNodeDropped = compound;
                        return true;
                    }
                }
            }
        }
        mCompoundNodeDropped = 0;
        setCursor(Qt::ArrowCursor);
        return true;
    }
Ejemplo n.º 19
0
bool Node::isDEFNode() 
{
	return isNode(defNodeString);
}
Ejemplo n.º 20
0
nsresult
XPathResult::SetExprResult(txAExprResult* aExprResult, uint16_t aResultType,
                           nsINode* aContextNode)
{
    MOZ_ASSERT(aExprResult);

    if ((isSnapshot(aResultType) || isIterator(aResultType) ||
         isNode(aResultType)) &&
        aExprResult->getResultType() != txAExprResult::NODESET) {
        // The DOM spec doesn't really say what should happen when reusing an
        // XPathResult and an error is thrown. Let's not touch the XPathResult
        // in that case.
        return NS_ERROR_DOM_TYPE_ERR;
    }

    mResultType = aResultType;
    mContextNode = do_GetWeakReference(aContextNode);

    if (mDocument) {
        mDocument->RemoveMutationObserver(this);
        mDocument = nullptr;
    }

    mResultNodes.Clear();

    // XXX This will keep the recycler alive, should we clear it?
    mResult = aExprResult;
    switch (mResultType) {
        case BOOLEAN_TYPE:
        {
            mBooleanResult = mResult->booleanValue();
            break;
        }
        case NUMBER_TYPE:
        {
            mNumberResult = mResult->numberValue();
            break;
        }
        case STRING_TYPE:
        {
            mResult->stringValue(mStringResult);
            break;
        }
        default:
        {
            MOZ_ASSERT(isNode() || isIterator() || isSnapshot());
        }
    }

    if (aExprResult->getResultType() == txAExprResult::NODESET) {
        txNodeSet *nodeSet = static_cast<txNodeSet*>(aExprResult);
        int32_t i, count = nodeSet->size();
        for (i = 0; i < count; ++i) {
            nsINode* node = txXPathNativeNode::getNode(nodeSet->get(i));
            mResultNodes.AppendObject(node);
        }

        if (count > 0) {
            mResult = nullptr;
        }
    }

    if (!isIterator()) {
        return NS_OK;
    }

    mInvalidIteratorState = false;

    if (mResultNodes.Count() > 0) {
        // If we support the document() function in DOM-XPath we need to
        // observe all documents that we have resultnodes in.
        mDocument = mResultNodes[0]->OwnerDoc();
        NS_ASSERTION(mDocument, "We need a document!");
        if (mDocument) {
            mDocument->AddMutationObserver(this);
        }
    }

    return NS_OK;
}
Ejemplo n.º 21
0
Node* NodeOrNodeList::getAsNode() const {
  DCHECK(isNode());
  return m_node;
}
const treeLeaf<Type>* treeNode<Type>::findLeafLineOctant
(
    const int level,
    const Type& shapes,
    const label octant,
    const vector& direction,
    point& start,
    const point& end
) const
{
    static const char* functionName =
        "treeNode<Type>::findLeafLineOctant"
        "(const int, const Type&, const label, const vector&,"
        " point&, const point&)";

    if (debug & 2)
    {
        space(Pout, 2*level);
        Pout<< "findLeafLineOctant : bb:" << this->bb()
            << "  start:" << start
            << "  end:" << end
            << "  mid:" << mid()
            << " Searching octant:" << octant
            << endl;
    }

    if (subNodes()[octant])
    {
        if (isNode(octant))
        {
            // Node: recurse into subnodes
            const treeNode<Type>* subNodePtr = getNodePtr(octant);

            if (subNodePtr->bb().contains(direction, start))
            {
                // Search on lower level
                const treeLeaf<Type>* subLeafPtr =
                    subNodePtr->findLeafLine
                    (
                        level + 1,
                        shapes,
                        start,
                        end
                    );

                if (debug & 2)
                {
                    space(Pout, 2*level);
                    Pout<< "findLeafLineOctant : bb:" << this->bb()
                        << " returning from sub treeNode"
                        << " with start:" << start << "  subLeaf:"
                        << long(subLeafPtr) << endl;
                }

                return subLeafPtr;
            }
            else
            {
                FatalErrorIn(functionName)
                    << "Sub node " << subNodePtr->bb()
                    << " at octant " << octant
                    << " does not contain start " << start
                    << abort(FatalError);
            }
        }
        else
        {
            // Leaf
            const treeLeaf<Type>* subLeafPtr = getLeafPtr(octant);

            if (subLeafPtr->bb().contains(direction, start))
            {
                // Step to end of subleaf bb
                point tmp;
                if 
                (
                   !subLeafPtr->bb().intersects
                    (
                        end,
                        start,
                        tmp
                    )
                )
                {
                    FatalErrorIn(functionName)
                        << "Sub leaf contains start " << start
                        << " but line does not intersect its bb "
                        << subLeafPtr->bb()
                        << abort(FatalError);
                }
                start = tmp;

                if (debug & 2)
                {
                    space(Pout, 2*level);
                    Pout<< "findLeafLineOctant : returning from intersecting"
                        << " treeLeaf " << subLeafPtr->bb()
                        << " with start:" << start << "  subLeaf:"
                        << long(subLeafPtr) << endl;
                }

                return subLeafPtr;
            }
            else
            {
                FatalErrorIn(functionName)
                    << "Sub leaf " << subLeafPtr->bb()
                    << " at octant " << octant
                    << " does not contain start " << start
                    << abort(FatalError);
            }
        }
    }
    else
    {
        // Empty subNode. Transfer across.
        const treeBoundBox emptyBb = this->bb().subBbox(mid(), octant);

        if (emptyBb.contains(direction, start))
        {
            if (debug & 2)
            {
                space(Pout, 2*level);
                Pout<< "findLeafLineOctant : Empty node. Octant:" << octant
                    << "  start:" << start
                    << "  bb:" << this->bb()
                    << "  emptyBb:" << emptyBb << endl;
            }

            // Update start by clipping to emptyBb
            point tmp;
            if 
            (
               !emptyBb.intersects
                (
                    end,
                    start,
                    tmp
                )
            )
            {
                FatalErrorIn(functionName)
                    << "Empty node contains start " << start
                    << " but line does not intersect its (calculated)"
                    << " bb " << emptyBb
                    << endl << "This might be due to truncation error"
                    << abort(FatalError);
            }
            start = tmp;

            if (debug & 2)
            {
                space(Pout, 2*level);
                Pout<< "findLeafLineOctant : returning from intersecting with"
                    << " empty " << emptyBb
                    << " with start:" << start << "  subLeaf:" << 0 << endl;
            }

            return NULL;
        }
        else
        {
            FatalErrorIn(functionName)
                << "Empty node " << emptyBb
                << " at octant " << octant
                << " does not contain start " << start
                << abort(FatalError);
        }
    }

    FatalErrorIn(functionName)
        << "Octant " << octant << " of cube " << this->bb()
        << " does not contain start " << start
        << abort(FatalError);

    return NULL;
}
Ejemplo n.º 23
0
bool Node::isRootNode() 
{
	return isNode(rootNodeString);
}