Parcourir la source

Correction de bug

Rémi Synave il y a 10 mois
Parent
commit
17d54fcb32
3 fichiers modifiés avec 79 ajouts et 40 suppressions
  1. 73 36
      csl/Experiment.cpp
  2. 4 2
      csl/Experiment.hpp
  3. 2 2
      dsl/MainWindow.cpp

+ 73 - 36
csl/Experiment.cpp

@@ -15,6 +15,7 @@
 #include <QJsonObject>
 #include <QJsonArray>
 #include <QJsonDocument>
+#include <QMessageBox>
 
 #include <QDebug>
 
@@ -31,6 +32,8 @@ Experiment::Experiment ():QMainWindow()
   suffix = NULL;
   choice = NULL;
   algo_side='X';
+  dNFixed = false;
+  expeInit = false;
 
   setWindowTitle (tr ("DSL - Draw Strength Line"));
 
@@ -110,23 +113,41 @@ Experiment::Experiment ():QMainWindow()
 }
 
 void
-Experiment::open ()
-{  
-  QString dir = QFileDialog::getExistingDirectory(this,
-						  tr("Open Directory"),
-						  QDir::currentPath (),
-						  QFileDialog::ShowDirsOnly
-						  | QFileDialog::DontResolveSymlinks);
+Experiment::start ()
+{
+
+  QString dir;
+  QString* directoryname;
+  
+  if(!dNFixed)
+    {
+      dir = QString(QDir::currentPath()+"/data");
+      directoryname = new QString(dir);
+      
+      QDir::setCurrent(*directoryname);
+      dNFixed = true;
+    }else
+    {
+      dir = QString(QDir::currentPath());
+      directoryname = new QString(dir);
+    }
+  
   
-  QString* directoryname = new QString(dir);
-  QDir::setCurrent(*directoryname);
   
   if(!dir.isEmpty())
     {
-      bool ok;
+      bool ok=false;
       suffix = new QString(QInputDialog::getText(this, tr("Your ID"),
 						 tr("ID to use :"), QLineEdit::Normal,
 						 QDir::home().dirName(), &ok));
+
+      if((*suffix) == "algo" || (*suffix) == "random" || (*suffix) == "_algo" || (*suffix) == "_random")
+	{
+	  QMessageBox msgBox;
+	  msgBox.setText("Your name can't be [_]algo or [_]random.");
+	  msgBox.exec();
+	  ok = false;
+	}
       
       if(ok)
 	{
@@ -137,7 +158,7 @@ Experiment::open ()
 	  filenames_json = new QStringList();
 	  choice = new QStringList();
 	  
-	  QDirIterator it(*directoryname, {"*.jpg", "*.png"}, QDir::Files);
+	  QDirIterator it(*directoryname, {"*.jpg"}, QDir::Files);
 	  while (it.hasNext()) {
 	    filenames->append( it.next() );
 	  }
@@ -167,38 +188,46 @@ Experiment::open ()
 	      filenames_json->swapItemsAt(rand1, rand2);
 	    }
 	  openedImage = -1;
+
+	  expeInit = true;
+	  openNext();
 	}
     }
-  openNext();
   
 }
 
 void Experiment::leftImage(){
-  if((algo_side != 'L') && (algo_side != 'R'))
+  if(expeInit)
     {
-      qDebug() << "Something went wrong";
-      QApplication::quit();
+      if((algo_side != 'L') && (algo_side != 'R'))
+	{
+	  qDebug() << "Something went wrong";
+	  QApplication::quit();
+	}
+      if(algo_side == 'L')
+	choice->append(QString("algo"));
+      else
+	choice->append(QString("random"));
+      
+      openNext();
     }
-  if(algo_side == 'L')
-    choice->append(QString("algo"));
-  else
-    choice->append(QString("random"));
-  
-  openNext();
 }
 
 void Experiment::rightImage(){
-  if((algo_side != 'L') && (algo_side != 'R'))
+  if(expeInit)
     {
-      qDebug() << "Something went wrong";
-      QApplication::quit();
+      if((algo_side != 'L') && (algo_side != 'R'))
+	{
+	  qDebug() << "Something went wrong";
+	  QApplication::quit();
+	}
+      if(algo_side == 'R')
+	choice->append(QString("algo"));
+      else
+	choice->append(QString("random"));
+      
+      openNext();
     }
-  if(algo_side == 'R')
-    choice->append(QString("algo"));
-  else
-    choice->append(QString("random"));
-  
-  openNext();
 }
 
 
