예제 #1
0
bool
NGRandomNetBuilder::createNewNode(NGNode* baseNode) {
    // calculate position of new node based on BaseNode
    SUMOReal dist = RandHelper::rand(myMinDistance, myMaxDistance);
    SUMOReal angle = RandHelper::rand((SUMOReal)(2 * M_PI));
    SUMOReal x = baseNode->getPosition().x() + dist * cos(angle);
    SUMOReal y = baseNode->getPosition().y() + dist * sin(angle);
    NGNode* newNode = new NGNode(myNet.getNextFreeID());
    newNode->setX(x);
    newNode->setY(y);
    newNode->setMaxNeighbours((SUMOReal) myNeighbourDistribution.num());
    NGEdge* newLink = new NGEdge(myNet.getNextFreeID(), baseNode, newNode);
    if (canConnect(baseNode, newNode)) {
        // add node
        myNet.add(newNode);
        myOuterNodes.push_front(newNode);
        // add link
        myNet.add(newLink);
        myOuterLinks.push_back(newLink);
        // check basenode for being outer node
        if (baseNode->LinkList.size() >= baseNode->getMaxNeighbours()) {
            removeOuterNode(baseNode);
        }
        return true;
    } else {
        delete newNode;
        return false;
    }
}
예제 #2
0
void AudioNode::connect(AudioNode* destination, unsigned int output, unsigned int input) {
  if (destination == NULL) {
    dm_debug_log(m_context->getLog(), Log::Error, "Trying to connect a node of type %s to a node that doesn't exist. did you create it?", this->getType());
    return;
  }

  //
  if (!canConnect(destination, output, input)) {
    return;
  }

	if (input >= destination->m_inputs.size()) {
    dm_debug_log(m_context->getLog(),Log::Error, "Trying to connect node %d(%d) to %d (%d doesn't exist)", ID, output, destination->ID, input);
		return;
	}

	if (output >= m_outputs.size()) {
    dm_debug_log(m_context->getLog(),Log::Error, "Trying to connect node %d(%d doesn't exist) to %d (%d)", ID, output, destination->ID, input);
		return;
	}
  context()->lock();

	destination->m_inputs[input]->connect(m_outputs[output]);
  m_outputs[output]->addInput(destination->m_inputs[input]);

  context()->unlock();
}
예제 #3
0
Connector *CircuitICNDocument::createConnector( const QString &startNodeId, const QString &endNodeId, QPointList *pointList )
{
	ECNode *startNode = getEcNodeWithID(startNodeId);
	ECNode *endNode = getEcNodeWithID(endNodeId);
	
	if ( !startNode || !endNode ) {
		kDebug() << "Either/both the connector start node and end node could not be found" << endl;
		return 0L;
	}
	
	if ( !canConnect( startNode, endNode ) ) return 0l;
	
	Connector *connector = endNode->createConnector(startNode);
	if (!connector) {
		kError() << k_funcinfo << "End node did not create the connector" << endl;
		return 0l;
	}

	startNode->addConnector(connector);
	flushDeleteList(); // Delete any connectors that might have been removed by the nodes
	
	// Set the route to the manual created one if the user created such a route
	if(pointList) connector->setRoutePoints(*pointList,true);
	
	// FIXME WTF is going on here? Redundant/meaningless code?
//	ConnectorList connectorList;
//	connectorList.append(connector);
	
	setModified(true);
	
	requestRerouteInvalidatedConnectors();
	return connector;
}
예제 #4
0
bool NetworkObserver::is_connection_available()
{
	QList<QNetworkInterface> list = QNetworkInterface::allInterfaces();


	for(QList<QNetworkInterface>::iterator it = list.begin() ; it != list.end() ; it ++)
	{
		if((*it).isValid())
		{	
			if((*it).flags() & QNetworkInterface::IsLoopBack)
				continue;


			if( (*it).flags() & QNetworkInterface::IsUp && (*it).flags() & QNetworkInterface::IsRunning )
			{
				QList<QNetworkAddressEntry> list2 = (*it).addressEntries  ();
				for(QList<QNetworkAddressEntry>::iterator itt = list2.begin() ; itt != list2.end();itt++ )
				{
					if(!(*itt).ip().isNull() && (*itt).ip().protocol() == QAbstractSocket::IPv4Protocol)
					{
						return canConnect();						
					}
				}
			}
		}
	}

	return false;
}
예제 #5
0
//---------------------------------------------connect
bool ModuleInputBase::connect(ModuleOutputBase* pOutput, bool bCheckCompatibility)
{
  if(pOutput && (!bCheckCompatibility || canConnect(pOutput)))
  {
    m_pConnectedOutput = pOutput;
    return true;
  }
  return false;
}
예제 #6
0
Connector * CircuitICNDocument::createConnector( Node *node, Connector *con, const QPoint &pos2, QPointList *pointList )
{
	if(!canConnect( node, con ) ) return 0;
	
	// FIXME dynamic_cast used, fix it in Connector class
	
	ECNode *conStartNode = dynamic_cast<ECNode *> (con->startNode() );
	ECNode *conEndNode   = dynamic_cast<ECNode *> (con->endNode() );
	ECNode *ecNode       = dynamic_cast<ECNode *> (node );
	
	const bool usedManual = con->usesManualPoints();
	
	ECNode *newNode = new JunctionNode(this, 0, pos2);

	QPointList autoPoints;
	if (!pointList) {
		addAllItemConnectorPoints();
		ConRouter cr(this);
		cr.mapRoute( int(node->x()), int(node->y()), pos2.x(), pos2.y() );
		autoPoints = cr.pointList(false);
		pointList = &autoPoints;
	}
	
	QList<QPointList> oldConPoints = con->splitConnectorPoints(pos2);
	con->hide();

	// The actual new connector
	Connector *new1 = newNode->createConnector(node);
	ecNode->addConnector(new1);
	new1->setRoutePoints(*pointList,usedManual);

	// The two connectors formed from the original one when split
	Connector *new2 = newNode->createConnector(conStartNode);
	conStartNode->addConnector(new2);
	new2->setRoutePoints( oldConPoints.at(0), usedManual );

	Connector *new3 = conEndNode->createConnector(newNode);
	newNode->addConnector(new3);
	new3->setRoutePoints( oldConPoints.at(1), usedManual );

	// Avoid flicker: tell them to update their draw lists now
	con->updateConnectorPoints(false);
	new1->updateDrawList();
	new2->updateDrawList();
	new3->updateDrawList();

	// Now it's safe to remove the connector...
	con->removeConnector();
	flushDeleteList();

	deleteNodeGroup(conStartNode);
	deleteNodeGroup(conEndNode);
	createNodeGroup(newNode)->init();

	return new1;
}
예제 #7
0
void
NGRandomNetBuilder::createNet(int numNodes) {
    myNumNodes = numNodes;

    NGNode* outerNode = new NGNode(myNet.getNextFreeID());
    outerNode->setX(0);
    outerNode->setY(0);
    outerNode->setMaxNeighbours(4);

    myNet.add(outerNode);
    myOuterNodes.push_back(outerNode);

    bool created = true;
    while (((int) myNet.nodeNo() < numNodes) && (myOuterNodes.size() > 0)) {
        // brings last element to front
        if (!created) {
            myOuterNodes.push_front(myOuterNodes.back());
            myOuterNodes.pop_back();
        }
        outerNode = myOuterNodes.back();
        findPossibleOuterNodes(outerNode);
        created = false;
        if ((myConNodes.size() > 0) && (RandHelper::rand() < myConnectivity)) {
            // create link
            NGEdge* newLink = new NGEdge(myNet.getNextFreeID(), outerNode, myConNodes.back());
            if (canConnect(outerNode, myConNodes.back())) {
                // add link
                myNet.add(newLink);
                myOuterLinks.push_back(newLink);
                // check nodes for being outer node
                if (outerNode->LinkList.size() >= outerNode->getMaxNeighbours()) {
                    removeOuterNode(outerNode);
                }
                if (myConNodes.back()->LinkList.size() >= myConNodes.back()->getMaxNeighbours()) {
                    removeOuterNode(myConNodes.back());
                }
                created = true;
            } else {
                delete newLink;
            }
        } else {
            int count = 0;
            do {
                created = createNewNode(outerNode);
                count++;
            } while ((count <= myNumTries) && !created);
            if (!created) {
                outerNode->setMaxNeighbours((SUMOReal) outerNode->LinkList.size());
                myOuterNodes.remove(outerNode);
            }
        }
    }
}
예제 #8
0
void
NGRandomNetBuilder::findPossibleOuterNodes(NGNode* node) {
    myConNodes.clear();
    NGNodeList::iterator ni;
    for (ni = myOuterNodes.begin(); ni != myOuterNodes.end(); ++ni) {
        NGNode* on = *ni;
        if (!node->connected(on)) {
            if ((node->getMaxNeighbours() > node->LinkList.size()) &&
                    ((on)->getMaxNeighbours() > (on)->LinkList.size())) {
                if (canConnect(node, on)) {
                    myConNodes.push_back(on);
                }
            }
        }
    }
}
예제 #9
0
void ConnectorItem::mousePressEvent(QGraphicsSceneMouseEvent* event)
{
    if(! canConnect())
        return;
    
    m_currentArrow = new ArrowItem(this);
    if(m_connectorType == INPUT)
    {
        m_currentArrow->setStart(mapFromScene(event->scenePos()));
        m_currentArrow->setEnd(QPointF(0, 0));
    }
    else
    {
        m_currentArrow->setStart(QPointF(0, 0));
        m_currentArrow->setEnd(mapFromScene(event->scenePos()));
    }
}
예제 #10
0
Connector *CircuitICNDocument::createConnector(Connector *con1, Connector *con2, const QPoint &pos1, const QPoint &pos2, QPointList *pointList )
{
	if ( !canConnect( con1, con2 ) ) return 0;
	
	const bool con1UsedManual = con1->usesManualPoints();
	const bool con2UsedManual = con2->usesManualPoints();
	
	QList<QPointList> oldCon1Points = con1->splitConnectorPoints(pos1);
	QList<QPointList> oldCon2Points = con2->splitConnectorPoints(pos2);
	
	ECNode *node1a = dynamic_cast<ECNode*> ( con1->startNode() );
	ECNode *node1b = dynamic_cast<ECNode*> ( con1->endNode(  ) );
	
	ECNode *node2a = dynamic_cast<ECNode*> ( con2->startNode() );
	ECNode *node2b = dynamic_cast<ECNode*> ( con2->endNode(  ) );
	
	if ( !node1a || !node1b || !node2a || !node2b ) return 0;
	
	con1->hide();	
	con2->hide();

	// from this point forward, we are dealing with a circuit document -> all nodes are electronic
	
	ECNode *newNode1 = new JunctionNode( this, 0, pos1 );
	ECNode *newNode2 = new JunctionNode( this, 0, pos2 );
	
	Connector *con1a = newNode1->createConnector(node1a);
	node1a->addConnector(con1a);

	Connector *con1b = newNode1->createConnector(node1b);
	node1b->addConnector(con1b);
	
	Connector *newCon = newNode1->createConnector(newNode2);
	newNode2->addConnector(newCon);
	
	Connector *con2a = node2a->createConnector(newNode2);
	newNode2->addConnector(con2a);

	Connector *con2b = node2b->createConnector(newNode2);
	newNode2->addConnector(con2b);
	
	if(!con1a || !con1b || !con2a || !con2b ) {
		// This should never happen, as the canConnect function should strictly
		// determine whether the connectors could be created before hand.
		kWarning() << k_funcinfo << "Not all the connectors were created, this should never happen" << endl;
		
		if(con1a) con1a->removeConnector();
		if(con1b) con1b->removeConnector();
		if(con2a) con2a->removeConnector();
		if(con2b) con2b->removeConnector();
		
		newNode1->removeNode();
		newNode2->removeNode();
		
		flushDeleteList();
		return 0;
	}
	
	con1a->setRoutePoints(oldCon1Points.at(0), con1UsedManual );
	con1b->setRoutePoints(oldCon1Points.at(1), con1UsedManual );
	
	con2a->setRoutePoints(oldCon2Points.at(0), con2UsedManual );
	con2b->setRoutePoints(oldCon2Points.at(1), con2UsedManual );
	
	QPointList autoPoints;

	if (!pointList) {
		addAllItemConnectorPoints();
		ConRouter cr(this);
		cr.mapRoute( pos1.x(), pos1.y(), pos2.x(), pos2.y() );
		autoPoints = cr.pointList(false);
		pointList = &autoPoints;
	}

	newCon->setRoutePoints(*pointList,true);

	// Avoid flicker: tell them to update their draw lists now
	con1->updateConnectorPoints(false);
	con2->updateConnectorPoints(false);
	newCon->updateDrawList();
	con1a->updateDrawList();
	con1b->updateDrawList();
	con2a->updateDrawList();
	con2b->updateDrawList();
	
	// Now it's safe to remove the connectors
	con1->removeConnector();
	con2->removeConnector();
	
	flushDeleteList();

	deleteNodeGroup(node1a);
	deleteNodeGroup(node1b);
	deleteNodeGroup(node2a);
	deleteNodeGroup(node2b);

	NodeGroup *ng = createNodeGroup(newNode1);

	ng->addNode( newNode2, true );
	ng->init();
	
	return newCon;
}