[us-commits] r2791 - in trunk: gui programs/us_com_project programs/us_experiment programs/us_xpn_viewer sql

svn at svn.aucsolutions.com svn at svn.aucsolutions.com
Tue Jul 16 21:34:05 MDT 2019


Author: alexey
Date: 2019-07-17 03:34:02 +0000 (Wed, 17 Jul 2019)
New Revision: 2791

Modified:
   trunk/gui/us_select_item.cpp
   trunk/gui/us_select_item.h
   trunk/programs/us_com_project/us_com_project_gui.cpp
   trunk/programs/us_com_project/us_com_project_gui.h
   trunk/programs/us_experiment/us_proto_ranges.cpp
   trunk/programs/us_xpn_viewer/us_xpn_viewer_gui.cpp
   trunk/sql/us3_autoflow_procs.sql
Log:
Autoflow, new featres && updates:

	  * Times in LIVE_UPDATE, bug fixed for proper times in hh:mm:ss format when total duration is more than a day
	  * In setting protocol, wavelength range is correted to [180-800] nm
	  * Delete Autoflow record with re-avaluation of machine states and possibility of submission another experiment is added.

Needs testing.



Modified: trunk/gui/us_select_item.cpp
===================================================================
--- trunk/gui/us_select_item.cpp	2019-07-16 01:50:11 UTC (rev 2790)
+++ trunk/gui/us_select_item.cpp	2019-07-17 03:34:02 UTC (rev 2791)
@@ -42,6 +42,7 @@
 {
    multi_sel         = false;
    deleted_button    = false;
+   deleted_button_autoflow    = false;
    autoflow_button   = false;
    autoflow_da       = false;
    
@@ -51,10 +52,14 @@
        if ( add_label == "DELETE" )
 	 deleted_button    = true;
        if ( add_label == "AUTOFLOW_GMP" )
-	 autoflow_button = true;
+	 {
+	   autoflow_button = true;
+	   deleted_button_autoflow  = true;
+	 }
        if ( add_label == "AUTOFLOW_DA" )
 	 {
 	   autoflow_button = true;
+	   deleted_button_autoflow  = true;
 	   autoflow_da     = true;
 	 }
      }
@@ -189,19 +194,26 @@
                                            accept_pb_label );
 
    
-   QPushButton* pb_delete = us_pushbutton( tr( "Delete Item" ) );
+   QPushButton* pb_delete          = us_pushbutton( tr( "Delete Item" ) );
+   QPushButton* pb_delete_autoflow = us_pushbutton( tr( "Delete Record" ) );
    
    buttons->addWidget( pb_cancel );
    buttons->addWidget( pb_delete );
+   buttons->addWidget( pb_delete_autoflow );
    buttons->addWidget( pb_accept );
 
    connect( pb_cancel, SIGNAL( clicked() ), SLOT( cancelled() ) );
    connect( pb_accept, SIGNAL( clicked() ), SLOT( accepted() ) );
    connect( pb_delete, SIGNAL( clicked() ), SLOT( deleted() ) );
+   connect( pb_delete_autoflow, SIGNAL( clicked() ), SLOT( deleted_autoflow() ) );
 
    if ( !deleted_button )
      pb_delete->hide();
 
+   if ( !deleted_button_autoflow )
+     pb_delete_autoflow->hide();
+
+   
    main->addLayout( buttons );
    resize( 700, 250 );
 
@@ -378,12 +390,91 @@
 // Delete button:
       /*  ALEXEY: For future Delete() function:
 
-	  to get ptotID -> items[selxP][2]; 
+	  to get autoflow ID -> items[selxP][0]; 
 	  delete (stored procedure) 
 	         + emit signal to us_experiment to update protdata BEFORE any selection; 
 	  then remove items[selxP] from QList; 
 	  then rebuild list by running list_data(); [move part of ]
       */
