Beispiel #1
0
	UbBundleBlock::UbBundleBlock( QGraphicsItem *parent,  QString blockInstanceId )
		:UbAbstractBlock(parent)
	{
		Engine::BlockHandles blockHandles = Engine::instance().getCurrentBlocks();
		Engine::BlockHandleIterator iter = blockHandles.begin();
		for ( ; iter!= blockHandles.end(); ++iter )
		{
			if ( iter->getIdAsString() == blockInstanceId.toUtf8().constData() )
			{
				//std::cout << "found " << std::endl;
				break;
			}
		}

		if ( iter != blockHandles.end() )
		{
			m_BlockHandle	= *iter;
			m_BlockId = QString::fromUtf8( m_BlockHandle.getIdAsString().c_str() );
			setName(m_BlockId);
		} else
		{
            throw std::exception();//"Cannot find any block instance with the specified Id.");
		}
		arrangeNodes();
		setAcceptHoverEvents( true ); 
	}
		Engine::BlockHandles Engine::getCurrentBlocks()
		{
			EngineImpl::BlockInstances const& currBlocks = m_EngineImpl.getCurrentBlockInstances();
			Engine::BlockHandles blocks;
			for ( EngineImpl::BlockInstanceConstIterator it = currBlocks.begin(); it != currBlocks.end(); ++it )
			{
				blocks.push_back( ( *it )->getHandle() );
			}

			return blocks;
		}
		void Engine::getCurrentSystemState( SystemState &state )
		{
			EngineImpl::Bundles const& currBundles = m_EngineImpl.getCurrentBundles();
			Engine::BundleHandles bundles;
			for ( EngineImpl::BundleConstIterator it = currBundles.begin(); it != currBundles.end(); ++it )
				bundles.push_back( ( *it )->getHandle() );

			EngineImpl::BlockInstances &currBlocks = m_EngineImpl.getCurrentBlockInstances();
			Engine::BlockHandles blocks;
			for ( EngineImpl::BlockInstanceConstIterator it = currBlocks.begin(); it != currBlocks.end(); ++it )
				blocks.push_back( ( *it )->getHandle() );

			EngineImpl::Links &currLinks = m_EngineImpl.getCurrentLinks();
			Engine::Links links;
			for ( EngineImpl::LinkConstIterator it = currLinks.begin(); it != currLinks.end(); ++it )
				links.insert( Engine::Link( ( *it )->getInletIO().getHandle(), ( *it )->getOutletIO().getHandle() ) );

			//state.mBundles = bundles;

			// !!!!! might lead to a memory leak
			state.mVertices.clear();
			state.mEdges.clear();

			for ( BlockHandles::const_iterator bIt = blocks.begin(); bIt != blocks.end(); ++bIt )
			{
				BlockHandle const& handle = ( *bIt );
				state.mVertices.insert( std::make_pair( handle, new SystemState::Vertex( handle ) ) );
			}

			for ( Links::iterator lIt = links.begin(); lIt != links.end(); ++lIt )
			{
				InletHandle inlet = ( *lIt ).first;
				BlockHandle inletOwner = inlet.getOwningBlock();
				OutletHandle outlet = ( *lIt ).second;
				BlockHandle outletOwner = outlet.getOwningBlock();

				// both blockHandles are now for sure in the graph's vertices
				SystemState::Vertex *in = state.mVertices[ inletOwner ];
				SystemState::Vertex *out = state.mVertices[ outletOwner ];

				SystemState::Edge *edge = new SystemState::Edge( *lIt, *in, *out );
				state.mEdges.insert( edge );
			}
		};