# HG changeset patch # User Jeandet Alexis # Date 2014-06-16 08:07:35 # Node ID 97ad912ad63cabfa55747d7c8f685c400f078ab5 # Parent 882bf2891037e7955cd2cde51d9c88ea96fe0730 Added Missing files diff --git a/src/common/genericBinaryFiles/BinFile/binaryfile.cpp b/src/common/genericBinaryFiles/BinFile/binaryfile.cpp new file mode 100644 --- /dev/null +++ b/src/common/genericBinaryFiles/BinFile/binaryfile.cpp @@ -0,0 +1,175 @@ +/*------------------------------------------------------------------------------ +-- This file is a part of the SocExplorer Software +-- Copyright (C) 2014, Plasma Physics Laboratory - CNRS +-- +-- This program is free software; you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as published by +-- the Free Software Foundation; either version 2 of the License, or +-- (at your option) any later version. +-- +-- This program is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU General Public License for more details. +-- +-- You should have received a copy of the GNU General Public License +-- along with this program; if not, write to the Free Software +-- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +-------------------------------------------------------------------------------*/ +/*-- Author : Alexis Jeandet +-- Mail : alexis.jeandet@member.fsf.org +----------------------------------------------------------------------------*/ +#include "binaryfile.h" +#include "srecfile.h" + +binaryFile::binaryFile() +{ +} + +binaryFile::binaryFile(const QString &File) +{ + openFile(File); +} + +binaryFile::binaryFile(const QStringList &Files) +{ + openFiles(Files); +} + +binaryFile::~binaryFile() +{ + +} + +bool binaryFile::openFile(const QString &File) +{ + return openFiles(QStringList()<p_files.append(new QFile(Files.at(i))); + this->p_files.at(i)->open(QIODevice::ReadOnly); + loadFile(this->p_files.at(i)); + } + return true; +} + +bool binaryFile::isopened() +{ + bool opened = true; + for(int i=0;ip_files.count();i++) + { + opened &= p_files.at(i)->isOpen(); + } + return opened; +} + +int binaryFile::closeFile() +{ + for(int i=0;iheader == p_files.at(i)->fileName()) + { + codeFragment* fragment = p_fragments.at(j); + p_fragments.removeAt(j); + delete fragment; + } + } + } + p_files.clear(); + p_fileName.clear(); + return 0; +} + +QList binaryFile::getFragments() +{ + return p_fragments; +} + +int binaryFile::getFragmentsCount() +{ + return p_fragments.count(); +} + +int binaryFile::getFragmentAddress(int index) +{ + if((index>=0)&&(indexaddress; + return 0; +} + +int binaryFile::getFragmentSize(int index) +{ + if((index>=0)&&(indexsize; + return 0; +} + +QString binaryFile::getFragmentHeader(int index) +{ + if((index>=0)&&(indexheader; + return ""; +} + +codeFragment *binaryFile::getFragment(int index) +{ + if((index>=0)&&(index=0)&&(indexdata; + return true; + } + return false; +} + +bool binaryFile::toSrec(const QString &fileName) +{ + srecFile::toSrec(p_fragments,fileName); +} + +bool binaryFile::toBinary(const QString &fileName) +{ + toBinary(p_fragments,fileName); +} + +bool binaryFile::toBinary(QList fragments, const QString &File) +{ + QFile file(File); + file.open(QIODevice::WriteOnly); + if(file.isOpen()) + { + for(int i=0;idata,fragments.at(i)->size); + } + return true; + } + return false; +} + +void binaryFile::loadFile(QFile *file) +{ + if (file->isOpen()) + { + codeFragment* fragment = new codeFragment(); + fragment->header = file->fileName(); + fragment->address = 0; + fragment->size = file->size(); + fragment->data = (char*)malloc(file->size()); + file->read(fragment->data,file->size()); + p_fragments.append(fragment); + } +} diff --git a/src/common/genericBinaryFiles/BinFile/binaryfile.h b/src/common/genericBinaryFiles/BinFile/binaryfile.h new file mode 100644 --- /dev/null +++ b/src/common/genericBinaryFiles/BinFile/binaryfile.h @@ -0,0 +1,64 @@ +/*------------------------------------------------------------------------------ +-- This file is a part of the SocExplorer Software +-- Copyright (C) 2014, Plasma Physics Laboratory - CNRS +-- +-- This program is free software; you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as published by +-- the Free Software Foundation; either version 2 of the License, or +-- (at your option) any later version. +-- +-- This program is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU General Public License for more details. +-- +-- You should have received a copy of the GNU General Public License +-- along with this program; if not, write to the Free Software +-- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +-------------------------------------------------------------------------------*/ +/*-- Author : Alexis Jeandet +-- Mail : alexis.jeandet@member.fsf.org +----------------------------------------------------------------------------*/ +#ifndef BINARYFILE_H +#define BINARYFILE_H +#include "abstractbinfile.h" +#include +#include +#include +#include +#include + +class binaryFile : public abstractBinFile +{ + Q_OBJECT +public: + explicit binaryFile(); + binaryFile(const QString& File); + binaryFile(const QStringList& Files); + ~binaryFile(); + bool openFile(const QString& File); + bool openFiles(const QStringList& Files); + bool isopened(); + int closeFile(); + QList getFragments(); + int getFragmentsCount(); + int getFragmentAddress(int index); + int getFragmentSize(int index); + QString getFragmentHeader(int index); + codeFragment* getFragment(int index); + bool getFragmentData(int index, char **buffer); + bool toSrec(const QString& fileName); + bool toBinary(const QString& fileName); + static bool toBinary(QList fragments,const QString& File); +signals: + +public slots: + +private: + void loadFile(QFile *file); + QStringList p_fileNames; + QListp_files; + QList p_fragments; +}; + +#endif // BINARYFILE_H diff --git a/src/common/genericBinaryFiles/BinFile/binaryfilewidget.cpp b/src/common/genericBinaryFiles/BinFile/binaryfilewidget.cpp new file mode 100644 --- /dev/null +++ b/src/common/genericBinaryFiles/BinFile/binaryfilewidget.cpp @@ -0,0 +1,150 @@ +#include "binaryfilewidget.h" +#include "ui_binaryfilewidget.h" +#include "qtablewidgetintitem.h" +#include +#include +#include "srecfile.h" + +binaryFileWidget::binaryFileWidget(QWidget *parent) : + abstractBinFileWidget(parent), + ui(new Ui::binaryFileWidget) +{ + ui->setupUi(this); + connect(this->ui->fragmentList,SIGNAL(cellActivated(int,int)),this,SLOT(fragmentCellActivated(int,int))); + connect(this->ui->fragmentList,SIGNAL(cellChanged(int,int)),this,SLOT(fragmentCellChanged(int,int))); + exportToSREC_action = new QAction(tr("Export to SREC"),this); + exportToBIN_action = new QAction(tr("Export to Binary"),this); + this->ui->fragmentList->addAction(exportToBIN_action); + this->ui->fragmentList->addAction(exportToSREC_action); + connect(this->exportToBIN_action,SIGNAL(triggered()),this,SLOT(exportToBIN())); + connect(this->exportToSREC_action,SIGNAL(triggered()),this,SLOT(exportToSREC())); +} + +binaryFileWidget::~binaryFileWidget() +{ + delete ui; +} + +void binaryFileWidget::setFile(abstractBinFile *file) +{ + this->p_binfile = (binaryFile*)file; + if(p_binfile->isopened()) + { + reloadFile(); + } +} + +void binaryFileWidget::reloadFile() +{ + this->ui->fragmentList->clear(); + this->ui->fragmentList->setRowCount(p_binfile->getFragmentsCount()); + this->ui->fragmentList->setHorizontalHeaderLabels(QStringList()<<"File"<<"Size"<<"Address"); + for(int i=0;igetFragmentsCount();i++) + { + QTableWidgetItem *newItem = new QTableWidgetItem(p_binfile->getFragmentHeader(i)); + newItem->setFlags(newItem->flags() ^ Qt::ItemIsEditable); + this->ui->fragmentList->setItem(i, 0, newItem); + + newItem = (QTableWidgetItem*)new QTableWidgetIntItem(QString("%1").arg(p_binfile->getFragmentSize(i)),DecimalItem); + newItem->setFlags(newItem->flags() ^ Qt::ItemIsEditable); + this->ui->fragmentList->setItem(i, 1, newItem); + + newItem = (QTableWidgetItem*)new QTableWidgetIntItem(QString("0x%1").arg(p_binfile->getFragmentAddress(i),8,16).replace(" ","0"),HexaDecimalItem); +// newItem->setFlags(newItem->flags() ^ Qt::ItemIsEditable); + this->ui->fragmentList->setItem(i, 2, newItem); + + } + this->ui->fragmentList->resizeColumnsToContents(); +} + +void binaryFileWidget::fragmentCellActivated(int row, int column) +{ + Q_UNUSED(column) + char* buff=NULL; + int index = this->ui->fragmentList->item(row,0)->text().toInt(); + if(index!=-1) + { + this->p_binfile->getFragmentData(index,&buff); + this->ui->hexViewer->setData(QByteArray(buff,this->p_binfile->getFragmentSize(index))); + this->ui->hexViewer->setAddressOffset(this->p_binfile->getFragmentAddress(index)); + } +} + +void binaryFileWidget::fragmentCellChanged(int row, int column) +{ + if(column==2) + { + QString newAddressStr = this->ui->fragmentList->item(row,column)->text(); + int newAddress = 0; + newAddressStr.remove(" "); + if(newAddressStr.at(0)=='0' && newAddressStr.at(1)=='x') + { + newAddress = newAddressStr.remove("0x").toUInt(0,16); + } + else + { + newAddress = newAddressStr.toUInt(); + } + this->p_binfile->getFragments().at(row)->address = newAddress; + } +} + +void binaryFileWidget::exportToSREC() +{ + QList SelectedFragmentsList=getSelectedFragments(); + if(SelectedFragmentsList.count()>0) + { + QString fileName = QFileDialog::getSaveFileName(this, tr("Save File"), + NULL, + tr("SREC Files (*.srec)")); + if(!fileName.isEmpty()) + { + srecFile::toSrec(SelectedFragmentsList,fileName); + } + } +} + +void binaryFileWidget::exportToBIN() +{ + QList SelectedFragmentsList=getSelectedFragments(); + if(SelectedFragmentsList.count()>0) + { + QString fileName = QFileDialog::getSaveFileName(this, tr("Save File"), + NULL, + tr("Binary Files (*.bin)")); + if(!fileName.isEmpty()) + { + binaryFile::toBinary(SelectedFragmentsList,fileName); + } + } +} + +QStringList binaryFileWidget::getSelectedFilesNames() +{ + QStringList SelectedFilesList; + QList items = this->ui->fragmentList->selectedItems(); + for(int i=0;igetFragmentHeader(items.at(i)->row()); + if(!SelectedFilesList.contains(file)) + { + SelectedFilesList.append(file); + } + } + return SelectedFilesList; +} + +QList binaryFileWidget::getSelectedFragments() +{ + QList SelectedFragmentsList; + QList items = this->ui->fragmentList->selectedItems(); + for(int i=0;igetFragment(items.at(i)->row()); + if(!SelectedFragmentsList.contains(fragment)) + { + SelectedFragmentsList.append(fragment); + } + } + return SelectedFragmentsList; +} diff --git a/src/common/genericBinaryFiles/BinFile/binaryfilewidget.h b/src/common/genericBinaryFiles/BinFile/binaryfilewidget.h new file mode 100644 --- /dev/null +++ b/src/common/genericBinaryFiles/BinFile/binaryfilewidget.h @@ -0,0 +1,60 @@ +/*------------------------------------------------------------------------------ +-- This file is a part of the SocExplorer Software +-- Copyright (C) 2014, Plasma Physics Laboratory - CNRS +-- +-- This program is free software; you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as published by +-- the Free Software Foundation; either version 2 of the License, or +-- (at your option) any later version. +-- +-- This program is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU General Public License for more details. +-- +-- You should have received a copy of the GNU General Public License +-- along with this program; if not, write to the Free Software +-- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +-------------------------------------------------------------------------------*/ +/*-- Author : Alexis Jeandet +-- Mail : alexis.jeandet@member.fsf.org +----------------------------------------------------------------------------*/ +#ifndef BINARYFILEWIDGET_H +#define BINARYFILEWIDGET_H + +#include +#include "binaryfile.h" +#include + +namespace Ui { +class binaryFileWidget; +} + +class binaryFileWidget : public abstractBinFileWidget +{ + Q_OBJECT + +public: + explicit binaryFileWidget(QWidget *parent = 0); + ~binaryFileWidget(); + +public slots: + void setFile(abstractBinFile* file); + void reloadFile(); + +private slots: + void fragmentCellActivated(int row, int column); + void fragmentCellChanged(int row, int column); + void exportToSREC(); + void exportToBIN(); + +private: + QStringList getSelectedFilesNames(); + QList getSelectedFragments(); + Ui::binaryFileWidget *ui; + binaryFile* p_binfile; + QAction* exportToSREC_action; + QAction* exportToBIN_action; +}; + +#endif // BINARYFILEWIDGET_H diff --git a/src/common/genericBinaryFiles/BinFile/binaryfilewidget.ui b/src/common/genericBinaryFiles/BinFile/binaryfilewidget.ui new file mode 100644 --- /dev/null +++ b/src/common/genericBinaryFiles/BinFile/binaryfilewidget.ui @@ -0,0 +1,64 @@ + + + binaryFileWidget + + + + 0 + 0 + 637 + 342 + + + + Form + + + + + + Qt::Horizontal + + + + + 200 + 0 + + + + + + Qt::ActionsContextMenu + + + + File + + + + + Size + + + + + Address + + + + + + + + + + QHexEdit + QWidget +
qhexedit.h
+ 1 +
+
+ + +