##// END OF EJS Templates
Some cleaning.
jeandet -
r10:536aeec6c7cb default
parent child
Show More
@@ -1,1 +1,1
1 b05d3dada0406dd7c1700d5d53719a901d214281 src/SocExplorerEngine/PeripheralWidget
1 e3a98a04d9ec8685bf222f8d687a614a71927549 src/SocExplorerEngine/PeripheralWidget
@@ -1,224 +1,224
1 1 /*------------------------------------------------------------------------------
2 2 -- This file is a part of the SocExplorer Software
3 3 -- Copyright (C) 2012, Laboratory of Plasmas Physic - CNRS
4 4 --
5 5 -- This program is free software; you can redistribute it and/or modify
6 6 -- it under the terms of the GNU General Public License as published by
7 7 -- the Free Software Foundation; either version 2 of the License, or
8 8 -- (at your option) any later version.
9 9 --
10 10 -- This program is distributed in the hope that it will be useful,
11 11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 13 -- GNU General Public License for more details.
14 14 --
15 15 -- You should have received a copy of the GNU General Public License
16 16 -- along with this program; if not, write to the Free Software
17 17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 18 -------------------------------------------------------------------------------*/
19 19 /*-- Author : Alexis Jeandet
20 20 -- Mail : alexis.jeandet@lpp.polytechnique.fr
21 21 ----------------------------------------------------------------------------*/
22 22 #include "socexplorerengine.h"
23 23 #include <proxy/socexplorerproxy.h>
24 24
25 25 SocExplorerEngine* SocExplorerEngine::_self = NULL;
26 26 socExplorerXmlModel* SocExplorerEngine::p_xmlmodel=NULL;
27 27 QMainWindow* SocExplorerEngine::mainWindow=NULL;
28 28 QList<SOCModel*>* SocExplorerEngine::SOCs=NULL;
29 29 int SocExplorerEngine::loglvl=1;
30 30
31 31 SocExplorerEngine::SocExplorerEngine(QObject *parent) :
32 32 QObject(parent)
33 33 {
34 34 if(SOCs==NULL)
35 35 {
36 36 SOCs = new QList<SOCModel*>;
37 37 }
38 38
39 39 }
40 40
41 41
42 42 void SocExplorerEngine::init()
43 43 {
44 44 QDir dir;
45 45 if(!_self)
46 46 {
47 47 _self= new SocExplorerEngine;
48 48 }
49 49 if(!dir.exists(configFolder()))
50 50 dir.mkdir(configFolder());
51 51 p_xmlmodel = new socExplorerXmlModel(_self);
52 52 p_xmlmodel->updateSOClist();
53 53 }
54 54
55 55 QString SocExplorerEngine::configFolder()
56 56 {
57 57 return QString(SOCEXPLORER_CONFIG_PATH);
58 58 }
59 59
60 60 SOCModel *SocExplorerEngine::plugin2Soc(socexplorerplugin *plugin)
61 61 {
62 62 if(!_self)
63 63 init();
64 64 if(plugin)
65 65 {
66 66 while (plugin->parent!=NULL) {
67 67 plugin = plugin->parent;
68 68 }
69 69 for(int i=0;i<SOCs->count();i++)
70 70 {
71 71 if(SOCs->at(i)->isRootDev(plugin))
72 72 return SOCs->at(i);
73 73 }
74 74 //no soc found so create a new one
75 75 SOCModel* soc=new SOCModel(plugin);
76 76 SOCs->append(soc);
77 77 return soc;
78 78 }
79 79 return NULL;
80 80 }
81 81
82 82
83 83 int SocExplorerEngine::addEnumDevice(socexplorerplugin* rootPlugin,int VID, int PID, qint32 baseAddress, const QString &name)
84 84 {
85 85 if(!_self)
86 86 init();
87 87 SOCModel* soc = plugin2Soc(rootPlugin);
88 88 if(soc && !soc->enumDeviceExists(baseAddress))
89 89 {
90 90 emit _self->enumDeviceAdded(soc->addEnumDevice(VID,PID,baseAddress,name));
91 91 return 1;
92 92 }
93 93 return 0;
94 94 }
95 95
96 96 QList<SOCModel *> *SocExplorerEngine::getSOCs()
97 97 {
98 98 if(!_self)
99 99 init();
100 100 return SOCs;
101 101 }
102 102
103 103 qint32 SocExplorerEngine::getEnumDeviceBaseAddress(const QString& rootPlugin,int VID, int PID, int count)
104 104 {
105 105 socexplorerplugin* plugin = socexplorerproxy::findPlugin(rootPlugin);
106 106 if(plugin==NULL)return -1;
107 107 SOCModel* soc = plugin2Soc(plugin);
108 108 if(soc==NULL)
109 109 return -1;
110 110 return soc->getEnumDeviceBaseAddress(VID,PID,count);
111 111 }
112 112
113 113 qint32 SocExplorerEngine::getEnumDeviceBaseAddress(socexplorerplugin *plugin, int VID, int PID, int count)
114 114 {
115 115 if(plugin==NULL)return -1;
116 116 SOCModel* soc = plugin2Soc(plugin);
117 117 if(soc==NULL)
118 118 return -1;
119 119 return soc->getEnumDeviceBaseAddress(VID,PID,count);
120 120 }
121 121
122 122 int SocExplorerEngine::addEnumDevice(const QString &rootPlugin, int VID, int PID, qint32 baseAddress, const QString &name)
123 123 {
124 124 socexplorerplugin* plugin = socexplorerproxy::findPlugin(rootPlugin);
125 125 if(plugin==NULL)return -1;
126 126 SOCModel* soc = plugin2Soc(plugin);
127 127 if(soc==NULL)
128 128 return -1;
129 129 soc->addEnumDevice(VID,PID,baseAddress,name);
130 130 return 1;
131 131 }
132 132
133 133
134 134 QString SocExplorerEngine::getDevName(int VID, int PID)
135 135 {
136 136 QList<QDomNodeList> list=p_xmlmodel->getAllNodes("peripheral");
137 137 for(int i=0;i<list.count();i++)
138 138 {
139 139 QDomNodeList nodes=list.at(i);
140 140 for(int l=0;l<nodes.count();l++)
141 141 {
142 142 QDomElement node=nodes.at(l).toElement();
143 143 int nodeVID=node.attribute("vid","0").toInt();
144 144 int nodePID=node.attribute("pid","0").toInt();
145 145 if((nodeVID==VID)&&(nodePID==PID))
146 146 {
147 147 return node.attribute("name","Unknow device");
148 148 }
149 149 }
150 150 }
151 151 return QString("Unknow device");
152 152 }
153 153
154 154 QString SocExplorerEngine::SocExplorerVersion(){return QString(SOCEXPLORER_VERSION);}
155 155
156 156 QString SocExplorerEngine::SocExplorerChangeset(){return QString(SOCEXPLORER_CHAGESET).split(" ").at(0);}
157 157
158 158 QString SocExplorerEngine::SocExplorerBranch(){return QString(SOCEXPLORER_BRANCH);}
159 159
160 160 socExplorerXmlModel *SocExplorerEngine::xmlModel()
161 161 {
162 162 if(!_self)
163 163 init();
164 164 return p_xmlmodel;
165 165 }
166 166
167 167 void SocExplorerEngine::setMainWindow(QMainWindow *Mainwindow)
168 168 {
169 169 if(!_self)
170 170 init();
171 171 mainWindow=Mainwindow;
172 172 }
173 173
174 174 QProgressBar *SocExplorerEngine::getProgressBar(const QString& format, int max)
175 175 {
176 176 if(!_self)
177 177 init();
178 178 QProgressBar* progressBar;
179 179 if(mainWindow!=NULL)
180 180 {
181 181 progressBar = new QProgressBar(mainWindow);
182 182 mainWindow->statusBar()->addWidget(progressBar);
183 183 }
184 184 else
185 185 {
186 186 progressBar = new QProgressBar();
187 187 }
188 188 progressBar->setMaximum(max);
189 189 progressBar->setFormat(format);
190 190 return progressBar;
191 191 }
192 192
193 193 void SocExplorerEngine::deleteProgressBar(QProgressBar *progressBar)
194 194 {
195 195 if(mainWindow!=NULL)
196 196 {
197 197 mainWindow->statusBar()->removeWidget(progressBar);
198 198 }
199 199 delete progressBar;
200 200 }
201 201
202 202 void SocExplorerEngine::addSOC(socexplorerplugin *rootPlugin)
203 203 {
204 204 plugin2Soc(rootPlugin);
205 205 }
206 206
207 207 void SocExplorerEngine::removeSOC(socexplorerplugin *rootPlugin)
208 208 {
209 209 SOCModel* soc=plugin2Soc(rootPlugin);
210 210 SOCs->removeAll(soc);
211 211 delete soc;
212 212 }
213 213
214 214 void SocExplorerEngine::message(socexplorerplugin *sender, const QString &message, int debugLevel)
215 215 {
216 216 // TODO add multi output message manager IE also log in files
217 217 if(!_self)
218 218 init();
219 219 if(loglvl>=debugLevel)
220 qDebug()<< QTime::currentTime().toString()+" " + sender->instanceName+":"+message;
220 qDebug()<< QTime::currentTime().toString()+" " + sender->instanceName()+":"+message;
221 221 }
222 222
223 223
224 224
@@ -1,141 +1,142
1 1 /*------------------------------------------------------------------------------
2 2 -- This file is a part of the SocExplorer Software
3 3 -- Copyright (C) 2011, Laboratory of Plasmas Physic - CNRS
4 4 --
5 5 -- This program is free software; you can redistribute it and/or modify
6 6 -- it under the terms of the GNU General Public License as published by
7 7 -- the Free Software Foundation; either version 2 of the License, or
8 8 -- (at your option) any later version.
9 9 --
10 10 -- This program is distributed in the hope that it will be useful,
11 11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 13 -- GNU General Public License for more details.
14 14 --
15 15 -- You should have received a copy of the GNU General Public License
16 16 -- along with this program; if not, write to the Free Software
17 17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 18 -------------------------------------------------------------------------------*/
19 19 /*-- Author : Alexis Jeandet
20 20 -- Mail : alexis.jeandet@lpp.polytechnique.fr
21 21 ----------------------------------------------------------------------------*/
22 22 #include "pluginmanagerWDGT.h"
23 23 #include "pluginloader.h"
24 24 #include <QFileDialog>
25 25 #include <unistd.h>
26 26 #include <qsvgicon.h>
27 27 #include <socexplorerengine.h>
28 28
29 29 #define mkbutton(button,text,image)button = new QPushButton();\
30 30 button->setIcon(QSvgIcon(image));\
31 31 button->setIconSize(QSize(16,16));\
32 32 button->setToolTip(text)
33 33
34 34
35 35
36 36 pluginmanagerWDGT::pluginmanagerWDGT(QWidget *parent) :
37 37 QSplitter(parent)
38 38 {
39 39 this->setWindowTitle("Plugin Manager");
40 40 this->setOrientation(Qt::Vertical);
41 41 this->pluginListWidgetContainer = new QWidget();
42 42 this->mainlayoutSpliter = new QSplitter;
43 43 this->pluginListLayout = new QVBoxLayout();
44 44 this->mainlayoutSpliter->setOrientation(Qt::Vertical);
45 45 this->treeview = new plugintree();
46 46 this->pluginTable = new PluginList;
47 47 this->ButtonsLayout = new QHBoxLayout();
48 48 this->ButtonsLayout->addStretch();
49 49 this->pluginListLayout->addLayout(this->ButtonsLayout);
50 50 this->addWidget(this->treeview);
51 51 this->pluginListWidgetContainer->setLayout(this->pluginListLayout);
52 52 this->addWidget(this->pluginListWidgetContainer);
53 53 this->pluginListLayout->addWidget(this->pluginTable);
54 54 this->pluginInfos = new pluginInfosWdgt;
55 55
56 56 mkbutton(this->addPluginBt,tr("add plugin"),":/images/open.svg");
57 57 mkbutton(this->removePluginBt,tr("remove plugin(s)"),":/images/trash.svg");
58 58 mkbutton(this->refreshPluginListBt,tr("Refresh Plugin(s) list"),":/images/refresh.svg");
59 59
60 60 this->ButtonsLayout->addWidget(this->addPluginBt);
61 61 this->ButtonsLayout->addWidget(this->refreshPluginListBt);
62 62 this->ButtonsLayout->addWidget(this->removePluginBt);
63 63
64 64 this->addWidget(this->pluginInfos);
65 65
66 66 connect(this->treeview,SIGNAL(geteplugintree()),this,SIGNAL(geteplugintree()));
67 67 connect(this,SIGNAL(treeChanged(QList<socexplorerplugin*>)),this->treeview,SLOT(treeChanged(QList<socexplorerplugin*>)));
68 68 connect(this->pluginTable,SIGNAL(currentRowChanged(int)),this,SLOT(libselected(int)));
69 69 connect(this->pluginTable,SIGNAL(itemSelectionChanged(QStringList)),this->pluginInfos,SLOT(updateInfos(QStringList)));
70 70 connect(this->addPluginBt,SIGNAL(clicked()),this,SLOT(addPlugin()));
71 71 connect(this->removePluginBt,SIGNAL(clicked()),this,SLOT(removePlugin()));
72 72 connect(this->pluginTable,SIGNAL(itemDoubleClicked(QListWidgetItem*)),this,SLOT(loadplugin(QListWidgetItem*)));
73 73 connect(this->refreshPluginListBt,SIGNAL(clicked()),this->pluginTable,SLOT(refreshPluginList()));
74 74 connect(this->treeview,SIGNAL(loadSysDriver(QString)),this,SIGNAL(loadSysDrviver(QString)));
75 75 connect(this->treeview,SIGNAL(loadSysDriverToParent(QString,QString)),this,SIGNAL(loadSysDriverToParent(QString,QString)));
76 76 connect(this->treeview,SIGNAL(changeSysDriverInstName(QString,QString)),this,SIGNAL(changeSysDriverInstName(QString,QString)));
77 77 connect(this->treeview,SIGNAL(closeSysDriver(QString)),this,SIGNAL(closeSysDriver(QString)));
78 connect(this->treeview,SIGNAL(pluginselected(QString)),this,SIGNAL(pluginselected(QString)));
78 79 this->rootLoadable = false;
79 80 this->childLoadable = false;
80 81 this->pluginTable->refreshPluginList();
81 82 this->pluginTable->refreshPluginList();
82 83 }
83 84
84 85
85 86 void pluginmanagerWDGT::setRootLoadable(bool flag)
86 87 {
87 88 this->rootLoadable = flag;
88 89 }
89 90
90 91
91 92 void pluginmanagerWDGT::setChildLoadable(bool flag)
92 93 {
93 94 this->childLoadable = flag;
94 95 }
95 96
96 97
97 98
98 99
99 100 void pluginmanagerWDGT::addPlugin()
100 101 {
101 102 QString fileName = QFileDialog::getOpenFileName(this,tr("Open Plugin"), QDir::homePath(), tr("Plugin Files Files (*.dll *.so *.so.*)"));
102 103 if(pluginloader::checklibrary(fileName))
103 104 {
104 105 QFile::copy(fileName,QString(SocExplorerEngine::pluginFolder())+"/"+ fileName.section('/',-1));
105 106 }
106 107 this->pluginTable->refreshPluginList();
107 108 }
108 109
109 110
110 111 void pluginmanagerWDGT::removePlugin()
111 112 {
112 113 for(int i=0;i<this->pluginTable->selectedItems().count();i++)
113 114 {
114 115 QListWidgetItem* item = this->pluginTable->selectedItems().at(i);
115 116 if(item!=NULL)
116 117 {
117 118 QFile::remove(QString(SocExplorerEngine::pluginFolder())+"/"+item->text());
118 119 }
119 120 }
120 121 this->pluginTable->refreshPluginList();
121 122 }
122 123
123 124
124 125
125 126 void pluginmanagerWDGT::loadplugin()
126 127 {
127 128 for(int i=0;i<this->pluginTable->selectedItems().count();i++)
128 129 {
129 130 QListWidgetItem* item = this->pluginTable->selectedItems().at(i);
130 131 if(item!=NULL)
131 132 {
132 133 QString plugin = QString(SocExplorerEngine::pluginFolder())+"/"+item->text();
133 134 emit this->loadSysDrviver(plugin);
134 135 }
135 136 }
136 137 this->pluginTable->refreshPluginList();
137 138 }
138 139
139 140
140 141
141 142
@@ -1,92 +1,94
1 1 /*------------------------------------------------------------------------------
2 2 -- This file is a part of the SocExplorer Software
3 3 -- Copyright (C) 2011, Laboratory of Plasmas Physic - CNRS
4 4 --
5 5 -- This program is free software; you can redistribute it and/or modify
6 6 -- it under the terms of the GNU General Public License as published by
7 7 -- the Free Software Foundation; either version 2 of the License, or
8 8 -- (at your option) any later version.
9 9 --
10 10 -- This program is distributed in the hope that it will be useful,
11 11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 13 -- GNU General Public License for more details.
14 14 --
15 15 -- You should have received a copy of the GNU General Public License
16 16 -- along with this program; if not, write to the Free Software
17 17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 18 -------------------------------------------------------------------------------*/
19 19 /*-- Author : Alexis Jeandet
20 20 -- Mail : alexis.jeandet@lpp.polytechnique.fr
21 21 ----------------------------------------------------------------------------*/
22 22 #ifndef PLUGINMANAGERWDGT_H
23 23 #define PLUGINMANAGERWDGT_H
24 24
25 25 #include <QApplication>
26 26 #include <QWidget>
27 27 #include <QDockWidget>
28 28 #include <QVBoxLayout>
29 29 #include <QHBoxLayout>
30 30 #include <QTableWidget>
31 31 #include <QDir>
32 32 #include <QStringList>
33 33 #include <QFileInfoList>
34 34 #include <QFileInfo>
35 35 #include <QTextEdit>
36 36 #include <QPushButton>
37 37 #include <QSplitter>
38 38 #include "plugininfoswdgt.h"
39 39 #include "pluginlist.h"
40 40 #include <socexplorerplugin.h>
41 41 #include <QList>
42 42 #include "plugintree.h"
43 43
44 44 #if defined(SOCEXPLORER_SDK_BUILD)
45 45 # define SOCEXPLORER_SDK_EXPORT Q_DECL_EXPORT
46 46 #else
47 47 # define SOCEXPLORER_SDK_EXPORT Q_DECL_IMPORT
48 48 #endif
49 49
50 50 class pluginmanagerWDGT : public QSplitter
51 51 {
52 52 Q_OBJECT
53 53 public:
54 54 SOCEXPLORER_SDK_EXPORT explicit pluginmanagerWDGT(QWidget *parent = 0);
55 55 SOCEXPLORER_SDK_EXPORT void setRootLoadable(bool flag);
56 56 SOCEXPLORER_SDK_EXPORT void setChildLoadable(bool flag);
57 57
58 58 signals:
59 59 void updatepluginInfo(const QString libname);
60 60 void loadSysDrviver(const QString name);
61 61 void loadSysDriverToParent(const QString name, const QString instanceName);
62 62 void geteplugintree(void);
63 63 void treeChanged(const QList<socexplorerplugin*>& drivers);
64 64 void changeSysDriverInstName(const QString newinstanceName,const QString previnstanceName);
65 65 void closeSysDriver(const QString instanceName);
66 void pluginselected(const QString& instanceName);
67
66 68 public slots:
67 69 //void libselected(int row);
68 70 void addPlugin();
69 71 void removePlugin();
70 72 void loadplugin();
71 73 //void loadplugin(QListWidgetItem*);
72 74
73 75 private:
74 76
75 77 bool rootLoadable;
76 78 bool childLoadable;
77 79 QWidget* pluginListWidgetContainer;
78 80 QVBoxLayout* pluginListLayout;
79 81 QHBoxLayout* ButtonsLayout;
80 82 QSplitter* mainlayoutSpliter;
81 83 PluginList* pluginTable;
82 84 pluginInfosWdgt* pluginInfos;
83 85 plugintree* treeview;
84 86 QPushButton* addPluginBt;
85 87 QPushButton* removePluginBt;
86 88 QPushButton* loadPluginBt;
87 89 QPushButton* refreshPluginListBt;
88 90
89 91
90 92 };
91 93
92 94 #endif // PLUGINMANAGERWDGT_H
@@ -1,210 +1,219
1 1 #include "plugintree.h"
2 2 #include "pluginloader.h"
3 3 #include <QApplication>
4 4 #include "qsvgicon.h"
5 5 #include <QHeaderView>
6 6 #include <QString>
7 7
8 8 plugintree::plugintree(QWidget *parent) :
9 9 QTreeWidget(parent)
10 10 {
11 11 this->editingItem=false;
12 12 this->editeditemprev=new QString;
13 13 this->setAcceptDrops(true);
14 14 this->setDragDropMode(QAbstractItemView::DropOnly);
15 15 connect(this,SIGNAL(itemChanged(QTreeWidgetItem*,int)),this,SLOT(pluginselectedslt(QTreeWidgetItem*,int)));
16 connect(this,SIGNAL(itemSelectionChanged()),this,SLOT(itemSelectionChangedslt()));
16 17 this->setHeaderLabels(QStringList()<<"Loaded plugins");
17 18 emit this->geteplugintree();
18 19 }
19 20
20 21
21 22 void plugintree::pluginselectedslt(QTreeWidgetItem *item, int column)
22 23 {
23 24 Q_UNUSED(column)
24 25 emit this->pluginselected(item->text(0));
25 26 }
26 27
28 void plugintree::itemSelectionChangedslt()
29 {
30 if(this->selectedItems().count()==1)
31 {
32 emit this->pluginselected(this->selectedItems().first()->text(0));
33 }
34 }
35
27 36 void plugintree::treeChanged(const QList<socexplorerplugin*>& drivers)
28 37 {
29 38 this->clear();
30 39 for(int i=0;i<drivers.count();i++)
31 40 {
32 41 QTreeWidgetItem* currentItem=new QTreeWidgetItem;
33 42 currentItem->setIcon(0,QSvgIcon(":/images/server.svg"));
34 currentItem->setText(0,drivers.at(i)->instanceName);
43 currentItem->setText(0,drivers.at(i)->instanceName());
35 44 this->addTopLevelItem(currentItem);
36 45 if(drivers.at(i)->childs.count()!=0)
37 46 {
38 47 this->addplugin(drivers.at(i),currentItem);
39 48 }
40 49 currentItem->setExpanded(true);
41 50 }
42 51 }
43 52
44 53 void plugintree::addplugin(socexplorerplugin *driver, QTreeWidgetItem *item)
45 54 {
46 55
47 56 for(int i=0;i<driver->childs.count();i++)
48 57 {
49 58 QTreeWidgetItem* currentItem=new QTreeWidgetItem;
50 59 currentItem->setIcon(0,QSvgIcon(":/images/server.svg"));
51 currentItem->setText(0,driver->childs.at(i)->instanceName);
60 currentItem->setText(0,driver->childs.at(i)->instanceName());
52 61 item->addChild(currentItem);
53 62 if(driver->childs.at(i)->childs.count()!=0)
54 63 {
55 64 this->addplugin(driver->childs.at(i),currentItem);
56 65 }
57 66 currentItem->setExpanded(true);
58 67 }
59 68
60 69 }
61 70
62 71
63 72
64 73
65 74 void plugintree::dragEnterEvent(QDragEnterEvent *event)
66 75 {
67 76 if (event->mimeData()->hasFormat("socexplorer/pluginName"))
68 77 {
69 78
70 79 if(pluginloader::isvalid(event->mimeData()->text()))
71 80 {
72 81 event->acceptProposedAction();
73 82 }else
74 83 {
75 84 event->ignore();
76 85 }
77 86
78 87 } else
79 88 {
80 89 event->ignore();
81 90 }
82 91 }
83 92
84 93 void plugintree::dragMoveEvent(QDragMoveEvent *event)
85 94 {
86 95 if (event->mimeData()->hasFormat("socexplorer/pluginName"))
87 96 {
88 97
89 98 if(pluginloader::isvalid(event->mimeData()->text()))
90 99 {
91 100 this->clearSelection();
92 101 if(this->itemAt(event->pos())!=NULL)
93 102 {
94 103 this->itemAt(event->pos())->setSelected(true);
95 104 event->acceptProposedAction();
96 105 }
97 106 else
98 107 if(pluginloader::libcanberoot(event->mimeData()->text()))
99 108 {
100 109 event->acceptProposedAction();
101 110 }
102 111 else
103 112 {
104 113 event->ignore();
105 114 }
106 115 }else
107 116 {
108 117 event->ignore();
109 118 }
110 119
111 120 } else
112 121 {
113 122 event->ignore();
114 123 }
115 124 }
116 125
117 126
118 127 void plugintree::mouseDoubleClickEvent(QMouseEvent *event)
119 128 {
120 129 this->clearSelection();
121 130 this->editeditem=this->itemAt(event->pos());
122 131 if(this->editeditem!=NULL && this->editingItem==false)
123 132 {
124 133 *this->editeditemprev=this->editeditem->text(0);
125 134 this->openPersistentEditor(this->editeditem);
126 135 this->editingItem=true;
127 136 }
128 137 QTreeWidget::mouseDoubleClickEvent(event);
129 138 }
130 139
131 140 void plugintree::mousePressEvent(QMouseEvent *event)
132 141 {
133 142 QTreeWidget::mousePressEvent(event);
134 143 if(this->editingItem==true && this->editeditem!=this->itemAt(event->pos()))
135 144 {
136 145 this->closePersistentEditor(this->editeditem);
137 146 if(QString::compare(this->editeditem->text(0),this->editeditemprev))
138 147 {
139 148 emit this->changeSysDriverInstName(this->editeditem->text(0),QString(*this->editeditemprev));
140 149 }
141 150 this->editingItem=false;
142 151 }
143 152 }
144 153
145 154
146 155 void plugintree::keyPressEvent(QKeyEvent *event)
147 156 {
148 157
149 158 {
150 159 switch(event->key())
151 160 {
152 161 case Qt::Key_Return:
153 162 if(this->editingItem==true)
154 163 {
155 164 this->closePersistentEditor(this->editeditem);
156 165 if(QString::compare(this->editeditem->text(0),this->editeditemprev))
157 166 {
158 167 emit this->changeSysDriverInstName(this->editeditem->text(0),QString(*this->editeditemprev));
159 168 }
160 169 this->editingItem=false;
161 170 }
162 171
163 172 break;
164 173 case Qt::Key_Delete:
165 174 if(this->selectedItems().count()==1)
166 175 {
167 176 emit this->closeSysDriver(this->selectedItems().first()->text(0));
168 177 }
169 178 break;
170 179 default:
171 180 break;
172 181 }
173 182 }
174 183 }
175 184
176 185
177 186 void plugintree::dropEvent(QDropEvent *event)
178 187 {
179 188 if (event->mimeData()->hasFormat("socexplorer/pluginName"))
180 189 {
181 190 QTreeWidgetItem* item=this->itemAt(event->pos());
182 191 if(item!=NULL)
183 192 {
184 193 emit this->loadSysDriverToParent(event->mimeData()->text(),item->text(0));
185 194 event->acceptProposedAction();
186 195 }
187 196 else if(pluginloader::libcanberoot(event->mimeData()->text()))
188 197 {
189 198 QString test(event->mimeData()->text());
190 199 emit this->loadSysDriver(event->mimeData()->text());
191 200 }
192 201 if (event->source() == this)
193 202 {
194 203 event->setDropAction(Qt::MoveAction);
195 204 event->accept();
196 205 } else {
197 206 if(pluginloader::checklibrary(event->mimeData()->text())!=0) //lib ok
198 207 {
199 208 if(pluginloader::libcanberoot(event->mimeData()->text()))
200 209 event->acceptProposedAction();
201 210 }
202 211 }
203 212 } else
204 213 {
205 214 event->ignore();
206 215 }
207 216 }
208 217
209 218
210 219
@@ -1,73 +1,73
1 1 /*------------------------------------------------------------------------------
2 2 -- This file is a part of the SocExplorer Software
3 3 -- Copyright (C) 2011, Laboratory of Plasmas Physic - CNRS
4 4 --
5 5 -- This program is free software; you can redistribute it and/or modify
6 6 -- it under the terms of the GNU General Public License as published by
7 7 -- the Free Software Foundation; either version 2 of the License, or
8 8 -- (at your option) any later version.
9 9 --
10 10 -- This program is distributed in the hope that it will be useful,
11 11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 13 -- GNU General Public License for more details.
14 14 --
15 15 -- You should have received a copy of the GNU General Public License
16 16 -- along with this program; if not, write to the Free Software
17 17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 18 -------------------------------------------------------------------------------*/
19 19 /*-- Author : Alexis Jeandet
20 20 -- Mail : alexis.jeandet@lpp.polytechnique.fr
21 21 ----------------------------------------------------------------------------*/
22 22 #ifndef PLUGINTREE_H
23 23 #define PLUGINTREE_H
24 24
25 25 #include <QWidget>
26 26 #include <QTreeWidget>
27 27 #include <socexplorerplugin.h>
28 28 #include <QList>
29 29 #include <QtGui/QDragEnterEvent>
30 30 #include <QtGui/QDragLeaveEvent>
31 31 #include <QtGui/QDragMoveEvent>
32 32 #include <QtGui/QDropEvent>
33 33 #include <QtCore/QMimeData>
34 34 #include <QtCore/QUrl>
35 35 #include <QtCore/QList>
36 36 #include <QPoint>
37 37 #include <QLabel>
38 38
39 39 class plugintree : public QTreeWidget
40 40 {
41 41 Q_OBJECT
42 42 public:
43 43 explicit plugintree(QWidget *parent = 0);
44 44
45 45 protected:
46 46 void dragEnterEvent(QDragEnterEvent *event);
47 47 void dragMoveEvent(QDragMoveEvent *event);
48 48 void dropEvent(QDropEvent *event);
49 49 void mousePressEvent(QMouseEvent *event);
50 50 void mouseDoubleClickEvent(QMouseEvent *event);
51 51 void keyPressEvent(QKeyEvent *event);
52 52
53 53 signals:
54 54 void geteplugintree(void);
55 55 void pluginselected(const QString& Name);
56 56 void loadSysDriverToParent(const QString name, const QString instanceName);
57 57 void loadSysDriver(const QString name);
58 58 void closeSysDriver(const QString instanceName);
59 59 void changeSysDriverInstName(const QString instanceName);
60 60 void changeSysDriverInstName(const QString newinstanceName,const QString previnstanceName);
61 61 public slots:
62 62 void treeChanged(const QList<socexplorerplugin*>& drivers);
63 63 void pluginselectedslt( QTreeWidgetItem * item, int column);
64
64 void itemSelectionChangedslt();
65 65
66 66 private:
67 67 void addplugin(socexplorerplugin* driver,QTreeWidgetItem* item);
68 68 QTreeWidgetItem* editeditem;
69 69 QString* editeditemprev;
70 70 bool editingItem;
71 71 };
72 72
73 73 #endif // PLUGINTREE_H
@@ -1,103 +1,103
1 1
2 2 #include <genericPySysdriver.h>
3 3 #include <socexplorerplugin.h>
4 4 #ifdef WIN32
5 5 #include <stdlib.h>
6 6 #define socexplorerBswap32(X) _byteswap_ulong(X)
7 7 #else
8 8 #ifdef UNIX
9 9 #include <byteswap.h>
10 10 #define socexplorerBswap32(X) bswap_32(X)
11 11 #endif
12 12 #endif
13 13
14 14
15 15
16 16
17 17 genericPySysdriver::genericPySysdriver(socexplorerplugin* plugin,QObject* parent):
18 18 QObject(parent)
19 19 {
20 20 Q_UNUSED(parent)
21 21 this->plugin = plugin;
22 22 }
23 23
24 24 QVariantList genericPySysdriver::Read(unsigned int address,unsigned int count)
25 25 {
26 26 unsigned int data[count];
27 27 QVariantList result;
28 28 this->plugin->Read(data,count,address);
29 29 for(unsigned int i = 0;i<count;i++)
30 30 {
31 31 result.append(QVariant((int)data[i]));
32 32 }
33 33 return result;
34 34 }
35 35 void genericPySysdriver::Write(unsigned int address,QList<QVariant> dataList)
36 36 {
37 37 unsigned int data[dataList.count()];
38 38 for(int i = 0;i<dataList.count();i++)
39 39 {
40 40 data[i] = (unsigned int)dataList.at(i).toUInt();
41 41 }
42 42 this->plugin->Write(data,dataList.count(),address);
43 43 }
44 44
45 45 bool genericPySysdriver::dumpMemory(unsigned int address,unsigned int count,QString file)
46 46 {
47 47 unsigned int* buffer = (unsigned int*)malloc(count*sizeof(unsigned int));
48 48 if(buffer!=NULL)
49 49 {
50 50 this->plugin->Read(buffer,count,address);
51 51 QFile outfile(file);
52 52 if (!outfile.open(QIODevice::ReadWrite | QIODevice::Text))
53 53 return false;
54 54 QTextStream out(&outfile);
55 55 for(int i=0;(unsigned int)i<count;i++)
56 56 out << "0x"+QString::number(address+(i*4),16) + ": 0x" + QString::number(buffer[i],16) + "\n";
57 57 free(buffer);
58 58 out.flush();
59 59 outfile.close();
60 60 return true;
61 61 }
62 62 return false;
63 63 }
64 64
65 65 bool genericPySysdriver::memSet(unsigned int address,int value, unsigned int count)
66 66 {
67 67 unsigned int* buffer = (unsigned int*)malloc(count*sizeof(unsigned int));
68 68 if(buffer!=NULL)
69 69 {
70 70 memset((void*)buffer,value,count*sizeof(unsigned int));
71 71 this->plugin->Write(buffer,count,address);
72 72 free(buffer );
73 73 return true;
74 74 }
75 75 return false;
76 76 }
77 77
78 78 bool genericPySysdriver::loadbin(unsigned int address,QString file)
79 79 {
80 80 QFile infile(file);
81 81 if (!infile.open(QIODevice::ReadOnly))
82 82 return false;
83 83 uint32_t* buffer = (uint32_t*)malloc(infile.size());
84 84 if(buffer!=NULL)
85 85 {
86 86 infile.read((char*)buffer,infile.size());
87 87 for(int i=0;i<(infile.size()/4);i++)
88 88 {
89 89 buffer[i] = socexplorerBswap32(buffer[i]);
90 90 }
91 91 this->plugin->Write(buffer,infile.size()/4,address);
92 92 free(buffer);
93 93 return true;
94 94 }
95 95 return false;
96 96
97 97 }
98 98
99 99 QString genericPySysdriver::instance()
100 100 {
101 return plugin->instanceName;
101 return plugin->instanceName();
102 102 }
103 103
@@ -1,84 +1,91
1 1 /*------------------------------------------------------------------------------
2 2 -- This file is a part of the SocExplorer Software
3 3 -- Copyright (C) 2014, Laboratory of Plasmas Physic - CNRS
4 4 --
5 5 -- This program is free software; you can redistribute it and/or modify
6 6 -- it under the terms of the GNU General Public License as published by
7 7 -- the Free Software Foundation; either version 2 of the License, or
8 8 -- (at your option) any later version.
9 9 --
10 10 -- This program is distributed in the hope that it will be useful,
11 11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 13 -- GNU General Public License for more details.
14 14 --
15 15 -- You should have received a copy of the GNU General Public License
16 16 -- along with this program; if not, write to the Free Software
17 17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 18 -------------------------------------------------------------------------------*/
19 19 /*-- Author : Alexis Jeandet
20 20 -- Mail : alexis.jeandet@lpp.polytechnique.fr
21 21 ----------------------------------------------------------------------------*/
22 22
23 23 #include <socexplorerplugin.h>
24 24
25 25
26 26 int socexplorerplugin::isConnected(){return this->Connected;}
27 27
28 28 QString socexplorerplugin::baseName(){return *_Name;}
29 29
30 30 int socexplorerplugin::baseAddress(){return this->BaseAddress;}
31 31
32 32 void socexplorerplugin::setBaseAddress(unsigned int baseAddress){this->BaseAddress = baseAddress;}
33 33
34 QString socexplorerplugin::instanceName()
35 {
36 return this->_instanceName;
37 }
38
34 39 int socexplorerplugin::registermenu(QMenu *menu)
35 40 {
36 this->menu = menu->addMenu(this->instanceName);
41 this->menu = menu->addMenu(this->_instanceName);
37 42 this->closeAction = this->menu->addAction(tr("Close plugin"));
38 43 QObject::connect(this->closeAction,SIGNAL(triggered()),this,SLOT(closeMe()));
39 44 this->ChildsMenu = this->menu->addMenu(QString("Childs"));
40 45 for(int i=0;i<this->childs.count();i++)
41 46 {
42 47 this->childs.at(i)->registermenu(this->ChildsMenu);
43 48 }
44 if(this->pyObject!=NULL)emit this->registerObject((QObject*)this->pyObject,this->instanceName);
49 if(this->pyObject!=NULL)emit this->registerObject((QObject*)this->pyObject,this->instanceName());
45 50 return 0;
46 51 }
47 52
48 53 void socexplorerplugin::postInstantiationTrigger()
49 54 {
50 55 return;
51 56 }
52 57
53 58 unsigned int socexplorerplugin::Write(unsigned int *Value, unsigned int count, unsigned int address)
54 59 {
55 60 if(parent!=NULL)
56 61 {
57 62 return parent->Write(Value,count,address);
58 63 }
59 64 return 0;
60 65 }
61 66
62 67 unsigned int socexplorerplugin::Read(unsigned int *Value, unsigned int count, unsigned int address)
63 68 {
64 69 if(parent!=NULL)
65 70 {
66 71 return parent->Read(Value,count,address);
67 72 }
68 73 return 0;
69 74 }
70 75
71 76 void socexplorerplugin::closeMe(){emit this->closePlugin(this);}
72 77
73 78 void socexplorerplugin::activate(bool flag){this->setEnabled(flag);emit this->activateSig(flag);}
74 79
75 80 void socexplorerplugin::setInstanceName(const QString &newName)
76 81 {
77 this->instanceName = newName;
78 this->menu->setTitle(this->instanceName);
82 this->_instanceName = newName;
83 if(this->menu)
84 this->menu->setTitle(this->_instanceName);
85 this->setWindowTitle(newName);
79 86 }
80 87
81 88 void socexplorerplugin::makeGenericPyWrapper()
82 89 {
83 90 this->pyObject = new genericPySysdriver(this);
84 91 }
@@ -1,176 +1,180
1 1 /*------------------------------------------------------------------------------
2 2 β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•— β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•— β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•— β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β–ˆβ–ˆβ•— β–ˆβ–ˆβ•—β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•— β–ˆβ–ˆβ•— β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•— β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•— β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—
3 3 β–ˆβ–ˆβ•”β•β•β•β•β•β–ˆβ–ˆβ•”β•β•β•β–ˆβ–ˆβ•—β–ˆβ–ˆβ•”β•β•β•β•β• β–ˆβ–ˆβ•”β•β•β•β•β•β•šβ–ˆβ–ˆβ•—β–ˆβ–ˆβ•”β•β–ˆβ–ˆβ•”β•β•β–ˆβ–ˆβ•—β–ˆβ–ˆβ•‘ β–ˆβ–ˆβ•”β•β•β•β–ˆβ–ˆβ•—β–ˆβ–ˆβ•”β•β•β–ˆβ–ˆβ•—β–ˆβ–ˆβ•”β•β•β•β•β•β–ˆβ–ˆβ•”β•β•β–ˆβ–ˆβ•—
4 4 β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β–ˆβ–ˆβ•‘ β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•‘ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•— β•šβ–ˆβ–ˆβ–ˆβ•”β• β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•”β•β–ˆβ–ˆβ•‘ β–ˆβ–ˆβ•‘ β–ˆβ–ˆβ•‘β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•”β•β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•— β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•”β•
5 5 β•šβ•β•β•β•β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•‘ β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•‘ β–ˆβ–ˆβ•”β•β•β• β–ˆβ–ˆβ•”β–ˆβ–ˆβ•— β–ˆβ–ˆβ•”β•β•β•β• β–ˆβ–ˆβ•‘ β–ˆβ–ˆβ•‘ β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•”β•β•β–ˆβ–ˆβ•—β–ˆβ–ˆβ•”β•β•β• β–ˆβ–ˆβ•”β•β•β–ˆβ–ˆβ•—
6 6 β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•‘β•šβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•”β•β•šβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•— β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β–ˆβ–ˆβ•”β• β–ˆβ–ˆβ•—β–ˆβ–ˆβ•‘ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β•šβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•”β•β–ˆβ–ˆβ•‘ β–ˆβ–ˆβ•‘β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β–ˆβ–ˆβ•‘ β–ˆβ–ˆβ•‘
7 7 β•šβ•β•β•β•β•β•β• β•šβ•β•β•β•β•β• β•šβ•β•β•β•β•β• β•šβ•β•β•β•β•β•β•β•šβ•β• β•šβ•β•β•šβ•β• β•šβ•β•β•β•β•β•β• β•šβ•β•β•β•β•β• β•šβ•β• β•šβ•β•β•šβ•β•β•β•β•β•β•β•šβ•β• β•šβ•β•
8 8
9 9 -- This file is a part of the SOC Explorer Software
10 10 -- Copyright (C) 2011, Laboratory of Plasmas Physic - CNRS
11 11 --
12 12 -- This program is free software; you can redistribute it and/or modify
13 13 -- it under the terms of the GNU General Public License as published by
14 14 -- the Free Software Foundation; either version 2 of the License, or
15 15 -- (at your option) any later version.
16 16 --
17 17 -- This program is distributed in the hope that it will be useful,
18 18 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
19 19 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 20 -- GNU General Public License for more details.
21 21 --
22 22 -- You should have received a copy of the GNU General Public License
23 23 -- along with this program; if not, write to the Free Software
24 24 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 25 -------------------------------------------------------------------------------*/
26 26 /*-- Author : Alexis Jeandet
27 27 -- Mail : alexis.jeandet@lpp.polytechnique.fr
28 28 ----------------------------------------------------------------------------*/
29 29 #ifndef SOCEXPLORERPLUGIN_H
30 30 #define SOCEXPLORERPLUGIN_H
31 31 #include <QWidget>
32 32 #include <QAction>
33 33 #include <QDockWidget>
34 34 #include <QMainWindow>
35 35 #include <QList>
36 36 #include <QMenu>
37 37 #include <socexplorer.h>
38 38 #include <QObject>
39 39 #include <QVariant>
40 40 #include <QVariantList>
41 41 #include <malloc.h>
42 42 #include <QFile>
43 43 #include <stdint.h>
44 44 #include <QTextStream>
45 45 #include <genericPySysdriver.h>
46 46 #ifndef driver_Name
47 47 #define driver_Name "Plugin"
48 48 #endif
49 49 #ifndef driver_Author
50 50 #define driver_Author "No Author"
51 51 #endif
52 52 #ifndef driver_Version
53 53 #define driver_Version "0.0.0"
54 54 #endif
55 55 #ifndef driver_Description
56 56 #define driver_Description "No description."
57 57 #endif
58 58 #ifndef driver_can_be_root
59 59 #define driver_can_be_root 0
60 60 #endif
61 61 #ifndef driver_can_be_child
62 62 #define driver_can_be_child 0
63 63 #endif
64 64 #ifndef driver_VID
65 65 #define driver_VID 0
66 66 #endif
67 67 #ifndef driver_PID
68 68 #define driver_PID 0
69 69 #endif
70 70
71 71 #if defined(SOCEXPLORER_SDK_BUILD)
72 72 # define SOCEXPLORER_SDK_EXPORT Q_DECL_EXPORT
73 73 #else
74 74 # define SOCEXPLORER_SDK_EXPORT Q_DECL_IMPORT
75 75 #endif
76 76
77 77 class genericPySysdriver;
78 78
79 79 //! socexplorerplugin is the base class for any SocExplorer plugin, it gives a standard interface to communicate
80 80 //! between each plugins and to interact with SocExplorer software.
81 81
82 82 class SOCEXPLORER_SDK_EXPORT socexplorerplugin : public QDockWidget
83 83 {
84 84 Q_OBJECT
85 85 public:
86 86 //! Default plugin constructor, any plugin should call this constructor. This constructor creates a
87 87 //! default python wrapper instance. If you want to connect your own python wrapper, you have to clear
88 88 //! createPyObject option and instanciate your own genericPySysdriver derivated object.
89 socexplorerplugin(QWidget *parent = 0,bool createPyObject=true)
89 socexplorerplugin(QWidget *parent = 0,bool createPyObject=true):QDockWidget(parent)
90 90 {
91 closeAction=NULL;
92 menu=NULL;
93 ChildsMenu=NULL;
91 94 this->Connected = false;
92 95 this->setFeatures(QDockWidget::DockWidgetMovable|QDockWidget::DockWidgetFloatable|QDockWidget::DockWidgetVerticalTitleBar);
93 96 _Name = new QString(driver_Name);
94 97 _Author = new QString(driver_Author);
95 98 _Version = new QString(driver_Version);
96 99 _Description = new QString(driver_Description);
97 100 _canBeChild = driver_can_be_child;
98 101 _canBeRoot = driver_can_be_root;
99 102 _VID = driver_VID;
100 103 _PID = driver_PID;
101 104 if(createPyObject)
102 105 {
103 106 this->makeGenericPyWrapper();
104 107 }
105 108 }
106 109 //! Tells if the plugin is connected, it is used to enable or disable all childrens interfaces.
107 110 virtual int isConnected();
108 111 //! Gives the associated Vendor IDentifier, usefull to automatically associate plugins with found
109 112 //! hardware while board enumeration.
110 113 virtual int VID(){return _PID;}
111 114 //! Gives the associated Product IDentifier, usefull to automatically associate plugins with found
112 115 //! hardware while board enumeration.
113 116 virtual int PID(){return _VID;}
114 117 //! Gives the plugin's base name, usefull to automatically generate instance name.
115 118 virtual QString baseName();
116 119 //! Gives the base address of the current instance, for example if your plugin is supposed to drive
117 120 //! an UART it will correspond to the address of it's first register. This address have at least to
118 121 //! be set by SocExplorer and it can be user accessible if you want.
119 122 virtual int baseAddress();
120 123 //! Sets the base address of the current instance, for example if your plugin is supposed to drive
121 124 //! an UART it will correspond to the address of it's first register. This address have at least to
122 125 //! be set by lppSocExplorer and it can be user accessible if you want.
123 126 virtual void setBaseAddress(unsigned int baseAddress);
124 127
125 128 genericPySysdriver* getPyObjectWrapper(){return this->pyObject;}
126 129 QList<socexplorerplugin*> childs;
127 130 socexplorerplugin* parent;
128 131 QAction* closeAction;
129 QString instanceName;
132 QString instanceName();
130 133 QMenu* menu;
131 134 QMenu* ChildsMenu;
132 135
133 136 signals:
134 137 //! Signal emited each time the plugin is about to be closed.
135 138 void closePlugin(socexplorerplugin* driver);
136 139 void activateSig(bool flag);
137 140 void registerObject(QObject* object,const QString& instanceName);
138 141
139 142 public slots:
140 143 virtual int registermenu(QMenu* menu);
141 144 virtual void postInstantiationTrigger();
142 145 //! Write slot this is the way your children plugins ask you for writing data.
143 146 //! If your plugin is supposed to have childern drivers you should implement this methode.
144 147 //! By default this methode forward the write request to the parent plugin.
145 148 //! \param Value Pointer the data buffer.
146 149 //! \param count Number of 32 bits words you should to write.
147 150 //! \param address Address from where you should to start to write.
148 151 //! \return Quantity of 32 bits words writtens.
149 152 virtual unsigned int Write(unsigned int* Value, unsigned int count,unsigned int address);
150 153 //! Read slot this is the way your children plugins ask you for reading data.
151 154 //! If your plugin is supposed to have childern drivers you should implement this methode.
152 155 //! By default this methode forward the write request to the parent plugin.
153 156 //! \param Value Pointer the data buffer.
154 157 //! \param count Number of 32 bits words you should to read.
155 158 //! \param address Address from where you should to start to read.
156 159 //! \return Quantity of 32 bits words read.
157 160 virtual unsigned int Read(unsigned int* Value, unsigned int count,unsigned int address);
158 161 virtual void closeMe();
159 162 virtual void activate(bool flag);
160 163 virtual void setInstanceName(const QString& newName);
161 164 protected:
162 165 void makeGenericPyWrapper();
163 166 int BaseAddress;
164 167 bool Connected;
165 168 genericPySysdriver* pyObject;
166 169 QString* _Name;
167 170 QString* _Author;
168 171 QString* _Version;
169 172 QString* _Description;
173 QString _instanceName;
170 174 int _canBeChild;
171 175 int _canBeRoot;
172 176 int _VID;
173 177 int _PID;
174 178 };
175 179
176 180 #endif // SOCEXPLORERPLUGIN_H
@@ -1,383 +1,379
1 1 /*------------------------------------------------------------------------------
2 2 -- This file is a part of the SocExplorer Software
3 3 -- Copyright (C) 2011, Laboratory of Plasmas Physic - CNRS
4 4 --
5 5 -- This program is free software; you can redistribute it and/or modify
6 6 -- it under the terms of the GNU General Public License as published by
7 7 -- the Free Software Foundation; either version 2 of the License, or
8 8 -- (at your option) any later version.
9 9 --
10 10 -- This program is distributed in the hope that it will be useful,
11 11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 13 -- GNU General Public License for more details.
14 14 --
15 15 -- You should have received a copy of the GNU General Public License
16 16 -- along with this program; if not, write to the Free Software
17 17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 18 -------------------------------------------------------------------------------*/
19 19 /*-- Author : Alexis Jeandet
20 20 -- Mail : alexis.jeandet@lpp.polytechnique.fr
21 21 ----------------------------------------------------------------------------*/
22 22 #include "socexplorerproxy.h"
23 23 #include <pluginmanagerWDGT.h>
24 24 #include <socexplorerengine.h>
25 25 #include <pluginloader.h>
26 26 #include <socexplorerplugin.h>
27 27
28 28 socexplorerproxy* socexplorerproxy::_self=NULL;
29 29 QMainWindow* socexplorerproxy::mainWindow=NULL;
30 30 QList<socexplorerplugin*>* socexplorerproxy::drivers=NULL;
31 31 QList<socexplorerplugin*>* socexplorerproxy::linearDriverList=NULL;
32 32 socexplorerplugin* socexplorerproxy::root=NULL;
33 33 socexplorerplugin* socexplorerproxy::parent=NULL;
34 34 PluginsCache* socexplorerproxy::cache=NULL;
35 35
36 36 socexplorerproxy::socexplorerproxy(QObject *parent) :
37 37 QObject(parent)
38 38 {
39 39 cache = new PluginsCache;
40 40 drivers = new QList<socexplorerplugin*>;
41 41 linearDriverList=new QList<socexplorerplugin*>;
42 42 root = NULL;
43 43 }
44 44
45 45
46 46 socexplorerproxy::socexplorerproxy(QMainWindow *Mainwindow, QObject *parent):
47 47 QObject(parent)
48 48 {
49 49 mainWindow = Mainwindow;
50 50 cache = new PluginsCache;
51 51 drivers = new QList<socexplorerplugin*>;
52 52 linearDriverList=new QList<socexplorerplugin*>;
53 53 root = NULL;
54 54 }
55 55
56 56
57 57 void socexplorerproxy::init()
58 58 {
59 59 if(!_self)
60 60 {
61 61 _self = new socexplorerproxy();
62 62 mainWindow = NULL;
63 63 }
64 64
65 65 }
66 66
67 67 void socexplorerproxy::setMainWindow(QMainWindow *Mainwindow)
68 68 {
69 69 if(!_self)init();
70 70 mainWindow=Mainwindow;
71 71 }
72 72
73 73 void socexplorerproxy::loadSysDriver(const QString name)
74 74 {
75 75 if(!_self)init();
76 76 if(pluginloader::libcanberoot(name))
77 77 {
78 78 socexplorerplugin* driver = pluginloader::newsocexplorerplugin(name);
79 79 QString driverName = _self->getinstanceName(driver->baseName());
80 80 loadSysDriver(driver,driverName);
81 81 }
82 82 }
83 83
84 84 void socexplorerproxy::loadSysDriver(const QString name, const QString instanceName)
85 85 {
86 86 if(!_self)init();
87 87 if(pluginloader::libcanberoot(name) && !_self->instanceExists(instanceName))
88 88 {
89 89 socexplorerplugin* driver = pluginloader::newsocexplorerplugin(name);
90 90 loadSysDriver(driver,instanceName);
91 91 }
92 92 }
93 93
94 94
95 95 void socexplorerproxy::loadSysDriver(socexplorerplugin *driver, const QString instanceName)
96 96 {
97 97 if(!_self)init();
98 driver->instanceName.append(instanceName);
98 driver->setInstanceName(instanceName);
99 99 driver->parent = NULL;
100 100 drivers->append(driver);
101 101 linearDriverList->append(driver);
102 102 connectChildToProxy(driver);
103 103 emit _self->addPluginGUI(driver);
104 104 emit _self->clearMenu();
105 105 emit _self->treeChanged(QList<socexplorerplugin*>(*drivers));
106 106 SocExplorerEngine::addSOC(driver);
107 107 }
108 108
109 109 void socexplorerproxy::loadChildSysDriver(socexplorerplugin *parent, const QString child)
110 110 {
111 111 if(!_self)init();
112 112 if(pluginloader::libcanbechild(child))
113 113 {
114 114 socexplorerplugin* driver = pluginloader::newsocexplorerplugin(child);
115 115 QString driverName = _self->getinstanceName(driver->baseName());
116 116 bool ok=true;
117 117 if(ok)
118 118 {
119 119 if(parent!=NULL)_self->loadSysDriverToParent(driver,parent,driverName);
120 120 }
121 121 }
122 122 }
123 123
124 124 void socexplorerproxy::loadSysDriverToParent(const QString name,const QString ParentInst)
125 125 {
126 126 if(!_self)init();
127 127 if(pluginloader::libcanbechild(name))
128 128 {
129 129 socexplorerplugin* driver = pluginloader::newsocexplorerplugin(name);
130 130 QString driverName = _self->getinstanceName(driver->baseName());
131 131 bool ok=true;
132 132 if(ok)
133 133 {
134 134 socexplorerplugin* parent=_self->getSysDriver(ParentInst);
135 135 if(parent!=NULL)loadSysDriverToParent(driver,parent,driverName);
136 136 }
137 137 }
138 138 }
139 139
140 140
141 141 void socexplorerproxy::loadSysDriverToParent(const QString name,const QString instanceName,const QString ParentInst)
142 142 {
143 143 if(!_self)init();
144 144 if(pluginloader::libcanbechild(name) && !_self->instanceExists(instanceName))
145 145 {
146 146 socexplorerplugin* driver = pluginloader::newsocexplorerplugin(name);
147 147 bool ok=true;
148 148 if(ok)
149 149 {
150 150 socexplorerplugin* parent=_self->getSysDriver(ParentInst);
151 151 if(parent!=NULL)loadSysDriverToParent(driver,parent,instanceName);
152 152 }
153 153 }
154 154 }
155 155
156 156 void socexplorerproxy::loadSysDriverToParent(socexplorerplugin *driver,socexplorerplugin *parent, const QString instanceName)
157 157 {
158 158 if(!_self)init();
159 159 linearDriverList->append(driver);
160 160 driver->parent = parent;
161 driver->instanceName.append(instanceName);
161 driver->setInstanceName(instanceName);
162 162 parent->childs.append(driver);
163 163 connectChildToProxy(driver);
164 164 connectChildToParent(parent,driver);
165 165 emit _self->clearMenu();
166 166 emit _self->addPluginGUI(driver);
167 167 emit _self->treeChanged(QList<socexplorerplugin*>(*drivers));
168 168 driver->postInstantiationTrigger();
169 169 }
170 170
171 171
172 172 void socexplorerproxy::changeSysDriverInstName(const QString instanceName)
173 173 {
174 174 Q_UNUSED(instanceName)
175 175 }
176 176
177 177 void socexplorerproxy::changeSysDriverInstName(const QString newinstanceName, const QString previnstanceName)
178 178 {
179 179 if(!_self)init();
180 180 socexplorerplugin*temp=_self->getSysDriver(previnstanceName);
181 181 if(temp!=NULL)
182 182 {
183 183 if(NULL!=_self->getSysDriver(newinstanceName))
184 184 {
185 185 emit _self->treeChanged(QList<socexplorerplugin*>(*drivers));
186 186 return;
187 187 }
188 188 temp->setInstanceName(newinstanceName);
189 189 }
190 190 emit _self->treeChanged(QList<socexplorerplugin*>(*drivers));
191 191 }
192 192
193 193 void socexplorerproxy::loadChild(socexplorerplugin *parent)
194 194 {
195 195 if(!_self)init();
196 196 parent = parent;
197 197 pluginmanagerWDGT* pluginmanager0 = new pluginmanagerWDGT;
198 198 pluginmanager0->setChildLoadable(true);
199 199 pluginmanager0->connect(pluginmanager0,SIGNAL(loadSysDrviver(QString)),_self,SLOT(loadSysDriverToParent(QString)));
200 200 pluginmanager0->show();
201 201 }
202 202
203 203
204 204 void socexplorerproxy::connectChildToParent(socexplorerplugin *parent, socexplorerplugin *child)
205 205 {
206 206 if(!_self)init();
207 //connect(child,SIGNAL(WriteSig(uint*,uint,uint)),parent,SLOT(Write(uint*,uint,uint)));
208 //connect(child,SIGNAL(ReadSig(uint*,uint,uint)),parent,SLOT(Read(uint*,uint,uint)));
209 connect(parent,SIGNAL(activateSig(bool)),child,SLOT(activate(bool)));//,Qt::DirectConnection);
207 connect(parent,SIGNAL(activateSig(bool)),child,SLOT(activate(bool)));
210 208 child->activate(parent->isConnected());
211 209 }
212 210
213 211 void socexplorerproxy::disconnectChildToParent(socexplorerplugin *child)
214 212 {
215 213 if(!_self)init();
216 //disconnect(child,SIGNAL(WriteSig(uint*,uint,uint)),child->parent,SLOT(Write(uint*,uint,uint)));
217 // disconnect(child,SIGNAL(ReadSig(uint*,uint,uint)),child->parent,SLOT(Read(uint*,uint,uint)));
218 disconnect(child->parent,SIGNAL(activateSig(bool)),child,SLOT(activate(bool)));//,Qt::DirectConnection);
214 disconnect(child->parent,SIGNAL(activateSig(bool)),child,SLOT(activate(bool)));
219 215 }
220 216
221 217
222 218 void socexplorerproxy::connectChildToProxy(socexplorerplugin *child)
223 219 {
224 220 if(!_self)init();
225 221 connect(child,SIGNAL(registerObject(QObject*,QString)),_self,SIGNAL(registerObject(QObject*,QString)));
226 222 connect(child,SIGNAL(closePlugin(socexplorerplugin*)),_self,SLOT(closeSysDriver(socexplorerplugin*)));
227 223 }
228 224
229 225 void socexplorerproxy::disconnectChildToProxy(socexplorerplugin *child)
230 226 {
231 227 if(!_self)init();
232 228 disconnect(child,SIGNAL(registerObject(QObject*,QString)),_self,SIGNAL(registerObject(QObject*,QString)));
233 229 disconnect(child,SIGNAL(closePlugin(socexplorerplugin*)),_self,SLOT(closeSysDriverFromDriver(socexplorerplugin*)));
234 230 }
235 231
236 232 QString socexplorerproxy::getinstanceName(const QString& baseName)
237 233 {
238 234 if(!_self)init();
239 235 int i=0;
240 236 QString name;
241 237 bool validName = false;
242 238 while(!validName)
243 239 {
244 240 name.clear();
245 241 name.append(baseName+QString::number(i));
246 242 validName = instanceNameIsValid(name);
247 243 i++;
248 244 }
249 245 return name;
250 246 }
251 247
252 248 void socexplorerproxy::changeSysDriverInstName(socexplorerplugin* driver)
253 249 {
254 250 if(!_self)init();
255 QString prevName(driver->instanceName);
251 QString prevName(driver->instanceName());
256 252 }
257 253
258 254 bool socexplorerproxy::instanceNameIsValid(const QString& instanceName)
259 255 {
260 256 if(!_self)init();
261 257 for(int k=0;k<linearDriverList->count();k++)
262 258 {
263 if(!linearDriverList->at(k)->instanceName.compare(instanceName))
259 if(!linearDriverList->at(k)->instanceName().compare(instanceName))
264 260 return false;
265 261 }
266 262 return true;
267 263 }
268 264
269 265 socexplorerplugin *socexplorerproxy::findPlugin(const QString &instanceName)
270 266 {
271 267 if(!_self)init();
272 268 for(int k=0;k<linearDriverList->count();k++)
273 269 {
274 if(linearDriverList->at(k)->instanceName.compare(instanceName))
270 if(linearDriverList->at(k)->instanceName().compare(instanceName))
275 271 return linearDriverList->at(k);
276 272 }
277 273 return NULL;
278 274 }
279 275
280 276 bool socexplorerproxy::instanceExists(const QString &instanceName)
281 277 {
282 278 return !socexplorerproxy::instanceNameIsValid(instanceName);
283 279 }
284 280
285 281 void socexplorerproxy::close()
286 282 {
287 283 if(!_self)init();
288 284 socexplorerplugin* tmpPtr;
289 285 while(drivers->count()>0)
290 286 {
291 287 tmpPtr = drivers->last();
292 288 drivers->removeLast();
293 289 _self->closeSysDriver(tmpPtr);
294 290 }
295 291 if(root!=NULL)
296 292 {
297 293 _self->closeSysDriver(root);
298 294 }
299 295
300 296 }
301 297
302 298 socexplorerplugin* socexplorerproxy::getSysDriver(const QString instanceName)
303 299 {
304 300 if(!_self)init();
305 301 for(int i=0;i<linearDriverList->count();i++)
306 302 {
307 if(!linearDriverList->at(i)->instanceName.compare(instanceName))
303 if(!linearDriverList->at(i)->instanceName().compare(instanceName))
308 304 return linearDriverList->at(i);
309 305 }
310 306 return NULL;
311 307 }
312 308
313 309
314 310 void socexplorerproxy::closeSysDriver(const QString instanceName)
315 311 {
316 312 if(!_self)init();
317 313 closeSysDriver(getSysDriver(instanceName),false);
318 314 }
319 315
320 316 void socexplorerproxy::closeSysDriver(socexplorerplugin *driver, bool recursive)
321 317 {
322 318 if(!_self)init();
323 319 if(driver!=NULL)
324 320 {
325 321 if(driver->parent==NULL)SocExplorerEngine::removeSOC(driver);
326 322 while(driver->childs.count()!=0)closeSysDriver(driver->childs.first());
327 323 linearDriverList->removeOne(driver);
328 324 if(driver->parent!= NULL)
329 325 {
330 326 driver->parent->childs.removeOne(driver); //Have parent so it's a child
331 327 disconnectChildToParent(driver);
332 328 disconnectChildToProxy(driver);
333 329 delete driver;
334 330 }
335 331 else
336 332 {
337 333 drivers->removeOne(driver);
338 334 disconnectChildToProxy(driver);
339 335 delete driver;
340 336 }
341 337 if(!recursive)
342 338 {
343 339 emit _self->clearMenu();
344 340 emit _self->registermenu(mainWindow);
345 341 emit _self->treeChanged(QList<socexplorerplugin*>(*drivers));
346 342 }
347 343 }
348 344
349 345 }
350 346
351 347 void socexplorerproxy::geteplugintree()
352 348 {
353 349 if(!_self)init();
354 350 emit _self->treeChanged(QList<socexplorerplugin*>(*drivers));
355 351 }
356 352
357 353 void socexplorerproxy::closeSysDriverFromDriver(socexplorerplugin *driver)
358 354 {
359 355 if(!_self)init();
360 356 emit _self->closeSysDriverSig(driver);
361 357 }
362 358
363 359 void socexplorerproxy::updateText()
364 360 {
365 361 if(!_self)init();
366 362 emit _self->clearMenu();
367 363 emit _self->registermenu(mainWindow);
368 364 }
369 365
370 366
371 367
372 368
373 369
374 370 void socexplorerproxy::makeMenu(QMenu* menu)
375 371 {
376 372 if(!_self)init();
377 373 for(int i=0;i<drivers->count();i++)
378 374 {
379 375 drivers->at(i)->registermenu(menu);
380 376 }
381 377 }
382 378
383 379
@@ -1,22 +1,23
1 1 #include "dockablepluginmanager.h"
2 2
3 3 dockablePluginManager::dockablePluginManager(QWidget *parent) :
4 4 QDockWidget(parent)
5 5 {
6 6 this->managerGui = new pluginmanagerWDGT;
7 7 connect(this->managerGui,SIGNAL(loadSysDrviver(QString)),this,SIGNAL(loadSysDrviver(QString)));
8 8 connect(this->managerGui,SIGNAL(loadSysDriverToParent(QString,QString)),this,SIGNAL(loadSysDriverToParent(QString,QString)));
9 9 connect(this->managerGui,SIGNAL(geteplugintree()),this,SIGNAL(geteplugintree()));
10 10 connect(this,SIGNAL(treeChanged(QList<socexplorerplugin*>)),this->managerGui,SIGNAL(treeChanged(QList<socexplorerplugin*>)));
11 11 connect(this->managerGui,SIGNAL(changeSysDriverInstName(QString,QString)),this,SIGNAL(changeSysDriverInstName(QString,QString)));
12 12 connect(this->managerGui,SIGNAL(closeSysDriver(QString)),this,SIGNAL(closeSysDriver(QString)));
13 connect(this->managerGui,SIGNAL(pluginselected(QString)),this,SIGNAL(pluginselected(QString)));
13 14 this->setWidget(this->managerGui);
14 15 this->setWindowTitle(this->managerGui->windowTitle());
15 16 }
16 17
17 18
18 19
19 20 void dockablePluginManager::setRootLoadable(bool flag)
20 21 {
21 22 this->managerGui->setRootLoadable(flag);
22 23 }
@@ -1,49 +1,50
1 1 /*------------------------------------------------------------------------------
2 2 -- This file is a part of the SocExplorer Software
3 3 -- Copyright (C) 2011, Laboratory of Plasmas Physic - CNRS
4 4 --
5 5 -- This program is free software; you can redistribute it and/or modify
6 6 -- it under the terms of the GNU General Public License as published by
7 7 -- the Free Software Foundation; either version 2 of the License, or
8 8 -- (at your option) any later version.
9 9 --
10 10 -- This program is distributed in the hope that it will be useful,
11 11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 13 -- GNU General Public License for more details.
14 14 --
15 15 -- You should have received a copy of the GNU General Public License
16 16 -- along with this program; if not, write to the Free Software
17 17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 18 -------------------------------------------------------------------------------*/
19 19 /*-- Author : Alexis Jeandet
20 20 -- Mail : alexis.jeandet@lpp.polytechnique.fr
21 21 ----------------------------------------------------------------------------*/
22 22 #ifndef DOCKABLEPLUGINMANAGER_H
23 23 #define DOCKABLEPLUGINMANAGER_H
24 24
25 25 #include <QDockWidget>
26 26 #include "pluginmanagerWDGT.h"
27 27
28 28 class dockablePluginManager : public QDockWidget
29 29 {
30 30 Q_OBJECT
31 31 public:
32 32 explicit dockablePluginManager(QWidget *parent = 0);
33 33 void setRootLoadable(bool flag);
34 34
35 35 signals:
36 36 void loadSysDrviver(const QString name);
37 37 void loadSysDriverToParent(const QString name, const QString instanceName);
38 38 void geteplugintree(void);
39 39 void treeChanged(const QList<socexplorerplugin*>& drivers);
40 40 void changeSysDriverInstName(const QString newinstanceName,const QString previnstanceName);
41 41 void closeSysDriver(const QString instanceName);
42 void pluginselected(const QString& instanceName);
42 43 public slots:
43 44
44 45 private:
45 46 pluginmanagerWDGT* managerGui;
46 47
47 48 };
48 49
49 50 #endif // DOCKABLEPLUGINMANAGER_H
@@ -1,223 +1,234
1 1 /*------------------------------------------------------------------------------
2 2 -- This file is a part of the SocExplorer Software
3 3 -- Copyright (C) 2011, Laboratory of Plasmas Physic - CNRS
4 4 --
5 5 -- This program is free software; you can redistribute it and/or modify
6 6 -- it under the terms of the GNU General Public License as published by
7 7 -- the Free Software Foundation; either version 2 of the License, or
8 8 -- (at your option) any later version.
9 9 --
10 10 -- This program is distributed in the hope that it will be useful,
11 11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 13 -- GNU General Public License for more details.
14 14 --
15 15 -- You should have received a copy of the GNU General Public License
16 16 -- along with this program; if not, write to the Free Software
17 17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 18 -------------------------------------------------------------------------------*/
19 19 /*-- Author : Alexis Jeandet
20 20 -- Mail : alexis.jeandet@lpp.polytechnique.fr
21 21 ----------------------------------------------------------------------------*/
22 22 #include "mainwindow.h"
23 23 #include <QDockWidget>
24 24
25 25 LPMONMainWindow::LPMONMainWindow(QString ScriptToEval, QWidget *parent)
26 26 : QMainWindow(parent)
27 27 {
28 28 QCoreApplication::setApplicationName("SocExplorer");
29 29 QCoreApplication::setOrganizationName("LPP");
30 30 QCoreApplication::setOrganizationDomain("lpp.fr");
31 31 this->makeObjects(ScriptToEval);
32 32 this->makeLayout();
33 33 this->makeMenu();
34 34 this->makeConnections();
35 35 this->setWindowIcon(QIcon(tr(":/images/logolppcutted.png")));
36 36 this->setAcceptDrops(true);
37 37 this->pluginManager->setRootLoadable(true);
38 38 this->PythonConsoleInst->pyConsoleRunFile(ScriptToEval);
39 QProgressBar* test = SocExplorerEngine::getProgressBar("test",10);
40 statusBar()->setFixedHeight(statusBar()->height());
41 SocExplorerEngine::deleteProgressBar(test);
39 // QProgressBar* test = SocExplorerEngine::getProgressBar("test",10);
40 // statusBar()->setFixedHeight(statusBar()->height());
41 // SocExplorerEngine::deleteProgressBar(test);
42 42 }
43 43
44 44
45 45 void LPMONMainWindow::makeObjects(QString ScriptToEval)
46 46 {
47 47 Q_UNUSED(ScriptToEval)
48 48 pluginsDockContainer = new QMainWindow;
49 49 pluginsDockContainer->setWindowFlags(Qt::Widget);
50 50 pluginsDockContainer->setDockNestingEnabled(true);
51 51 this->mainWidget = new QSplitter(Qt::Vertical);
52 52 this->appTranslator = new QTranslator;
53 53 this->Quit = new QAction(tr("&Quit"),this);
54 54 this->Quit->setShortcut(tr("CTRL+Q"));
55 55 this->ManagePlugins = new QAction(tr("&Manage Plugins"),this);
56 56 this->ManagePlugins->setShortcut(tr("CTRL+P"));
57 57 this->regsManager = new QAction(tr("&Manage registers"),this);
58 58 this->exploreRegs = new QAction(tr("&Explore registers"),this);
59 59 this->help = new QAction(tr("&Help"),this);
60 60 this->help->setShortcut(tr("CTRL+H"));
61 61 this->about = new QAction(tr("&About"),this);
62 62 socexplorerproxy::setMainWindow(this);
63 63 SocExplorerEngine::setMainWindow(this);
64 64 SocExplorerEngine::xmlModel()->scanXmlFiles();
65 65 this->regExplorer = new regsExplorer();
66 66 this->regExplorer->setAllowedAreas(Qt::AllDockWidgetAreas);
67 this->pluginsDockContainer->addDockWidget(Qt::TopDockWidgetArea,this->regExplorer);
67 // this->pluginsDockContainer->addDockWidget(Qt::TopDockWidgetArea,this->regExplorer);
68 this->addPluginInterface(this->regExplorer);
68 69 this->PythonConsoleInst = new PythonConsole(socexplorerproxy::self());
69 70 this->PythonConsoleInst->addObject("SocExplorerEngine",SocExplorerEngine::self());
70 71 this->pluginManager = new dockablePluginManager();
71 72 this->toolpane = new toolBar;
72 73 this->p_about = new aboutsocexplorer();
73 74 }
74 75
75 76 void LPMONMainWindow::makeLayout()
76 77 {
77 78 this->mainWidget->addWidget(pluginsDockContainer);
78 79 this->mainWidget->addWidget(this->PythonConsoleInst);
79 80 this->toolpane->setAllowedAreas(Qt::RightDockWidgetArea|Qt::LeftDockWidgetArea);
80 81 this->addDockWidget(Qt::LeftDockWidgetArea,this->toolpane);
81 82 this->toolpane->addTool(this->pluginManager);
82 83 this->setCentralWidget(this->mainWidget);
83 84 }
84 85
85 86
86 87 void LPMONMainWindow::makeConnections()
87 88 {
88 89 connect(socexplorerproxy::self(),SIGNAL(clearMenu()),this,SLOT(clearMenu()));
89 90 connect(this,SIGNAL(translateSig()),socexplorerproxy::self(),SLOT(updateText()));
90 91 connect(socexplorerproxy::self(),SIGNAL(addPluginGUI(QDockWidget*)),this,SLOT(addPluginInterface(QDockWidget*)));
91 92 connect(this->ManagePlugins,SIGNAL(triggered()),this,SLOT(launchPluginManager()));
92 93 connect(this->Quit,SIGNAL(triggered()),qApp,SLOT(quit()));
93 94 connect(this,SIGNAL(registerObject(QObject*,QString)),this->PythonConsoleInst,SLOT(registerObject(QObject*,QString)));
94 95 connect(socexplorerproxy::self(),SIGNAL(registerObject(QObject*,QString)),this,SIGNAL(registerObject(QObject*,QString)));
95 96 connect(this->pluginManager,SIGNAL(geteplugintree()),socexplorerproxy::self(),SLOT(geteplugintree()));
96 97 connect(socexplorerproxy::self(),SIGNAL(treeChanged(QList<socexplorerplugin*>)),this->pluginManager,SIGNAL(treeChanged(QList<socexplorerplugin*>)));
97 98 connect(this->pluginManager,SIGNAL(changeSysDriverInstName(QString,QString)),socexplorerproxy::self(),SLOT(changeSysDriverInstName(QString,QString)));
98 99 connect(this->pluginManager,SIGNAL(changeSysDriverInstName(QString,QString)),this->PythonConsoleInst,SLOT(changeSysDriverInstName(QString,QString)));
99 100 connect(this->pluginManager,SIGNAL(closeSysDriver(QString)),socexplorerproxy::self(),SLOT(closeSysDriver(QString)));
100 101 connect(this->pluginManager,SIGNAL(closeSysDriver(QString)),this->PythonConsoleInst,SLOT(removeDriver(QString)));
102 connect(this->pluginManager,SIGNAL(pluginselected(QString)),this,SLOT(pluginselected(QString)));
101 103 connect(this->about,SIGNAL(triggered()),this,SLOT(showAboutBox()));
102 104 connect(this->exploreRegs,SIGNAL(triggered()),this->regExplorer,SLOT(show()));
105
103 106 this->pluginManager->connect(this->pluginManager,SIGNAL(loadSysDrviver(QString)),socexplorerproxy::self(),SLOT(loadSysDriver(QString)));
104 107 this->pluginManager->connect(this->pluginManager,SIGNAL(loadSysDriverToParent(QString,QString)),socexplorerproxy::self(),SLOT(loadSysDriverToParent(QString,QString)));
105 108
106 109 }
107 110
108 111
109 112 void LPMONMainWindow::launchPluginManager()
110 113 {
111 114
112 115 if(this->pluginManager->isHidden())
113 116 {
114 117 this->pluginManager->setHidden(false);
115 118 }
116 119
117 120 }
118 121
119 122
120 123 void LPMONMainWindow::addPluginInterface(QDockWidget *plugin)
121 124 {
122 125 static QDockWidget* last=NULL;
123 126 plugin->setAllowedAreas(Qt::AllDockWidgetAreas);
124 127 this->pluginsDockContainer->addDockWidget(Qt::TopDockWidgetArea,plugin);
125 128 if(last!=NULL)
126 129 this->pluginsDockContainer->tabifyDockWidget(last,plugin);
127 130 last = plugin;
128 131
129 132 }
130 133
131 134
132 135 void LPMONMainWindow::clearMenu()
133 136 {
134 137 this->menuBar()->clear();
135 138 this->makeMenu();
136 139 }
137 140
138 141
139 142 void LPMONMainWindow::makeMenu()
140 143 {
141 144 this->FileMenu = menuBar()->addMenu(tr("&File"));
142 145 this->PluginsMenu = menuBar()->addMenu(tr("&Plugins"));
143 146 this->ToolsMenu = menuBar()->addMenu(tr("&Tools"));
144 147 this->ToolsMenu->addAction(this->exploreRegs);
145 148 this->FileMenu->addAction(this->Quit);
146 149 socexplorerproxy::self()->makeMenu(this->PluginsMenu);
147 150 this->PluginsMenu->addAction(this->ManagePlugins);
148 151
149 152 this->helpMenu = menuBar()->addMenu(tr("Help"));
150 153 this->helpMenu->addAction(this->help);
151 154 this->helpMenu->addAction(this->about);
152 155
153 156 }
154 157
155 158
156 159 LPMONMainWindow::~LPMONMainWindow()
157 160 {
158 161 delete this->p_about;
159 162 }
160 163
161 164
162 165 void LPMONMainWindow::setLangage(QAction *action)
163 166 {
164 167 QString local = action->data().toString();
165 168 QString qmPath = QDir(QString("translations")).absolutePath();
166 169 appTranslator->load(qmPath+"/socexplorer_"+local+".qm");
167 170 qApp->installTranslator(appTranslator);
168 171 emit this->translateSig();
169 172 }
170 173
171 174
172 175 void LPMONMainWindow::createLangMenu()
173 176 {
174 177 this->langMenu = menuBar()->addMenu(tr("&Langue"));
175 178 this->langActionGrp = new QActionGroup(this);
176 179 connect(this->langActionGrp,SIGNAL(triggered(QAction*)),this,SLOT(setLangage(QAction*)));
177 180 QDir* qmDir = new QDir(QString("translations"));
178 181 QStringList LangFiles = qmDir->entryList(QStringList("socexplorer_*.qm"));
179 182 for(int i=0;i<LangFiles.size();++i)
180 183 {
181 184 QString Local = LangFiles[i];
182 185 Local.remove(0,Local.indexOf('_')+1);
183 186 Local.chop(3);
184 187 QTranslator translator;
185 188 translator.load(LangFiles[i],qmDir->absolutePath());
186 189 QString langage = translator.translate("MainWindow","English");
187 190 QAction *action = new QAction(tr("&%1 %2").arg(i+1).arg(langage),this);
188 191 action->setCheckable(true);
189 192 action->setData(Local);
190 193 langMenu->addAction(action);
191 194 langActionGrp->addAction(action);
192 195 if(langage==tr("English"))
193 196 action->setChecked(true);
194 197 }
195 198 }
196 199
197 200
198 201 void LPMONMainWindow::updateText()
199 202 {
200 203 emit this->translateSig();
201 204 }
202 205
203 206
204 207
205 208 void LPMONMainWindow::showAboutBox()
206 209 {
207 210 p_about->show();
208 211 }
209 212
213 void LPMONMainWindow::pluginselected(const QString &instanceName)
214 {
215 socexplorerplugin* drv=socexplorerproxy::self()->getSysDriver(instanceName);
216 // if(drv)
217 // drv->activate(true);
218 // TODO add plugin widget auto focus
219 }
220
210 221
211 222
212 223 void LPMONMainWindow::closeEvent(QCloseEvent *event)
213 224 {
214 225 socexplorerproxy::self()->close();
215 226 qApp->closeAllWindows();
216 227 event->accept();
217 228 }
218 229
219 230
220 231
221 232
222 233
223 234
@@ -1,85 +1,85
1 1 /*------------------------------------------------------------------------------
2 2 -- This file is a part of the SocExplorer Software
3 3 -- Copyright (C) 2011, Laboratory of Plasmas Physic - CNRS
4 4 --
5 5 -- This program is free software; you can redistribute it and/or modify
6 6 -- it under the terms of the GNU General Public License as published by
7 7 -- the Free Software Foundation; either version 2 of the License, or
8 8 -- (at your option) any later version.
9 9 --
10 10 -- This program is distributed in the hope that it will be useful,
11 11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 13 -- GNU General Public License for more details.
14 14 --
15 15 -- You should have received a copy of the GNU General Public License
16 16 -- along with this program; if not, write to the Free Software
17 17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 18 -------------------------------------------------------------------------------*/
19 19 /*-- Author : Alexis Jeandet
20 20 -- Mail : alexis.jeandet@lpp.polytechnique.fr
21 21 ----------------------------------------------------------------------------*/
22 22 #ifndef MAINWINDOW_H
23 23 #define MAINWINDOW_H
24 24
25 25 #include <QMainWindow>
26 26 #include <QApplication>
27 27 #include <QVBoxLayout>
28 28 #include <QIcon>
29 29 #include <QMenuBar>
30 30 #include <QMenu>
31 31 #include <QAction>
32 32 #include <QDockWidget>
33 33 #include <QTranslator>
34 34 #include <QSplitter>
35 35 #include "dockablepluginmanager.h"
36 36 #include <socexplorerproxy.h>
37 37 #include "PyWdgt/pythonconsole.h"
38 38 #include "aboutsocexplorer.h"
39 39 #include "toolbar.h"
40 40 #include "regsExplorer/regsexplorer.h"
41 41
42 42 class LPMONMainWindow : public QMainWindow
43 43 {
44 44 Q_OBJECT
45 45
46 46 public:
47 47 LPMONMainWindow(QString ScriptToEval,QWidget *parent = 0);
48 48 ~LPMONMainWindow();
49 49 QAction* Quit,*LoadPlugin,*ManagePlugins,*help,*regsManager,*exploreRegs,*about,*translateAction;
50 50 QActionGroup*langActionGrp;
51 51 QMenu* FileMenu,*PluginsMenu,*ToolsMenu,*langMenu,*helpMenu;
52 52 QTranslator* appTranslator;
53 53 void createLangMenu();
54 54 void closeEvent(QCloseEvent *event);
55 55 toolBar* toolpane;
56 56
57 57
58 58 public slots:
59 59 void launchPluginManager();
60 60 void addPluginInterface(QDockWidget* plugin);
61 61 void clearMenu();
62 62 void updateText();
63 63 void setLangage(QAction* action);
64 64 void showAboutBox();
65
65 void pluginselected(const QString& instanceName);
66 66
67 67 signals:
68 68 void translateSig();
69 69 void registerObject(QObject* object,const QString& instanceName);
70 70
71 71 private:
72 72 void makeObjects(QString ScriptToEval);
73 73 void makeLayout();
74 74 void makeConnections();
75 75 void makeMenu();
76 76 QMainWindow* pluginsDockContainer;
77 77 QSplitter* mainWidget;
78 78 PythonConsole* PythonConsoleInst;
79 79 dockablePluginManager* pluginManager;
80 80 regsExplorer* regExplorer;
81 81 aboutsocexplorer* p_about;
82 82
83 83 };
84 84
85 85 #endif // MAINWINDOW_H
General Comments 0
You need to be logged in to leave comments. Login now