Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <QMenu>
00022 #include <QtDebug>
00023
00024 #include "Plugin.h"
00025 #include "DashelTarget.h"
00026 #include "MainWindow.h"
00027 #include "../utils/utils.h"
00028 #include "../common/productids.h"
00029 #include "NamedValuesVectorModel.h"
00030
00031
00032
00033 #include "plugins/VariablesViewPlugin.h"
00034 #include "plugins/ThymioBootloader.h"
00035 #include "plugins/ThymioVPL/ThymioVisualProgramming.h"
00036
00037 namespace Aseba
00038 {
00041
00042 InvasivePlugin::InvasivePlugin(NodeTab* nodeTab) : nodeTab(nodeTab) { mainWindow = nodeTab->mainWindow; };
00043
00044 Dashel::Stream* InvasivePlugin::getDashelStream()
00045 {
00046 DashelTarget* target =
00047 polymorphic_downcast<DashelTarget*>(nodeTab->target);
00048 return target->dashelInterface.stream;
00049 }
00050
00051 Target* InvasivePlugin::getTarget()
00052 {
00053 return nodeTab->target;
00054 }
00055
00056 unsigned InvasivePlugin::getNodeId()
00057 {
00058 return nodeTab->id;
00059 }
00060
00061 void InvasivePlugin::displayCode(QList<QString> code, int line)
00062 {
00063 nodeTab->displayCode(code, line);
00064 }
00065
00066 void InvasivePlugin::loadNrun()
00067 {
00068 nodeTab->loadClicked();
00069 nodeTab->target->run(nodeTab->id);
00070 }
00071
00072 void InvasivePlugin::stop()
00073 {
00074 nodeTab->target->stop(nodeTab->id);
00075 }
00076
00077 bool InvasivePlugin::saveFile(bool as)
00078 {
00079 if( as )
00080 return mainWindow->saveFile();
00081
00082 return mainWindow->save();
00083 }
00084
00085 void InvasivePlugin::openFile()
00086 {
00087 mainWindow->openFile();
00088 }
00089
00090 bool InvasivePlugin::newFile()
00091 {
00092 return mainWindow->newFile();
00093 }
00094
00095 TargetVariablesModel * InvasivePlugin::getVariablesModel()
00096 {
00097 return nodeTab->vmMemoryModel;
00098 }
00099
00100 void InvasivePlugin::setVariableValues(unsigned addr, const VariablesDataVector &data)
00101 {
00102 nodeTab->setVariableValues(addr, data);
00103 }
00104
00106 template<typename C>
00107 NodeToolInterface* createInstance(NodeTab* node)
00108 {
00109 return new C(node);
00110 }
00111
00113 bool NodeToolInterfaces::containsNamed(const QString& name) const
00114 {
00115 for (const_iterator it(begin()); it != end(); ++it)
00116 if ((*it)->name == name)
00117 return true;
00118 return false;
00119 }
00120
00122 NodeToolInterface* NodeToolInterfaces::getNamed(const QString& name) const
00123 {
00124 for (const_iterator it(begin()); it != end(); ++it)
00125 if ((*it)->name == name)
00126 return *it;
00127 return 0;
00128 }
00129
00131 void NodeToolRegistrar::reg(const QString& name, const ProductIds& pid, const CreatorFunc func)
00132 {
00133 for (ProductIds::const_iterator it(pid.begin()); it != pid.end(); ++it)
00134 reg(name, *it, func);
00135 }
00136
00138 void NodeToolRegistrar::reg(const QString& name, const ProductId pid, const CreatorFunc func)
00139 {
00140 pidCreators.insert(pid, CreatorFuncNamePair(func, name));
00141 namedCreators[name] = func;
00142 }
00143
00145 void NodeToolRegistrar::update(const ProductId pid, NodeTab* node, NodeToolInterfaces& tools) const
00146 {
00147 typedef PidCreatorMap::const_iterator ConstIt;
00148 ConstIt it(pidCreators.find(pid));
00149 while (it != pidCreators.end() && it.key() == pid)
00150 {
00151 const QString& name(it.value().second);
00152 if (!tools.containsNamed(name))
00153 {
00154 const CreatorFunc& creatorFunc(it.value().first);
00155 tools.push_back(creatorFunc(node));
00156 tools.back()->name = name;
00157 }
00158 ++it;
00159 }
00160 }
00161
00163 void NodeToolRegistrar::update(const QString& name, NodeTab* node, NodeToolInterfaces& tools) const
00164 {
00165 if (tools.containsNamed(name))
00166 return;
00167 typedef NamedCreatorMap::const_iterator ConstIt;
00168 ConstIt it(namedCreators.find(name));
00169 if (it == namedCreators.end())
00170 return;
00171 const CreatorFunc& creatorFunc(it.value());
00172 tools.push_back(creatorFunc(node));
00173 tools.back()->name = name;
00174 }
00175
00177 void NodeToolRegistrar::dump(std::ostream &stream)
00178 {
00179 for (PidCreatorMap::const_iterator it = pidCreators.begin(); it != pidCreators.end(); ++it)
00180 stream << "- " << it->first << "\n";
00181 }
00182
00183 NodeToolRegistrer::NodeToolRegistrer()
00184 {
00185 ProductIds linearCameraPids;
00186 linearCameraPids << ASEBA_PID_CHALLENGE << ASEBA_PID_PLAYGROUND << ASEBA_PID_EPUCK << ASEBA_PID_SMARTROB;
00187 reg("LinearCameraViewPlugin", linearCameraPids, &createInstance<LinearCameraViewPlugin>);
00188
00189 reg("ThymioVisualProgramming", ASEBA_PID_THYMIO2, &createInstance<ThymioVisualProgramming>);
00190 }
00191
00193 };