Esempio n. 1
0
Node *CNItem::getClosestNode( const QPoint &pos )
{
	// Work through the nodes, finding the one closest to the (x, y) position
	Node *shortestNode = 0L;
	double shortestDistance = 1e10; // Nice large distance :-)
	
	const NodeInfoMap::iterator end = m_nodeMap.end();
	for ( NodeInfoMap::iterator it = m_nodeMap.begin(); it != end; ++it )
	{
		Node *node = p_icnDocument->nodeWithID(it.data().id);
		if (node)
		{
			// Calculate the distance
			// Yeah, it's actually the distance squared; but it's all relative, so doesn't matter
			double distance = std::pow(node->x()-pos.x(),2) + std::pow(node->y()-pos.y(),2);
			
			if ( distance < shortestDistance )
			{
				shortestDistance = distance;
				shortestNode = node;
			}
		}
	}
	
	return shortestNode;
}
Esempio n. 2
0
void CNItem::setVisible( bool yes )
{
	if (b_deleted)
	{
		Item::setVisible(false);
		return;
	}
	
	Item::setVisible(yes);
	
	const TextMap::iterator textMapEnd = m_textMap.end();
	for ( TextMap::iterator it = m_textMap.begin(); it != textMapEnd; ++it )
	{
		it.data()->setVisible(yes);
	}

	const NodeInfoMap::iterator nodeMapEnd = m_nodeMap.end();
	for ( NodeInfoMap::iterator it = m_nodeMap.begin(); it != nodeMapEnd; ++it )
	{
		it.data().node->setVisible(yes);
	}
	
	CNItem::setDrawWidgets(yes);
	
	if (!yes)
		updateConnectorPoints(false);
}
Esempio n. 3
0
ConnectorList CNItem::connectorList()
{
	ConnectorList list;

	const NodeInfoMap::iterator nodeMapEnd = m_nodeMap.end();
	for ( NodeInfoMap::iterator it = m_nodeMap.begin(); it != nodeMapEnd; ++it )
	{
		Node *node = p_icnDocument->nodeWithID(it.data().id);
		if (node)
		{
			ConnectorList nodeList = node->getAllConnectors();
			ConnectorList::iterator end = nodeList.end();
			for ( ConnectorList::iterator it = nodeList.begin(); it != end; ++it )
			{
				if ( *it && !list.contains(*it) )
				{
					list.append(*it);
				}
			}

		}
	}
	
	return list;
}
Esempio n. 4
0
bool CNItem::removeNode( const QString &name )
{
	NodeInfoMap::iterator it = m_nodeMap.find(name);
	if ( it == m_nodeMap.end() ) {
		return false;
	}
	it.data().node->removeNode();
	p_icnDocument->flushDeleteList();
	m_nodeMap.erase(it);
	return true;
}
Esempio n. 5
0
FlowPartList FlowPart::outputParts() {
	FlowPartList list;

	const NodeInfoMap::iterator end = m_nodeMap.end();
	for (NodeInfoMap::iterator it = m_nodeMap.begin(); it != end; ++it) {
		FlowPart *part = outputPart(it.key());

		if (part) list.append(part);
	}

	return list;
}
Esempio n. 6
0
void PIC_IC::initPackage( MicroInfo * microInfo )
{
	// The code in this function is a stripped down version of that in PICComponent::initPackage
	
	if (!microInfo)
		return;
	
	MicroPackage * microPackage = microInfo->package();
	if (!microPackage)
		return;
	
	//BEGIN Get pin IDs
	QStringList allPinIDs = microPackage->pinIDs();
	QStringList ioPinIDs = microPackage->pinIDs( PicPin::type_bidir | PicPin::type_input | PicPin::type_open );
	
	// Now, we make the unwanted pin ids blank, so a pin is not created for them
	const QStringList::iterator allPinIDsEnd = allPinIDs.end();
	for ( QStringList::iterator it = allPinIDs.begin(); it != allPinIDsEnd; ++it )
	{
		if ( !ioPinIDs.contains(*it) )
			*it = "";
	}
	//END Get pin IDs
	
	
	//BEGIN Remove old stuff
	// Remove old text
	TextMap textMapCopy = m_textMap;
	const TextMap::iterator textMapEnd = textMapCopy.end();
	for ( TextMap::iterator it = textMapCopy.begin(); it != textMapEnd; ++it )
		removeDisplayText(it.key());
	
	// Remove old nodes
	NodeInfoMap nodeMapCopy = m_nodeMap;
	const NodeInfoMap::iterator nodeMapEnd = nodeMapCopy.end();
	for ( NodeInfoMap::iterator it = nodeMapCopy.begin(); it != nodeMapEnd; ++it )
	{
		if ( !ioPinIDs.contains(it.key()) )
			removeNode( it.key() );
	}
	//END Remove old stuff
	
	
	
	//BEGIN Create new stuff
	initDIPSymbol( allPinIDs, 80 );
	initDIP(allPinIDs);
	//END Create new stuff
	
	
	addDisplayText( "picid", QRect(offsetX(), offsetY()-16, width(), 16), microInfo->id() );
}
Esempio n. 7
0
void FlowPart::updateNodePositions() {
	if (m_orientation > 7) {
		kdWarning() << k_funcinfo << "Invalid orientation: " << m_orientation << endl;
		return;
	}

	NodeInfo *stdInputInfo = m_stdInput ? &m_nodeMap["stdinput"] : 0;
	NodeInfo *stdOutputInfo = m_stdOutput ? &m_nodeMap["stdoutput"] : 0;
	NodeInfo *altOutputInfo = m_altOutput ? &m_nodeMap["altoutput"] : 0;

	if (m_stdInput && m_stdOutput && m_altOutput) {
		stdInputInfo->orientation = diamondNodePositioning[m_orientation][0];
		stdOutputInfo->orientation = diamondNodePositioning[m_orientation][1];
		altOutputInfo->orientation = diamondNodePositioning[m_orientation][2];
	} else if (m_stdInput && m_stdOutput) {
		stdInputInfo->orientation = inOutNodePositioning[m_orientation][0];
		stdOutputInfo->orientation = inOutNodePositioning[m_orientation][1];
	} else if (m_orientation < 4) {
		if (stdInputInfo)
			stdInputInfo->orientation = inNodePositioning[m_orientation];
		else if (stdOutputInfo)
			stdOutputInfo->orientation = outNodePositioning[m_orientation];
	} else {
		kdWarning() << k_funcinfo << "Invalid orientation: " << m_orientation << endl;
		return;
	}

	const NodeInfoMap::iterator end = m_nodeMap.end();

	for (NodeInfoMap::iterator it = m_nodeMap.begin(); it != end; ++it) {
		if (!it.data().node)
			kdError() << k_funcinfo << "Node in nodemap is null" << endl;
		else {
			switch (it.data().orientation) {

			case 0:
				it.data().x = offsetX() + width() + 8;
				it.data().y = 0;
				break;

			case 270:
				it.data().x = 0;
				it.data().y = offsetY() - 8;
				break;

			case 180:
				it.data().x = offsetX() - 8;
				it.data().y = 0;
				break;

			case 90:
				it.data().x = 0;
				it.data().y = offsetY() + height() + 8;;
				break;
			}
		}
	}

	updateAttachedPositioning();
}
Esempio n. 8
0
void CNItem::updateZ( int baseZ )
{
	Item::updateZ(baseZ);
	
	double _z = z();
	
	const NodeInfoMap::iterator nodeMapEnd = m_nodeMap.end();
	for ( NodeInfoMap::iterator it = m_nodeMap.begin(); it != nodeMapEnd; ++it )
		it.data().node->setZ( _z + 0.5 );
	
	const WidgetMap::iterator widgetMapEnd = m_widgetMap.end();
	for ( WidgetMap::iterator it = m_widgetMap.begin(); it != widgetMapEnd; ++it )
		it.data()->setZ( _z + 0.5 );
	
	const TextMap::iterator textMapEnd = m_textMap.end();
	for ( TextMap::iterator it = m_textMap.begin(); it != textMapEnd; ++it )
		it.data()->setZ( _z + 0.5 );
}
Esempio n. 9
0
void CNItem::updateNodeLevels()
{
	int l = level();
	
	// Tell our nodes about our level
	const NodeInfoMap::iterator nodeMapEnd = m_nodeMap.end();
	for ( NodeInfoMap::iterator it = m_nodeMap.begin(); it != nodeMapEnd; ++it )
	{
		it.data().node->setLevel(l);
	}
	
	const ItemList::iterator end = m_children.end();
	for ( ItemList::iterator it = m_children.begin(); it != end; ++it )
	{
		if ( CNItem *cnItem = dynamic_cast<CNItem*>((Item*)*it) )
			cnItem->updateNodeLevels();
	}
}
Esempio n. 10
0
FlowPartList FlowPart::inputParts() {
	FlowPartList list;

	const NodeInfoMap::iterator nEnd = m_nodeMap.end();
	for (NodeInfoMap::iterator it = m_nodeMap.begin(); it != nEnd; ++it) {
		Node *node = m_pFlowCodeDocument->nodeWithID(it.data().id);
		FlowPartList newList;

		if (FPNode *fpNode = dynamic_cast<FPNode*>(node))
			newList = fpNode->inputFlowParts();

		const FlowPartList::iterator nlEnd = newList.end();
		for (FlowPartList::iterator it = newList.begin(); it != nlEnd; ++it) {
			if (*it) list.append(*it);
		}
	}

	return list;
}
Esempio n. 11
0
void FlowPart::updateAttachedPositioning() {
	if (b_deleted) return;

	//BEGIN Rearrange text if appropriate
	const QRect textPos[4] = {
		QRect(offsetX() + width(),	6,				40, 16),
		QRect(0,				offsetY() - 16,		40, 16),
		QRect(offsetX() - 40,		6,				40, 16),
		QRect(0,				offsetY() + height(),	40, 16)
	};

	NodeInfo *stdOutputInfo = m_stdOutput ? &m_nodeMap["stdoutput"] : 0;
	NodeInfo *altOutputInfo = m_altOutput ? &m_nodeMap["altoutput"] : 0;

	Text *outputTrueText = m_textMap.contains("output_true") ? m_textMap["output_true"] : 0;
	Text *outputFalseText = m_textMap.contains("output_false") ? m_textMap["output_false"] : 0;

	if (stdOutputInfo && outputTrueText)
		outputTrueText->setOriginalRect(textPos[ nodeDirToPos(stdOutputInfo->orientation)]);

	if (altOutputInfo && outputFalseText)
		outputFalseText->setOriginalRect(textPos[ nodeDirToPos(altOutputInfo->orientation)]);

	const TextMap::iterator textMapEnd = m_textMap.end();
	for (TextMap::iterator it = m_textMap.begin(); it != textMapEnd; ++it) {
		QRect pos = it.data()->recommendedRect();
		it.data()->move(pos.x() + x(), pos.y() + y());
		it.data()->setGuiPartSize(pos.width(), pos.height());
	}
	//END Rearrange text if appropriate

	const NodeInfoMap::iterator end = m_nodeMap.end();
	for (NodeInfoMap::iterator it = m_nodeMap.begin(); it != end; ++it) {
		if (!it.data().node) {
			kdError() << k_funcinfo << "Node in nodemap is null" << endl;
			continue;
		}

		double nx = it.data().x;
		double ny = it.data().y;

#define round_8(x) (((x) > 0) ? int(((x)+4)/8)*8 : int(((x)-4)/8)*8)
		nx = round_8(nx);
		ny = round_8(ny);
#undef round_8

		it.data().node->move(int(nx + x()), int(ny + y()));
		it.data().node->setOrientation(it.data().orientation);
	}
}
Esempio n. 12
0
FlowPart* FlowPart::endPart(QStringList ids, FlowPartList *previousParts) {
	if (ids.empty()) {
		const NodeInfoMap::iterator end = m_nodeMap.end();
		for (NodeInfoMap::iterator it = m_nodeMap.begin(); it != end; ++it) {
			ids.append(it.key());
		}

		filterEndPartIDs(&ids);
	}

	const bool createdList = (!previousParts);

	if (createdList) {
		previousParts = new FlowPartList;
	} else if (previousParts->contains(this)) {
		return 0l;
	}

	previousParts->append(this);

	if (ids.empty()) {
		return 0;
	}

	if (ids.size() == 1) {
		return outputPart(*(ids.begin()));
	}

	typedef QValueList<FlowPartList>  ValidPartsList;

	ValidPartsList validPartsList;

	const QStringList::iterator idsEnd = ids.end();
	for (QStringList::iterator it = ids.begin(); it != idsEnd; ++it) {
		int prevLevel = level();
		FlowPartList validParts;
		FlowPart *part = outputPart(*it);

		while (part) {
			if (!validParts.contains(part)) {
				validParts.append(part);
// 				if ( part->level() >= level() ) {
				const int _l = part->level();
				part = part->endPart(QStringList(), previousParts);
				prevLevel = _l;
// 				} else {
// 					part = 0l;
// 				}
			} else {
				part = 0;
			}
		}

		if (!validParts.empty()) {
			validPartsList.append(validParts);
		}
	}

	if (createdList) {
		delete previousParts;
		previousParts = 0;
	}

	if (validPartsList.empty()) return 0;

	FlowPartList firstList = *(validPartsList.begin());

	const FlowPartList::iterator flEnd = firstList.end();
	const ValidPartsList::iterator vplEnd = validPartsList.end();
	for (FlowPartList::iterator it = firstList.begin(); it != flEnd; ++it) {
		bool ok = true;

		for (ValidPartsList::iterator vplit = validPartsList.begin(); vplit != vplEnd; ++vplit) {
			if (!(*vplit).contains(*it)) ok = false;
		}

		if (ok) return *it;
	}

	return 0l;
}
Esempio n. 13
0
void PICComponent::initPackage( MicroInfo * microInfo )
{
	MicroPackage * microPackage = microInfo ? microInfo->package() : 0l;
	
	if ( microPackage )
	{
		m_bCreatedInitialPackage = true;
		
		//BEGIN Get pin IDs
		QStringList allPinIDs = microPackage->pinIDs();
		QStringList ioPinIDs = microPackage->pinIDs( PicPin::type_bidir | PicPin::type_input | PicPin::type_open );
	
		// Now, we make the unwanted pin ids blank, so a pin is not created for them
		const QStringList::iterator allPinIDsEnd = allPinIDs.end();
		for ( QStringList::iterator it = allPinIDs.begin(); it != allPinIDsEnd; ++it )
		{
			if ( !ioPinIDs.contains(*it) )
				*it = "";
		}
		//END Get pin IDs
	
	
		//BEGIN Remove old stuff
		// Remove old text
		TextMap textMapCopy = m_textMap;
		const TextMap::iterator textMapEnd = textMapCopy.end();
		for ( TextMap::iterator it = textMapCopy.begin(); it != textMapEnd; ++it )
			removeDisplayText(it.key());
	
		// Remove the old pins
		deletePICComponentPins();
	
		// Remove old nodes
		NodeInfoMap nodeMapCopy = m_nodeMap;
		const NodeInfoMap::iterator nodeMapEnd = nodeMapCopy.end();
		for ( NodeInfoMap::iterator it = nodeMapCopy.begin(); it != nodeMapEnd; ++it )
		{
			if ( !ioPinIDs.contains(it.key()) )
				removeNode( it.key() );
		}
	
		removeElements();
		//END Remove old stuff
	
	
	
		//BEGIN Create new stuff
		initDIPSymbol( allPinIDs, 80 );
		initDIP(allPinIDs);
	
		PicPinMap picPinMap = microPackage->pins( PicPin::type_bidir | PicPin::type_input | PicPin::type_open );
		const PicPinMap::iterator picPinMapEnd = picPinMap.end();
		for ( PicPinMap::iterator it = picPinMap.begin(); it != picPinMapEnd; ++it )
			m_picComponentPinMap[it.key()] = new PICComponentPin( this, it.value() );
		//END Create new stuff
	
	
		removeDisplayText( "no_file" );
		addDisplayText( "picid", QRect(offsetX(), offsetY()-16, width(), 16), microInfo->id() );
	}
	else
	{
		setSize( -48, -72, 96, 144 );
		removeDisplayText( "picid" );
		addDisplayText( "no_file", sizeRect(), i18n("(No\nprogram\nloaded)") );
	}
	
	
	//BEGIN Update button positions
	int leftpos = (width()-88)/2+offsetX();
	button("run")->setOriginalRect( QRect( leftpos, height()+4+offsetY(), 20, 20 ) );
	button("pause")->setOriginalRect( QRect( leftpos+23, height()+4+offsetY(), 20, 20 ) );
	button("reset")->setOriginalRect( QRect( leftpos+46, height()+4+offsetY(), 20, 20 ) );
	button("reload")->setOriginalRect( QRect( leftpos+69, height()+4+offsetY(), 20, 20 ) );
	updateAttachedPositioning();
	//END Update button positions
}
Esempio n. 14
0
QString CNItem::nodeId( const QString &internalNodeId )
{
	NodeInfoMap::iterator it = m_nodeMap.find(internalNodeId);
	if ( it == m_nodeMap.end() ) return "";
	else return it.data().id;
}