Plugin.h
Go to the documentation of this file.
00001 /*
00002         Aseba - an event-based framework for distributed robot control
00003         Copyright (C) 2007--2012:
00004                 Stephane Magnenat <stephane at magnenat dot net>
00005                 (http://stephane.magnenat.net)
00006                 and other contributors, see authors.txt for details
00007         
00008         This program is free software: you can redistribute it and/or modify
00009         it under the terms of the GNU Lesser General Public License as published
00010         by the Free Software Foundation, version 3 of the License.
00011         
00012         This program is distributed in the hope that it will be useful,
00013         but WITHOUT ANY WARRANTY; without even the implied warranty of
00014         MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015         GNU Lesser General Public License for more details.
00016         
00017         You should have received a copy of the GNU Lesser General Public License
00018         along with this program. If not, see <http://www.gnu.org/licenses/>.
00019 */
00020 
00021 #ifndef PLUGIN_H
00022 #define PLUGIN_H
00023 
00024 #include <QLabel>
00025 #include <QDomDocument>
00026 #include <QMultiMap>
00027 #include <dashel/dashel.h>
00028 #include <stdexcept>
00029 #include <iostream>
00030 #include <set>
00031 #include "../compiler/compiler.h"
00032 
00033 class QMenu;
00034 
00035 namespace Dashel
00036 {
00037         class Stream;
00038 }
00039 
00040 namespace Aseba
00041 {
00044         
00045         class NodeTab;
00046         class Target;
00047         class TargetVariablesModel;
00048         class MainWindow;
00049         
00051         struct InvasivePlugin
00052         {
00053                 NodeTab* nodeTab;
00054                 MainWindow *mainWindow;
00055                 
00056                 InvasivePlugin(NodeTab* nodeTab);
00057                 virtual ~InvasivePlugin() {}
00058                 
00059                 Dashel::Stream* getDashelStream();
00060                 Target * getTarget();
00061                 unsigned getNodeId();
00062                 void displayCode(QList<QString> code, int line);
00063                 void loadNrun();
00064                 void stop();
00065                 TargetVariablesModel * getVariablesModel();
00066                 void setVariableValues(unsigned, const VariablesDataVector &);
00067                 bool saveFile(bool as=false);
00068                 void openFile();
00069                 bool newFile();
00070         };
00071         
00073         struct NodeToolInterface
00074         {
00075                 typedef QPair<QString, QDomDocument> SavedContent;
00076                 QString name; 
00077                 
00078                 virtual ~NodeToolInterface() {}
00079                 
00080                 virtual void loadFromDom(const QDomDocument& content, bool fromFile) {};
00081                 virtual QDomDocument saveToDom() const { return QDomDocument(); } 
00082                 SavedContent getSaved() const { return SavedContent(name, saveToDom()); }
00083                 
00084                 virtual QWidget* createMenuEntry() = 0;
00085                 virtual void closeAsSoonAsPossible() = 0;
00087                 virtual bool surviveTabDestruction() const { return false; }
00088         };
00089         
00091         struct NodeToolInterfaces: std::vector<NodeToolInterface*>
00092         {
00093                 bool containsNamed(const QString& name) const;
00094                 NodeToolInterface* getNamed(const QString& name) const;
00095         };
00096         
00098         struct NodeToolRegistrar
00099         {
00101                 typedef int ProductId;
00103                 typedef QList<ProductId> ProductIds;
00105                 typedef NodeToolInterface* (*CreatorFunc)(NodeTab* node);
00106                 
00107                 void reg(const QString& name, const ProductIds& pid, const CreatorFunc func);
00108                 
00109                 void reg(const QString& name, const ProductId pid, const CreatorFunc func);
00110                 
00111                 void update(const ProductId pid, NodeTab* node, NodeToolInterfaces& tools) const;
00112                 
00113                 void update(const QString& name, NodeTab* node, NodeToolInterfaces& tools) const;
00114                 
00115                 void dump(std::ostream &stream);
00116                 
00117         protected:
00118                 typedef QPair<CreatorFunc, QString> CreatorFuncNamePair;
00119                 typedef QMultiMap<ProductId, CreatorFuncNamePair> PidCreatorMap;
00120                 PidCreatorMap pidCreators;
00121                 typedef QMap<QString, CreatorFunc> NamedCreatorMap;
00122                 NamedCreatorMap namedCreators;
00123         };
00124         
00125         struct NodeToolRegistrer: NodeToolRegistrar
00126         {
00127                 NodeToolRegistrer();
00128         };
00129         
00130         static NodeToolRegistrer nodeToolRegistrer;
00131 
00133 }; // Aseba
00134 
00135 #endif


aseba
Author(s): Stéphane Magnenat
autogenerated on Sun Oct 5 2014 23:46:39