Commits
Darrell Schiebel authored fdcb1b59c83
69 69 | char *temp = strdup(str); |
70 70 | for ( int off = strlen(str) - 1; off >= 0; --off ) { |
71 71 | if ( temp[off] == '/' ) temp[off] = '\0'; |
72 72 | else break; |
73 73 | } |
74 74 | std::string result = temp; |
75 75 | free(temp); |
76 76 | return result; |
77 77 | } |
78 78 | |
79 + | grpcFlagAgentState::grpcFlagAgentState( ) : userChoice_p("Continue"), userFixA1_p(""), userFixA2_p(""), |
80 + | skipScan_p(-1), skipSpw_p(-1), skipField_p(-1), |
81 + | antenna1_p(""),antenna2_p(""), input_received(false) { } |
82 + | |
79 83 | ::grpc::Status grpcFlagAgentResponse::button( ::grpc::ServerContext *context, |
80 84 | const ::rpc::gui::ButtonEvent *req, |
81 85 | ::google::protobuf::Empty* ) { |
82 86 | static const auto debug = getenv("GRPC_DEBUG"); |
83 87 | if ( debug ) { |
84 - | std::cerr << "plotserver button event received " << |
88 + | std::cerr << "plotserver '" << req->name( ) << "' button event received " << |
85 89 | " (process " << getpid( ) << ", thread " << |
86 90 | std::this_thread::get_id() << ")" << std::endl; |
87 91 | fflush(stderr); |
88 92 | } |
93 + | |
94 + | // Manage buttons from: Data Plot Window |
95 + | if ( req->name( ) == "NextBaseline" || req->name( ) == "PrevBaseline" || |
96 + | req->name( ) == "NextScan" || req->name( ) == "NextField" || |
97 + | req->name( ) == "NextSpw" || req->name( ) == "StopDisplay" || req->name( ) == "Quit") { |
98 + | std::lock_guard<std::mutex> lock(state->set_values); |
99 + | state->userChoice_p = req->name( ); // set input |
100 + | state->input_received = true; // set whenever state object is modified |
101 + | if ( state->input_needed ) |
102 + | state->output.set_value(true); // signal controlling thread that wait is over |
103 + | } |
104 + | |
105 + | // Manage buttons from: Report Plot Window |
106 + | if ( req->name( ) == "Next" || req->name( ) == "Prev" || req->name( ) == "Quit") { |
107 + | std::lock_guard<std::mutex> lock(state->set_values); |
108 + | state->userChoice_p = req->name( ); // set input |
109 + | state->input_received = true; // set whenever state object is modified |
110 + | if ( state->input_needed ) |
111 + | state->output.set_value(true); // signal controlling thread that wait is over |
112 + | } |
113 + | |
89 114 | return grpc::Status::OK; |
90 115 | } |
91 116 | ::grpc::Status grpcFlagAgentResponse::check( ::grpc::ServerContext *context, |
92 117 | const ::rpc::gui::CheckEvent *req, |
93 118 | ::google::protobuf::Empty* ) { |
94 119 | static const auto debug = getenv("GRPC_DEBUG"); |
95 120 | if ( debug ) { |
96 - | std::cerr << "plotserver check event received " << |
121 + | std::cerr << "plotserver " << req->name( ) << |
122 + | " [" << req->state( ) << "] check event received " << |
97 123 | " (process " << getpid( ) << ", thread " << |
98 124 | std::this_thread::get_id() << ")" << std::endl; |
99 125 | fflush(stderr); |
100 126 | } |
127 + | |
128 + | // Manage check boxes from: Data Plot Window |
129 + | if ( req->name( ) == "FixAntenna1" ) { |
130 + | std::lock_guard<std::mutex> lock(state->set_values); |
131 + | state->userChoice_p = "Continue"; |
132 + | state->userFixA1_p = (req->state( ) == 0) ? "" : state->antenna1_p; |
133 + | state->input_received = true; |
134 + | if ( state->input_needed ) |
135 + | state->output.set_value(true); // signal controlling thread that wait is over |
136 + | } else if ( req->name( ) == "FixAntenna2" ) { |
137 + | std::lock_guard<std::mutex> lock(state->set_values); |
138 + | state->userChoice_p = "Continue"; |
139 + | state->userFixA2_p = (req->state( ) == 0 ) ? "" : state->antenna2_p; |
140 + | state->input_received = true; |
141 + | if ( state->input_needed ) |
142 + | state->output.set_value(true); // signal controlling thread that wait is over |
143 + | } |
101 144 | return grpc::Status::OK; |
102 145 | } |
103 146 | ::grpc::Status grpcFlagAgentResponse::radio( ::grpc::ServerContext *context, |
104 147 | const ::rpc::gui::RadioEvent *req, |
105 148 | ::google::protobuf::Empty* ) { |
106 149 | static const auto debug = getenv("GRPC_DEBUG"); |
107 150 | if ( debug ) { |
108 - | std::cerr << "plotserver radio event received " << |
151 + | std::cerr << "plotserver " << req->name( ) << |
152 + | " [" << req->state( ) << "] radio event received " << |
109 153 | " (process " << getpid( ) << ", thread " << |
110 154 | std::this_thread::get_id() << ")" << std::endl; |
111 155 | fflush(stderr); |
112 156 | } |
113 157 | return grpc::Status::OK; |
114 158 | } |
115 159 | ::grpc::Status grpcFlagAgentResponse::linetext( ::grpc::ServerContext *context, |
116 160 | const ::rpc::gui::LineTextEvent *req, |
117 161 | ::google::protobuf::Empty* ) { |
118 162 | static const auto debug = getenv("GRPC_DEBUG"); |
119 163 | if ( debug ) { |
120 - | std::cerr << "plotserver linetext event received " << |
164 + | std::cerr << "plotserver " << req->name( ) << |
165 + | " [" << req->text( ) << "] linetext event received " << |
121 166 | " (process " << getpid( ) << ", thread " << |
122 167 | std::this_thread::get_id() << ")" << std::endl; |
123 168 | fflush(stderr); |
124 169 | } |
125 170 | return grpc::Status::OK; |
126 171 | } |
127 172 | ::grpc::Status grpcFlagAgentResponse::slidevalue( ::grpc::ServerContext *context, |
128 173 | const ::rpc::gui::SlideValueEvent *req, |
129 174 | ::google::protobuf::Empty* ) { |
130 175 | static const auto debug = getenv("GRPC_DEBUG"); |
131 176 | if ( debug ) { |
132 - | std::cerr << "plotserver slidevalue event received " << |
177 + | std::cerr << "plotserver " << req->name( ) << |
178 + | "[" << req->value( ) << "] slidevalue event received " << |
133 179 | " (process " << getpid( ) << ", thread " << |
134 180 | std::this_thread::get_id() << ")" << std::endl; |
135 181 | fflush(stderr); |
136 182 | } |
137 183 | return grpc::Status::OK; |
138 184 | } |
139 185 | ::grpc::Status grpcFlagAgentResponse::exiting( ::grpc::ServerContext *context, |
140 186 | const ::google::protobuf::Empty*, |
141 187 | ::google::protobuf::Empty* ) { |
142 188 | static const auto debug = getenv("GRPC_DEBUG"); |
384 430 | std::this_thread::get_id() << ")" << std::endl; |
385 431 | fflush(stderr); |
386 432 | } |
387 433 | |
388 434 | plot_started_ = true; |
389 435 | |
390 436 | return true; |
391 437 | } |
392 438 | |
393 439 | |
394 - | FlagAgentDisplay::plotter_t::plotter_t( ) : active_(false), response_svc(new grpcFlagAgentResponse), |
395 - | plot_started_(false) { |
440 + | FlagAgentDisplay::plotter_t::plotter_t(std::shared_ptr<grpcFlagAgentState> state) : |
441 + | active_(false), response_svc(new grpcFlagAgentResponse(state)), plot_started_(false) { |
396 442 | static const auto debug = getenv("GRPC_DEBUG"); |
397 443 | |
398 444 | if ( debug ) { |
399 445 | std::cerr << "attempting to start plotserver process " << |
400 446 | " (process " << getpid( ) << ", thread " << |
401 447 | std::this_thread::get_id() << ")" << std::endl; |
402 448 | fflush(stderr); |
403 449 | } |
404 450 | std::string ps_path = get_casaplotserver_path( ); |
405 451 | if ( ps_path.size() > 0 ) { |
429 475 | std::cerr << "could not find casaplotserver executable " << |
430 476 | " (process " << getpid( ) << ", thread " << |
431 477 | std::this_thread::get_id() << ")" << std::endl; |
432 478 | fflush(stderr); |
433 479 | } |
434 480 | |
435 481 | } |
436 482 | |
437 483 | |
438 484 | FlagAgentDisplay::FlagAgentDisplay(double) : FlagAgentBase(0.0) { |
439 - | dataplotter_p.reset(new plotter_t( )); |
485 + | dataplotter_p.reset(new plotter_t(gui_state)); |
440 486 | fprintf( stderr, "creating plotter panel............\n" ); |
441 487 | create_panel( dataplotter_p, 0 ); |
442 488 | } |
443 489 | |
444 490 | FlagAgentDisplay::FlagAgentDisplay(FlagDataHandler *dh, Record config, Bool writePrivateFlagCube): |
445 491 | FlagAgentBase(dh,config,ANTENNA_PAIRS_INTERACTIVE,writePrivateFlagCube), |
446 - | dataplotter_p(NULL),reportplotter_p(NULL), |
447 - | userChoice_p("Continue"), userFixA1_p(""), userFixA2_p(""), |
448 - | skipScan_p(-1), skipSpw_p(-1), skipField_p(-1),pause_p(false), |
492 + | gui_state(new grpcFlagAgentState), |
493 + | dataplotter_p(NULL),reportplotter_p(NULL), pause_p(false), |
449 494 | fieldId_p(-1), fieldName_p(""), scanStart_p(-1), scanEnd_p(-1), spwId_p(-1), |
450 495 | nPolarizations_p(1), freqList_p(Vector<Double>()), |
451 - | antenna1_p(""),antenna2_p(""), |
452 496 | dataDisplay_p(false), reportDisplay_p(false),reportFormat_p("screen"), |
453 497 | stopAndExit_p(false),/* reportReturn_p(false),*/ showBandpass_p(false) |
454 498 | { |
455 499 | // Parse parameters and set base variables. |
456 500 | setAgentParameters(config); |
457 501 | // Request loading polarization map to FlagDataHandler |
458 502 | flagDataHandler_p->setMapPolarizations(true); |
459 503 | // Make the list of colours (these are almost all predefined ones for Qt. |
460 504 | // Can add more later, based on RGB values. |
461 505 | plotColours_p.resize(13); |
776 820 | if (!checkVisExpression(flagDataHandler_p->getPolarizationMap())) return; |
777 821 | |
778 822 | // Iterate through antenna pair map |
779 823 | std::pair<Int,Int> antennaPair; |
780 824 | antennaPairMapIterator myAntennaPairMapIterator; |
781 825 | bool stepback=false; |
782 826 | for (myAntennaPairMapIterator=antennaPairMap_ptr->begin(); myAntennaPairMapIterator != antennaPairMap_ptr->end(); ++myAntennaPairMapIterator) |
783 827 | { |
784 828 | |
785 829 | // Check whether to skip the rest of this chunk or not |
786 - | if(skipSpw_p != -1) |
830 + | if(gui_state->skipSpw_p != -1) |
787 831 | { |
788 - | if(skipSpw_p == spwId_p) {dataDisplay_p=false;} // Skip the rest of this SPW |
789 - | else {skipSpw_p = -1; dataDisplay_p=true;} // Reached next SPW. Reset state |
832 + | if(gui_state->skipSpw_p == spwId_p) {dataDisplay_p=false;} // Skip the rest of this SPW |
833 + | else { |
834 + | std::lock_guard<std::mutex> lock(gui_state->set_values); |
835 + | gui_state->skipSpw_p = -1; |
836 + | dataDisplay_p=true; |
837 + | } // Reached next SPW. Reset state |
790 838 | } |
791 - | if(skipField_p != -1) |
839 + | if(gui_state->skipField_p != -1) |
792 840 | { |
793 - | if(skipField_p == fieldId_p) {dataDisplay_p=false;} // Skip the rest of this Field |
794 - | else {skipField_p = -1; dataDisplay_p=true;} // Reached next Field. Reset state |
841 + | if(gui_state->skipField_p == fieldId_p) {dataDisplay_p=false;} // Skip the rest of this Field |
842 + | else { |
843 + | std::lock_guard<std::mutex> lock(gui_state->set_values); |
844 + | gui_state->skipField_p = -1; |
845 + | dataDisplay_p=true; |
846 + | } // Reached next Field. Reset state |
795 847 | } |
796 - | if(skipScan_p != -1) |
848 + | if(gui_state->skipScan_p != -1) |
797 849 | { |
798 - | if(skipScan_p == scanEnd_p) {dataDisplay_p=false;} // Skip the rest of this Scan |
799 - | else {skipScan_p = -1; dataDisplay_p=true;} // Reached next Scan. Reset state |
850 + | if(gui_state->skipScan_p == scanEnd_p) {dataDisplay_p=false;} // Skip the rest of this Scan |
851 + | else { |
852 + | std::lock_guard<std::mutex> lock(gui_state->set_values); |
853 + | gui_state->skipScan_p = -1; |
854 + | dataDisplay_p=true; |
855 + | } // Reached next Scan. Reset state |
800 856 | } |
801 857 | |
802 858 | |
803 859 | // Display this baseline |
804 860 | if(dataDisplay_p) |
805 861 | { |
806 862 | |
807 863 | // If choice from previous plot was to go backwards in baseline. |
808 864 | if(stepback) |
809 865 | { |
810 866 | // Go to previous baseline (decrement by 2) |
811 867 | if( myAntennaPairMapIterator != antennaPairMap_ptr->begin() ) |
812 868 | -- myAntennaPairMapIterator; |
813 869 | if( myAntennaPairMapIterator != antennaPairMap_ptr->begin() ) |
814 870 | -- myAntennaPairMapIterator; |
815 871 | |
816 872 | // If antenna constraints exist, keep going back until first match is found. |
817 873 | // If not found, stay on current baseline (continue) |
818 - | if( userFixA1_p != String("") || userFixA2_p != String("") ) |
874 + | if( gui_state->userFixA1_p != "" || gui_state->userFixA2_p != "" ) |
819 875 | { |
820 876 | antennaPairMapIterator tempIterator; |
821 877 | bool found=false; |
822 878 | for(tempIterator = myAntennaPairMapIterator; tempIterator != antennaPairMap_ptr->begin() ; --tempIterator ) |
823 879 | { |
824 880 | if( ! skipBaseline(tempIterator->first) ) {found=true; break;} |
825 881 | } |
826 882 | if(found) // Jump to this antenna pair |
827 883 | { |
828 884 | myAntennaPairMapIterator = tempIterator; |
829 885 | } |
830 886 | else |
831 887 | { |
832 888 | *logger_p << "No Previous baseline in this chunk with Ant1 : " |
833 - | << ( (userFixA1_p==String(""))?String("any"):userFixA1_p ) |
889 + | << ( (gui_state->userFixA1_p != "") ? gui_state->userFixA1_p : "any" ) |
834 890 | << " and Ant2 : " |
835 - | << ( (userFixA2_p==String(""))?String("any"):userFixA2_p ) |
891 + | << ( (gui_state->userFixA2_p != "") ? gui_state->userFixA2_p : "any" ) |
836 892 | << LogIO::POST; |
837 893 | |
838 894 | // Stay on current baseline |
839 895 | if( myAntennaPairMapIterator != antennaPairMap_ptr->end() ) |
840 896 | ++myAntennaPairMapIterator; |
841 897 | } |
842 898 | } |
843 899 | |
844 900 | // Reset state |
845 901 | stepback=false; |
855 911 | processAntennaPair(antennaPair.first,antennaPair.second); |
856 912 | |
857 913 | // If Plot window is visible, and, if asked for, get and react to user-choices. |
858 914 | if(pause_p==true) |
859 915 | { |
860 916 | |
861 917 | // Wait for User Input |
862 918 | getUserInput(); // Fills in userChoice_p. userfix |
863 919 | |
864 920 | // React to user-input |
865 - | if(userChoice_p=="Quit") |
921 + | if(gui_state->userChoice_p=="Quit") |
866 922 | { |
867 923 | dataDisplay_p = false; |
868 924 | stopAndExit_p = true; |
869 925 | *logger_p << "Exiting flagger" << LogIO::POST; |
870 926 | if ( dataplotter_p != NULL ) { |
871 927 | done(dataplotter_p); |
872 928 | dataplotter_p=NULL; |
873 929 | } |
874 930 | flagDataHandler_p->stopIteration(); |
875 931 | return ; |
876 932 | } |
877 - | else if(userChoice_p=="StopDisplay") |
933 + | else if(gui_state->userChoice_p=="StopDisplay") |
878 934 | { |
879 935 | dataDisplay_p = false; |
880 936 | *logger_p << "Stopping display. Continuing flagging." << LogIO::POST; |
881 937 | if ( dataplotter_p != NULL ) { |
882 938 | done(dataplotter_p); |
883 939 | dataplotter_p=NULL; |
884 940 | } |
885 941 | } |
886 - | else if(userChoice_p=="PrevBaseline") |
942 + | else if(gui_state->userChoice_p=="PrevBaseline") |
887 943 | { |
888 944 | if( myAntennaPairMapIterator==antennaPairMap_ptr->begin() ) |
889 945 | *logger_p << "Already on first baseline..." << LogIO::POST; |
890 946 | stepback=true; |
891 947 | } |
892 - | else if(userChoice_p=="NextScan") |
948 + | else if(gui_state->userChoice_p=="NextScan") |
893 949 | { |
894 950 | //*logger_p << "Next Scan " << LogIO::POST; |
895 - | skipScan_p = scanEnd_p; |
951 + | std::lock_guard<std::mutex> lock(gui_state->set_values); |
952 + | gui_state->skipScan_p = scanEnd_p; |
896 953 | } |
897 - | else if(userChoice_p=="NextSpw") |
954 + | else if(gui_state->userChoice_p=="NextSpw") |
898 955 | { |
899 956 | //*logger_p << "Next SPW " << LogIO::POST; |
900 - | skipSpw_p = spwId_p; |
957 + | std::lock_guard<std::mutex> lock(gui_state->set_values); |
958 + | gui_state->skipSpw_p = spwId_p; |
901 959 | } |
902 - | else if(userChoice_p=="NextField") |
960 + | else if(gui_state->userChoice_p=="NextField") |
903 961 | { |
904 962 | //*logger_p << "Next Field " << LogIO::POST; |
905 - | skipField_p = fieldId_p; |
963 + | std::lock_guard<std::mutex> lock(gui_state->set_values); |
964 + | gui_state->skipField_p = fieldId_p; |
906 965 | } |
907 - | else if(userChoice_p=="Continue") |
966 + | else if(gui_state->userChoice_p=="Continue") |
908 967 | { |
909 968 | //*logger_p << "Next chunk " << LogIO::POST; // Right now, a chunk is one baseline ! |
910 969 | return; |
911 970 | } |
912 971 | |
913 972 | }// end if pause=true |
914 973 | |
915 974 | }// if dataDisplay_p |
916 975 | |
917 976 | }// end antennaMapIterator |
918 977 | |
919 978 | return; |
920 979 | }// end iterateAntennaPairsInteractive |
921 980 | |
922 981 | |
923 982 | Bool |
924 983 | FlagAgentDisplay::skipBaseline(std::pair<Int,Int> antennaPair) |
925 984 | { |
926 - | String antenna1Name = flagDataHandler_p->antennaNames_p->operator()(antennaPair.first); |
927 - | String antenna2Name = flagDataHandler_p->antennaNames_p->operator()(antennaPair.second); |
985 + | std::string antenna1Name = flagDataHandler_p->antennaNames_p->operator()(antennaPair.first); |
986 + | std::string antenna2Name = flagDataHandler_p->antennaNames_p->operator()(antennaPair.second); |
928 987 | // if(userFixA2_p != "") cout << "*********** userfixa2 : " << userFixA2_p << " thisant : " << antenna1Name << " && " << antenna2Name << LogIO::POST; |
929 - | return ( (userFixA1_p != "" && userFixA1_p != antenna1Name) || (userFixA2_p != "" && userFixA2_p != antenna2Name) ) ; |
988 + | return ( (gui_state->userFixA1_p != "" && gui_state->userFixA1_p != antenna1Name) || |
989 + | (gui_state->userFixA2_p != "" && gui_state->userFixA2_p != antenna2Name) ) ; |
930 990 | } |
931 991 | |
932 992 | bool |
933 993 | FlagAgentDisplay::computeAntennaPairFlags(const vi::VisBuffer2 &visBuffer, |
934 994 | VisMapper &visibilities,FlagMapper &flags,Int antenna1,Int antenna2, |
935 995 | vector<uInt> &/*rows*/) |
936 996 | { |
937 997 | logger_p->origin(LogOrigin(agentName_p,__FUNCTION__,WHERE)); |
938 998 | // Gather shapes |
939 999 | IPosition flagCubeShape = visibilities.shape(); |
940 1000 | uInt nChannels = flagCubeShape(0); |
941 1001 | uInt nTimes = flagCubeShape(1); |
942 1002 | |
943 1003 | // Read antenna names for the current baseline |
944 1004 | String antenna1Name = flagDataHandler_p->antennaNames_p->operator()(antenna1); |
945 1005 | String antenna2Name = flagDataHandler_p->antennaNames_p->operator()(antenna2); |
946 1006 | String baselineName = antenna1Name + "&&" + antenna2Name; |
947 - | antenna1_p = antenna1Name; |
948 - | antenna2_p = antenna2Name; |
1007 + | { |
1008 + | std::lock_guard<std::mutex> lock(gui_state->set_values); |
1009 + | gui_state->antenna1_p = antenna1Name; |
1010 + | gui_state->antenna2_p = antenna2Name; |
1011 + | } |
949 1012 | |
950 1013 | String scanRange = (scanStart_p!=scanEnd_p)?String::toString(scanStart_p)+"~"+String::toString(scanEnd_p) : String::toString(scanStart_p); |
951 1014 | String spwName = String::toString(visBuffer.spectralWindows()(0)); |
952 1015 | |
953 1016 | // Get Frequency List |
954 1017 | freqList_p.resize(nChannels); |
955 1018 | for(uInt ch=0;ch<nChannels;ch++) freqList_p[ch]=(Double)ch; |
956 1019 | |
957 1020 | |
958 1021 | /* |
1296 1359 | |
1297 1360 | }// end of plotpoints |
1298 1361 | else |
1299 1362 | { |
1300 1363 | *logger_p << "NO Display for : " << reportid << " : " << agentName << LogIO::POST; |
1301 1364 | } |
1302 1365 | |
1303 1366 | getReportUserInput(); |
1304 1367 | |
1305 1368 | // React to user-input |
1306 - | if(userChoice_p=="Quit") |
1369 + | if(gui_state->userChoice_p=="Quit") |
1307 1370 | { |
1308 1371 | dataDisplay_p = false; |
1309 1372 | stopAndExit_p = true; |
1310 1373 | //*logger_p << "Exiting flagger" << LogIO::POST; |
1311 1374 | if( reportplotter_p != NULL ) { |
1312 1375 | done(reportplotter_p); |
1313 1376 | reportplotter_p = NULL; |
1314 1377 | } |
1315 1378 | return true; |
1316 1379 | } |
1317 - | else if(userChoice_p=="Prev") |
1380 + | else if(gui_state->userChoice_p=="Prev") |
1318 1381 | { |
1319 1382 | //*logger_p << "Prev Plot" << LogIO::POST; |
1320 1383 | if( reportid==0 ) |
1321 1384 | *logger_p << "Already on first plot..." << LogIO::POST; |
1322 1385 | else |
1323 1386 | --reportid; |
1324 1387 | stepback=true; |
1325 1388 | } |
1326 - | else if(userChoice_p=="Continue" || userChoice_p=="Next") |
1389 + | else if(gui_state->userChoice_p=="Continue" || gui_state->userChoice_p=="Next") |
1327 1390 | { |
1328 1391 | //*logger_p << "Next Plot " << LogIO::POST; |
1329 1392 | if( reportid==nReports-1 ) |
1330 1393 | { |
1331 1394 | *logger_p << "Already on last plot..." << LogIO::POST; |
1332 1395 | --reportid; |
1333 1396 | } |
1334 1397 | } |
1335 1398 | |
1336 1399 | }// if valid plot type |
1365 1428 | // by the private variable 'showBandPass_p'. This can be later |
1366 1429 | // enabled when we get per-chunk 'extra info' displays/reports from |
1367 1430 | // the agents. Right now, it's redundant info, and takes up too much |
1368 1431 | // space on small laptop screens. |
1369 1432 | Bool FlagAgentDisplay::buildDataPlotWindow() |
1370 1433 | { |
1371 1434 | |
1372 1435 | setDataLayout(); |
1373 1436 | AlwaysAssert( dock_xml_p != NULL , AipsError ); |
1374 1437 | |
1375 - | dataplotter_p.reset(new plotter_t( )); |
1438 + | dataplotter_p.reset(new plotter_t(gui_state)); |
1376 1439 | |
1377 1440 | Int nrows; |
1378 1441 | if(showBandpass_p==true) nrows=3; |
1379 1442 | else nrows=2; |
1380 1443 | panels_p.resize(nPolarizations_p*nrows); |
1381 1444 | string zoomloc=""; |
1382 1445 | string legendloc="bottom"; |
1383 1446 | |
1384 1447 | // First row : Data with no flags |
1385 1448 | panels_p[0] = create_panel(dataplotter_p,0); |
1432 1495 | |
1433 1496 | }// end buildDataPlotWindow |
1434 1497 | |
1435 1498 | |
1436 1499 | Bool FlagAgentDisplay::buildReportPlotWindow() |
1437 1500 | { |
1438 1501 | |
1439 1502 | setReportLayout(); |
1440 1503 | AlwaysAssert( report_dock_xml_p != NULL , AipsError ); |
1441 1504 | |
1442 - | reportplotter_p.reset(new plotter_t( )); |
1505 + | reportplotter_p.reset(new plotter_t(gui_state)); |
1443 1506 | |
1444 1507 | report_panels_p.resize(1); |
1445 1508 | string zoomloc=""; |
1446 1509 | string legendloc="bottom"; |
1447 1510 | report_panels_p[0] = create_panel(reportplotter_p,0); |
1448 1511 | |
1449 1512 | create_dock( reportplotter_p, report_panels_p[0], report_dock_xml_p ); |
1450 1513 | return true; |
1451 1514 | |
1452 1515 | }// end buildReportPlotWindow |
1453 1516 | |
1454 1517 | |
1455 1518 | |
1456 - | void FlagAgentDisplay :: getUserInput() |
1457 - | { |
1458 - | |
1459 - | userChoice_p = "Continue"; |
1460 - | String returnvalue; |
1461 - | |
1462 - | Bool exitEventLoop=false; |
1463 - | |
1464 - | while( ! exitEventLoop) |
1465 - | { |
1466 - | |
1467 - | returnvalue = dataplotter_p->eventloop(); |
1468 - | if(returnvalue == "NextBaseline" || returnvalue == "PrevBaseline" || returnvalue == "NextScan" |
1469 - | || returnvalue == "NextField" || returnvalue == "NextSpw" |
1470 - | || returnvalue == "StopDisplay" || returnvalue == "Quit") |
1471 - | { |
1472 - | userChoice_p = returnvalue; |
1473 - | exitEventLoop=true; |
1474 - | } |
1475 - | else if(returnvalue == "FixAntenna1:0" || returnvalue == "FixAntenna1:2" ) |
1476 - | { |
1477 - | userChoice_p = "Continue"; |
1478 - | // userFixA1_p=(returnvalue.lastchar()=='0')?-1:antenna1_p; |
1479 - | userFixA1_p=(returnvalue.lastchar()=='0')?String(""):antenna1_p; |
1480 - | exitEventLoop=false; |
1481 - | } |
1482 - | else if(returnvalue == "FixAntenna2:0" || returnvalue == "FixAntenna2:2" ) |
1483 - | { |
1484 - | userChoice_p = "Continue"; |
1485 - | // userFixA2_p=(returnvalue.lastchar()=='0')?-1:antenna2_p; |
1486 - | userFixA2_p=(returnvalue.lastchar()=='0')?String(""):antenna2_p; |
1487 - | exitEventLoop=false; |
1488 - | } |
1489 - | else *logger_p << LogIO::DEBUG2 << "Unknown GUI choice : " << returnvalue << LogIO::POST; |
1490 - | |
1491 - | // *logger_p << "ReturnValue : " << returnvalue << " userChoice : " << userChoice_p << " userFixA1 : " << userFixA1_p << " userFixA2 : " << userFixA2_p << LogIO::POST; |
1519 + | void FlagAgentDisplay :: getUserInput() { |
1492 1520 | |
1493 - | } |
1494 - | |
1521 + | if ( gui_state->input_received ) { |
1522 + | // GUI input received while this thread was preoccupied... |
1523 + | std::lock_guard<std::mutex> lock(gui_state->set_values); |
1524 + | gui_state->input_received = false; |
1525 + | return; |
1526 + | } else { |
1527 + | std::lock_guard<std::mutex> lock(gui_state->set_values); |
1528 + | gui_state->userChoice_p = "Continue"; |
1529 + | gui_state->output = std::promise<bool>( ); |
1530 + | gui_state->input_needed = true; |
1531 + | } |
1495 1532 | |
1496 - | return; |
1533 + | auto fut = gui_state->output.get_future(); |
1534 + | fut.get( ); |
1497 1535 | } |
1498 1536 | |
1499 1537 | |
1500 1538 | |
1501 1539 | void FlagAgentDisplay :: getReportUserInput() |
1502 1540 | { |
1503 - | |
1504 - | userChoice_p = "Continue"; |
1505 - | String returnvalue; |
1506 - | |
1507 - | Bool exitEventLoop=false; |
1508 - | |
1509 - | while( ! exitEventLoop) |
1510 - | { |
1511 - | |
1512 - | returnvalue = reportplotter_p->eventloop(); |
1513 - | if(returnvalue == "Next" || returnvalue == "Prev" || returnvalue == "Quit") |
1514 - | { |
1515 - | userChoice_p = returnvalue; |
1516 - | exitEventLoop=true; |
1517 - | } |
1518 - | else *logger_p << LogIO::DEBUG2 << "Unknown GUI choice (Not sure why eventloop is exiting without user-click... re-entering... )" << returnvalue << LogIO::POST; |
1519 - | |
1520 - | //*logger_p << "ReturnValue : " << returnvalue << " userChoice : " << userChoice_p << LogIO::POST; |
1521 - | |
1522 - | } |
1523 - | |
1541 + | if ( gui_state->input_received ) { |
1542 + | // GUI input received while this thread was preoccupied... |
1543 + | std::lock_guard<std::mutex> lock(gui_state->set_values); |
1544 + | gui_state->input_received = false; |
1545 + | return; |
1546 + | } else { |
1547 + | std::lock_guard<std::mutex> lock(gui_state->set_values); |
1548 + | gui_state->userChoice_p = "Continue"; |
1549 + | gui_state->output = std::promise<bool>( ); |
1550 + | gui_state->input_needed = true; |
1551 + | } |
1524 1552 | |
1525 - | return; |
1553 + | auto fut = gui_state->output.get_future(); |
1554 + | fut.get( ); |
1526 1555 | } |
1527 1556 | |
1557 + | |
1528 1558 | ////////////////////////////////////////////////////////////////////////////////////////////////////// |
1529 1559 | ////// Plot functions |
1530 1560 | ////////////////////////////////////////////////////////////////////////////////////////////////////// |
1531 1561 | |
1532 1562 | void FlagAgentDisplay::DisplayRaster(Int xdim, Int ydim, Vector<Float> &data, int frame) |
1533 1563 | { |
1534 1564 | if(data.nelements() != (uInt) xdim*ydim) |
1535 1565 | { |
1536 1566 | logger_p->origin(LogOrigin(agentName_p,__FUNCTION__,WHERE)); |
1537 1567 | *logger_p << LogIO::WARN << "Error in data XY dimensions. Not plotting" << LogIO::POST; |