#!/usr/bin/perl # # $Id$ # # This file is part of the Virtual Leaf. # # The Virtual Leaf 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 3 of the License, or # (at your option) any later version. # # The Virtual Leaf 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 the Virtual Leaf. If not, see . # # Copyright 2010 Roeland Merks. # # input: parameter file + types # format: par_name = default_value/type # output: C++ source code of class Parameter # and sample parameter file %funname = ( "double" => "toDouble", "int" => "toInt", ); %typetrans = ( "double" => "double", "float" => "double", "int" => "int", "bool" => "bool", "char *" => "char *", "string" => "char *", "directory" => "char *", "doublelist" => "double *", "label" => "label", "title" => "title", ); $basename = "pardialog"; open parfile,"<$ARGV[0]"; open cppfile,">$basename.cpp"; $i=0; while () { if (/^#/) { next; } @line=split(/=/); #ignore empty lines if ($#line<1) { next; } $param[$i]=$line[0]; $value_type=$line[1]; @typel=split(/ \/ /,$value_type); $value[$i] = $typel[0]; $type[$i] = $typel[1]; #get rid of spaces $type[$i] =~ s/ //g; $type[$i] =~s/\n//g; $convtype[$i]=$typetrans{$type[$i]}; $param[$i] =~ s/ //g; if ($convtype[$i] ne "label" && $convtype[$i] ne "title") { #get rid of spaces $value[$i] =~ s/ //g; } if ($convtype[$i] eq "char *") { $value[$i] = "\"$value[$i]\""; } #print cppfile "param = $param, value = $value, type = $type\n"; $i++; } $lines=$i; print cppfile <. * * Copyright 2010 Roeland Merks. * */ // WARNING: This file is automatically generated by make_parameter_source.pl. Do not edit. // Do not edit. All edits will be discarded. #include "$basename.h" #include "parameter.h" #include #include #include #include #include static const std::string _module_id("\$Id\$"); ParameterDialog::ParameterDialog(QWidget *parent, const char *name, Qt::WindowFlags f) : QDialog(parent,name,false,f) { extern Parameter par; END_HEADER for ($i=0;$i<$lines;$i++) { if ($convtype[$i] eq "label" || $convtype[$i] eq "title") { next; } if ($convtype[$i] eq "double *") { print cppfile " QString $param[$i]_string(\""; @paramlist = split(/,/,$value[$i]); for ($j=1;$j<=$#paramlist;$j++) { print cppfile "%$j,"; } print cppfile "%$j\");\n"; print cppfile " $param[$i]_string = $param[$i]_string"; for ($j=0;$j<=$#paramlist;$j++) { print cppfile ".arg(par.$param[$i]\[$j\])"; } print cppfile ";\n"; print cppfile " $param[$i]_edit = new QLineEdit( $param[$i]_string, this, \"$param[$i]_edit\" );\n"; } else { if ($convtype[$i] eq "bool") { print cppfile " $param[$i]_edit = new QLineEdit( QString(\"%1\").arg(sbool(par.$param[$i])), this, \"$param[$i]_edit\" );\n"; } else { print cppfile " $param[$i]_edit = new QLineEdit( QString(\"%1\").arg(par.$param[$i]), this, \"$param[$i]_edit\" );\n"; } } } print cppfile <addWidget( new QLabel( \"$value[$i]\", this), $row, $col, 1, 2 );\n"; $c++; } else { if ($convtype[$i] eq "title") { if ($ntitles) { print stderr "Sorry, only one title allowed. Aborting source construction...\n"; exit(1); } print cppfile " setWindowTitle( QString( \"$value[$i]\") );\n"; print cppfile " grid->addWidget( new QLabel( \"

$value[$i]

\",this), $row, $col, 1, -1, Qt::AlignCenter);\n"; print cppfile " grid->addWidget( new QLabel( \"\", this), $row+1, $col, 1, -1);\n"; $ntitles++; } else { print cppfile " grid->addWidget( new QLabel( \"$param[$i]\", this ),$row, $col );\n"; print cppfile " grid->addWidget( $param[$i]_edit, $row, $col+1 );\n"; $c++; } } } $row = $numrows+1; $col = 2*int($i/$numrows); print cppfile <addWidget(pb, $row, $col ); connect( pb, SIGNAL( clicked() ), this, SLOT( write() ) ); QPushButton *pb2 = new QPushButton( \"&Close\", this ); grid->addWidget(pb2,$row, $col+1 ); connect( pb2, SIGNAL( clicked() ), this, SLOT( close() ) ); QPushButton *pb3 = new QPushButton( \"&Reset\", this ); grid->addWidget(pb3, $row, $col+2 ); connect( pb3, SIGNAL( clicked() ), this, SLOT( Reset() ) ); show(); }; ParameterDialog::~ParameterDialog(void) { ANOTHER_LABEL for ($i=0;$i<$lines;$i++) { if ($convtype[$i] ne "label" && $convtype[$i] ne "title") { print cppfile "delete $param[$i]_edit;\n"; } } print cppfile <text().section(',', $j, $j);\n"; print cppfile " par.$param[$i]\[$j\] = tmpval.toDouble();\n"; } } else { if ($convtype[$i] eq "bool") { print cppfile " tmpval = $param[$i]_edit->text().stripWhiteSpace();\n"; print cppfile " if (tmpval == \"true\" || tmpval == \"yes\" ) par.$param[$i] = true;\n"; print cppfile " else if (tmpval == \"false\" || tmpval == \"no\") par.$param[$i] = false;\n"; print cppfile " else {\n"; print cppfile " if (QMessageBox::question(this, \"Syntax error\", tr(\"Value %1 of parameter %2 is not recognized as Boolean.\\nDo you mean TRUE or FALSE?\").arg(tmpval).arg(\"$param[$i]\"),\"True\",\"False\", QString::null, 0, 1)==0) par.$param[$i]=true;\n"; print cppfile " else par.$param[$i]=false;\n"; print cppfile " }\n"; } else { if ($convtype[$i] eq "char *") { print cppfile " par.$param[$i] = strdup((const char *)$param[$i]_edit->text());\n"; } else { print cppfile " par.$param[$i] = $param[$i]_edit->text().$funname{$convtype[$i]}();\n"; } } } } print cppfile <setText( $param[$i]_string );\n"; } else { if ($convtype[$i] eq "bool") { print cppfile " $param[$i]_edit->setText( QString(\"%1\").arg(sbool(par.$param[$i])));\n"; } else { print cppfile " $param[$i]_edit->setText( QString(\"%1\").arg(par.$param[$i]) );\n"; } } } print cppfile "}\n\n"; # qparameter.h open hfile, ">$basename.h"; print hfile <. * * Copyright 2010 Roeland Merks. * */ // WARNING: This file is automatically generated by make_parameter_source.pl. Do not edit. // Do not edit. All edits will be discarded. #ifndef PARAMETER_DIALOG_H #define PARAMETER_DIALOG_H #include #include #include #include #include #include class ParameterDialog : public QDialog { Q_OBJECT public: ParameterDialog(QWidget *parent=0, const char *name = 0, Qt::WindowFlags f = 0); virtual ~ParameterDialog(void); public slots: void Reset(void); private slots: void write(void); private: END_HEADER2 for ($i=0;$i<$lines;$i++) { if ($convtype[$i] ne "label" && $convtype[$i] ne "title") { print hfile " QLineEdit *$param[$i]_edit;\n"; } } print hfile <