28 #include <boost/regex.hpp>
29 #include <boost/tokenizer.hpp>
31 #include "core/common/WLogger.h"
32 #include "core/common/WStringUtils.h"
33 #include "core/kernel/WProjectFile.h"
34 #include "core/kernel/WKernel.h"
35 #include "core/kernel/WModuleContainer.h"
36 #include "core/kernel/WModule.h"
38 #include "WQtNetworkEditor.h"
39 #include "WQtNetworkItemGrid.h"
40 #include "WQtNetworkEditorProjectFileIO.h"
44 m_networkEditor( ne ),
61 p->setProject( project );
74 int* parseIntSequence( std::string seq,
int size,
int& loaded )
78 typedef boost::tokenizer<boost::char_separator< char > > tokenizer;
79 boost::char_separator< char > sep(
";" );
80 tokenizer tok( seq, sep );
83 int* values =
new int[ size ];
86 for( tokenizer::iterator it = tok.begin(); ( it != tok.end() ) && ( i < size ); ++it )
88 values[ i ] = string_utils::fromString< int >( ( *it ) );
99 static const boost::regex networkCoordRe(
"^ *QT5GUI_NETWORK:([0-9]*)=(.*)$" );
100 static const boost::regex networkFlagsRe(
"^ *QT5GUI_NETWORK_Flags:([0-9]*)=(.*)$" );
101 static const boost::regex networkScaleRe(
"^ *QT5GUI_NETWORK_Scale:(.*)$" );
104 boost::smatch matches;
105 if( boost::regex_match( line, matches, networkCoordRe ) )
110 wlog::debug(
"Project Loader [Parser]" ) <<
"Line " << lineNumber <<
": Network \"" << matches[2] <<
"\" with module ID " << matches[1];
112 unsigned int id = string_utils::fromString< unsigned int >( matches[1] );
124 else if( boost::regex_match( line, matches, networkFlagsRe ) )
129 wlog::debug(
"Project Loader [Parser]" ) <<
"Line " << lineNumber <<
": Network Flags\"" << matches[2] <<
"\" with module ID " << matches[1];
131 unsigned int id = string_utils::fromString< unsigned int >( matches[1] );
143 else if( boost::regex_match( line, matches, networkScaleRe ) )
145 wlog::debug(
"Project Loader [Parser]" ) <<
"Line " << lineNumber <<
": Network Scale " << matches[1];
146 m_networkScale = string_utils::fromString< double >( matches[1] );
166 bbTL = ( *it ).second;
167 bbBR = ( *it ).second;
172 bbTL.rx() = std::min( bbTL.x(), ( *it ).second.x() );
173 bbTL.ry() = std::min( bbTL.y(), ( *it ).second.y() );
174 bbBR.rx() = std::max( bbBR.x(), ( *it ).second.x() );
175 bbBR.ry() = std::max( bbBR.y(), ( *it ).second.y() );
197 QPoint p = ( *it ).second - bbTL;
211 QPoint p = ( *it ).second;
213 static_cast< bool >( p.y() ) );
222 output <<
"//////////////////////////////////////////////////////////////////////////////////////////////////////////////////" << std::endl <<
223 "// QtGUI Network Information" << std::endl <<
224 "//////////////////////////////////////////////////////////////////////////////////////////////////////////////////" << std::endl <<
248 QPoint p = grid->
whereIs( item );
251 output <<
"QT5GUI_NETWORK:" <<
id <<
"=" << p.x() - bb.x() <<
";" << p.y() - bb.y() << std::endl;
static WKernel * getRunningKernel()
Returns pointer to the currently running kernel.
std::shared_ptr< WModuleContainer > getRootContainer() const
Returns the root module container.
ModuleContainerType::const_iterator ModuleConstIterator
The const iterator type of the container.
std::shared_ptr< WModule > SPtr
Shared pointer to a WModule.
A base class for all parts of OpenWalnut which can be serialized to a project file.
void setApplyOrder(ApplyOrder order)
Set the order of calls to "done".
WProjectFile * getProject() const
The project using this parser.
std::shared_ptr< WProjectFileIO > SPtr
Abbreviation for a shared pointer.
Class loading project files.
std::shared_ptr< WModule > mapToModule(unsigned int id) const
Map a given project file ID to a module.
unsigned int mapFromModule(std::shared_ptr< WModule > module) const
Map a given module to project file ID.
virtual bool parse(std::string line, unsigned int lineNumber)
This method parses the specified line and interprets it.
ModuleNetworkCoordinates m_networkCoords
The mapping of network coordinates for each module.
WQtNetworkEditorProjectFileIO(WQtNetworkEditor *ne)
Default constructor.
virtual SPtr clone(WProjectFile *project) const
Create a clone of the IO.
double m_networkScale
Keep scale.
ModuleNetworkFlags m_networkFlags
Keep flags.
virtual void save(std::ostream &output)
Saves the state to the specified stream.
virtual ~WQtNetworkEditorProjectFileIO()
Destructor.
virtual void done()
Called whenever the end of the project file has been reached.
WQtNetworkEditor * m_networkEditor
The network editor to use.
Container widget to hold the WQtNetworkScene.
WQtNetworkItem * findItemByModule(std::shared_ptr< WModule > module)
Simple search the WQtNetworkItem that belongs to the WModule.
WQtNetworkEditorView * getView()
Get the view handling the scene.
WQtNetworkSceneLayout * getLayout()
Get the layouter of the scene.
Implement a virtual grid for placing QGraphicsItems.
virtual QPoint whereIs(QGraphicsItem *item)
Find the position of the specified item.
virtual bool isInGrid(QGraphicsItem *item)
Check whether the item is managed in the grid.
virtual QRect getGridBoundingRect() const
Returns the boundaries in grid coordinates.
int getFirstFreeColumn() const
Return the index of the first empty column.
This class represents a WModule as QGraphicsItem and contains a reference to its in- and outports.
bool wasLayedOut() const
Checks whether the item was layed out earlier.
bool wasManuallyPlaced() const
Item was placed by hand.
void setModuleDefaultFlags(WModule::SPtr module, bool layedOut, bool manuallyLayedOut)
Set a default flag combination for the given module.
WQtNetworkItemGrid * getGrid() const
Get the grid used for the layout.
void setModuleDefaultPosition(WModule::SPtr module, QPoint coord)
Set a default position for a given module.
std::shared_ptr< WSharedObjectTicketRead< ModuleContainerType > > ReadTicket
Type for read tickets.
std::string toString(const T &value)
Convert a given value to a string.
WStreamedLogger debug(const std::string &source)
Logging a debug message.