+void US_SelectItem::deleted_autoflow()
+{
+   QList< QTableWidgetItem* > selitems = tw_data->selectedItems();
+   
+   int     AutoflowRow;
+   QString AutoflowID;
+   if ( selitems.size() == 0 )
+     {
+       QMessageBox::information( this,
+				 tr( "No Autoflow Record Selected" ),
+				 tr( "You have not selected any auflow record.\nSelect or Cancel" ) );
+       return;
+     }
+
+   // Return the index to the selected item
+   QTableWidgetItem* twi  = selitems.at( 0 );
+   int irow          = twi->row();
+   twi               = tw_data->item( irow, 0 );
+   
+   AutoflowRow            = qMax( 0, itemlist.indexOf( twi->text() ) );
+   
+   AutoflowID = items[ AutoflowRow ][ 0 ];
+
+   //Attempt autoflow record deletion:
+   qDebug() << "Autoflow ID to delete: ID, name, run status: " << AutoflowID << ", " << items[ AutoflowRow ][ 1 ] << ", " << items[ AutoflowRow ][ 4 ];
+
+   QMessageBox msgBox;
+   msgBox.setText(tr( "You have selected the following Record to delete:<br><br>" )
+		  + tr("<b>ID: </b>") + items[ AutoflowRow ][ 0 ]
+		  + tr("<br>")
+		  + tr("<b>Name: </b>") + items[ AutoflowRow ][ 1 ]
+		  + tr("<br>")
+		  + tr("<b>Status: </b> ") + items[ AutoflowRow ][ 4 ]
+		  + tr( "<br><br>Proceed?" ));
+   msgBox.setInformativeText("<font color='red'><b>NOTE:</b> if deleted, this run cannot be monitored with this program anymore!</font>");
+   msgBox.setWindowTitle(tr("Delete Autoflow Record"));
+   QPushButton *Confirm   = msgBox.addButton(tr("Delete"), QMessageBox::YesRole);
+   QPushButton *Cancel    = msgBox.addButton(tr("Cancel"), QMessageBox::RejectRole);
+
+   msgBox.setIcon(QMessageBox::Question);
+   msgBox.exec();
+    
+   if (msgBox.clickedButton() == Cancel) 
+     return;
+   else if (msgBox.clickedButton() == Confirm)
+     {
+       US_Passwd pw;
+       US_DB2* db = new US_DB2( pw.getPasswd() );
+       QStringList q( "" );
+       q.clear();
+       q  << QString( "delete_autoflow_record_by_id" )
+	  << AutoflowID;
+
+       int status = db->statusQuery( q );
+       
+       if ( status == US_DB2::NO_AUTOFLOW_RECORD )
+	 {
+	   QMessageBox::warning( this,
+				 tr( "Autoflow Record Not Deleted" ),
+				 tr( "This record could not be deleted since\n"
+				     "it is not present in the LIMS DB." ) );
+	   return;
+	 }
+
+       items.removeAt( AutoflowRow );     // Remove deleted item row
+       list_data();                       // Rebuild protocol list in the dialog
+       
+       QString msg("Autoflow record  has been successfully deleted.");
+       QMessageBox::information( this,
+			     tr( "Autoflow Record  Deleted" ),
+			     msg );
+
+
+       emit accept_autoflow_deletion();        // Signal to pass to us_comproject to update (re-read reduced) autoflow records
+       
+     }
+}
+
+
 void US_SelectItem::deleted()
 {
    QList< QTableWidgetItem* > selitems = tw_data->selectedItems();

Modified: trunk/gui/us_select_item.h
===================================================================
--- trunk/gui/us_select_item.h	2019-07-16 01:50:11 UTC (rev 2790)
+++ trunk/gui/us_select_item.h	2019-07-17 03:34:02 UTC (rev 2791)
@@ -63,6 +63,7 @@
 
       bool           multi_sel;   //!< Flag: multiple selections enabled?
       bool           deleted_button; //If Delete button is present
+      bool           deleted_button_autoflow; //If Delete Autoflow button is present
       bool           autoflow_button; //If autoflow, Cancel becomes define another Experiment
       bool           autoflow_da;  // If called by non-GMP us_comproject (DA)
       
@@ -78,10 +79,12 @@
       void cancelled      ( void );
       void accepted       ( void );
       void deleted        ( void );
+      void deleted_autoflow ( void );
       void help           ( void )
       { showHelp.show_help( "select_item.html" ); };
 
    signals:
-      void accept_deletion( void ); 
+      void accept_deletion( void );
+      void accept_autoflow_deletion( void ); 
 };
 #endif

