Exemplo n.º 1
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);
}
Exemplo n.º 2
0
void CNItem::setDisplayText( const QString &id, const QString &display )
{
	TextMap::iterator it = m_textMap.find(id);
	if ( it == m_textMap.end() )
	{
		kError() << "CNItem::setDisplayText: Could not find text with id \""<<id<<"\""<<endl;
		return;
	}
	it.data()->setText(display);
	updateAttachedPositioning();
}
Exemplo n.º 3
0
void CNItem::removeDisplayText( const QString &id )
{
	TextMap::iterator it = m_textMap.find(id);
	if ( it == m_textMap.end() )
	{
// 		kError() << "CNItem::removeDisplayText: Could not find text with id \""<<id<<"\""<<endl;
		return;
	}
	it.data()->updateConnectorPoints(false);
	delete it.data();
	m_textMap.remove(it);
}
Exemplo n.º 4
0
void CNItem::removeItem()
{
	if (b_deleted)
		return;
	
	const TextMap::iterator textMapEnd = m_textMap.end();
	for ( TextMap::iterator it = m_textMap.begin(); it != textMapEnd; ++it )
		it.data()->setCanvas(0l);
	
	Item::removeItem();
	updateConnectorPoints(false);
}
Exemplo n.º 5
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() );
}
Exemplo n.º 6
0
CNItem::~CNItem()
{
	const TextMap::iterator textMapEnd = m_textMap.end();
	for ( TextMap::iterator it = m_textMap.begin(); it != textMapEnd; ++it )
	{
		if (it.data()) it.data()->setCanvas(0l);

		delete (Text*)it.data();
	}
	m_textMap.clear();
	
	updateConnectorPoints(false);
}
Exemplo n.º 7
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);
	}
}
Exemplo 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 );
}
Exemplo n.º 9
0
Text* CNItem::addDisplayText( const QString &id, const QRect & pos, const QString &display, bool internal, int flags )
{
	Text *text = 0l;
	TextMap::iterator it = m_textMap.find(id);
	if ( it != m_textMap.end() )
	{
// 		kWarning() << "CNItem::addDisplayText: removing old text"<<endl;
		delete it.data();
		m_textMap.remove(it);
	}
	
	text = new Text( "", this, pos, canvas(), flags );
	text->setZ( z()+(internal?0.1:-0.1) );
	
	m_textMap[id] = text;
	
	// Calculate the correct size
	setDisplayText( id, display );
	text->show();
	return text;
}
Exemplo n.º 10
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
}
Exemplo n.º 11
0
void CNItem::updateConnectorPoints( bool add )
{
	if ( b_deleted || !isVisible() )
		add = false;

	if ( b_pointsAdded == add )
		return;

	b_pointsAdded = add;

	Cells *cells = p_icnDocument->cells();
	if (!cells)
		return;
	
	// Get translation matrix
	// Hackish...
	QWMatrix m;
	if ( Component *c = dynamic_cast<Component*>(this) )
		m = c->transMatrix( c->angleDegrees(), c->flipped(), int(x()), int(y()), false );
	
	// Convention used here: _UM = unmapped by both matrix and cell reference, _M = mapped

	const QPoint start_UM = QPoint( int(x()+offsetX())-8, int(y()+offsetY())-8 );
	const QPoint end_UM = start_UM + QPoint( width()+2*8, height()+2*8 );
	
	const QPoint start_M = roundDown( m.map(start_UM), 8 );
	const QPoint end_M = roundDown( m.map(end_UM), 8 );
	
	
	int sx_M = start_M.x();
	int ex_M = end_M.x();
	
	int sy_M = start_M.y();
	int ey_M = end_M.y();
	
	
	// Normalise start and end points
	if ( sx_M > ex_M )
	{
		const int temp = sx_M;
		sx_M = ex_M;
		ex_M = temp;
	}
	if ( sy_M > ey_M )
	{
		const int temp = sy_M;
		sy_M = ey_M;
		ey_M = temp;
	}
	
	ex_M++;
	ey_M++;
	
	const int mult = add ? 1 : -1;
	
	for ( int x = sx_M; x < ex_M; x++ )
	{
		for ( int y = sy_M; y < ey_M; y++ )
		{
			if ( cells->haveCell( x, y ) )
			{
				if ( x != sx_M && y != sy_M && x != (ex_M-1) && y != (ey_M-1) )
				{
					cells->cell( x, y ).CIpenalty += mult*ICNDocument::hs_item;
				}
				else 
				{
//					(*cells)[x][y].CIpenalty += mult*ICNDocument::hs_item/2;
					cells->cell( x, y ).CIpenalty += mult*ICNDocument::hs_connector*5;
				}
			}
		}
	}
	
#if 0
	// And subtract the positions of the node on the border
	NodeInfoMap::iterator end = m_nodeMap.end();
	for ( NodeInfoMap::iterator it = m_nodeMap.begin(); it != end; ++it )
	{
		const int x = (int)((it->second.node->x()-4)/cellSize);
		const int y = (int)((it->second.node->y()-4)/cellSize);
		if ( p_icnDocument->isValidCellReference(x,y) ) {
			(*cells)[x][y].CIpenalty -= mult*ICNDocument::hs_connector*5;
		}
	}
#endif
	
	const TextMap::iterator textMapEnd = m_textMap.end();
	for ( TextMap::iterator it = m_textMap.begin(); it != textMapEnd; ++it )
	{
		it.data()->updateConnectorPoints(add);
	}
	const WidgetMap::iterator widgetMapEnd = m_widgetMap.end();
	for ( WidgetMap::iterator it = m_widgetMap.begin(); it != widgetMapEnd; ++it )
	{
		it.data()->updateConnectorPoints(add);
	}
}