#ifndef SH_SERVER_DATA_GENERATOR_H
#define SH_SERVER_DATA_GENERATOR_H

#include "SH_plugins.h"
#include <blockview.h>


class SHServerDataGenerator: public QObject {
	Q_OBJECT
public:
	explicit SHServerDataGenerator(QObject * parent = 0);
	~SHServerDataGenerator();

	BlockView * blockView() const {return view_;}
	void setBlockView(BlockView * view) {view_ = view;}

	SHS::Object generateObject(BlockItem * b, int oid = 0);
	void generate(BlockItem * block, const QString & filename, const PropertyStorage & proj_props);

private:
	struct TracedBlock {
		PIStringList devices() const;
		BlockItem * block;
		BlockItemPin * pin;
		QList<SSPair> pathes;
		QList<BlockItem * > gateways;
	};

	void resetTraceState();
	QList<BlockItemPin * > connectedPins(BlockItemPin * pin);
	QList<TracedBlock> getNeighbourBlocks(BlockItem * block, bool input);
	QList<BlockItemPin * > getFarBlocks(BlockItem * block);
	QString gatePin(BlockItem * gw, BlockItem * b);
	QList<TracedBlock> gatherBlocks(BlockItem * block, bool input);
	void applyTracedToObject(SHS::Object & o, const TracedBlock & t, SHS::PacketFlag flag);
	QVariantMap visibleProperties(const PropertyStorage * ps);
	SHS::BlockFlags blockFlags(BlockItem * block);

	BlockView * view_;

public slots:
	
private slots:
	
signals:
	
};

#endif