@@ -245,14 +274,22 @@ Experiment::openNext (){
 	  waLeft->loadSL (filenames_json->at(openedImage).toStdString ());
 	  algo_side='L';
 	  for(int i = 0 ; i < waLeft->getNumberOfLines() ; i++)
-	    waRight->addRandomSL();
+	    {
+	      waRight->addRandomSL();
+	      QString jsonFile = QDir::currentPath ().append("/").append(QFileInfo(filenames->at(openedImage)).baseName().append(QString("_random")).append(".json"));
+	      waRight->saveStrengthLine (jsonFile.toStdString ());
+	    }
 	}
       else
 	{
 	  waRight->loadSL (filenames_json->at(openedImage).toStdString ());
 	  algo_side='R';
 	  for(int i = 0 ; i < waRight->getNumberOfLines() ; i++)
-	    waLeft->addRandomSL();
+	    {
+	      waLeft->addRandomSL();
+	      QString jsonFile = QDir::currentPath ().append("/").append(QFileInfo(filenames->at(openedImage)).baseName().append(QString("_random")).append(".json"));
+	      waLeft->saveStrengthLine (jsonFile.toStdString ());
+	    }
 	}
       waLeft->setReadOnly(true);
       waRight->setReadOnly(true);
@@ -266,9 +303,9 @@ Experiment::openNext (){
 void
 Experiment::createActions ()
 {
-  openAct = new QAction (tr ("&Open directory"), this);
-  openAct->setShortcuts (QKeySequence::Open);
-  connect (openAct, &QAction::triggered, this, &Experiment::open);
+  startAct = new QAction (tr ("&Start"), this);
+  startAct->setShortcuts (QKeySequence::Save);
+  connect (startAct, &QAction::triggered, this, &Experiment::start);
 
   exitAct = new QAction (tr ("E&xit"), this);
   exitAct->setShortcuts (QKeySequence::Quit);
@@ -279,7 +316,7 @@ void
 Experiment::createMenus ()
 {
   fileMenu = menuBar ()->addMenu (tr ("&File"));
-  fileMenu->addAction (openAct);
+  fileMenu->addAction (startAct);
 
   fileMenu->addSeparator ();
 

+ 4 - 2
csl/Experiment.hpp

@@ -24,10 +24,12 @@ private:
   const QString *suffix_IA = new QString("_algo");
   int screenWidth, screenHeight;
   char algo_side;
+  bool dNFixed;
+  bool expeInit;
 
   QMenu *fileMenu;
 
-  QAction *openAct;
+  QAction *startAct;
   QAction *exitAct;
 
   WorkArea *waLeft;
@@ -49,7 +51,7 @@ private:
 
 		     
 private slots:
-  void open ();
+  void start ();
   void leftImage();
   void rightImage();
   

+ 2 - 2
dsl/MainWindow.cpp

@@ -74,7 +74,7 @@ MainWindow::openFile ()
     QString filename = QFileDialog::getOpenFileName (this,
 						     QObject::tr ("Open image file"),
 						     QDir::currentPath (),
-						     QObject::tr("Images files (*.jpg *.png);;All files (*.*)"));
+						     QObject::tr("Images files (*.jpg);;All files (*.*)"));
 
     if(!filename.isEmpty()) {
     
@@ -90,7 +90,7 @@ MainWindow::openFile ()
 	  delete filenames;
 	  filenames = new QStringList();
 	
-	  QDirIterator it(*directoryname, {"*.jpg", "*.png"}, QDir::Files);
+	  QDirIterator it(*directoryname, {"*.jpg"}, QDir::Files);
 	  while (it.hasNext()) {
 	    filenames->append( it.next() );
 	  }