Commit e3c63438 authored by cfouard's avatar cfouard
Browse files

FIXED argv[2] in actionstatemachine

FIXED (partially fixed) LUT on double (not fully fixed, integer parameters remain to be changed into double).
FIXED Wizard now use .in files to create CMake, Action and Extension classes. Components class remains to be .in generated
FIXED several Wizard Bugs

git-svn-id: svn+ssh://scm.forge.imag.fr/var/lib/gforge/chroot/scmrepos/svn/camitk/trunk/camitk@143 ec899d31-69d1-42ba-9299-647d76f65fb3
parent 98ecd85e
......@@ -105,14 +105,20 @@ void ImageLutWidget::updateComponent(ImageComponent * comp) {
// initialize the sliders value
// int nbOfColors = myComponent->getLut()->GetNumberOfTableValues();
double imgMinColor = myComponent->getImageData()->GetScalarTypeMin();
double imgMaxColor = myComponent->getImageData()->GetScalarTypeMax();
double * imgRange = myComponent->getImageData()->GetScalarRange();
double imgMinColor = imgRange[0];
double imgMaxColor = imgRange[1];
// double imgMinColor = myComponent->getImageData()->get GetScalarTypeMin();
// double imgMaxColor = myComponent->getImageData()->GetScalarTypeMax();
double nbColorsOrg = imgMaxColor - imgMinColor;
long int nbOfColors = (long int) (nbColorsOrg);
// as this widget is only grayscale, compute the average of the color values
lutMin = myComponent->getImageData()->GetScalarTypeMin();
lutMax = myComponent->getImageData()->GetScalarTypeMax();
// lutMin = myComponent->getImageData()->GetScalarTypeMin();
// lutMax = myComponent->getImageData()->GetScalarTypeMax();
lutMin = imgMinColor;
lutMax = imgMaxColor;
blockAllSignals ( true );
initLevelGUI(lutMin, lutMax, myComponent->getLut()->GetLevel());
......
This diff is collapsed.
#include "ElementGenerator.h"
//#include "ElementGenerator.h"
// include from STD
#include <set>
// includes from Qt
#include <QMap>
#include <QDir>
#include <QPair>
#include <QString>
#include <QFileInfo>
#include <QTextStream>
#include <Parameters.hxx>
#include <Action.hxx>
#ifndef ACTIONGENERATOR_H
......@@ -6,40 +19,57 @@
using namespace coreschema;
class ActionGenerator : public ElementGenerator {
class ActionGenerator {
public :
static bool generateActionFiles(QString xmlFileName, QString devDirectoryName, QString * elementClassName = NULL);
protected:
ActionGenerator(QString xmlFilename, QString devDirectoryName);
// Inherited from ElementGenerator
virtual void setXmlFileName(QString xmlFileName) throw (QString);
virtual void setDevDirectoryName(QString devDirectoryName) throw (QString);
virtual void createElement() throw (QString);
virtual void generateActionFiles() throw (QString);
virtual void writeDeclareConstructor();
virtual void writeHFile() throw (QString);
virtual void writeCFile() throw (QString);
virtual void writeImplementationFile() throw (QString);
virtual void writeDeclareSpecificMethods();
virtual void specialHDeclare();
/** XML DOM Element create by CodeSynthesis
* This action contains all of the informations of the xml file
*/
std::auto_ptr<Action> theAction;
virtual void writeConstructor();
virtual void writeDestructor();
virtual void writeSpecificCMethods();
/// Where to find the XML description of the Action
QFileInfo xmlFileName;
virtual void writeElementImplementationFile() throw (QString);
virtual void writeSpecificITKImplementation();
/// Where to store the produced files
QDir devDirectoryName;
// Re-implementation
virtual void writeDeclareParametersAttributes();
/// Name of the created Action class
/// redundant information already contained in theAction, for practicle purpose.
QString className;
/// Does the action have parameters stored as properties ?
bool hasParameters;
/** List containing all parameters of the action stored as properties of theAction
* For practical reasons, this map contains for each parameter:
* - key: the name of the parameter
* - value: a QPair of element:
* - first: the type of the parameter
* - second: the default value of the parameter
* (if non exists in the XML file, a default one is given)
*/
QMap<QString, QPair<QString, QString>> parameters;
// Specific methods
void writeDeclareGetWidget();
void writeDeclareApply();
void writeApply();
std::auto_ptr<Action> theAction;
/// Set of additional files to include
std::set<QString> additionalIncludes;
private:
bool isItkFilter;
// bool hasImplementationFile;
};
#endif
This diff is collapsed.
#include "ElementGenerator.h"
//#include "ElementGenerator.h"
#include <Component.hxx>
......@@ -7,7 +7,8 @@
using namespace coreschema;
class ComponentGenerator : public ElementGenerator {
class ComponentGenerator {
/*
public :
enum RepresentationType {
......@@ -38,7 +39,7 @@ protected:
std::auto_ptr<Component> theComponent;
RepresentationType representation;
*/
};
#endif
#include "ElementGenerator.h"
// Includes from Qt
#include <QTextStream>
#include <QDate>
#include <QTime>
// includes from std
#include <iostream>
#include <Parameter.hxx>
#include <ParameterType.hxx>
using namespace coreschema;
ElementGenerator::ElementGenerator(QString xmlFilename, QString devDirectoryName) {
out = NULL;
name = QString("element");
elementClassName = QString("");
parentClass = QString("");
hasParameters = false;
hasSpecialHDeclare = false;
hasImplementationFile = false;
theParams = Parameters::parameter_sequence();
setXmlFileName(xmlFilename);
setDevDirectoryName(devDirectoryName);
}
void ElementGenerator::setXmlFileName(QString xmlFileName) throw (QString) {
QFileInfo xmlFile(xmlFileName);
if ((! xmlFile.exists()) || (! xmlFile.isFile())) {
QString msg = "Exception from " + name + " generation: \n The file " + xmlFileName + " does not exist or is not a file...\n";
throw (msg);
}
this->xmlFileName = xmlFile;
// TODO manage exception (despite Qt...).
// TODO find how to read an xml file with an absolute path !!!
std::string xmlFileStr = this->xmlFileName.canonicalFilePath().toStdString();
}
void ElementGenerator::setDevDirectoryName(QString devDirectoryName) throw (QString) {
QFileInfo devDir(devDirectoryName);
if ( ! devDir.isDir()) {
QString msg = "Exception from action generation: \n The path " + devDirectoryName + " is not a directory\n";
throw (msg);
}
this->devDirectoryName.cd(devDirectoryName);
}
void ElementGenerator::generateElementFiles() throw (QString) {
// Generating .h
QFileInfo extFileHPath;
extFileHPath.setFile(this->devDirectoryName, elementClassName + ".h");
QFile extFileH(extFileHPath.absoluteFilePath());
if (! extFileH.open(QIODevice::WriteOnly | QIODevice::Text)) {
QString msg = "Exception from " + name + " generation: \n Cannot write on file " + extFileHPath.fileName() + "\n";
throw (msg);
}
out = new QTextStream(&extFileH);
writeElementHFile();
extFileH.close();
delete out;
out = NULL;
// Generating .cpp
QFileInfo extFileCPath;
extFileCPath.setFile(this->devDirectoryName, elementClassName + ".cpp");
QFile extFileC(extFileCPath.absoluteFilePath());
if (! extFileC.open(QIODevice::WriteOnly | QIODevice::Text)) {
QString msg = "Exception from " + name + " generation: \n Cannot write on file " + extFileCPath.fileName() + "\n";
throw (msg);
}
out = new QTextStream(&extFileC);
writeElementCFile();
extFileC.close();
delete out;
out = NULL;
// Generating _implementation.h
if (hasImplementationFile) {
QFileInfo extFileImpPath;
extFileImpPath.setFile(this->devDirectoryName, elementClassName + "_implementation");
QFile extFileImpFile(extFileImpPath.absoluteFilePath());
if (! extFileImpFile.open(QIODevice::WriteOnly | QIODevice::Text)) {
QString msg = "Exception from " + name + " generation: \n Cannot write on file " + extFileImpFile.fileName() + "\n";
throw (msg);
}
out = new QTextStream(&extFileImpFile);
writeElementImplementationFile();
extFileImpFile.close();
delete out;
out = NULL;
}
}
void ElementGenerator::writeDeclareDestructor() {
(*out) << " /// Default Destructor" << endl;
(*out) << " virtual ~" << elementClassName << "();" << endl;
(*out) << endl;
}
void ElementGenerator::writeElementHFile() {
QString headdef = elementClassName.toUpper() + "_H";
(*out) << "#ifndef " << headdef << endl;
(*out) << "#define " << headdef << endl;
(*out) << endl;
(*out) << "#include <QObject>" << endl;
(*out) << "#include <" << parentClass << ".h>" << endl;
if (hasParameters)
if (hasSpecialHDeclare) {
specialHDeclare();
}
(*out) << endl;
(*out) << "using namespace camitk;" << endl;
(*out) << endl;
(*out) << "class " << elementClassName << " : public " << parentClass <<" {" << endl;
(*out) << endl;
writeDeclareQObject();
(*out) << endl;
(*out) << "public: " << endl;
writeDeclareConstructor();
writeDeclareDestructor();
writeDeclareSpecificMethods();
(*out) << "}; " << endl;
(*out) << "#endif // " << headdef << endl;
}
void ElementGenerator::writeElementCFile() {
(*out) << "#include \"" << elementClassName <<".h\"" << endl;
(*out) << endl;
// erase duplicates in the include
for (std::set<QString>::const_iterator it = this->additionalIncludes.begin();
it != additionalIncludes.end(); it++)
(*out) << "#include <" << (*it) << "> " << endl;
(*out) << endl;
(*out) << "using namespace camitk;" << endl;
(*out) << endl;
(*out) << endl;
writeConstructor();
writeDestructor();
writeSpecificCMethods();
}
void ElementGenerator::writeParametersInitialization() {
if (hasParameters) {
(*out) << " // Setting parameters default values" << endl;
for (Parameters::parameter_const_iterator it = theParams.begin(); it < theParams.end(); it++) {
QString parameterName = QString((*it).name().c_str());
QString parameterType = QString((*it).type().c_str());
QString parameterVal;
if ((*it).defaultValue().present()) {
parameterVal = QString((*it).defaultValue()->c_str());
}
else {
if (parameterType == "int")
parameterVal = "0";
else if (parameterType == "bool")
parameterVal = "false";
else if (parameterType == "double")
parameterVal = "0.0";
else if (parameterType == "QString")
parameterVal = "\"Hello World\"";
else if (parameterType == "QDate") {
QDate today = QDate::currentDate();
QString defValue;
QTextStream in(&defValue);
in << today.year() << ", " << today.month() << ", " << today.day();
parameterVal = defValue;
}
else if (parameterType == "QTime") {
QTime now = QTime::currentTime();
QString defValue;
QTextStream in(&defValue);
in << now.hour() << ", " << now.minute() << ", " << now.second();
parameterVal = defValue;
}
else if (parameterType == "QColor")
parameterVal = "255, 255, 255, 255";
else if (parameterType == "QPoint")
parameterVal = "0, 0";
else if (parameterType == "QPointF")
parameterVal = "0.0, 0.0";
else if (parameterType == "QVector3D")
parameterVal = "0.0, 0.0, 0.0";
}
(*out) << " " << "setProperty(\"" << parameterName << "\", QVariant(";
if ((parameterType == "int") || (parameterType == "double") || (parameterType == "bool") || (parameterType == "QString"))
(*out) << parameterVal << "));" << endl;
else
(*out) << parameterType << "(" << parameterVal << ")));" << endl;
}
}
}
// include from STD
#include <set>
// includes from Qt
#include <QString>
#include <QTextStream>
#include <QFileInfo>
#include <QDir>
#include <Parameters.hxx>
#ifndef ELEMENTGENERATOR_H
#define ELEMENTGENERATOR_H
using namespace coreschema;
class ElementGenerator {
protected:
ElementGenerator(QString xmlFilename, QString devDirectoryName);
virtual void setXmlFileName(QString xmlFileName) throw (QString);
virtual void setDevDirectoryName(QString devDirectoryName) throw (QString);
virtual void generateElementFiles() throw (QString);
virtual void writeElementImplementationFile() throw (QString) {};
virtual void writeElementHFile();
virtual void writeElementCFile();
/// this method adds a Q_OBJECT line or not (default), depending on the element, see derived classes
virtual void writeDeclareQObject() {};
virtual void writeDeclareDestructor();
virtual void writeDeclareConstructor() = 0;
virtual void writeDeclareSpecificMethods() {};
virtual void writeConstructor() = 0;
virtual void writeDestructor() = 0;
virtual void writeParametersInitialization();
virtual void writeSpecificCMethods() {};
virtual void specialHDeclare() {};
QFileInfo xmlFileName;
QDir devDirectoryName;
QString name;
// Redundant info to make writing easier
bool hasImplementationFile;
bool hasParameters;
bool hasSpecialHDeclare;
QString elementClassName;
QString parentClass;
QTextStream * out;
std::set<QString> additionalIncludes;
Parameters::parameter_sequence theParams;
};
#endif
......@@ -249,8 +249,13 @@ bool ExtTypeWindow::makeActionXML() {
std::string xml (oss.str ());
// Writing in the right xml file
QDir xmlDir(this->workingDirectory);
if (! xmlDir.exists("xml"))
xmlDir.mkdir("xml");
xmlDir.cd("xml");
QFileInfo xmlFileInfo;
xmlFileInfo.setFile(this->workingDirectory, qActionClassName + ".xml");
xmlFileInfo.setFile(xmlDir.absolutePath(), qActionClassName + ".xml");
QFile xmlFile(xmlFileInfo.absoluteFilePath());
if (! xmlFile.open(QIODevice::WriteOnly | QIODevice::Text)) {
QString msg = "Exception from action xml file generation \n Cannot write on file " + xmlFileInfo.absoluteFilePath() + "\n";
......@@ -320,8 +325,13 @@ bool ExtTypeWindow::makeComponentXML() {
std::string xml (oss.str ());
// Writing in the right xml file
QDir xmlDir(this->workingDirectory);
if (! xmlDir.exists("xml"))
xmlDir.mkdir("xml");
xmlDir.cd("xml");
QFileInfo xmlFileInfo;
xmlFileInfo.setFile(this->workingDirectory, qComponentClassName + ".xml");
xmlFileInfo.setFile(xmlDir.absolutePath(), qComponentClassName + ".xml");
QFile xmlFile(xmlFileInfo.absoluteFilePath());
if (! xmlFile.open(QIODevice::WriteOnly | QIODevice::Text)) {
QString msg = "Exception from action xml file generation \n Cannot write on file " + xmlFileInfo.absoluteFilePath() + "\n";
......
This diff is collapsed.
// includes from std
// includes from Qt
#include <QString>
#include <QFileInfo>
#include <QDir>
// Includes from coreschema
#include <Extension.hxx>
#ifndef EXTENSIONGENERATOR_H
#define EXTENSIONGENERATOR_H
using namespace coreschema;
class ExtensionGenerator {
public :
enum ExtensionType {
ACTION,
APPLICATION,
COMPONENT,
VIEWER,
UNKNOWN
};
static bool generateExtensionFiles(QString xmlFileName, QString devDirectoryName);
protected:
ExtensionGenerator(QString xmlFileName, QString devDirectoryName) throw (QString);
void setXmlFileName(QString xmlFileName) throw (QString);
void setDevDirectoryName(QString devDirectoryName) throw (QString);
void generateCMakeLists() throw (QString);
void generateExtensionFiles() throw (QString);
void generateInternFilesList() throw (QString);
void generateInternFiles() throw (QString);
void generateActionExtensionFiles() throw (QString);
void generateActionsList() throw (QString);
void generateActionFiles() throw (QString);
void generateComponentExtensionFiles() throw (QString);
void generateComponentsList() throw (QString);
void generateComponentFiles() throw (QString);
QFileInfo xmlFileName;
QDir devDirectoryName;
std::auto_ptr<Extension> theExtension;
ExtensionType type;
std::vector<QFileInfo> elementsList;
std::vector<QString> generatedClassList;
};
#endif
// includes from std
// includes from Qt
#include <QString>
#include <QFileInfo>
#include <QDir>
// Includes from coreschema
#include <Extension.hxx>
#ifndef EXTENSIONGENERATOR_H
#define EXTENSIONGENERATOR_H
using namespace coreschema;
class ExtensionGenerator {
public :
enum ExtensionType {
ACTION,
APPLICATION,
COMPONENT,
VIEWER,
UNKNOWN
};
static bool generateExtensionFiles(QString xmlFileName, QString devDirectoryName);
protected:
ExtensionGenerator(QString xmlFileName, QString devDirectoryName) throw (QString);
void setXmlFileName(QString xmlFileName) throw (QString);
void setDevDirectoryName(QString devDirectoryName) throw (QString);
void createTestDataFiles() throw (QString);
void generateCMakeLists() throw (QString);
void generateExtensionFiles() throw (QString);
void generateInternFilesList() throw (QString);
void generateInternFiles() throw (QString);
void generateActionExtensionFiles() throw (QString);
void generateActionsList() throw (QString);
void generateActionFiles() throw (QString);
void generateComponentExtensionFiles() throw (QString);
void generateComponentsList() throw (QString);
void generateComponentFiles() throw (QString);
void showReport();
void writeReport();
QFileInfo xmlFileName;
QDir devDirectoryName;
QDir srcDir;
std::auto_ptr<Extension> theExtension;
ExtensionType type;
std::vector<QFileInfo> elementsList;
std::vector<QString> generatedClassList;
};
#endif