Main Page | Namespace List | Data Structures | File List | Data Fields | Globals

inn.ui.h

Go to the documentation of this file.
00001 /****************************************************************************
00002 ** ui.h extension file, included from the uic-generated form implementation.
00003 **
00004 ** If you want to add, delete, or rename functions or slots, use
00005 ** Qt Designer to update this file, preserving your code.
00006 **
00007 ** You should not define a constructor or destructor in this file.
00008 ** Instead, write your code in functions called init() and destroy().
00009 ** These will automatically be called by the form's constructor and
00010 ** destructor.
00011 *****************************************************************************/
00012 
00013 # include <qtextedit.h>
00014 # include <qmessagebox.h>
00015 # include <qfile.h>
00016 # include <qtextstream.h>
00017 # include <qstring.h>
00018 # include <qstatusbar.h>
00019 # include <qfiledialog.h>
00020 
00021 # include <newnetworkwizard.h>
00022 # include <aboutdialog.h>
00023 # include <learningdialog.h>
00024 # include <testingdialog.h>
00025 # include <axon.h>
00026 # include <network.h>
00027 # include <networkparser.h>
00028 
00029 extern Network * network ;
00030 
00031 QString filename ;
00032 
00033 void Inn::init() {
00034     console->append("Welcome to INN") ;
00035 }
00036 
00037 void Inn::newNetworkWizard( void ) {
00038  if (network->nbNeurons() > 0) {
00039   switch( QMessageBox::question ( 
00040         this, 
00041         "New Network Wizard", 
00042         "Are you sure you wanna start a new network ?", 
00043         QMessageBox::Yes, 
00044         QMessageBox::No ) ) {
00045       case QMessageBox::Yes : 
00046        network->removeAxons();
00047     network->clearLayer(0) ;
00048     network->clearLayer(1) ;
00049     network->clearHiddenLayers() ;
00050        break ;
00051       case QMessageBox::No : 
00052        return ;
00053     }
00054         }
00055     NewNetworkWizard * wizard = new NewNetworkWizard(this) ;
00056     wizard->show() ;
00057 }
00058 
00059 
00060 void Inn::fileSaveAsSlot() {
00061     QString fn = QFileDialog::getSaveFileName( QString::null, QString::null,
00062                                                this );
00063     if ( !fn.isEmpty() ) {
00064         filename = fn;
00065         fileSaveSlot();
00066     } else {
00067         statusBar()->message( "Saving aborted", 2000 );
00068     }
00069 }
00070 
00071 
00072 void Inn::fileCloseSlot() {
00073   network->removeAxons();
00074   network->clearLayer(0) ;
00075   network->clearLayer(1) ;
00076   network->clearHiddenLayers() ;
00077 }
00078 
00079 
00080 void Inn::fileSaveSlot() {
00081     if ( filename.isEmpty() ) {
00082         fileSaveAsSlot();
00083         return;
00084     }
00085 
00086     QFile file( filename );
00087     if ( !file.open( IO_WriteOnly ) ) {
00088         statusBar()->message( QString("Could not write to %1").arg(filename), 2000 );
00089         return;
00090     }
00091     
00092     QString s ;
00093     list<Layer*>::iterator liter;
00094  list<Neuron*>::iterator niter;
00095  list<Axon*>::iterator aiter ;
00096 
00097  /* Writing the XML file in a textstream */
00098  QTextStream textstream( &file );
00099  textstream << "<!-- INN XML Network File v0.1 -->\n" ;
00100  textstream << "<!-- Julien Wintz & Pierre Kraemer -->\n" ;
00101     textstream << "<network>\n" ;
00102     textstream << "    <parameters>\n" ;
00103     QString k ; k.sprintf("        <sigmoid k=\"%f\"/>\n", network->getK()) ;
00104     textstream << k ;
00105     textstream << "    </parameters>\n" ;
00106     textstream << "    <layers>\n" ;
00107     
00108     /* Input layer */
00109     s.sprintf("        <layer id=\"%d\">\n", (int)network->getInputLayer()->getId()) ;
00110  textstream << s ;
00111     for (niter = network->getInputLayer()->getNeurons()->begin(); niter != network->getInputLayer()->getNeurons()->end(); niter++) {
00112      QString s1 ; s1.sprintf("            <neuron id=\"%d\" x=\"%f\" z=\"%f\"/>\n", (int)(*niter)->getId(), (*niter)->getX(), (*niter)->getZ()) ;
00113      textstream << s1 ;
00114     }
00115     textstream << "        </layer>\n" ;
00116     
00117     /* Hidden layers */
00118     for (liter = network->getHiddenLayers()->begin(); liter != network->getHiddenLayers()->end(); liter++) {
00119      s.sprintf("        <layer id=\"%d\">\n", (int)(*liter)->getId()) ;
00120      textstream << s ;
00121      list<Neuron*>::iterator niter;
00122      for (niter = (*liter)->getNeurons()->begin(); niter != (*liter)->getNeurons()->end(); niter++) {
00123       QString s1 ; s1.sprintf("            <neuron id=\"%d\" x=\"%f\" z=\"%f\"/>\n", (int)(*niter)->getId(), (*niter)->getX(), (*niter)->getZ()) ;
00124       textstream << s1 ;
00125      }
00126      textstream << "        </layer>\n" ;
00127     }
00128     
00129     /* Output layer */
00130     s.sprintf("        <layer id=\"%d\">\n", (int)network->getOutputLayer()->getId()) ;
00131  textstream << s ;
00132     for (niter = network->getOutputLayer()->getNeurons()->begin(); niter != network->getOutputLayer()->getNeurons()->end(); niter++) {
00133      QString s1 ; s1.sprintf("            <neuron id=\"%d\" x=\"%f\" z=\"%f\"/>\n", (int)(*niter)->getId(), (*niter)->getX(), (*niter)->getZ()) ;
00134      textstream << s1 ;
00135     }
00136     textstream << "        </layer>\n" ;
00137     textstream << "    </layers>\n" ;
00138     
00139     /* Axons */
00140     textstream << "    <axons>\n" ;
00141     for (aiter = network->getAxons()->begin(); aiter != network->getAxons()->end(); aiter++) {  
00142       QString s1 ; s1.sprintf("        <axon id=\"%d\" in=\"%d\" out=\"%d\" weight=\"%f\"/>\n", 
00143            (*aiter)->getId(), (*aiter)->getNeuronIn()->getId(), (*aiter)->getNeuronOut()->getId(), (*aiter)->getWeight()) ;
00144       textstream << s1 ;
00145     }
00146     textstream << "    </axons>\n" ;
00147     textstream << "</network>\n" ;
00148     
00149     file.close();
00150     statusBar()->message( QString( "File %1 saved" ).arg( filename ), 2000 );
00151 }
00152 
00153 
00154 void Inn::helpManualSlot() {
00155  viewer->help() ;
00156 }
00157 
00158 
00159 void Inn::fileOpenSlot() {
00160   if (network->nbNeurons() > 0) {
00161     switch( QMessageBox::question ( 
00162           this, 
00163           "Open a Network", 
00164           "Are you sure you wanna open a new network ?", 
00165           QMessageBox::Yes, 
00166           QMessageBox::No ) ) {
00167         case QMessageBox::Yes : 
00168        network->removeAxons();
00169        network->clearLayer(0) ;
00170        network->clearLayer(1) ;
00171        network->clearHiddenLayers() ;
00172           break ;
00173         case QMessageBox::No : return ;
00174       }
00175   }
00176     filename = QFileDialog::getOpenFileName(
00177                     ".",
00178                     "XML file (*.xml)",
00179                     this,
00180                     "open file a network file",
00181                     "Choose a file to open" ) ;
00182     
00183     load() ;
00184 }
00185 
00186 
00187 void Inn::helpAboutSlot() {
00188     AboutDialog * dialog = new AboutDialog(this) ;
00189     dialog->show() ;
00190 }
00191 
00192 
00193 void Inn::actionTestSlot() {
00194     TestingDialog * dialog = new TestingDialog( this ) ;
00195     dialog->show() ;
00196 }
00197 
00198 
00199 void Inn::fullscreenSlot() {
00200  viewer->setFullScreen(fullscreenBox->isChecked()) ;
00201 }
00202 
00203 
00204 void Inn::load( void ) {
00205     QFile file( filename );
00206     if ( !file.open( IO_ReadOnly ) ) return;
00207     NetworkParser handler ;  
00208     QXmlInputSource source( &file ) ;
00209     QXmlSimpleReader reader ;
00210     reader.setContentHandler( &handler ) ;
00211     reader.parse( source ) ;
00212     file.close() ;
00213     statusBar()->message( "Loaded network " + filename, 2000 );
00214 }
00215 
00216 void Inn::slotAboutQT( void ) {
00217     QMessageBox::aboutQt( this, "Intuitive Neural Network" );
00218 }
00219 
00220 void Inn::addNeuronSlot() {
00221  if( network->existLayer(viewer->selectedName()) ) {
00222   network->addNeuron(viewer->selectedName()) ;
00223  } else {
00224   QMessageBox::warning(this, "Adding a neuron", "Select the layer you want to add the neuron on") ;
00225  }
00226 }
00227 
00228 void Inn::addNewAxonSlot() {
00229  if(pushButtonAxon->isOn()) viewer->setMode(ADDAXON) ;
00230  else viewer->resetMode() ;
00231 } 
00232 
00233 
00234 void Inn::deleteSlot() {
00235   if(network->existNeuron(viewer->selectedName())) network->removeNeuron( viewer->selectedName() ) ;
00236  else if( network->existAxon(viewer->selectedName()) ) network->removeAxon( viewer->selectedName(), true ) ;
00237    else if( viewer->selectedName() == 0 ) network->clearLayer(0) ;
00238  else if( viewer->selectedName() == 1 ) network->clearLayer(1) ;
00239   else if( network->existLayer(viewer->selectedName())) network->removeHiddenLayer( viewer->selectedName() ) ;
00240   
00241 }
00242 
00243 
00244 void Inn::addNewHiddenLayerSLot() {
00245     network->addHiddenLayer() ;
00246 }
00247 
00248 
00249 void Inn::displayValuesSlot() {
00250  network->setDisplayValues(valuesBox->isChecked()) ;
00251 }
00252 
00253 
00254 void Inn::displayAxonsSlot() {
00255  network->setDisplayAxons(axonsBox->isChecked()) ;
00256 }
00257 
00258 
00259 void Inn::actionLearnSlot() {
00260     LearningDialog * dialog = new LearningDialog(this) ;
00261     dialog->show() ;
00262 }
00263 
00264 
00265 void Inn::displayAxis() {
00266  viewer->setDrawAxis(axisBox->isChecked()) ;
00267 }
00268 
00269 
00270 void Inn::displayNeurons() {
00271  network->setDisplayNeurons(neuronsBox->isChecked()) ;
00272 }
00273 
00274 
00275 void Inn::displayLayers() {
00276  network->setDisplayLayers(layersBox->isChecked()) ; 
00277 }
00278 
00279 
00280 void Inn::topologyMLPSlot() {
00281  network->removeAxons() ;
00282      network->constructTopologyMLP() ;
00283 }
00284 
00285 
00286 void Inn::topologyCCSlot() {
00287  network->removeAxons() ;
00288  network->constructTopologyCC();
00289 }
00290 
00291 

Generated on Fri Dec 3 14:57:50 2004 for INN by doxygen 1.3.6