Modified: trunk/programs/us_com_project/us_com_project_gui.cpp
===================================================================
--- trunk/programs/us_com_project/us_com_project_gui.cpp	2019-07-16 01:50:11 UTC (rev 2790)
+++ trunk/programs/us_com_project/us_com_project_gui.cpp	2019-07-17 03:34:02 UTC (rev 2791)
@@ -13,7 +13,7 @@
 #include "us_crypto.h"
 #include "us_select_item.h"
 #include "us_images.h"
-#include "us_select_item.h"
+//#include "us_select_item.h"
 
 #if QT_VERSION < 0x050000
 #define setSamples(a,b,c)  setData(a,b,c)
@@ -498,21 +498,25 @@
   else
     autoflow_btn = "AUTOFLOW_GMP";
   
-  //US_SelectItem pdiag( autoflowdata, hdrs, pdtitle, &prx, autoflow_btn, -2 );
-  US_SelectItem* pdiag = new  US_SelectItem( autoflowdata, hdrs, pdtitle, &prx, autoflow_btn, -2 );
+  //US_SelectItem pdiag_autoflow( autoflowdata, hdrs, pdtitle, &prx, autoflow_btn, -2 );
+  //US_SelectItem* pdiag_autoflow = new  US_SelectItem( autoflowdata, hdrs, pdtitle, &prx, autoflow_btn, -2 );
+
+  pdiag_autoflow = new  US_SelectItem( autoflowdata, hdrs, pdtitle, &prx, autoflow_btn, -2 );
   
-  pdiag->setParent(this, Qt::Window);
-  pdiag->setWindowFlags(Qt::Dialog | Qt::WindowMinimizeButtonHint | Qt::WindowMaximizeButtonHint | Qt::WindowCloseButtonHint  );
-  //pdiag->setWindowFlags(Qt::Window | Qt::WindowCloseButtonHint | Qt::WindowMinimizeButtonHint | Qt::WindowMaximizeButtonHint  );
+  connect( pdiag_autoflow, SIGNAL( accept_autoflow_deletion() ), this, SLOT( update_autoflow_data() ));
+  
+  pdiag_autoflow->setParent(this, Qt::Window);
+  pdiag_autoflow->setWindowFlags(Qt::Dialog | Qt::WindowMinimizeButtonHint | Qt::WindowMaximizeButtonHint | Qt::WindowCloseButtonHint  );
+  //pdiag_autoflow->setWindowFlags(Qt::Window | Qt::WindowCloseButtonHint | Qt::WindowMinimizeButtonHint | Qt::WindowMaximizeButtonHint  );
 
   //disable 'Define Another Exp.' button if all instruments are in use
   if ( occupied_instruments.size() >= instruments.size() )
-    pdiag->pb_cancel->setEnabled( false );
+    pdiag_autoflow->pb_cancel->setEnabled( false );
   
   
   QString autoflow_id_selected("");
   
-  if ( pdiag->exec() == QDialog::Accepted )
+  if ( pdiag_autoflow->exec() == QDialog::Accepted )
     autoflow_id_selected  = autoflowdata[ prx ][ 0 ];
   else
     {
@@ -591,10 +595,39 @@
       return;
     }
   //and so on...
+   
+}
+
+//Re-evaluate autoflow records & occupied instruments & if Define Another Exp. should be enabled....
+void US_ComProjectMain::update_autoflow_data( void )
+{
+  qDebug() << "Updating autoflow records!!!";
   
+  US_Passwd  pw;
+  US_DB2* dbP  = new US_DB2( pw.getPasswd() );
+
+  //Re-read autoflow records
+  list_all_autoflow_records( autoflowdata, dbP );
+
+  //Re-count instruments in use
+  occupied_instruments.clear();
+  for ( int i=0; i < autoflowdata.size(); i++ )
+    {
+      if ( autoflowdata[ i ][ 5 ] == "LIVE_UPDATE" )
+	occupied_instruments << autoflowdata[ i ][ 2 ];
+    }
   
+  //Re-set Define Another Exp. button
+  if ( occupied_instruments.size() >= instruments.size() )
+    pdiag_autoflow->pb_cancel->setEnabled( false );
+  else
+    pdiag_autoflow->pb_cancel->setEnabled( true );
+
+  qDebug() << "Define Another Exp. button reset";
+  
 }
 
+
 //Slot to delete Postgres Optima ExperimentDefinition record
 void US_ComProjectMain::delete_psql_record( int ExpId )
 {

Modified: trunk/programs/us_com_project/us_com_project_gui.h
===================================================================
--- trunk/programs/us_com_project/us_com_project_gui.h	2019-07-16 01:50:11 UTC (rev 2790)
+++ trunk/programs/us_com_project/us_com_project_gui.h	2019-07-17 03:34:02 UTC (rev 2791)
@@ -33,6 +33,7 @@
 #include "us_license_t.h"
 #include "us_plot.h"
 #include "us_license.h"
+#include "us_select_item.h"
 
 class US_ComProjectMain;
 
@@ -270,6 +271,8 @@
   bool window_closed;
   
   QStringList occupied_instruments;
+
+  US_SelectItem* pdiag_autoflow;
     
  private:
   US_ExperGui*      epanExp;         // US_Exp panel
@@ -315,7 +318,8 @@
 
   void define_new_experiment( QStringList & );
 
-  void delete_psql_record( int );  
+  void delete_psql_record( int );
+  void update_autoflow_data( void );  
   
 signals:
   void pass_to_live_update( QMap < QString, QString > & protocol_details ); 

Modified: trunk/programs/us_experiment/us_proto_ranges.cpp
===================================================================
--- trunk/programs/us_experiment/us_proto_ranges.cpp	2019-07-16 01:50:11 UTC (rev 2790)
+++ trunk/programs/us_experiment/us_proto_ranges.cpp	2019-07-17 03:34:02 UTC (rev 2791)
@@ -1034,8 +1034,8 @@
    QLabel* lb_strwln      = us_label(  tr( "Start Wavelength" ) );
    QLabel* lb_endwln      = us_label(  tr( "End Wavelength" ) );
    QLabel* lb_incwln      = us_label(  tr( "Wavelength Increment" ) );
-   ct_strwln              = us_counter( 2, 100, 800, 1 );
-   ct_endwln              = us_counter( 2, 100, 800, 1 );
+   ct_strwln              = us_counter( 2, 180, 800, 1 );
+   ct_endwln              = us_counter( 2, 180, 800, 1 );
    ct_incwln              = us_counter( 2,   1,  20, 1 );
    const int def_swl      = 200;
    const int def_ewl      = 600;
@@ -1352,7 +1352,7 @@
 
   qDebug() << "First and Last element: " << selected[0].toDouble() << ", " << selected[ selected.size() -1 ].toDouble();
   
-  if ( selected[0].toDouble() < 100.0 || selected[ selected.size() -1 ].toDouble() > 800.0  )   // Boundaries [100-800] nm
+  if ( selected[0].toDouble() < 180.0 || selected[ selected.size() -1 ].toDouble() > 800.0  )   // Boundaries [100-800] nm
     {
       QPalette *palette = new QPalette();
       palette->setColor(QPalette::Text,Qt::red);
@@ -1360,7 +1360,7 @@
       le_wrange->setPalette(*palette);
       
       QString mtitle_error    = tr( "Error" );
-      QString message_error   = tr( "Selected wavelengths are outside of accepted range of [100-800] nm!" );
+      QString message_error   = tr( "Selected wavelengths are outside of accepted range of [180-800] nm!" );
       QMessageBox::critical( this, mtitle_error, message_error );
       
       selected.clear();

Modified: trunk/programs/us_xpn_viewer/us_xpn_viewer_gui.cpp
===================================================================
--- trunk/programs/us_xpn_viewer/us_xpn_viewer_gui.cpp	2019-07-16 01:50:11 UTC (rev 2790)
+++ trunk/programs/us_xpn_viewer/us_xpn_viewer_gui.cpp	2019-07-17 03:34:02 UTC (rev 2791)
@@ -1846,6 +1846,10 @@
   timeToList( running_time, dhms_r );
   QString running_time_text;
   //ALEXEY: hh:mm:ss - OR do we need dd:hh:mm instead ?
+  //ALEXEY: if times >~1 day, update #hours
+  if ( dhms_r[0] > 0 )
+    dhms_r[1] += 24;
+  
   running_time_text = QString::number(dhms_r[1]) + ":" + QString::number(dhms_r[2]) + ":" + QString::number(dhms_r[3]);
   le_running->setText( running_time_text );
   qApp->processEvents();
@@ -1859,6 +1863,10 @@
   timeToList( elapsed_time, dhms_e );
   QString elapsed_time_text;
   //ALEXEY: hh:mm:ss - OR do we need dd:hh:mm instead ?
+  //ALEXEY: if times >~1 day, update #hours
+  if ( dhms_e[0] > 0 )
+    dhms_e[1] += 24;
+  
   elapsed_time_text = QString::number(dhms_e[1]) + ":" + QString::number(dhms_e[2]) + ":" + QString::number(dhms_e[3]);
   le_elapsed->setText( elapsed_time_text );
   qApp->processEvents();
@@ -1869,6 +1877,10 @@
   timeToList( remaining_time, dhms_remain );
   QString remaining_time_text;
   //ALEXEY: hh:mm:ss - OR do we need dd:hh:mm instead ?
+  //ALEXEY: if times >~1 day, update #hours
+  if ( dhms_remain[0] > 0 )
+    dhms_remain[1] += 24;
+    
   remaining_time_text = QString::number(dhms_remain[1]) + ":" + QString::number(dhms_remain[2]) + ":" + QString::number(dhms_remain[3]);
   le_remaining->setText( remaining_time_text );
   qApp->processEvents();

Modified: trunk/sql/us3_autoflow_procs.sql
===================================================================
--- trunk/sql/us3_autoflow_procs.sql	2019-07-16 01:50:11 UTC (rev 2790)
+++ trunk/sql/us3_autoflow_procs.sql	2019-07-17 03:34:02 UTC (rev 2791)
@@ -126,6 +126,45 @@
 
 
 
+-- DELETE  autoflow record by ID 
+DROP PROCEDURE IF EXISTS delete_autoflow_record_by_id$$
+CREATE PROCEDURE delete_autoflow_record_by_id ( p_personGUID    CHAR(36),
+                                     	      p_password      VARCHAR(80),
+                			      p_ID            INT )
+  MODIFIES SQL DATA
+
+BEGIN
+  DECLARE count_records INT;	
+	
+  CALL config();
+  SET @US3_LAST_ERRNO = @OK;
+  SET @US3_LAST_ERROR = '';
+
+  IF ( verify_user( p_personGUID, p_password ) = @OK ) THEN
+    
+    -- Find out if record exists for associated runID 
+    SELECT COUNT(*) INTO count_records 
+    FROM autoflow 
+    WHERE ID = p_ID;
+
+    IF ( count_records = 0 ) THEN
+      SET @US3_LAST_ERRNO = @NO_AUTOFLOW_RECORD;
+      SET @US3_LAST_ERROR = 'Record cannot be deleted as it does not exist for current experiment run';   
+
+    ELSE
+      DELETE FROM autoflow
+      WHERE ID = p_ID;
+    
+    END IF;  
+
+  END IF;
+      
+  SELECT @US3_LAST_ERRNO AS status;
+
+END$$
+
+
+
 -- Returns complete information about autoflow record
 DROP PROCEDURE IF EXISTS read_autoflow_record$$
 CREATE PROCEDURE read_autoflow_record ( p_personGUID    CHAR(36),



More information about the us-commits mailing list