Skip to content
Snippets Groups Projects
Commit 388af5d7 authored by Sacha Percot-Tétu's avatar Sacha Percot-Tétu
Browse files

Operation is an abstract class representing an image

processing
operation. It overloads the application operator, retrieve
input data
from the end-user, call the pure virtual method operation and
output
some data to the end-user.
parent afbb62aa
No related branches found
No related tags found
No related merge requests found
#include <QDialog>
#include <QWidget>
#include <QVBoxLayout>
#include <QPushButton>
#include "Operation.h"
using namespace std;
using namespace imagein;
Operation::Operation(string name) : _name(name), _needCurrentImg(false), _currentImg(NULL) {
}
std::string Operation::getName() {
return _name;
}
void Operation::addInput(Input* input) {
this->_inputs.push_back(input);
}
void Operation::addInput(const Input& input) {
this->_inputs.push_back(input.clone());
}
void Operation::addOutput(const Output& output) {
_outputs.push_back(output.clone());
}
std::vector<QWidget*> Operation::operator()(const Image* currentImg) {
vector<QWidget*> result;
if(this->needCurrentImg()) {
if(currentImg==NULL) return result;
*_currentImg = *currentImg;
}
if(_inputs.size()>0) {
QDialog* dialog = new QDialog();
dialog->setWindowTitle("Paramtres");
dialog->setMinimumWidth(160);
QVBoxLayout* layout = new QVBoxLayout();
dialog->setLayout(layout);
for(vector<Input*>::iterator it = _inputs.begin(); it < _inputs.end(); ++it) {
(*it)->fillDialog(dialog);
}
QPushButton *okButton = new QPushButton("Valider", dialog);
okButton->setDefault(true);
layout->addWidget(okButton);
QObject::connect(okButton, SIGNAL(clicked()), dialog, SLOT(accept()));
QDialog::DialogCode code = static_cast<QDialog::DialogCode>(dialog->exec());
cout << code << endl;
if(code!=QDialog::Accepted) {
return result;
}
for(vector<Input*>::iterator it = _inputs.begin(); it < _inputs.end(); ++it) {
(*it)->pickValue();
}
}
_outputs.clear();
this->operation();
for(vector<Output*>::iterator it = _outputs.begin(); it < _outputs.end(); ++it) {
result.push_back((*it)->getWidget());
}
return result;
}
\ No newline at end of file
#ifndef EIIMAGE_OPERATION_H
#define EIIMAGE_OPERATION_H
#include <vector>
#include <string>
#include "Input.h"
#include "Parameter.h"
#include "Output.h"
#include "Image.h"
class QWidget;
struct CurrentImg {
};
class Operation {
private:
template<class D, class B> struct Derived_from {
static void constraints(D* p) { B* pb = p; }
Derived_from() { void(*p)(D*) = constraints; }
};
public:
Operation(std::string name);
std::vector<QWidget*> operator()(const imagein::Image*);
std::string getName();
inline bool needCurrentImg() { return _needCurrentImg; }
protected:
virtual void operation() = 0;
void addInput(Input* input);
void addInput(const Input& input);
void addOutput(const Output& output);
template<typename T, class C>
void addParam(const Parameter<T>& param, T C::* ptr) {
Derived_from<C, Operation>();
C* object = dynamic_cast<C*>(this);
if(object==NULL) {
throw "The parameter's pointer doesn't belong to the class which add it";
}
Parameter<T>* newParam = param.clone();
newParam->_ptr = &(object->*ptr);
this->_inputs.push_back(newParam);
}
template<class C>
void addParam(const CurrentImg&, imagein::Image C::* ptr) {
Derived_from<C, Operation>();
C* object = dynamic_cast<C*>(this);
if(object==NULL) {
throw "The parameter's pointer doesn't belong to the class which add it";
}
_needCurrentImg = true;
_currentImg = &(object->*ptr);
}
private:
std::string _name;
std::vector<Input*> _inputs;
std::vector<Output*> _outputs;
bool _needCurrentImg;
imagein::Image* _currentImg;
};
#endif //!EIIMAGE_OPERATION_H
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment