//# along with this library; if not, write to the Free Software Foundation,
//# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
//# Correspondence concerning AIPS++ should be addressed as follows:
//# Internet email: aips2-request@nrao.edu.
//# Postal address: AIPS++ Project Office
//# National Radio Astronomy Observatory
//# Charlottesville, VA 22903-2475 USA
#include <casa/Exceptions/Error.h>
#if ! defined(WITHOUT_DBUS)
#include <casadbus/session/DBusSession.h>
#include <casadbus/synthesis/ImagerControl.h>
#include <display/Clean/ConfirmStop.ui.h>
#include <casadbus/utilities/io.h>
typedef casa::dbus::variant variant_t;
#include <casagrpc/types/variant.h>
typedef casa::grpc::variant variant_t;
static std::string name( ) { return "SynthesisImager"; }
ImagerControl( const std::string &con ) {
fprintf( stderr, "ImagerControl(%s)\n", con.c_str( ) );
bool incrementController( ) {
fprintf(stderr,"ImagerControl::incrementController( )\n");
bool decrementController( ) {
fprintf(stderr,"ImagerControl::decrementController( )\n");
void changePauseFlag( const bool & ) {
fprintf(stderr,"ImagerControl::changePauseFlag( const bool & )\n");
void changeStopFlag( const bool & ) {
fprintf(stderr,"ImagerControl::changeStopFlag( const bool & )\n");
void controlUpdate(const std::map<std::string,grpc::variant>&) {
fprintf(stderr,"ImagerControl::controlUpdate(const std::map<std::string,grpc::variant>&)\n");
std::map<std::string,grpc::variant> getDetails( ) {
fprintf(stderr,"ImagerControl::getDetails( )\n");
return std::map<std::string,grpc::variant>( );
std::string getDescription( ) {
fprintf(stderr,"ImagerContro::getDescription( )\n");
#include <ui/ui_ConfirmStop.h>
#include <display/Clean/CleanGui.qo.h>
using namespace casacore;
CleanGui::CleanGui(QWidget *parent) : QDialog(parent), ic(0), current_process_index(-1),
current_process_state(UNDEFINED) {
const QString WINDOW_TITLE( "Clean Tool");
this->setWindowTitle( WINDOW_TITLE );
default_send_tooltip = send_button->toolTip( );
cycle_factor_entry->setValidator(double_validator);
loop_gain_entry->setValidator(double_validator);
clean_processes->setColumnCount(1);
clean_processes->setHeaderLabels(label_list);
QTreeWidgetItem *current_item = 0;
#if ! defined(WITHOUT_DBUS)
casa::DBusSession &session = casa::DBusSession::instance( );
typedef std::vector<std::string> namelist_t;
namelist_t names = session.listNames( );
fprintf( stderr, "<CleanGui::CleanGui>: finding existing clean services...\n" );
for ( namelist_t::iterator it = names.begin( ); it != names.end( ); ++it ) {
cout << std::setw(25) << "<CleanGui::CleanGui>:" << std::setw(50) << it->c_str( ) <<
std::cout << std::setw(25) << "<CleanGui::CleanGui>:" << std::setw(50) << it->c_str( ) <<
std::setw(50) << ImagerControl::interface_name( );
if ( it->compare( 0, ImagerControl::interface_name( ).size( ), ImagerControl::interface_name( ) ) == 0 ) {
cout << std::setw(7) << "(yes)" << endl;
std::cout << std::setw(7) << "(yes)" << std::endl;
value.erase( 0, ImagerControl::interface_name( ).size( ) );
QTreeWidgetItem *item = new QTreeWidgetItem(clean_processes);
if ( current_item == 0 ) current_item = item;
item->setText( 0, QString::fromStdString(value) );
item->setCheckState( 0, Qt::Unchecked );
else { cout << std::setw(7) << "(no)" << endl; }
else { std::cout << std::setw(7) << "(no)" << std::endl; }
fprintf( stderr, "POINT WHERE DBUS WAS USED TO CONNECT TO RUNNING INTERACTIVE CLEAN\n" );
//**** setup signals here
connect( send_button, SIGNAL(pressed( )), SLOT(send_state_event( )) );
connect( clean_processes, SIGNAL(itemSelectionChanged()), SLOT(selection_change()) );
connect( clean_processes, SIGNAL(itemChanged(QTreeWidgetItem*,int)), SLOT(check_box_change(QTreeWidgetItem*,int)) );
connect( stop_button, SIGNAL(pressed( )), SLOT(stop_button_event( )) );
int index = clean_processes->indexOfTopLevelItem(item);
if ( index < 0 || index == current_process_index ) return;
current_process_index = -1;
QString process_id = item->text(0);
cout << "<CleanGui::selection_change>: creating imager control object:\t" << ImagerControl::name( ) + process_id.toStdString( ) << endl;
std::cout << "<CleanGui::selection_change>: creating imager control object:\t" << ImagerControl::name( ) + process_id.toStdString( ) << std::endl;
ic = new ImagerControl( "edu.nrao.casa." + ImagerControl::name( ) + process_id.toStdString( ) );
current_process_index = index;
if ( item->checkState(0) != Qt::Unchecked )
} catch ( const AipsError &err ) {
void CleanGui::refresh( ) {
fprintf( stderr, "<CleanGui::refresh>: getting details...\n" );
typedef std::map<std::string,dbus::variant> details_t;
typedef std::map<std::string,variant_t> details_t;
details_t details = ic->getDetails( );
#if ! defined(WITHOUT_DBUS)
std::ostream_iterator<std::string> out( cerr, ", " );
std::transform( details.begin( ), details.end( ), out,
(std::string (*)(const std::pair<std::string,dbus::variant>&)) dbus::asString );
(std::string (*)(const std::pair<std::string,variant_t>&)) dbus::asString );
fflush(stderr); //*** catches cerr too...
fprintf( stderr, "INSERT DICTIONARY DUMP HERE\n" );
/***********************************************************************
****** Is interaction currently enabled? ******
***********************************************************************/
details_t::iterator it = details.find("interactivemode");
if ( it != details.end( ) && it->second.type( ) == dbus::variant::BOOL ) {
if ( it != details.end( ) && it->second.type( ) == variant_t::BOOL ) {
if ( it->second.getBool( ) ) {
interactive_label->setText("interactive");
interactive_label->setText("not interactive");
/***********************************************************************
****** Fill in the threshold... ******
***********************************************************************/
it = details.find("threshold");
if ( it != details.end( ) && it->second.type( ) == dbus::variant::DOUBLE ) {
if ( it != details.end( ) && it->second.type( ) == variant_t::DOUBLE ) {
double threshold = it->second.getDouble( );
QString val = QString::number(threshold);
threshold_entry->setText(val);
current_clean_state[threshold_entry] = val;
threshold_entry->clear( );
current_clean_state[threshold_entry] = "";
/***********************************************************************
****** Fill in the niter... ******
***********************************************************************/
it = details.find("niter");
if ( it != details.end( ) && it->second.type( ) == dbus::variant::INT ) {
if ( it != details.end( ) && it->second.type( ) == variant_t::INT ) {
int niter = it->second.getInt( );
QString val = QString::number(niter);
niter_entry->setText(val);
current_clean_state[niter_entry] = val;
current_clean_state[niter_entry] = "";
/***********************************************************************
****** Fill in clean process description... ******
***********************************************************************/
std::string description = ic->getDescription( );
process_description->setPlainText( QString::fromStdString(description) );
/***********************************************************************
****** Fill in cycle niter... ******
***********************************************************************/
it = details.find("cycleniter");
if ( it != details.end( ) && it->second.type( ) == dbus::variant::INT ) {
if ( it != details.end( ) && it->second.type( ) == variant_t::INT ) {
int niter = it->second.getInt( );
QString val = QString::number(niter);
cycle_niter_entry->setText(val);
current_clean_state[cycle_niter_entry] = val;
cycle_niter_entry->clear( );
current_clean_state[cycle_niter_entry] = "";
/***********************************************************************
****** Fill in cycle threshold... ******
***********************************************************************/
it = details.find("cyclethreshold");
if ( it != details.end( ) && it->second.type( ) == dbus::variant::DOUBLE ) {
if ( it != details.end( ) && it->second.type( ) == variant_t::DOUBLE ) {
double threshold = it->second.getDouble( );
QString val = QString::number(threshold);
cycle_threshold_entry->setText(val);
current_clean_state[cycle_threshold_entry] = val;
cycle_threshold_entry->clear( );
current_clean_state[cycle_threshold_entry] = "";
/***********************************************************************
****** Fill in interactive niter... ******
***********************************************************************/
it = details.find("interactiveniter");
if ( it != details.end( ) && it->second.type( ) == dbus::variant::INT ) {
if ( it != details.end( ) && it->second.type( ) == variant_t::INT ) {
int niter = it->second.getInt( );
QString val = QString::number(niter);
interactive_niter_entry->setText(val);
current_clean_state[interactive_niter_entry] = val;
interactive_niter_entry->clear( );
current_clean_state[interactive_niter_entry] = "";
/***********************************************************************
****** Fill in interactive threshold... ******
***********************************************************************/
it = details.find("interactivethreshold");
if ( it != details.end( ) && it->second.type( ) == dbus::variant::DOUBLE ) {
if ( it != details.end( ) && it->second.type( ) == variant_t::DOUBLE ) {
double threshold = it->second.getDouble( );
QString val = QString::number(threshold);
interactive_threshold_entry->setText(val);
current_clean_state[interactive_threshold_entry] = val;
interactive_threshold_entry->clear( );
current_clean_state[interactive_threshold_entry] = "";
/***********************************************************************
****** Fill in cycle factor entry... ******
***********************************************************************/
it = details.find("cyclefactor");
if ( it != details.end( ) && it->second.type( ) == dbus::variant::DOUBLE ) {
if ( it != details.end( ) && it->second.type( ) == variant_t::DOUBLE ) {
double factor = it->second.getDouble( );
QString val = QString::number(factor);
cycle_factor_entry->setText(val);
current_clean_state[cycle_factor_entry] = val;
cycle_factor_entry->clear( );
current_clean_state[cycle_factor_entry] = "";
/***********************************************************************
****** Fill in loop gain entry... ******
***********************************************************************/
it = details.find("loopgain");
if ( it != details.end( ) && it->second.type( ) == dbus::variant::DOUBLE ) {
if ( it != details.end( ) && it->second.type( ) == variant_t::DOUBLE ) {
double gain = it->second.getDouble( );
QString val = QString::number(gain);
loop_gain_entry->setText(val);
current_clean_state[loop_gain_entry] = val;
loop_gain_entry->clear( );
current_clean_state[loop_gain_entry] = "";
/***********************************************************************
****** Fill in current clean state... ******
***********************************************************************/
it = details.find("cleanstate");
if ( it != details.end( ) && it->second.type( ) == dbus::variant::STRING ) {
if ( it != details.end( ) && it->second.type( ) == variant_t::STRING ) {
std::string state = it->second.getString( );
clean_state_label->setText(QString::fromStdString(state));
if ( state == "paused" ) {
current_process_state = PAUSED;
play_button->setIcon(QIcon(":/icons/Anim4_Play.png"));
} else if ( state == "stopped" ) {
current_process_state = STOPPED;
play_button->setIcon(QIcon(":/icons/Anim4_Play.png"));
play_button->setEnabled(false);
} catch ( std::exception e ) {
fprintf( stderr, "error CleanGui::refresh( ): %s\n", e.what( ) );
fprintf( stderr, "unexpected error in CleanGui::refresh( )\n" );
std::map<std::string,dbus::variant> CleanGui::collect( ) {
typedef std::map<std::string,dbus::variant> details_t;
std::map<std::string,variant_t> CleanGui::collect( ) {
typedef std::map<std::string,variant_t> details_t;
cerr << "CleanGui::collect( )\n" << endl;
cerr << "CleanGui::collect( )\n" << std::endl;
/***********************************************************************
****** Is interaction currently enabled? ******
***********************************************************************/
// interactive_label->text( );
/***********************************************************************
****** Fill in the threshold... ******
***********************************************************************/