OpenWalnut  1.5.0dev
WQtNetworkEditorProjectFileIO.h
1 //---------------------------------------------------------------------------
2 //
3 // Project: OpenWalnut ( http://www.openwalnut.org )
4 //
5 // Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
6 // For more information see http://www.openwalnut.org/copying
7 //
8 // This file is part of OpenWalnut.
9 //
10 // OpenWalnut is free software: you can redistribute it and/or modify
11 // it under the terms of the GNU Lesser General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // OpenWalnut is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public License
21 // along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
22 //
23 //---------------------------------------------------------------------------
24 
25 #ifndef WQTNETWORKEDITORPROJECTFILEIO_H
26 #define WQTNETWORKEDITORPROJECTFILEIO_H
27 
28 #include <map>
29 #include <string>
30 
31 #include <QtCore/QPoint>
32 
33 #include "core/common/WProjectFileIO.h"
34 
35 class WQtNetworkEditor;
36 class WProjectFile;
37 
38 /**
39  * IO class for writing the network editor meta data for the modules.
40  */
42 {
43 public:
44  /**
45  * Default constructor.
46  *
47  * \param ne the network editor to use to query meta info.
48  */
50 
51  /**
52  * Destructor.
53  */
55 
56  /**
57  * This method parses the specified line and interprets it. It gets called line by line by WProjectFile.
58  *
59  * \param line the current line as string
60  * \param lineNumber the current line number. Useful for error/warning/debugging output.
61  *
62  * \return true if the line could be parsed.
63  */
64  virtual bool parse( std::string line, unsigned int lineNumber );
65 
66  /**
67  * Called whenever the end of the project file has been reached. This is useful if your specific parser class wants to do some post
68  * processing after parsing line by line.
69  */
70  virtual void done();
71 
72  /**
73  * Saves the state to the specified stream.
74  *
75  * \param output the stream to print the state to.
76  */
77  virtual void save( std::ostream& output ); // NOLINT
78 
79  /**
80  * Create a clone of the IO. This is especially useful for custom parsers registered at \ref WProjectFile::registerParser. Implement this
81  * function.
82  *
83  * \param project the project file using this parser instance.
84  *
85  * \return Cloned instance.
86  */
87  virtual SPtr clone( WProjectFile* project ) const;
88 
89 protected:
90 private:
91  /**
92  * The network editor to use.
93  */
95 
96  /**
97  * Map between module ID and network coord
98  */
99  typedef std::map< unsigned int, QPoint > ModuleNetworkCoordinates;
100 
101  /**
102  * Map between module ID and network flags. We are lazy and use QPoint to store our flags.
103  */
104  typedef std::map< unsigned int, QPoint > ModuleNetworkFlags;
105 
106  /**
107  * The mapping of network coordinates for each module.
108  */
110 
111  /**
112  * Keep flags.
113  */
115 
116  double m_networkScale; //!< Keep scale.
117 
118  /**
119  * The bounding coordinates of the loaded grid: top-left
120  */
121  QPoint m_bbTL;
122 
123  /**
124  * The bounding coordinates of the loaded grid: top-left
125  */
126  QPoint m_bbBR;
127 };
128 
129 #endif // WQTNETWORKEDITORPROJECTFILEIO_H
A base class for all parts of OpenWalnut which can be serialized to a project file.
std::shared_ptr< WProjectFileIO > SPtr
Abbreviation for a shared pointer.
Class loading project files.
Definition: WProjectFile.h:50
IO class for writing the network editor meta data for the modules.
std::map< unsigned int, QPoint > ModuleNetworkFlags
Map between module ID and network flags.
QPoint m_bbBR
The bounding coordinates of the loaded grid: top-left.
virtual bool parse(std::string line, unsigned int lineNumber)
This method parses the specified line and interprets it.
QPoint m_bbTL
The bounding coordinates of the loaded grid: top-left.
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.
std::map< unsigned int, QPoint > ModuleNetworkCoordinates
Map between module ID and network coord.
ModuleNetworkFlags m_networkFlags
Keep flags.
virtual void save(std::ostream &output)
Saves the state to the specified stream.
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.